#include "asterisk.h"
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
#include <netdb.h>
#include <signal.h>
#include <sys/signal.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <arpa/inet.h>
#include <netinet/ip.h>
#include <regex.h>
#include "asterisk/lock.h"
#include "asterisk/channel.h"
#include "asterisk/config.h"
#include "asterisk/logger.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/options.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
#include "asterisk/rtp.h"
#include "asterisk/udptl.h"
#include "asterisk/acl.h"
#include "asterisk/manager.h"
#include "asterisk/callerid.h"
#include "asterisk/cli.h"
#include "asterisk/app.h"
#include "asterisk/musiconhold.h"
#include "asterisk/dsp.h"
#include "asterisk/features.h"
#include "asterisk/srv.h"
#include "asterisk/astdb.h"
#include "asterisk/causes.h"
#include "asterisk/utils.h"
#include "asterisk/file.h"
#include "asterisk/astobj.h"
#include "asterisk/devicestate.h"
#include "asterisk/linkedlists.h"
#include "asterisk/stringfields.h"
#include "asterisk/monitor.h"
#include "asterisk/localtime.h"
#include "asterisk/abstract_jb.h"
#include "asterisk/compiler.h"
#include "asterisk/threadstorage.h"
#include "asterisk/translate.h"
Go to the source code of this file.
Data Structures | |
| struct | ast_peer_list |
| The peer list: Peers and Friends. More... | |
| struct | ast_register_list |
| The register list: Other SIP proxys we register with and place calls to. More... | |
| struct | ast_user_list |
| The user list: Users and friends. More... | |
| struct | c_referstatusstring |
| struct | cfsip_methods |
| struct | cfsip_options |
| List of well-known SIP options. If we get this in a require, we should check the list and answer accordingly. More... | |
| struct | cfsubscription_types |
| struct | domain |
| Domain data structure. More... | |
| struct | domain_list |
| struct | sip_auth |
| sip_auth: Credentials for authentication to other SIP services More... | |
| struct | sip_dual |
| structure used in transfers More... | |
| struct | sip_history |
| sip_history: Structure for saving transactions within a SIP dialog More... | |
| struct | sip_history_head |
| struct | sip_invite_param |
| Parameters to the transmit_invite function. More... | |
| struct | sip_peer |
| Structure for SIP peer data, we place calls to peers if registered or fixed IP address (host). More... | |
| struct | sip_pkt |
| sip packet - raw format for outbound packets that are sent or scheduled for transmission More... | |
| struct | sip_pvt |
| sip_pvt: PVT structures are used for each SIP dialog, ie. a call, a registration, a subscribe More... | |
| struct | sip_refer |
| Structure to handle SIP transfers. Dynamically allocated when needed. More... | |
| struct | sip_registry |
| Registrations with other SIP proxies. More... | |
| struct | sip_request |
| sip_request: The data grabbed from the UDP socket More... | |
| struct | sip_route |
| Structure to save routing information for a SIP session. More... | |
| struct | sip_user |
| Structure for SIP user data. User's place calls to us. More... | |
| struct | t38properties |
| T.38 channel settings (at some point we need to make this alloc'ed. More... | |
Defines | |
| #define | ALLOWED_METHODS "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY" |
| SIP Methods we support. | |
| #define | append_history(p, event, fmt, args...) append_history_full(p, "%-15s " fmt, event, ## args) |
| Append to SIP dialog history. | |
| #define | CALLERID_UNKNOWN "Unknown" |
| #define | CAN_CREATE_DIALOG 1 |
| #define | CAN_CREATE_DIALOG_UNSUPPORTED_METHOD 2 |
| #define | CAN_NOT_CREATE_DIALOG 0 |
| #define | CHECK_AUTH_BUF_INITLEN 256 |
| #define | DEC_CALL_LIMIT 0 |
| #define | DEC_CALL_RINGING 2 |
| #define | DEFAULT_ALLOW_EXT_DOM TRUE |
| #define | DEFAULT_ALLOWGUEST TRUE |
| #define | DEFAULT_AUTOCREATEPEER FALSE |
| #define | DEFAULT_CALLERID "asterisk" |
| #define | DEFAULT_COMPACTHEADERS FALSE |
| #define | DEFAULT_CONTEXT "default" |
| #define | DEFAULT_DEFAULT_EXPIRY 120 |
| #define | DEFAULT_EXPIRY 900 |
| #define | DEFAULT_FREQ_NOTOK 10 * 1000 |
| #define | DEFAULT_FREQ_OK 60 * 1000 |
| #define | DEFAULT_MAX_CALL_BITRATE (384) |
| #define | DEFAULT_MAX_EXPIRY 3600 |
| #define | DEFAULT_MAX_FORWARDS "70" |
| #define | DEFAULT_MAXMS 2000 |
| #define | DEFAULT_MIN_EXPIRY 60 |
| #define | DEFAULT_MOHINTERPRET "default" |
| #define | DEFAULT_MOHSUGGEST "" |
| #define | DEFAULT_MWITIME 10 |
| #define | DEFAULT_NOTIFYMIME "application/simple-message-summary" |
| #define | DEFAULT_NOTIFYRINGING TRUE |
| #define | DEFAULT_PEDANTIC FALSE |
| #define | DEFAULT_QUALIFY FALSE |
| #define | DEFAULT_REALM "asterisk" |
| #define | DEFAULT_REGISTRATION_TIMEOUT 20 |
| #define | DEFAULT_RETRANS 1000 |
| #define | DEFAULT_SRVLOOKUP TRUE |
| #define | DEFAULT_T1MIN 100 |
| #define | DEFAULT_TOS_AUDIO 0 |
| #define | DEFAULT_TOS_SIP 0 |
| #define | DEFAULT_TOS_VIDEO 0 |
| #define | DEFAULT_TRANS_TIMEOUT -1 |
| #define | DEFAULT_USERAGENT "Asterisk PBX" |
| #define | DEFAULT_VMEXTEN "asterisk" |
| #define | EXPIRY_GUARD_LIMIT 30 |
| #define | EXPIRY_GUARD_MIN 500 |
| #define | EXPIRY_GUARD_PCT 0.20 |
| #define | EXPIRY_GUARD_SECS 15 |
| #define | FALSE 0 |
| #define | FLAG_FATAL (1 << 1) |
| #define | FLAG_RESPONSE (1 << 0) |
| #define | FORMAT "%-15.15s %-10.10s %-11.11s %5.5d/%5.5d %-15.15s %-3.3s %-3.3s %-15.15s %-10.10s\n" |
| #define | FORMAT "%-30.30s %-12.12s %8d %-20.20s %-25.25s\n" |
| #define | FORMAT "%-40.40s %-20.20s %-16.16s\n" |
| #define | FORMAT "%-25.25s %-15.15s %-3.3s %-3.3s %-3.3s %-8d %-10s %-10s\n" |
| #define | FORMAT "%-25.25s %-15.15s %-15.15s %-15.15s %-5.5s%-10.10s\n" |
| #define | FORMAT "%-25.25s %-15.15s %-15.15s \n" |
| #define | FORMAT2 "%-15.15s %-10.10s %-11.11s %-11.11s %-15.15s %-7.7s %-15.15s\n" |
| #define | FORMAT2 "%-30.30s %-12.12s %8.8s %-20.20s %-25.25s\n" |
| #define | FORMAT2 "%-25.25s %-15.15s %-3.3s %-3.3s %-3.3s %-8s %-10s %-10s\n" |
| #define | FORMAT2 "%-25.25s %-15.15s %-15.15s \n" |
| #define | FORMAT3 "%-15.15s %-10.10s %-11.11s %-15.15s %-13.13s %-15.15s %-10.10s\n" |
| #define | INC_CALL_LIMIT 1 |
| #define | INC_CALL_RINGING 3 |
| #define | INITIAL_CSEQ 101 |
| #define | IPTOS_MINCOST 0x02 |
| #define | MAX(a, b) ((a) > (b) ? (a) : (b)) |
| #define | MAX_AUTHTRIES 3 |
| #define | MAX_HISTORY_ENTRIES 50 |
| #define | MAX_RETRANS 6 |
| #define | NO_RTP 0 |
| #define | NOT_SUPPORTED 0 |
| #define | RTP 1 |
| #define | SDP_MAX_RTPMAP_CODECS 32 |
| #define | SDP_SAMPLE_RATE(x) 8000 |
| #define | SIP_ALREADYGONE (1 << 0) |
| #define | SIP_CALL_LIMIT (1 << 28) |
| #define | SIP_CAN_REINVITE (1 << 20) |
| #define | SIP_CAN_REINVITE_NAT (2 << 20) |
| #define | SIP_DEFER_BYE_ON_TRANSFER (1 << 15) |
| #define | SIP_DTMF (3 << 16) |
| #define | SIP_DTMF_AUTO (3 << 16) |
| #define | SIP_DTMF_INBAND (1 << 16) |
| #define | SIP_DTMF_INFO (2 << 16) |
| #define | SIP_DTMF_RFC2833 (0 << 16) |
| #define | SIP_FLAGS_TO_COPY |
| #define | SIP_FREE_BIT (1 << 14) |
| #define | SIP_G726_NONSTANDARD (1 << 31) |
| #define | SIP_GOTREFER (1 << 7) |
| #define | SIP_INC_COUNT (1 << 30) |
| #define | SIP_INSECURE_INVITE (1 << 24) |
| #define | SIP_INSECURE_PORT (1 << 23) |
| #define | SIP_MAX_HEADERS 64 |
| #define | SIP_MAX_LINES 64 |
| #define | SIP_MAX_PACKET 4096 |
| #define | SIP_NAT (3 << 18) |
| #define | SIP_NAT_ALWAYS (3 << 18) |
| #define | SIP_NAT_NEVER (0 << 18) |
| #define | SIP_NAT_RFC3581 (1 << 18) |
| #define | SIP_NAT_ROUTE (2 << 18) |
| #define | SIP_NEEDDESTROY (1 << 1) |
| #define | SIP_NEEDREINVITE (1 << 5) |
| #define | SIP_NO_HISTORY (1 << 27) |
| #define | SIP_NOVIDEO (1 << 2) |
| #define | SIP_OPT_100REL (1 << 1) |
| #define | SIP_OPT_EARLY_SESSION (1 << 3) |
| #define | SIP_OPT_EVENTLIST (1 << 11) |
| #define | SIP_OPT_GRUU (1 << 12) |
| #define | SIP_OPT_HISTINFO (1 << 15) |
| #define | SIP_OPT_JOIN (1 << 4) |
| #define | SIP_OPT_NOREFERSUB (1 << 14) |
| #define | SIP_OPT_PATH (1 << 5) |
| #define | SIP_OPT_PRECONDITION (1 << 7) |
| #define | SIP_OPT_PREF (1 << 6) |
| #define | SIP_OPT_PRIVACY (1 << 8) |
| #define | SIP_OPT_REPLACES (1 << 0) |
| #define | SIP_OPT_RESPRIORITY (1 << 16) |
| #define | SIP_OPT_SDP_ANAT (1 << 9) |
| #define | SIP_OPT_SEC_AGREE (1 << 10) |
| #define | SIP_OPT_TARGET_DIALOG (1 << 13) |
| #define | SIP_OPT_TIMER (1 << 2) |
| #define | SIP_OUTGOING (1 << 13) |
| #define | SIP_PAGE2_ALLOWOVERLAP (1 << 17) |
| #define | SIP_PAGE2_ALLOWSUBSCRIBE (1 << 16) |
| #define | SIP_PAGE2_BUGGY_MWI (1 << 26) |
| #define | SIP_PAGE2_CALL_ONHOLD (3 << 23) |
| #define | SIP_PAGE2_CALL_ONHOLD_ACTIVE (1 << 23) |
| #define | SIP_PAGE2_CALL_ONHOLD_INACTIVE (3 << 23) |
| #define | SIP_PAGE2_CALL_ONHOLD_ONEDIR (2 << 23) |
| #define | SIP_PAGE2_DEBUG (3 << 11) |
| #define | SIP_PAGE2_DEBUG_CONFIG (1 << 11) |
| #define | SIP_PAGE2_DEBUG_CONSOLE (1 << 12) |
| #define | SIP_PAGE2_DIALOG_ESTABLISHED (1 << 29) |
| #define | SIP_PAGE2_DYNAMIC (1 << 13) |
| #define | SIP_PAGE2_FLAGS_TO_COPY |
| #define | SIP_PAGE2_IGNOREREGEXPIRE (1 << 10) |
| #define | SIP_PAGE2_INC_RINGING (1 << 19) |
| #define | SIP_PAGE2_OUTGOING_CALL (1 << 27) |
| #define | SIP_PAGE2_RFC2833_COMPENSATE (1 << 25) |
| #define | SIP_PAGE2_RT_FROMCONTACT (1 << 4) |
| #define | SIP_PAGE2_RTAUTOCLEAR (1 << 2) |
| #define | SIP_PAGE2_RTCACHEFRIENDS (1 << 0) |
| #define | SIP_PAGE2_RTSAVE_SYSNAME (1 << 5) |
| #define | SIP_PAGE2_RTUPDATE (1 << 1) |
| #define | SIP_PAGE2_SELFDESTRUCT (1 << 14) |
| #define | SIP_PAGE2_STATECHANGEQUEUE (1 << 9) |
| #define | SIP_PAGE2_SUBSCRIBEMWIONLY (1 << 18) |
| #define | SIP_PAGE2_T38SUPPORT (7 << 20) |
| #define | SIP_PAGE2_T38SUPPORT_RTP (2 << 20) |
| #define | SIP_PAGE2_T38SUPPORT_TCP (4 << 20) |
| #define | SIP_PAGE2_T38SUPPORT_UDPTL (1 << 20) |
| #define | SIP_PAGE2_UDPTL_DESTINATION (1 << 28) |
| #define | SIP_PAGE2_VIDEOSUPPORT (1 << 15) |
| #define | SIP_PENDINGBYE (1 << 6) |
| #define | SIP_PKT_DEBUG (1 << 0) |
| #define | SIP_PKT_IGNORE (1 << 2) |
| #define | SIP_PKT_IGNORE_REQ (1 << 4) |
| #define | SIP_PKT_IGNORE_RESP (1 << 3) |
| #define | SIP_PKT_WITH_TOTAG (1 << 1) |
| #define | SIP_PROG_INBAND (3 << 25) |
| #define | SIP_PROG_INBAND_NEVER (0 << 25) |
| #define | SIP_PROG_INBAND_NO (1 << 25) |
| #define | SIP_PROG_INBAND_YES (2 << 25) |
| #define | SIP_PROGRESS_SENT (1 << 4) |
| #define | SIP_PROMISCREDIR (1 << 8) |
| #define | SIP_REALTIME (1 << 11) |
| #define | SIP_REINVITE (7 << 20) |
| #define | SIP_REINVITE_UPDATE (4 << 20) |
| #define | SIP_RINGING (1 << 3) |
| #define | SIP_SENDRPID (1 << 29) |
| #define | SIP_TRANS_TIMEOUT 32000 |
| #define | SIP_TRUSTRPID (1 << 9) |
| #define | SIP_USECLIENTCODE (1 << 12) |
| #define | SIP_USEREQPHONE (1 << 10) |
| #define | SIPBUFSIZE 512 |
| #define | sipdebug ast_test_flag(&global_flags[1], SIP_PAGE2_DEBUG) |
| #define | sipdebug_config ast_test_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONFIG) |
| #define | sipdebug_console ast_test_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONSOLE) |
| #define | STANDARD_SIP_PORT 5060 |
| Standard SIP port from RFC 3261. DO NOT CHANGE THIS. | |
| #define | SUPPORTED 1 |
| #define | SUPPORTED_EXTENSIONS "replaces" |
| SIP Extensions we support. | |
| #define | T38FAX_FILL_BIT_REMOVAL (1 << 0) |
| #define | T38FAX_RATE_12000 (1 << 12) |
| #define | T38FAX_RATE_14400 (1 << 13) |
| #define | T38FAX_RATE_2400 (1 << 8) |
| #define | T38FAX_RATE_4800 (1 << 9) |
| #define | T38FAX_RATE_7200 (1 << 10) |
| #define | T38FAX_RATE_9600 (1 << 11) |
| #define | T38FAX_RATE_MANAGEMENT_LOCAL_TCF (1 << 3) |
| #define | T38FAX_RATE_MANAGEMENT_TRANSFERED_TCF (0 << 3) |
| #define | T38FAX_TRANSCODING_JBIG (1 << 2) |
| #define | T38FAX_TRANSCODING_MMR (1 << 1) |
| #define | T38FAX_UDP_EC_FEC (1 << 4) |
| #define | T38FAX_UDP_EC_NONE (0 << 4) |
| #define | T38FAX_UDP_EC_REDUNDANCY (2 << 4) |
| #define | T38FAX_VERSION (3 << 6) |
| #define | T38FAX_VERSION_0 (0 << 6) |
| #define | T38FAX_VERSION_1 (1 << 6) |
| #define | TRUE 1 |
| #define | UNLINK(element, head, prev) |
| #define | VIDEO_CODEC_MASK 0x1fc0000 |
| #define | XMIT_ERROR -2 |
Enumerations | |
| enum | check_auth_result { AUTH_SUCCESSFUL = 0, AUTH_CHALLENGE_SENT = 1, AUTH_SECRET_FAILED = -1, AUTH_USERNAME_MISMATCH = -2, AUTH_NOT_FOUND = -3, AUTH_FAKE_AUTH = -4, AUTH_UNKNOWN_DOMAIN = -5, AUTH_PEER_NOT_DYNAMIC = -6, AUTH_ACL_FAILED = -7 } |
| Authentication result from check_auth* functions. More... | |
| enum | domain_mode { SIP_DOMAIN_AUTO, SIP_DOMAIN_CONFIG } |
| Modes for SIP domain handling in the PBX. More... | |
| enum | invitestates { INV_NONE = 0, INV_CALLING = 1, INV_PROCEEDING = 2, INV_EARLY_MEDIA = 3, INV_COMPLETED = 4, INV_CONFIRMED = 5, INV_TERMINATED = 6, INV_CANCELLED = 7 } |
| States for the INVITE transaction, not the dialog. More... | |
| enum | parse_register_result { PARSE_REGISTER_FAILED, PARSE_REGISTER_UPDATE, PARSE_REGISTER_QUERY } |
| enum | referstatus { REFER_IDLE, REFER_SENT, REFER_RECEIVED, REFER_CONFIRMED, REFER_ACCEPTED, REFER_RINGING, REFER_200OK, REFER_FAILED, REFER_NOAUTH } |
| Parameters to know status of transfer. More... | |
| enum | sip_auth_type { PROXY_AUTH, WWW_AUTH } |
| Authentication types - proxy or www authentication. More... | |
| enum | sip_result { AST_SUCCESS = 0, AST_FAILURE = -1 } |
| enum | sipmethod { SIP_UNKNOWN, SIP_RESPONSE, SIP_REGISTER, SIP_OPTIONS, SIP_NOTIFY, SIP_INVITE, SIP_ACK, SIP_PRACK, SIP_BYE, SIP_REFER, SIP_SUBSCRIBE, SIP_MESSAGE, SIP_UPDATE, SIP_INFO, SIP_CANCEL, SIP_PUBLISH, SIP_PING } |
| SIP Request methods known by Asterisk. More... | |
| enum | sipregistrystate { REG_STATE_UNREGISTERED = 0, REG_STATE_REGSENT, REG_STATE_AUTHSENT, REG_STATE_REGISTERED, REG_STATE_REJECTED, REG_STATE_TIMEOUT, REG_STATE_NOAUTH, REG_STATE_FAILED } |
| States for outbound registrations (with register= lines in sip.conf. More... | |
| enum | subscriptiontype { NONE = 0, XPIDF_XML, DIALOG_INFO_XML, CPIM_PIDF_XML, PIDF_XML, MWI_NOTIFICATION } |
| enum | t38state { T38_DISABLED = 0, T38_LOCAL_DIRECT, T38_LOCAL_REINVITE, T38_PEER_DIRECT, T38_PEER_REINVITE, T38_ENABLED } |
| T38 States for a call. More... | |
| enum | transfermodes { TRANSFER_OPENFORALL, TRANSFER_CLOSED } |
| Authorization scheme for call transfers. More... | |
| enum | xmittype { XMIT_CRITICAL = 2, XMIT_RELIABLE = 1, XMIT_UNRELIABLE = 0 } |
Functions | |
| static const char * | __get_header (const struct sip_request *req, const char *name, int *start) |
| static void | __reg_module (void) |
| static int | __set_address_from_contact (const char *fullcontact, struct sockaddr_in *sin) |
| static void | __sip_ack (struct sip_pvt *p, int seqno, int resp, int sipmethod) |
| Acknowledges receipt of a packet and stops retransmission called with p locked. | |
| static int | __sip_autodestruct (const void *data) |
| Kill a SIP dialog (called by scheduler). | |
| static int | __sip_destroy (struct sip_pvt *p, int lockowner) |
| Execute destruction of SIP dialog structure, release memory. | |
| static int | __sip_do_register (struct sip_registry *r) |
| Register with SIP proxy. | |
| static void | __sip_pretend_ack (struct sip_pvt *p) |
| Pretend to ack all packets called with p locked. | |
| static int | __sip_reliable_xmit (struct sip_pvt *p, int seqno, int resp, char *data, int len, int fatal, int sipmethod) |
| Transmit packet with retransmits. | |
| static int | __sip_semi_ack (struct sip_pvt *p, int seqno, int resp, int sipmethod) |
| Acks receipt of packet, keep it around (used for provisional responses). | |
| static int | __sip_show_channels (int fd, int argc, char *argv[], int subscriptions) |
| SIP show channels CLI (main function). | |
| static int | __sip_xmit (struct sip_pvt *p, char *data, int len) |
| Transmit SIP message. | |
| static int | __transmit_response (struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable) |
| Base transmit response function. | |
| static void | __unreg_module (void) |
| static int | _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 int | _sip_show_peers (int fd, int *total, struct mansession *s, const struct message *m, int argc, const char *argv[]) |
| _sip_show_peers: Execute sip show peers command | |
| static int | acf_channel_read (struct ast_channel *chan, char *funcname, char *preparse, char *buf, size_t buflen) |
| static void | add_blank (struct sip_request *req) |
| add a blank line if no body | |
| static void | add_codec_to_sdp (const struct sip_pvt *p, int codec, int sample_rate, char **m_buf, size_t *m_size, char **a_buf, size_t *a_size, int debug, int *min_packet_size) |
| Add codec offer to SDP offer/answer body in INVITE or 200 OK. | |
| static int | add_digit (struct sip_request *req, char digit, unsigned int duration) |
| Add DTMF INFO tone to sip message. | |
| static int | add_header (struct sip_request *req, const char *var, const char *value) |
| Add header to SIP message. | |
| static int | add_header_contentLength (struct sip_request *req, int len) |
| Add 'Content-Length' header to SIP message. | |
| static int | add_line (struct sip_request *req, const char *line) |
| Add content (not header) to SIP message. | |
| static void | add_noncodec_to_sdp (const struct sip_pvt *p, int format, int sample_rate, char **m_buf, size_t *m_size, char **a_buf, size_t *a_size, int debug) |
| Add RFC 2833 DTMF offer to SDP. | |
| static struct sip_auth * | add_realm_authentication (struct sip_auth *authlist, char *configuration, int lineno) |
| Add realm authentication in list. | |
| static void | add_route (struct sip_request *req, struct sip_route *route) |
| Add route header into request per learned route. | |
| static enum sip_result | add_sdp (struct sip_request *resp, struct sip_pvt *p) |
| 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_t38_sdp (struct sip_request *resp, struct sip_pvt *p) |
| Add T.38 Session Description Protocol message. | |
| static int | add_text (struct sip_request *req, const char *text) |
| Add text body to SIP message. | |
| static int | add_vidupdate (struct sip_request *req) |
| add XML encoded media control with update | |
| static void | append_date (struct sip_request *req) |
| Append date to SIP message. | |
| static void | append_history_full (struct sip_pvt *p, const char *fmt,...) |
| Append to SIP dialog history with arg list. | |
| static void | append_history_va (struct sip_pvt *p, const char *fmt, va_list ap) |
| Append to SIP dialog history with arg list. | |
| static void | ast_quiet_chan (struct ast_channel *chan) |
| Turn off generator data XXX Does this function belong in the SIP channel? | |
| static int | ast_sip_ouraddrfor (struct in_addr *them, struct in_addr *us) |
| NAT fix - decide which IP address to use for ASterisk server? | |
| static int | attempt_transfer (struct sip_dual *transferer, struct sip_dual *target) |
| Attempt transfer of SIP call This fix for attended transfers on a local PBX. | |
| static int | auto_congest (const void *nothing) |
| Scheduled congestion on a call. | |
| static void | build_callid_pvt (struct sip_pvt *pvt) |
| Build SIP Call-ID value for a non-REGISTER transaction. | |
| static void | build_callid_registry (struct sip_registry *reg, struct in_addr ourip, const char *fromdomain) |
| Build SIP Call-ID value for a REGISTER transaction. | |
| static void | build_contact (struct sip_pvt *p) |
| Build contact header - the contact header we send out. | |
| static struct sip_peer * | build_peer (const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime) |
| Build peer from configuration (file or realtime static/dynamic). | |
| static int | build_reply_digest (struct sip_pvt *p, int method, char *digest, int digest_len) |
| Build reply digest. | |
| static void | build_route (struct sip_pvt *p, struct sip_request *req, int backwards) |
| Build route list from Record-Route header. | |
| static void | build_rpid (struct sip_pvt *p) |
| Build the Remote Party-ID & From using callingpres options. | |
| static struct sip_user * | build_user (const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime) |
| Initiate a SIP user structure from configuration (configuration or realtime). | |
| static void | build_via (struct sip_pvt *p) |
| Build a Via header for a request. | |
| static int | cb_extensionstate (char *context, char *exten, int state, void *data) |
| Callback for the devicestate notification (SUBSCRIBE) support subsystem. | |
| static void | change_hold_state (struct sip_pvt *dialog, struct sip_request *req, int holdstate, int sendonly) |
| Change hold state for a call. | |
| static enum check_auth_result | check_auth (struct sip_pvt *p, struct sip_request *req, const char *username, const char *secret, const char *md5secret, int sipmethod, char *uri, enum xmittype reliable, int ignore) |
| Check user authorization from peer definition Some actions, like REGISTER and INVITEs from peers require authentication (if peer have secret set). | |
| static void | check_auth_buf_init (void) |
| static void | check_pendings (struct sip_pvt *p) |
| Check pending actions on SIP call. | |
| static int | check_sip_domain (const char *domain, char *context, size_t len) |
| check_sip_domain: Check if domain part of uri is local to our server | |
| static int | check_user (struct sip_pvt *p, struct sip_request *req, int sipmethod, char *uri, enum xmittype reliable, struct sockaddr_in *sin) |
| Find user If we get a match, this will add a reference pointer to the user object in ASTOBJ, that needs to be unreferenced. | |
| static enum check_auth_result | check_user_full (struct sip_pvt *p, struct sip_request *req, int sipmethod, char *uri, enum xmittype reliable, struct sockaddr_in *sin, struct sip_peer **authpeer) |
| Check if matching user or peer is defined Match user on From: user name and peer on IP/port This is used on first invite (not re-invites) and subscribe requests. | |
| static void | check_via (struct sip_pvt *p, const struct sip_request *req) |
| check Via: header for hostname, port and rport request/answer | |
| 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 int | clear_realm_authentication (struct sip_auth *authlist) |
| Clear realm authentication list (at reload). | |
| static void | clear_sip_domains (void) |
| Clear our domain list (at reload). | |
| static char * | complete_sip_debug_peer (const char *line, const char *word, int pos, int state) |
| Support routine for 'sip debug peer' CLI. | |
| static char * | complete_sip_peer (const char *word, int state, int flags2) |
| Do completion on peer name. | |
| static char * | complete_sip_prune_realtime_peer (const char *line, const char *word, int pos, int state) |
| Support routine for 'sip prune realtime peer' CLI. | |
| static char * | complete_sip_prune_realtime_user (const char *line, const char *word, int pos, int state) |
| Support routine for 'sip prune realtime user' 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_user (const char *word, int state, int flags2) |
| 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' CLI. | |
| static char * | complete_sipnotify (const char *line, const char *word, int pos, int state) |
| Support routine for 'sip notify' CLI. | |
| static int | copy_all_header (struct sip_request *req, const struct sip_request *orig, const char *field) |
| Copy all headers from one request to another. | |
| static int | copy_header (struct sip_request *req, const struct sip_request *orig, const char *field) |
| Copy one header field from one request to another. | |
| static void | copy_request (struct sip_request *dst, const struct sip_request *src) |
| copy SIP request (mostly used to save request for responses) | |
| static 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) |
| create address structure from peer 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. return -1 on error, 0 on success. | |
| static void | destroy_association (struct sip_peer *peer) |
| Remove registration data from realtime database or AST/DB when registration expires. | |
| static int | determine_firstline_parts (struct sip_request *req) |
| Parse first line of incoming SIP request. | |
| static void * | do_monitor (void *data) |
| The SIP monitoring thread. | |
| static int | do_proxy_auth (struct sip_pvt *p, struct sip_request *req, char *header, char *respheader, int sipmethod, int init) |
| Add authentication on outbound SIP packet. | |
| static int | do_register_auth (struct sip_pvt *p, struct sip_request *req, char *header, char *respheader) |
| Authenticate for outbound registration. | |
| static void | do_setnat (struct sip_pvt *p, int natflags) |
| Set nat mode on the various data sockets. | |
| static int | does_peer_need_mwi (struct sip_peer *peer) |
| Check whether peer needs a new MWI notification check. | |
| static const char * | domain_mode_to_text (const enum domain_mode mode) |
| Print domain mode to cli. | |
| static const char * | dtmfmode2str (int mode) |
| Convert DTMF mode to printable string. | |
| static int | expire_register (const void *data) |
| Expire registration of SIP peer. | |
| static void | extract_uri (struct sip_pvt *p, struct sip_request *req) |
| Check Contact: URI of SIP message. | |
| static const char * | find_alias (const char *name, const char *_default) |
| Find compressed SIP alias. | |
| static struct sip_pvt * | find_call (struct sip_request *req, struct sockaddr_in *sin, const int intended_method) |
| Connect incoming SIP message to current dialog or create new dialog structure Called by handle_request, sipsock_read. | |
| static const char * | find_closing_quote (const char *start, const char *lim) |
| Locate closing quote in a string, skipping escaped quotes. optionally with a limit on the search. start must be past the first quote. | |
| static struct sip_peer * | find_peer (const char *peer, struct sockaddr_in *sin, int realtime, int devstate_only) |
| Locate peer by name or ip address This is used on incoming SIP message to find matching peer on ip or outgoing message to find matching peer on name. | |
| static struct sip_auth * | find_realm_authentication (struct sip_auth *authlist, const char *realm) |
| Find authentication for a specific realm. | |
| static int | find_sdp (struct sip_request *req) |
| Determine whether a SIP message contains an SDP in its body. | |
| static int | find_sip_method (const char *msg) |
| find_sip_method: Find SIP method from header | |
| static struct cfsubscription_types * | find_subscription_type (enum subscriptiontype subtype) |
| Find subscription type in array. | |
| static struct sip_user * | find_user (const char *name, int realtime) |
| Locate user by name Locates user by name (From: sip uri user name part) first from in-memory list (static configuration) then from realtime storage (defined in extconfig.conf). | |
| static void | free_old_route (struct sip_route *route) |
| Remove route from route list. | |
| static int | func_check_sipdomain (struct ast_channel *chan, 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, char *function, char *data, char *buf, size_t len) |
| Read SIP header (dialplan function). | |
| static int | function_sipchaninfo_read (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) |
| ${SIPCHANINFO()} Dialplan function - reads sip channel data | |
| static int | function_sippeer (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) |
| ${SIPPEER()} Dialplan function - reads peer data | |
| static char * | generate_random_string (char *buf, size_t size) |
| Generate 32 byte random string for callid's etc. | |
| static int | get_also_info (struct sip_pvt *p, struct sip_request *oreq) |
| Call transfer support (old way, deprecated by the IETF)--. | |
| static char * | get_body (struct sip_request *req, char *name) |
| Get a specific line from the message body. | |
| static char * | get_body_by_line (const char *line, const char *name, int nameLen) |
| Reads one line of SIP message body. | |
| static char * | get_calleridname (const char *input, char *output, size_t outputsize) |
| Get caller id name from SIP headers. | |
| static int | get_destination (struct sip_pvt *p, struct sip_request *oreq) |
| Find out who the call is for We use the INVITE uri to find out. | |
| static const char * | get_header (const struct sip_request *req, const char *name) |
| Get header from SIP request. | |
| static char * | get_in_brackets (char *tmp) |
| Pick out text in brackets from character string. | |
| static int | get_msg_text (char *buf, int len, struct sip_request *req) |
| Get text out of a SIP MESSAGE packet. | |
| static int | get_rdnis (struct sip_pvt *p, struct sip_request *oreq) |
| Get referring dnis. | |
| static int | get_refer_info (struct sip_pvt *transferer, struct sip_request *outgoing_req) |
| Call transfer support (the REFER method) Extracts Refer headers into pvt dialog structure. | |
| static int | get_rpid_num (const char *input, char *output, int maxlen) |
| Get caller id number from Remote-Party-ID header field Returns true if number should be restricted (privacy setting found) output is set to NULL if no number found. | |
| static const char * | get_sdp (struct sip_request *req, const char *name) |
| Get a line from an SDP message body. | |
| 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 struct sip_pvt * | get_sip_pvt_byid_locked (const char *callid, const char *totag, const char *fromtag) |
| Lock interface lock and find matching pvt lock. | |
| static const char * | gettag (const struct sip_request *req, const char *header, char *tagbuf, int tagbufsize) |
| Get tag from packet. | |
| static int | handle_common_options (struct ast_flags *flags, struct ast_flags *mask, struct ast_variable *v) |
| Handle flag-type options common to configuration of devices - users and peers. | |
| static int | handle_invite_replaces (struct sip_pvt *p, struct sip_request *req, int debug, int ignore, int seqno, struct sockaddr_in *sin) |
| Handle the transfer part of INVITE with a replaces: header, meaning a target pickup or an attended transfer. | |
| static int | handle_request (struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int *recount, int *nounlock) |
| Handle incoming SIP requests (methods). | |
| 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 void | handle_request_info (struct sip_pvt *p, struct sip_request *req) |
| Receive SIP INFO Message. | |
| static int | handle_request_invite (struct sip_pvt *p, struct sip_request *req, int debug, int seqno, struct sockaddr_in *sin, int *recount, char *e, int *nounlock) |
| Handle incoming INVITE request. | |
| static int | handle_request_message (struct sip_pvt *p, struct sip_request *req) |
| Handle incoming MESSAGE request. | |
| static int | handle_request_notify (struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int seqno, char *e) |
| Handle incoming notifications. | |
| static int | handle_request_options (struct sip_pvt *p, struct sip_request *req) |
| Handle incoming OPTIONS request. | |
| static int | handle_request_refer (struct sip_pvt *p, struct sip_request *req, int debug, int ignore, int seqno, int *nounlock) |
| static int | handle_request_register (struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, char *e) |
| Handle incoming REGISTER request. | |
| static int | handle_request_subscribe (struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int seqno, char *e) |
| Handle incoming SUBSCRIBE request. | |
| static void | handle_response (struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int ignore, int seqno) |
| Handle SIP response in dialogue. | |
| static void | handle_response_invite (struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno) |
| Handle SIP response to INVITE dialogue. | |
| static void | handle_response_peerpoke (struct sip_pvt *p, int resp, struct sip_request *req) |
| Handle qualification responses (OPTIONS). | |
| static void | handle_response_refer (struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno) |
| static int | handle_response_register (struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int ignore, int seqno) |
| Handle responses on REGISTER to services. | |
| static const char * | hangup_cause2sip (int cause) |
| Convert Asterisk hangup causes to SIP codes. | |
| static int | hangup_sip2cause (int cause) |
| Convert SIP hangup causes to Asterisk hangup causes. | |
| static int | init_req (struct sip_request *req, int sipmethod, const char *recip) |
| Initialize SIP request. | |
| static int | init_resp (struct sip_request *resp, const char *msg) |
| Initialize SIP response, based on SIP request. | |
| static void | initialize_initreq (struct sip_pvt *p, struct sip_request *req) |
| Initialize the initital request packet in the pvt structure. This packet is used for creating replies and future requests in a dialog. | |
| static void | initreqprep (struct sip_request *req, struct sip_pvt *p, int sipmethod) |
| Initiate new SIP request to peer/user. | |
| static const char * | insecure2str (int port, int invite) |
| Convert Insecure setting to printable string. | |
| static void | list_route (struct sip_route *route) |
| List all routes - mostly for debugging. | |
| static int | load_module (void) |
| PBX load module - initialization. | |
| static int | local_attended_transfer (struct sip_pvt *transferer, struct sip_dual *current, struct sip_request *req, int seqno) |
| Find all call legs and bridge transferee with target called from handle_request_refer. | |
| static int | lws2sws (char *msgbuf, int len) |
| Parse multiline SIP headers into one header This is enabled if pedanticsipchecking is enabled. | |
| static void | make_our_tag (char *tagbuf, size_t len) |
| Make our SIP dialog tag. | |
| static int | manager_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 | 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 char * | nat2str (int nat) |
| Convert NAT setting to text string. | |
| static void | parse_copy (struct sip_request *dst, const struct sip_request *src) |
| Copy SIP request, parse it. | |
| static void | parse_moved_contact (struct sip_pvt *p, struct sip_request *req) |
| Parse 302 Moved temporalily response. | |
| static int | parse_ok_contact (struct sip_pvt *pvt, struct sip_request *req) |
| Save contact header for 200 OK on INVITE. | |
| static enum parse_register_result | parse_register_contact (struct sip_pvt *pvt, struct sip_peer *peer, struct sip_request *req) |
| Parse contact header and save registration (peer registration). | |
| static int | parse_request (struct sip_request *req) |
| Parse a SIP message. | |
| static unsigned int | parse_sip_options (struct sip_pvt *pvt, const char *supported) |
| Parse supported header in incoming packet. | |
| static int | peer_status (struct sip_peer *peer, char *status, int statuslen) |
| Report Peer status in character string. | |
| 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 int | process_sdp (struct sip_pvt *p, struct sip_request *req) |
| Process SIP SDP offer, select formats and activate RTP channels If offer is rejected, we will not change any properties of the call Return 0 on success, a negative value on errors. Must be called after find_sdp(). | |
| static struct sip_peer * | realtime_peer (const char *newpeername, struct sockaddr_in *sin, int devstate_only) |
| realtime_peer: Get peer from realtime storage Checks the "sippeers" realtime family from extconfig.conf | |
| static void | realtime_update_peer (const char *peername, struct sockaddr_in *sin, const char *username, const char *fullcontact, int expirey) |
| 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 struct sip_user * | realtime_user (const char *username) |
| Load user from realtime storage Loads user from "sipusers" category in realtime (extconfig.conf) Users are matched on From: user name (the domain in skipped). | |
| static void | receive_message (struct sip_pvt *p, struct sip_request *req) |
| Receive SIP MESSAGE method messages. | |
| static char * | referstatus2str (enum referstatus rstatus) |
| Convert transfer status to string. | |
| static void | reg_source_db (struct sip_peer *peer) |
| Get registration details from Asterisk DB. | |
| static void | register_peer_exten (struct sip_peer *peer, int onoff) |
| Automatically add peer extension to dial plan. | |
| static enum check_auth_result | register_verify (struct sip_pvt *p, struct sockaddr_in *sin, struct sip_request *req, char *uri) |
Verify registration of user
| |
| static char * | regstate2str (enum sipregistrystate regstate) |
| Convert registration state status to string. | |
| static int | reload (void) |
| Part of Asterisk module interface. | |
| static int | reload_config (enum channelreloadreason reason) |
| Re-read SIP.conf config file. | |
| static int | reply_digest (struct sip_pvt *p, struct sip_request *req, char *header, int sipmethod, char *digest, int digest_len) |
| reply to authentication for outbound registrations | |
| static int | reqprep (struct sip_request *req, struct sip_pvt *p, int sipmethod, int seqno, int newbranch) |
| Initialize a SIP request message (not the initial one in a dialog). | |
| static int | 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 int | retrans_pkt (const void *data) |
| Retransmit SIP message if no answer (Called from scheduler). | |
| static int | send_request (struct sip_pvt *p, struct sip_request *req, enum xmittype reliable, int seqno) |
| Send SIP Request to the other part of the dialogue. | |
| static int | send_response (struct sip_pvt *p, struct sip_request *req, enum xmittype reliable, int seqno) |
| Transmit response on SIP request. | |
| static int | set_address_from_contact (struct sip_pvt *pvt) |
| Change the other partys IP address based on given contact. | |
| static void | set_destination (struct sip_pvt *p, char *uri) |
| Set destination from SIP URI. | |
| static void | set_insecure_flags (struct ast_flags *flags, const char *value, int lineno) |
| Parse the "insecure" setting from sip.conf or from realtime. | |
| static void | set_peer_defaults (struct sip_peer *peer) |
| Set peer defaults before configuring specific configurations. | |
| static int | sip_addheader (struct ast_channel *chan, void *data) |
| Add a SIP header to an outbound INVITE. | |
| static int | sip_addrcmp (char *name, struct sockaddr_in *sin) |
| Support routine for find_peer. | |
| static struct sip_pvt * | sip_alloc (ast_string_field callid, struct sockaddr_in *sin, int useglobal_nat, const int intended_method) |
| Allocate SIP_PVT structure and set defaults. | |
| static void | sip_alreadygone (struct sip_pvt *dialog) |
| static int | sip_answer (struct ast_channel *ast) |
| sip_answer: Answer SIP call , send 200 OK on Invite Part of PBX interface | |
| static int | sip_call (struct ast_channel *ast, char *dest, int timeout) |
| Initiate SIP call from PBX used from the dial() application. | |
| static int | sip_cancel_destroy (struct sip_pvt *p) |
| Cancel destruction of SIP dialog. | |
| static int | sip_debug_test_addr (const struct sockaddr_in *addr) |
| See if we pass debug IP filter. | |
| static int | sip_debug_test_pvt (struct sip_pvt *p) |
| Test PVT for debugging output. | |
| static void | sip_destroy (struct sip_pvt *p) |
| Destroy SIP call structure. | |
| static void | sip_destroy_peer (struct sip_peer *peer) |
| Destroy peer object from memory. | |
| static void | sip_destroy_user (struct sip_user *user) |
| Remove user object from in-memory storage. | |
| static int | sip_devicestate (void *data) |
| Part of PBX channel interface. | |
| static int | sip_do_debug (int fd, int argc, char *argv[]) |
| Turn on SIP debugging (CLI command). | |
| static int | sip_do_debug_deprecated (int fd, int argc, char *argv[]) |
| static int | sip_do_debug_ip (int fd, int argc, char *argv[]) |
| Enable SIP Debugging in CLI. | |
| static int | sip_do_debug_peer (int fd, int argc, char *argv[]) |
| sip_do_debug_peer: Turn on SIP debugging with peer mask | |
| static int | sip_do_history (int fd, int argc, char *argv[]) |
| Enable SIP History logging (CLI). | |
| static int | sip_do_reload (enum channelreloadreason reason) |
| Reload module. | |
| static int | sip_dtmfmode (struct ast_channel *chan, void *data) |
| Set the DTMFmode for an outbound SIP call (application). | |
| static void | sip_dump_history (struct sip_pvt *dialog) |
| Dump SIP history to debug log file at end of lifespan for SIP dialog. | |
| static int | sip_fixup (struct ast_channel *oldchan, struct ast_channel *newchan) |
| sip_fixup: Fix up a channel: If a channel is consumed, this is called. Basically update any ->owner links | |
| static int | sip_get_codec (struct ast_channel *chan) |
| Return SIP UA's codec (part of the RTP interface). | |
| static enum ast_rtp_get_result | sip_get_rtp_peer (struct ast_channel *chan, struct ast_rtp **rtp) |
| Returns null if we can't reinvite audio (part of RTP interface). | |
| static struct ast_udptl * | sip_get_udptl_peer (struct ast_channel *chan) |
| static enum ast_rtp_get_result | sip_get_vrtp_peer (struct ast_channel *chan, struct ast_rtp **rtp) |
| Returns null if we can't reinvite video (part of RTP interface). | |
| static int | sip_handle_t38_reinvite (struct ast_channel *chan, struct sip_pvt *pvt, int reinvite) |
| Handle T38 reinvite. | |
| static int | sip_hangup (struct ast_channel *ast) |
| sip_hangup: Hangup SIP call Part of PBX interface, called from ast_hangup | |
| static int | sip_indicate (struct ast_channel *ast, int condition, const void *data, size_t datalen) |
| Play indication to user With SIP a lot of indications is sent as messages, letting the device play the indication - busy signal, congestion etc. | |
| static const char * | sip_nat_mode (const struct sip_pvt *p) |
| Display SIP nat mode. | |
| static struct ast_channel * | sip_new (struct sip_pvt *i, int state, const char *title) |
| Initiate a call in the SIP channel called from sip_request_call (calls from the pbx ) for outbound channels and from handle_request_invite for inbound channels. | |
| static int | sip_no_debug (int fd, int argc, char *argv[]) |
| Disable SIP Debugging in CLI. | |
| static int | sip_no_debug_deprecated (int fd, int argc, char *argv[]) |
| static int | sip_no_history (int fd, int argc, char *argv[]) |
| Disable SIP History logging (CLI). | |
| static int | sip_notify (int fd, int argc, char *argv[]) |
| Cli command to send SIP notify to peer. | |
| static int | sip_park (struct ast_channel *chan1, struct ast_channel *chan2, struct sip_request *req, int seqno) |
| Park a call using the subsystem in res_features.c This is executed in a separate thread. | |
| static void * | sip_park_thread (void *stuff) |
| Park SIP call support function Starts in a new thread, then parks the call XXX Should we add a wait period after streaming audio and before hangup?? Sometimes the audio can't be heard before hangup. | |
| static void | sip_peer_hold (struct sip_pvt *p, int hold) |
| Change onhold state of a peer using a pvt structure. | |
| static void | sip_poke_all_peers (void) |
| Send a poke to all known peers Space them out 100 ms apart XXX We might have a cool algorithm for this or use random - any suggestions? | |
| 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) |
| 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_prune_realtime (int fd, int argc, char *argv[]) |
| Remove temporary realtime objects from memory (CLI). | |
| static struct ast_frame * | sip_read (struct ast_channel *ast) |
| Read SIP RTP from channel. | |
| static struct sockaddr_in * | sip_real_dst (const struct sip_pvt *p) |
| The real destination address for a write. | |
| static int | sip_refer_allocate (struct sip_pvt *p) |
| Allocate SIP refer structure. | |
| static int | sip_reg_timeout (const void *data) |
| Registration timeout, register again. | |
| static int | sip_register (char *value, int lineno) |
| Parse register=> line in sip.conf and add to registry. | |
| static void | sip_registry_destroy (struct sip_registry *reg) |
| Destroy registry object Objects created with the register= statement in static configuration. | |
| static int | sip_reinvite_retry (const void *data) |
| Reset the NEEDREINVITE flag after waiting when we get 491 on a Re-invite to avoid race conditions between asterisk servers. Called from the scheduler. | |
| static int | sip_reload (int fd, int argc, char *argv[]) |
| Force reload of module from cli. | |
| static struct ast_channel * | sip_request_call (const char *type, int format, void *data, int *cause) |
| PBX interface function -build SIP pvt structure SIP calls initiated by the PBX arrive here. | |
| static int | sip_reregister (const void *data) |
| Update registration with SIP Proxy. | |
| static struct ast_frame * | sip_rtp_read (struct ast_channel *ast, struct sip_pvt *p, int *faxdetect) |
| Read RTP from network. | |
| static void | sip_scheddestroy (struct sip_pvt *p, int ms) |
| Schedule destruction of SIP dialog. | |
| static void | sip_send_all_registers (void) |
| Send all known registrations. | |
| static int | sip_send_mwi_to_peer (struct sip_peer *peer) |
| 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_sendtext (struct ast_channel *ast, const char *text) |
| Send SIP MESSAGE text within a call Called from PBX core sendtext() application. | |
| static int | sip_set_rtp_peer (struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codecs, int nat_active) |
| Set the RTP peer for this call. | |
| static int | sip_set_udptl_peer (struct ast_channel *chan, struct ast_udptl *udptl) |
| static int | sip_show_channel (int fd, int argc, char *argv[]) |
| Show details of one active dialog. | |
| static int | sip_show_channels (int fd, int argc, char *argv[]) |
| Show active SIP channels. | |
| static int | sip_show_domains (int fd, int argc, char *argv[]) |
| CLI command to list local domains. | |
| static int | sip_show_history (int fd, int argc, char *argv[]) |
| Show history details of one dialog. | |
| static int | sip_show_inuse (int fd, int argc, char *argv[]) |
| CLI Command to show calls within limits set by call_limit. | |
| static int | sip_show_objects (int fd, int argc, char *argv[]) |
| List all allocated SIP Objects (realtime or static). | |
| static int | sip_show_peer (int fd, int argc, char *argv[]) |
| Show one peer in detail. | |
| static int | sip_show_peers (int fd, int argc, char *argv[]) |
| CLI Show Peers command. | |
| static int | sip_show_registry (int fd, int argc, char *argv[]) |
| Show SIP Registry (registrations with other SIP proxies. | |
| static int | sip_show_settings (int fd, int argc, char *argv[]) |
| List global settings for the SIP channel. | |
| static int | sip_show_subscriptions (int fd, int argc, char *argv[]) |
| Show active SIP subscriptions. | |
| static int | sip_show_user (int fd, int argc, char *argv[]) |
| Show one user in detail. | |
| static int | sip_show_users (int fd, int argc, char *argv[]) |
| 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 int | sip_transfer (struct ast_channel *ast, const char *dest) |
| Transfer SIP call. | |
| static int | sip_uri_cmp (const char *input1, const char *input2) |
| static int | sip_uri_headers_cmp (const char *input1, const char *input2) |
| helper routine for sip_uri_cmp | |
| static int | sip_uri_params_cmp (const char *input1, const char *input2) |
| helper routine for sip_uri_cmp | |
| 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 socket. | |
| static void | stop_media_flows (struct sip_pvt *p) |
| Immediately stop RTP, VRTP and UDPTL as applicable. | |
| static const char * | subscription_type2str (enum subscriptiontype subtype) |
| Show subscription type in string format. | |
| static int | t38_get_rate (int t38cap) |
| Get Max T.38 Transmission rate from T38 capabilities. | |
| static struct sip_peer * | temp_peer (const char *name) |
| Create temporary peer (used in autocreatepeer mode). | |
| static void | temp_pvt_cleanup (void *) |
| static void | temp_pvt_init (void) |
| A per-thread temporary pvt structure. | |
| static char * | transfermode2str (enum transfermodes mode) |
| Convert transfer mode to text string. | |
| static void | transmit_fake_auth_response (struct sip_pvt *p, struct sip_request *req, int reliable) |
| Send a fake 401 Unauthorized response when the administrator wants to hide the names of local users/peers from fishers. | |
| static int | transmit_info_with_digit (struct sip_pvt *p, const char digit, unsigned int duration) |
| Send SIP INFO dtmf message, see Cisco documentation on cisco.com. | |
| static int | transmit_info_with_vidupdate (struct sip_pvt *p) |
| Send SIP INFO with video update request. | |
| static int | transmit_invite (struct sip_pvt *p, int sipmethod, int sdp, int init) |
| Build REFER/INVITE/OPTIONS 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, char *vmexten) |
| Notify user of messages waiting in voicemail. | |
| 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. | |
| 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. | |
| static int | transmit_reinvite_with_sdp (struct sip_pvt *p) |
| Transmit reinvite with SDP. | |
| static int | transmit_reinvite_with_t38_sdp (struct sip_pvt *p) |
| Transmit reinvite with T38 SDP We reinvite so that the T38 processing can take place. SIP Signalling stays with * in the path. | |
| static int | transmit_request (struct sip_pvt *p, int sipmethod, int seqno, enum xmittype reliable, int newbranch) |
| Transmit generic SIP request returns XMIT_ERROR if transmit failed with a critical error (don't retry). | |
| static int | transmit_request_with_auth (struct sip_pvt *p, int sipmethod, int seqno, enum xmittype reliable, int newbranch) |
| Transmit SIP request, auth added. | |
| static int | transmit_response (struct sip_pvt *p, const char *msg, const struct sip_request *req) |
| Transmit response, no retransmits. | |
| static int | transmit_response_reliable (struct sip_pvt *p, const char *msg, const struct sip_request *req) |
| Transmit response, Make sure you get an ACK This is only used for responses to INVITEs, where we need to make sure we get an ACK. | |
| static int | transmit_response_using_temp (ast_string_field callid, struct sockaddr_in *sin, int useglobal_nat, const int intended_method, const struct sip_request *req, const char *msg) |
| Transmit response, no retransmits, using a temporary pvt structure. | |
| static int | transmit_response_with_allow (struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable) |
| Append Accept header, content length before transmitting response. | |
| static int | transmit_response_with_auth (struct sip_pvt *p, const char *msg, const struct sip_request *req, const char *randdata, enum xmittype reliable, const char *header, int stale) |
| Respond with authorization request. | |
| static int | transmit_response_with_date (struct sip_pvt *p, const char *msg, const struct sip_request *req) |
| Append date and content length before transmitting response. | |
| static int | transmit_response_with_sdp (struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable) |
| Used for 200 OK and 183 early media. | |
| static int | transmit_response_with_t38_sdp (struct sip_pvt *p, char *msg, struct sip_request *req, int retrans) |
| Used for 200 OK and 183 early media. | |
| static int | transmit_response_with_unsupported (struct sip_pvt *p, const char *msg, const struct sip_request *req, const char *unsupported) |
| Transmit response, no retransmits. | |
| static int | transmit_sip_request (struct sip_pvt *p, struct sip_request *req) |
| Transmit SIP request unreliably (only used in sip_notify subsystem). | |
| static int | transmit_state_notify (struct sip_pvt *p, int state, int full, int timeout) |
| Used in the SUBSCRIBE notification subsystem. | |
| static void | try_suggested_sip_codec (struct sip_pvt *p) |
| Try setting codec suggested by the SIP_CODEC channel variable. | |
| static int | unload_module (void) |
| PBX unload module API. | |
| static int | update_call_counter (struct sip_pvt *fup, int event) |
| update_call_counter: Handle call_limit for SIP users Setting a call-limit will cause calls above the limit not to be accepted. | |
| static void | update_peer (struct sip_peer *p, int expiry) |
| Update peer data in database (if used). | |
Variables | |
| static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Session Initiation Protocol (SIP)" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, } |
| static struct in_addr | __ourip |
| static int | allow_external_domains |
| static int | apeerobjs = 0 |
| static char * | app_dtmfmode = "SIPDtmfMode" |
| static char * | app_sipaddheader = "SIPAddHeader" |
| static const struct ast_module_info * | ast_module_info = &__mod_info |
| static struct sip_auth * | authl = NULL |
| static int | autocreatepeer |
| static struct sockaddr_in | bindaddr = { 0, } |
| static struct ast_threadstorage | check_auth_buf = { .once = PTHREAD_ONCE_INIT , .key_init = check_auth_buf_init , } |
| static struct ast_custom_function | checksipdomain_function |
| static struct ast_cli_entry | cli_sip [] |
| static struct ast_cli_entry | cli_sip_debug_deprecated |
| static struct ast_cli_entry | cli_sip_no_debug_deprecated |
| static int | compactheaders |
| static const char | config [] = "sip.conf" |
| static char | debug_usage [] |
| static struct sockaddr_in | debugaddr |
| static char | default_callerid [AST_MAX_EXTENSION] |
| static char | default_context [AST_MAX_CONTEXT] |
| static int | default_expiry = DEFAULT_DEFAULT_EXPIRY |
| static char | default_fromdomain [AST_MAX_EXTENSION] |
| static struct ast_jb_conf | default_jbconf |
| Global jitterbuffer configuration - by default, jb is disabled. | |
| static char | default_language [MAX_LANGUAGE] |
| static int | default_maxcallbitrate |
| static char | default_mohinterpret [MAX_MUSICCLASS] |
| static char | default_mohsuggest [MAX_MUSICCLASS] |
| static char | default_notifymime [AST_MAX_EXTENSION] |
| static struct ast_codec_pref | default_prefs |
| static int | default_qualify |
| static char | default_subscribecontext [AST_MAX_CONTEXT] |
| static char | default_vmexten [AST_MAX_EXTENSION] |
| static char * | descrip_dtmfmode = "SIPDtmfMode(inband|info|rfc2833): Changes the dtmfmode for a SIP call\n" |
| static char * | descrip_sipaddheader |
| static int | dumphistory |
| static int | expiry = DEFAULT_EXPIRY |
| static time_t | externexpire = 0 |
| static char | externhost [MAXHOSTNAMELEN] |
| static struct sockaddr_in | externip |
| static int | externrefresh = 10 |
| static int | global_allowguest |
| static int | global_allowsubscribe |
| static enum transfermodes | global_allowtransfer |
| static int | global_alwaysauthreject |
| static int | global_autoframing |
| static int | global_callevents |
| static int | global_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_GSM | AST_FORMAT_H263 |
| Codecs that we support by default:. | |
| static struct ast_ha * | global_contact_ha = NULL |
| Global list of addresses dynamic peers are not allowed to use. | |
| static int | global_directrtpsetup |
| static int | global_dynamic_exclude_static = 0 |
| static struct ast_flags | global_flags [2] = {{0}} |
| static struct ast_jb_conf | global_jbconf |
| static int | global_limitonpeers |
| static int | global_matchexterniplocally |
| static int | global_mwitime |
| static int | global_notifyhold |
| static int | global_notifyringing |
| static char | global_realm [MAXHOSTNAMELEN] |
| static int | global_reg_timeout |
| static int | global_regattempts_max |
| static char | global_regcontext [AST_MAX_CONTEXT] |
| static int | global_relaxdtmf |
| static int | global_rtautoclear |
| static int | global_rtpholdtimeout |
| static int | global_rtpkeepalive |
| static int | global_rtptimeout |
| static int | global_t1min |
| static int | global_t38_capability = T38FAX_VERSION_0 | T38FAX_RATE_2400 | T38FAX_RATE_4800 | T38FAX_RATE_7200 | T38FAX_RATE_9600 |
| static unsigned int | global_tos_audio |
| static unsigned int | global_tos_sip |
| static unsigned int | global_tos_video |
| static char | global_useragent [AST_MAX_EXTENSION] |
| static char | history_usage [] |
| static struct sip_pvt * | iflist |
| sip_pvt: PVT structures are used for each SIP dialog, ie. a call, a registration, a subscribe | |
| static ast_mutex_t | iflock = ((ast_mutex_t) PTHREAD_MUTEX_INITIALIZER ) |
| Protect the SIP dialog list (of sip_pvt's). | |
| static struct io_context * | io |
| static struct ast_ha * | localaddr |
| static char | mandescr_show_peer [] |
| static char | mandescr_show_peers [] |
| static int | max_expiry = DEFAULT_MAX_EXPIRY |
| static int | min_expiry = DEFAULT_MIN_EXPIRY |
| static pthread_t | monitor_thread = AST_PTHREADT_NULL |
| This is the thread for the monitor which checks for input on the channels which are not currently in use. | |
| static ast_mutex_t | monlock = ((ast_mutex_t) PTHREAD_MUTEX_INITIALIZER ) |
| static ast_mutex_t | netlock = ((ast_mutex_t) PTHREAD_MUTEX_INITIALIZER ) |
| Protect the monitoring thread, so only one process can kill or start it, and not when it's doing something critical. | |
| static char | no_debug_usage [] |
| static char | no_history_usage [] |
| static const char | notify_config [] = "sip_notify.conf" |
| static struct ast_config * | notify_types |
| static char | notify_usage [] |
| static int | ourport |
| static struct sockaddr_in | outboundproxyip |
| static int | pedanticsipchecking |
| static struct ast_peer_list | peerl |
| The peer list: Peers and Friends. | |
| static char | prune_realtime_usage [] |
| static int | recordhistory |
| static struct c_referstatusstring | referstatusstrings [] |
| static struct ast_register_list | regl |
| The register list: Other SIP proxys we register with and place calls to. | |
| static int | regobjs = 0 |
| static int | rpeerobjs = 0 |
| static int | ruserobjs = 0 |
| static struct sched_context * | sched |
| static char | show_channel_usage [] |
| static char | show_channels_usage [] |
| static char | show_domains_usage [] |
| static char | show_history_usage [] |
| static char | show_inuse_usage [] |
| static char | show_objects_usage [] |
| static char | show_peer_usage [] |
| static char | show_peers_usage [] |
| static char | show_reg_usage [] |
| static char | show_settings_usage [] |
| static char | show_subscriptions_usage [] |
| static char | show_user_usage [] |
| static char | show_users_usage [] |
| static struct ast_custom_function | sip_header_function |
| static struct cfsip_methods | sip_methods [] |
| static struct cfsip_options | sip_options [] |
| List of well-known SIP options. If we get this in a require, we should check the list and answer accordingly. | |
| static ast_mutex_t | sip_reload_lock = ((ast_mutex_t) PTHREAD_MUTEX_INITIALIZER ) |
| static char | sip_reload_usage [] |
| static int | sip_reloading = FALSE |
| static enum channelreloadreason | sip_reloadreason |
| static struct ast_rtp_protocol | sip_rtp |
| Interface structure with callbacks used to connect to RTP module. | |
| static struct ast_channel_tech | sip_tech |
| Definition of this channel for PBX channel registration. | |
| static struct ast_channel_tech | sip_tech_info |
| This version of the sip channel tech has no send_digit_begin callback. This is for use with channels using SIP INFO DTMF so that the core knows that the channel doesn't want DTMF BEGIN frames. | |
| 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. | |
| struct ast_custom_function | sippeer_function |
| Structure to declare a dialplan function: SIPPEER. | |
| static int | sipsock = -1 |
| static int * | sipsock_read_id |
| static int | speerobjs = 0 |
| static int | srvlookup |
| static struct cfsubscription_types | subscription_types [] |
| static int | suserobjs = 0 |
| static char * | synopsis_dtmfmode = "Change the dtmfmode for a SIP call" |
| static char * | synopsis_sipaddheader = "Add a SIP header to the outbound call" |
| static struct ast_threadstorage | ts_temp_pvt = { .once = PTHREAD_ONCE_INIT , .key_init = temp_pvt_init , } |
| static struct ast_user_list | userl |
| The user list: Users and friends. | |
See Also: Implementation of RFC 3261 - without S/MIME, TCP and TLS support Configuration file sip.conf
SIP over TLS
Better support of forking
VIA branch tag transaction checking
Transaction support
A new INVITE is sent to handle_request_invite(), that will end up starting a new channel in the PBX, the new channel after that executing in a separate channel thread. This is an incoming "call". When the call is answered, either by a bridged channel or the PBX itself the sip_answer() function is called.
The actual media - Video or Audio - is mostly handled by the RTP subsystem in rtp.c
Definition in file chan_sip.c.
| #define ALLOWED_METHODS "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY" |
SIP Methods we support.
Definition at line 476 of file chan_sip.c.
Referenced by respprep(), transmit_invite(), transmit_notify_with_sipfrag(), transmit_refer(), transmit_reinvite_with_sdp(), and transmit_reinvite_with_t38_sdp().
| #define append_history | ( | p, | |||
| event, | |||||
| fmt, | |||||
| args... | ) | append_history_full(p, "%-15s " fmt, event, ## args) |
Append to SIP dialog history.
Definition at line 1857 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(), handle_request_bye(), handle_request_invite(), handle_request_refer(), handle_request_register(), handle_request_subscribe(), handle_response_invite(), local_attended_transfer(), 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(), sipsock_read(), transmit_register(), transmit_reinvite_with_sdp(), and transmit_response_with_auth().
| #define CALLERID_UNKNOWN "Unknown" |
| #define CAN_CREATE_DIALOG 1 |
| #define CAN_CREATE_DIALOG_UNSUPPORTED_METHOD 2 |
| #define CAN_NOT_CREATE_DIALOG 0 |
Definition at line 368 of file chan_sip.c.
| #define CHECK_AUTH_BUF_INITLEN 256 |
| #define DEC_CALL_LIMIT 0 |
Definition at line 613 of file chan_sip.c.
Referenced by __sip_destroy(), handle_request_cancel(), handle_request_invite(), handle_response_invite(), sip_hangup(), and update_call_counter().
| #define DEC_CALL_RINGING 2 |
Definition at line 615 of file chan_sip.c.
Referenced by handle_response_invite(), and update_call_counter().
| #define DEFAULT_ALLOW_EXT_DOM TRUE |
| #define DEFAULT_ALLOWGUEST TRUE |
| #define DEFAULT_AUTOCREATEPEER FALSE |
| #define DEFAULT_CALLERID "asterisk" |
| #define DEFAULT_COMPACTHEADERS FALSE |
| #define DEFAULT_CONTEXT "default" |
Definition at line 495 of file chan_sip.c.
| #define DEFAULT_DEFAULT_EXPIRY 120 |
| #define DEFAULT_EXPIRY 900 |
Expire slowly
Definition at line 189 of file chan_sip.c.
| #define DEFAULT_FREQ_NOTOK 10 * 1000 |
Qualification: How often to check, if the host is down...
Definition at line 204 of file chan_sip.c.
| #define DEFAULT_FREQ_OK 60 * 1000 |
Qualification: How often to check for the host to be up
Definition at line 203 of file chan_sip.c.
| #define DEFAULT_MAX_CALL_BITRATE (384) |
| #define DEFAULT_MAX_EXPIRY 3600 |
| #define DEFAULT_MAX_FORWARDS "70" |
Definition at line 176 of file chan_sip.c.
Referenced by initreqprep(), reqprep(), and transmit_register().
| #define DEFAULT_MAXMS 2000 |
Qualification: Must be faster than 2 seconds by default
Definition at line 202 of file chan_sip.c.
| #define DEFAULT_MIN_EXPIRY 60 |
| #define DEFAULT_MOHINTERPRET "default" |
| #define DEFAULT_MOHSUGGEST "" |
| #define DEFAULT_MWITIME 10 |
| #define DEFAULT_NOTIFYMIME "application/simple-message-summary" |
| #define DEFAULT_NOTIFYRINGING TRUE |
| #define DEFAULT_PEDANTIC FALSE |
| #define DEFAULT_QUALIFY FALSE |
| #define DEFAULT_REALM "asterisk" |
| #define DEFAULT_REGISTRATION_TIMEOUT 20 |
| #define DEFAULT_RETRANS 1000 |
How frequently to retransmit Default: 2 * 500 ms in RFC 3261
Definition at line 206 of file chan_sip.c.
| #define DEFAULT_SRVLOOKUP TRUE |
| #define DEFAULT_T1MIN 100 |
100 MS for minimal roundtrip time
Definition at line 514 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_TOS_AUDIO 0 |
Audio packets should be marked as DSCP EF (Expedited Forwarding), but the default is 0 to be compatible with previous versions.
Definition at line 506 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_TOS_SIP 0 |
Call signalling packets should be marked as DSCP CS3, but the default is 0 to be compatible with previous versions.
Definition at line 505 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_TOS_VIDEO 0 |
Video packets should be marked as DSCP AF41, but the default is 0 to be compatible with previous versions.
Definition at line 507 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_TRANS_TIMEOUT -1 |
Definition at line 211 of file chan_sip.c.
Referenced by __sip_autodestruct(), cb_extensionstate(), check_auth(), check_pendings(), handle_invite_replaces(), handle_request(), handle_request_bye(), handle_request_cancel(), handle_request_info(), handle_request_invite(), handle_request_notify(), handle_request_options(), handle_request_register(), handle_response_invite(), handle_response_register(), receive_message(), sip_hangup(), sip_notify(), and sip_send_mwi_to_peer().
| #define DEFAULT_USERAGENT "Asterisk PBX" |
Default Useragent: header unless re-defined in sip.conf
Definition at line 517 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_VMEXTEN "asterisk" |
| #define EXPIRY_GUARD_LIMIT 30 |
Below here, we use EXPIRY_GUARD_PCT instead of EXPIRY_GUARD_SECS
Definition at line 181 of file chan_sip.c.
Referenced by handle_response_register().
| #define EXPIRY_GUARD_MIN 500 |
This is the minimum guard time applied. If GUARD_PCT turns out to be lower than this, it will use this time instead. This is in milliseconds.
Definition at line 183 of file chan_sip.c.
Referenced by handle_response_register().
| #define EXPIRY_GUARD_PCT 0.20 |
Percentage of expires timeout to use when below EXPIRY_GUARD_LIMIT
Definition at line 187 of file chan_sip.c.
Referenced by handle_response_register().
| #define EXPIRY_GUARD_SECS 15 |
How long before expiry do we reregister
Definition at line 180 of file chan_sip.c.
Referenced by handle_response_register().
| #define FALSE 0 |
Definition at line 154 of file chan_sip.c.
| #define FLAG_FATAL (1 << 1) |
| #define FLAG_RESPONSE (1 << 0) |
Definition at line 1033 of file chan_sip.c.
Referenced by __sip_ack(), __sip_pretend_ack(), __sip_reliable_xmit(), __sip_semi_ack(), handle_request(), and retrans_pkt().
| #define FORMAT "%-15.15s %-10.10s %-11.11s %5.5d/%5.5d %-15.15s %-3.3s %-3.3s %-15.15s %-10.10s\n" |
| #define FORMAT "%-30.30s %-12.12s %8d %-20.20s %-25.25s\n" |
| #define FORMAT "%-40.40s %-20.20s %-16.16s\n" |
| #define FORMAT "%-25.25s %-15.15s %-3.3s %-3.3s %-3.3s %-8d %-10s %-10s\n" |
| #define FORMAT "%-25.25s %-15.15s %-15.15s %-15.15s %-5.5s%-10.10s\n" |
| #define FORMAT "%-25.25s %-15.15s %-15.15s \n" |
| #define FORMAT2 "%-15.15s %-10.10s %-11.11s %-11.11s %-15.15s %-7.7s %-15.15s\n" |
| #define FORMAT2 "%-30.30s %-12.12s %8.8s %-20.20s %-25.25s\n" |
| #define FORMAT2 "%-25.25s %-15.15s %-3.3s %-3.3s %-3.3s %-8s %-10s %-10s\n" |
| #define FORMAT2 "%-25.25s %-15.15s %-15.15s \n" |
| #define FORMAT3 "%-15.15s %-10.10s %-11.11s %-15.15s %-13.13s %-15.15s %-10.10s\n" |
Referenced by __sip_show_channels().
| #define INC_CALL_LIMIT 1 |
Definition at line 614 of file chan_sip.c.
Referenced by handle_request_invite(), sip_hangup(), and update_call_counter().
| #define INC_CALL_RINGING 3 |
| #define INITIAL_CSEQ 101 |
our initial sip sequence number
Definition at line 220 of file chan_sip.c.
Referenced by sip_alloc(), sip_register(), and transmit_response_using_temp().
| #define IPTOS_MINCOST 0x02 |
Definition at line 167 of file chan_sip.c.
| #define MAX | ( | a, | |||
| b | ) | ((a) > (b) ? (a) : (b)) |
Definition at line 197 of file chan_sip.c.
| #define MAX_AUTHTRIES 3 |
Try authentication three times, then fail
Definition at line 212 of file chan_sip.c.
Referenced by handle_response(), handle_response_invite(), and handle_response_register().
| #define MAX_HISTORY_ENTRIES 50 |
Max entires in the history list for a sip_pvt
Definition at line 1031 of file chan_sip.c.
Referenced by append_history_va().
| #define MAX_RETRANS 6 |
Try only 6 times for retransmissions, a total of 7 transmissions
Definition at line 207 of file chan_sip.c.
| #define NO_RTP 0 |
Definition at line 236 of file chan_sip.c.
| #define NOT_SUPPORTED 0 |
Definition at line 409 of file chan_sip.c.
| #define RTP 1 |
Definition at line 235 of file chan_sip.c.
| #define SDP_MAX_RTPMAP_CODECS 32 |
Maximum number of codecs allowed in received SDP
Definition at line 218 of file chan_sip.c.
Referenced by process_sdp().
| #define SDP_SAMPLE_RATE | ( | x | ) | 8000 |
Definition at line 6519 of file chan_sip.c.
Referenced by add_sdp().
| #define SIP_ALREADYGONE (1 << 0) |
Whether or not we've already been destroyed by our peer
Definition at line 720 of file chan_sip.c.
Referenced by __sip_autodestruct(), handle_request(), handle_response_invite(), sip_alreadygone(), sip_hangup(), and sip_set_rtp_peer().
| #define SIP_CALL_LIMIT (1 << 28) |
Call limit enforced for this call
Definition at line 761 of file chan_sip.c.
Referenced by check_user_full(), create_addr_from_peer(), and update_call_counter().
| #define SIP_CAN_REINVITE (1 << 20) |
allow peers to be reinvited to send media directly p2p
Definition at line 749 of file chan_sip.c.
Referenced by _sip_show_peer(), handle_common_options(), reload_config(), sip_get_rtp_peer(), sip_get_udptl_peer(), sip_get_vrtp_peer(), and sip_handle_t38_reinvite().
| #define SIP_CAN_REINVITE_NAT (2 << 20) |
allow media reinvite when new peer is behind NAT
Definition at line 750 of file chan_sip.c.
Referenced by handle_common_options(), sip_get_rtp_peer(), and sip_set_rtp_peer().
| #define SIP_DEFER_BYE_ON_TRANSFER (1 << 15) |
Do not hangup at first ast_hangup
Definition at line 735 of file chan_sip.c.
Referenced by handle_invite_replaces(), handle_request_refer(), local_attended_transfer(), sip_hangup(), and sip_set_rtp_peer().
| #define SIP_DTMF (3 << 16) |
DTMF Support: four settings, uses two bits
Definition at line 736 of file chan_sip.c.
Referenced by _sip_show_peer(), check_user_full(), create_addr_from_peer(), handle_common_options(), handle_request_invite(), process_sdp(), sip_alloc(), sip_dtmfmode(), sip_new(), sip_rtp_read(), sip_senddigit_begin(), sip_senddigit_end(), sip_show_channel(), and sip_show_settings().
| #define SIP_DTMF_AUTO (3 << 16) |
DTMF Support: AUTO switch between rfc2833 and in-band DTMF
Definition at line 740 of file chan_sip.c.
Referenced by check_user_full(), create_addr_from_peer(), dtmfmode2str(), handle_common_options(), process_sdp(), and sip_alloc().
| #define SIP_DTMF_INBAND (1 << 16) |
DTMF Support: Inband audio, only for ULAW/ALAW - "inband"
Definition at line 738 of file chan_sip.c.
Referenced by dtmfmode2str(), handle_common_options(), process_sdp(), sip_dtmfmode(), sip_new(), sip_rtp_read(), sip_senddigit_begin(), and sip_senddigit_end().
| #define SIP_DTMF_INFO (2 << 16) |
DTMF Support: SIP Info messages - "info"
Definition at line 739 of file chan_sip.c.
Referenced by dtmfmode2str(), handle_common_options(), sip_dtmfmode(), sip_new(), and sip_senddigit_end().
| #define SIP_DTMF_RFC2833 (0 << 16) |
DTMF Support: RTP DTMF - "rfc2833"
Definition at line 737 of file chan_sip.c.
Referenced by check_user_full(), create_addr_from_peer(), dtmfmode2str(), handle_common_options(), handle_request_invite(), process_sdp(), reload_config(), sip_alloc(), sip_dtmfmode(), sip_rtp_read(), sip_senddigit_begin(), and sip_senddigit_end().
| #define SIP_FLAGS_TO_COPY |
Value:
(SIP_PROMISCREDIR | SIP_TRUSTRPID | SIP_SENDRPID | SIP_DTMF | SIP_REINVITE | \ SIP_PROG_INBAND | SIP_USECLIENTCODE | SIP_NAT | SIP_G726_NONSTANDARD | \ SIP_USEREQPHONE | SIP_INSECURE_PORT | SIP_INSECURE_INVITE)
Definition at line 766 of file chan_sip.c.
Referenced by build_user(), check_user_full(), create_addr_from_peer(), set_peer_defaults(), sip_alloc(), and sip_poke_peer().
| #define SIP_FREE_BIT (1 << 14) |
----
Definition at line 734 of file chan_sip.c.
| #define SIP_G726_NONSTANDARD (1 << 31) |
Use non-standard packing for G726-32 data
Definition at line 764 of file chan_sip.c.
Referenced by add_codec_to_sdp(), handle_common_options(), and process_sdp().
| #define SIP_GOTREFER (1 << 7) |
Got a refer?
Definition at line 727 of file chan_sip.c.
Referenced by handle_request_refer(), local_attended_transfer(), sip_handle_t38_reinvite(), sip_read(), sip_set_rtp_peer(), and sip_set_udptl_peer().
| #define SIP_INC_COUNT (1 << 30) |
Did this connection increment the counter of in-use calls?
Definition at line 763 of file chan_sip.c.
Referenced by __sip_destroy(), handle_request_cancel(), sip_hangup(), and update_call_counter().
| #define SIP_INSECURE_INVITE (1 << 24) |
don't require authentication for incoming INVITEs
Definition at line 754 of file chan_sip.c.
Referenced by _sip_show_peer(), check_user_full(), handle_common_options(), and set_insecure_flags().
| #define SIP_INSECURE_PORT (1 << 23) |
don't require matching port for incoming requests
Definition at line 753 of file chan_sip.c.
Referenced by _sip_show_peer(), handle_common_options(), realtime_peer(), set_insecure_flags(), and sip_addrcmp().
| #define SIP_MAX_HEADERS 64 |
Max amount of SIP headers to read
Definition at line 214 of file chan_sip.c.
Referenced by add_header(), and parse_request().
| #define SIP_MAX_LINES 64 |
Max amount of lines in SIP attachment (like SDP)
Definition at line 215 of file chan_sip.c.
Referenced by add_line(), and parse_request().
| #define SIP_MAX_PACKET 4096 |
Also from RFC 3261 (2543), should sub headers tho
Definition at line 216 of file chan_sip.c.
| #define SIP_NAT (3 << 18) |
four settings, uses two bits
Definition at line 742 of file chan_sip.c.
Referenced by _sip_show_peer(), build_via(), copy_via_headers(), create_addr_from_peer(), handle_common_options(), process_sdp(), register_verify(), sip_alloc(), sip_nat_mode(), sip_real_dst(), sip_show_channel(), sip_show_settings(), sip_show_users(), and transmit_response_using_temp().
| #define SIP_NAT_ALWAYS (3 << 18) |
NAT Both ROUTE and RFC3581
Definition at line 746 of file chan_sip.c.
Referenced by copy_via_headers(), handle_common_options(), and nat2str().
| #define SIP_NAT_NEVER (0 << 18) |
No nat support
Definition at line 743 of file chan_sip.c.
Referenced by handle_common_options(), and nat2str().
| #define SIP_NAT_RFC3581 (1 << 18) |
NAT RFC3581
Definition at line 744 of file chan_sip.c.
Referenced by build_via(), copy_via_headers(), handle_common_options(), nat2str(), and reload_config().
| #define SIP_NAT_ROUTE (2 << 18) |
NAT Only ROUTE
Definition at line 745 of file chan_sip.c.
Referenced by _sip_show_peers(), check_user_full(), check_via(), create_addr_from_peer(), handle_common_options(), nat2str(), parse_register_contact(), send_request(), set_address_from_contact(), sip_alloc(), sip_nat_mode(), sip_real_dst(), and transmit_response_using_temp().
| #define SIP_NEEDDESTROY (1 << 1) |
if we need to be destroyed by the monitor thread
Definition at line 721 of file chan_sip.c.
Referenced by __sip_autodestruct(), __sip_show_channels(), do_monitor(), handle_request(), handle_request_refer(), handle_request_subscribe(), handle_response(), handle_response_invite(), handle_response_peerpoke(), handle_response_refer(), handle_response_register(), retrans_pkt(), sip_hangup(), sip_reg_timeout(), and sip_show_channel().
| #define SIP_NEEDREINVITE (1 << 5) |
Do we need to send another reinvite?
Definition at line 725 of file chan_sip.c.
Referenced by check_pendings(), sip_handle_t38_reinvite(), sip_hangup(), sip_read(), sip_reinvite_retry(), sip_set_rtp_peer(), and sip_set_udptl_peer().
| #define SIP_NO_HISTORY (1 << 27) |
Suppress recording request/response history
Definition at line 760 of file chan_sip.c.
Referenced by append_history_full(), do_register_auth(), handle_request_bye(), handle_request_invite(), send_request(), send_response(), sip_alloc(), sip_hangup(), sip_new(), sip_reregister(), sip_scheddestroy(), sip_set_rtp_peer(), sipsock_read(), transmit_register(), transmit_reinvite_with_sdp(), and transmit_response_using_temp().
| #define SIP_NOVIDEO (1 << 2) |
Didn't get video in invite, don't offer
Definition at line 722 of file chan_sip.c.
Referenced by add_sdp(), process_sdp(), and sip_indicate().
| #define SIP_OPT_100REL (1 << 1) |
Definition at line 412 of file chan_sip.c.
| #define SIP_OPT_EARLY_SESSION (1 << 3) |
Definition at line 414 of file chan_sip.c.
| #define SIP_OPT_EVENTLIST (1 << 11) |
Definition at line 422 of file chan_sip.c.
| #define SIP_OPT_GRUU (1 << 12) |
Definition at line 423 of file chan_sip.c.
| #define SIP_OPT_HISTINFO (1 << 15) |
Definition at line 426 of file chan_sip.c.
| #define SIP_OPT_JOIN (1 << 4) |
Definition at line 415 of file chan_sip.c.
| #define SIP_OPT_NOREFERSUB (1 << 14) |
Definition at line 425 of file chan_sip.c.
| #define SIP_OPT_PATH (1 << 5) |
Definition at line 416 of file chan_sip.c.
| #define SIP_OPT_PRECONDITION (1 << 7) |
Definition at line 418 of file chan_sip.c.
| #define SIP_OPT_PREF (1 << 6) |
Definition at line 417 of file chan_sip.c.
| #define SIP_OPT_PRIVACY (1 << 8) |
Definition at line 419 of file chan_sip.c.
| #define SIP_OPT_REPLACES (1 << 0) |
| #define SIP_OPT_RESPRIORITY (1 << 16) |
Definition at line 427 of file chan_sip.c.
| #define SIP_OPT_SDP_ANAT (1 << 9) |
Definition at line 420 of file chan_sip.c.
| #define SIP_OPT_SEC_AGREE (1 << 10) |
Definition at line 421 of file chan_sip.c.
| #define SIP_OPT_TARGET_DIALOG (1 << 13) |
Definition at line 424 of file chan_sip.c.
| #define SIP_OPT_TIMER (1 << 2) |
Definition at line 413 of file chan_sip.c.
| #define SIP_OUTGOING (1 << 13) |
Direction of the last transaction in this dialog
Definition at line 733 of file chan_sip.c.
Referenced by handle_request_bye(), handle_request_invite(), handle_request_refer(), handle_response(), handle_response_invite(), reqprep(), respprep(), sip_call(), sip_hangup(), sip_indicate(), sip_poke_peer(), sip_send_mwi_to_peer(), sip_show_channel(), sip_write(), transmit_refer(), transmit_register(), transmit_reinvite_with_sdp(), transmit_reinvite_with_t38_sdp(), and transmit_response_with_sdp().
| #define SIP_PAGE2_ALLOWOVERLAP (1 << 17) |
Allow overlap dialing ?
Definition at line 788 of file chan_sip.c.
Referenced by _sip_show_peer(), get_destination(), handle_common_options(), handle_request_invite(), reload_config(), and sip_show_settings().
| #define SIP_PAGE2_ALLOWSUBSCRIBE (1 << 16) |
Allow subscriptions from this peer?
Definition at line 787 of file chan_sip.c.
Referenced by _sip_show_peer(), build_peer(), build_user(), handle_common_options(), handle_request_subscribe(), reload_config(), and sip_show_settings().
| #define SIP_PAGE2_BUGGY_MWI (1 << 26) |
26: Buggy CISCO MWI fix
Definition at line 800 of file chan_sip.c.
Referenced by handle_common_options(), and transmit_notify_with_mwi().
| #define SIP_PAGE2_CALL_ONHOLD (3 << 23) |
Call states
Definition at line 795 of file chan_sip.c.
Referenced by __sip_destroy(), __sip_show_channels(), add_sdp(), change_hold_state(), handle_request_cancel(), handle_request_invite(), process_sdp(), sip_hangup(), and update_call_counter().
| #define SIP_PAGE2_CALL_ONHOLD_ACTIVE (1 << 23) |
| #define SIP_PAGE2_CALL_ONHOLD_INACTIVE (3 << 23) |
23: Inactive hold
Definition at line 798 of file chan_sip.c.
Referenced by add_sdp(), and change_hold_state().
| #define SIP_PAGE2_CALL_ONHOLD_ONEDIR (2 << 23) |
23: One directional hold
Definition at line 797 of file chan_sip.c.
Referenced by add_sdp(), and change_hold_state().
| #define SIP_PAGE2_DEBUG (3 << 11) |
Definition at line 781 of file chan_sip.c.
| #define SIP_PAGE2_DEBUG_CONFIG (1 << 11) |
| #define SIP_PAGE2_DEBUG_CONSOLE (1 << 12) |
Definition at line 783 of file chan_sip.c.
Referenced by reload_config(), sip_do_debug(), sip_do_debug_deprecated(), sip_do_debug_ip(), sip_do_debug_peer(), sip_no_debug(), and sip_no_debug_deprecated().
| #define SIP_PAGE2_DIALOG_ESTABLISHED (1 << 29) |
29: Has a dialog been established?
Definition at line 803 of file chan_sip.c.
Referenced by find_call(), handle_request_bye(), handle_request_invite(), handle_request_subscribe(), handle_response(), handle_response_invite(), and sip_answer().
| #define SIP_PAGE2_DYNAMIC (1 << 13) |
Dynamic Peers register with Asterisk
Definition at line 784 of file chan_sip.c.
Referenced by _sip_show_peer(), _sip_show_peers(), build_peer(), function_sippeer(), register_verify(), and temp_peer().
| #define SIP_PAGE2_FLAGS_TO_COPY |
Value:
(SIP_PAGE2_ALLOWSUBSCRIBE | SIP_PAGE2_ALLOWOVERLAP | SIP_PAGE2_VIDEOSUPPORT | \ SIP_PAGE2_T38SUPPORT | SIP_PAGE2_RFC2833_COMPENSATE | SIP_PAGE2_BUGGY_MWI | SIP_PAGE2_UDPTL_DESTINATION)
Definition at line 805 of file chan_sip.c.
Referenced by build_user(), check_user_full(), create_addr_from_peer(), set_peer_defaults(), sip_alloc(), and sip_poke_peer().
| #define SIP_PAGE2_IGNOREREGEXPIRE (1 << 10) |
Definition at line 780 of file chan_sip.c.
Referenced by build_peer(), destroy_association(), reload_config(), and sip_show_settings().
| #define SIP_PAGE2_INC_RINGING (1 << 19) |
Did this connection increment the counter of in-use calls?
Definition at line 790 of file chan_sip.c.
Referenced by update_call_counter().
| #define SIP_PAGE2_OUTGOING_CALL (1 << 27) |
27: Is this an outgoing call?
Definition at line 801 of file chan_sip.c.
Referenced by get_sip_pvt_byid_locked(), sip_request_call(), and update_call_counter().
| #define SIP_PAGE2_RFC2833_COMPENSATE (1 << 25) |
25: ????
Definition at line 799 of file chan_sip.c.
Referenced by create_addr_from_peer(), handle_common_options(), handle_request_invite(), process_sdp(), sip_alloc(), and sip_show_settings().
| #define SIP_PAGE2_RT_FROMCONTACT (1 << 4) |
Definition at line 776 of file chan_sip.c.
Referenced by build_peer(), destroy_association(), parse_register_contact(), and reg_source_db().
| #define SIP_PAGE2_RTAUTOCLEAR (1 << 2) |
Definition at line 775 of file chan_sip.c.
Referenced by expire_register(), realtime_peer(), and reload_config().
| #define SIP_PAGE2_RTCACHEFRIENDS (1 << 0) |
Definition at line 773 of file chan_sip.c.
Referenced by build_peer(), complete_sip_prune_realtime_peer(), complete_sip_prune_realtime_user(), parse_register_contact(), realtime_peer(), realtime_user(), reload_config(), sip_prune_realtime(), sip_show_settings(), update_call_counter(), and update_peer().
| #define SIP_PAGE2_RTSAVE_SYSNAME (1 << 5) |
Definition at line 777 of file chan_sip.c.
Referenced by realtime_update_peer(), reload_config(), and sip_show_settings().
| #define SIP_PAGE2_RTUPDATE (1 << 1) |
Definition at line 774 of file chan_sip.c.
Referenced by reload_config(), sip_show_settings(), and update_peer().
| #define SIP_PAGE2_SELFDESTRUCT (1 << 14) |
Automatic peers need to destruct themselves
Definition at line 785 of file chan_sip.c.
Referenced by expire_register(), sip_destroy_peer(), and temp_peer().
| #define SIP_PAGE2_STATECHANGEQUEUE (1 << 9) |
D: Unsent state pending change exists
Definition at line 779 of file chan_sip.c.
Referenced by cb_extensionstate(), and handle_response().
| #define SIP_PAGE2_SUBSCRIBEMWIONLY (1 << 18) |
Only issue MWI notification if subscribed to
Definition at line 789 of file chan_sip.c.
Referenced by build_peer(), does_peer_need_mwi(), and register_verify().
| #define SIP_PAGE2_T38SUPPORT (7 << 20) |
T38 Fax Passthrough Support
Definition at line 791 of file chan_sip.c.
Referenced by create_addr_from_peer(), and sip_alloc().
| #define SIP_PAGE2_T38SUPPORT_RTP (2 << 20) |
21: T38 Fax Passthrough Support (not implemented)
Definition at line 793 of file chan_sip.c.
Referenced by _sip_show_peer(), add_sdp(), handle_common_options(), and sip_show_settings().
| #define SIP_PAGE2_T38SUPPORT_TCP (4 << 20) |
22: T38 Fax Passthrough Support (not implemented)
Definition at line 794 of file chan_sip.c.
Referenced by _sip_show_peer(), handle_common_options(), and sip_show_settings().
| #define SIP_PAGE2_T38SUPPORT_UDPTL (1 << 20) |
20: T38 Fax Passthrough Support
Definition at line 792 of file chan_sip.c.
Referenced by _sip_show_peer(), handle_common_options(), sip_read(), sip_rtp_read(), and sip_show_settings().
| #define SIP_PAGE2_UDPTL_DESTINATION (1 << 28) |
28: Use source IP of RTP as destination if NAT is enabled
Definition at line 802 of file chan_sip.c.
Referenced by handle_common_options(), and process_sdp().
| #define SIP_PAGE2_VIDEOSUPPORT (1 << 15) |
Definition at line 786 of file chan_sip.c.
Referenced by _sip_show_peer(), _sip_show_peers(), check_user_full(), create_addr_from_peer(), handle_common_options(), reload_config(), sip_alloc(), and sip_show_settings().
| #define SIP_PENDINGBYE (1 << 6) |
Need to send bye after we ack?
Definition at line 726 of file chan_sip.c.
Referenced by check_pendings(), handle_response_invite(), sip_handle_t38_reinvite(), sip_hangup(), sip_read(), sip_set_rtp_peer(), and sip_set_udptl_peer().
| #define SIP_PKT_DEBUG (1 << 0) |
Debug this packet
Definition at line 810 of file chan_sip.c.
Referenced by handle_request(), handle_request_message(), handle_request_refer(), handle_request_register(), handle_request_subscribe(), handle_response(), initialize_initreq(), and sipsock_read().
| #define SIP_PKT_IGNORE (1 << 2) |
This is a re-transmit, ignore it
Definition at line 812 of file chan_sip.c.
Referenced by check_auth(), check_user_full(), handle_request(), handle_request_bye(), handle_request_invite(), handle_request_message(), handle_request_refer(), handle_request_subscribe(), handle_response(), handle_response_invite(), and register_verify().
| #define SIP_PKT_IGNORE_REQ (1 << 4) |
| #define SIP_PKT_IGNORE_RESP (1 << 3) |
| #define SIP_PKT_WITH_TOTAG (1 << 1) |
This packet has a to-tag
Definition at line 811 of file chan_sip.c.
Referenced by find_call(), and handle_request().
| #define SIP_PROG_INBAND (3 << 25) |
three settings, uses two bits
Definition at line 756 of file chan_sip.c.
Referenced by handle_common_options(), sip_indicate(), and sip_show_settings().
| #define SIP_PROG_INBAND_NEVER (0 << 25) |
| #define SIP_PROG_INBAND_NO (1 << 25) |
Definition at line 758 of file chan_sip.c.
Referenced by handle_common_options(), and sip_show_settings().
| #define SIP_PROG_INBAND_YES (2 << 25) |
Definition at line 759 of file chan_sip.c.
Referenced by handle_common_options(), and sip_indicate().
| #define SIP_PROGRESS_SENT (1 << 4) |
Have sent 183 message progress
Definition at line 724 of file chan_sip.c.
Referenced by sip_indicate(), and sip_write().
| #define SIP_PROMISCREDIR (1 << 8) |
Promiscuous redirection
Definition at line 728 of file chan_sip.c.
Referenced by _sip_show_peer(), handle_common_options(), parse_moved_contact(), sip_show_channel(), and sip_show_settings().
| #define SIP_REALTIME (1 << 11) |
Flag for realtime users
Definition at line 731 of file chan_sip.c.
Referenced by _sip_show_peer(), _sip_show_peers(), build_peer(), parse_register_contact(), realtime_peer(), realtime_user(), sip_destroy_peer(), sip_destroy_user(), update_call_counter(), and update_peer().
| #define SIP_REINVITE (7 << 20) |
| #define SIP_REINVITE_UPDATE (4 << 20) |
use UPDATE (RFC3311) when reinviting this peer
Definition at line 751 of file chan_sip.c.
Referenced by handle_common_options(), transmit_reinvite_with_sdp(), and transmit_reinvite_with_t38_sdp().
| #define SIP_RINGING (1 << 3) |
| #define SIP_SENDRPID (1 << 29) |
Remote Party-ID Support
Definition at line 762 of file chan_sip.c.
Referenced by _sip_show_peer(), handle_common_options(), and initreqprep().
| #define SIP_TRANS_TIMEOUT 32000 |
SIP request timeout (rfc 3261) 64*T1
Definition at line 208 of file chan_sip.c.
Referenced by sip_call(), and sip_sipredirect().
| #define SIP_TRUSTRPID (1 << 9) |
Trust RPID headers?
Definition at line 729 of file chan_sip.c.
Referenced by _sip_show_peer(), check_user_full(), and handle_common_options().
| #define SIP_USECLIENTCODE (1 << 12) |
Trust X-ClientCode info message
Definition at line 732 of file chan_sip.c.
Referenced by handle_common_options(), handle_request_info(), and sip_show_settings().
| #define SIP_USEREQPHONE (1 << 10) |
Add user=phone to numeric URI. Default off
Definition at line 730 of file chan_sip.c.
Referenced by _sip_show_peer(), build_peer(), initreqprep(), reload_config(), and sip_show_settings().
| #define SIPBUFSIZE 512 |
Definition at line 161 of file chan_sip.c.
Referenced by __sip_show_channels(), add_route(), add_sdp(), extract_uri(), handle_request_refer(), initreqprep(), parse_moved_contact(), parse_ok_contact(), parse_register_contact(), process_sdp(), respprep(), sip_call(), sip_new(), sip_show_channel(), sip_show_settings(), transmit_invite(), and transmit_notify_with_sipfrag().
| #define sipdebug ast_test_flag(&global_flags[1], SIP_PAGE2_DEBUG) |
Definition at line 842 of file chan_sip.c.
Referenced by __sip_ack(), __sip_reliable_xmit(), __sip_semi_ack(), add_sip_domain(), build_reply_digest(), check_auth(), handle_request_info(), handle_request_invite(), handle_request_notify(), handle_request_refer(), handle_request_subscribe(), handle_response(), handle_response_register(), local_attended_transfer(), parse_request(), parse_sip_options(), reqprep(), retrans_pkt(), sip_addheader(), sip_call(), sip_debug_test_addr(), sip_debug_test_pvt(), sip_dump_history(), sip_hangup(), sip_poke_peer(), sip_reregister(), transmit_invite(), transmit_refer(), transmit_register(), transmit_reinvite_with_sdp(), transmit_reinvite_with_t38_sdp(), and update_call_counter().
| #define sipdebug_config ast_test_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONFIG) |
Definition at line 843 of file chan_sip.c.
| #define sipdebug_console ast_test_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONSOLE) |
Definition at line 844 of file chan_sip.c.
Referenced by sip_do_debug(), and sip_do_debug_deprecated().
| #define STANDARD_SIP_PORT 5060 |
Standard SIP port from RFC 3261. DO NOT CHANGE THIS.
Definition at line 482 of file chan_sip.c.
Referenced by __set_address_from_contact(), build_contact(), build_peer(), check_via(), create_addr(), initreqprep(), parse_register_contact(), reload_config(), set_destination(), set_peer_defaults(), sip_show_registry(), and transmit_register().
| #define SUPPORTED 1 |
Define SIP option tags, used in Require: and Supported: headers We need to be aware of these properties in the phones to use the replace: header. We should not do that without knowing that the other end supports it... This is nothing we can configure, we learn by the dialog Supported: header on the REGISTER (peer) or the INVITE (other devices) We are not using many of these today, but will in the future. This is documented in RFC 3261
Definition at line 408 of file chan_sip.c.
| #define SUPPORTED_EXTENSIONS "replaces" |
SIP Extensions we support.
Definition at line 479 of file chan_sip.c.
Referenced by respprep(), transmit_invite(), transmit_notify_with_sipfrag(), transmit_refer(), transmit_reinvite_with_sdp(), and transmit_reinvite_with_t38_sdp().
| #define T38FAX_FILL_BIT_REMOVAL (1 << 0) |
Default: 0 (unset)
Definition at line 817 of file chan_sip.c.
Referenced by add_t38_sdp(), and process_sdp().
| #define T38FAX_RATE_12000 (1 << 12) |
12000 bps t38FaxRate
Definition at line 836 of file chan_sip.c.
Referenced by process_sdp(), and t38_get_rate().
| #define T38FAX_RATE_14400 (1 << 13) |
14400 bps t38FaxRate This is default: NO MMR and JBIG trancoding, NO fill bit removal, transferredTCF TCF, UDP FEC, Version 0 and 9600 max fax rate
Definition at line 837 of file chan_sip.c.
Referenced by process_sdp(), and t38_get_rate().
| #define T38FAX_RATE_2400 (1 << 8) |
2400 bps t38FaxRate
Definition at line 832 of file chan_sip.c.
Referenced by process_sdp(), and t38_get_rate().
| #define T38FAX_RATE_4800 (1 << 9) |
4800 bps t38FaxRate
Definition at line 833 of file chan_sip.c.
Referenced by process_sdp(), and t38_get_rate().
| #define T38FAX_RATE_7200 (1 << 10) |
7200 bps t38FaxRate
Definition at line 834 of file chan_sip.c.
Referenced by process_sdp(), and t38_get_rate().
| #define T38FAX_RATE_9600 (1 << 11) |
9600 bps t38FaxRate
Definition at line 835 of file chan_sip.c.
Referenced by process_sdp(), and t38_get_rate().
| #define T38FAX_RATE_MANAGEMENT_LOCAL_TCF (1 << 3) |
Unset for transferredTCF (UDPTL), set for localTCF (TPKT)
Definition at line 822 of file chan_sip.c.
Referenced by add_t38_sdp(), and process_sdp().
| #define T38FAX_RATE_MANAGEMENT_TRANSFERED_TCF (0 << 3) |
Definition at line 821 of file chan_sip.c.
Referenced by create_addr_from_peer(), process_sdp(), and sip_alloc().
| #define T38FAX_TRANSCODING_JBIG (1 << 2) |
Default: 0 (unset)
Definition at line 819 of file chan_sip.c.
Referenced by add_t38_sdp(), and process_sdp().
| #define T38FAX_TRANSCODING_MMR (1 << 1) |
Default: 0 (unset)
Definition at line 818 of file chan_sip.c.
Referenced by add_t38_sdp(), and process_sdp().
| #define T38FAX_UDP_EC_FEC (1 << 4) |
Set for t38UDPFEC
Definition at line 825 of file chan_sip.c.
Referenced by create_addr_from_peer(), process_sdp(), and sip_alloc().
| #define T38FAX_UDP_EC_NONE (0 << 4) |
two bits, if unset NO t38UDPEC field in T38 SDP
Definition at line 824 of file chan_sip.c.
Referenced by add_t38_sdp(), create_addr_from_peer(), process_sdp(), and sip_alloc().
| #define T38FAX_UDP_EC_REDUNDANCY (2 << 4) |
Set for t38UDPRedundancy
Definition at line 826 of file chan_sip.c.
Referenced by add_t38_sdp(), create_addr_from_peer(), process_sdp(), and sip_alloc().
| #define T38FAX_VERSION (3 << 6) |
two bits, 2 values so far, up to 4 values max
Definition at line 828 of file chan_sip.c.
Referenced by add_t38_sdp().
| #define T38FAX_VERSION_0 (0 << 6) |
Version 0
Definition at line 829 of file chan_sip.c.
Referenced by add_t38_sdp(), and process_sdp().
| #define T38FAX_VERSION_1 (1 << 6) |
Version 1
Definition at line 830 of file chan_sip.c.
Referenced by add_t38_sdp(), and process_sdp().
| #define TRUE 1 |
Definition at line 158 of file chan_sip.c.
| #define UNLINK | ( | element, | |||
| head, | |||||
| prev | ) |
--- some list management macros.
Definition at line 1617 of file chan_sip.c.
Referenced by __sip_ack(), and __sip_destroy().
| #define VIDEO_CODEC_MASK 0x1fc0000 |
Video codecs from H.261 thru AST_FORMAT_MAX_VIDEO
Definition at line 165 of file chan_sip.c.
| #define XMIT_ERROR -2 |
Definition at line 163 of file chan_sip.c.
Referenced by __sip_reliable_xmit(), __sip_xmit(), handle_response_invite(), retrans_pkt(), sip_call(), and sip_poke_peer().
| enum check_auth_result |
Authentication result from check_auth* functions.
| AUTH_SUCCESSFUL | |
| AUTH_CHALLENGE_SENT | |
| AUTH_SECRET_FAILED | |
| AUTH_USERNAME_MISMATCH | |
| AUTH_NOT_FOUND | |
| AUTH_FAKE_AUTH | |
| AUTH_UNKNOWN_DOMAIN | |
| AUTH_PEER_NOT_DYNAMIC | |
| AUTH_ACL_FAILED |
Definition at line 344 of file chan_sip.c.
00344 { 00345 AUTH_SUCCESSFUL = 0, 00346 AUTH_CHALLENGE_SENT = 1, 00347 AUTH_SECRET_FAILED = -1, 00348 AUTH_USERNAME_MISMATCH = -2, 00349 AUTH_NOT_FOUND = -3, 00350 AUTH_FAKE_AUTH = -4, 00351 AUTH_UNKNOWN_DOMAIN = -5, 00352 AUTH_PEER_NOT_DYNAMIC = -6, 00353 AUTH_ACL_FAILED = -7, 00354 };
| enum domain_mode |
Modes for SIP domain handling in the PBX.
| SIP_DOMAIN_AUTO | This domain is auto-configured |
| SIP_DOMAIN_CONFIG | This domain is from configuration |
Definition at line 683 of file chan_sip.c.
00683 { 00684 SIP_DOMAIN_AUTO, /*!< This domain is auto-configured */ 00685 SIP_DOMAIN_CONFIG, /*!< This domain is from configuration */ 00686 };
| enum invitestates |
States for the INVITE transaction, not the dialog.
| INV_NONE | No state at all, maybe not an INVITE dialog |
| INV_CALLING | Invite sent, no answer |
| INV_PROCEEDING | We got/sent 1xx message |
| INV_EARLY_MEDIA | We got/sent 18x message with to-tag back |
| INV_COMPLETED | Got final response with error. Wait for ACK, then CONFIRMED |
| INV_CONFIRMED | Confirmed response - we've got an ack (Incoming calls only) |
| INV_TERMINATED | Transaction done - either successful (AST_STATE_UP) or failed, but done The only way out of this is a BYE from one side |
| INV_CANCELLED | Transaction cancelled by client or server in non-terminated state |
Definition at line 255 of file chan_sip.c.
00255 { 00256 INV_NONE = 0, /*!< No state at all, maybe not an INVITE dialog */ 00257 INV_CALLING = 1, /*!< Invite sent, no answer */ 00258 INV_PROCEEDING = 2, /*!< We got/sent 1xx message */ 00259 INV_EARLY_MEDIA = 3, /*!< We got/sent 18x message with to-tag back */ 00260 INV_COMPLETED = 4, /*!< Got final response with error. Wait for ACK, then CONFIRMED */ 00261 INV_CONFIRMED = 5, /*!< Confirmed response - we've got an ack (Incoming calls only) */ 00262 INV_TERMINATED = 6, /*!< Transaction done - either successful (AST_STATE_UP) or failed, but done 00263 The only way out of this is a BYE from one side */ 00264 INV_CANCELLED = 7, /*!< Transaction cancelled by client or server in non-terminated state */ 00265 };
Definition at line 282 of file chan_sip.c.
00282 { 00283 PARSE_REGISTER_FAILED, 00284 PARSE_REGISTER_UPDATE, 00285 PARSE_REGISTER_QUERY, 00286 };
| enum referstatus |
Parameters to know status of transfer.
| REFER_IDLE | No REFER is in progress |
| REFER_SENT | Sent REFER to transferee |
| REFER_RECEIVED | Received REFER from transferer |
| REFER_CONFIRMED | Refer confirmed with a 100 TRYING |
| REFER_ACCEPTED | Accepted by transferee |
| REFER_RINGING | Target Ringing |
| REFER_200OK | Answered by transfer target |
| REFER_FAILED | REFER declined - go on |
| REFER_NOAUTH | We had no auth for REFER |
Definition at line 866 of file chan_sip.c.
00866 { 00867 REFER_IDLE, /*!< No REFER is in progress */ 00868 REFER_SENT, /*!< Sent REFER to transferee */ 00869 REFER_RECEIVED, /*!< Received REFER from transferer */ 00870 REFER_CONFIRMED, /*!< Refer confirmed with a 100 TRYING */ 00871 REFER_ACCEPTED, /*!< Accepted by transferee */ 00872 REFER_RINGING, /*!< Target Ringing */ 00873 REFER_200OK, /*!< Answered by transfer target */ 00874 REFER_FAILED, /*!< REFER declined - go on */ 00875 REFER_NOAUTH /*!< We had no auth for REFER */ 00876 };
| enum sip_auth_type |
Authentication types - proxy or www authentication.
Definition at line 338 of file chan_sip.c.
00338 { 00339 PROXY_AUTH, 00340 WWW_AUTH, 00341 };
| enum sip_result |
Definition at line 247 of file chan_sip.c.
00247 { 00248 AST_SUCCESS = 0, 00249 AST_FAILURE = -1, 00250 };
| enum sipmethod |
SIP Request methods known by Asterisk.
| SIP_UNKNOWN | |
| SIP_RESPONSE | |
| SIP_REGISTER | |
| SIP_OPTIONS | |
| SIP_NOTIFY | |
| SIP_INVITE | |
| SIP_ACK | |
| SIP_PRACK | |
| SIP_BYE | |
| SIP_REFER | |
| SIP_SUBSCRIBE | |
| SIP_MESSAGE | |
| SIP_UPDATE | |
| SIP_INFO | |
| SIP_CANCEL | |
| SIP_PUBLISH | |
| SIP_PING |
Definition at line 313 of file chan_sip.c.
00313 { 00314 SIP_UNKNOWN, /* Unknown response */ 00315 SIP_RESPONSE, /* Not request, response to outbound request */ 00316 SIP_REGISTER, 00317 SIP_OPTIONS, 00318 SIP_NOTIFY, 00319 SIP_INVITE, 00320 SIP_ACK, 00321 SIP_PRACK, /* Not supported at all */ 00322 SIP_BYE, 00323 SIP_REFER, 00324 SIP_SUBSCRIBE, 00325 SIP_MESSAGE, 00326 SIP_UPDATE, /* We can send UPDATE; but not accept it */ 00327 SIP_INFO, 00328 SIP_CANCEL, 00329 SIP_PUBLISH, /* Not supported at all */ 00330 SIP_PING, /* Not supported at all, no standard but still implemented out there */ 00331 };
| enum sipregistrystate |
States for outbound registrations (with register= lines in sip.conf.
Definition at line 357 of file chan_sip.c.
00357 { 00358 REG_STATE_UNREGISTERED = 0, /*!< We are not registred */ 00359 REG_STATE_REGSENT, /*!< Registration request sent */ 00360 REG_STATE_AUTHSENT, /*!< We have tried to authenticate */ 00361 REG_STATE_REGISTERED, /*!< Registred and done */ 00362 REG_STATE_REJECTED, /*!< Registration rejected */ 00363 REG_STATE_TIMEOUT, /*!< Registration timed out */ 00364 REG_STATE_NOAUTH, /*!< We have no accepted credentials */ 00365 REG_STATE_FAILED, /*!< Registration failed after several tries */ 00366 };
| enum subscriptiontype |
Definition at line 288 of file chan_sip.c.
00288 { 00289 NONE = 0, 00290 XPIDF_XML, 00291 DIALOG_INFO_XML, 00292 CPIM_PIDF_XML, 00293 PIDF_XML, 00294 MWI_NOTIFICATION 00295 };
| enum t38state |
T38 States for a call.
Definition at line 847 of file chan_sip.c.
00847 { 00848 T38_DISABLED = 0, /*!< Not enabled */ 00849 T38_LOCAL_DIRECT, /*!< Offered from local */ 00850 T38_LOCAL_REINVITE, /*!< Offered from local - REINVITE */ 00851 T38_PEER_DIRECT, /*!< Offered from peer */ 00852 T38_PEER_REINVITE, /*!< Offered from peer - REINVITE */ 00853 T38_ENABLED /*!< Negotiated (enabled) */ 00854 };
| enum transfermodes |
Authorization scheme for call transfers.
Definition at line 241 of file chan_sip.c.
00241 { 00242 TRANSFER_OPENFORALL, /*!< Allow all SIP transfers */ 00243 TRANSFER_CLOSED, /*!< Allow no SIP transfers */ 00244 };
| enum xmittype |
| XMIT_CRITICAL | Transmit critical SIP message reliably, with re-transmits. If it fails, it's critical and will cause a teardown of the session |
| XMIT_RELIABLE | Transmit SIP message reliably, with re-transmits |
| XMIT_UNRELIABLE | Transmit SIP message without bothering with re-transmits |
Definition at line 275 of file chan_sip.c.
00275 { 00276 XMIT_CRITICAL = 2, /*!< Transmit critical SIP message reliably, with re-transmits. 00277 If it fails, it's critical and will cause a teardown of the session */ 00278 XMIT_RELIABLE = 1, /*!< Transmit SIP message reliably, with re-transmits */ 00279 XMIT_UNRELIABLE = 0, /*!< Transmit SIP message without bothering with re-transmits */ 00280 };
| static const char * __get_header | ( | const struct sip_request * | req, | |
| const char * | name, | |||
| int * | start | |||
| ) | [static] |
Definition at line 4290 of file chan_sip.c.
References ast_skip_blanks(), find_alias(), sip_request::header, sip_request::headers, and len().
Referenced by build_route(), copy_all_header(), copy_via_headers(), func_header_read(), get_header(), and handle_response_register().
04291 { 04292 int pass; 04293 04294 /* 04295 * Technically you can place arbitrary whitespace both before and after the ':' in 04296 * a header, although RFC3261 clearly says you shouldn't before, and place just 04297 * one afterwards. If you shouldn't do it, what absolute idiot decided it was 04298 * a good idea to say you can do it, and if you can do it, why in the hell would. 04299 * you say you shouldn't. 04300 * Anyways, pedanticsipchecking controls whether we allow spaces before ':', 04301 * and we always allow spaces after that for compatibility. 04302 */ 04303 for (pass = 0; name && pass < 2;pass++) { 04304 int x, len = strlen(name); 04305 for (x=*start; x<req->headers; x++) { 04306 if (!strncasecmp(req->header[x], name, len)) { 04307 char *r = req->header[x] + len; /* skip name */ 04308 if (pedanticsipchecking) 04309 r = ast_skip_blanks(r); 04310 04311 if (*r == ':') { 04312 *start = x+1; 04313 return ast_skip_blanks(r+1); 04314 } 04315 } 04316 } 04317 if (pass == 0) /* Try aliases */ 04318 name = find_alias(name, NULL); 04319 } 04320 04321 /* Don't return NULL, so get_header is always a valid pointer */ 04322 return ""; 04323 }
| static void __reg_module | ( | void | ) | [static] |
Definition at line 18790 of file chan_sip.c.
| static int __set_address_from_contact | ( | const char * | fullcontact, | |
| struct sockaddr_in * | sin | |||
| ) | [static] |
Definition at line 8140 of file chan_sip.c.
References ast_copy_string(), ast_gethostbyname(), ast_log(), hp, LOG_NOTICE, LOG_WARNING, and STANDARD_SIP_PORT.
Referenced by build_peer(), and set_address_from_contact().
08141 { 08142 struct hostent *hp; 08143 struct ast_hostent ahp; 08144 int port; 08145 char *c, *host, *pt; 08146 char contact_buf[256]; 08147 char *contact; 08148 08149 /* Work on a copy */ 08150 ast_copy_string(contact_buf, fullcontact, sizeof(contact_buf)); 08151 contact = contact_buf; 08152 08153 /* Make sure it's a SIP URL */ 08154 if (strncasecmp(contact, "sip:", 4)) { 08155 ast_log(LOG_NOTICE, "'%s' is not a valid SIP contact (missing sip:) trying to use anyway\n", contact); 08156 } else 08157 contact += 4; 08158 08159 /* Ditch arguments */ 08160 /* XXX this code is replicated also shortly below */ 08161 08162 /* Grab host */ 08163 host = strchr(contact, '@'); 08164 if (!host) { /* No username part */ 08165 host = contact; 08166 c = NULL; 08167 } else { 08168 *host++ = '\0'; 08169 } 08170 pt = strchr(host, ':'); 08171 if (pt) { 08172 *pt++ = '\0'; 08173 port = atoi(pt); 08174 } else 08175 port = STANDARD_SIP_PORT; 08176 08177 contact = strsep(&contact, ";"); /* trim ; and beyond in username part */ 08178 host = strsep(&host, ";"); /* trim ; and beyond in host/domain part */ 08179 08180 /* XXX This could block for a long time XXX */ 08181 /* We should only do this if it's a name, not an IP */ 08182 hp = ast_gethostbyname(host, &ahp); 08183 if (!hp) { 08184 ast_log(LOG_WARNING, "Invalid host name in Contact: (can't resolve in DNS) : '%s'\n", host); 08185 return -1; 08186 } 08187 sin->sin_family = AF_INET; 08188 memcpy(&sin->sin_addr, hp->h_addr, sizeof(sin->sin_addr)); 08189 sin->sin_port = htons(port); 08190 08191 return 0; 08192 }
| static void __sip_ack | ( | struct sip_pvt * | p, | |
| int | seqno, | |||
| int | resp, | |||
| int | sipmethod | |||
| ) | [static] |
Acknowledges receipt of a packet and stops retransmission called with p locked.
Definition at line 2164 of file chan_sip.c.
References ast_log(), ast_sched_del(), ast_test_flag, sip_pvt::callid, sip_pkt::data, DEADLOCK_AVOIDANCE, FALSE, FLAG_RESPONSE, free, sip_pvt::lock, LOG_DEBUG, sip_pkt::next, option_debug, sip_pvt::packets, sip_pvt::pendinginvite, sip_pkt::retransid, sip_pkt::seqno, sip_methods, sipdebug, cfsip_methods::text, TRUE, and UNLINK.
Referenced by __sip_pretend_ack(), handle_request(), and handle_response().
02165 { 02166 struct sip_pkt *cur, *prev = NULL; 02167 02168 /* Just in case... */ 02169 char *msg; 02170 int res = FALSE; 02171 02172 msg = sip_methods[sipmethod].text; 02173 02174 for (cur = p->packets; cur; prev = cur, cur = cur->next) { 02175 if ((cur->seqno == seqno) && ((ast_test_flag(cur, FLAG_RESPONSE)) == resp) && 02176 ((ast_test_flag(cur, FLAG_RESPONSE)) || 02177 (!strncasecmp(msg, cur->data, strlen(msg)) && (cur->data[strlen(msg)] < 33)))) { 02178 if (!resp && (seqno == p->pendinginvite)) { 02179 if (option_debug) 02180 ast_log(LOG_DEBUG, "Acked pending invite %d\n", p->pendinginvite); 02181 p->pendinginvite = 0; 02182 } 02183 /* this is our baby */ 02184 res = TRUE; 02185 UNLINK(cur, p->packets, prev); 02186 if (cur->retransid > -1) { 02187 if (sipdebug && option_debug > 3) 02188 ast_log(LOG_DEBUG, "** SIP TIMER: Cancelling retransmit of packet (reply received) Retransid #%d\n", cur->retransid); 02189 } 02190 /* This odd section is designed to thwart a 02191 * race condition in the packet scheduler. There are 02192 * two conditions under which deleting the packet from the 02193 * scheduler can fail. 02194 * 02195 * 1. The packet has been removed from the scheduler because retransmission 02196 * is being attempted. The problem is that if the packet is currently attempting 02197 * retransmission and we are at this point in the code, then that MUST mean 02198 * that retrans_pkt is waiting on p's lock. Therefore we will relinquish the 02199 * lock temporarily to allow retransmission. 02200 * 02201 * 2. The packet has reached its maximum number of retransmissions and has 02202 * been permanently removed from the packet scheduler. If this is the case, then 02203 * the packet's retransid will be set to -1. The atomicity of the setting and checking 02204 * of the retransid to -1 is ensured since in both cases p's lock is held. 02205 */ 02206 while (cur->retransid > -1 && ast_sched_del(sched, cur->retransid)) { 02207 DEADLOCK_AVOIDANCE(&p->lock); 02208 } 02209 free(cur); 02210 break; 02211 } 02212 } 02213 if (option_debug) 02214 ast_log(LOG_DEBUG, "Stopping retransmission on '%s' of %s %d: Match %s\n", p->callid, resp ? "Response" : "Request", seqno, res == FALSE ? "Not Found" : "Found"); 02215 }
| static int __sip_autodestruct | ( | const void * | data | ) | [static] |
Kill a SIP dialog (called by scheduler).
Definition at line 2080 of file chan_sip.c.
References append_history, AST_EXTENSION_DEACTIVATED, ast_log(), ast_queue_hangup(), ast_set_flag, ast_test_flag, ASTOBJ_UNREF, sip_pvt::autokillid, sip_pvt::callid, DEFAULT_TRANS_TIMEOUT, sip_pvt::flags, LOG_DEBUG, LOG_WARNING, sip_pvt::method, MWI_NOTIFICATION, NONE, option_debug, sip_pvt::owner, sip_pvt::packets, sip_pvt::refer, sip_pvt::relatedpeer, SIP_ALREADYGONE, SIP_BYE, SIP_CANCEL, sip_destroy(), sip_destroy_peer(), sip_methods, SIP_NEEDDESTROY, sip_scheddestroy(), sip_pvt::subscribed, cfsip_methods::text, transmit_request_with_auth(), transmit_state_notify(), TRUE, and XMIT_RELIABLE.
Referenced by sip_scheddestroy().
02081 { 02082 struct sip_pvt *p = (struct sip_pvt *)data; 02083 02084 /* If this is a subscription, tell the phone that we got a timeout */ 02085 if (p->subscribed) { 02086 transmit_state_notify(p, AST_EXTENSION_DEACTIVATED, 1, TRUE); /* Send last notification */ 02087 p->subscribed = NONE; 02088 append_history(p, "Subscribestatus", "timeout"); 02089 if (option_debug > 2) 02090 ast_log(LOG_DEBUG, "Re-scheduled destruction of SIP subsription %s\n", p->callid ? p->callid : "<unknown>"); 02091 return 10000; /* Reschedule this destruction so that we know that it's gone */ 02092 } 02093 02094 /* If there are packets still waiting for delivery, delay the destruction */ 02095 /* via bug 12101, the two usages of SIP_NEEDDESTROY in the following block 02096 * of code make a sort of "safety relief valve", that allows sip channels 02097 * that were created via INVITE, then thru some sequence were CANCELED, 02098 * to die, rather than infinitely be rescheduled */ 02099 if (p->packets && !ast_test_flag(&p->flags[0], SIP_NEEDDESTROY)) { 02100 if (option_debug > 2) 02101 ast_log(LOG_DEBUG, "Re-scheduled destruction of SIP call %s\n", p->callid ? p->callid : "<unknown>"); 02102 append_history(p, "ReliableXmit", "timeout"); 02103 if (p->method == SIP_CANCEL || p->method == SIP_BYE) { 02104 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 02105 } 02106 return 10000; 02107 } 02108 02109 /* If we're destroying a subscription, dereference peer object too */ 02110 if (p->subscribed == MWI_NOTIFICATION && p->relatedpeer) 02111 ASTOBJ_UNREF(p->relatedpeer,sip_destroy_peer); 02112 02113 /* Reset schedule ID */ 02114 p->autokillid = -1; 02115 02116 if (option_debug) 02117 ast_log(LOG_DEBUG, "Auto destroying SIP dialog '%s'\n", p->callid); 02118 append_history(p, "AutoDestroy", "%s", p->callid); 02119 if (p->owner) { 02120 ast_log(LOG_WARNING, "Autodestruct on dialog '%s' with owner in place (Method: %s)\n", p->callid, sip_methods[p->method].text); 02121 ast_queue_hangup(p->owner); 02122 } else if (p->refer && !ast_test_flag(&p->flags[0], SIP_ALREADYGONE)) { 02123 if (option_debug > 2) 02124 ast_log(LOG_DEBUG, "Finally hanging up channel after transfer: %s\n", p->callid); 02125 transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, 1); 02126 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 02127 } else 02128 sip_destroy(p); 02129 return 0; 02130 }
| static int __sip_destroy | ( | struct sip_pvt * | p, | |
| int | lockowner | |||
| ) | [static] |
Execute destruction of SIP dialog structure, release memory.
Definition at line 3099 of file chan_sip.c.
References ast_channel::_softhangup, ast_channel_lock, ast_channel_unlock, ast_extension_state_del(), AST_LIST_REMOVE_HEAD, ast_log(), ast_mutex_destroy(), ast_rtp_destroy(), ast_rtp_get_bridged(), AST_SCHED_DEL, AST_SOFTHANGUP_DEV, ast_string_field_free_memory, ast_test_flag, ast_udptl_destroy(), ast_variables_destroy(), ast_verbose(), ASTOBJ_UNREF, sip_pvt::autokillid, sip_registry::call, sip_pvt::callid, sip_pvt::chanvars, DEC_CALL_LIMIT, sip_pvt::flags, free, free_old_route(), sip_pvt::history, sip_pvt::history_entries, iflist, sip_pvt::initid, sip_pvt::lock, LOG_DEBUG, LOG_WARNING, sip_pvt::method, sip_peer::mwipvt, ast_channel::name, sip_pkt::next, sip_pvt::next, option_debug, sip_pvt::options, sip_pvt::owner, sip_pvt::packets, sip_pvt::refer, sip_pvt::registry, sip_pvt::relatedpeer, sip_pkt::retransid, sip_pvt::route, sip_pvt::rtp, sip_debug_test_pvt(), sip_destroy_peer(), sip_dump_history(), SIP_INC_COUNT, sip_methods, SIP_PAGE2_CALL_ONHOLD, sip_registry_destroy(), sip_pvt::stateid, ast_channel::tech_pvt, cfsip_methods::text, sip_pvt::udptl, UNLINK, update_call_counter(), sip_pvt::vrtp, and sip_pvt::waitid.
Referenced by do_monitor(), sip_destroy(), and unload_module().
03100 { 03101 struct sip_pvt *cur, *prev = NULL; 03102 struct sip_pkt *cp; 03103 03104 /* We absolutely cannot destroy the rtp struct while a bridge is active or we WILL crash */ 03105 if (p->rtp && ast_rtp_get_bridged(p->rtp)) { 03106 ast_verbose("Bridge still active. Delaying destroy of SIP dialog '%s' Method: %s\n", p->callid, sip_methods[p->method].text); 03107 return -1; 03108 } 03109 03110 if (p->vrtp && ast_rtp_get_bridged(p->vrtp)) { 03111 ast_verbose("Bridge still active. Delaying destroy of SIP dialog '%s' Method: %s\n", p->callid, sip_methods[p->method].text); 03112 return -1; 03113 } 03114 03115 if (sip_debug_test_pvt(p) || option_debug > 2) 03116 ast_verbose("Really destroying SIP dialog '%s' Method: %s\n", p->callid, sip_methods[p->method].text); 03117 03118 if (ast_test_flag(&p->flags[0], SIP_INC_COUNT) || ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD)) { 03119 update_call_counter(p, DEC_CALL_LIMIT); 03120 if (option_debug > 1) 03121 ast_log(LOG_DEBUG, "This call did not properly clean up call limits. Call ID %s\n", p->callid); 03122 } 03123 03124 /* Unlink us from the owner if we have one */ 03125 if (p->owner) { 03126 if (lockowner) 03127 ast_channel_lock(p->owner); 03128 if (option_debug) 03129 ast_log(LOG_DEBUG, "Detaching from %s\n", p->owner->name); 03130 p->owner->tech_pvt = NULL; 03131 /* Make sure that the channel knows its backend is going away */ 03132 p->owner->_softhangup |= AST_SOFTHANGUP_DEV; 03133 if (lockowner) 03134 ast_channel_unlock(p->owner); 03135 /* Give the channel a chance to react before deallocation */ 03136 usleep(1); 03137 } 03138 03139 /* Remove link from peer to subscription of MWI */ 03140 if (p->relatedpeer) { 03141 if (p->relatedpeer->mwipvt == p) { 03142 p->relatedpeer->mwipvt = NULL; 03143 } 03144 ASTOBJ_UNREF(p->relatedpeer, sip_destroy_peer); 03145 } 03146 03147 if (dumphistory) 03148 sip_dump_history(p); 03149 03150 if (p->options) 03151 free(p->options); 03152 03153 if (p->stateid > -1) 03154 ast_extension_state_del(p->stateid, NULL); 03155 AST_SCHED_DEL(sched, p->initid); 03156 AST_SCHED_DEL(sched, p->waitid); 03157 AST_SCHED_DEL(sched, p->autokillid); 03158 03159 if (p->rtp) { 03160 ast_rtp_destroy(p->rtp); 03161 } 03162 if (p->vrtp) { 03163 ast_rtp_destroy(p->vrtp); 03164 } 03165 if (p->udptl) 03166 ast_udptl_destroy(p->udptl); 03167 if (p->refer) 03168 free(p->refer); 03169 if (p->route) { 03170 free_old_route(p->route); 03171 p->route = NULL; 03172 } 03173 if (p->registry) { 03174 if (p->registry->call == p) 03175 p->registry->call = NULL; 03176 ASTOBJ_UNREF(p->registry, sip_registry_destroy); 03177 } 03178 03179 /* Clear history */ 03180 if (p->history) { 03181 struct sip_history *hist; 03182 while ( (hist = AST_LIST_REMOVE_HEAD(p->history, list)) ) { 03183 free(hist); 03184 p->history_entries--; 03185 } 03186 free(p->history); 03187 p->history = NULL; 03188 } 03189 03190 for (prev = NULL, cur = iflist; cur; prev = cur, cur = cur->next) { 03191 if (cur == p) { 03192 UNLINK(cur, iflist, prev); 03193 break; 03194 } 03195 } 03196 if (!cur) { 03197 ast_log(LOG_WARNING, "Trying to destroy \"%s\", not found in dialog list?!?! \n", p->callid); 03198 return 0; 03199 } 03200 03201 /* remove all current packets in this dialog */ 03202 while((cp = p->packets)) { 03203 p->packets = p->packets->next; 03204 AST_SCHED_DEL(sched, cp->retransid); 03205 free(cp); 03206 } 03207 if (p->chanvars) { 03208 ast_variables_destroy(p->chanvars); 03209 p->chanvars = NULL; 03210 } 03211 ast_mutex_destroy(&p->lock); 03212 03213 ast_string_field_free_memory(p); 03214 03215 free(p); 03216 return 0; 03217 }
| static int __sip_do_register | ( | struct sip_registry * | r | ) | [static] |
Register with SIP proxy.
Definition at line 7575 of file chan_sip.c.
References SIP_REGISTER, and transmit_register().
Referenced by sip_reregister().
07576 { 07577 int res; 07578 07579 res = transmit_register(r, SIP_REGISTER, NULL, NULL); 07580 return res; 07581 }
| static void __sip_pretend_ack | ( | struct sip_pvt * | p | ) | [static] |
Pretend to ack all packets called with p locked.
Definition at line 2219 of file chan_sip.c.
References __sip_ack(), ast_log(), ast_test_flag, sip_pkt::data, find_sip_method(), FLAG_RESPONSE, LOG_WARNING, sip_pkt::method, sip_pvt::packets, sip_pkt::seqno, sip_methods, and cfsip_methods::text.
Referenced by handle_request_bye(), handle_request_cancel(), sip_hangup(), and sip_reg_timeout().
02220 { 02221 struct sip_pkt *cur = NULL; 02222 02223 while (p->packets) { 02224 int method; 02225 if (cur == p->packets) { 02226 ast_log(LOG_WARNING, "Have a packet that doesn't want to give up! %s\n", sip_methods[cur->method].text); 02227 return; 02228 } 02229 cur = p->packets; 02230 method = (cur->method) ? cur->method : find_sip_method(cur->data); 02231 __sip_ack(p, cur->seqno, ast_test_flag(cur, FLAG_RESPONSE), method); 02232 } 02233 }
| static enum sip_result __sip_reliable_xmit | ( | struct sip_pvt * | p, | |
| int | seqno, | |||
| int | resp, | |||
| char * | data, | |||
| int | len, | |||
| int | fatal, | |||
| int | sipmethod | |||
| ) | [static] |
Transmit packet with retransmits.
Definition at line 2033 of file chan_sip.c.
References __sip_xmit(), append_history, ast_calloc, AST_FAILURE, ast_log(), ast_sched_add_variable(), ast_set_flag, AST_SUCCESS, ast_test_flag, sip_pkt::data, DEFAULT_RETRANS, FLAG_FATAL, FLAG_RESPONSE, LOG_DEBUG, sip_pkt::method, sip_pkt::next, option_debug, sip_pkt::owner, sip_pkt::packetlen, sip_pvt::packets, sip_pvt::pendinginvite, retrans_pkt(), sip_pkt::retransid, sip_pkt::seqno, SIP_INVITE, sipdebug, sip_pvt::timer_t1, sip_pkt::timer_t1, and XMIT_ERROR.
Referenced by send_request(), and send_response().
02034 { 02035 struct sip_pkt *pkt; 02036 int siptimer_a = DEFAULT_RETRANS; 02037 int xmitres = 0; 02038 02039 if (!(pkt = ast_calloc(1, sizeof(*pkt) + len + 1))) 02040 return AST_FAILURE; 02041 memcpy(pkt->data, data, len); 02042 pkt->method = sipmethod; 02043 pkt->packetlen = len; 02044 pkt->next = p->packets; 02045 pkt->owner = p; 02046 pkt->seqno = seqno; 02047 if (resp) 02048 ast_set_flag(pkt, FLAG_RESPONSE); 02049 pkt->data[len] = '\0'; 02050 pkt->timer_t1 = p->timer_t1; /* Set SIP timer T1 */ 02051 pkt->retransid = -1; 02052 if (fatal) 02053 ast_set_flag(pkt, FLAG_FATAL); 02054 if (pkt->timer_t1) 02055 siptimer_a = pkt->timer_t1 * 2; 02056 02057 if (option_debug > 3 && sipdebug) 02058 ast_log(LOG_DEBUG, "*** SIP TIMER: Initializing retransmit timer on packet: Id #%d\n", pkt->retransid); 02059 pkt->retransid = -1; 02060 pkt->next = p->packets; 02061 p->packets = pkt; 02062 if (sipmethod == SIP_INVITE) { 02063 /* Note this is a pending invite */ 02064 p->pendinginvite = seqno; 02065 } 02066 02067 xmitres = __sip_xmit(pkt->owner, pkt->data, pkt->packetlen); /* Send packet */ 02068 02069 if (xmitres == XMIT_ERROR) { /* Serious network trouble, no need to try again */ 02070 append_history(pkt->owner, "XmitErr", "%s", (ast_test_flag(pkt, FLAG_FATAL)) ? "(Critical)" : "(Non-critical)"); 02071 return AST_FAILURE; 02072 } else { 02073 /* Schedule retransmission */ 02074 pkt->retransid = ast_sched_add_variable(sched, siptimer_a, retrans_pkt, pkt, 1); 02075 return AST_SUCCESS; 02076 } 02077 }
| static int __sip_semi_ack | ( | struct sip_pvt * | p, | |
| int | seqno, | |||
| int | resp, | |||
| int | sipmethod | |||
| ) | [static] |
Acks receipt of packet, keep it around (used for provisional responses).
Definition at line 2236 of file chan_sip.c.
References ast_log(), AST_SCHED_DEL, ast_test_flag, sip_pvt::callid, sip_pkt::data, FLAG_RESPONSE, LOG_DEBUG, method_match(), sip_pkt::next, option_debug, sip_pvt::packets, sip_pkt::retransid, sip_pkt::seqno, sip_methods, sipdebug, and cfsip_methods::text.
Referenced by handle_response().
02237 { 02238 struct sip_pkt *cur; 02239 int res = -1; 02240 02241 for (cur = p->packets; cur; cur = cur->next) { 02242 if (cur->seqno == seqno && ast_test_flag(cur, FLAG_RESPONSE) == resp && 02243 (ast_test_flag(cur, FLAG_RESPONSE) || method_match(sipmethod, cur->data))) { 02244 /* this is our baby */ 02245 if (cur->retransid > -1) { 02246 if (option_debug > 3 && sipdebug) 02247 ast_log(LOG_DEBUG, "*** SIP TIMER: Cancelling retransmission #%d - %s (got response)\n", cur->retransid, sip_methods[sipmethod].text); 02248 } 02249 AST_SCHED_DEL(sched, cur->retransid); 02250 res = 0; 02251 break; 02252 } 02253 } 02254 if (option_debug) 02255 ast_log(LOG_DEBUG, "(Provisional) Stopping retransmission (but retaining packet) on '%s' %s %d: %s\n", p->callid, resp ? "Response" : "Request", seqno, res == -1 ? "Not Found" : "Found"); 02256 return res; 02257 }
| static int __sip_show_channels | ( | int | fd, | |
| int | argc, | |||
| char * | argv[], | |||
| int | subscriptions | |||
| ) | [static] |
SIP show channels CLI (main function).
Definition at line 10980 of file chan_sip.c.
References ast_cli(), ast_extension_state2str(), ast_getformatname_multiple(), ast_inet_ntoa(), ast_mutex_lock(), ast_mutex_unlock(), ast_test_flag, sip_pvt::callid, sip_pvt::cid_num, sip_pvt::flags, FORMAT, FORMAT2, FORMAT3, sip_pvt::icseq, iflist, iflock, sip_pvt::lastmsg, sip_pvt::laststate, sip_peer::mailbox, MWI_NOTIFICATION, ast_channel::nativeformats, sip_pvt::next, NONE, sip_pvt::ocseq, sip_pvt::owner, sip_pvt::refer, referstatus2str(), sip_pvt::relatedpeer, RESULT_SHOWUSAGE, RESULT_SUCCESS, S_OR, sip_pvt::sa, SIP_NEEDDESTROY, SIP_PAGE2_CALL_ONHOLD, SIPBUFSIZE, sip_refer::status, sip_pvt::subscribed, sip_pvt::subscribeuri, subscription_type2str(), and sip_pvt::username.
Referenced by sip_show_channels(), and sip_show_subscriptions().
10981 { 10982 #define FORMAT3 "%-15.15s %-10.10s %-11.11s %-15.15s %-13.13s %-15.15s %-10.10s\n" 10983 #define FORMAT2 "%-15.15s %-10.10s %-11.11s %-11.11s %-15.15s %-7.7s %-15.15s\n" 10984 #define FORMAT "%-15.15s %-10.10s %-11.11s %5.5d/%5.5d %-15.15s %-3.3s %-3.3s %-15.15s %-10.10s\n" 10985 struct sip_pvt *cur; 10986 int numchans = 0; 10987 char *referstatus = NULL; 10988 10989 if (argc != 3) 10990 return RESULT_SHOWUSAGE; 10991 ast_mutex_lock(&iflock); 10992 cur = iflist; 10993 if (!subscriptions) 10994 ast_cli(fd, FORMAT2, "Peer", "User/ANR", "Call ID", "Seq (Tx/Rx)", "Format", "Hold", "Last Message"); 10995 else 10996 ast_cli(fd, FORMAT3, "Peer", "User", "Call ID", "Extension", "Last state", "Type", "Mailbox"); 10997 for (; cur; cur = cur->next) { 10998 referstatus = ""; 10999 if (cur->refer) { /* SIP transfer in progress */ 11000 referstatus = referstatus2str(cur->refer->status); 11001 } 11002 if (cur->subscribed == NONE && !subscriptions) { 11003 char formatbuf[SIPBUFSIZE/2]; 11004 ast_cli(fd, FORMAT, ast_inet_ntoa(cur->sa.sin_addr), 11005 S_OR(cur->username, S_OR(cur->cid_num, "(None)")), 11006 cur->callid, 11007 cur->ocseq, cur->icseq, 11008 ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->owner ? cur->owner->nativeformats : 0), 11009 ast_test_flag(&cur->flags[1], SIP_PAGE2_CALL_ONHOLD) ? "Yes" : "No", 11010 ast_test_flag(&cur->flags[0], SIP_NEEDDESTROY) ? "(d)" : "", 11011 cur->lastmsg , 11012 referstatus 11013 ); 11014 numchans++; 11015 } 11016 if (cur->subscribed != NONE && subscriptions) { 11017 ast_cli(fd, FORMAT3, ast_inet_ntoa(cur->sa.sin_addr), 11018 S_OR(cur->username, S_OR(cur->cid_num, "(None)")), 11019 cur->callid, 11020 /* the 'complete' exten/context is hidden in the refer_to field for subscriptions */ 11021 cur->subscribed == MWI_NOTIFICATION ? "--" : cur->subscribeuri, 11022 cur->subscribed == MWI_NOTIFICATION ? "<none>" : ast_extension_state2str(cur->laststate), 11023 subscription_type2str(cur->subscribed), 11024 cur->subscribed == MWI_NOTIFICATION ? (cur->relatedpeer ? cur->relatedpeer->mailbox : "<none>") : "<none>" 11025 ); 11026 numchans++; 11027 } 11028 } 11029 ast_mutex_unlock(&iflock); 11030 if (!subscriptions) 11031 ast_cli(fd, "%d active SIP channel%s\n", numchans, (numchans != 1) ? "s" : ""); 11032 else 11033 ast_cli(fd, "%d active SIP subscription%s\n", numchans, (numchans != 1) ? "s" : ""); 11034 return RESULT_SUCCESS; 11035 #undef FORMAT 11036 #undef FORMAT2 11037 #undef FORMAT3 11038 }
| static int __sip_xmit | ( | struct sip_pvt * | p, | |
| char * | data, | |||
| int | len | |||
| ) | [static] |
Transmit SIP message.
Definition at line 1784 of file chan_sip.c.
References ast_inet_ntoa(), ast_log(), errno, LOG_WARNING, sip_real_dst(), and XMIT_ERROR.
Referenced by __sip_reliable_xmit(), retrans_pkt(), send_request(), and send_response().
01785 { 01786 int res; 01787 const struct sockaddr_in *dst = sip_real_dst(p); 01788 res = sendto(sipsock, data, len, 0, (const struct sockaddr *)dst, sizeof(struct sockaddr_in)); 01789 01790 if (res == -1) { 01791 switch (errno) { 01792 case EBADF: /* Bad file descriptor - seems like this is generated when the host exist, but doesn't accept the UDP packet */ 01793 case EHOSTUNREACH: /* Host can't be reached */ 01794 case ENETDOWN: /* Inteface down */ 01795 case ENETUNREACH: /* Network failure */ 01796 case ECONNREFUSED: /* ICMP port unreachable */ 01797 res = XMIT_ERROR; /* Don't bother with trying to transmit again */ 01798 } 01799 } 01800 if (res != len) 01801 ast_log(LOG_WARNING, "sip_xmit of %p (len %d) to %s:%d returned %d: %s\n", data, len, ast_inet_ntoa(dst->sin_addr), ntohs(dst->sin_port), res, strerror(errno)); 01802 return res; 01803 }
| 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 6113 of file chan_sip.c.
References add_header(), add_header_contentLength(), ast_cause2str(), ast_log(), get_header(), ast_channel::hangupcause, LOG_WARNING, sip_pvt::method, sip_pvt::owner, respprep(), send_response(), and SIP_INVITE.
Referenced by transmit_response(), transmit_response_reliable(), and transmit_response_using_temp().
06114 { 06115 struct sip_request resp; 06116 int seqno = 0; 06117 06118 if (reliable && (sscanf(get_header(req, "CSeq"), "%d ", &seqno) != 1)) { 06119 ast_log(LOG_WARNING, "Unable to determine sequence number from '%s'\n", get_header(req, "CSeq")); 06120 return -1; 06121 } 06122 respprep(&resp, p, msg, req); 06123 add_header_contentLength(&resp, 0); 06124 /* If we are cancelling an incoming invite for some reason, add information 06125 about the reason why we are doing this in clear text */ 06126 if (p->method == SIP_INVITE && msg[0] != '1' && p->owner && p->owner->hangupcause) { 06127 char buf[10]; 06128 06129 add_header(&resp, "X-Asterisk-HangupCause", ast_cause2str(p->owner->hangupcause)); 06130 snprintf(buf, sizeof(buf), "%d", p->owner->hangupcause); 06131 add_header(&resp, "X-Asterisk-HangupCauseCode", buf); 06132 } 06133 return send_response(p, &resp, reliable, seqno); 06134 }
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 18790 of file chan_sip.c.
| static int _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 10532 of file chan_sip.c.
References sip_peer::accountcode, sip_peer::addr, sip_peer::allowtransfer, sip_peer::amaflags, ast_callerid_merge(), ast_cdr_flags2str(), ast_check_realtime(), ast_cli(), ast_codec_pref_index(), ast_describe_caller_presentation(), ast_getformatname(), ast_getformatname_multiple(), ast_inet_ntoa(), ast_print_group(), ast_sched_when(), ast_strlen_zero(), ast_test_flag, astman_append(), astman_get_header(), astman_send_error(), ASTOBJ_UNREF, sip_peer::auth, sip_peer::autoframing, sip_peer::call_limit, sip_peer::callgroup, sip_peer::callingpres, sip_peer::capability, sip_peer::chanvars, sip_peer::cid_name, sip_peer::cid_num, sip_peer::context, sip_peer::defaddr, dtmfmode2str(), sip_peer::expire, FALSE, find_peer(), sip_peer::flags, sip_peer::fromdomain, sip_peer::fromuser, sip_peer::fullcontact, sip_peer::ha, cfsip_options::id, insecure2str(), sip_peer::language, sip_peer::lastmsg, sip_peer::lastmsgssent, sip_peer::mailbox, sip_peer::maxcallbitrate, sip_auth::md5secret, sip_peer::md5secret, ast_variable::name, sip_peer::name, nat2str(), ast_variable::next, sip_auth::next, peer_status(), sip_peer::pickupgroup, sip_peer::prefs, print_codec_to_cli(), print_group(), sip_auth::realm, sip_peer::regexten, RESULT_SHOWUSAGE, RESULT_SUCCESS, S_OR, sip_auth::secret, sip_peer::secret, SIP_CAN_REINVITE, sip_destroy_peer(), SIP_DTMF, SIP_INSECURE_INVITE, SIP_INSECURE_PORT, SIP_NAT, sip_options, SIP_PAGE2_ALLOWOVERLAP, SIP_PAGE2_ALLOWSUBSCRIBE, SIP_PAGE2_DYNAMIC, SIP_PAGE2_T38SUPPORT_RTP, SIP_PAGE2_T38SUPPORT_TCP, SIP_PAGE2_T38SUPPORT_UDPTL, SIP_PAGE2_VIDEOSUPPORT, SIP_PROMISCREDIR, SIP_REALTIME, SIP_SENDRPID, SIP_TRUSTRPID, SIP_USEREQPHONE, sip_peer::sipoptions, sip_peer::subscribecontext, text, sip_peer::tohost, transfermode2str(), TRUE, sip_peer::useragent, sip_peer::username, sip_auth::username, ast_variable::value, and sip_peer::vmexten.
Referenced by manager_sip_show_peer(), and sip_show_peer().
10533 { 10534 char status[30] = ""; 10535 char cbuf[256]; 10536 struct sip_peer *peer; 10537 char codec_buf[512]; 10538 struct ast_codec_pref *pref; 10539 struct ast_variable *v; 10540 struct sip_auth *auth; 10541 int x = 0, codec = 0, load_realtime; 10542 int realtimepeers; 10543 10544 realtimepeers = ast_check_realtime("sippeers"); 10545 10546 if (argc < 4) 10547 return RESULT_SHOWUSAGE; 10548 10549 load_realtime = (argc == 5 && !strcmp(argv[4], "load")) ? TRUE : FALSE; 10550 peer = find_peer(argv[3], NULL, load_realtime, 0); 10551 if (s) { /* Manager */ 10552 if (peer) { 10553 const char *id = astman_get_header(m,"ActionID"); 10554 10555 astman_append(s, "Response: Success\r\n"); 10556 if (!ast_strlen_zero(id)) 10557 astman_append(s, "ActionID: %s\r\n",id); 10558 } else { 10559 snprintf (cbuf, sizeof(cbuf), "Peer %s not found.", argv[3]); 10560 astman_send_error(s, m, cbuf); 10561 return 0; 10562 } 10563 } 10564 if (peer && type==0 ) { /* Normal listing */ 10565 ast_cli(fd,"\n\n"); 10566 ast_cli(fd, " * Name : %s\n", peer->name); 10567 if (realtimepeers) { /* Realtime is enabled */ 10568 ast_cli(fd, " Realtime peer: %s\n", ast_test_flag(&peer->flags[0], SIP_REALTIME) ? "Yes, cached" : "No"); 10569 } 10570 ast_cli(fd, " Secret : %s\n", ast_strlen_zero(peer->secret)?"<Not set>":"<Set>"); 10571 ast_cli(fd, " MD5Secret : %s\n", ast_strlen_zero(peer->md5secret)?"<Not set>":"<Set>"); 10572 for (auth = peer->auth; auth; auth = auth->next) { 10573 ast_cli(fd, " Realm-auth : Realm %-15.15s User %-10.20s ", auth->realm, auth->username); 10574 ast_cli(fd, "%s\n", !ast_strlen_zero(auth->secret)?"<Secret set>":(!ast_strlen_zero(auth->md5secret)?"<MD5secret set>" : "<Not set>")); 10575 } 10576 ast_cli(fd, " Context : %s\n", peer->context); 10577 ast_cli(fd, " Subscr.Cont. : %s\n", S_OR(peer->subscribecontext, "<Not set>") ); 10578 ast_cli(fd, " Language : %s\n", peer->language); 10579 if (!ast_strlen_zero(peer->accountcode)) 10580 ast_cli(fd, " Accountcode : %s\n", peer->accountcode); 10581 ast_cli(fd, " AMA flags : %s\n", ast_cdr_flags2str(peer->amaflags)); 10582 ast_cli(fd, " Transfer mode: %s\n", transfermode2str(peer->allowtransfer)); 10583 ast_cli(fd, " CallingPres : %s\n", ast_describe_caller_presentation(peer->callingpres)); 10584 if (!ast_strlen_zero(peer->fromuser)) 10585 ast_cli(fd, " FromUser : %s\n", peer->fromuser); 10586 if (!ast_strlen_zero(peer->fromdomain)) 10587 ast_cli(fd, " FromDomain : %s\n", peer->fromdomain); 10588 ast_cli(fd, " Callgroup : "); 10589 print_group(fd, peer->callgroup, 0); 10590 ast_cli(fd, " Pickupgroup : "); 10591 print_group(fd, peer->pickupgroup, 0); 10592 ast_cli(fd, " Mailbox : %s\n", peer->mailbox); 10593 ast_cli(fd, " VM Extension : %s\n", peer->vmexten); 10594 ast_cli(fd, " LastMsgsSent : %d/%d\n", (peer->lastmsgssent & 0x7fff0000) >> 16, peer->lastmsgssent & 0xffff); 10595 ast_cli(fd, " Call limit : %d\n", peer->call_limit); 10596 ast_cli(fd, " Dynamic : %s\n", (ast_test_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC)?"Yes":"No")); 10597 ast_cli(fd, " Callerid : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), peer->cid_name, peer->cid_num, "<unspecified>")); 10598 ast_cli(fd, " MaxCallBR : %d kbps\n", peer->maxcallbitrate); 10599 ast_cli(fd, " Expire : %ld\n", ast_sched_when(sched, peer->expire)); 10600 ast_cli(fd, " Insecure : %s\n", insecure2str(ast_test_flag(&peer->flags[0], SIP_INSECURE_PORT), ast_test_flag(&peer->flags[0], SIP_INSECURE_INVITE))); 10601 ast_cli(fd, " Nat : %s\n", nat2str(ast_test_flag(&peer->flags[0], SIP_NAT))); 10602 ast_cli(fd, " ACL : %s\n", (peer->ha?"Yes":"No")); 10603 ast_cli(fd, " T38 pt UDPTL : %s\n", ast_test_flag(&peer->flags[1], SIP_PAGE2_T38SUPPORT_UDPTL)?"Yes":"No"); 10604 #ifdef WHEN_WE_HAVE_T38_FOR_OTHER_TRANSPORTS 10605 ast_cli(fd, " T38 pt RTP : %s\n", ast_test_flag(&peer->flags[1], SIP_PAGE2_T38SUPPORT_RTP)?"Yes":"No"); 10606 ast_cli(fd, " T38 pt TCP : %s\n", ast_test_flag(&peer->flags[1], SIP_PAGE2_T38SUPPORT_TCP)?"Yes":"No"); 10607 #endif 10608 ast_cli(fd, " CanReinvite : %s\n", ast_test_flag(&peer->flags[0], SIP_CAN_REINVITE)?"Yes":"No"); 10609 ast_cli(fd, " PromiscRedir : %s\n", ast_test_flag(&peer->flags[0], SIP_PROMISCREDIR)?"Yes":"No"); 10610 ast_cli(fd, " User=Phone : %s\n", ast_test_flag(&peer->flags[0], SIP_USEREQPHONE)?"Yes":"No"); 10611 ast_cli(fd, " Video Support: %s\n", ast_test_flag(&peer->flags[1], SIP_PAGE2_VIDEOSUPPORT)?"Yes":"No"); 10612 ast_cli(fd, " Trust RPID : %s\n", ast_test_flag(&peer->flags[0], SIP_TRUSTRPID) ? "Yes" : "No"); 10613 ast_cli(fd, " Send RPID : %s\n", ast_test_flag(&peer->flags[0], SIP_SENDRPID) ? "Yes" : "No"); 10614 ast_cli(fd, " Subscriptions: %s\n", ast_test_flag(&peer->flags[1], SIP_PAGE2_ALLOWSUBSCRIBE) ? "Yes" : "No"); 10615 ast_cli(fd, " Overlap dial : %s\n", ast_test_flag(&peer->flags[1], SIP_PAGE2_ALLOWOVERLAP) ? "Yes" : "No"); 10616 10617 /* - is enumerated */ 10618 ast_cli(fd, " DTMFmode : %s\n", dtmfmode2str(ast_test_flag(&peer->flags[0], SIP_DTMF))); 10619 ast_cli(fd, " LastMsg : %d\n", peer->lastmsg); 10620 ast_cli(fd, " ToHost : %s\n", peer->tohost); 10621 ast_cli(fd, " Addr->IP : %s Port %d\n", peer->addr.sin_addr.s_addr ? ast_inet_ntoa(peer->addr.sin_addr) : "(Unspecified)", ntohs(peer->addr.sin_port)); 10622 ast_cli(fd, " Defaddr->IP : %s Port %d\n", ast_inet_ntoa(peer->defaddr.sin_addr), ntohs(peer->defaddr.sin_port)); 10623 if (!ast_strlen_zero(global_regcontext)) 10624 ast_cli(fd, " Reg. exten : %s\n", peer->regexten); 10625 ast_cli(fd, " Def. Username: %s\n", peer->username); 10626 ast_cli(fd, " SIP Options : "); 10627 if (peer->sipoptions) { 10628 int lastoption = -1; 10629 for (x=0 ; (x < (sizeof(sip_options) / sizeof(sip_options[0]))); x++) { 10630 if (sip_options[x].id != lastoption) { 10631 if (peer->sipoptions & sip_options[x].id) 10632 ast_cli(fd, "%s ", sip_options[x].text); 10633 lastoption = x; 10634 } 10635 } 10636 } else 10637 ast_cli(fd, "(none)"); 10638 10639 ast_cli(fd, "\n"); 10640 ast_cli(fd, " Codecs : "); 10641 ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, peer->capability); 10642 ast_cli(fd, "%s\n", codec_buf); 10643 ast_cli(fd, " Codec Order : ("); 10644 print_codec_to_cli(fd, &peer->prefs); 10645 ast_cli(fd, ")\n"); 10646 10647 ast_cli(fd, " Auto-Framing: %s \n", peer->autoframing ? "Yes" : "No"); 10648 ast_cli(fd, " Status : "); 10649 peer_status(peer, status, sizeof(status)); 10650 ast_cli(fd, "%s\n",status); 10651 ast_cli(fd, " Useragent : %s\n", peer->useragent); 10652 ast_cli(fd, " Reg. Contact : %s\n", peer->fullcontact); 10653 if (peer->chanvars) { 10654 ast_cli(fd, " Variables :\n"); 10655 for (v = peer->chanvars ; v ; v = v->next) 10656 ast_cli(fd, " %s = %s\n", v->name, v->value); 10657 } 10658 ast_cli(fd,"\n"); 10659 ASTOBJ_UNREF(peer,sip_destroy_peer); 10660 } else if (peer && type == 1) { /* manager listing */ 10661 char buf[256]; 10662 astman_append(s, "Channeltype: SIP\r\n"); 10663 astman_append(s, "ObjectName: %s\r\n", peer->name); 10664 astman_append(s, "ChanObjectType: peer\r\n"); 10665 astman_append(s, "SecretExist: %s\r\n", ast_strlen_zero(peer->secret)?"N":"Y"); 10666 astman_append(s, "MD5SecretExist: %s\r\n", ast_strlen_zero(peer->md5secret)?"N":"Y"); 10667 astman_append(s, "Context: %s\r\n", peer->context); 10668 astman_append(s, "Language: %s\r\n", peer->language); 10669 if (!ast_strlen_zero(peer->accountcode)) 10670 astman_append(s, "Accountcode: %s\r\n", peer->accountcode); 10671 astman_append(s, "AMAflags: %s\r\n", ast_cdr_flags2str(peer->amaflags)); 10672 astman_append(s, "CID-CallingPres: %s\r\n", ast_describe_caller_presentation(peer->callingpres)); 10673 if (!ast_strlen_zero(peer->fromuser)) 10674 astman_append(s, "SIP-FromUser: %s\r\n", peer->fromuser); 10675 if (!ast_strlen_zero(peer->fromdomain)) 10676 astman_append(s, "SIP-FromDomain: %s\r\n", peer->fromdomain); 10677 astman_append(s, "Callgroup: "); 10678 astman_append(s, "%s\r\n", ast_print_group(buf, sizeof(buf), peer->callgroup)); 10679 astman_append(s, "Pickupgroup: "); 10680 astman_append(s, "%s\r\n", ast_print_group(buf, sizeof(buf), peer->pickupgroup)); 10681 astman_append(s, "VoiceMailbox: %s\r\n", peer->mailbox); 10682 astman_append(s, "TransferMode: %s\r\n", transfermode2str(peer->allowtransfer)); 10683 astman_append(s, "LastMsgsSent: %d\r\n", peer->lastmsgssent); 10684 astman_append(s, "Call-limit: %d\r\n", peer->call_limit); 10685 astman_append(s, "MaxCallBR: %d kbps\r\n", peer->maxcallbitrate); 10686 astman_append(s, "Dynamic: %s\r\n", (ast_test_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC)?"Y":"N")); 10687 astman_append(s, "Callerid: %s\r\n", ast_callerid_merge(cbuf, sizeof(cbuf), peer->cid_name, peer->cid_num, "")); 10688 astman_append(s, "RegExpire: %ld seconds\r\n", ast_sched_when(sched,peer->expire)); 10689 astman_append(s, "SIP-AuthInsecure: %s\r\n", insecure2str(ast_test_flag(&peer->flags[0], SIP_INSECURE_PORT), ast_test_flag(&peer->flags[0], SIP_INSECURE_INVITE))); 10690 astman_append(s, "SIP-NatSupport: %s\r\n", nat2str(ast_test_flag(&peer->flags[0], SIP_NAT))); 10691 astman_append(s, "ACL: %s\r\n", (peer->ha?"Y":"N")); 10692 astman_append(s, "SIP-CanReinvite: %s\r\n", (ast_test_flag(&peer->flags[0], SIP_CAN_REINVITE)?"Y":"N")); 10693 astman_append(s, "SIP-PromiscRedir: %s\r\n", (ast_test_flag(&peer->flags[0], SIP_PROMISCREDIR)?"Y":"N")); 10694 astman_append(s, "SIP-UserPhone: %s\r\n", (ast_test_flag(&peer->flags[0], SIP_USEREQPHONE)?"Y":"N")); 10695 astman_append(s, "SIP-VideoSupport: %s\r\n", (ast_test_flag(&peer->flags[1], SIP_PAGE2_VIDEOSUPPORT)?"Y":"N")); 10696 10697 /* - is enumerated */ 10698 astman_append(s, "SIP-DTMFmode: %s\r\n", dtmfmode2str(ast_test_flag(&peer->flags[0], SIP_DTMF))); 10699 astman_append(s, "SIPLastMsg: %d\r\n", peer->lastmsg); 10700 astman_append(s, "ToHost: %s\r\n", peer->tohost); 10701 astman_append(s, "Address-IP: %s\r\nAddress-Port: %d\r\n", peer->addr.sin_addr.s_addr ? ast_inet_ntoa(peer->addr.sin_addr) : "", ntohs(peer->addr.sin_port)); 10702 astman_append(s, "Default-addr-IP: %s\r\nDefault-addr-port: %d\r\n", ast_inet_ntoa(peer->defaddr.sin_addr), ntohs(peer->defaddr.sin_port)); 10703 astman_append(s, "Default-Username: %s\r\n", peer->username); 10704 if (!ast_strlen_zero(global_regcontext)) 10705 astman_append(s, "RegExtension: %s\r\n", peer->regexten); 10706 astman_append(s, "Codecs: "); 10707 ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, peer->capability); 10708 astman_append(s, "%s\r\n", codec_buf); 10709 astman_append(s, "CodecOrder: "); 10710 pref = &peer->prefs; 10711 for(x = 0; x < 32 ; x++) { 10712 codec = ast_codec_pref_index(pref,x); 10713 if (!codec) 10714 break; 10715 astman_append(s, "%s", ast_getformatname(codec)); 10716 if (x < 31 && ast_codec_pref_index(pref,x+1)) 10717 astman_append(s, ","); 10718 } 10719 10720 astman_append(s, "\r\n"); 10721 astman_append(s, "Status: "); 10722 peer_status(peer, status, sizeof(status)); 10723 astman_append(s, "%s\r\n", status); 10724 astman_append(s, "SIP-Useragent: %s\r\n", peer->useragent); 10725 astman_append(s, "Reg-Contact : %s\r\n", peer->fullcontact); 10726 if (peer->chanvars) { 10727 for (v = peer->chanvars ; v ; v = v->next) { 10728 astman_append(s, "ChanVariable:\n"); 10729 astman_append(s, " %s,%s\r\n", v->name, v->value); 10730 } 10731 } 10732 10733 ASTOBJ_UNREF(peer,sip_destroy_peer); 10734 10735 } else { 10736 ast_cli(fd,"Peer %s not found.\n", argv[3]); 10737 ast_cli(fd,"\n"); 10738 } 10739 10740 return RESULT_SUCCESS; 10741 }
| static int _sip_show_peers | ( | int | fd, | |
| int * | total, | |||
| struct mansession * | s, | |||
| const struct message * | m, | |||
| int | argc, | |||
| const char * | argv[] | |||
| ) | [static] |
_sip_show_peers: Execute sip show peers command
Definition at line 10082 of file chan_sip.c.
References ast_check_realtime(), ast_cli(), ast_copy_string(), ast_inet_ntoa(), ast_strlen_zero(), ast_test_flag, astman_append(), astman_get_header(), ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_RDLOCK, ASTOBJ_UNLOCK, FALSE, FORMAT, FORMAT2, id, name, peer_status(), peerl, RESULT_SHOWUSAGE, RESULT_SUCCESS, SIP_NAT_ROUTE, SIP_PAGE2_DYNAMIC, SIP_PAGE2_VIDEOSUPPORT, SIP_REALTIME, and TRUE.
Referenced by manager_sip_show_peers(), and sip_show_peers().
10083 { 10084 regex_t regexbuf; 10085 int havepattern = FALSE; 10086 10087 #define FORMAT2 "%-25.25s %-15.15s %-3.3s %-3.3s %-3.3s %-8s %-10s %-10s\n" 10088 #define FORMAT "%-25.25s %-15.15s %-3.3s %-3.3s %-3.3s %-8d %-10s %-10s\n" 10089 10090 char name[256]; 10091 int total_peers = 0; 10092 int peers_mon_online = 0; 10093 int peers_mon_offline = 0; 10094 int peers_unmon_offline = 0; 10095 int peers_unmon_online = 0; 10096 const char *id; 10097 char idtext[256] = ""; 10098 int realtimepeers; 10099 10100 realtimepeers = ast_check_realtime("sippeers"); 10101 10102 if (s) { /* Manager - get ActionID */ 10103 id = astman_get_header(m,"ActionID"); 10104 if (!ast_strlen_zero(id)) 10105 snprintf(idtext, sizeof(idtext), "ActionID: %s\r\n", id); 10106 } 10107 10108 switch (argc) { 10109 case 5: 10110 if (!strcasecmp(argv[3], "like")) { 10111 if (regcomp(®exbuf, argv[4], REG_EXTENDED | REG_NOSUB)) 10112 return RESULT_SHOWUSAGE; 10113 havepattern = TRUE; 10114 } else 10115 return RESULT_SHOWUSAGE; 10116 case 3: 10117 break; 10118 default: 10119 return RESULT_SHOWUSAGE; 10120 } 10121 10122 if (!s) /* Normal list */ 10123 ast_cli(fd, FORMAT2, "Name/username", "Host", "Dyn", "Nat", "ACL", "Port", "Status", (realtimepeers ? "Realtime" : "")); 10124 10125 ASTOBJ_CONTAINER_TRAVERSE(&peerl, 1, do { 10126 char status[20] = ""; 10127 char srch[2000]; 10128 char pstatus; 10129 10130 ASTOBJ_RDLOCK(iterator); 10131 10132 if (havepattern && regexec(®exbuf, iterator->name, 0, NULL, 0)) { 10133 ASTOBJ_UNLOCK(iterator); 10134 continue; 10135 } 10136 10137 if (!ast_strlen_zero(iterator->username) && !s) 10138 snprintf(name, sizeof(name), "%s/%s", iterator->name, iterator->username); 10139 else 10140 ast_copy_string(name, iterator->name, sizeof(name)); 10141 10142 pstatus = peer_status(iterator, status, sizeof(status)); 10143 if (pstatus == 1) 10144 peers_mon_online++; 10145 else if (pstatus == 0) 10146 peers_mon_offline++; 10147 else { 10148 if (iterator->addr.sin_port == 0) 10149 peers_unmon_offline++; 10150 else 10151 peers_unmon_online++; 10152 } 10153 10154 snprintf(srch, sizeof(srch), FORMAT, name, 10155 iterator->addr.sin_addr.s_addr ? ast_inet_ntoa(iterator->addr.sin_addr) : "(Unspecified)", 10156 ast_test_flag(&iterator->flags[1], SIP_PAGE2_DYNAMIC) ? " D " : " ", /* Dynamic or not? */ 10157 ast_test_flag(&iterator->flags[0], SIP_NAT_ROUTE) ? " N " : " ", /* NAT=yes? */ 10158 iterator->ha ? " A " : " ", /* permit/deny */ 10159 ntohs(iterator->addr.sin_port), status, 10160 realtimepeers ? (ast_test_flag(&iterator->flags[0], SIP_REALTIME) ? "Cached RT":"") : ""); 10161 10162 if (!s) {/* Normal CLI list */ 10163 ast_cli(fd, FORMAT, name, 10164 iterator->addr.sin_addr.s_addr ? ast_inet_ntoa(iterator->addr.sin_addr) : "(Unspecified)", 10165 ast_test_flag(&iterator->flags[1], SIP_PAGE2_DYNAMIC) ? " D " : " ", /* Dynamic or not? */ 10166 ast_test_flag(&iterator->flags[0], SIP_NAT_ROUTE) ? " N " : " ", /* NAT=yes? */ 10167 iterator->ha ? " A " : " ", /* permit/deny */ 10168 10169 ntohs(iterator->addr.sin_port), status, 10170 realtimepeers ? (ast_test_flag(&iterator->flags[0], SIP_REALTIME) ? "Cached RT":"") : ""); 10171 } else { /* Manager format */ 10172 /* The names here need to be the same as other channels */ 10173 astman_append(s, 10174 "Event: PeerEntry\r\n%s" 10175 "Channeltype: SIP\r\n" 10176 "ObjectName: %s\r\n" 10177 "ChanObjectType: peer\r\n" /* "peer" or "user" */ 10178 "IPaddress: %s\r\n" 10179 "IPport: %d\r\n" 10180 "Dynamic: %s\r\n" 10181 "Natsupport: %s\r\n" 10182 "VideoSupport: %s\r\n" 10183 "ACL: %s\r\n" 10184 "Status: %s\r\n" 10185 "RealtimeDevice: %s\r\n\r\n", 10186 idtext, 10187 iterator->name, 10188 iterator->addr.sin_addr.s_addr ? ast_inet_ntoa(iterator->addr.sin_addr) : "-none-", 10189 ntohs(iterator->addr.sin_port), 10190 ast_test_flag(&iterator->flags[1], SIP_PAGE2_DYNAMIC) ? "yes" : "no", /* Dynamic or not? */ 10191 ast_test_flag(&iterator->flags[0], SIP_NAT_ROUTE) ? "yes" : "no", /* NAT=yes? */ 10192 ast_test_flag(&iterator->flags[1], SIP_PAGE2_VIDEOSUPPORT) ? "yes" : "no", /* VIDEOSUPPORT=yes? */ 10193 iterator->ha ? "yes" : "no", /* permit/deny */ 10194 status, 10195 realtimepeers ? (ast_test_flag(&iterator->flags[0], SIP_REALTIME) ? "yes":"no") : "no"); 10196 } 10197 10198 ASTOBJ_UNLOCK(iterator); 10199 10200 total_peers++; 10201 } while(0) ); 10202 10203 if (!s) 10204 ast_cli(fd, "%d sip peers [Monitored: %d online, %d offline Unmonitored: %d online, %d offline]\n", 10205 total_peers, peers_mon_online, peers_mon_offline, peers_unmon_online, peers_unmon_offline); 10206 10207 if (havepattern) 10208 regfree(®exbuf); 10209 10210 if (total) 10211 *total = total_peers; 10212 10213 10214 return RESULT_SUCCESS; 10215 #undef FORMAT 10216 #undef FORMAT2 10217 }
| static int acf_channel_read | ( | struct ast_channel * | chan, | |
| char * | funcname, | |||
| char * | preparse, | |||
| char * | buf, | |||
| size_t | buflen | |||
| ) | [static] |
Definition at line 15199 of file chan_sip.c.
References AST_APP_ARG, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_log(), ast_rtp_get_quality(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_rtp_quality::local_count, ast_rtp_quality::local_jitter, ast_rtp_quality::local_lostpackets, ast_rtp_quality::local_ssrc, LOG_ERROR, LOG_WARNING, parse(), ast_rtp_quality::remote_count, ast_rtp_quality::remote_jitter, ast_rtp_quality::remote_lostpackets, ast_rtp_quality::remote_ssrc, sip_pvt::rtp, ast_rtp_quality::rtt, ast_channel::tech, ast_channel::tech_pvt, type, and sip_pvt::vrtp.
15200 { 15201 struct ast_rtp_quality qos; 15202 struct sip_pvt *p = chan->tech_pvt; 15203 char *all = "", *parse = ast_strdupa(preparse); 15204 AST_DECLARE_APP_ARGS(args, 15205 AST_APP_ARG(param); 15206 AST_APP_ARG(type); 15207 AST_APP_ARG(field); 15208 ); 15209 AST_STANDARD_APP_ARGS(args, parse); 15210 15211 /* Sanity check */ 15212 if (chan->tech != &sip_tech && chan->tech != &sip_tech_info) { 15213 ast_log(LOG_ERROR, "Cannot call %s on a non-SIP channel\n", funcname); 15214 return 0; 15215 } 15216 15217 if (strcasecmp(args.param, "rtpqos")) 15218 return 0; 15219 15220 /* Default arguments of audio,all */ 15221 if (ast_strlen_zero(args.type)) 15222 args.type = "audio"; 15223 if (ast_strlen_zero(args.field)) 15224 args.field = "all"; 15225 15226 memset(buf, 0, buflen); 15227 memset(&qos, 0, sizeof(qos)); 15228 15229 if (strcasecmp(args.type, "AUDIO") == 0) { 15230 all = ast_rtp_get_quality(p->rtp, &qos); 15231 } else if (strcasecmp(args.type, "VIDEO") == 0) { 15232 all = ast_rtp_get_quality(p->vrtp, &qos); 15233 } 15234 15235 if (strcasecmp(args.field, "local_ssrc") == 0) 15236 snprintf(buf, buflen, "%u", qos.local_ssrc); 15237 else if (strcasecmp(args.field, "local_lostpackets") == 0) 15238 snprintf(buf, buflen, "%u", qos.local_lostpackets); 15239 else if (strcasecmp(args.field, "local_jitter") == 0) 15240 snprintf(buf, buflen, "%.0lf", qos.local_jitter * 1000.0); 15241 else if (strcasecmp(args.field, "local_count") == 0) 15242 snprintf(buf, buflen, "%u", qos.local_count); 15243 else if (strcasecmp(args.field, "remote_ssrc") == 0) 15244 snprintf(buf, buflen, "%u", qos.remote_ssrc); 15245 else if (strcasecmp(args.field, "remote_lostpackets") == 0) 15246 snprintf(buf, buflen, "%u", qos.remote_lostpackets); 15247 else if (strcasecmp(args.field, "remote_jitter") == 0) 15248 snprintf(buf, buflen, "%.0lf", qos.remote_jitter * 1000.0); 15249 else if (strcasecmp(args.field, "remote_count") == 0) 15250 snprintf(buf, buflen, "%u", qos.remote_count); 15251 else if (strcasecmp(args.field, "rtt") == 0) 15252 snprintf(buf, buflen, "%.0lf", qos.rtt * 1000.0); 15253 else if (strcasecmp(args.field, "all") == 0) 15254 ast_copy_string(buf, all, buflen); 15255 else { 15256 ast_log(LOG_WARNING, "Unrecognized argument '%s' to %s\n", preparse, funcname); 15257 return -1; 15258 } 15259 return 0; 15260 }
| static void add_blank | ( | struct sip_request * | req | ) | [static] |
add a blank line if no body
Definition at line 2270 of file chan_sip.c.
References sip_request::data, sip_request::len, and sip_request::lines.
Referenced by send_request(), and send_response().
02271 { 02272 if (!req->lines) { 02273 /* Add extra empty return. add_header() reserves 4 bytes so cannot be truncated */ 02274 snprintf(req->data + req->len, sizeof(req->data) - req->len, "\r\n"); 02275 req->len += strlen(req->data + req->len); 02276 } 02277 }
| static void add_codec_to_sdp | ( | const struct sip_pvt * | p, | |
| int | codec, | |||
| int | sample_rate, | |||
| char ** | m_buf, | |||
| size_t * | m_size, | |||
| char ** | a_buf, | |||
| size_t * | a_size, | |||
| int | debug, | |||
| int * | min_packet_size | |||
| ) | [static] |
Add codec offer to SDP offer/answer body in INVITE or 200 OK.
Definition at line 6318 of file chan_sip.c.
References ast_build_string(), ast_codec_pref_getsize(), AST_FORMAT_G723_1, AST_FORMAT_G729A, AST_FORMAT_ILBC, ast_getformatname(), ast_rtp_codec_getpref(), ast_rtp_lookup_code(), ast_rtp_lookup_mime_subtype(), AST_RTP_OPT_G726_NONSTANDARD, ast_test_flag, ast_verbose(), ast_format_list::cur_ms, sip_pvt::flags, sip_pvt::rtp, and SIP_G726_NONSTANDARD.
Referenced by add_sdp().
06321 { 06322 int rtp_code; 06323 struct ast_format_list fmt; 06324 06325 06326 if (debug) 06327 ast_verbose("Adding codec 0x%x (%s) to SDP\n", codec, ast_getformatname(codec)); 06328 if ((rtp_code = ast_rtp_lookup_code(p->rtp, 1, codec)) == -1) 06329 return; 06330 06331 if (p->rtp) { 06332 struct ast_codec_pref *pref = ast_rtp_codec_getpref(p->rtp); 06333 fmt = ast_codec_pref_getsize(pref, codec); 06334 } else /* I dont see how you couldn't have p->rtp, but good to check for and error out if not there like earlier code */ 06335 return; 06336 ast_build_string(m_buf, m_size, " %d", rtp_code); 06337 ast_build_string(a_buf, a_size, "a=rtpmap:%d %s/%d\r\n", rtp_code, 06338 ast_rtp_lookup_mime_subtype(1, codec, 06339 ast_test_flag(&p->flags[0], SIP_G726_NONSTANDARD) ? AST_RTP_OPT_G726_NONSTANDARD : 0), 06340 sample_rate); 06341 if (codec == AST_FORMAT_G729A) { 06342 /* Indicate that we don't support VAD (G.729 annex B) */ 06343 ast_build_string(a_buf, a_size, "a=fmtp:%d annexb=no\r\n", rtp_code); 06344 } else if (codec == AST_FORMAT_G723_1) { 06345 /* Indicate that we don't support VAD (G.723.1 annex A) */ 06346 ast_build_string(a_buf, a_size, "a=fmtp:%d annexa=no\r\n", rtp_code); 06347 } else if (codec == AST_FORMAT_ILBC) { 06348 /* Add information about us using only 20/30 ms packetization */ 06349 ast_build_string(a_buf, a_size, "a=fmtp:%d mode=%d\r\n", rtp_code, fmt.cur_ms); 06350 } 06351 06352 if (fmt.cur_ms && (fmt.cur_ms < *min_packet_size)) 06353 *min_packet_size = fmt.cur_ms; 06354 06355 /* Our first codec packetization processed cannot be less than zero */ 06356 if ((*min_packet_size) == 0 && fmt.cur_ms) 06357 *min_packet_size = fmt.cur_ms; 06358 }
| static int add_digit | ( | struct sip_request * | req, | |
| char | digit, | |||
| unsigned int | duration | |||
| ) | [static] |
Add DTMF INFO tone to sip message.
Definition at line 6286 of file chan_sip.c.
References add_header(), add_header_contentLength(), and add_line().
Referenced by transmit_info_with_digit().
06287 { 06288 char tmp[256]; 06289 06290 snprintf(tmp, sizeof(tmp), "Signal=%c\r\nDuration=%u\r\n", digit, duration); 06291 add_header(req, "Content-Type", "application/dtmf-relay"); 06292 add_header_contentLength(req, strlen(tmp)); 06293 add_line(req, tmp); 06294 return 0; 06295 }
| static int add_header | ( | struct sip_request * | req, | |
| const char * | var, | |||
| const char * | value | |||
| ) | [static] |
Add header to SIP message.
Definition at line 5677 of file chan_sip.c.
References ast_log(), sip_request::data, find_alias(), sip_request::header, sip_request::headers, sip_request::len, sip_request::lines, LOG_WARNING, and SIP_MAX_HEADERS.
Referenced by __transmit_response(), add_digit(), add_header_contentLength(), add_route(), add_sdp(), add_t38_sdp(), add_text(), add_vidupdate(), append_date(), copy_all_header(), copy_header(), copy_via_headers(), initreqprep(), reqprep(), respprep(), sip_notify(), transmit_invite(), transmit_notify_with_mwi(), transmit_notify_with_sipfrag(), transmit_refer(), transmit_register(), transmit_reinvite_with_sdp(), transmit_reinvite_with_t38_sdp(), transmit_request_with_auth(), transmit_response_with_allow(), transmit_response_with_auth(), transmit_response_with_unsupported(), and transmit_state_notify().
05678 { 05679 int maxlen = sizeof(req->data) - 4 - req->len; /* 4 bytes are for two \r\n ? */ 05680 05681 if (req->headers == SIP_MAX_HEADERS) { 05682 ast_log(LOG_WARNING, "Out of SIP header space\n"); 05683 return -1; 05684 } 05685 05686 if (req->lines) { 05687 ast_log(LOG_WARNING, "Can't add more headers when lines have been added\n"); 05688 return -1; 05689 } 05690 05691 if (maxlen <= 0) { 05692 ast_log(LOG_WARNING, "Out of space, can't add anymore (%s:%s)\n", var, value); 05693 return -1; 05694 } 05695 05696 req->header[req->headers] = req->data + req->len; 05697 05698 if (compactheaders) 05699 var = find_alias(var, var); 05700 05701 snprintf(req->header[req->headers], maxlen, "%s: %s\r\n", var, value); 05702 req->len += strlen(req->header[req->headers]); 05703 req->headers++; 05704 05705 return 0; 05706 }
| static int add_header_contentLength | ( | struct sip_request * | req, | |
| int | len | |||
| ) | [static] |
Add 'Content-Length' header to SIP message.
Definition at line 5709 of file chan_sip.c.
References add_header().
Referenced by __transmit_response(), add_digit(), add_sdp(), add_t38_sdp(), add_text(), add_vidupdate(), transmit_invite(), transmit_notify_with_mwi(), transmit_notify_with_sipfrag(), transmit_register(), transmit_request(), transmit_request_with_auth(), transmit_response_with_allow(), transmit_response_with_auth(), transmit_response_with_date(), transmit_response_with_unsupported(), and transmit_state_notify().
05710 { 05711 char clen[10]; 05712 05713 snprintf(clen, sizeof(clen), "%d", len); 05714 return add_header(req, "Content-Length", clen); 05715 }
| static int add_line | ( | struct sip_request * | req, | |
| const char * | line | |||
| ) | [static] |
Add content (not header) to SIP message.
Definition at line 5718 of file chan_sip.c.
References ast_log(), sip_request::data, sip_request::len, sip_request::line, sip_request::lines, LOG_WARNING, and SIP_MAX_LINES.
Referenced by add_digit(), add_sdp(), add_t38_sdp(), add_text(), add_vidupdate(), transmit_notify_with_mwi(), transmit_notify_with_sipfrag(), and transmit_state_notify().
05719 { 05720 if (req->lines == SIP_MAX_LINES) { 05721 ast_log(LOG_WARNING, "Out of SIP line space\n"); 05722 return -1; 05723 } 05724 if (!req->lines) { 05725 /* Add extra empty return */ 05726 snprintf(req->data + req->len, sizeof(req->data) - req->len, "\r\n"); 05727 req->len += strlen(req->data + req->len); 05728 } 05729 if (req->len >= sizeof(req->data) - 4) { 05730 ast_log(LOG_WARNING, "Out of space, can't add anymore\n"); 05731 return -1; 05732 } 05733 req->line[req->lines] = req->data + req->len; 05734 snprintf(req->line[req->lines], sizeof(req->data) - req->len, "%s", line); 05735 req->len += strlen(req->line[req->lines]); 05736 req->lines++; 05737 return 0; 05738 }
| static void add_noncodec_to_sdp | ( | const struct sip_pvt * | p, | |
| int | format, | |||
| int | sample_rate, | |||
| char ** | m_buf, | |||
| size_t * | m_size, | |||
| char ** | a_buf, | |||
| size_t * | a_size, | |||
| int | debug | |||
| ) | [static] |
Add RFC 2833 DTMF offer to SDP.
Definition at line 6494 of file chan_sip.c.
References ast_build_string(), AST_RTP_DTMF, ast_rtp_lookup_code(), ast_rtp_lookup_mime_subtype(), ast_verbose(), and sip_pvt::rtp.
Referenced by add_sdp().
06497 { 06498 int rtp_code; 06499 06500 if (debug) 06501 ast_verbose("Adding non-codec 0x%x (%s) to SDP\n", format, ast_rtp_lookup_mime_subtype(0, format, 0)); 06502 if ((rtp_code = ast_rtp_lookup_code(p->rtp, 0, format)) == -1) 06503 return; 06504 06505 ast_build_string(m_buf, m_size, " %d", rtp_code); 06506 ast_build_string(a_buf, a_size, "a=rtpmap:%d %s/%d\r\n", rtp_code, 06507 ast_rtp_lookup_mime_subtype(0, format, 0), 06508 sample_rate); 06509 if (format == AST_RTP_DTMF) 06510 /* Indicate we support DTMF and FLASH... */ 06511 ast_build_string(a_buf, a_size, "a=fmtp:%d 0-16\r\n", rtp_code); 06512 }
| static struct sip_auth * add_realm_authentication | ( | struct sip_auth * | authlist, | |
| char * | configuration, | |||
| int | lineno | |||
| ) | [static, read] |
Add realm authentication in list.
Definition at line 16843 of file chan_sip.c.
References ast_calloc, ast_copy_string(), ast_log(), ast_strlen_zero(), ast_verbose(), LOG_DEBUG, LOG_WARNING, sip_auth::md5secret, sip_auth::next, option_debug, option_verbose, sip_auth::realm, sip_auth::secret, secret, sip_auth::username, and username.
Referenced by build_peer(), and reload_config().
16844 { 16845 char authcopy[256]; 16846 char *username=NULL, *realm=NULL, *secret=NULL, *md5secret=NULL; 16847 char *stringp; 16848 struct sip_auth *a, *b, *auth; 16849 16850 if (ast_strlen_zero(configuration)) 16851 return authlist; 16852 16853 if (option_debug) 16854 ast_log(LOG_DEBUG, "Auth config :: %s\n", configuration); 16855 16856 ast_copy_string(authcopy, configuration, sizeof(authcopy)); 16857 stringp = authcopy; 16858 16859 username = stringp; 16860 realm = strrchr(stringp, '@'); 16861 if (realm) 16862 *realm++ = '\0'; 16863 if (ast_strlen_zero(username) || ast_strlen_zero(realm)) { 16864 ast_log(LOG_WARNING, "Format for authentication entry is user[:secret]@realm at line %d\n", lineno); 16865 return authlist; 16866 } 16867 stringp = username; 16868 username = strsep(&stringp, ":"); 16869 if (username) { 16870 secret = strsep(&stringp, ":"); 16871 if (!secret) { 16872 stringp = username; 16873 md5secret = strsep(&stringp,"#"); 16874 } 16875 } 16876 if (!(auth = ast_calloc(1, sizeof(*auth)))) 16877 return authlist; 16878 16879 ast_copy_string(auth->realm, realm, sizeof(auth->realm)); 16880 ast_copy_string(auth->username, username, sizeof(auth->username)); 16881 if (secret) 16882 ast_copy_string(auth->secret, secret, sizeof(auth->secret)); 16883 if (md5secret) 16884 ast_copy_string(auth->md5secret, md5secret, sizeof(auth->md5secret)); 16885 16886 /* find the end of the list */ 16887 for (b = NULL, a = authlist; a ; b = a, a = a->next) 16888 ; 16889 if (b) 16890 b->next = auth; /* Add structure add end of list */ 16891 else 16892 authlist = auth; 16893 16894 if (option_verbose > 2) 16895 ast_verbose("Added authentication for realm %s\n", realm); 16896 16897 return authlist; 16898 16899 }
| static void add_route | ( | struct sip_request * | req, | |
| struct sip_route * | route | |||
| ) | [static] |
Add route header into request per learned route.
Definition at line 5839 of file chan_sip.c.
References add_header(), ast_copy_string(), sip_route::hop, sip_route::next, and SIPBUFSIZE.
Referenced by reqprep().
05840 { 05841 char r[SIPBUFSIZE*2], *p; 05842 int n, rem = sizeof(r); 05843 05844 if (!route) 05845 return; 05846 05847 p = r; 05848 for (;route ; route = route->next) { 05849 n = strlen(route->hop); 05850 if (rem < n+3) /* we need room for ",<route>" */ 05851 break; 05852 if (p != r) { /* add a separator after fist route */ 05853 *p++ = ','; 05854 --rem; 05855 } 05856 *p++ = '<'; 05857 ast_copy_string(p, route->hop, rem); /* cannot fail */ 05858 p += n; 05859 *p++ = '>'; 05860 rem -= (n+2); 05861 } 05862 *p = '\0'; 05863 add_header(req, "Route", r); 05864 }
| static enum sip_result add_sdp | ( | struct sip_request * | resp, | |
| struct sip_pvt * | p | |||
| ) | [static] |
Add Session Description Protocol message.
Definition at line 6522 of file chan_sip.c.
References add_codec_to_sdp(), add_header(), add_header_contentLength(), add_line(), add_noncodec_to_sdp(), ast_build_string(), ast_codec_pref_index(), AST_FAILURE, AST_FORMAT_AUDIO_MASK, AST_FORMAT_MAX_AUDIO, AST_FORMAT_MAX_VIDEO, AST_FORMAT_VIDEO_MASK, ast_getformatname_multiple(), ast_inet_ntoa(), ast_internal_timing_enabled(), ast_log(), ast_rtp_get_us(), AST_RTP_MAX, AST_SUCCESS, ast_test_flag, ast_verbose(), capability, debug, FALSE, sip_pvt::flags, sip_pvt::jointcapability, sip_pvt::jointnoncodeccapability, sip_pvt::lastrtprx, sip_pvt::lastrtptx, len(), LOG_DEBUG, LOG_WARNING, sip_pvt::maxcallbitrate, option_debug, sip_pvt::ourip, sip_pvt::owner, sip_pvt::prefcodec, sip_pvt::prefs, sip_pvt::redirip, sip_pvt::rtp, SDP_SAMPLE_RATE, sip_pvt::sessionid, sip_pvt::sessionversion, sip_debug_test_pvt(), SIP_NOVIDEO, SIP_PAGE2_CALL_ONHOLD, SIP_PAGE2_CALL_ONHOLD_INACTIVE, SIP_PAGE2_CALL_ONHOLD_ONEDIR, SIP_PAGE2_T38SUPPORT_RTP, SIPBUFSIZE, sip_pvt::t38, t38properties::t38support, TRUE, sip_pvt::vredirip, and sip_pvt::vrtp.
Referenced by transmit_invite(), transmit_reinvite_with_sdp(), and transmit_response_with_sdp().
06523 { 06524 int len = 0; 06525 int alreadysent = 0; 06526 06527 struct sockaddr_in sin; 06528 struct sockaddr_in vsin; 06529 struct sockaddr_in dest; 06530 struct sockaddr_in vdest = { 0, }; 06531 06532 /* SDP fields */ 06533 char *version = "v=0\r\n"; /* Protocol version */ 06534 char *subject = "s=session\r\n"; /* Subject of the session */ 06535 char owner[256]; /* Session owner/creator */ 06536 char connection[256]; /* Connection data */ 06537 char *stime = "t=0 0\r\n"; /* Time the session is active */ 06538 char bandwidth[256] = ""; /* Max bitrate */ 06539 char *hold; 06540 char m_audio[256]; /* Media declaration line for audio */ 06541 char m_video[256]; /* Media declaration line for video */ 06542 char a_audio[1024]; /* Attributes for audio */ 06543 char a_video[1024]; /* Attributes for video */ 06544 char *m_audio_next = m_audio; 06545 char *m_video_next = m_video; 06546 size_t m_audio_left = sizeof(m_audio); 06547 size_t m_video_left = sizeof(m_video); 06548 char *a_audio_next = a_audio; 06549 char *a_video_next = a_video; 06550 size_t a_audio_left = sizeof(a_audio); 06551 size_t a_video_left = sizeof(a_video); 06552 06553 int x; 06554 int capability; 06555 int needvideo = FALSE; 06556 int debug = sip_debug_test_pvt(p); 06557 int min_audio_packet_size = 0; 06558 int min_video_packet_size = 0; 06559 06560 m_video[0] = '\0'; /* Reset the video media string if it's not needed */ 06561 06562 if (!p->rtp) { 06563 ast_log(LOG_WARNING, "No way to add SDP without an RTP structure\n"); 06564 return AST_FAILURE; 06565 } 06566 06567 /* Set RTP Session ID and version */ 06568 if (!p->sessionid) { 06569 p->sessionid = getpid(); 06570 p->sessionversion = p->sessionid; 06571 } else 06572 p->sessionversion++; 06573 06574 /* Get our addresses */ 06575 ast_rtp_get_us(p->rtp, &sin); 06576 if (p->vrtp) 06577 ast_rtp_get_us(p->vrtp, &vsin); 06578 06579 /* Is this a re-invite to move the media out, then use the original offer from caller */ 06580 if (p->redirip.sin_addr.s_addr) { 06581 dest.sin_port = p->redirip.sin_port; 06582 dest.sin_addr = p->redirip.sin_addr; 06583 } else { 06584 dest.sin_addr = p->ourip; 06585 dest.sin_port = sin.sin_port; 06586 } 06587 06588 capability = p->jointcapability; 06589 06590 06591 if (option_debug > 1) { 06592 char codecbuf[SIPBUFSIZE]; 06593 ast_log(LOG_DEBUG, "** Our capability: %s Video flag: %s\n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), capability), ast_test_flag(&p->flags[0], SIP_NOVIDEO) ? "True" : "False"); 06594 ast_log(LOG_DEBUG, "** Our prefcodec: %s \n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), p->prefcodec)); 06595 } 06596 06597 #ifdef WHEN_WE_HAVE_T38_FOR_OTHER_TRANSPORTS 06598 if (ast_test_flag(&p->t38.t38support, SIP_PAGE2_T38SUPPORT_RTP)) { 06599 ast_build_string(&m_audio_next, &m_audio_left, " %d", 191); 06600 ast_build_string(&a_audio_next, &a_audio_left, "a=rtpmap:%d %s/%d\r\n", 191, "t38", 8000); 06601 } 06602 #endif 06603 06604 /* Check if we need video in this call */ 06605 if ((capability & AST_FORMAT_VIDEO_MASK) && !ast_test_flag(&p->flags[0], SIP_NOVIDEO)) { 06606 if (p->vrtp) { 06607 needvideo = TRUE; 06608 if (option_debug > 1) 06609 ast_log(LOG_DEBUG, "This call needs video offers!\n"); 06610 } else if (option_debug > 1) 06611 ast_log(LOG_DEBUG, "This call needs video offers, but there's no video support enabled!\n"); 06612 } 06613 06614 06615 /* Ok, we need video. Let's add what we need for video and set codecs. 06616 Video is handled differently than audio since we can not transcode. */ 06617 if (needvideo) { 06618 /* Determine video destination */ 06619 if (p->vredirip.sin_addr.s_addr) { 06620 vdest.sin_addr = p->vredirip.sin_addr; 06621 vdest.sin_port = p->vredirip.sin_port; 06622 } else { 06623 vdest.sin_addr = p->ourip; 06624 vdest.sin_port = vsin.sin_port; 06625 } 06626 ast_build_string(&m_video_next, &m_video_left, "m=video %d RTP/AVP", ntohs(vdest.sin_port)); 06627 06628 /* Build max bitrate string */ 06629 if (p->maxcallbitrate) 06630 snprintf(bandwidth, sizeof(bandwidth), "b=CT:%d\r\n", p->maxcallbitrate); 06631 if (debug) 06632 ast_verbose("Video is at %s port %d\n", ast_inet_ntoa(p->ourip), ntohs(vsin.sin_port)); 06633 } 06634 06635 if (debug) 06636 ast_verbose("Audio is at %s port %d\n", ast_inet_ntoa(p->ourip), ntohs(sin.sin_port)); 06637 06638 /* Start building generic SDP headers */ 06639 06640 /* We break with the "recommendation" and send our IP, in order that our 06641 peer doesn't have to ast_gethostbyname() us */ 06642 06643 snprintf(owner, sizeof(owner), "o=root %d %d IN IP4 %s\r\n", p->sessionid, p->sessionversion, ast_inet_ntoa(dest.sin_addr)); 06644 snprintf(connection, sizeof(connection), "c=IN IP4 %s\r\n", ast_inet_ntoa(dest.sin_addr)); 06645 ast_build_string(&m_audio_next, &m_audio_left, "m=audio %d RTP/AVP", ntohs(dest.sin_port)); 06646 06647 if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD) == SIP_PAGE2_CALL_ONHOLD_ONEDIR) 06648 hold = "a=recvonly\r\n"; 06649 else if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD) == SIP_PAGE2_CALL_ONHOLD_INACTIVE) 06650 hold = "a=inactive\r\n"; 06651 else 06652 hold = "a=sendrecv\r\n"; 06653 06654 /* Now, start adding audio codecs. These are added in this order: 06655 - First what was requested by the calling channel 06656 - Then preferences in order from sip.conf device config for this peer/user 06657 - Then other codecs in capabilities, including video 06658 */ 06659 06660 /* Prefer the audio codec we were requested to use, first, no matter what 06661 Note that p->prefcodec can include video codecs, so mask them out 06662 */ 06663 if (capability & p->prefcodec) { 06664 int codec = p->prefcodec & AST_FORMAT_AUDIO_MASK; 06665 06666 add_codec_to_sdp(p, codec, SDP_SAMPLE_RATE(codec), 06667 &m_audio_next, &m_audio_left, 06668 &a_audio_next, &a_audio_left, 06669 debug, &min_audio_packet_size); 06670 alreadysent |= codec; 06671 } 06672 06673 /* Start by sending our preferred audio codecs */ 06674 for (x = 0; x < 32; x++) { 06675 int codec; 06676 06677 if (!(codec = ast_codec_pref_index(&p->prefs, x))) 06678 break; 06679 06680 if (!(capability & codec)) 06681 continue; 06682 06683 if (alreadysent & codec) 06684 continue; 06685 06686 add_codec_to_sdp(p, codec, SDP_SAMPLE_RATE(codec), 06687 &m_audio_next, &m_audio_left, 06688 &a_audio_next, &a_audio_left, 06689 debug, &min_audio_packet_size); 06690 alreadysent |= codec; 06691 } 06692 06693 /* Now send any other common audio and video codecs, and non-codec formats: */ 06694 for (x = 1; x <= (needvideo ? AST_FORMAT_MAX_VIDEO : AST_FORMAT_MAX_AUDIO); x <<= 1) { 06695 if (!(capability & x)) /* Codec not requested */ 06696 continue; 06697 06698 if (alreadysent & x) /* Already added to SDP */ 06699 continue; 06700 06701 if (x <= AST_FORMAT_MAX_AUDIO) 06702 add_codec_to_sdp(p, x, SDP_SAMPLE_RATE(x), 06703 &m_audio_next, &m_audio_left, 06704 &a_audio_next, &a_audio_left, 06705 debug, &min_audio_packet_size); 06706 else 06707 add_codec_to_sdp(p, x, 90000, 06708 &m_video_next, &m_video_left, 06709 &a_video_next, &a_video_left, 06710 debug, &min_video_packet_size); 06711 } 06712 06713 /* Now add DTMF RFC2833 telephony-event as a codec */ 06714 for (x = 1; x <= AST_RTP_MAX; x <<= 1) { 06715 if (!(p->jointnoncodeccapability & x)) 06716 continue; 06717 06718 add_noncodec_to_sdp(p, x, 8000, 06719 &m_audio_next, &m_audio_left, 06720 &a_audio_next, &a_audio_left, 06721 debug); 06722 } 06723 06724 if (option_debug > 2) 06725 ast_log(LOG_DEBUG, "-- Done with adding codecs to SDP\n"); 06726 06727 if (!p->owner || !ast_internal_timing_enabled(p->owner)) 06728 ast_build_string(&a_audio_next, &a_audio_left, "a=silenceSupp:off - - - -\r\n"); 06729 06730 if (min_audio_packet_size) 06731 ast_build_string(&a_audio_next, &a_audio_left, "a=ptime:%d\r\n", min_audio_packet_size); 06732 06733 if (min_video_packet_size) 06734 ast_build_string(&a_video_next, &a_video_left, "a=ptime:%d\r\n", min_video_packet_size); 06735 06736 if ((m_audio_left < 2) || (m_video_left < 2) || (a_audio_left == 0) || (a_video_left == 0)) 06737 ast_log(LOG_WARNING, "SIP SDP may be truncated due to undersized buffer!!\n"); 06738 06739 ast_build_string(&m_audio_next, &m_audio_left, "\r\n"); 06740 if (needvideo) 06741 ast_build_string(&m_video_next, &m_video_left, "\r\n"); 06742 06743 len = strlen(version) + strlen(subject) + strlen(owner) + strlen(connection) + strlen(stime) + strlen(m_audio) + strlen(a_audio) + strlen(hold); 06744 if (needvideo) /* only if video response is appropriate */ 06745 len += strlen(m_video) + strlen(a_video) + strlen(bandwidth) + strlen(hold); 06746 06747 add_header(resp, "Content-Type", "application/sdp"); 06748 add_header_contentLength(resp, len); 06749 add_line(resp, version); 06750 add_line(resp, owner); 06751 add_line(resp, subject); 06752 add_line(resp, connection); 06753 if (needvideo) /* only if video response is appropriate */ 06754 add_line(resp, bandwidth); 06755 add_line(resp, stime); 06756 add_line(resp, m_audio); 06757 add_line(resp, a_audio); 06758 add_line(resp, hold); 06759 if (needvideo) { /* only if video response is appropriate */ 06760 add_line(resp, m_video); 06761 add_line(resp, a_video); 06762 add_line(resp, hold); /* Repeat hold for the video stream */ 06763 } 06764 06765 /* Update lastrtprx when we send our SDP */ 06766 p->lastrtprx = p->lastrtptx = time(NULL); /* XXX why both ? */ 06767 06768 if (option_debug > 2) { 06769 char buf[SIPBUFSIZE]; 06770 ast_log(LOG_DEBUG, "Done building SDP. Settling with this capability: %s\n", ast_getformatname_multiple(buf, SIPBUFSIZE, capability)); 06771 } 06772 06773 return AST_SUCCESS; 06774 }
| 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 16779 of file chan_sip.c.
References ast_calloc, ast_copy_string(), AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_log(), ast_strlen_zero(), domain::context, domain::domain, LOG_DEBUG, LOG_WARNING, domain::mode, and sipdebug.
Referenced by reload_config().
16780 { 16781 struct domain *d; 16782 16783 if (ast_strlen_zero(domain)) { 16784 ast_log(LOG_WARNING, "Zero length domain.\n"); 16785 return 1; 16786 } 16787 16788 if (!(d = ast_calloc(1, sizeof(*d)))) 16789 return 0; 16790 16791 ast_copy_string(d->domain, domain, sizeof(d->domain)); 16792 16793 if (!ast_strlen_zero(context)) 16794 ast_copy_string(d->context, context, sizeof(d->context)); 16795 16796 d->mode = mode; 16797 16798 AST_LIST_LOCK(&domain_list); 16799 AST_LIST_INSERT_TAIL(&domain_list, d, list); 16800 AST_LIST_UNLOCK(&domain_list); 16801 16802 if (sipdebug) 16803 ast_log(LOG_DEBUG, "Added local SIP domain '%s'\n", domain); 16804 16805 return 1; 16806 }
| static int add_t38_sdp | ( | struct sip_request * | resp, | |
| struct sip_pvt * | p | |||
| ) | [static] |
Add T.38 Session Description Protocol message.
Definition at line 6397 of file chan_sip.c.
References add_header(), add_header_contentLength(), add_line(), ast_build_string(), ast_inet_ntoa(), ast_log(), ast_udptl_get_local_max_datagram(), ast_udptl_get_us(), t38properties::capability, debug, t38properties::jointcapability, sip_pvt::lastrtprx, sip_pvt::lastrtptx, len(), LOG_DEBUG, LOG_WARNING, sip_pvt::ourip, t38properties::peercapability, s, sip_pvt::sessionid, sip_pvt::sessionversion, sip_debug_test_pvt(), t, sip_pvt::t38, t38_get_rate(), T38FAX_FILL_BIT_REMOVAL, T38FAX_RATE_MANAGEMENT_LOCAL_TCF, T38FAX_TRANSCODING_JBIG, T38FAX_TRANSCODING_MMR, T38FAX_UDP_EC_NONE, T38FAX_UDP_EC_REDUNDANCY, T38FAX_VERSION, T38FAX_VERSION_0, T38FAX_VERSION_1, sip_pvt::udptl, and sip_pvt::udptlredirip.
Referenced by transmit_invite(), transmit_reinvite_with_t38_sdp(), and transmit_response_with_t38_sdp().
06398 { 06399 int len = 0; 06400 int x = 0; 06401 struct sockaddr_in udptlsin; 06402 char v[256] = ""; 06403 char s[256] = ""; 06404 char o[256] = ""; 06405 char c[256] = ""; 06406 char t[256] = ""; 06407 char m_modem[256]; 06408 char a_modem[1024]; 06409 char *m_modem_next = m_modem; 06410 size_t m_modem_left = sizeof(m_modem); 06411 char *a_modem_next = a_modem; 06412 size_t a_modem_left = sizeof(a_modem); 06413 struct sockaddr_in udptldest = { 0, }; 06414 int debug; 06415 06416 debug = sip_debug_test_pvt(p); 06417 len = 0; 06418 if (!p->udptl) { 06419 ast_log(LOG_WARNING, "No way to add SDP without an UDPTL structure\n"); 06420 return -1; 06421 } 06422 06423 if (!p->sessionid) { 06424 p->sessionid = getpid(); 06425 p->sessionversion = p->sessionid; 06426 } else 06427 p->sessionversion++; 06428 06429 /* Our T.38 end is */ 06430 ast_udptl_get_us(p->udptl, &udptlsin); 06431 06432 /* Determine T.38 UDPTL destination */ 06433 if (p->udptlredirip.sin_addr.s_addr) { 06434 udptldest.sin_port = p->udptlredirip.sin_port; 06435 udptldest.sin_addr = p->udptlredirip.sin_addr; 06436 } else { 06437 udptldest.sin_addr = p->ourip; 06438 udptldest.sin_port = udptlsin.sin_port; 06439 } 06440 06441 if (debug) 06442 ast_log(LOG_DEBUG, "T.38 UDPTL is at %s port %d\n", ast_inet_ntoa(p->ourip), ntohs(udptlsin.sin_port)); 06443 06444 /* We break with the "recommendation" and send our IP, in order that our 06445 peer doesn't have to ast_gethostbyname() us */ 06446 06447 if (debug) { 06448 ast_log(LOG_DEBUG, "Our T38 capability (%d), peer T38 capability (%d), joint capability (%d)\n", 06449 p->t38.capability, 06450 p->t38.peercapability, 06451 p->t38.jointcapability); 06452 } 06453 snprintf(v, sizeof(v), "v=0\r\n"); 06454 snprintf(o, sizeof(o), "o=root %d %d IN IP4 %s\r\n", p->sessionid, p->sessionversion, ast_inet_ntoa(udptldest.sin_addr)); 06455 snprintf(s, sizeof(s), "s=session\r\n"); 06456 snprintf(c, sizeof(c), "c=IN IP4 %s\r\n", ast_inet_ntoa(udptldest.sin_addr)); 06457 snprintf(t, sizeof(t), "t=0 0\r\n"); 06458 ast_build_string(&m_modem_next, &m_modem_left, "m=image %d udptl t38\r\n", ntohs(udptldest.sin_port)); 06459 06460 if ((p->t38.jointcapability & T38FAX_VERSION) == T38FAX_VERSION_0) 06461 ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxVersion:0\r\n"); 06462 if ((p->t38.jointcapability & T38FAX_VERSION) == T38FAX_VERSION_1) 06463 ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxVersion:1\r\n"); 06464 if ((x = t38_get_rate(p->t38.jointcapability))) 06465 ast_build_string(&a_modem_next, &a_modem_left, "a=T38MaxBitRate:%d\r\n",x); 06466 ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxFillBitRemoval:%d\r\n", (p->t38.jointcapability & T38FAX_FILL_BIT_REMOVAL) ? 1 : 0); 06467 ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxTranscodingMMR:%d\r\n", (p->t38.jointcapability & T38FAX_TRANSCODING_MMR) ? 1 : 0); 06468 ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxTranscodingJBIG:%d\r\n", (p->t38.jointcapability & T38FAX_TRANSCODING_JBIG) ? 1 : 0); 06469 ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxRateManagement:%s\r\n", (p->t38.jointcapability & T38FAX_RATE_MANAGEMENT_LOCAL_TCF) ? "localTCF" : "transferredTCF"); 06470 x = ast_udptl_get_local_max_datagram(p->udptl); 06471 ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxMaxBuffer:%d\r\n",x); 06472 ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxMaxDatagram:%d\r\n",x); 06473 if (p->t38.jointcapability != T38FAX_UDP_EC_NONE) 06474 ast_build_string(&a_modem_next, &a_modem_left, "a=T38FaxUdpEC:%s\r\n", (p->t38.jointcapability & T38FAX_UDP_EC_REDUNDANCY) ? "t38UDPRedundancy" : "t38UDPFEC"); 06475 len = strlen(v) + strlen(s) + strlen(o) + strlen(c) + strlen(t) + strlen(m_modem) + strlen(a_modem); 06476 add_header(resp, "Content-Type", "application/sdp"); 06477 add_header_contentLength(resp, len); 06478 add_line(resp, v); 06479 add_line(resp, o); 06480 add_line(resp, s); 06481 add_line(resp, c); 06482 add_line(resp, t); 06483 add_line(resp, m_modem); 06484 add_line(resp, a_modem); 06485 06486 /* Update lastrtprx when we send our SDP */ 06487 p->lastrtprx = p->lastrtptx = time(NULL); 06488 06489 return 0; 06490 }
| static int add_text | ( | struct sip_request * | req, | |
| const char * | text | |||
| ) | [static] |
Add text body to SIP message.
Definition at line 6275 of file chan_sip.c.
References add_header(), add_header_contentLength(), and add_line().
Referenced by transmit_message_with_text().
06276 { 06277 /* XXX Convert \n's to \r\n's XXX */ 06278 add_header(req, "Content-Type", "text/plain"); 06279 add_header_contentLength(req, strlen(text)); 06280 add_line(req, text); 06281 return 0; 06282 }
| static int add_vidupdate | ( | struct sip_request * | req | ) | [static] |
add XML encoded media control with update
Definition at line 6299 of file chan_sip.c.
References add_header(), add_header_contentLength(), and add_line().
Referenced by transmit_info_with_vidupdate().
06300 { 06301 const char *xml_is_a_huge_waste_of_space = 06302 "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n" 06303 " <media_control>\r\n" 06304 " <vc_primitive>\r\n" 06305 " <to_encoder>\r\n" 06306 " <picture_fast_update>\r\n" 06307 " </picture_fast_update>\r\n" 06308 " </to_encoder>\r\n" 06309 " </vc_primitive>\r\n" 06310 " </media_control>\r\n"; 06311 add_header(req, "Content-Type", "application/media_control+xml"); 06312 add_header_contentLength(req, strlen(xml_is_a_huge_waste_of_space)); 06313 add_line(req, xml_is_a_huge_waste_of_space); 06314 return 0; 06315 }
| static void append_date | ( | struct sip_request * | req | ) | [static] |
Append date to SIP message.
Definition at line 6222 of file chan_sip.c.
References add_header(), and t.
Referenced by transmit_invite(), transmit_response_with_date(), and transmit_response_with_unsupported().
06223 { 06224 char tmpdat[256]; 06225 struct tm tm; 06226 time_t t = time(NULL); 06227 06228 gmtime_r(&t, &tm); 06229 strftime(tmpdat, sizeof(tmpdat), "%a, %d %b %Y %T GMT", &tm); 06230 add_header(req, "Date", tmpdat); 06231 }
| static void append_history_full | ( | struct sip_pvt * | p, | |
| const char * | fmt, | |||
| ... | ||||
| ) | [static] |
Append to SIP dialog history with arg list.
Definition at line 1890 of file chan_sip.c.
References append_history_va(), ast_test_flag, sip_pvt::flags, and SIP_NO_HISTORY.
01891 { 01892 va_list ap; 01893 01894 if (!p) 01895 return; 01896 01897 if (ast_test_flag(&p->flags[0], SIP_NO_HISTORY) 01898 && !recordhistory && !dumphistory) { 01899 return; 01900 } 01901 01902 va_start(ap, fmt); 01903 append_history_va(p, fmt, ap); 01904 va_end(ap); 01905 01906 return; 01907 }
| 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 1863 of file chan_sip.c.
References ast_calloc, AST_LIST_INSERT_TAIL, AST_LIST_REMOVE_HEAD, sip_history::event, free, and MAX_HISTORY_ENTRIES.
Referenced by append_history_full().
01864 { 01865 char buf[80], *c = buf; /* max history length */ 01866 struct sip_history *hist; 01867 int l; 01868 01869 vsnprintf(buf, sizeof(buf), fmt, ap); 01870 strsep(&c, "\r\n"); /* Trim up everything after \r or \n */ 01871 l = strlen(buf) + 1; 01872 if (!(hist = ast_calloc(1, sizeof(*hist) + l))) 01873 return; 01874 if (!p->history && !(p->history = ast_calloc(1, sizeof(*p->history)))) { 01875 free(hist); 01876 return; 01877 } 01878 memcpy(hist->event, buf, l); 01879 if (p->history_entries == MAX_HISTORY_ENTRIES) { 01880 struct sip_history *oldest; 01881 oldest = AST_LIST_REMOVE_HEAD(p->history, list); 01882 p->history_entries--; 01883 free(oldest); 01884 } 01885 AST_LIST_INSERT_TAIL(p->history, hist, list); 01886 p->history_entries++; 01887 }
| 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 13450 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().
13451 { 13452 if (chan && chan->_state == AST_STATE_UP) { 13453 if (ast_test_flag(chan, AST_FLAG_MOH)) 13454 ast_moh_stop(chan); 13455 else if (chan->generatordata) 13456 ast_deactivate_generator(chan); 13457 } 13458 }
| static enum sip_result ast_sip_ouraddrfor | ( | struct in_addr * | them, | |
| struct in_addr * | us | |||
| ) | [static] |
NAT fix - decide which IP address to use for ASterisk server?
Using the localaddr structure built up with localnet statements in sip.conf apply it to their address to see if we need to substitute our externip or can get away with our internal bindaddr
Definition at line 1823 of file chan_sip.c.
References ast_apply_ha(), ast_gethostbyname(), ast_inet_ntoa(), ast_log(), ast_ouraddrfor(), AST_SUCCESS, externip, hp, LOG_DEBUG, LOG_NOTICE, and option_debug.
Referenced by sip_alloc(), sip_notify(), sip_poke_peer(), sip_request_call(), sip_send_mwi_to_peer(), transmit_register(), and transmit_response_using_temp().
01824 { 01825 struct sockaddr_in theirs, ours; 01826 01827 /* Get our local information */ 01828 ast_ouraddrfor(them, us); 01829 theirs.sin_addr = *them; 01830 ours.sin_addr = *us; 01831 01832 if (localaddr && externip.sin_addr.s_addr && 01833 (ast_apply_ha(localaddr, &theirs)) && 01834 (!global_matchexterniplocally || !ast_apply_ha(localaddr, &ours))) { 01835 if (externexpire && time(NULL) >= externexpire) { 01836 struct ast_hostent ahp; 01837 struct hostent *hp; 01838 01839 externexpire = time(NULL) + externrefresh; 01840 if ((hp = ast_gethostbyname(externhost, &ahp))) { 01841 memcpy(&externip.sin_addr, hp->h_addr, sizeof(externip.sin_addr)); 01842 } else 01843 ast_log(LOG_NOTICE, "Warning: Re-lookup of '%s' failed!\n", externhost); 01844 } 01845 *us = externip.sin_addr; 01846 if (option_debug) { 01847 ast_log(LOG_DEBUG, "Target address %s is not local, substituting externip\n", 01848 ast_inet_ntoa(*(struct in_addr *)&them->s_addr)); 01849 } 01850 } else if (bindaddr.sin_addr.s_addr) 01851 *us = bindaddr.sin_addr; 01852 return AST_SUCCESS; 01853 }
Attempt transfer of SIP call This fix for attended transfers on a local PBX.
Definition at line 13462 of file chan_sip.c.
References ast_channel::_state, ast_channel_masquerade(), ast_log(), ast_quiet_chan(), AST_SOFTHANGUP_DEV, ast_softhangup_nolock(), ast_state2str(), sip_dual::chan1, sip_dual::chan2, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, ast_channel::name, and option_debug.
Referenced by local_attended_transfer().
13463 { 13464 int res = 0; 13465 struct ast_channel *peera = NULL, 13466 *peerb = NULL, 13467 *peerc = NULL, 13468 *peerd = NULL; 13469 13470 13471 /* We will try to connect the transferee with the target and hangup 13472 all channels to the transferer */ 13473 if (option_debug > 3) { 13474 ast_log(LOG_DEBUG, "Sip transfer:--------------------\n"); 13475 if (transferer->chan1) 13476 ast_log(LOG_DEBUG, "-- Transferer to PBX channel: %s State %s\n", transferer->chan1->name, ast_state2str(transferer->chan1->_state)); 13477 else 13478 ast_log(LOG_DEBUG, "-- No transferer first channel - odd??? \n"); 13479 if (target->chan1) 13480 ast_log(LOG_DEBUG, "-- Transferer to PBX second channel (target): %s State %s\n", target->chan1->name, ast_state2str(target->chan1->_state)); 13481 else 13482 ast_log(LOG_DEBUG, "-- No target first channel ---\n"); 13483 if (transferer->chan2) 13484 ast_log(LOG_DEBUG, "-- Bridged call to transferee: %s State %s\n", transferer->chan2->name, ast_state2str(transferer->chan2->_state)); 13485 else 13486 ast_log(LOG_DEBUG, "-- No bridged call to transferee\n"); 13487 if (target->chan2) 13488 ast_log(LOG_DEBUG, "-- Bridged call to transfer target: %s State %s\n", target->chan2 ? target->chan2->name : "<none>", target->chan2 ? ast_state2str(target->chan2->_state) : "(none)"); 13489 else 13490 ast_log(LOG_DEBUG, "-- No target second channel ---\n"); 13491 ast_log(LOG_DEBUG, "-- END Sip transfer:--------------------\n"); 13492 } 13493 if (transferer->chan2) { /* We have a bridge on the transferer's channel */ 13494 peera = transferer->chan1; /* Transferer - PBX -> transferee channel * the one we hangup */ 13495 peerb = target->chan1; /* Transferer - PBX -> target channel - This will get lost in masq */ 13496 peerc = transferer->chan2; /* Asterisk to Transferee */ 13497 peerd = target->chan2; /* Asterisk to Target */ 13498 if (option_debug > 2) 13499 ast_log(LOG_DEBUG, "SIP transfer: Four channels to handle\n"); 13500 } else if (target->chan2) { /* Transferer has no bridge (IVR), but transferee */ 13501 peera = target->chan1; /* Transferer to PBX -> target channel */ 13502 peerb = transferer->chan1; /* Transferer to IVR*/ 13503 peerc = target->chan2; /* Asterisk to Target */ 13504 peerd = transferer->chan2; /* Nothing */ 13505 if (option_debug > 2) 13506 ast_log(LOG_DEBUG, "SIP transfer: Three channels to handle\n"); 13507 } 13508 13509 if (peera && peerb && peerc && (peerb != peerc)) { 13510 ast_quiet_chan(peera); /* Stop generators */ 13511 ast_quiet_chan(peerb); 13512 ast_quiet_chan(peerc); 13513 if (peerd) 13514 ast_quiet_chan(peerd); 13515 13516 if (option_debug > 3) 13517 ast_log(LOG_DEBUG, "SIP transfer: trying to masquerade %s into %s\n", peerc->name, peerb->name); 13518 if (ast_channel_masquerade(peerb, peerc)) { 13519 ast_log(LOG_WARNING, "Failed to masquerade %s into %s\n", peerb->name, peerc->name); 13520 res = -1; 13521 } else 13522 ast_log(LOG_DEBUG, "SIP transfer: Succeeded to masquerade channels.\n"); 13523 return res; 13524 } else { 13525 ast_log(LOG_NOTICE, "SIP Transfer attempted with no appropriate bridged calls to transfer\n"); 13526 if (transferer->chan1) 13527 ast_softhangup_nolock(transferer->chan1, AST_SOFTHANGUP_DEV); 13528 if (target->chan1) 13529 ast_softhangup_nolock(target->chan1, AST_SOFTHANGUP_DEV); 13530 return -2; 13531 } 13532 return 0; 13533 }
| static int auto_congest | ( | const void * | nothing | ) | [static] |
Scheduled congestion on a call.
Definition at line 2960 of file chan_sip.c.
References append_history, ast_channel_trylock, ast_channel_unlock, AST_CONTROL_CONGESTION, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_queue_control(), sip_pvt::initid, sip_pvt::lock, LOG_NOTICE, ast_channel::name, and sip_pvt::owner.
Referenced by sip_call().
02961 { 02962 struct sip_pvt *p = (struct sip_pvt *)nothing; 02963 02964 ast_mutex_lock(&p->lock); 02965 p->initid = -1; 02966 if (p->owner) { 02967 /* XXX fails on possible deadlock */ 02968 if (!ast_channel_trylock(p->owner)) { 02969 ast_log(LOG_NOTICE, "Auto-congesting %s\n", p->owner->name); 02970 append_history(p, "Cong", "Auto-congesting (timer)"); 02971 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 02972 ast_channel_unlock(p->owner); 02973 } 02974 } 02975 ast_mutex_unlock(&p->lock); 02976 return 0; 02977 }
| static void build_callid_pvt | ( | struct sip_pvt * | pvt | ) | [static] |
Build SIP Call-ID value for a non-REGISTER transaction.
Definition at line 4464 of file chan_sip.c.
References ast_inet_ntoa(), ast_string_field_build, sip_pvt::callid, sip_pvt::fromdomain, generate_random_string(), sip_pvt::ourip, and S_OR.
Referenced by sip_alloc(), sip_notify(), sip_poke_peer(), sip_request_call(), and sip_send_mwi_to_peer().
04465 { 04466 char buf[33]; 04467 04468 const char *host = S_OR(pvt->fromdomain, ast_inet_ntoa(pvt->ourip)); 04469 04470 ast_string_field_build(pvt, callid, "%s@%s", generate_random_string(buf, sizeof(buf)), host); 04471 04472 }
| static void build_callid_registry | ( | struct sip_registry * | reg, | |
| struct in_addr | ourip, | |||
| const char * | fromdomain | |||
| ) | [static] |
Build SIP Call-ID value for a REGISTER transaction.
Definition at line 4475 of file chan_sip.c.
References ast_inet_ntoa(), ast_string_field_build, sip_pvt::callid, generate_random_string(), and S_OR.
Referenced by transmit_register().
04476 { 04477 char buf[33]; 04478 04479 const char *host = S_OR(fromdomain, ast_inet_ntoa(ourip)); 04480 04481 ast_string_field_build(reg, callid, "%s@%s", generate_random_string(buf, sizeof(buf)), host); 04482 }
| static void build_contact | ( | struct sip_pvt * | p | ) | [static] |
Build contact header - the contact header we send out.
Definition at line 6945 of file chan_sip.c.
References ast_inet_ntoa(), ast_string_field_build, ast_strlen_zero(), sip_pvt::exten, sip_pvt::ourip, and STANDARD_SIP_PORT.
Referenced by check_user_full(), handle_request_invite(), handle_request_options(), handle_request_subscribe(), initreqprep(), register_verify(), and transmit_register().
06946 { 06947 /* Construct Contact: header */ 06948 if (ourport != STANDARD_SIP_PORT) 06949 ast_string_field_build(p, our_contact, "<sip:%s%s%s:%d>", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(p->ourip), ourport); 06950 else 06951 ast_string_field_build(p, our_contact, "<sip:%s%s%s>", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(p->ourip)); 06952 }
| static struct sip_peer * build_peer | ( | const char * | name, | |
| struct ast_variable * | v, | |||
| struct ast_variable * | alt, | |||
| int | realtime | |||
| ) | [static, read] |
Build peer from configuration (file or realtime static/dynamic).
Definition at line 17110 of file chan_sip.c.
References __set_address_from_contact(), sip_peer::accountcode, add_realm_authentication(), sip_peer::addr, sip_peer::allowtransfer, sip_peer::amaflags, ast_append_ha(), ast_callerid_split(), ast_calloc, ast_cdr_amaflags2int(), ast_clear_flag, ast_copy_flags, ast_copy_string(), ast_free_ha(), ast_get_group(), ast_get_ip(), ast_get_ip_or_srv(), ast_get_time_t(), ast_inet_ntoa(), ast_log(), ast_parse_allow_disallow(), ast_parse_caller_presentation(), AST_SCHED_DEL, ast_set2_flag, ast_set_flag, ast_strdupa, ast_strlen_zero(), ast_test_flag, ast_true(), ast_variable_new(), ast_variables_destroy(), ASTOBJ_CONTAINER_FIND_UNLINK_FULL, ASTOBJ_FLAG_MARKED, ASTOBJ_INIT, ASTOBJ_UNMARK, ASTOBJ_UNREF, sip_peer::auth, sip_peer::autoframing, sip_peer::call_limit, sip_peer::callgroup, sip_peer::callingpres, sip_peer::capability, sip_peer::chanvars, sip_peer::cid_name, sip_peer::cid_num, clear_realm_authentication(), sip_peer::contactha, sip_peer::context, sip_peer::defaddr, DEFAULT_MAXMS, destroy_association(), sip_peer::expire, ast_flags::flags, sip_peer::flags, sip_peer::fromdomain, sip_peer::fromuser, sip_peer::fullcontact, sip_peer::ha, handle_common_options(), sip_peer::language, sip_peer::lastmsgssent, ast_variable::lineno, LOG_DEBUG, LOG_WARNING, sip_peer::mailbox, sip_peer::maxcallbitrate, sip_peer::maxms, sip_peer::md5secret, sip_peer::mohinterpret, sip_peer::mohsuggest, ast_variable::name, sip_peer::name, ast_variable::next, sip_peer::objflags, option_debug, peerl, sip_peer::pickupgroup, sip_peer::prefs, reg_source_db(), sip_peer::regexten, sip_peer::rtpholdtimeout, sip_peer::rtpkeepalive, sip_peer::rtptimeout, sip_peer::secret, set_peer_defaults(), sip_destroy_peer(), SIP_PAGE2_ALLOWSUBSCRIBE, SIP_PAGE2_DYNAMIC, SIP_PAGE2_IGNOREREGEXPIRE, SIP_PAGE2_RT_FROMCONTACT, SIP_PAGE2_RTCACHEFRIENDS, SIP_PAGE2_SUBSCRIBEMWIONLY, SIP_REALTIME, SIP_USEREQPHONE, STANDARD_SIP_PORT, sip_peer::subscribecontext, sip_peer::tohost, TRANSFER_CLOSED, TRANSFER_OPENFORALL, TRUE, sip_peer::username, ast_variable::value, and sip_peer::vmexten.
Referenced by realtime_peer(), and reload_config().
17111 { 17112 struct sip_peer *peer = NULL; 17113 struct ast_ha *oldha = NULL; 17114 int obproxyfound=0; 17115 int found=0; 17116 int firstpass=1; 17117 int format=0; /* Ama flags */ 17118 time_t regseconds = 0; 17119 char *varname = NULL, *varval = NULL; 17120 struct ast_variable *tmpvar = NULL; 17121 struct ast_flags peerflags[2] = {{(0)}}; 17122 struct ast_flags mask[2] = {{(0)}}; 17123 char fullcontact[sizeof(peer->fullcontact)] = ""; 17124 17125 if (!realtime || ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS)) 17126 /* Note we do NOT use find_peer here, to avoid realtime recursion */ 17127 /* We also use a case-sensitive comparison (unlike find_peer) so 17128 that case changes made to the peer name will be properly handled 17129 during reload 17130 */ 17131 peer = ASTOBJ_CONTAINER_FIND_UNLINK_FULL(&peerl, name, name, 0, 0, strcmp); 17132 17133 if (peer) { 17134 /* Already in the list, remove it and it will be added back (or FREE'd) */ 17135 found = 1; 17136 if (!(peer->objflags & ASTOBJ_FLAG_MARKED)) 17137 firstpass = 0; 17138 } else { 17139 if (!(peer = ast_calloc(1, sizeof(*peer)))) 17140 return NULL; 17141 17142 if (realtime && !ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS)) 17143 rpeerobjs++; 17144 else 17145 speerobjs++; 17146 ASTOBJ_INIT(peer); 17147 } 17148 /* Note that our peer HAS had its reference count incrased */ 17149 if (firstpass) { 17150 peer->lastmsgssent = -1; 17151 oldha = peer->ha; 17152 peer->ha = NULL; 17153 set_peer_defaults(peer); /* Set peer defaults */ 17154 } 17155 if (!found && name) 17156 ast_copy_string(peer->name, name, sizeof(peer->name)); 17157 17158 /* If we have channel variables, remove them (reload) */ 17159 if (peer->chanvars) { 17160 ast_variables_destroy(peer->chanvars); 17161 peer->chanvars = NULL; 17162 /* XXX should unregister ? */ 17163 } 17164 17165 /* If we have realm authentication information, remove them (reload) */ 17166 clear_realm_authentication(peer->auth); 17167 peer->auth = NULL; 17168 17169 for (; v || ((v = alt) && !(alt=NULL)); v = v->next) { 17170 if (handle_common_options(&peerflags[0], &mask[0], v)) 17171 continue; 17172 if (realtime && !strcasecmp(v->name, "regseconds")) { 17173 ast_get_time_t(v->value, ®seconds, 0, NULL); 17174 } else if (realtime && !strcasecmp(v->name, "ipaddr") && !ast_strlen_zero(v->value) ) { 17175 inet_aton(v->value, &(peer->addr.sin_addr)); 17176 } else if (realtime && !strcasecmp(v->name, "name")) 17177 ast_copy_string(peer->name, v->value, sizeof(peer->name)); 17178 else if (realtime && !strcasecmp(v->name, "fullcontact")) { 17179 /* Reconstruct field, because realtime separates our value at the ';' */ 17180 if (!ast_strlen_zero(fullcontact)) { 17181 strncat(fullcontact, ";", sizeof(fullcontact) - strlen(fullcontact) - 1); 17182 strncat(fullcontact, v->value, sizeof(fullcontact) - strlen(fullcontact) - 1); 17183 } else { 17184 ast_copy_string(fullcontact, v->value, sizeof(fullcontact)); 17185 ast_set_flag(&peer->flags[1], SIP_PAGE2_RT_FROMCONTACT); 17186 } 17187 } else if (!strcasecmp(v->name, "secret")) 17188 ast_copy_string(peer->secret, v->value, sizeof(peer->secret)); 17189 else if (!strcasecmp(v->name, "md5secret")) 17190 ast_copy_string(peer->md5secret, v->value, sizeof(peer->md5secret)); 17191 else if (!strcasecmp(v->name, "auth")) 17192 peer->auth = add_realm_authentication(peer->auth, v->value, v->lineno); 17193 else if (!strcasecmp(v->name, "callerid")) { 17194 ast_callerid_split(v->value, peer->cid_name, sizeof(peer->cid_name), peer->cid_num, sizeof(peer->cid_num)); 17195 } else if (!strcasecmp(v->name, "fullname")) { 17196 ast_copy_string(peer->cid_name, v->value, sizeof(peer->cid_name)); 17197 } else if (!strcasecmp(v->name, "cid_number")) { 17198 ast_copy_string(peer->cid_num, v->value, sizeof(peer->cid_num)); 17199 } else if (!strcasecmp(v->name, "context")) { 17200 ast_copy_string(peer->context, v->value, sizeof(peer->context)); 17201 } else if (!strcasecmp(v->name, "subscribecontext")) { 17202 ast_copy_string(peer->subscribecontext, v->value, sizeof(peer->subscribecontext)); 17203 } else if (!strcasecmp(v->name, "fromdomain")) { 17204 ast_copy_string(peer->fromdomain, v->value, sizeof(peer->fromdomain)); 17205 } else if (!strcasecmp(v->name, "usereqphone")) { 17206 ast_set2_flag(&peer->flags[0], ast_true(v->value), SIP_USEREQPHONE); 17207 } else if (!strcasecmp(v->name, "fromuser")) { 17208 ast_copy_string(peer->fromuser, v->value, sizeof(peer->fromuser)); 17209 } else if (!strcasecmp(v->name, "host") || !strcasecmp(v->name, "outboundproxy")) { 17210 if (!strcasecmp(v->value, "dynamic")) { 17211 if (!strcasecmp(v->name, "outboundproxy") || obproxyfound) { 17212 ast_log(LOG_WARNING, "You can't have a dynamic outbound proxy, you big silly head at line %d.\n", v->lineno); 17213 } else { 17214 /* They'll register with us */ 17215 if (!found || !ast_test_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC)) { 17216 /* Initialize stuff if this is a new peer, or if it used to be 17217 * non-dynamic before the reload. */ 17218 memset(&peer->addr.sin_addr, 0, 4); 17219 if (peer->addr.sin_port) { 17220 /* If we've already got a port, make it the default rather than absolute */ 17221 peer->defaddr.sin_port = peer->addr.sin_port; 17222 peer->addr.sin_port = 0; 17223 } 17224 } 17225 ast_set_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC); 17226 } 17227 } else { 17228 /* Non-dynamic. Make sure we become that way if we're not */ 17229 if (!AST_SCHED_DEL(sched, peer->expire)) { 17230 struct sip_peer *peer_ptr = peer; 17231 ASTOBJ_UNREF(peer_ptr, sip_destroy_peer); 17232 } 17233 ast_clear_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC); 17234 if (!obproxyfound || !strcasecmp(v->name, "outboundproxy")) { 17235 if (ast_get_ip_or_srv(&peer->addr, v->value, srvlookup ? "_sip._udp" : NULL)) { 17236 ASTOBJ_UNREF(peer, sip_destroy_peer); 17237 return NULL; 17238 } 17239 } 17240 if (!strcasecmp(v->name, "outboundproxy")) 17241 obproxyfound=1; 17242 else { 17243 ast_copy_string(peer->tohost, v->value, sizeof(peer->tohost)); 17244 if (!peer->addr.sin_port) 17245 peer->addr.sin_port = htons(STANDARD_SIP_PORT); 17246 } 17247 if (global_dynamic_exclude_static) { 17248 global_contact_ha = ast_append_ha("deny", (char *)ast_inet_ntoa(peer->addr.sin_addr), global_contact_ha); 17249 } 17250 } 17251 } else if (!strcasecmp(v->name, "defaultip")) { 17252 if (ast_get_ip(&peer->defaddr, v->value)) { 17253 ASTOBJ_UNREF(peer, sip_destroy_peer); 17254 return NULL; 17255 } 17256 } else if (!strcasecmp(v->name, "permit") || !strcasecmp(v->name, "deny")) { 17257 peer->ha = ast_append_ha(v->name, v->value, peer->ha); 17258 } else if (!strcasecmp(v->name, "contactpermit") || !strcasecmp(v->name, "contactdeny")) { 17259 peer->contactha = ast_append_ha(v->name + 7, v->value, peer->contactha); 17260 } else if (!strcasecmp(v->name, "port")) { 17261 if (!realtime && ast_test_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC)) 17262 peer->defaddr.sin_port = htons(atoi(v->value)); 17263 else 17264 peer->addr.sin_port = htons(atoi(v->value)); 17265 } else if (!strcasecmp(v->name, "callingpres")) { 17266 peer->callingpres = ast_parse_caller_presentation(v->value); 17267 if (peer->callingpres == -1) 17268 peer->callingpres = atoi(v->value); 17269 } else if (!strcasecmp(v->name, "username")) { 17270 ast_copy_string(peer->username, v->value, sizeof(peer->username)); 17271 } else if (!strcasecmp(v->name, "language")) { 17272 ast_copy_string(peer->language, v->value, sizeof(peer->language)); 17273 } else if (!strcasecmp(v->name, "regexten")) { 17274 ast_copy_string(peer->regexten, v->value, sizeof(peer->regexten)); 17275 } else if (!strcasecmp(v->name, "call-limit") || !strcasecmp(v->name, "incominglimit")) { 17276 peer->call_limit = atoi(v->value); 17277 if (peer->call_limit < 0) 17278 peer->call_limit = 0; 17279 } else if (!strcasecmp(v->name, "amaflags")) { 17280 format = ast_cdr_amaflags2int(v->value); 17281 if (format < 0) { 17282 ast_log(LOG_WARNING, "Invalid AMA Flags for peer: %s at line %d\n", v->value, v->lineno); 17283 } else { 17284 peer->amaflags = format; 17285 } 17286 } else if (!strcasecmp(v->name, "accountcode")) { 17287 ast_copy_string(peer->accountcode, v->value, sizeof(peer->accountcode)); 17288 } else if (!strcasecmp(v->name, "mohinterpret") 17289 || !strcasecmp(v->name, "musicclass") || !strcasecmp(v->name, "musiconhold")) { 17290 ast_copy_string(peer->mohinterpret, v->value, sizeof(peer->mohinterpret)); 17291 } else if (!strcasecmp(v->name, "mohsuggest")) { 17292 ast_copy_string(peer->mohsuggest, v->value, sizeof(peer->mohsuggest)); 17293 } else if (!strcasecmp(v->name, "mailbox")) { 17294 ast_copy_string(peer->mailbox, v->value, sizeof(peer->mailbox)); 17295 } else if (!strcasecmp(v->name, "hasvoicemail")) { 17296 /* People expect that if 'hasvoicemail' is set, that the mailbox will 17297 * be also set, even if not explicitly specified. */ 17298 if (ast_true(v->value) && ast_strlen_zero(peer->mailbox)) { 17299 ast_copy_string(peer->mailbox, name, sizeof(peer->mailbox)); 17300 } 17301 } else if (!strcasecmp(v->name, "subscribemwi")) { 17302 ast_set2_flag(&peer->flags[1], ast_true(v->value), SIP_PAGE2_SUBSCRIBEMWIONLY); 17303 } else if (!strcasecmp(v->name, "vmexten")) { 17304 ast_copy_string(peer->vmexten, v->value, sizeof(peer->vmexten)); 17305 } else if (!strcasecmp(v->name, "callgroup")) { 17306 peer->callgroup = ast_get_group(v->value); 17307 } else if (!strcasecmp(v->name, "allowtransfer")) { 17308 peer->allowtransfer = ast_true(v->value) ? TRANSFER_OPENFORALL : TRANSFER_CLOSED; 17309 } else if (!strcasecmp(v->name, "pickupgroup")) { 17310 peer->pickupgroup = ast_get_group(v->value); 17311 } else if (!strcasecmp(v->name, "allow")) { 17312 ast_parse_allow_disallow(&peer->prefs, &peer->capability, v->value, 1); 17313 } else if (!strcasecmp(v->name, "disallow")) { 17314 ast_parse_allow_disallow(&peer->prefs, &peer->capability, v->value, 0); 17315 } else if (!strcasecmp(v->name, "autoframing")) { 17316 peer->autoframing = ast_true(v->value); 17317 } else if (!strcasecmp(v->name, "rtptimeout")) { 17318 if ((sscanf(v->value, "%d", &peer->rtptimeout) != 1) || (peer->rtptimeout < 0)) { 17319 ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno); 17320 peer->rtptimeout = global_rtptimeout; 17321 } 17322 } else if (!strcasecmp(v->name, "rtpholdtimeout")) { 17323 if ((sscanf(v->value, "%d", &peer->rtpholdtimeout) != 1) || (peer->rtpholdtimeout < 0)) { 17324 ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno); 17325 peer->rtpholdtimeout = global_rtpholdtimeout; 17326 } 17327 } else if (!strcasecmp(v->name, "rtpkeepalive")) { 17328 if ((sscanf(v->value, "%d", &peer->rtpkeepalive) != 1) || (peer->rtpkeepalive < 0)) { 17329 ast_log(LOG_WARNING, "'%s' is not a valid RTP keepalive time at line %d. Using default.\n", v->value, v->lineno); 17330 peer->rtpkeepalive = global_rtpkeepalive; 17331 } 17332 } else if (!strcasecmp(v->name, "setvar")) { 17333 /* Set peer channel variable */ 17334 varname = ast_strdupa(v->value); 17335 if ((varval = strchr(varname, '='))) { 17336 *varval++ = '\0'; 17337 if ((tmpvar = ast_variable_new(varname, varval))) { 17338 tmpvar->next = peer->chanvars; 17339 peer->chanvars = tmpvar; 17340 } 17341 } 17342 } else if (!strcasecmp(v->name, "qualify")) { 17343 if (!strcasecmp(v->value, "no")) { 17344 peer->maxms = 0; 17345 } else if (!strcasecmp(v->value, "yes")) { 17346 peer->maxms = default_qualify ? default_qualify : DEFAULT_MAXMS; 17347 } else if (sscanf(v->value, "%d", &peer->maxms) != 1) { 17348 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); 17349 peer->maxms = 0; 17350 } 17351 if (realtime && !ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS) && peer->maxms > 0) { 17352 /* This would otherwise cause a network storm, where the 17353 * qualify response refreshes the peer from the database, 17354 * which in turn causes another qualify to be sent, ad 17355 * infinitum. */ 17356 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); 17357 peer->maxms = 0; 17358 } 17359 } else if (!strcasecmp(v->name, "maxcallbitrate")) { 17360 peer->maxcallbitrate = atoi(v->value); 17361 if (peer->maxcallbitrate < 0) 17362 peer->maxcallbitrate = default_maxcallbitrate; 17363 } 17364 } 17365 if (!ast_strlen_zero(fullcontact)) { 17366 ast_copy_string(peer->fullcontact, fullcontact, sizeof(peer->fullcontact)); 17367 /* We have a hostname in the fullcontact, but if we don't have an 17368 * address listed on the entry (or if it's 'dynamic'), then we need to 17369 * parse the entry to obtain the IP address, so a dynamic host can be 17370 * contacted immediately after reload (as opposed to waiting for it to 17371 * register once again). */ 17372 __set_address_from_contact(fullcontact, &peer->addr); 17373 } 17374 17375 if (!ast_test_flag(&global_flags[1], SIP_PAGE2_IGNOREREGEXPIRE) && ast_test_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC) && realtime) { 17376 time_t nowtime = time(NULL); 17377 17378 if ((nowtime - regseconds) > 0) { 17379 destroy_association(peer); 17380 memset(&peer->addr, 0, sizeof(peer->addr)); 17381 if (option_debug) 17382 ast_log(LOG_DEBUG, "Bah, we're expired (%d/%d/%d)!\n", (int)(nowtime - regseconds), (int)regseconds, (int)nowtime); 17383 } 17384 } 17385 ast_copy_flags(&peer->flags[0], &peerflags[0], mask[0].flags); 17386 ast_copy_flags(&peer->flags[1], &peerflags[1], mask[1].flags); 17387 if (ast_test_flag(&peer->flags[1], SIP_PAGE2_ALLOWSUBSCRIBE)) 17388 global_allowsubscribe = TRUE; /* No global ban any more */ 17389 if (!found && ast_test_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC) && !ast_test_flag(&peer->flags[0], SIP_REALTIME)) 17390 reg_source_db(peer); 17391 ASTOBJ_UNMARK(peer); 17392 ast_free_ha(oldha); 17393 return peer; 17394 }
| static int build_reply_digest | ( | struct sip_pvt * | p, | |
| int | method, | |||
| char * | digest, | |||
| int | digest_len | |||
| ) | [static] |
Build reply digest.
Definition at line 11730 of file chan_sip.c.
References append_history, ast_copy_string(), ast_inet_ntoa(), ast_log(), ast_md5_hash(), ast_random(), ast_strlen_zero(), sip_pvt::authname, sip_pvt::callid, sip_pvt::domain, find_realm_authentication(), LOG_DEBUG, sip_auth::md5secret, sip_registry::md5secret, sip_pvt::nonce, sip_pvt::noncecount, sip_pvt::opaque, sip_registry::opaque, sip_pvt::peerauth, sip_pvt::peermd5secret, sip_pvt::peername, sip_pvt::peersecret, sip_pvt::qop, sip_pvt::realm, sip_pvt::sa, sip_auth::secret, secret, sip_methods, sipdebug, text, sip_pvt::uri, sip_auth::username, sip_pvt::username, and username.
Referenced by reply_digest(), transmit_register(), and transmit_request_with_auth().
11731 { 11732 char a1[256]; 11733 char a2[256]; 11734 char a1_hash[256]; 11735 char a2_hash[256]; 11736 char resp[256]; 11737 char resp_hash[256]; 11738 char uri[256]; 11739 char opaque[256] = ""; 11740 char cnonce[80]; 11741 const char *username; 11742 const char *secret; 11743 const char *md5secret; 11744 struct sip_auth *auth = NULL; /* Realm authentication */ 11745 11746 if (!ast_strlen_zero(p->domain)) 11747 ast_copy_string(uri, p->domain, sizeof(uri)); 11748 else if (!ast_strlen_zero(p->uri)) 11749 ast_copy_string(uri, p->uri, sizeof(uri)); 11750 else 11751 snprintf(uri, sizeof(uri), "sip:%s@%s",p->username, ast_inet_ntoa(p->sa.sin_addr)); 11752 11753 snprintf(cnonce, sizeof(cnonce), "%08lx", ast_random()); 11754 11755 /* Check if we have separate auth credentials */ 11756 if(!(auth = find_realm_authentication(p->peerauth, p->realm))) /* Start with peer list */ 11757 auth = find_realm_authentication(authl, p->realm); /* If not, global list */ 11758 11759 if (auth) { 11760 ast_log(LOG_DEBUG, "use realm [%s] from peer [%s][%s]\n", auth->username, p->peername, p->username); 11761 username = auth->username; 11762 secret = auth->secret; 11763 md5secret = auth->md5secret; 11764 if (sipdebug) 11765 ast_log(LOG_DEBUG,"Using realm %s authentication for call %s\n", p->realm, p->callid); 11766 } else { 11767 /* No authentication, use peer or register= config */ 11768 username = p->authname; 11769 secret = p->peersecret; 11770 md5secret = p->peermd5secret; 11771 } 11772 if (ast_strlen_zero(username)) /* We have no authentication */ 11773 return -1; 11774 11775 /* Calculate SIP digest response */ 11776 snprintf(a1,sizeof(a1),"%s:%s:%s", username, p->realm, secret); 11777 snprintf(a2,sizeof(a2),"%s:%s", sip_methods[method].text, uri); 11778 if (!ast_strlen_zero(md5secret)) 11779 ast_copy_string(a1_hash, md5secret, sizeof(a1_hash)); 11780 else 11781 ast_md5_hash(a1_hash,a1); 11782 ast_md5_hash(a2_hash,a2); 11783 11784 p->noncecount++; 11785 if (!ast_strlen_zero(p->qop)) 11786 snprintf(resp,sizeof(resp),"%s:%s:%08x:%s:%s:%s", a1_hash, p->nonce, p->noncecount, cnonce, "auth", a2_hash); 11787 else 11788 snprintf(resp,sizeof(resp),"%s:%s:%s", a1_hash, p->nonce, a2_hash); 11789 ast_md5_hash(resp_hash, resp); 11790 11791 /* only include the opaque string if it's set */ 11792 if (!ast_strlen_zero(p->opaque)) { 11793 snprintf(opaque, sizeof(opaque), ", opaque=\"%s\"", p->opaque); 11794 } 11795 11796 /* XXX We hard code our qop to "auth" for now. XXX */ 11797 if (!ast_strlen_zero(p->qop)) 11798 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); 11799 else 11800 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); 11801 11802 append_history(p, "AuthResp", "Auth response sent for %s in realm %s - nc %d", username, p->realm, p->noncecount); 11803 11804 return 0; 11805 }
| static void build_route | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| int | backwards | |||
| ) | [static] |
Build route list from Record-Route header.
Definition at line 8402 of file chan_sip.c.
References __get_header(), ast_copy_string(), ast_log(), ast_malloc, ast_strlen_zero(), free_old_route(), get_header(), sip_route::hop, len(), list_route(), LOG_DEBUG, sip_route::next, option_debug, sip_pvt::route, sip_pvt::route_persistant, and sip_debug_test_pvt().
Referenced by handle_request_invite(), and handle_response_invite().
08403 { 08404 struct sip_route *thishop, *head, *tail; 08405 int start = 0; 08406 int len; 08407 const char *rr, *contact, *c; 08408 08409 /* Once a persistant route is set, don't fool with it */ 08410 if (p->route && p->route_persistant) { 08411 if (option_debug) 08412 ast_log(LOG_DEBUG, "build_route: Retaining previous route: <%s>\n", p->route->hop); 08413 return; 08414 } 08415 08416 if (p->route) { 08417 free_old_route(p->route); 08418 p->route = NULL; 08419 } 08420 08421 /* We only want to create the route set the first time this is called */ 08422 p->route_persistant = 1; 08423 08424 /* Build a tailq, then assign it to p->route when done. 08425 * If backwards, we add entries from the head so they end up 08426 * in reverse order. However, we do need to maintain a correct 08427 * tail pointer because the contact is always at the end. 08428 */ 08429 head = NULL; 08430 tail = head; 08431 /* 1st we pass through all the hops in any Record-Route headers */ 08432 for (;;) { 08433 /* Each Record-Route header */ 08434 rr = __get_header(req, "Record-Route", &start); 08435 if (*rr == '\0') 08436 break; 08437 for (; (rr = strchr(rr, '<')) ; rr += len) { /* Each route entry */ 08438 ++rr; 08439 len = strcspn(rr, ">") + 1; 08440 /* Make a struct route */ 08441 if ((thishop = ast_malloc(sizeof(*thishop) + len))) { 08442 /* ast_calloc is not needed because all fields are initialized in this block */ 08443 ast_copy_string(thishop->hop, rr, len); 08444 if (option_debug > 1) 08445 ast_log(LOG_DEBUG, "build_route: Record-Route hop: <%s>\n", thishop->hop); 08446 /* Link in */ 08447 if (backwards) { 08448 /* Link in at head so they end up in reverse order */ 08449 thishop->next = head; 08450 head = thishop; 08451 /* If this was the first then it'll be the tail */ 08452 if (!tail) 08453 tail = thishop; 08454 } else { 08455 thishop->next = NULL; 08456 /* Link in at the end */ 08457 if (tail) 08458 tail->next = thishop; 08459 else 08460 head = thishop; 08461 tail = thishop; 08462 } 08463 } 08464 } 08465 } 08466 08467 /* Only append the contact if we are dealing with a strict router */ 08468 if (!head || (!ast_strlen_zero(head->hop) && strstr(head->hop,";lr") == NULL) ) { 08469 /* 2nd append the Contact: if there is one */ 08470 /* Can be multiple Contact headers, comma separated values - we just take the first */ 08471 contact = get_header(req, "Contact"); 08472 if (!ast_strlen_zero(contact)) { 08473 if (option_debug > 1) 08474 ast_log(LOG_DEBUG, "build_route: Contact hop: %s\n", contact); 08475 /* Look for <: delimited address */ 08476 c = strchr(contact, '<'); 08477 if (c) { 08478 /* Take to > */ 08479 ++c; 08480 len = strcspn(c, ">") + 1; 08481 } else { 08482 /* No <> - just take the lot */ 08483 c = contact; 08484 len = strlen(contact) + 1; 08485 } 08486 if ((thishop = ast_malloc(sizeof(*thishop) + len))) { 08487 /* ast_calloc is not needed because all fields are initialized in this block */ 08488 ast_copy_string(thishop->hop, c, len); 08489 thishop->next = NULL; 08490 /* Goes at the end */ 08491 if (tail) 08492 tail->next = thishop; 08493 else 08494 head = thishop; 08495 } 08496 } 08497 } 08498 08499 /* Store as new route */ 08500 p->route = head; 08501 08502 /* For debugging dump what we ended up with */ 08503 if (sip_debug_test_pvt(p)) 08504 list_route(p->route); 08505 }
| static void build_rpid | ( | struct sip_pvt * | p | ) | [static] |
Build the Remote Party-ID & From using callingpres options.
Definition at line 6955 of file chan_sip.c.
References ast_inet_ntoa(), ast_log(), AST_PRES_ALLOWED, AST_PRES_ALLOWED_NETWORK_NUMBER, AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN, AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED, AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, AST_PRES_NUMBER_NOT_AVAILABLE, AST_PRES_PROHIB_NETWORK_NUMBER, AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN, AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED, AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN, AST_PRES_RESTRICTION, ast_string_field_build, ast_string_field_set, ast_strlen_zero(), sip_pvt::callingpres, ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, FALSE, sip_pvt::fromdomain, sip_pvt::fromuser, LOG_WARNING, sip_pvt::ourip, sip_pvt::owner, sip_pvt::rpid, sip_pvt::rpid_from, S_OR, sip_pvt::tag, and TRUE.
Referenced by initreqprep().
06956 { 06957 int send_pres_tags = TRUE; 06958 const char *privacy=NULL; 06959 const char *screen=NULL; 06960 char buf[256]; 06961 const char *clid = default_callerid; 06962 const char *clin = NULL; 06963 const char *fromdomain; 06964 06965 if (!ast_strlen_zero(p->rpid) || !ast_strlen_zero(p->rpid_from)) 06966 return; 06967 06968 if (p->owner && p->owner->cid.cid_num) 06969 clid = p->owner->cid.cid_num; 06970 if (p->owner && p->owner->cid.cid_name) 06971 clin = p->owner->cid.cid_name; 06972 if (ast_strlen_zero(clin)) 06973 clin = clid; 06974 06975 switch (p->callingpres) { 06976 case AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED: 06977 privacy = "off"; 06978 screen = "no"; 06979 break; 06980 case AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN: 06981 privacy = "off"; 06982 screen = "yes"; 06983 break; 06984 case AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN: 06985 privacy = "off"; 06986 screen = "no"; 06987 break; 06988 case AST_PRES_ALLOWED_NETWORK_NUMBER: 06989 privacy = "off"; 06990 screen = "yes"; 06991 break; 06992 case AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED: 06993 privacy = "full"; 06994 screen = "no"; 06995 break; 06996 case AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN: 06997 privacy = "full"; 06998 screen = "yes"; 06999 break; 07000 case AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN: 07001 privacy = "full"; 07002 screen = "no"; 07003 break; 07004 case AST_PRES_PROHIB_NETWORK_NUMBER: 07005 privacy = "full"; 07006 screen = "yes"; 07007 break; 07008 case AST_PRES_NUMBER_NOT_AVAILABLE: 07009 send_pres_tags = FALSE; 07010 break; 07011 default: 07012 ast_log(LOG_WARNING, "Unsupported callingpres (%d)\n", p->callingpres); 07013 if ((p->callingpres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) 07014 privacy = "full"; 07015 else 07016 privacy = "off"; 07017 screen = "no"; 07018 break; 07019 } 07020 07021 fromdomain = S_OR(p->fromdomain, ast_inet_ntoa(p->ourip)); 07022 07023 snprintf(buf, sizeof(buf), "\"%s\" <sip:%s@%s>", clin, clid, fromdomain); 07024 if (send_pres_tags) 07025 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ";privacy=%s;screen=%s", privacy, screen); 07026 ast_string_field_set(p, rpid, buf); 07027 07028 ast_string_field_build(p, rpid_from, "\"%s\" <sip:%s@%s>;tag=%s", clin, 07029 S_OR(p->fromuser, clid), 07030 fromdomain, p->tag); 07031 }
| static struct sip_user * build_user | ( | const char * | name, | |
| struct ast_variable * | v, | |||
| struct ast_variable * | alt, | |||
| int | realtime | |||
| ) | [static, read] |
Initiate a SIP user structure from configuration (configuration or realtime).
Definition at line 16930 of file chan_sip.c.
References sip_user::accountcode, sip_user::allowtransfer, sip_user::amaflags, ast_append_ha(), ast_callerid_split(), ast_calloc, ast_cdr_amaflags2int(), ast_copy_flags, ast_copy_string(), ast_free_ha(), ast_get_group(), ast_log(), ast_parse_allow_disallow(), ast_parse_caller_presentation(), ast_strdupa, ast_test_flag, ast_true(), ast_variable_new(), ASTOBJ_INIT, sip_user::autoframing, sip_user::call_limit, sip_user::callgroup, sip_user::callingpres, sip_user::capability, sip_user::chanvars, sip_user::cid_name, sip_user::cid_num, sip_user::context, default_prefs, ast_flags::flags, sip_user::flags, format, sip_user::ha, handle_common_options(), sip_user::language, ast_variable::lineno, LOG_WARNING, sip_user::maxcallbitrate, sip_user::md5secret, sip_user::mohinterpret, sip_user::mohsuggest, ast_variable::name, sip_user::name, ast_variable::next, sip_user::pickupgroup, sip_user::prefs, sip_user::secret, SIP_FLAGS_TO_COPY, SIP_PAGE2_ALLOWSUBSCRIBE, SIP_PAGE2_FLAGS_TO_COPY, sip_user::subscribecontext, TRANSFER_CLOSED, TRANSFER_OPENFORALL, TRUE, and ast_variable::value.
Referenced by realtime_user(), and reload_config().
16931 { 16932 struct sip_user *user; 16933 int format; 16934 struct ast_ha *oldha = NULL; 16935 char *varname = NULL, *varval = NULL; 16936 struct ast_variable *tmpvar = NULL; 16937 struct ast_flags userflags[2] = {{(0)}}; 16938 struct ast_flags mask[2] = {{(0)}}; 16939 16940 16941 if (!(user = ast_calloc(1, sizeof(*user)))) 16942 return NULL; 16943 16944 suserobjs++; 16945 ASTOBJ_INIT(user); 16946 ast_copy_string(user->name, name, sizeof(user->name)); 16947 oldha = user->ha; 16948 user->ha = NULL; 16949 ast_copy_flags(&user->flags[0], &global_flags[0], SIP_FLAGS_TO_COPY); 16950 ast_copy_flags(&user->flags[1], &global_flags[1], SIP_PAGE2_FLAGS_TO_COPY); 16951 user->capability = global_capability; 16952 user->allowtransfer = global_allowtransfer; 16953 user->maxcallbitrate = default_maxcallbitrate; 16954 user->autoframing = global_autoframing; 16955 user->prefs = default_prefs; 16956 /* set default context */ 16957 strcpy(user->context, default_context); 16958 strcpy(user->language, default_language); 16959 strcpy(user->mohinterpret, default_mohinterpret); 16960 strcpy(user->mohsuggest, default_mohsuggest); 16961 /* First we walk through the v parameters list and then the alt parameters list */ 16962 for (; v || ((v = alt) && !(alt=NULL)); v = v->next) { 16963 if (handle_common_options(&userflags[0], &mask[0], v)) 16964 continue; 16965 16966 if (!strcasecmp(v->name, "context")) { 16967 ast_copy_string(user->context, v->value, sizeof(user->context)); 16968 } else if (!strcasecmp(v->name, "subscribecontext")) { 16969 ast_copy_string(user->subscribecontext, v->value, sizeof(user->subscribecontext)); 16970 } else if (!strcasecmp(v->name, "setvar")) { 16971 varname = ast_strdupa(v->value); 16972 if ((varval = strchr(varname,'='))) { 16973 *varval++ = '\0'; 16974 if ((tmpvar = ast_variable_new(varname, varval))) { 16975 tmpvar->next = user->chanvars; 16976 user->chanvars = tmpvar; 16977 } 16978 } 16979 } else if (!strcasecmp(v->name, "permit") || 16980 !strcasecmp(v->name, "deny")) { 16981 user->ha = ast_append_ha(v->name, v->value, user->ha); 16982 } else if (!strcasecmp(v->name, "allowtransfer")) { 16983 user->allowtransfer = ast_true(v->value) ? TRANSFER_OPENFORALL : TRANSFER_CLOSED; 16984 } else if (!strcasecmp(v->name, "secret")) { 16985 ast_copy_string(user->secret, v->value, sizeof(user->secret)); 16986 } else if (!strcasecmp(v->name, "md5secret")) { 16987 ast_copy_string(user->md5secret, v->value, sizeof(user->md5secret)); 16988 } else if (!strcasecmp(v->name, "callerid")) { 16989 ast_callerid_split(v->value, user->cid_name, sizeof(user->cid_name), user->cid_num, sizeof(user->cid_num)); 16990 } else if (!strcasecmp(v->name, "fullname")) { 16991 ast_copy_string(user->cid_name, v->value, sizeof(user->cid_name)); 16992 } else if (!strcasecmp(v->name, "cid_number")) { 16993 ast_copy_string(user->cid_num, v->value, sizeof(user->cid_num)); 16994 } else if (!strcasecmp(v->name, "callgroup")) { 16995 user->callgroup = ast_get_group(v->value); 16996 } else if (!strcasecmp(v->name, "pickupgroup")) { 16997 user->pickupgroup = ast_get_group(v->value); 16998 } else if (!strcasecmp(v->name, "language")) { 16999 ast_copy_string(user->language, v->value, sizeof(user->language)); 17000 } else if (!strcasecmp(v->name, "mohinterpret") 17001 || !strcasecmp(v->name, "musicclass") || !strcasecmp(v->name, "musiconhold")) { 17002 ast_copy_string(user->mohinterpret, v->value, sizeof(user->mohinterpret)); 17003 } else if (!strcasecmp(v->name, "mohsuggest")) { 17004 ast_copy_string(user->mohsuggest, v->value, sizeof(user->mohsuggest)); 17005 } else if (!strcasecmp(v->name, "accountcode")) { 17006 ast_copy_string(user->accountcode, v->value, sizeof(user->accountcode)); 17007 } else if (!strcasecmp(v->name, "call-limit")) { 17008 user->call_limit = atoi(v->value); 17009 if (user->call_limit < 0) 17010 user->call_limit = 0; 17011 } else if (!strcasecmp(v->name, "amaflags")) { 17012 format = ast_cdr_amaflags2int(v->value); 17013 if (format < 0) { 17014 ast_log(LOG_WARNING, "Invalid AMA Flags: %s at line %d\n", v->value, v->lineno); 17015 } else { 17016 user->amaflags = format; 17017 } 17018 } else if (!strcasecmp(v->name, "allow")) { 17019 ast_parse_allow_disallow(&user->prefs, &user->capability, v->value, 1); 17020 } else if (!strcasecmp(v->name, "disallow")) { 17021 ast_parse_allow_disallow(&user->prefs, &user->capability, v->value, 0); 17022 } else if (!strcasecmp(v->name, "autoframing")) { 17023 user->autoframing = ast_true(v->value); 17024 } else if (!strcasecmp(v->name, "callingpres")) { 17025 user->callingpres = ast_parse_caller_presentation(v->value); 17026 if (user->callingpres == -1) 17027 user->callingpres = atoi(v->value); 17028 } else if (!strcasecmp(v->name, "maxcallbitrate")) { 17029 user->maxcallbitrate = atoi(v->value); 17030 if (user->maxcallbitrate < 0) 17031 user->maxcallbitrate = default_maxcallbitrate; 17032 } 17033 /* We can't just report unknown options here because this may be a 17034 * type=friend entry. All user options are valid for a peer, but not 17035 * the other way around. */ 17036 } 17037 ast_copy_flags(&user->flags[0], &userflags[0], mask[0].flags); 17038 ast_copy_flags(&user->flags[1], &userflags[1], mask[1].flags); 17039 if (ast_test_flag(&user->flags[1], SIP_PAGE2_ALLOWSUBSCRIBE)) 17040 global_allowsubscribe = TRUE; /* No global ban any more */ 17041 ast_free_ha(oldha); 17042 return user; 17043 }
| static void build_via | ( | struct sip_pvt * | p | ) | [static] |
Build a Via header for a request.
Definition at line 1807 of file chan_sip.c.
References ast_inet_ntoa(), ast_string_field_build, ast_test_flag, sip_pvt::branch, sip_pvt::flags, sip_pvt::ourip, SIP_NAT, and SIP_NAT_RFC3581.
Referenced by reqprep(), sip_alloc(), sip_notify(), sip_poke_peer(), sip_request_call(), sip_send_mwi_to_peer(), transmit_invite(), transmit_register(), and transmit_response_using_temp().
01808 { 01809 /* Work around buggy UNIDEN UIP200 firmware */ 01810 const char *rport = ast_test_flag(&p->flags[0], SIP_NAT) & SIP_NAT_RFC3581 ? ";rport" : ""; 01811 01812 /* z9hG4bK is a magic cookie. See RFC 3261 section 8.1.1.7 */ 01813 ast_string_field_build(p, via, "SIP/2.0/UDP %s:%d;branch=z9hG4bK%08x%s", 01814 ast_inet_ntoa(p->ourip), ourport, (int) p->branch, rport); 01815 }
| static int cb_extensionstate | ( | char * | context, | |
| char * | exten, | |||
| int | state, | |||
| void * | data | |||
| ) | [static] |
Callback for the devicestate notification (SUBSCRIBE) support subsystem.
Definition at line 8710 of file chan_sip.c.
References append_history, AST_EXTENSION_DEACTIVATED, AST_EXTENSION_REMOVED, ast_extension_state2str(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_set_flag, ast_test_flag, ast_verbose(), sip_pvt::autokillid, DEFAULT_TRANS_TIMEOUT, FALSE, sip_pvt::flags, sip_pvt::laststate, sip_pvt::lock, LOG_WARNING, NONE, option_verbose, sip_pvt::pendinginvite, sip_cancel_destroy(), SIP_PAGE2_STATECHANGEQUEUE, sip_scheddestroy(), sip_pvt::stateid, sip_pvt::subscribed, transmit_state_notify(), sip_pvt::username, VERBOSE_PREFIX_1, and VERBOSE_PREFIX_2.
Referenced by handle_request_subscribe(), and handle_response().
08711 { 08712 struct sip_pvt *p = data; 08713 08714 ast_mutex_lock(&p->lock); 08715 08716 switch(state) { 08717 case AST_EXTENSION_DEACTIVATED: /* Retry after a while */ 08718 case AST_EXTENSION_REMOVED: /* Extension is gone */ 08719 if (p->autokillid > -1 && sip_cancel_destroy(p)) /* Remove subscription expiry for renewals */ 08720 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 08721 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); /* Delete subscription in 32 secs */ 08722 ast_verbose(VERBOSE_PREFIX_2 "Extension state: Watcher for hint %s %s. Notify User %s\n", exten, state == AST_EXTENSION_DEACTIVATED ? "deactivated" : "removed", p->username); 08723 p->stateid = -1; 08724 p->subscribed = NONE; 08725 append_history(p, "Subscribestatus", "%s", state == AST_EXTENSION_REMOVED ? "HintRemoved" : "Deactivated"); 08726 break; 08727 default: /* Tell user */ 08728 p->laststate = state; 08729 break; 08730 } 08731 if (p->subscribed != NONE) { /* Only send state NOTIFY if we know the format */ 08732 if (!p->pendinginvite) { 08733 transmit_state_notify(p, state, 1, FALSE); 08734 } else { 08735 /* We already have a NOTIFY sent that is not answered. Queue the state up. 08736 if many state changes happen meanwhile, we will only send a notification of the last one */ 08737 ast_set_flag(&p->flags[1], SIP_PAGE2_STATECHANGEQUEUE); 08738 } 08739 } 08740 if (option_verbose > 1) 08741 ast_verbose(VERBOSE_PREFIX_1 "Extension Changed %s[%s] new state %s for Notify User %s %s\n", exten, context, ast_extension_state2str(state), p->username, 08742 ast_test_flag(&p->flags[1], SIP_PAGE2_STATECHANGEQUEUE) ? "(queued)" : ""); 08743 08744 08745 ast_mutex_unlock(&p->lock); 08746 08747 return 0; 08748 }
| 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 5045 of file chan_sip.c.
References append_history, ast_clear_flag, ast_set_flag, ast_test_flag, sip_request::data, EVENT_FLAG_CALL, sip_pvt::flags, manager_event(), ast_channel::name, sip_pvt::owner, SIP_PAGE2_CALL_ONHOLD, SIP_PAGE2_CALL_ONHOLD_ACTIVE, SIP_PAGE2_CALL_ONHOLD_INACTIVE, SIP_PAGE2_CALL_ONHOLD_ONEDIR, sip_peer_hold(), and ast_channel::uniqueid.
Referenced by handle_request_invite(), and process_sdp().
05046 { 05047 if (global_notifyhold && (!holdstate || !ast_test_flag(&dialog->flags[1], SIP_PAGE2_CALL_ONHOLD))) 05048 sip_peer_hold(dialog, holdstate); 05049 if (global_callevents) 05050 manager_event(EVENT_FLAG_CALL, holdstate ? "Hold" : "Unhold", 05051 "Channel: %s\r\n" 05052 "Uniqueid: %s\r\n", 05053 dialog->owner->name, 05054 dialog->owner->uniqueid); 05055 append_history(dialog, holdstate ? "Hold" : "Unhold", "%s", req->data); 05056 if (!holdstate) { /* Put off remote hold */ 05057 ast_clear_flag(&dialog->flags[1], SIP_PAGE2_CALL_ONHOLD); /* Clear both flags */ 05058 return; 05059 } 05060 /* No address for RTP, we're on hold */ 05061 05062 if (sendonly == 1) /* One directional hold (sendonly/recvonly) */ 05063 ast_set_flag(&dialog->flags[1], SIP_PAGE2_CALL_ONHOLD_ONEDIR); 05064 else if (sendonly == 2) /* Inactive stream */ 05065 ast_set_flag(&dialog->flags[1], SIP_PAGE2_CALL_ONHOLD_INACTIVE); 05066 else 05067 ast_set_flag(&dialog->flags[1], SIP_PAGE2_CALL_ONHOLD_ACTIVE); 05068 return; 05069 }
| static enum check_auth_result check_auth | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| const char * | username, | |||
| const char * | secret, | |||
| const char * | md5secret, | |||
| int | sipmethod, | |||
| char * | uri, | |||
| enum xmittype | reliable, | |||
| int | ignore | |||
| ) | [static] |
Check user authorization from peer definition Some actions, like REGISTER and INVITEs from peers require authentication (if peer have secret set).
XXX
XXX
Definition at line 8515 of file chan_sip.c.
References append_history, ast_copy_string(), ast_dynamic_str_thread_get(), ast_dynamic_str_thread_set(), AST_DYNSTR_BUILD_FAILED, ast_log(), ast_md5_hash(), ast_random(), ast_skip_blanks(), ast_string_field_build, ast_strlen_zero(), ast_test_flag, AUTH_CHALLENGE_SENT, AUTH_SECRET_FAILED, AUTH_SUCCESSFUL, AUTH_USERNAME_MISMATCH, check_auth_buf, CHECK_AUTH_BUF_INITLEN, DEFAULT_TRANS_TIMEOUT, FALSE, get_header(), keys, LOG_NOTICE, LOG_WARNING, sip_pvt::randdata, s, S_OR, sip_methods, SIP_PKT_IGNORE, SIP_REGISTER, sip_scheddestroy(), SIP_SUBSCRIBE, sipdebug, ast_dynamic_str::str, text, transmit_response_with_auth(), and TRUE.
Referenced by check_user_full(), and register_verify().
08518 { 08519 const char *response = "407 Proxy Authentication Required"; 08520 const char *reqheader = "Proxy-Authorization"; 08521 const char *respheader = "Proxy-Authenticate"; 08522 const char *authtoken; 08523 char a1_hash[256]; 08524 char resp_hash[256]=""; 08525 char *c; 08526 int wrongnonce = FALSE; 08527 int good_response; 08528 const char *usednonce = p->randdata; 08529 struct ast_dynamic_str *buf; 08530 int res; 08531 08532 /* table of recognised keywords, and their value in the digest */ 08533 enum keys { K_RESP, K_URI, K_USER, K_NONCE, K_LAST }; 08534 struct x { 08535 const char *key; 08536 const char *s; 08537 } *i, keys[] = { 08538 [K_RESP] = { "response=", "" }, 08539 [K_URI] = { "uri=", "" }, 08540 [K_USER] = { "username=", "" }, 08541 [K_NONCE] = { "nonce=", "" }, 08542 [K_LAST] = { NULL, NULL} 08543 }; 08544 08545 /* Always OK if no secret */ 08546 if (ast_strlen_zero(secret) && ast_strlen_zero(md5secret)) 08547 return AUTH_SUCCESSFUL; 08548 if (sipmethod == SIP_REGISTER || sipmethod == SIP_SUBSCRIBE) { 08549 /* On a REGISTER, we have to use 401 and its family of headers instead of 407 and its family 08550 of headers -- GO SIP! Whoo hoo! Two things that do the same thing but are used in 08551 different circumstances! What a surprise. */ 08552 response = "401 Unauthorized"; 08553 reqheader = "Authorization"; 08554 respheader = "WWW-Authenticate"; 08555 } 08556 authtoken = get_header(req, reqheader); 08557 if (ignore && !ast_strlen_zero(p->randdata) && ast_strlen_zero(authtoken)) { 08558 /* This is a retransmitted invite/register/etc, don't reconstruct authentication 08559 information */ 08560 if (!reliable) { 08561 /* Resend message if this was NOT a reliable delivery. Otherwise the 08562 retransmission should get it */ 08563 transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, 0); 08564 /* Schedule auto destroy in 32 seconds (according to RFC 3261) */ 08565 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 08566 } 08567 return AUTH_CHALLENGE_SENT; 08568 } else if (ast_strlen_zero(p->randdata) || ast_strlen_zero(authtoken)) { 08569 /* We have no auth, so issue challenge and request authentication */ 08570 ast_string_field_build(p, randdata, "%08lx", ast_random()); /* Create nonce for challenge */ 08571 transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, 0); 08572 /* Schedule auto destroy in 32 seconds */ 08573 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 08574 return AUTH_CHALLENGE_SENT; 08575 } 08576 08577 /* --- We have auth, so check it */ 08578 08579 /* Whoever came up with the authentication section of SIP can suck my %&#$&* for not putting 08580 an example in the spec of just what it is you're doing a hash on. */ 08581 08582 if (!(buf = ast_dynamic_str_thread_get(&check_auth_buf, CHECK_AUTH_BUF_INITLEN))) 08583 return AUTH_SECRET_FAILED; /*! XXX \todo need a better return code here */ 08584 08585 /* Make a copy of the response and parse it */ 08586 res = ast_dynamic_str_thread_set(&buf, 0, &check_auth_buf, "%s", authtoken); 08587 08588 if (res == AST_DYNSTR_BUILD_FAILED) 08589 return AUTH_SECRET_FAILED; /*! XXX \todo need a better return code here */ 08590 08591 c = buf->str; 08592 08593 while(c && *(c = ast_skip_blanks(c)) ) { /* lookup for keys */ 08594 for (i = keys; i->key != NULL; i++) { 08595 const char *separator = ","; /* default */ 08596 08597 if (strncasecmp(c, i->key, strlen(i->key)) != 0) 08598 continue; 08599 /* Found. Skip keyword, take text in quotes or up to the separator. */ 08600 c += strlen(i->key); 08601 if (*c == '"') { /* in quotes. Skip first and look for last */ 08602 c++; 08603 separator = "\""; 08604 } 08605 i->s = c; 08606 strsep(&c, separator); 08607 break; 08608 } 08609 if (i->key == NULL) /* not found, jump after space or comma */ 08610 strsep(&c, " ,"); 08611 } 08612 08613 /* Verify that digest username matches the username we auth as */ 08614 if (strcmp(username, keys[K_USER].s)) { 08615 ast_log(LOG_WARNING, "username mismatch, have <%s>, digest has <%s>\n", 08616 username, keys[K_USER].s); 08617 /* Oops, we're trying something here */ 08618 return AUTH_USERNAME_MISMATCH; 08619 } 08620 08621 /* Verify nonce from request matches our nonce. If not, send 401 with new nonce */ 08622 if (strcasecmp(p->randdata, keys[K_NONCE].s)) { /* XXX it was 'n'casecmp ? */ 08623 wrongnonce = TRUE; 08624 usednonce = keys[K_NONCE].s; 08625 } 08626 08627 if (!ast_strlen_zero(md5secret)) 08628 ast_copy_string(a1_hash, md5secret, sizeof(a1_hash)); 08629 else { 08630 char a1[256]; 08631 snprintf(a1, sizeof(a1), "%s:%s:%s", username, global_realm, secret); 08632 ast_md5_hash(a1_hash, a1); 08633 } 08634 08635 /* compute the expected response to compare with what we received */ 08636 { 08637 char a2[256]; 08638 char a2_hash[256]; 08639 char resp[256]; 08640 08641 snprintf(a2, sizeof(a2), "%s:%s", sip_methods[sipmethod].text, 08642 S_OR(keys[K_URI].s, uri)); 08643 ast_md5_hash(a2_hash, a2); 08644 snprintf(resp, sizeof(resp), "%s:%s:%s", a1_hash, usednonce, a2_hash); 08645 ast_md5_hash(resp_hash, resp); 08646 } 08647 08648 good_response = keys[K_RESP].s && 08649 !strncasecmp(keys[K_RESP].s, resp_hash, strlen(resp_hash)); 08650 if (wrongnonce) { 08651 if (good_response) { 08652 if (sipdebug) 08653 ast_log(LOG_NOTICE, "Correct auth, but based on stale nonce received from '%s'\n", get_header(req, "To")); 08654 /* We got working auth token, based on stale nonce . */ 08655 ast_string_field_build(p, randdata, "%08lx", ast_random()); 08656 transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, TRUE); 08657 } else { 08658 /* Everything was wrong, so give the device one more try with a new challenge */ 08659 if (!ast_test_flag(req, SIP_PKT_IGNORE)) { 08660 if (sipdebug) 08661 ast_log(LOG_NOTICE, "Bad authentication received from '%s'\n", get_header(req, "To")); 08662 ast_string_field_build(p, randdata, "%08lx", ast_random()); 08663 } else { 08664 if (sipdebug) 08665 ast_log(LOG_NOTICE, "Duplicate authentication received from '%s'\n", get_header(req, "To")); 08666 } 08667 transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, FALSE); 08668 } 08669 08670 /* Schedule auto destroy in 32 seconds */ 08671 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 08672 return AUTH_CHALLENGE_SENT; 08673 } 08674 if (good_response) { 08675 append_history(p, "AuthOK", "Auth challenge succesful for %s", username); 08676 return AUTH_SUCCESSFUL; 08677 } 08678 08679 /* Ok, we have a bad username/secret pair */ 08680 /* Tell the UAS not to re-send this authentication data, because 08681 it will continue to fail 08682 */ 08683 08684 return AUTH_SECRET_FAILED; 08685 }
| static void check_auth_buf_init | ( | void | ) | [static] |
| static void check_pendings | ( | struct sip_pvt * | p | ) | [static] |
Check pending actions on SIP call.
Definition at line 12204 of file chan_sip.c.
References ast_clear_flag, ast_log(), ast_test_flag, sip_pvt::callid, DEFAULT_TRANS_TIMEOUT, FALSE, sip_pvt::flags, INV_CALLING, INV_EARLY_MEDIA, INV_PROCEEDING, sip_pvt::invitestate, sip_pvt::lastinvite, LOG_DEBUG, option_debug, sip_pvt::pendinginvite, SIP_BYE, SIP_CANCEL, SIP_NEEDREINVITE, SIP_PENDINGBYE, sip_scheddestroy(), transmit_reinvite_with_sdp(), transmit_request(), transmit_request_with_auth(), TRUE, sip_pvt::waitid, and XMIT_RELIABLE.
Referenced by handle_request(), and handle_response_invite().
12205 { 12206 if (ast_test_flag(&p->flags[0], SIP_PENDINGBYE)) { 12207 /* if we can't BYE, then this is really a pending CANCEL */ 12208 if (p->invitestate == INV_PROCEEDING || p->invitestate == INV_EARLY_MEDIA) 12209 transmit_request(p, SIP_CANCEL, p->lastinvite, XMIT_RELIABLE, FALSE); 12210 /* Actually don't destroy us yet, wait for the 487 on our original 12211 INVITE, but do set an autodestruct just in case we never get it. */ 12212 else { 12213 /* We have a pending outbound invite, don't send someting 12214 new in-transaction */ 12215 if (p->pendinginvite) 12216 return; 12217 12218 /* Perhaps there is an SD change INVITE outstanding */ 12219 transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, TRUE); 12220 } 12221 ast_clear_flag(&p->flags[0], SIP_PENDINGBYE); 12222 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 12223 } else if (ast_test_flag(&p->flags[0], SIP_NEEDREINVITE)) { 12224 /* if we can't REINVITE, hold it for later */ 12225 if (p->pendinginvite || p->invitestate == INV_CALLING || p->invitestate == INV_PROCEEDING || p->invitestate == INV_EARLY_MEDIA || p->waitid > 0) { 12226 if (option_debug) 12227 ast_log(LOG_DEBUG, "NOT Sending pending reinvite (yet) on '%s'\n", p->callid); 12228 } else { 12229 if (option_debug) 12230 ast_log(LOG_DEBUG, "Sending pending reinvite on '%s'\n", p->callid); 12231 /* Didn't get to reinvite yet, so do it now */ 12232 transmit_reinvite_with_sdp(p); 12233 ast_clear_flag(&p->flags[0], SIP_NEEDREINVITE); 12234 } 12235 } 12236 }
| 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 16809 of file chan_sip.c.
References ast_copy_string(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_strlen_zero(), domain::context, domain::domain, and result.
Referenced by func_check_sipdomain(), get_destination(), handle_request_refer(), and register_verify().
16810 { 16811 struct domain *d; 16812 int result = 0; 16813 16814 AST_LIST_LOCK(&domain_list); 16815 AST_LIST_TRAVERSE(&domain_list, d, list) { 16816 if (strcasecmp(d->domain, domain)) 16817 continue; 16818 16819 if (len && !ast_strlen_zero(d->context)) 16820 ast_copy_string(context, d->context, len); 16821 16822 result = 1; 16823 break; 16824 } 16825 AST_LIST_UNLOCK(&domain_list); 16826 16827 return result; 16828 }
| static int check_user | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| int | sipmethod, | |||
| char * | uri, | |||
| enum xmittype | reliable, | |||
| struct sockaddr_in * | sin | |||
| ) | [static] |
Find user If we get a match, this will add a reference pointer to the user object in ASTOBJ, that needs to be unreferenced.
Definition at line 9828 of file chan_sip.c.
References check_user_full().
Referenced by handle_request_invite().
09829 { 09830 return check_user_full(p, req, sipmethod, uri, reliable, sin, NULL); 09831 }
| static enum check_auth_result check_user_full | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| int | sipmethod, | |||
| char * | uri, | |||
| enum xmittype | reliable, | |||
| struct sockaddr_in * | sin, | |||
| struct sip_peer ** | authpeer | |||
| ) | [static] |
Check if matching user or peer is defined Match user on From: user name and peer on IP/port This is used on first invite (not re-invites) and subscribe requests.
Definition at line 9504 of file chan_sip.c.
References sip_peer::accountcode, sip_user::accountcode, accountcode, sip_user::allowtransfer, sip_pvt::allowtransfer, sip_peer::amaflags, sip_user::amaflags, sip_pvt::amaflags, ast_apply_ha(), ast_copy_flags, ast_copy_string(), AST_FORMAT_VIDEO_MASK, ast_inet_ntoa(), ast_is_shrinkable_phonenumber(), ast_log(), ast_rtp_codec_setpref(), ast_rtp_destroy(), AST_RTP_DTMF, ast_set_flag, ast_shrink_phone_number(), ast_strdupa, ast_string_field_free, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_uri_decode(), ast_variable_new(), ast_verbose(), ASTOBJ_REF, ASTOBJ_UNREF, AUTH_FAKE_AUTH, AUTH_SECRET_FAILED, AUTH_SUCCESSFUL, sip_peer::autoframing, sip_user::autoframing, sip_pvt::autoframing, build_contact(), sip_peer::call_limit, sip_user::call_limit, sip_peer::callgroup, sip_user::callgroup, sip_pvt::callgroup, sip_peer::callingpres, sip_user::callingpres, sip_pvt::callingpres, sip_peer::capability, sip_user::capability, sip_pvt::capability, sip_peer::chanvars, sip_pvt::chanvars, sip_user::chanvars, check_auth(), sip_peer::cid_name, sip_user::cid_name, cid_name, sip_peer::cid_num, sip_user::cid_num, cid_num, sip_peer::context, domain::context, sip_user::context, debug, do_setnat(), exten, sip_pvt::exten, find_peer(), find_user(), sip_peer::flags, sip_user::flags, sip_pvt::flags, sip_peer::fullcontact, get_calleridname(), get_header(), get_in_brackets(), get_rpid_num(), sip_user::ha, t38properties::jointcapability, sip_pvt::jointcapability, sip_pvt::jointnoncodeccapability, sip_peer::language, sip_user::language, language, sip_peer::lastms, LOG_NOTICE, LOG_WARNING, sip_peer::maxcallbitrate, sip_user::maxcallbitrate, sip_pvt::maxcallbitrate, sip_peer::maxms, sip_peer::md5secret, sip_user::md5secret, sip_peer::mohinterpret, sip_user::mohinterpret, mohinterpret, sip_peer::mohsuggest, sip_user::mohsuggest, mohsuggest, sip_peer::name, sip_user::name, ast_variable::next, sip_pvt::noncodeccapability, sip_pvt::our_contact, t38properties::peercapability, sip_pvt::peercapability, sip_pvt::peermd5secret, sip_pvt::peersecret, sip_peer::pickupgroup, sip_user::pickupgroup, sip_pvt::pickupgroup, sip_peer::prefs, sip_user::prefs, sip_pvt::prefs, sip_pvt::recv, sip_pvt::rtp, sip_peer::secret, sip_user::secret, SIP_CALL_LIMIT, sip_cancel_destroy(), sip_debug_test_addr(), sip_destroy_peer(), sip_destroy_user(), SIP_DTMF, SIP_DTMF_AUTO, SIP_DTMF_RFC2833, SIP_FLAGS_TO_COPY, SIP_INSECURE_INVITE, SIP_INVITE, SIP_NAT_ROUTE, SIP_PAGE2_FLAGS_TO_COPY, SIP_PAGE2_VIDEOSUPPORT, SIP_PKT_IGNORE, SIP_SUBSCRIBE, SIP_TRUSTRPID, sip_peer::sipoptions, sip_user::sipoptions, sip_pvt::sipoptions, sip_peer::subscribecontext, sip_user::subscribecontext, t, sip_pvt::t38, sip_pvt::timer_t1, sip_peer::username, username, and sip_pvt::vrtp.
Referenced by check_user(), and handle_request_subscribe().
09507 { 09508 struct sip_user *user = NULL; 09509 struct sip_peer *peer; 09510 char from[256], *c; 09511 char *of; 09512 char rpid_num[50]; 09513 const char *rpid; 09514 enum check_auth_result res = AUTH_SUCCESSFUL; 09515 char *t; 09516 char calleridname[50]; 09517 int debug=sip_debug_test_addr(sin); 09518 struct ast_variable *tmpvar = NULL, *v = NULL; 09519 char *uri2 = ast_strdupa(uri); 09520 09521 /* Terminate URI */ 09522 t = uri2; 09523 while (*t && *t > 32 && *t != ';') 09524 t++; 09525 *t = '\0'; 09526 ast_copy_string(from, get_header(req, "From"), sizeof(from)); /* XXX bug in original code, overwrote string */ 09527 if (pedanticsipchecking) 09528 ast_uri_decode(from); 09529 /* XXX here tries to map the username for invite things */ 09530 memset(calleridname, 0, sizeof(calleridname)); 09531 get_calleridname(from, calleridname, sizeof(calleridname)); 09532 if (calleridname[0]) 09533 ast_string_field_set(p, cid_name, calleridname); 09534 09535 rpid = get_header(req, "Remote-Party-ID"); 09536 memset(rpid_num, 0, sizeof(rpid_num)); 09537 if (!ast_strlen_zero(rpid)) 09538 p->callingpres = get_rpid_num(rpid, rpid_num, sizeof(rpid_num)); 09539 09540 of = get_in_brackets(from); 09541 if (ast_strlen_zero(p->exten)) { 09542 t = uri2; 09543 if (!strncasecmp(t, "sip:", 4)) 09544 t+= 4; 09545 ast_string_field_set(p, exten, t); 09546 t = strchr(p->exten, '@'); 09547 if (t) 09548 *t = '\0'; 09549 if (ast_strlen_zero(p->our_contact)) 09550 build_contact(p); 09551 } 09552 /* save the URI part of the From header */ 09553 ast_string_field_set(p, from, of); 09554 if (strncasecmp(of, "sip:", 4)) { 09555 ast_log(LOG_NOTICE, "From address missing 'sip:', using it anyway\n"); 09556 } else 09557 of += 4; 09558 /* Get just the username part */ 09559 if ((c = strchr(of, '@'))) { 09560 char *tmp; 09561 *c = '\0'; 09562 if ((c = strchr(of, ':'))) 09563 *c = '\0'; 09564 tmp = ast_strdupa(of); 09565 /* We need to be able to handle auth-headers looking like 09566 <sip:8164444422;phone-context=+1@1.2.3.4:5060;user=phone;tag=SDadkoa01-gK0c3bdb43> 09567 */ 09568 tmp = strsep(&tmp, ";"); 09569 if (ast_is_shrinkable_phonenumber(tmp)) 09570 ast_shrink_phone_number(tmp); 09571 ast_string_field_set(p, cid_num, tmp); 09572 } 09573 09574 if (!authpeer) /* If we are looking for a peer, don't check the user objects (or realtime) */ 09575 user = find_user(of, 1); 09576 09577 /* Find user based on user name in the from header */ 09578 if (user && ast_apply_ha(user->ha, sin)) { 09579 ast_copy_flags(&p->flags[0], &user->flags[0], SIP_FLAGS_TO_COPY); 09580 ast_copy_flags(&p->flags[1], &user->flags[1], SIP_PAGE2_FLAGS_TO_COPY); 09581 if (sipmethod == SIP_INVITE) { 09582 /* copy channel vars */ 09583 for (v = user->chanvars ; v ; v = v->next) { 09584 if ((tmpvar = ast_variable_new(v->name, v->value))) { 09585 tmpvar->next = p->chanvars; 09586 p->chanvars = tmpvar; 09587 } 09588 } 09589 } 09590 p->prefs = user->prefs; 09591 /* Set Frame packetization */ 09592 if (p->rtp) { 09593 ast_rtp_codec_setpref(p->rtp, &p->prefs); 09594 p->autoframing = user->autoframing; 09595 } 09596 /* replace callerid if rpid found, and not restricted */ 09597 if (!ast_strlen_zero(rpid_num) && ast_test_flag(&p->flags[0], SIP_TRUSTRPID)) { 09598 char *tmp; 09599 if (*calleridname) 09600 ast_string_field_set(p, cid_name, calleridname); 09601 tmp = ast_strdupa(rpid_num); 09602 if (ast_is_shrinkable_phonenumber(tmp)) 09603 ast_shrink_phone_number(tmp); 09604 ast_string_field_set(p, cid_num, tmp); 09605 } 09606 09607 do_setnat(p, ast_test_flag(&p->flags[0], SIP_NAT_ROUTE) ); 09608 09609 if (!(res = check_auth(p, req, user->name, user->secret, user->md5secret, sipmethod, uri2, reliable, ast_test_flag(req, SIP_PKT_IGNORE)))) { 09610 if (sip_cancel_destroy(p)) 09611 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 09612 ast_copy_flags(&p->flags[0], &user->flags[0], SIP_FLAGS_TO_COPY); 09613 ast_copy_flags(&p->flags[1], &user->flags[1], SIP_PAGE2_FLAGS_TO_COPY); 09614 /* Copy SIP extensions profile from INVITE */ 09615 if (p->sipoptions) 09616 user->sipoptions = p->sipoptions; 09617 09618 /* If we have a call limit, set flag */ 09619 if (user->call_limit) 09620 ast_set_flag(&p->flags[0], SIP_CALL_LIMIT); 09621 if (!ast_strlen_zero(user->context)) 09622 ast_string_field_set(p, context, user->context); 09623 if (!ast_strlen_zero(user->cid_num)) { 09624 char *tmp = ast_strdupa(user->cid_num); 09625 if (ast_is_shrinkable_phonenumber(tmp)) 09626 ast_shrink_phone_number(tmp); 09627 ast_string_field_set(p, cid_num, tmp); 09628 } 09629 if (!ast_strlen_zero(user->cid_name)) 09630 ast_string_field_set(p, cid_name, user->cid_name); 09631 ast_string_field_set(p, username, user->name); 09632 ast_string_field_set(p, peername, user->name); 09633 ast_string_field_set(p, peersecret, user->secret); 09634 ast_string_field_set(p, peermd5secret, user->md5secret); 09635 ast_string_field_set(p, subscribecontext, user->subscribecontext); 09636 ast_string_field_set(p, accountcode, user->accountcode); 09637 ast_string_field_set(p, language, user->language); 09638 ast_string_field_set(p, mohsuggest, user->mohsuggest); 09639 ast_string_field_set(p, mohinterpret, user->mohinterpret); 09640 p->allowtransfer = user->allowtransfer; 09641 p->amaflags = user->amaflags; 09642 p->callgroup = user->callgroup; 09643 p->pickupgroup = user->pickupgroup; 09644 if (user->callingpres) /* User callingpres setting will override RPID header */ 09645 p->callingpres = user->callingpres; 09646 09647 /* Set default codec settings for this call */ 09648 p->capability = user->capability; /* User codec choice */ 09649 p->jointcapability = user->capability; /* Our codecs */ 09650 if (p->peercapability) /* AND with peer's codecs */ 09651 p->jointcapability &= p->peercapability; 09652 if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) || 09653 (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) 09654 p->noncodeccapability |= AST_RTP_DTMF; 09655 else 09656 p->noncodeccapability &= ~AST_RTP_DTMF; 09657 p->jointnoncodeccapability = p->noncodeccapability; 09658 if (p->t38.peercapability) 09659 p->t38.jointcapability &= p->t38.peercapability; 09660 p->maxcallbitrate = user->maxcallbitrate; 09661 /* If we do not support video, remove video from call structure */ 09662 if ((!ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) || !(p->capability & AST_FORMAT_VIDEO_MASK)) && p->vrtp) { 09663 ast_rtp_destroy(p->vrtp); 09664 p->vrtp = NULL; 09665 } 09666 } 09667 if (user && debug) 09668 ast_verbose("Found user '%s'\n", user->name); 09669 } else { 09670 if (user) { 09671 if (!authpeer && debug) 09672 ast_verbose("Found user '%s', but fails host access\n", user->name); 09673 ASTOBJ_UNREF(user,sip_destroy_user); 09674 } 09675 user = NULL; 09676 } 09677 09678 if (!user) { 09679 /* If we didn't find a user match, check for peers */ 09680 if (sipmethod == SIP_SUBSCRIBE) 09681 /* For subscribes, match on peer name only */ 09682 peer = find_peer(of, NULL, 1, 0); 09683 else 09684 /* Look for peer based on the IP address we received data from */ 09685 /* If peer is registered from this IP address or have this as a default 09686 IP address, this call is from the peer 09687 */ 09688 peer = find_peer(NULL, &p->recv, 1, 0); 09689 09690 if (peer) { 09691 /* Set Frame packetization */ 09692 if (p->rtp) { 09693 ast_rtp_codec_setpref(p->rtp, &peer->prefs); 09694 p->autoframing = peer->autoframing; 09695 } 09696 if (debug) 09697 ast_verbose("Found peer '%s'\n", peer->name); 09698 09699 /* Take the peer */ 09700 ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY); 09701 ast_copy_flags(&p->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY); 09702 09703 /* Copy SIP extensions profile to peer */ 09704 if (p->sipoptions) 09705 peer->sipoptions = p->sipoptions; 09706 09707 /* replace callerid if rpid found, and not restricted */ 09708 if (!ast_strlen_zero(rpid_num) && ast_test_flag(&p->flags[0], SIP_TRUSTRPID)) { 09709 char *tmp = ast_strdupa(rpid_num); 09710 if (*calleridname) 09711 ast_string_field_set(p, cid_name, calleridname); 09712 if (ast_is_shrinkable_phonenumber(tmp)) 09713 ast_shrink_phone_number(tmp); 09714 ast_string_field_set(p, cid_num, tmp); 09715 } 09716 do_setnat(p, ast_test_flag(&p->flags[0], SIP_NAT_ROUTE)); 09717 09718 ast_string_field_set(p, peersecret, peer->secret); 09719 ast_string_field_set(p, peermd5secret, peer->md5secret); 09720 ast_string_field_set(p, subscribecontext, peer->subscribecontext); 09721 ast_string_field_set(p, mohinterpret, peer->mohinterpret); 09722 ast_string_field_set(p, mohsuggest, peer->mohsuggest); 09723 if (peer->callingpres) /* Peer calling pres setting will override RPID */ 09724 p->callingpres = peer->callingpres; 09725 if (peer->maxms && peer->lastms) 09726 p->timer_t1 = peer->lastms < global_t1min ? global_t1min : peer->lastms; 09727 if (ast_test_flag(&peer->flags[0], SIP_INSECURE_INVITE)) { 09728 /* Pretend there is no required authentication */ 09729 ast_string_field_free(p, peersecret); 09730 ast_string_field_free(p, peermd5secret); 09731 } 09732 if (!(res = check_auth(p, req, peer->name, p->peersecret, p->peermd5secret, sipmethod, uri2, reliable, ast_test_flag(req, SIP_PKT_IGNORE)))) { 09733 ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY); 09734 ast_copy_flags(&p->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY); 09735 /* If we have a call limit, set flag */ 09736 if (peer->call_limit) 09737 ast_set_flag(&p->flags[0], SIP_CALL_LIMIT); 09738 ast_string_field_set(p, peername, peer->name); 09739 ast_string_field_set(p, authname, peer->name); 09740 09741 if (sipmethod == SIP_INVITE) { 09742 /* copy channel vars */ 09743 for (v = peer->chanvars ; v ; v = v->next) { 09744 if ((tmpvar = ast_variable_new(v->name, v->value))) { 09745 tmpvar->next = p->chanvars; 09746 p->chanvars = tmpvar; 09747 } 09748 } 09749 } 09750 if (authpeer) { 09751 (*authpeer) = ASTOBJ_REF(peer); /* Add a ref to the object here, to keep it in memory a bit longer if it is realtime */ 09752 } 09753 09754 if (!ast_strlen_zero(peer->username)) { 09755 ast_string_field_set(p, username, peer->username); 09756 /* Use the default username for authentication on outbound calls */ 09757 /* XXX this takes the name from the caller... can we override ? */ 09758 ast_string_field_set(p, authname, peer->username); 09759 } 09760 if (!ast_strlen_zero(peer->cid_num)) { 09761 char *tmp = ast_strdupa(peer->cid_num); 09762 if (ast_is_shrinkable_phonenumber(tmp)) 09763 ast_shrink_phone_number(tmp); 09764 ast_string_field_set(p, cid_num, tmp); 09765 } 09766 if (!ast_strlen_zero(peer->cid_name)) 09767 ast_string_field_set(p, cid_name, peer->cid_name); 09768 ast_string_field_set(p, fullcontact, peer->fullcontact); 09769 if (!ast_strlen_zero(peer->context)) 09770 ast_string_field_set(p, context, peer->context); 09771 ast_string_field_set(p, peersecret, peer->secret); 09772 ast_string_field_set(p, peermd5secret, peer->md5secret); 09773 ast_string_field_set(p, language, peer->language); 09774 ast_string_field_set(p, accountcode, peer->accountcode); 09775 p->amaflags = peer->amaflags; 09776 p->callgroup = peer->callgroup; 09777 p->pickupgroup = peer->pickupgroup; 09778 p->capability = peer->capability; 09779 p->prefs = peer->prefs; 09780 p->jointcapability = peer->capability; 09781 if (p->peercapability) 09782 p->jointcapability &= p->peercapability; 09783 p->maxcallbitrate = peer->maxcallbitrate; 09784 if ((!ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) || !(p->capability & AST_FORMAT_VIDEO_MASK)) && p->vrtp) { 09785 ast_rtp_destroy(p->vrtp); 09786 p->vrtp = NULL; 09787 } 09788 if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) || 09789 (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) 09790 p->noncodeccapability |= AST_RTP_DTMF; 09791 else 09792 p->noncodeccapability &= ~AST_RTP_DTMF; 09793 p->jointnoncodeccapability = p->noncodeccapability; 09794 if (p->t38.peercapability) 09795 p->t38.jointcapability &= p->t38.peercapability; 09796 } 09797 ASTOBJ_UNREF(peer, sip_destroy_peer); 09798 } else { 09799 if (debug) 09800 ast_verbose("Found no matching peer or user for '%s:%d'\n", ast_inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port)); 09801 09802 /* do we allow guests? */ 09803 if (!global_allowguest) { 09804 if (global_alwaysauthreject) 09805 res = AUTH_FAKE_AUTH; /* reject with fake authorization request */ 09806 else 09807 res = AUTH_SECRET_FAILED; /* we don't want any guests, authentication will fail */ 09808 } else if (!ast_strlen_zero(rpid_num) && ast_test_flag(&p->flags[0], SIP_TRUSTRPID)) { 09809 char *tmp = ast_strdupa(rpid_num); 09810 if (*calleridname) 09811 ast_string_field_set(p, cid_name, calleridname); 09812 if (ast_is_shrinkable_phonenumber(tmp)) 09813 ast_shrink_phone_number(tmp); 09814 ast_string_field_set(p, cid_num, tmp); 09815 } 09816 } 09817 09818 } 09819 09820 if (user) 09821 ASTOBJ_UNREF(user, sip_destroy_user); 09822 return res; 09823 }
| static void check_via | ( | struct sip_pvt * | p, | |
| const struct sip_request * | req | |||
| ) | [static] |
check Via: header for hostname, port and rport request/answer
Definition at line 9372 of file chan_sip.c.
References ast_copy_string(), ast_gethostbyname(), ast_inet_ntoa(), ast_log(), ast_set_flag, ast_skip_blanks(), ast_verbose(), sip_pvt::flags, get_header(), hp, LOG_WARNING, sip_pvt::sa, sip_debug_test_pvt(), sip_nat_mode(), SIP_NAT_ROUTE, sip_real_dst(), and STANDARD_SIP_PORT.
Referenced by handle_request_bye(), handle_request_cancel(), handle_request_invite(), handle_request_register(), handle_request_subscribe(), and transmit_response_using_temp().
09373 { 09374 char via[512]; 09375 char *c, *pt; 09376 struct hostent *hp; 09377 struct ast_hostent ahp; 09378 09379 ast_copy_string(via, get_header(req, "Via"), sizeof(via)); 09380 09381 /* Work on the leftmost value of the topmost Via header */ 09382 c = strchr(via, ','); 09383 if (c) 09384 *c = '\0'; 09385 09386 /* Check for rport */ 09387 c = strstr(via, ";rport"); 09388 if (c && (c[6] != '=')) /* rport query, not answer */ 09389 ast_set_flag(&p->flags[0], SIP_NAT_ROUTE); 09390 09391 c = strchr(via, ';'); 09392 if (c) 09393 *c = '\0'; 09394 09395 c = strchr(via, ' '); 09396 if (c) { 09397 *c = '\0'; 09398 c = ast_skip_blanks(c+1); 09399 if (strcasecmp(via, "SIP/2.0/UDP")) { 09400 ast_log(LOG_WARNING, "Don't know how to respond via '%s'\n", via); 09401 return; 09402 } 09403 pt = strchr(c, ':'); 09404 if (pt) 09405 *pt++ = '\0'; /* remember port pointer */ 09406 hp = ast_gethostbyname(c, &ahp); 09407 if (!hp) { 09408 ast_log(LOG_WARNING, "'%s' is not a valid host\n", c); 09409 return; 09410 } 09411 memset(&p->sa, 0, sizeof(p->sa)); 09412 p->sa.sin_family = AF_INET; 09413 memcpy(&p->sa.sin_addr, hp->h_addr, sizeof(p->sa.sin_addr)); 09414 p->sa.sin_port = htons(pt ? atoi(pt) : STANDARD_SIP_PORT); 09415 09416 if (sip_debug_test_pvt(p)) { 09417 const struct sockaddr_in *dst = sip_real_dst(p); 09418 ast_verbose("Sending to %s : %d (%s)\n", ast_inet_ntoa(dst->sin_addr), ntohs(dst->sin_port), sip_nat_mode(p)); 09419 } 09420 } 09421 }
| 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 10272 of file chan_sip.c.
References ast_context_destroy(), ast_context_find(), ast_copy_string(), and AST_MAX_CONTEXT.
Referenced by reload_config().
10273 { 10274 char *oldcontext, *newcontext, *stalecontext, *stringp, newlist[AST_MAX_CONTEXT]; 10275 10276 while ((oldcontext = strsep(&old, "&"))) { 10277 stalecontext = '\0'; 10278 ast_copy_string(newlist, new, sizeof(newlist)); 10279 stringp = newlist; 10280 while ((newcontext = strsep(&stringp, "&"))) { 10281 if (strcmp(newcontext, oldcontext) == 0) { 10282 /* This is not the context you're looking for */ 10283 stalecontext = '\0'; 10284 break; 10285 } else if (strcmp(newcontext, oldcontext)) { 10286 stalecontext = oldcontext; 10287 } 10288 10289 } 10290 if (stalecontext) 10291 ast_context_destroy(ast_context_find(stalecontext), "SIP"); 10292 } 10293 }
| static int clear_realm_authentication | ( | struct sip_auth * | authlist | ) | [static] |
Clear realm authentication list (at reload).
Definition at line 16902 of file chan_sip.c.
References free, and sip_auth::next.
Referenced by build_peer(), reload_config(), sip_destroy_peer(), and unload_module().
16903 { 16904 struct sip_auth *a = authlist; 16905 struct sip_auth *b; 16906 16907 while (a) { 16908 b = a; 16909 a = a->next; 16910 free(b); 16911 } 16912 16913 return 1; 16914 }
| static void clear_sip_domains | ( | void | ) | [static] |
Clear our domain list (at reload).
Definition at line 16831 of file chan_sip.c.
References AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, AST_LIST_UNLOCK, and free.
Referenced by reload_config(), and unload_module().
16832 { 16833 struct domain *d; 16834 16835 AST_LIST_LOCK(&domain_list); 16836 while ((d = AST_LIST_REMOVE_HEAD(&domain_list, list))) 16837 free(d); 16838 AST_LIST_UNLOCK(&domain_list); 16839 }
| static char * complete_sip_debug_peer | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Support routine for 'sip debug peer' CLI.
Definition at line 11090 of file chan_sip.c.
References complete_sip_peer().
11091 { 11092 if (pos == 3) 11093 return complete_sip_peer(word, state, 0); 11094 11095 return NULL; 11096 }
| static char * complete_sip_peer | ( | const char * | word, | |
| int | state, | |||
| int | flags2 | |||
| ) | [static] |
Do completion on peer name.
Definition at line 11064 of file chan_sip.c.
References ast_strdup, ast_test_flag, ASTOBJ_CONTAINER_TRAVERSE, peerl, and result.
Referenced by complete_sip_debug_peer(), complete_sip_prune_realtime_peer(), complete_sip_show_peer(), and complete_sipnotify().
11065 { 11066 char *result = NULL; 11067 int wordlen = strlen(word); 11068 int which = 0; 11069 11070 ASTOBJ_CONTAINER_TRAVERSE(&peerl, !result, do { 11071 /* locking of the object is not required because only the name and flags are being compared */ 11072 if (!strncasecmp(word, iterator->name, wordlen) && 11073 (!flags2 || ast_test_flag(&iterator->flags[1], flags2)) && 11074 ++which > state) 11075 result = ast_strdup(iterator->name); 11076 } while(0) ); 11077 return result; 11078 }
| static char * complete_sip_prune_realtime_peer | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Support routine for 'sip prune realtime peer' CLI.
Definition at line 11158 of file chan_sip.c.
References complete_sip_peer(), and SIP_PAGE2_RTCACHEFRIENDS.
11159 { 11160 if (pos == 4) 11161 return complete_sip_peer(word, state, SIP_PAGE2_RTCACHEFRIENDS); 11162 return NULL; 11163 }
| static char * complete_sip_prune_realtime_user | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Support routine for 'sip prune realtime user' CLI.
Definition at line 11166 of file chan_sip.c.
References complete_sip_user(), and SIP_PAGE2_RTCACHEFRIENDS.
11167 { 11168 if (pos == 4) 11169 return complete_sip_user(word, state, SIP_PAGE2_RTCACHEFRIENDS); 11170 11171 return NULL; 11172 }
| 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 11081 of file chan_sip.c.
References complete_sip_peer().
11082 { 11083 if (pos == 3) 11084 return complete_sip_peer(word, state, 0); 11085 11086 return NULL; 11087 }
| 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 11119 of file chan_sip.c.
References complete_sip_user().
11120 { 11121 if (pos == 3) 11122 return complete_sip_user(word, state, 0); 11123 11124 return NULL; 11125 }
| static char * complete_sip_user | ( | const char * | word, | |
| int | state, | |||
| int | flags2 | |||
| ) | [static] |
Do completion on user name.
Definition at line 11099 of file chan_sip.c.
References ast_strdup, ast_test_flag, ASTOBJ_CONTAINER_TRAVERSE, result, and userl.
Referenced by complete_sip_prune_realtime_user(), and complete_sip_show_user().
11100 { 11101 char *result = NULL; 11102 int wordlen = strlen(word); 11103 int which = 0; 11104 11105 ASTOBJ_CONTAINER_TRAVERSE(&userl, !result, do { 11106 /* locking of the object is not required because only the name and flags are being compared */ 11107 if (!strncasecmp(word, iterator->name, wordlen)) { 11108 if (flags2 && !ast_test_flag(&iterator->flags[1], flags2)) 11109 continue; 11110 if (++which > state) { 11111 result = ast_strdup(iterator->name); 11112 } 11113 } 11114 } while(0) ); 11115 return result; 11116 }
| static char * complete_sipch | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Support routine for 'sip show channel' CLI.
Definition at line 11041 of file chan_sip.c.
References ast_mutex_lock(), ast_mutex_unlock(), ast_strdup, sip_pvt::callid, iflist, iflock, and sip_pvt::next.
11042 { 11043 int which=0; 11044 struct sip_pvt *cur; 11045 char *c = NULL; 11046 int wordlen = strlen(word); 11047 11048 if (pos != 3) { 11049 return NULL; 11050 } 11051 11052 ast_mutex_lock(&iflock); 11053 for (cur = iflist; cur; cur = cur->next) { 11054 if (!strncasecmp(word, cur->callid, wordlen) && ++which > state) { 11055 c = ast_strdup(cur->callid); 11056 break; 11057 } 11058 } 11059 ast_mutex_unlock(&iflock); 11060 return c; 11061 }
| static char * complete_sipnotify | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Support routine for 'sip notify' CLI.
Definition at line 11128 of file chan_sip.c.
References ast_category_browse(), ast_strdup, and complete_sip_peer().
11129 { 11130 char *c = NULL; 11131 11132 if (pos == 2) { 11133 int which = 0; 11134 char *cat = NULL; 11135 int wordlen = strlen(word); 11136 11137 /* do completion for notify type */ 11138 11139 if (!notify_types) 11140 return NULL; 11141 11142 while ( (cat = ast_category_browse(notify_types, cat)) ) { 11143 if (!strncasecmp(word, cat, wordlen) && ++which > state) { 11144 c = ast_strdup(cat); 11145 break; 11146 } 11147 } 11148 return c; 11149 } 11150 11151 if (pos > 2) 11152 return complete_sip_peer(word, state, 0); 11153 11154 return NULL; 11155 }
| 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 5752 of file chan_sip.c.
References __get_header(), add_header(), and ast_strlen_zero().
Referenced by respprep().
05753 { 05754 int start = 0; 05755 int copied = 0; 05756 for (;;) { 05757 const char *tmp = __get_header(orig, field, &start); 05758 05759 if (ast_strlen_zero(tmp)) 05760 break; 05761 /* Add what we're responding to */ 05762 add_header(req, field, tmp); 05763 copied++; 05764 } 05765 return copied ? 0 : -1; 05766 }
| 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 5741 of file chan_sip.c.
References add_header(), ast_log(), ast_strlen_zero(), get_header(), and LOG_NOTICE.
Referenced by reqprep(), and respprep().
05742 { 05743 const char *tmp = get_header(orig, field); 05744 05745 if (!ast_strlen_zero(tmp)) /* Add what we're responding to */ 05746 return add_header(req, field, tmp); 05747 ast_log(LOG_NOTICE, "No field '%s' present to copy\n", field); 05748 return -1; 05749 }
| 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 6798 of file chan_sip.c.
References sip_request::header, sip_request::line, offset, sip_request::rlPart1, and sip_request::rlPart2.
Referenced by handle_request_bye(), handle_request_invite(), handle_request_refer(), handle_request_register(), handle_request_subscribe(), initialize_initreq(), sip_park(), and sip_park_thread().
06799 { 06800 long offset; 06801 int x; 06802 offset = ((void *)dst) - ((void *)src); 06803 /* First copy stuff */ 06804 memcpy(dst, src, sizeof(*dst)); 06805 /* Now fix pointer arithmetic */ 06806 for (x=0; x < src->headers; x++) 06807 dst->header[x] += offset; 06808 for (x=0; x < src->lines; x++) 06809 dst->line[x] += offset; 06810 dst->rlPart1 += offset; 06811 dst->rlPart2 += offset; 06812 }
| 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.
Definition at line 5774 of file chan_sip.c.
References __get_header(), add_header(), ast_copy_string(), ast_inet_ntoa(), ast_log(), ast_strlen_zero(), ast_test_flag, sip_pvt::flags, LOG_NOTICE, sip_pvt::recv, SIP_NAT, SIP_NAT_ALWAYS, and SIP_NAT_RFC3581.
Referenced by respprep().
05775 { 05776 int copied = 0; 05777 int start = 0; 05778 05779 for (;;) { 05780 char new[512]; 05781 const char *oh = __get_header(orig, field, &start); 05782 05783 if (ast_strlen_zero(oh)) 05784 break; 05785 05786 if (!copied) { /* Only check for empty rport in topmost via header */ 05787 char leftmost[512], *others, *rport; 05788 05789 /* Only work on leftmost value */ 05790 ast_copy_string(leftmost, oh, sizeof(leftmost)); 05791 others = strchr(leftmost, ','); 05792 if (others) 05793 *others++ = '\0'; 05794 05795 /* Find ;rport; (empty request) */ 05796 rport = strstr(leftmost, ";rport"); 05797 if (rport && *(rport+6) == '=') 05798 rport = NULL; /* We already have a parameter to rport */ 05799 05800 /* Check rport if NAT=yes or NAT=rfc3581 (which is the default setting) */ 05801 if (rport && ((ast_test_flag(&p->flags[0], SIP_NAT) == SIP_NAT_ALWAYS) || (ast_test_flag(&p->flags[0], SIP_NAT) == SIP_NAT_RFC3581))) { 05802 /* We need to add received port - rport */ 05803 char *end; 05804 05805 rport = strstr(leftmost, ";rport"); 05806 05807 if (rport) { 05808 end = strchr(rport + 1, ';'); 05809 if (end) 05810 memmove(rport, end, strlen(end) + 1); 05811 else 05812 *rport = '\0'; 05813 } 05814 05815 /* Add rport to first VIA header if requested */ 05816 snprintf(new, sizeof(new), "%s;received=%s;rport=%d%s%s", 05817 leftmost, ast_inet_ntoa(p->recv.sin_addr), 05818 ntohs(p->recv.sin_port), 05819 others ? "," : "", others ? others : ""); 05820 } else { 05821 /* We should *always* add a received to the topmost via */ 05822 snprintf(new, sizeof(new), "%s;received=%s%s%s", 05823 leftmost, ast_inet_ntoa(p->recv.sin_addr), 05824 others ? "," : "", others ? others : ""); 05825 } 05826 oh = new; /* the header to copy */ 05827 } /* else add the following via headers untouched */ 05828 add_header(req, field, oh); 05829 copied++; 05830 } 05831 if (!copied) { 05832 ast_log(LOG_NOTICE, "No header field '%s' present to copy\n", field); 05833 return -1; 05834 } 05835 return 0; 05836 }
| static int create_addr | ( | struct sip_pvt * | dialog, | |
| const char * | opeer | |||
| ) | [static] |
create address structure from peer name Or, if peer not found, find it in the global DNS returns TRUE (-1) on failure, FALSE on success
Definition at line 2906 of file chan_sip.c.
References ast_copy_string(), ast_get_srv(), ast_gethostbyname(), ast_log(), ast_string_field_set, ASTOBJ_UNREF, create_addr_from_peer(), find_peer(), hp, LOG_WARNING, portno, sip_pvt::recv, sip_pvt::sa, sip_destroy_peer(), STANDARD_SIP_PORT, sip_pvt::timer_t1, and sip_peer::tohost.
Referenced by handle_request_invite(), sip_notify(), sip_request_call(), and transmit_register().
02907 { 02908 struct hostent *hp; 02909 struct ast_hostent ahp; 02910 struct sip_peer *p; 02911 char *port; 02912 int portno; 02913 char host[MAXHOSTNAMELEN], *hostn; 02914 char peer[256]; 02915 02916 ast_copy_string(peer, opeer, sizeof(peer)); 02917 port = strchr(peer, ':'); 02918 if (port) 02919 *port++ = '\0'; 02920 dialog->sa.sin_family = AF_INET; 02921 dialog->timer_t1 = 500; /* Default SIP retransmission timer T1 (RFC 3261) */ 02922 p = find_peer(peer, NULL, 1, 0); 02923 02924 if (p) { 02925 int res = create_addr_from_peer(dialog, p); 02926 if (port) { 02927 portno = atoi(port); 02928 dialog->sa.sin_port = dialog->recv.sin_port = htons(portno); 02929 } 02930 ASTOBJ_UNREF(p, sip_destroy_peer); 02931 return res; 02932 } 02933 hostn = peer; 02934 portno = port ? atoi(port) : STANDARD_SIP_PORT; 02935 if (srvlookup) { 02936 char service[MAXHOSTNAMELEN]; 02937 int tportno; 02938 int ret; 02939 02940 snprintf(service, sizeof(service), "_sip._udp.%s", peer); 02941 ret = ast_get_srv(NULL, host, sizeof(host), &tportno, service); 02942 if (ret > 0) { 02943 hostn = host; 02944 portno = tportno; 02945 } 02946 } 02947 hp = ast_gethostbyname(hostn, &ahp); 02948 if (!hp) { 02949 ast_log(LOG_WARNING, "No such host: %s\n", peer); 02950 return -1; 02951 } 02952 ast_string_field_set(dialog, tohost, peer); 02953 memcpy(&dialog->sa.sin_addr, hp->h_addr, sizeof(dialog->sa.sin_addr)); 02954 dialog->sa.sin_port = htons(portno); 02955 dialog->recv = dialog->sa; 02956 return 0; 02957 }
Create address structure from peer reference. return -1 on error, 0 on success.
Definition at line 2797 of file chan_sip.c.
References sip_peer::addr, sip_peer::allowtransfer, sip_pvt::allowtransfer, ast_copy_flags, AST_FORMAT_VIDEO_MASK, ast_inet_ntoa(), ast_log(), ast_rtp_codec_setpref(), ast_rtp_destroy(), AST_RTP_DTMF, ast_rtp_set_rtpholdtimeout(), ast_rtp_set_rtpkeepalive(), ast_rtp_set_rtptimeout(), ast_rtp_setdtmf(), ast_rtp_setdtmfcompensate(), ast_set_flag, ast_strdupa, ast_string_field_build, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_udptl_destroy(), ast_udptl_get_error_correction_scheme(), sip_peer::auth, sip_peer::autoframing, sip_pvt::autoframing, sip_peer::call_limit, sip_peer::callgroup, sip_pvt::callgroup, sip_pvt::callid, t38properties::capability, sip_peer::capability, sip_pvt::capability, sip_peer::context, domain::context, sip_peer::defaddr, do_setnat(), sip_peer::flags, sip_pvt::flags, sip_peer::fromdomain, sip_peer::fromuser, sip_peer::fullcontact, sip_request::headers, sip_pvt::initreq, t38properties::jointcapability, sip_pvt::jointnoncodeccapability, language, sip_peer::language, sip_peer::lastms, LOG_DEBUG, sip_peer::maxcallbitrate, sip_pvt::maxcallbitrate, sip_peer::maxms, sip_pvt::maxtime, sip_peer::md5secret, sip_peer::mohinterpret, mohinterpret, sip_peer::mohsuggest, mohsuggest, sip_peer::name, sip_pvt::noncodeccapability, option_debug, sip_pvt::peerauth, sip_peer::pickupgroup, sip_pvt::pickupgroup, sip_peer::prefs, sip_pvt::prefs, sip_pvt::recv, sip_pvt::rtp, sip_peer::rtpholdtimeout, sip_peer::rtpkeepalive, sip_pvt::rtptimeout, sip_peer::rtptimeout, sip_pvt::sa, sip_peer::secret, SIP_CALL_LIMIT, SIP_DTMF, SIP_DTMF_AUTO, SIP_DTMF_RFC2833, SIP_FLAGS_TO_COPY, SIP_NAT, SIP_NAT_ROUTE, SIP_PAGE2_FLAGS_TO_COPY, SIP_PAGE2_RFC2833_COMPENSATE, SIP_PAGE2_T38SUPPORT, SIP_PAGE2_VIDEOSUPPORT, sip_pvt::t38, T38FAX_RATE_MANAGEMENT_TRANSFERED_TCF, T38FAX_UDP_EC_FEC, T38FAX_UDP_EC_NONE, T38FAX_UDP_EC_REDUNDANCY, sip_pvt::timer_t1, sip_pvt::tohost, sip_peer::tohost, sip_pvt::udptl, UDPTL_ERROR_CORRECTION_FEC, UDPTL_ERROR_CORRECTION_NONE, UDPTL_ERROR_CORRECTION_REDUNDANCY, username, sip_peer::username, and sip_pvt::vrtp.
Referenced by create_addr(), and sip_send_mwi_to_peer().
02798 { 02799 if ((peer->addr.sin_addr.s_addr || peer->defaddr.sin_addr.s_addr) && 02800 (!peer->maxms || ((peer->lastms >= 0) && (peer->lastms <= peer->maxms)))) { 02801 dialog->sa = (peer->addr.sin_addr.s_addr) ? peer->addr : peer->defaddr; 02802 dialog->recv = dialog->sa; 02803 } else 02804 return -1; 02805 02806 ast_copy_flags(&dialog->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY); 02807 ast_copy_flags(&dialog->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY); 02808 dialog->capability = peer->capability; 02809 if ((!ast_test_flag(&dialog->flags[1], SIP_PAGE2_VIDEOSUPPORT) || !(dialog->capability & AST_FORMAT_VIDEO_MASK)) && dialog->vrtp) { 02810 ast_rtp_destroy(dialog->vrtp); 02811 dialog->vrtp = NULL; 02812 } 02813 dialog->prefs = peer->prefs; 02814 if (ast_test_flag(&dialog->flags[1], SIP_PAGE2_T38SUPPORT)) { 02815 dialog->t38.capability = global_t38_capability; 02816 if (dialog->udptl) { 02817 if (ast_udptl_get_error_correction_scheme(dialog->udptl) == UDPTL_ERROR_CORRECTION_FEC ) 02818 dialog->t38.capability |= T38FAX_UDP_EC_FEC; 02819 else if (ast_udptl_get_error_correction_scheme(dialog->udptl) == UDPTL_ERROR_CORRECTION_REDUNDANCY ) 02820 dialog->t38.capability |= T38FAX_UDP_EC_REDUNDANCY; 02821 else if (ast_udptl_get_error_correction_scheme(dialog->udptl) == UDPTL_ERROR_CORRECTION_NONE ) 02822 dialog->t38.capability |= T38FAX_UDP_EC_NONE; 02823 dialog->t38.capability |= T38FAX_RATE_MANAGEMENT_TRANSFERED_TCF; 02824 if (option_debug > 1) 02825 ast_log(LOG_DEBUG,"Our T38 capability (%d)\n", dialog->t38.capability); 02826 } 02827 dialog->t38.jointcapability = dialog->t38.capability; 02828 } else if (dialog->udptl) { 02829 ast_udptl_destroy(dialog->udptl); 02830 dialog->udptl = NULL; 02831 } 02832 do_setnat(dialog, ast_test_flag(&dialog->flags[0], SIP_NAT) & SIP_NAT_ROUTE ); 02833 02834 if (dialog->rtp) { 02835 ast_rtp_setdtmf(dialog->rtp, ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833); 02836 ast_rtp_setdtmfcompensate(dialog->rtp, ast_test_flag(&dialog->flags[1], SIP_PAGE2_RFC2833_COMPENSATE)); 02837 ast_rtp_set_rtptimeout(dialog->rtp, peer->rtptimeout); 02838 ast_rtp_set_rtpholdtimeout(dialog->rtp, peer->rtpholdtimeout); 02839 ast_rtp_set_rtpkeepalive(dialog->rtp, peer->rtpkeepalive); 02840 /* Set Frame packetization */ 02841 ast_rtp_codec_setpref(dialog->rtp, &dialog->prefs); 02842 dialog->autoframing = peer->autoframing; 02843 } 02844 if (dialog->vrtp) { 02845 ast_rtp_setdtmf(dialog->vrtp, 0); 02846 ast_rtp_setdtmfcompensate(dialog->vrtp, 0); 02847 ast_rtp_set_rtptimeout(dialog->vrtp, peer->rtptimeout); 02848 ast_rtp_set_rtpholdtimeout(dialog->vrtp, peer->rtpholdtimeout); 02849 ast_rtp_set_rtpkeepalive(dialog->vrtp, peer->rtpkeepalive); 02850 } 02851 02852 ast_string_field_set(dialog, peername, peer->name); 02853 ast_string_field_set(dialog, authname, peer->username); 02854 ast_string_field_set(dialog, username, peer->username); 02855 ast_string_field_set(dialog, peersecret, peer->secret); 02856 ast_string_field_set(dialog, peermd5secret, peer->md5secret); 02857 ast_string_field_set(dialog, mohsuggest, peer->mohsuggest); 02858 ast_string_field_set(dialog, mohinterpret, peer->mohinterpret); 02859 ast_string_field_set(dialog, tohost, peer->tohost); 02860 ast_string_field_set(dialog, fullcontact, peer->fullcontact); 02861 if (!dialog->initreq.headers && !ast_strlen_zero(peer->fromdomain)) { 02862 char *tmpcall; 02863 char *c; 02864 tmpcall = ast_strdupa(dialog->callid); 02865 c = strchr(tmpcall, '@'); 02866 if (c) { 02867 *c = '\0'; 02868 ast_string_field_build(dialog, callid, "%s@%s", tmpcall, peer->fromdomain); 02869 } 02870 } 02871 if (ast_strlen_zero(dialog->tohost)) 02872 ast_string_field_set(dialog, tohost, ast_inet_ntoa(dialog->sa.sin_addr)); 02873 if (!ast_strlen_zero(peer->fromdomain)) 02874 ast_string_field_set(dialog, fromdomain, peer->fromdomain); 02875 if (!ast_strlen_zero(peer->fromuser)) 02876 ast_string_field_set(dialog, fromuser, peer->fromuser); 02877 if (!ast_strlen_zero(peer->language)) 02878 ast_string_field_set(dialog, language, peer->language); 02879 dialog->maxtime = peer->maxms; 02880 dialog->callgroup = peer->callgroup; 02881 dialog->pickupgroup = peer->pickupgroup; 02882 dialog->peerauth = peer->auth; 02883 dialog->allowtransfer = peer->allowtransfer; 02884 /* Set timer T1 to RTT for this peer (if known by qualify=) */ 02885 /* Minimum is settable or default to 100 ms */ 02886 if (peer->maxms && peer->lastms) 02887 dialog->timer_t1 = peer->lastms < global_t1min ? global_t1min : peer->lastms; 02888 if ((ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) || 02889 (ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) 02890 dialog->noncodeccapability |= AST_RTP_DTMF; 02891 else 02892 dialog->noncodeccapability &= ~AST_RTP_DTMF; 02893 dialog->jointnoncodeccapability = dialog->noncodeccapability; 02894 ast_string_field_set(dialog, context, peer->context); 02895 dialog->rtptimeout = peer->rtptimeout; 02896 if (peer->call_limit) 02897 ast_set_flag(&dialog->flags[0], SIP_CALL_LIMIT); 02898 dialog->maxcallbitrate = peer->maxcallbitrate; 02899 02900 return 0; 02901 }
| static void destroy_association | ( | struct sip_peer * | peer | ) | [static] |
Remove registration data from realtime database or AST/DB when registration expires.
Definition at line 7989 of file chan_sip.c.
References ast_db_del(), ast_test_flag, ast_update_realtime(), sip_peer::flags, sip_peer::name, SIP_PAGE2_IGNOREREGEXPIRE, and SIP_PAGE2_RT_FROMCONTACT.
Referenced by build_peer(), expire_register(), and parse_register_contact().
07990 { 07991 if (!ast_test_flag(&global_flags[1], SIP_PAGE2_IGNOREREGEXPIRE)) { 07992 if (ast_test_flag(&peer->flags[1], SIP_PAGE2_RT_FROMCONTACT)) 07993 ast_update_realtime("sippeers", "name", peer->name, "fullcontact", "", "ipaddr", "", "port", "", "regseconds", "0", "username", "", "regserver", "", NULL); 07994 else 07995 ast_db_del("SIP/Registry", peer->name); 07996 } 07997 }
| static int determine_firstline_parts | ( | struct sip_request * | req | ) | [static] |
Parse first line of incoming SIP request.
Definition at line 6842 of file chan_sip.c.
References ast_log(), ast_skip_blanks(), ast_skip_nonblanks(), ast_trim_blanks(), sip_request::header, LOG_WARNING, sip_request::rlPart1, and sip_request::rlPart2.
Referenced by parse_request().
06843 { 06844 char *e = ast_skip_blanks(req->header[0]); /* there shouldn't be any */ 06845 06846 if (!*e) 06847 return -1; 06848 req->rlPart1 = e; /* method or protocol */ 06849 e = ast_skip_nonblanks(e); 06850 if (*e) 06851 *e++ = '\0'; 06852 /* Get URI or status code */ 06853 e = ast_skip_blanks(e); 06854 if ( !*e ) 06855 return -1; 06856 ast_trim_blanks(e); 06857 06858 if (!strcasecmp(req->rlPart1, "SIP/2.0") ) { /* We have a response */ 06859 if (strlen(e) < 3) /* status code is 3 digits */ 06860 return -1; 06861 req->rlPart2 = e; 06862 } else { /* We have a request */ 06863 if ( *e == '<' ) { /* XXX the spec says it must not be in <> ! */ 06864 ast_log(LOG_WARNING, "bogus uri in <> %s\n", e); 06865 e++; 06866 if (!*e) 06867 return -1; 06868 } 06869 req->rlPart2 = e; /* URI */ 06870 e = ast_skip_nonblanks(e); 06871 if (*e) 06872 *e++ = '\0'; 06873 e = ast_skip_blanks(e); 06874 if (strcasecmp(e, "SIP/2.0") ) { 06875 ast_log(LOG_WARNING, "Bad request protocol %s\n", e); 06876 return -1; 06877 } 06878 } 06879 return 1; 06880 }
| static void * do_monitor | ( | void * | data | ) | [static] |
The SIP monitoring thread.
Definition at line 16109 of file chan_sip.c.
References __sip_destroy(), ast_channel_trylock, ast_channel_unlock, ast_io_add(), ast_io_change(), AST_IO_IN, ast_io_remove(), ast_io_wait(), ast_log(), ast_mutex_lock(), ast_mutex_trylock(), ast_mutex_unlock(), ast_rtp_get_peer(), ast_rtp_get_rtpholdtimeout(), ast_rtp_get_rtpkeepalive(), ast_rtp_get_rtptimeout(), ast_rtp_sendcng(), ast_rtp_set_rtpholdtimeout(), ast_rtp_set_rtptimeout(), ast_sched_runq(), ast_sched_wait(), AST_SOFTHANGUP_DEV, ast_softhangup_nolock(), AST_STATE_UP, ast_test_flag, ast_verbose(), ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_REF, ASTOBJ_UNLOCK, ASTOBJ_UNREF, ASTOBJ_WRLOCK, DEADLOCK_AVOIDANCE, does_peer_need_mwi(), FALSE, iflist, iflock, LOG_DEBUG, LOG_NOTICE, monlock, sip_pvt::next, option_debug, option_verbose, peerl, sip_destroy_peer(), sip_do_reload(), SIP_NEEDDESTROY, sip_reload_lock, sip_send_mwi_to_peer(), sipsock_read(), t, T38_ENABLED, TRUE, and VERBOSE_PREFIX_1.
16110 { 16111 int res; 16112 struct sip_pvt *sip; 16113 struct sip_peer *peer = NULL; 16114 time_t t; 16115 int fastrestart = FALSE; 16116 int lastpeernum = -1; 16117 int curpeernum; 16118 int reloading; 16119 16120 /* Add an I/O event to our SIP UDP socket */ 16121 if (sipsock > -1) 16122 sipsock_read_id = ast_io_add(io, sipsock, sipsock_read, AST_IO_IN, NULL); 16123 16124 /* From here on out, we die whenever asked */ 16125 for(;;) { 16126 /* Check for a reload request */ 16127 ast_mutex_lock(&sip_reload_lock); 16128 reloading = sip_reloading; 16129 sip_reloading = FALSE; 16130 ast_mutex_unlock(&sip_reload_lock); 16131 if (reloading) { 16132 if (option_verbose > 0) 16133 ast_verbose(VERBOSE_PREFIX_1 "Reloading SIP\n"); 16134 sip_do_reload(sip_reloadreason); 16135 16136 /* Change the I/O fd of our UDP socket */ 16137 if (sipsock > -1) { 16138 if (sipsock_read_id) 16139 sipsock_read_id = ast_io_change(io, sipsock_read_id, sipsock, NULL, 0, NULL); 16140 else 16141 sipsock_read_id = ast_io_add(io, sipsock, sipsock_read, AST_IO_IN, NULL); 16142 } else if (sipsock_read_id) { 16143 ast_io_remove(io, sipsock_read_id); 16144 sipsock_read_id = NULL; 16145 } 16146 } 16147 restartsearch: 16148 /* Check for interfaces needing to be killed */ 16149 ast_mutex_lock(&iflock); 16150 t = time(NULL); 16151 /* don't scan the interface list if it hasn't been a reasonable period 16152 of time since the last time we did it (when MWI is being sent, we can 16153 get back to this point every millisecond or less) 16154 */ 16155 for (sip = iflist; !fastrestart && sip; sip = sip->next) { 16156 /*! \note If we can't get a lock on an interface, skip it and come 16157 * back later. Note that there is the possibility of a deadlock with 16158 * sip_hangup otherwise, because sip_hangup is called with the channel 16159 * locked first, and the iface lock is attempted second. 16160 */ 16161 if (ast_mutex_trylock(&sip->lock)) 16162 continue; 16163 16164 /* Check RTP timeouts and kill calls if we have a timeout set and do not get RTP */ 16165 if (sip->rtp && sip->owner && 16166 (sip->owner->_state == AST_STATE_UP) && 16167 !sip->redirip.sin_addr.s_addr && 16168 sip->t38.state != T38_ENABLED) { 16169 if (sip->lastrtptx && 16170 ast_rtp_get_rtpkeepalive(sip->rtp) && 16171 (t > sip->lastrtptx + ast_rtp_get_rtpkeepalive(sip->rtp))) { 16172 /* Need to send an empty RTP packet */ 16173 sip->lastrtptx = time(NULL); 16174 ast_rtp_sendcng(sip->rtp, 0); 16175 } 16176 if (sip->lastrtprx && 16177 (ast_rtp_get_rtptimeout(sip->rtp) || ast_rtp_get_rtpholdtimeout(sip->rtp)) && 16178 (t > sip->lastrtprx + ast_rtp_get_rtptimeout(sip->rtp))) { 16179 /* Might be a timeout now -- see if we're on hold */ 16180 struct sockaddr_in sin; 16181 ast_rtp_get_peer(sip->rtp, &sin); 16182 if (sin.sin_addr.s_addr || 16183 (ast_rtp_get_rtpholdtimeout(sip->rtp) && 16184 (t > sip->lastrtprx + ast_rtp_get_rtpholdtimeout(sip->rtp)))) { 16185 /* Needs a hangup */ 16186 if (ast_rtp_get_rtptimeout(sip->rtp)) { 16187 while (sip->owner && ast_channel_trylock(sip->owner)) { 16188 DEADLOCK_AVOIDANCE(&sip->lock); 16189 } 16190 if (sip->owner) { 16191 ast_log(LOG_NOTICE, 16192 "Disconnecting call '%s' for lack of RTP activity in %ld seconds\n", 16193 sip->owner->name, 16194 (long) (t - sip->lastrtprx)); 16195 /* Issue a softhangup */ 16196 ast_softhangup_nolock(sip->owner, AST_SOFTHANGUP_DEV); 16197 ast_channel_unlock(sip->owner); 16198 /* forget the timeouts for this call, since a hangup 16199 has already been requested and we don't want to 16200 repeatedly request hangups 16201 */ 16202 ast_rtp_set_rtptimeout(sip->rtp, 0); 16203 ast_rtp_set_rtpholdtimeout(sip->rtp, 0); 16204 if (sip->vrtp) { 16205 ast_rtp_set_rtptimeout(sip->vrtp, 0); 16206 ast_rtp_set_rtpholdtimeout(sip->vrtp, 0); 16207 } 16208 } 16209 } 16210 } 16211 } 16212 } 16213 /* If we have sessions that needs to be destroyed, do it now */ 16214 if (ast_test_flag(&sip->flags[0], SIP_NEEDDESTROY) && !sip->packets && 16215 !sip->owner) { 16216 ast_mutex_unlock(&sip->lock); 16217 __sip_destroy(sip, 1); 16218 ast_mutex_unlock(&iflock); 16219 usleep(1); 16220 goto restartsearch; 16221 } 16222 ast_mutex_unlock(&sip->lock); 16223 } 16224 ast_mutex_unlock(&iflock); 16225 16226 /* XXX TODO The scheduler usage in this module does not have sufficient 16227 * synchronization being done between running the scheduler and places 16228 * scheduling tasks. As it is written, any scheduled item may not run 16229 * any sooner than about 1 second, regardless of whether a sooner time 16230 * was asked for. */ 16231 16232 pthread_testcancel(); 16233 /* Wait for sched or io */ 16234 res = ast_sched_wait(sched); 16235 if ((res < 0) || (res > 1000)) 16236 res = 1000; 16237 /* If we might need to send more mailboxes, don't wait long at all.*/ 16238 if (fastrestart) 16239 res = 1; 16240 res = ast_io_wait(io, res); 16241 if (option_debug && res > 20) 16242 ast_log(LOG_DEBUG, "chan_sip: ast_io_wait ran %d all at once\n", res); 16243 ast_mutex_lock(&monlock); 16244 res = ast_sched_runq(sched); 16245 if (option_debug && res >= 20) 16246 ast_log(LOG_DEBUG, "chan_sip: ast_sched_runq ran %d all at once\n", res); 16247 16248 /* Send MWI notifications to peers - static and cached realtime peers */ 16249 t = time(NULL); 16250 fastrestart = FALSE; 16251 curpeernum = 0; 16252 peer = NULL; 16253 /* Find next peer that needs mwi */ 16254 ASTOBJ_CONTAINER_TRAVERSE(&peerl, !peer, do { 16255 if ((curpeernum > lastpeernum) && does_peer_need_mwi(iterator)) { 16256 fastrestart = TRUE; 16257 lastpeernum = curpeernum; 16258 peer = ASTOBJ_REF(iterator); 16259 }; 16260 curpeernum++; 16261 } while (0) 16262 ); 16263 /* Send MWI to the peer */ 16264 if (peer) { 16265 ASTOBJ_WRLOCK(peer); 16266 sip_send_mwi_to_peer(peer); 16267 ASTOBJ_UNLOCK(peer); 16268 ASTOBJ_UNREF(peer,sip_destroy_peer); 16269 } else { 16270 /* Reset where we come from */ 16271 lastpeernum = -1; 16272 } 16273 ast_mutex_unlock(&monlock); 16274 } 16275 /* Never reached */ 16276 return NULL; 16277 16278 }
| static int do_proxy_auth | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| char * | header, | |||
| char * | respheader, | |||
| int | sipmethod, | |||
| int | init | |||
| ) | [static] |
Add authentication on outbound SIP packet.
Definition at line 11631 of file chan_sip.c.
References ast_calloc, ast_log(), sip_invite_param::auth, sip_invite_param::authheader, sip_pvt::authtries, LOG_DEBUG, option_debug, sip_pvt::options, reply_digest(), SIP_INVITE, sip_methods, cfsip_methods::text, and transmit_invite().
Referenced by handle_response(), handle_response_invite(), and handle_response_refer().
11632 { 11633 char digest[1024]; 11634 11635 if (!p->options && !(p->options = ast_calloc(1, sizeof(*p->options)))) 11636 return -2; 11637 11638 p->authtries++; 11639 if (option_debug > 1) 11640 ast_log(LOG_DEBUG, "Auth attempt %d on %s\n", p->authtries, sip_methods[sipmethod].text); 11641 memset(digest, 0, sizeof(digest)); 11642 if (reply_digest(p, req, header, sipmethod, digest, sizeof(digest) )) { 11643 /* No way to authenticate */ 11644 return -1; 11645 } 11646 /* Now we have a reply digest */ 11647 p->options->auth = digest; 11648 p->options->authheader = respheader; 11649 return transmit_invite(p, sipmethod, sipmethod == SIP_INVITE, init); 11650 }
| static int do_register_auth | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| char * | header, | |||
| char * | respheader | |||
| ) | [static] |
Authenticate for outbound registration.
Definition at line 11610 of file chan_sip.c.
References append_history, ast_test_flag, ast_verbose(), sip_pvt::authtries, sip_pvt::flags, sip_registry::hostname, sip_pvt::registry, reply_digest(), sip_debug_test_pvt(), SIP_NO_HISTORY, SIP_REGISTER, and transmit_register().
Referenced by handle_response_register().
11611 { 11612 char digest[1024]; 11613 p->authtries++; 11614 memset(digest,0,sizeof(digest)); 11615 if (reply_digest(p, req, header, SIP_REGISTER, digest, sizeof(digest))) { 11616 /* There's nothing to use for authentication */ 11617 /* No digest challenge in request */ 11618 if (sip_debug_test_pvt(p) && p->registry) 11619 ast_verbose("No authentication challenge, sending blank registration to domain/host name %s\n", p->registry->hostname); 11620 /* No old challenge */ 11621 return -1; 11622 } 11623 if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) 11624 append_history(p, "RegistryAuth", "Try: %d", p->authtries); 11625 if (sip_debug_test_pvt(p) && p->registry) 11626 ast_verbose("Responding to challenge, registration to domain/host name %s\n", p->registry->hostname); 11627 return transmit_register(p->registry, SIP_REGISTER, digest, respheader); 11628 }
| static void do_setnat | ( | struct sip_pvt * | p, | |
| int | natflags | |||
| ) | [static] |
Set nat mode on the various data sockets.
Definition at line 2773 of file chan_sip.c.
References ast_log(), ast_rtp_setnat(), ast_udptl_setnat(), LOG_DEBUG, domain::mode, option_debug, sip_pvt::rtp, sip_pvt::udptl, and sip_pvt::vrtp.
Referenced by check_user_full(), create_addr_from_peer(), sip_alloc(), and transmit_response_using_temp().
02774 { 02775 const char *mode = natflags ? "On" : "Off"; 02776 02777 if (p->rtp) { 02778 if (option_debug) 02779 ast_log(LOG_DEBUG, "Setting NAT on RTP to %s\n", mode); 02780 ast_rtp_setnat(p->rtp, natflags); 02781 } 02782 if (p->vrtp) { 02783 if (option_debug) 02784 ast_log(LOG_DEBUG, "Setting NAT on VRTP to %s\n", mode); 02785 ast_rtp_setnat(p->vrtp, natflags); 02786 } 02787 if (p->udptl) { 02788 if (option_debug) 02789 ast_log(LOG_DEBUG, "Setting NAT on UDPTL to %s\n", mode); 02790 ast_udptl_setnat(p->udptl, natflags); 02791 } 02792 }
| static int does_peer_need_mwi | ( | struct sip_peer * | peer | ) | [static] |
Check whether peer needs a new MWI notification check.
Definition at line 16088 of file chan_sip.c.
References ast_strlen_zero(), ast_test_flag, FALSE, sip_peer::flags, sip_peer::lastmsgcheck, sip_peer::mailbox, sip_peer::mwipvt, SIP_PAGE2_SUBSCRIBEMWIONLY, t, and TRUE.
Referenced by do_monitor().
16089 { 16090 time_t t = time(NULL); 16091 16092 if (ast_test_flag(&peer->flags[1], SIP_PAGE2_SUBSCRIBEMWIONLY) && 16093 !peer->mwipvt) { /* We don't have a subscription */ 16094 peer->lastmsgcheck = t; /* Reset timer */ 16095 return FALSE; 16096 } 16097 16098 if (!ast_strlen_zero(peer->mailbox) && (t - peer->lastmsgcheck) > global_mwitime) 16099 return TRUE; 16100 16101 return FALSE; 16102 }
| static const char * domain_mode_to_text | ( | const enum domain_mode | mode | ) | [static] |
Print domain mode to cli.
Definition at line 10461 of file chan_sip.c.
References SIP_DOMAIN_AUTO, and SIP_DOMAIN_CONFIG.
Referenced by sip_show_domains().
10462 { 10463 switch (mode) { 10464 case SIP_DOMAIN_AUTO: 10465 return "[Automatic]"; 10466 case SIP_DOMAIN_CONFIG: 10467 return "[Configured]"; 10468 } 10469 10470 return ""; 10471 }
| static const char * dtmfmode2str | ( | int | mode | ) | [static] |
Convert DTMF mode to printable string.
Definition at line 10241 of file chan_sip.c.
References SIP_DTMF_AUTO, SIP_DTMF_INBAND, SIP_DTMF_INFO, and SIP_DTMF_RFC2833.
Referenced by _sip_show_peer(), sip_show_channel(), and sip_show_settings().
10242 { 10243 switch (mode) { 10244 case SIP_DTMF_RFC2833: 10245 return "rfc2833"; 10246 case SIP_DTMF_INFO: 10247 return "info"; 10248 case SIP_DTMF_INBAND: 10249 return "inband"; 10250 case SIP_DTMF_AUTO: 10251 return "auto"; 10252 } 10253 return "<error>"; 10254 }
| static int expire_register | ( | const void * | data | ) | [static] |
Expire registration of SIP peer.
Definition at line 8000 of file chan_sip.c.
References sip_peer::addr, ast_device_state_changed(), ast_test_flag, ASTOBJ_CONTAINER_UNLINK, ASTOBJ_UNREF, destroy_association(), EVENT_FLAG_SYSTEM, sip_peer::expire, FALSE, sip_peer::flags, manager_event(), sip_peer::name, peerl, register_peer_exten(), sip_destroy_peer(), SIP_PAGE2_RTAUTOCLEAR, and SIP_PAGE2_SELFDESTRUCT.
Referenced by parse_register_contact(), realtime_peer(), and reg_source_db().
08001 { 08002 struct sip_peer *peer = (struct sip_peer *)data; 08003 08004 if (!peer) /* Hmmm. We have no peer. Weird. */ 08005 return 0; 08006 08007 memset(&peer->addr, 0, sizeof(peer->addr)); 08008 08009 destroy_association(peer); /* remove registration data from storage */ 08010 08011 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: SIP/%s\r\nPeerStatus: Unregistered\r\nCause: Expired\r\n", peer->name); 08012 register_peer_exten(peer, FALSE); /* Remove regexten */ 08013 peer->expire = -1; 08014 ast_device_state_changed("SIP/%s", peer->name); 08015 08016 /* Do we need to release this peer from memory? 08017 Only for realtime peers and autocreated peers 08018 */ 08019 if (ast_test_flag(&peer->flags[1], SIP_PAGE2_SELFDESTRUCT) || 08020 ast_test_flag(&peer->flags[1], SIP_PAGE2_RTAUTOCLEAR)) { 08021 struct sip_peer *peer_ptr = peer_ptr; 08022 peer_ptr = ASTOBJ_CONTAINER_UNLINK(&peerl, peer); 08023 if (peer_ptr) { 08024 ASTOBJ_UNREF(peer_ptr, sip_destroy_peer); 08025 } 08026 } 08027 08028 ASTOBJ_UNREF(peer, sip_destroy_peer); 08029 08030 return 0; 08031 }
| static void extract_uri | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Check Contact: URI of SIP message.
Definition at line 6932 of file chan_sip.c.
References ast_copy_string(), ast_string_field_set, ast_strlen_zero(), get_header(), get_in_brackets(), and SIPBUFSIZE.
Referenced by handle_request(), and handle_request_invite().
06933 { 06934 char stripped[SIPBUFSIZE]; 06935 char *c; 06936 06937 ast_copy_string(stripped, get_header(req, "Contact"), sizeof(stripped)); 06938 c = get_in_brackets(stripped); 06939 c = strsep(&c, ";"); /* trim ; and beyond */ 06940 if (!ast_strlen_zero(c)) 06941 ast_string_field_set(p, uri, c); 06942 }
| 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 4253 of file chan_sip.c.
References aliases.
Referenced by __get_header(), and add_header().
04254 { 04255 /*! \brief Structure for conversion between compressed SIP and "normal" SIP */ 04256 static const struct cfalias { 04257 char * const fullname; 04258 char * const shortname; 04259 } aliases[] = { 04260 { "Content-Type", "c" }, 04261 { "Content-Encoding", "e" }, 04262 { "From", "f" }, 04263 { "Call-ID", "i" }, 04264 { "Contact", "m" }, 04265 { "Content-Length", "l" }, 04266 { "Subject", "s" }, 04267 { "To", "t" }, 04268 { "Supported", "k" }, 04269 { "Refer-To", "r" }, 04270 { "Referred-By", "b" }, 04271 { "Allow-Events", "u" }, 04272 { "Event", "o" }, 04273 { "Via", "v" }, 04274 { "Accept-Contact", "a" }, 04275 { "Reject-Contact", "j" }, 04276 { "Request-Disposition", "d" }, 04277 { "Session-Expires", "x" }, 04278 { "Identity", "y" }, 04279 { "Identity-Info", "n" }, 04280 }; 04281 int x; 04282 04283 for (x=0; x<sizeof(aliases) / sizeof(aliases[0]); x++) 04284 if (!strcasecmp(aliases[x].fullname, name)) 04285 return aliases[x].shortname; 04286 04287 return _default; 04288 }
| static struct sip_pvt * find_call | ( | struct sip_request * | req, | |
| struct sockaddr_in * | sin, | |||
| const int | intended_method | |||
| ) | [static, read] |
Connect incoming SIP message to current dialog or create new dialog structure Called by handle_request, sipsock_read.
Definition at line 4620 of file chan_sip.c.
References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_set_flag, ast_strlen_zero(), ast_test_flag, sip_pvt::callid, CAN_CREATE_DIALOG, CAN_CREATE_DIALOG_UNSUPPORTED_METHOD, FALSE, sip_pvt::flags, sip_pvt::from, get_header(), gettag(), iflist, iflock, sip_pvt::lock, LOG_DEBUG, sip_request::method, sip_pvt::next, option_debug, SIP_ACK, sip_alloc(), sip_methods, SIP_NOTIFY, SIP_PAGE2_DIALOG_ESTABLISHED, SIP_PKT_WITH_TOTAG, SIP_REFER, SIP_REGISTER, SIP_RESPONSE, sip_pvt::tag, cfsip_methods::text, sip_pvt::theirtag, and transmit_response_using_temp().
Referenced by sipsock_read().
04621 { 04622 struct sip_pvt *p = NULL; 04623 char *tag = ""; /* note, tag is never NULL */ 04624 char totag[128]; 04625 char fromtag[128]; 04626 const char *callid = get_header(req, "Call-ID"); 04627 const char *from = get_header(req, "From"); 04628 const char *to = get_header(req, "To"); 04629 const char *cseq = get_header(req, "Cseq"); 04630 04631 /* Call-ID, to, from and Cseq are required by RFC 3261. (Max-forwards and via too - ignored now) */ 04632 /* get_header always returns non-NULL so we must use ast_strlen_zero() */ 04633 if (ast_strlen_zero(callid) || ast_strlen_zero(to) || 04634 ast_strlen_zero(from) || ast_strlen_zero(cseq)) 04635 return NULL; /* Invalid packet */ 04636 04637 if (pedanticsipchecking) { 04638 /* In principle Call-ID's uniquely identify a call, but with a forking SIP proxy 04639 we need more to identify a branch - so we have to check branch, from 04640 and to tags to identify a call leg. 04641 For Asterisk to behave correctly, you need to turn on pedanticsipchecking 04642 in sip.conf 04643 */ 04644 if (gettag(req, "To", totag, sizeof(totag))) 04645 ast_set_flag(req, SIP_PKT_WITH_TOTAG); /* Used in handle_request/response */ 04646 gettag(req, "From", fromtag, sizeof(fromtag)); 04647 04648 tag = (req->method == SIP_RESPONSE) ? totag : fromtag; 04649 04650 if (option_debug > 4 ) 04651 ast_log(LOG_DEBUG, "= Looking for Call ID: %s (Checking %s) --From tag %s --To-tag %s \n", callid, req->method==SIP_RESPONSE ? "To" : "From", fromtag, totag); 04652 } 04653 04654 ast_mutex_lock(&iflock); 04655 for (p = iflist; p; p = p->next) { 04656 /* In pedantic, we do not want packets with bad syntax to be connected to a PVT */ 04657 int found = FALSE; 04658 if (ast_strlen_zero(p->callid)) 04659 continue; 04660 if (req->method == SIP_REGISTER) 04661 found = (!strcmp(p->callid, callid)); 04662 else { 04663 found = !strcmp(p->callid, callid); 04664 if (pedanticsipchecking && found) { 04665 found = ast_strlen_zero(tag) || ast_strlen_zero(p->theirtag) || !ast_test_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED) || !strcmp(p->theirtag, tag); 04666 } 04667 } 04668 04669 if (option_debug > 4) 04670 ast_log(LOG_DEBUG, "= %s Their Call ID: %s Their Tag %s Our tag: %s\n", found ? "Found" : "No match", p->callid, p->theirtag, p->tag); 04671 04672 /* If we get a new request within an existing to-tag - check the to tag as well */ 04673 if (pedanticsipchecking && found && req->method != SIP_RESPONSE) { /* SIP Request */ 04674 if (p->tag[0] == '\0' && totag[0]) { 04675 /* We have no to tag, but they have. Wrong dialog */ 04676 found = FALSE; 04677 } else if (totag[0]) { /* Both have tags, compare them */ 04678 if (strcmp(totag, p->tag)) { 04679 found = FALSE; /* This is not our packet */ 04680 } 04681 } 04682 if (!found && option_debug > 4) 04683 ast_log(LOG_DEBUG, "= Being pedantic: This is not our match on request: Call ID: %s Ourtag <null> Totag %s Method %s\n", p->callid, totag, sip_methods[req->method].text); 04684 } 04685 if (found) { 04686 /* Found the call */ 04687 ast_mutex_unlock(&iflock); 04688 ast_mutex_lock(&p->lock); 04689 return p; 04690 } 04691 } 04692 ast_mutex_unlock(&iflock); 04693 04694 /* See if the method is capable of creating a dialog */ 04695 if (sip_methods[intended_method].can_create == CAN_CREATE_DIALOG) { 04696 if (intended_method == SIP_REFER) { 04697 /* We do support REFER, but not outside of a dialog yet */ 04698 transmit_response_using_temp(callid, sin, 1, intended_method, req, "603 Declined (no dialog)"); 04699 } else if (intended_method == SIP_NOTIFY) { 04700 /* We do not support out-of-dialog NOTIFY either, 04701 like voicemail notification, so cancel that early */ 04702 transmit_response_using_temp(callid, sin, 1, intended_method, req, "489 Bad event"); 04703 } else { 04704 /* Ok, time to create a new SIP dialog object, a pvt */ 04705 if ((p = sip_alloc(callid, sin, 1, intended_method))) { 04706 /* Ok, we've created a dialog, let's go and process it */ 04707 ast_mutex_lock(&p->lock); 04708 } else { 04709 /* We have a memory or file/socket error (can't allocate RTP sockets or something) so we're not 04710 getting a dialog from sip_alloc. 04711 04712 Without a dialog we can't retransmit and handle ACKs and all that, but at least 04713 send an error message. 04714 04715 Sorry, we apologize for the inconvienience 04716 */ 04717 transmit_response_using_temp(callid, sin, 1, intended_method, req, "500 Server internal error"); 04718 if (option_debug > 3) 04719 ast_log(LOG_DEBUG, "Failed allocating SIP dialog, sending 500 Server internal error and giving up\n"); 04720 } 04721 } 04722 return p; 04723 } else if( sip_methods[intended_method].can_create == CAN_CREATE_DIALOG_UNSUPPORTED_METHOD) { 04724 /* A method we do not support, let's take it on the volley */ 04725 transmit_response_using_temp(callid, sin, 1, intended_method, req, "501 Method Not Implemented"); 04726 } else if (intended_method != SIP_RESPONSE && intended_method != SIP_ACK) { 04727 /* This is a request outside of a dialog that we don't know about 04728 ...never reply to an ACK! 04729 */ 04730 transmit_response_using_temp(callid, sin, 1, intended_method, req, "481 Call leg/transaction does not exist"); 04731 } 04732 /* We do not respond to responses for dialogs that we don't know about, we just drop 04733 the session quickly */ 04734 04735 return p; 04736 }
| static const char* find_closing_quote | ( | const char * | start, | |
| const char * | lim | |||
| ) | [static] |
Locate closing quote in a string, skipping escaped quotes. optionally with a limit on the search. start must be past the first quote.
Definition at line 2334 of file chan_sip.c.
References s.
Referenced by get_in_brackets().
02335 { 02336 char last_char = '\0'; 02337 const char *s; 02338 for (s = start; *s && s != lim; last_char = *s++) { 02339 if (*s == '"' && last_char != '\\') 02340 break; 02341 } 02342 return s; 02343 }
| static struct sip_peer * find_peer | ( | const char * | peer, | |
| struct sockaddr_in * | sin, | |||
| int | realtime, | |||
| int | devstate_only | |||
| ) | [static, read] |
Locate peer by name or ip address This is used on incoming SIP message to find matching peer on ip or outgoing message to find matching peer on name.
Definition at line 2685 of file chan_sip.c.
References ASTOBJ_CONTAINER_FIND, ASTOBJ_CONTAINER_FIND_FULL, name, peerl, realtime_peer(), and sip_addrcmp().
02686 { 02687 struct sip_peer *p = NULL; 02688 02689 if (peer) 02690 p = ASTOBJ_CONTAINER_FIND(&peerl, peer); 02691 else 02692 p = ASTOBJ_CONTAINER_FIND_FULL(&peerl, sin, name, sip_addr_hashfunc, 1, sip_addrcmp); 02693 02694 if (!p && (realtime || devstate_only)) 02695 p = realtime_peer(peer, sin, devstate_only); 02696 02697 return p; 02698 }
| static struct sip_auth * find_realm_authentication | ( | struct sip_auth * | authlist, | |
| const char * | realm | |||
| ) | [static, read] |
Find authentication for a specific realm.
Definition at line 16917 of file chan_sip.c.
References sip_auth::next, and sip_auth::realm.
Referenced by build_reply_digest().
16918 { 16919 struct sip_auth *a; 16920 16921 for (a = authlist; a; a = a->next) { 16922 if (!strcasecmp(a->realm, realm)) 16923 break; 16924 } 16925 16926 return a; 16927 }
| static int find_sdp | ( | struct sip_request * | req | ) | [static] |
Determine whether a SIP message contains an SDP in its body.
| req | the SIP request to process |
Definition at line 4953 of file chan_sip.c.
References ast_log(), ast_strdupa, ast_strlen_zero(), FALSE, get_header(), sip_request::line, sip_request::lines, LOG_WARNING, sip_request::sdp_end, sip_request::sdp_start, and TRUE.
Referenced by handle_request(), handle_request_invite(), handle_response(), and handle_response_invite().
04954 { 04955 const char *content_type; 04956 const char *content_length; 04957 const char *search; 04958 char *boundary; 04959 unsigned int x; 04960 int boundaryisquoted = FALSE; 04961 int found_application_sdp = FALSE; 04962 int found_end_of_headers = FALSE; 04963 04964 content_length = get_header(req, "Content-Length"); 04965 04966 if (!ast_strlen_zero(content_length)) { 04967 if (sscanf(content_length, "%ud", &x) != 1) { 04968 ast_log(LOG_WARNING, "Invalid Content-Length: %s\n", content_length); 04969 return 0; 04970 } 04971 04972 /* Content-Length of zero means there can't possibly be an 04973 SDP here, even if the Content-Type says there is */ 04974 if (x == 0) 04975 return 0; 04976 } 04977 04978 content_type = get_header(req, "Content-Type"); 04979 04980 /* if the body contains only SDP, this is easy */ 04981 if (!strncasecmp(content_type, "application/sdp", 15)) { 04982 req->sdp_start = 0; 04983 req->sdp_end = req->lines; 04984 return req->lines ? 1 : 0; 04985 } 04986 04987 /* if it's not multipart/mixed, there cannot be an SDP */ 04988 if (strncasecmp(content_type, "multipart/mixed", 15)) 04989 return 0; 04990 04991 /* if there is no boundary marker, it's invalid */ 04992 if ((search = strcasestr(content_type, ";boundary="))) 04993 search += 10; 04994 else if ((search = strcasestr(content_type, "; boundary="))) 04995 search += 11; 04996 else 04997 return 0; 04998 04999 if (ast_strlen_zero(search)) 05000 return 0; 05001 05002 /* If the boundary is quoted with ", remove quote */ 05003 if (*search == '\"') { 05004 search++; 05005 boundaryisquoted = TRUE; 05006 } 05007 05008 /* make a duplicate of the string, with two extra characters 05009 at the beginning */ 05010 boundary = ast_strdupa(search - 2); 05011 boundary[0] = boundary[1] = '-'; 05012 /* Remove final quote */ 05013 if (boundaryisquoted) 05014 boundary[strlen(boundary) - 1] = '\0'; 05015 05016 /* search for the boundary marker, the empty line delimiting headers from 05017 sdp part and the end boundry if it exists */ 05018 05019 for (x = 0; x < (req->lines ); x++) { 05020 if(!strncasecmp(req->line[x], boundary, strlen(boundary))){ 05021 if(found_application_sdp && found_end_of_headers){ 05022 req->sdp_end = x-1; 05023 return 1; 05024 } 05025 found_application_sdp = FALSE; 05026 } 05027 if(!strcasecmp(req->line[x], "Content-Type: application/sdp")) 05028 found_application_sdp = TRUE; 05029 05030 if(strlen(req->line[x]) == 0 ){ 05031 if(found_application_sdp && !found_end_of_headers){ 05032 req->sdp_start = x; 05033 found_end_of_headers = TRUE; 05034 } 05035 } 05036 } 05037 if(found_application_sdp && found_end_of_headers) { 05038 req->sdp_end = x; 05039 return TRUE; 05040 } 05041 return FALSE; 05042 }
| static int find_sip_method | ( | const char * | msg | ) | [static] |
find_sip_method: Find SIP method from header
Definition at line 1692 of file chan_sip.c.
References ast_strlen_zero(), method_match(), and sip_methods.
Referenced by __sip_pretend_ack(), handle_response(), and sipsock_read().
01693 { 01694 int i, res = 0; 01695 01696 if (ast_strlen_zero(msg)) 01697 return 0; 01698 for (i = 1; i < (sizeof(sip_methods) / sizeof(sip_methods[0])) && !res; i++) { 01699 if (method_match(i, msg)) 01700 res = sip_methods[i].id; 01701 } 01702 return res; 01703 }
| static struct cfsubscription_types * find_subscription_type | ( | enum subscriptiontype | subtype | ) | [static, read] |
Find subscription type in array.
Definition at line 10955 of file chan_sip.c.
References subscription_types, and type.
Referenced by transmit_state_notify().
10956 { 10957 int i; 10958 10959 for (i = 1; (i < (sizeof(subscription_types) / sizeof(subscription_types[0]))); i++) { 10960 if (subscription_types[i].type == subtype) { 10961 return &subscription_types[i]; 10962 } 10963 } 10964 return &subscription_types[0]; 10965 }
| static struct sip_user * find_user | ( | const char * | name, | |
| int | realtime | |||
| ) | [static, read] |
Locate user by name Locates user by name (From: sip uri user name part) first from in-memory list (static configuration) then from realtime storage (defined in extconfig.conf).
Definition at line 2764 of file chan_sip.c.
References ASTOBJ_CONTAINER_FIND, realtime_user(), and userl.
02765 { 02766 struct sip_user *u = ASTOBJ_CONTAINER_FIND(&userl, name); 02767 if (!u && realtime) 02768 u = realtime_user(name); 02769 return u; 02770 }
| static void free_old_route | ( | struct sip_route * | route | ) | [static] |
Remove route from route list.
Definition at line 8379 of file chan_sip.c.
References free, sip_route::next, and domain::next.
Referenced by __sip_destroy(), and build_route().
08380 { 08381 struct sip_route *next; 08382 08383 while (route) { 08384 next = route->next; 08385 free(route); 08386 route = next; 08387 } 08388 }
| static int func_check_sipdomain | ( | struct ast_channel * | chan, | |
| char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Dial plan function to check if domain is local.
Definition at line 11966 of file chan_sip.c.
References ast_copy_string(), ast_log(), ast_strlen_zero(), check_sip_domain(), and LOG_WARNING.
11967 { 11968 if (ast_strlen_zero(data)) { 11969 ast_log(LOG_WARNING, "CHECKSIPDOMAIN requires an argument - A domain name\n"); 11970 return -1; 11971 } 11972 if (check_sip_domain(data, NULL, 0)) 11973 ast_copy_string(buf, data, len); 11974 else 11975 buf[0] = '\0'; 11976 return 0; 11977 }
| static int func_header_read | ( | struct ast_channel * | chan, | |
| char * | function, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Read SIP header (dialplan function).
Definition at line 11902 of file chan_sip.c.
References __get_header(), AST_APP_ARG, ast_channel_lock, ast_channel_unlock, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_log(), AST_STANDARD_APP_ARGS, ast_strlen_zero(), sip_request::header, sip_pvt::initreq, LOG_WARNING, ast_channel::tech, and ast_channel::tech_pvt.
11903 { 11904 struct sip_pvt *p; 11905 const char *content = NULL; 11906 AST_DECLARE_APP_ARGS(args, 11907 AST_APP_ARG(header); 11908 AST_APP_ARG(number); 11909 ); 11910 int i, number, start = 0; 11911 11912 if (ast_strlen_zero(data)) { 11913 ast_log(LOG_WARNING, "This function requires a header name.\n"); 11914 return -1; 11915 } 11916 11917 ast_channel_lock(chan); 11918 if (chan->tech != &sip_tech && chan->tech != &sip_tech_info) { 11919 ast_log(LOG_WARNING, "This function can only be used on SIP channels.\n"); 11920 ast_channel_unlock(chan); 11921 return -1; 11922 } 11923 11924 AST_STANDARD_APP_ARGS(args, data); 11925 if (!args.number) { 11926 number = 1; 11927 } else { 11928 sscanf(args.number, "%d", &number); 11929 if (number < 1) 11930 number = 1; 11931 } 11932 11933 p = chan->tech_pvt; 11934 11935 /* If there is no private structure, this channel is no longer alive */ 11936 if (!p) { 11937 ast_channel_unlock(chan); 11938 return -1; 11939 } 11940 11941 for (i = 0; i < number; i++) 11942 content = __get_header(&p->initreq, args.header, &start); 11943 11944 if (ast_strlen_zero(content)) { 11945 ast_channel_unlock(chan); 11946 return -1; 11947 } 11948 11949 ast_copy_string(buf, content, len); 11950 ast_channel_unlock(chan); 11951 11952 return 0; 11953 }
| static int function_sipchaninfo_read | ( | struct ast_channel * | chan, | |
| char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
${SIPCHANINFO()} Dialplan function - reads sip channel data
Definition at line 12085 of file chan_sip.c.
References ast_channel_lock, ast_channel_unlock, ast_copy_string(), ast_inet_ntoa(), ast_log(), sip_pvt::from, LOG_WARNING, sip_pvt::peername, sip_pvt::recv, sip_pvt::sa, t38properties::state, sip_pvt::t38, T38_DISABLED, ast_channel::tech, ast_channel::tech_pvt, sip_pvt::uri, and sip_pvt::useragent.
12086 { 12087 struct sip_pvt *p; 12088 12089 *buf = 0; 12090 12091 if (!data) { 12092 ast_log(LOG_WARNING, "This function requires a parameter name.\n"); 12093 return -1; 12094 } 12095 12096 ast_channel_lock(chan); 12097 if (chan->tech != &sip_tech && chan->tech != &sip_tech_info) { 12098 ast_log(LOG_WARNING, "This function can only be used on SIP channels.\n"); 12099 ast_channel_unlock(chan); 12100 return -1; 12101 } 12102 12103 p = chan->tech_pvt; 12104 12105 /* If there is no private structure, this channel is no longer alive */ 12106 if (!p) { 12107 ast_channel_unlock(chan); 12108 return -1; 12109 } 12110 12111 if (!strcasecmp(data, "peerip")) { 12112 ast_copy_string(buf, p->sa.sin_addr.s_addr ? ast_inet_ntoa(p->sa.sin_addr) : "", len); 12113 } else if (!strcasecmp(data, "recvip")) { 12114 ast_copy_string(buf, p->recv.sin_addr.s_addr ? ast_inet_ntoa(p->recv.sin_addr) : "", len); 12115 } else if (!strcasecmp(data, "from")) { 12116 ast_copy_string(buf, p->from, len); 12117 } else if (!strcasecmp(data, "uri")) { 12118 ast_copy_string(buf, p->uri, len); 12119 } else if (!strcasecmp(data, "useragent")) { 12120 ast_copy_string(buf, p->useragent, len); 12121 } else if (!strcasecmp(data, "peername")) { 12122 ast_copy_string(buf, p->peername, len); 12123 } else if (!strcasecmp(data, "t38passthrough")) { 12124 if (p->t38.state == T38_DISABLED) 12125 ast_copy_string(buf, "0", sizeof("0")); 12126 else /* T38 is offered or enabled in this call */ 12127 ast_copy_string(buf, "1", sizeof("1")); 12128 } else { 12129 ast_channel_unlock(chan); 12130 return -1; 12131 } 12132 ast_channel_unlock(chan); 12133 12134 return 0; 12135 }
| static int function_sippeer | ( | struct ast_channel * | chan, | |
| char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
${SIPPEER()} Dialplan function - reads peer data
Definition at line 11991 of file chan_sip.c.
References sip_peer::accountcode, sip_peer::addr, ast_codec_pref_index(), ast_copy_string(), ast_getformatname(), ast_getformatname_multiple(), ast_inet_ntoa(), ast_test_flag, ASTOBJ_UNREF, sip_peer::call_limit, sip_peer::capability, sip_peer::cid_name, sip_peer::cid_num, sip_peer::context, sip_peer::expire, find_peer(), sip_peer::flags, sip_peer::inUse, sip_peer::language, sip_peer::mailbox, peer_status(), sip_peer::prefs, sip_peer::regexten, sip_destroy_peer(), SIP_PAGE2_DYNAMIC, and sip_peer::useragent.
11992 { 11993 struct sip_peer *peer; 11994 char *colname; 11995 11996 if ((colname = strchr(data, ':'))) /*! \todo Will be deprecated after 1.4 */ 11997 *colname++ = '\0'; 11998 else if ((colname = strchr(data, '|'))) 11999 *colname++ = '\0'; 12000 else 12001 colname = "ip"; 12002 12003 if (!(peer = find_peer(data, NULL, 1, 0))) 12004 return -1; 12005 12006 if (!strcasecmp(colname, "ip")) { 12007 ast_copy_string(buf, peer->addr.sin_addr.s_addr ? ast_inet_ntoa(peer->addr.sin_addr) : "", len); 12008 } else if (!strcasecmp(colname, "status")) { 12009 peer_status(peer, buf, len); 12010 } else if (!strcasecmp(colname, "language")) { 12011 ast_copy_string(buf, peer->language, len); 12012 } else if (!strcasecmp(colname, "regexten")) { 12013 ast_copy_string(buf, peer->regexten, len); 12014 } else if (!strcasecmp(colname, "limit")) { 12015 snprintf(buf, len, "%d", peer->call_limit); 12016 } else if (!strcasecmp(colname, "curcalls")) { 12017 snprintf(buf, len, "%d", peer->inUse); 12018 } else if (!strcasecmp(colname, "accountcode")) { 12019 ast_copy_string(buf, peer->accountcode, len); 12020 } else if (!strcasecmp(colname, "useragent")) { 12021 ast_copy_string(buf, peer->useragent, len); 12022 } else if (!strcasecmp(colname, "mailbox")) { 12023 ast_copy_string(buf, peer->mailbox, len); 12024 } else if (!strcasecmp(colname, "context")) { 12025 ast_copy_string(buf, peer->context, len); 12026 } else if (!strcasecmp(colname, "expire")) { 12027 snprintf(buf, len, "%d", peer->expire); 12028 } else if (!strcasecmp(colname, "dynamic")) { 12029 ast_copy_string(buf, (ast_test_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC) ? "yes" : "no"), len); 12030 } else if (!strcasecmp(colname, "callerid_name")) { 12031 ast_copy_string(buf, peer->cid_name, len); 12032 } else if (!strcasecmp(colname, "callerid_num")) { 12033 ast_copy_string(buf, peer->cid_num, len); 12034 } else if (!strcasecmp(colname, "codecs")) { 12035 ast_getformatname_multiple(buf, len -1, peer->capability); 12036 } else if (!strncasecmp(colname, "codec[", 6)) { 12037 char *codecnum; 12038 int index = 0, codec = 0; 12039 12040 codecnum = colname + 6; /* move past the '[' */ 12041 codecnum = strsep(&codecnum, "]"); /* trim trailing ']' if any */ 12042 index = atoi(codecnum); 12043 if((codec = ast_codec_pref_index(&peer->prefs, index))) { 12044 ast_copy_string(buf, ast_getformatname(codec), len); 12045 } else { 12046 buf[0] = '\0'; 12047 } 12048 } else { 12049 buf[0] = '\0'; 12050 } 12051 12052 ASTOBJ_UNREF(peer, sip_destroy_peer); 12053 12054 return 0; 12055 }
| static char * generate_random_string | ( | char * | buf, | |
| size_t | size | |||
| ) | [static] |
Generate 32 byte random string for callid's etc.
Definition at line 4451 of file chan_sip.c.
References ast_random().
Referenced by build_callid_pvt(), and build_callid_registry().
04452 { 04453 long val[4]; 04454 int x; 04455 04456 for (x=0; x<4; x++) 04457 val[x] = ast_random(); 04458 snprintf(buf, size, "%08lx%08lx%08lx%08lx", val[0], val[1], val[2], val[3]); 04459 04460 return buf; 04461 }
| 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 9312 of file chan_sip.c.
References ast_canmatch_extension(), ast_copy_string(), ast_exists_extension(), ast_log(), ast_string_field_set, ast_strlen_zero(), ast_uri_decode(), ast_verbose(), domain::context, sip_pvt::context, get_header(), get_in_brackets(), sip_pvt::initreq, LOG_DEBUG, LOG_WARNING, ast_channel::macrocontext, option_debug, sip_pvt::owner, pbx_builtin_getvar_helper(), sip_pvt::refer, sip_refer::refer_call, sip_refer::refer_contact, sip_refer::refer_to, sip_refer::refer_to_domain, sip_refer::referred_by, S_OR, sip_debug_test_pvt(), and sip_refer_allocate().
Referenced by handle_request_bye().
09313 { 09314 char tmp[256] = "", *c, *a; 09315 struct sip_request *req = oreq ? oreq : &p->initreq; 09316 struct sip_refer *referdata = NULL; 09317 const char *transfer_context = NULL; 09318 09319 if (!p->refer && !sip_refer_allocate(p)) 09320 return -1; 09321 09322 referdata = p->refer; 09323 09324 ast_copy_string(tmp, get_header(req, "Also"), sizeof(tmp)); 09325 c = get_in_brackets(tmp); 09326 09327 if (pedanticsipchecking) 09328 ast_uri_decode(c); 09329 09330 if (strncasecmp(c, "sip:", 4)) { 09331 ast_log(LOG_WARNING, "Huh? Not a SIP header in Also: transfer (%s)?\n", c); 09332 return -1; 09333 } 09334 c += 4; 09335 if ((a = strchr(c, ';'))) /* Remove arguments */ 09336 *a = '\0'; 09337 09338 if ((a = strchr(c, '@'))) { /* Separate Domain */ 09339 *a++ = '\0'; 09340 ast_copy_string(referdata->refer_to_domain, a, sizeof(referdata->refer_to_domain)); 09341 } 09342 09343 if (sip_debug_test_pvt(p)) 09344 ast_verbose("Looking for %s in %s\n", c, p->context); 09345 09346 if (p->owner) /* Mimic behaviour in res_features.c */ 09347 transfer_context = pbx_builtin_getvar_helper(p->owner, "TRANSFER_CONTEXT"); 09348 09349 /* By default, use the context in the channel sending the REFER */ 09350 if (ast_strlen_zero(transfer_context)) { 09351 transfer_context = S_OR(p->owner->macrocontext, 09352 S_OR(p->context, default_context)); 09353 } 09354 if (ast_exists_extension(NULL, transfer_context, c, 1, NULL)) { 09355 /* This is a blind transfer */ 09356 if (option_debug) 09357 ast_log(LOG_DEBUG,"SIP Bye-also transfer to Extension %s@%s \n", c, transfer_context); 09358 ast_copy_string(referdata->refer_to, c, sizeof(referdata->refer_to)); 09359 ast_copy_string(referdata->referred_by, "", sizeof(referdata->referred_by)); 09360 ast_copy_string(referdata->refer_contact, "", sizeof(referdata->refer_contact)); 09361 referdata->refer_call = NULL; 09362 /* Set new context */ 09363 ast_string_field_set(p, context, transfer_context); 09364 return 0; 09365 } else if (ast_canmatch_extension(NULL, p->context, c, 1, NULL)) { 09366 return 1; 09367 } 09368 09369 return -1; 09370 }
| static char* get_body | ( | struct sip_request * | req, | |
| char * | name | |||
| ) | [static] |
Get a specific line from the message body.
Definition at line 4237 of file chan_sip.c.
References get_body_by_line(), len(), sip_request::line, and sip_request::lines.
Referenced by handle_request_info().
04238 { 04239 int x; 04240 int len = strlen(name); 04241 char *r; 04242 04243 for (x = 0; x < req->lines; x++) { 04244 r = get_body_by_line(req->line[x], name, len); 04245 if (r[0] != '\0') 04246 return r; 04247 } 04248 04249 return ""; 04250 }
| static char* get_body_by_line | ( | const char * | line, | |
| const char * | name, | |||
| int | nameLen | |||
| ) | [static] |
Reads one line of SIP message body.
Definition at line 4203 of file chan_sip.c.
References ast_skip_blanks().
Referenced by get_body(), and get_sdp_iterate().
04204 { 04205 if (strncasecmp(line, name, nameLen) == 0 && line[nameLen] == '=') 04206 return ast_skip_blanks(line + nameLen + 1); 04207 04208 return ""; 04209 }
| static char * get_calleridname | ( | const char * | input, | |
| char * | output, | |||
| size_t | outputsize | |||
| ) | [static] |
Get caller id name from SIP headers.
Definition at line 9424 of file chan_sip.c.
References ast_copy_string(), and ast_skip_blanks().
Referenced by check_user_full().
09425 { 09426 const char *end = strchr(input,'<'); /* first_bracket */ 09427 const char *tmp = strchr(input,'"'); /* first quote */ 09428 int bytes = 0; 09429 int maxbytes = outputsize - 1; 09430 09431 if (!end || end == input) /* we require a part in brackets */ 09432 return NULL; 09433 09434 end--; /* move just before "<" */ 09435 09436 if (tmp && tmp <= end) { 09437 /* The quote (tmp) precedes the bracket (end+1). 09438 * Find the matching quote and return the content. 09439 */ 09440 end = strchr(tmp+1, '"'); 09441 if (!end) 09442 return NULL; 09443 bytes = (int) (end - tmp); 09444 /* protect the output buffer */ 09445 if (bytes > maxbytes) 09446 bytes = maxbytes; 09447 ast_copy_string(output, tmp + 1, bytes); 09448 } else { 09449 /* No quoted string, or it is inside brackets. */ 09450 /* clear the empty characters in the begining*/ 09451 input = ast_skip_blanks(input); 09452 /* clear the empty characters in the end */ 09453 while(*end && *end < 33 && end > input) 09454 end--; 09455 if (end >= input) { 09456 bytes = (int) (end - input) + 2; 09457 /* protect the output buffer */ 09458 if (bytes > maxbytes) 09459 bytes = maxbytes; 09460 ast_copy_string(output, input, bytes); 09461 } else 09462 return NULL; 09463 } 09464 return output; 09465 }
| static int get_destination | ( | struct sip_pvt * | p, | |
| struct sip_request * | oreq | |||
| ) | [static] |
Find out who the call is for We use the INVITE uri to find out.
Definition at line 8959 of file chan_sip.c.
References ast_canmatch_extension(), ast_copy_string(), ast_exists_extension(), ast_get_hint(), AST_LIST_EMPTY, ast_log(), AST_MAX_EXTENSION, ast_pickup_ext(), ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_uri_decode(), ast_verbose(), check_sip_domain(), sip_pvt::cid_num, sip_pvt::context, domain::context, sip_pvt::domain, exten, sip_pvt::exten, get_header(), get_in_brackets(), sip_pvt::initreq, LOG_DEBUG, LOG_WARNING, sip_request::method, option_debug, sip_request::rlPart2, S_OR, sip_debug_test_pvt(), SIP_INVITE, sip_methods, SIP_PAGE2_ALLOWOVERLAP, SIP_REFER, SIP_SUBSCRIBE, sip_pvt::subscribecontext, and cfsip_methods::text.
Referenced by handle_request_invite(), handle_request_options(), and handle_request_subscribe().
08960 { 08961 char tmp[256] = "", *uri, *a; 08962 char tmpf[256] = "", *from; 08963 struct sip_request *req; 08964 char *colon; 08965 char *decoded_uri; 08966 08967 req = oreq; 08968 if (!req) 08969 req = &p->initreq; 08970 08971 /* Find the request URI */ 08972 if (req->rlPart2) 08973 ast_copy_string(tmp, req->rlPart2, sizeof(tmp)); 08974 08975 if (pedanticsipchecking) 08976 ast_uri_decode(tmp); 08977 08978 uri = get_in_brackets(tmp); 08979 08980 if (strncasecmp(uri, "sip:", 4)) { 08981 ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", uri); 08982 return -1; 08983 } 08984 uri += 4; 08985 08986 /* Now find the From: caller ID and name */ 08987 ast_copy_string(tmpf, get_header(req, "From"), sizeof(tmpf)); 08988 if (!ast_strlen_zero(tmpf)) { 08989 if (pedanticsipchecking) 08990 ast_uri_decode(tmpf); 08991 from = get_in_brackets(tmpf); 08992 } else { 08993 from = NULL; 08994 } 08995 08996 if (!ast_strlen_zero(from)) { 08997 if (strncasecmp(from, "sip:", 4)) { 08998 ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", from); 08999 return -1; 09000 } 09001 from += 4; 09002 if ((a = strchr(from, '@'))) 09003 *a++ = '\0'; 09004 else 09005 a = from; /* just a domain */ 09006 from = strsep(&from, ";"); /* Remove userinfo options */ 09007 a = strsep(&a, ";"); /* Remove URI options */ 09008 ast_string_field_set(p, fromdomain, a); 09009 } 09010 09011 /* Skip any options and find the domain */ 09012 09013 /* Get the target domain */ 09014 if ((a = strchr(uri, '@'))) { 09015 *a++ = '\0'; 09016 } else { /* No username part */ 09017 a = uri; 09018 uri = "s"; /* Set extension to "s" */ 09019 } 09020 colon = strchr(a, ':'); /* Remove :port */ 09021 if (colon) 09022 *colon = '\0'; 09023 09024 uri = strsep(&uri, ";"); /* Remove userinfo options */ 09025 a = strsep(&a, ";"); /* Remove URI options */ 09026 09027 ast_string_field_set(p, domain, a); 09028 09029 if (!AST_LIST_EMPTY(&domain_list)) { 09030 char domain_context[AST_MAX_EXTENSION]; 09031 09032 domain_context[0] = '\0'; 09033 if (!check_sip_domain(p->domain, domain_context, sizeof(domain_context))) { 09034 if (!allow_external_domains && (req->method == SIP_INVITE || req->method == SIP_REFER)) { 09035 if (option_debug) 09036 ast_log(LOG_DEBUG, "Got SIP %s to non-local domain '%s'; refusing request.\n", sip_methods[req->method].text, p->domain); 09037 return -2; 09038 } 09039 } 09040 /* If we have a context defined, overwrite the original context */ 09041 if (!ast_strlen_zero(domain_context)) 09042 ast_string_field_set(p, context, domain_context); 09043 } 09044 09045 /* If the request coming in is a subscription and subscribecontext has been specified use it */ 09046 if (req->method == SIP_SUBSCRIBE && !ast_strlen_zero(p->subscribecontext)) 09047 ast_string_field_set(p, context, p->subscribecontext); 09048 09049 if (sip_debug_test_pvt(p)) 09050 ast_verbose("Looking for %s in %s (domain %s)\n", uri, p->context, p->domain); 09051 09052 /* If this is a subscription we actually just need to see if a hint exists for the extension */ 09053 if (req->method == SIP_SUBSCRIBE) { 09054 char hint[AST_MAX_EXTENSION]; 09055 return (ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, p->context, p->exten) ? 0 : -1); 09056 } else { 09057 decoded_uri = ast_strdupa(uri); 09058 ast_uri_decode(decoded_uri); 09059 /* Check the dialplan for the username part of the request URI, 09060 the domain will be stored in the SIPDOMAIN variable 09061 Since extensions.conf can have unescaped characters, try matching a decoded 09062 uri in addition to the non-decoded uri 09063 Return 0 if we have a matching extension */ 09064 if (ast_exists_extension(NULL, p->context, uri, 1, S_OR(p->cid_num, from)) || ast_exists_extension(NULL, p->context, decoded_uri, 1, S_OR(p->cid_num, from)) || 09065 !strcmp(decoded_uri, ast_pickup_ext())) { 09066 if (!oreq) 09067 ast_string_field_set(p, exten, decoded_uri); 09068 return 0; 09069 } 09070 } 09071 09072 /* Return 1 for pickup extension or overlap dialling support (if we support it) */ 09073 if((ast_test_flag(&global_flags[1], SIP_PAGE2_ALLOWOVERLAP) && 09074 ast_canmatch_extension(NULL, p->context, decoded_uri, 1, S_OR(p->cid_num, from))) || 09075 !strncmp(decoded_uri, ast_pickup_ext(), strlen(decoded_uri))) { 09076 return 1; 09077 } 09078 09079 return -1; 09080 }
| static const char * get_header | ( | const struct sip_request * | req, | |
| const char * | name | |||
| ) | [static] |
Get header from SIP request.
Definition at line 4326 of file chan_sip.c.
References __get_header().
Referenced by __transmit_response(), build_route(), check_auth(), check_user_full(), check_via(), copy_header(), extract_uri(), find_call(), find_sdp(), get_also_info(), get_destination(), get_rdnis(), get_refer_info(), gettag(), handle_request(), handle_request_bye(), handle_request_info(), handle_request_invite(), handle_request_notify(), handle_request_register(), handle_request_subscribe(), handle_response(), handle_response_invite(), handle_response_refer(), handle_response_register(), parse_moved_contact(), parse_ok_contact(), parse_register_contact(), receive_message(), register_verify(), reply_digest(), reqprep(), respprep(), send_request(), send_response(), sip_sipredirect(), sipsock_read(), transmit_refer(), transmit_response_with_auth(), transmit_response_with_sdp(), transmit_response_with_t38_sdp(), and transmit_state_notify().
04327 { 04328 int start = 0; 04329 return __get_header(req, name, &start); 04330 }
| static char * get_in_brackets | ( | char * | tmp | ) | [static] |
Pick out text in brackets from character string.
| tmp | input string that will be modified Examples: |
Definition at line 2356 of file chan_sip.c.
References ast_log(), find_closing_quote(), LOG_WARNING, and parse().
Referenced by check_user_full(), extract_uri(), get_also_info(), get_destination(), get_rdnis(), get_refer_info(), parse_moved_contact(), parse_ok_contact(), parse_register_contact(), register_verify(), reqprep(), transmit_refer(), and transmit_state_notify().
02357 { 02358 const char *parse = tmp; 02359 char *first_bracket; 02360 02361 /* 02362 * Skip any quoted text until we find the part in brackets. 02363 * On any error give up and return the full string. 02364 */ 02365 while ( (first_bracket = strchr(parse, '<')) ) { 02366 char *first_quote = strchr(parse, '"'); 02367 02368 if (!first_quote || first_quote > first_bracket) 02369 break; /* no need to look at quoted part */ 02370 /* the bracket is within quotes, so ignore it */ 02371 parse = find_closing_quote(first_quote + 1, NULL); 02372 if (!*parse) { /* not found, return full string ? */ 02373 /* XXX or be robust and return in-bracket part ? */ 02374 ast_log(LOG_WARNING, "No closing quote found in '%s'\n", tmp); 02375 break; 02376 } 02377 parse++; 02378 } 02379 if (first_bracket) { 02380 char *second_bracket = strchr(first_bracket + 1, '>'); 02381 if (second_bracket) { 02382 *second_bracket = '\0'; 02383 tmp = first_bracket + 1; 02384 } else { 02385 ast_log(LOG_WARNING, "No closing bracket found in '%s'\n", tmp); 02386 } 02387 } 02388 return tmp; 02389 }
| static int get_msg_text | ( | char * | buf, | |
| int | len, | |||
| struct sip_request * | req | |||
| ) | [static] |
Get text out of a SIP MESSAGE packet.
Definition at line 9834 of file chan_sip.c.
References sip_request::line, and sip_request::lines.
Referenced by handle_request_notify(), and receive_message().
09835 { 09836 int x; 09837 int y; 09838 09839 buf[0] = '\0'; 09840 y = len - strlen(buf) - 5; 09841 if (y < 0) 09842 y = 0; 09843 for (x=0;x<req->lines;x++) { 09844 strncat(buf, req->line[x], y); /* safe */ 09845 y -= strlen(req->line[x]) + 1; 09846 if (y < 0) 09847 y = 0; 09848 if (y != 0) 09849 strcat(buf, "\n"); /* safe */ 09850 } 09851 return 0; 09852 }
| static int get_rdnis | ( | struct sip_pvt * | p, | |
| struct sip_request * | oreq | |||
| ) | [static] |
Get referring dnis.
Definition at line 8930 of file chan_sip.c.
References ast_copy_string(), ast_log(), ast_string_field_set, ast_strlen_zero(), ast_verbose(), get_header(), get_in_brackets(), sip_pvt::initreq, LOG_WARNING, and sip_debug_test_pvt().
Referenced by handle_request_invite().
08931 { 08932 char tmp[256], *c, *a; 08933 struct sip_request *req; 08934 08935 req = oreq; 08936 if (!req) 08937 req = &p->initreq; 08938 ast_copy_string(tmp, get_header(req, "Diversion"), sizeof(tmp)); 08939 if (ast_strlen_zero(tmp)) 08940 return 0; 08941 c = get_in_brackets(tmp); 08942 if (strncasecmp(c, "sip:", 4)) { 08943 ast_log(LOG_WARNING, "Huh? Not an RDNIS SIP header (%s)?\n", c); 08944 return -1; 08945 } 08946 c += 4; 08947 a = c; 08948 strsep(&a, "@;"); /* trim anything after @ or ; */ 08949 if (sip_debug_test_pvt(p)) 08950 ast_verbose("RDNIS is %s\n", c); 08951 ast_string_field_set(p, rdnis, c); 08952 08953 return 0; 08954 }
| 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 9146 of file chan_sip.c.
References ast_copy_string(), ast_exists_extension(), ast_log(), ast_strdupa, ast_strlen_zero(), ast_uri_decode(), ast_verbose(), sip_refer::attendedtransfer, sip_pvt::context, get_header(), get_in_brackets(), sip_pvt::initreq, LOG_DEBUG, LOG_WARNING, ast_channel::macrocontext, option_debug, sip_pvt::owner, pbx_builtin_getvar_helper(), sip_pvt::refer, sip_refer::refer_to, sip_refer::refer_to_context, sip_refer::refer_to_domain, sip_refer::refer_to_urioption, sip_refer::referred_by, sip_refer::referred_by_name, sip_refer::replaces_callid, sip_refer::replaces_callid_fromtag, sip_refer::replaces_callid_totag, S_OR, and sip_debug_test_pvt().
Referenced by handle_request_refer().
09147 { 09148 09149 const char *p_referred_by = NULL; 09150 char *h_refer_to = NULL; 09151 char *h_referred_by = NULL; 09152 char *refer_to; 09153 const char *p_refer_to; 09154 char *referred_by_uri = NULL; 09155 char *ptr; 09156 struct sip_request *req = NULL; 09157 const char *transfer_context = NULL; 09158 struct sip_refer *referdata; 09159 09160 09161 req = outgoing_req; 09162 referdata = transferer->refer; 09163 09164 if (!req) 09165 req = &transferer->initreq; 09166 09167 p_refer_to = get_header(req, "Refer-To"); 09168 if (ast_strlen_zero(p_refer_to)) { 09169 ast_log(LOG_WARNING, "Refer-To Header missing. Skipping transfer.\n"); 09170 return -2; /* Syntax error */ 09171 } 09172 h_refer_to = ast_strdupa(p_refer_to); 09173 refer_to = get_in_brackets(h_refer_to); 09174 if (pedanticsipchecking) 09175 ast_uri_decode(refer_to); 09176 09177 if (strncasecmp(refer_to, "sip:", 4)) { 09178 ast_log(LOG_WARNING, "Can't transfer to non-sip: URI. (Refer-to: %s)?\n", refer_to); 09179 return -3; 09180 } 09181 refer_to += 4; /* Skip sip: */ 09182 09183 /* Get referred by header if it exists */ 09184 p_referred_by = get_header(req, "Referred-By"); 09185 if (!ast_strlen_zero(p_referred_by)) { 09186 char *lessthan; 09187 h_referred_by = ast_strdupa(p_referred_by); 09188 if (pedanticsipchecking) 09189 ast_uri_decode(h_referred_by); 09190 09191 /* Store referrer's caller ID name */ 09192 ast_copy_string(referdata->referred_by_name, h_referred_by, sizeof(referdata->referred_by_name)); 09193 if ((lessthan = strchr(referdata->referred_by_name, '<'))) { 09194 *(lessthan - 1) = '\0'; /* Space */ 09195 } 09196 09197 referred_by_uri = get_in_brackets(h_referred_by); 09198 if(strncasecmp(referred_by_uri, "sip:", 4)) { 09199 ast_log(LOG_WARNING, "Huh? Not a sip: header (Referred-by: %s). Skipping.\n", referred_by_uri); 09200 referred_by_uri = (char *) NULL; 09201 } else { 09202 referred_by_uri += 4; /* Skip sip: */ 09203 } 09204 } 09205 09206 /* Check for arguments in the refer_to header */ 09207 if ((ptr = strchr(refer_to, '?'))) { /* Search for arguments */ 09208 *ptr++ = '\0'; 09209 if (!strncasecmp(ptr, "REPLACES=", 9)) { 09210 char *to = NULL, *from = NULL; 09211 09212 /* This is an attended transfer */ 09213 referdata->attendedtransfer = 1; 09214 ast_copy_string(referdata->replaces_callid, ptr+9, sizeof(referdata->replaces_callid)); 09215 ast_uri_decode(referdata->replaces_callid); 09216 if ((ptr = strchr(referdata->replaces_callid, ';'))) /* Find options */ { 09217 *ptr++ = '\0'; 09218 } 09219 09220 if (ptr) { 09221 /* Find the different tags before we destroy the string */ 09222 to = strcasestr(ptr, "to-tag="); 09223 from = strcasestr(ptr, "from-tag="); 09224 } 09225 09226 /* Grab the to header */ 09227 if (to) { 09228 ptr = to + 7; 09229 if ((to = strchr(ptr, '&'))) 09230 *to = '\0'; 09231 if ((to = strchr(ptr, ';'))) 09232 *to = '\0'; 09233 ast_copy_string(referdata->replaces_callid_totag, ptr, sizeof(referdata->replaces_callid_totag)); 09234 } 09235 09236 if (from) { 09237 ptr = from + 9; 09238 if ((to = strchr(ptr, '&'))) 09239 *to = '\0'; 09240 if ((to = strchr(ptr, ';'))) 09241 *to = '\0'; 09242 ast_copy_string(referdata->replaces_callid_fromtag, ptr, sizeof(referdata->replaces_callid_fromtag)); 09243 } 09244 09245 if (option_debug > 1) { 09246 if (!pedanticsipchecking) 09247 ast_log(LOG_DEBUG,"Attended transfer: Will use Replace-Call-ID : %s (No check of from/to tags)\n", referdata->replaces_callid ); 09248 else 09249 ast_log(LOG_DEBUG,"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>" ); 09250 } 09251 } 09252 } 09253 09254 if ((ptr = strchr(refer_to, '@'))) { /* Separate domain */ 09255 char *urioption = NULL, *domain; 09256 *ptr++ = '\0'; 09257 09258 if ((urioption = strchr(ptr, ';'))) /* Separate urioptions */ 09259 *urioption++ = '\0'; 09260 09261 domain = ptr; 09262 if ((ptr = strchr(domain, ':'))) /* Remove :port */ 09263 *ptr = '\0'; 09264 09265 /* Save the domain for the dial plan */ 09266 ast_copy_string(referdata->refer_to_domain, domain, sizeof(referdata->refer_to_domain)); 09267 if (urioption) 09268 ast_copy_string(referdata->refer_to_urioption, urioption, sizeof(referdata->refer_to_urioption)); 09269 } 09270 09271 if ((ptr = strchr(refer_to, ';'))) /* Remove options */ 09272 *ptr = '\0'; 09273 ast_copy_string(referdata->refer_to, refer_to, sizeof(referdata->refer_to)); 09274 09275 if (referred_by_uri) { 09276 if ((ptr = strchr(referred_by_uri, ';'))) /* Remove options */ 09277 *ptr = '\0'; 09278 ast_copy_string(referdata->referred_by, referred_by_uri, sizeof(referdata->referred_by)); 09279 } else { 09280 referdata->referred_by[0] = '\0'; 09281 } 09282 09283 /* Determine transfer context */ 09284 if (transferer->owner) /* Mimic behaviour in res_features.c */ 09285 transfer_context = pbx_builtin_getvar_helper(transferer->owner, "TRANSFER_CONTEXT"); 09286 09287 /* By default, use the context in the channel sending the REFER */ 09288 if (ast_strlen_zero(transfer_context)) { 09289 transfer_context = S_OR(transferer->owner->macrocontext, 09290 S_OR(transferer->context, default_context)); 09291 } 09292 09293 ast_copy_string(referdata->refer_to_context, transfer_context, sizeof(referdata->refer_to_context)); 09294 09295 /* Either an existing extension or the parking extension */ 09296 if (ast_exists_extension(NULL, transfer_context, refer_to, 1, NULL) ) { 09297 if (sip_debug_test_pvt(transferer)) { 09298 ast_verbose("SIP transfer to extension %s@%s by %s\n", refer_to, transfer_context, referred_by_uri); 09299 } 09300 /* We are ready to transfer to the extension */ 09301 return 0; 09302 } 09303 if (sip_debug_test_pvt(transferer)) 09304 ast_verbose("Failed SIP Transfer to non-existing extension %s in context %s\n n", refer_to, transfer_context); 09305 09306 /* Failure, we can't find this extension */ 09307 return -1; 09308 }
| static int get_rpid_num | ( | const char * | input, | |
| char * | output, | |||
| int | maxlen | |||
| ) | [static] |
Get caller id number from Remote-Party-ID header field Returns true if number should be restricted (privacy setting found) output is set to NULL if no number found.
Definition at line 9471 of file chan_sip.c.
References ast_copy_string(), and AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED.
Referenced by check_user_full().
09472 { 09473 char *start; 09474 char *end; 09475 09476 start = strchr(input,':'); 09477 if (!start) { 09478 output[0] = '\0'; 09479 return 0; 09480 } 09481 start++; 09482 09483 /* we found "number" */ 09484 ast_copy_string(output,start,maxlen); 09485 output[maxlen-1] = '\0'; 09486 09487 end = strchr(output,'@'); 09488 if (end) 09489 *end = '\0'; 09490 else 09491 output[0] = '\0'; 09492 if (strstr(input,"privacy=full") || strstr(input,"privacy=uri")) 09493 return AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED; 09494 09495 return 0; 09496 }
| static const char * get_sdp | ( | struct sip_request * | req, | |
| const char * | name | |||
| ) | [static] |
Get a line from an SDP message body.
Definition at line 4229 of file chan_sip.c.
References get_sdp_iterate().
Referenced by process_sdp().
04230 { 04231 int dummy = 0; 04232 04233 return get_sdp_iterate(&dummy, req, name); 04234 }
| 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 4215 of file chan_sip.c.
References get_body_by_line(), len(), and sip_request::line.
Referenced by get_sdp(), and process_sdp().
04216 { 04217 int len = strlen(name); 04218 04219 while (*start < req->sdp_end) { 04220 const char *r = get_body_by_line(req->line[(*start)++], name, len); 04221 if (r[0] != '\0') 04222 return r; 04223 } 04224 04225 return ""; 04226 }
| static struct sip_pvt * get_sip_pvt_byid_locked | ( | const char * | callid, | |
| const char * | totag, | |||
| const char * | fromtag | |||
| ) | [static, read] |
Lock interface lock and find matching pvt lock.
Definition at line 9084 of file chan_sip.c.
References ast_channel_trylock, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_strlen_zero(), ast_test_flag, sip_pvt::callid, DEADLOCK_AVOIDANCE, sip_pvt::flags, iflist, iflock, sip_pvt::lock, LOG_DEBUG, match(), sip_pvt::next, option_debug, sip_pvt::owner, SIP_PAGE2_OUTGOING_CALL, sip_pvt::tag, and sip_pvt::theirtag.
Referenced by handle_request_invite(), and local_attended_transfer().
09085 { 09086 struct sip_pvt *sip_pvt_ptr; 09087 09088 ast_mutex_lock(&iflock); 09089 09090 if (option_debug > 3 && totag) 09091 ast_log(LOG_DEBUG, "Looking for callid %s (fromtag %s totag %s)\n", callid, fromtag ? fromtag : "<no fromtag>", totag ? totag : "<no totag>"); 09092 09093 /* Search interfaces and find the match */ 09094 for (sip_pvt_ptr = iflist; sip_pvt_ptr; sip_pvt_ptr = sip_pvt_ptr->next) { 09095 if (!strcmp(sip_pvt_ptr->callid, callid)) { 09096 int match = 1; 09097 09098 /* Go ahead and lock it (and its owner) before returning */ 09099 ast_mutex_lock(&sip_pvt_ptr->lock); 09100 09101 /* Check if tags match. If not, this is not the call we want 09102 (With a forking SIP proxy, several call legs share the 09103 call id, but have different tags) 09104 */ 09105 if (pedanticsipchecking) { 09106 const char *pvt_fromtag, *pvt_totag; 09107 09108 if (ast_test_flag(&sip_pvt_ptr->flags[1], SIP_PAGE2_OUTGOING_CALL)) { 09109 /* Outgoing call tags : from is "our", to is "their" */ 09110 pvt_fromtag = sip_pvt_ptr->tag ; 09111 pvt_totag = sip_pvt_ptr->theirtag ; 09112 } else { 09113 /* Incoming call tags : from is "their", to is "our" */ 09114 pvt_fromtag = sip_pvt_ptr->theirtag ; 09115 pvt_totag = sip_pvt_ptr->tag ; 09116 } 09117 if (ast_strlen_zero(fromtag) || strcmp(fromtag, pvt_fromtag) || (!ast_strlen_zero(totag) && strcmp(totag, pvt_totag))) 09118 match = 0; 09119 } 09120 09121 if (!match) { 09122 ast_mutex_unlock(&sip_pvt_ptr->lock); 09123 continue; 09124 } 09125 09126 if (option_debug > 3 && totag) 09127 ast_log(LOG_DEBUG, "Matched %s call - their tag is %s Our tag is %s\n", 09128 ast_test_flag(&sip_pvt_ptr->flags[1], SIP_PAGE2_OUTGOING_CALL) ? "OUTGOING": "INCOMING", 09129 sip_pvt_ptr->theirtag, sip_pvt_ptr->tag); 09130 09131 /* deadlock avoidance... */ 09132 while (sip_pvt_ptr->owner && ast_channel_trylock(sip_pvt_ptr->owner)) { 09133 DEADLOCK_AVOIDANCE(&sip_pvt_ptr->lock); 09134 } 09135 break; 09136 } 09137 } 09138 ast_mutex_unlock(&iflock); 09139 if (option_debug > 3 && !sip_pvt_ptr) 09140 ast_log(LOG_DEBUG, "Found no match for callid %s to-tag %s from-tag %s\n", callid, totag, fromtag); 09141 return sip_pvt_ptr; 09142 }
| static const char * gettag | ( | const struct sip_request * | req, | |
| const char * | header, | |||
| char * | tagbuf, | |||
| int | tagbufsize | |||
| ) | [static] |
Get tag from packet.
Definition at line 13540 of file chan_sip.c.
References ast_copy_string(), and get_header().
Referenced by find_call(), handle_request(), handle_request_subscribe(), and handle_response().
13541 { 13542 const char *thetag; 13543 13544 if (!tagbuf) 13545 return NULL; 13546 tagbuf[0] = '\0'; /* reset the buffer */ 13547 thetag = get_header(req, header); 13548 thetag = strcasestr(thetag, ";tag="); 13549 if (thetag) { 13550 thetag += 5; 13551 ast_copy_string(tagbuf, thetag, tagbufsize); 13552 return strsep(&tagbuf, ";"); 13553 } 13554 return NULL; 13555 }
| 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 - users and 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 16666 of file chan_sip.c.
References ast_clear_flag, ast_copy_string(), ast_false(), ast_log(), ast_set2_flag, ast_set_flag, ast_true(), ast_variable::lineno, LOG_WARNING, ast_variable::name, domain::next, set_insecure_flags(), SIP_CAN_REINVITE, SIP_CAN_REINVITE_NAT, SIP_DTMF, SIP_DTMF_AUTO, SIP_DTMF_INBAND, SIP_DTMF_INFO, SIP_DTMF_RFC2833, SIP_G726_NONSTANDARD, SIP_INSECURE_INVITE, SIP_INSECURE_PORT, SIP_NAT, SIP_NAT_ALWAYS, SIP_NAT_NEVER, SIP_NAT_RFC3581, SIP_NAT_ROUTE, SIP_PAGE2_ALLOWOVERLAP, SIP_PAGE2_ALLOWSUBSCRIBE, SIP_PAGE2_BUGGY_MWI, SIP_PAGE2_RFC2833_COMPENSATE, SIP_PAGE2_T38SUPPORT_RTP, SIP_PAGE2_T38SUPPORT_TCP, SIP_PAGE2_T38SUPPORT_UDPTL, SIP_PAGE2_UDPTL_DESTINATION, SIP_PAGE2_VIDEOSUPPORT, SIP_PROG_INBAND, SIP_PROG_INBAND_NO, SIP_PROG_INBAND_YES, SIP_PROMISCREDIR, SIP_REINVITE, SIP_REINVITE_UPDATE, SIP_SENDRPID, SIP_TRUSTRPID, SIP_USECLIENTCODE, and ast_variable::value.
Referenced by build_peer(), build_user(), and reload_config().
16667 { 16668 int res = 1; 16669 16670 if (!strcasecmp(v->name, "trustrpid")) { 16671 ast_set_flag(&mask[0], SIP_TRUSTRPID); 16672 ast_set2_flag(&flags[0], ast_true(v->value), SIP_TRUSTRPID); 16673 } else if (!strcasecmp(v->name, "sendrpid")) { 16674 ast_set_flag(&mask[0], SIP_SENDRPID); 16675 ast_set2_flag(&flags[0], ast_true(v->value), SIP_SENDRPID); 16676 } else if (!strcasecmp(v->name, "g726nonstandard")) { 16677 ast_set_flag(&mask[0], SIP_G726_NONSTANDARD); 16678 ast_set2_flag(&flags[0], ast_true(v->value), SIP_G726_NONSTANDARD); 16679 } else if (!strcasecmp(v->name, "useclientcode")) { 16680 ast_set_flag(&mask[0], SIP_USECLIENTCODE); 16681 ast_set2_flag(&flags[0], ast_true(v->value), SIP_USECLIENTCODE); 16682 } else if (!strcasecmp(v->name, "dtmfmode")) { 16683 ast_set_flag(&mask[0], SIP_DTMF); 16684 ast_clear_flag(&flags[0], SIP_DTMF); 16685 if (!strcasecmp(v->value, "inband")) 16686 ast_set_flag(&flags[0], SIP_DTMF_INBAND); 16687 else if (!strcasecmp(v->value, "rfc2833")) 16688 ast_set_flag(&flags[0], SIP_DTMF_RFC2833); 16689 else if (!strcasecmp(v->value, "info")) 16690 ast_set_flag(&flags[0], SIP_DTMF_INFO); 16691 else if (!strcasecmp(v->value, "auto")) 16692 ast_set_flag(&flags[0], SIP_DTMF_AUTO); 16693 else { 16694 ast_log(LOG_WARNING, "Unknown dtmf mode '%s' on line %d, using rfc2833\n", v->value, v->lineno); 16695 ast_set_flag(&flags[0], SIP_DTMF_RFC2833); 16696 } 16697 } else if (!strcasecmp(v->name, "nat")) { 16698 ast_set_flag(&mask[0], SIP_NAT); 16699 ast_clear_flag(&flags[0], SIP_NAT); 16700 if (!strcasecmp(v->value, "never")) 16701 ast_set_flag(&flags[0], SIP_NAT_NEVER); 16702 else if (!strcasecmp(v->value, "route")) 16703 ast_set_flag(&flags[0], SIP_NAT_ROUTE); 16704 else if (ast_true(v->value)) 16705 ast_set_flag(&flags[0], SIP_NAT_ALWAYS); 16706 else 16707 ast_set_flag(&flags[0], SIP_NAT_RFC3581); 16708 } else if (!strcasecmp(v->name, "canreinvite")) { 16709 ast_set_flag(&mask[0], SIP_REINVITE); 16710 ast_clear_flag(&flags[0], SIP_REINVITE); 16711 if(ast_true(v->value)) { 16712 ast_set_flag(&flags[0], SIP_CAN_REINVITE | SIP_CAN_REINVITE_NAT); 16713 } else if (!ast_false(v->value)) { 16714 char buf[64]; 16715 char *word, *next = buf; 16716 16717 ast_copy_string(buf, v->value, sizeof(buf)); 16718 while ((word = strsep(&next, ","))) { 16719 if(!strcasecmp(word, "update")) { 16720 ast_set_flag(&flags[0], SIP_REINVITE_UPDATE | SIP_CAN_REINVITE); 16721 } else if(!strcasecmp(word, "nonat")) { 16722 ast_set_flag(&flags[0], SIP_CAN_REINVITE); 16723 ast_clear_flag(&flags[0], SIP_CAN_REINVITE_NAT); 16724 } else { 16725 ast_log(LOG_WARNING, "Unknown canreinvite mode '%s' on line %d\n", v->value, v->lineno); 16726 } 16727 } 16728 } 16729 } else if (!strcasecmp(v->name, "insecure")) { 16730 ast_set_flag(&mask[0], SIP_INSECURE_PORT | SIP_INSECURE_INVITE); 16731 ast_clear_flag(&flags[0], SIP_INSECURE_PORT | SIP_INSECURE_INVITE); 16732 set_insecure_flags(flags, v->value, v->lineno); 16733 } else if (!strcasecmp(v->name, "progressinband")) { 16734 ast_set_flag(&mask[0], SIP_PROG_INBAND); 16735 ast_clear_flag(&flags[0], SIP_PROG_INBAND); 16736 if (ast_true(v->value)) 16737 ast_set_flag(&flags[0], SIP_PROG_INBAND_YES); 16738 else if (strcasecmp(v->value, "never")) 16739 ast_set_flag(&flags[0], SIP_PROG_INBAND_NO); 16740 } else if (!strcasecmp(v->name, "promiscredir")) { 16741 ast_set_flag(&mask[0], SIP_PROMISCREDIR); 16742 ast_set2_flag(&flags[0], ast_true(v->value), SIP_PROMISCREDIR); 16743 } else if (!strcasecmp(v->name, "videosupport")) { 16744 ast_set_flag(&mask[1], SIP_PAGE2_VIDEOSUPPORT); 16745 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_VIDEOSUPPORT); 16746 } else if (!strcasecmp(v->name, "allowoverlap")) { 16747 ast_set_flag(&mask[1], SIP_PAGE2_ALLOWOVERLAP); 16748 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_ALLOWOVERLAP); 16749 } else if (!strcasecmp(v->name, "allowsubscribe")) { 16750 ast_set_flag(&mask[1], SIP_PAGE2_ALLOWSUBSCRIBE); 16751 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_ALLOWSUBSCRIBE); 16752 } else if (!strcasecmp(v->name, "t38pt_udptl")) { 16753 ast_set_flag(&mask[1], SIP_PAGE2_T38SUPPORT_UDPTL); 16754 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_T38SUPPORT_UDPTL); 16755 #ifdef WHEN_WE_HAVE_T38_FOR_OTHER_TRANSPORTS 16756 } else if (!strcasecmp(v->name, "t38pt_rtp")) { 16757 ast_set_flag(&mask[1], SIP_PAGE2_T38SUPPORT_RTP); 16758 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_T38SUPPORT_RTP); 16759 } else if (!strcasecmp(v->name, "t38pt_tcp")) { 16760 ast_set_flag(&mask[1], SIP_PAGE2_T38SUPPORT_TCP); 16761 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_T38SUPPORT_TCP); 16762 #endif 16763 } else if (!strcasecmp(v->name, "rfc2833compensate")) { 16764 ast_set_flag(&mask[1], SIP_PAGE2_RFC2833_COMPENSATE); 16765 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_RFC2833_COMPENSATE); 16766 } else if (!strcasecmp(v->name, "buggymwi")) { 16767 ast_set_flag(&mask[1], SIP_PAGE2_BUGGY_MWI); 16768 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_BUGGY_MWI); 16769 } else if (!strcasecmp(v->name, "t38pt_usertpsource")) { 16770 ast_set_flag(&mask[1], SIP_PAGE2_UDPTL_DESTINATION); 16771 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_UDPTL_DESTINATION); 16772 } else 16773 res = 0; 16774 16775 return res; 16776 }
| static int handle_invite_replaces | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| int | debug, | |||
| int | ignore, | |||
| int | seqno, | |||
| struct sockaddr_in * | sin | |||
| ) | [static] |
Handle the transfer part of INVITE with a replaces: header, meaning a target pickup or an attended transfer.
Definition at line 13725 of file chan_sip.c.
References ast_channel::_state, append_history, ast_bridged_channel(), AST_CAUSE_SWITCH_CONGESTION, ast_channel_masquerade(), ast_channel_unlock, ast_frfree, ast_hangup(), ast_log(), ast_mutex_unlock(), ast_quiet_chan(), ast_read(), ast_set_flag, ast_setstate(), ast_state2str(), AST_STATE_DOWN, AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, DEFAULT_TRANS_TIMEOUT, f, sip_pvt::flags, ast_channel::hangupcause, sip_pvt::lock, LOG_DEBUG, LOG_ERROR, LOG_NOTICE, LOG_WARNING, ast_channel::name, option_debug, sip_pvt::owner, sip_pvt::refer, sip_refer::refer_call, SIP_DEFER_BYE_ON_TRANSFER, sip_scheddestroy(), ast_channel::tech_pvt, transmit_response(), transmit_response_reliable(), transmit_response_with_sdp(), and XMIT_RELIABLE.
Referenced by handle_request_invite().
13726 { 13727 struct ast_frame *f; 13728 int earlyreplace = 0; 13729 int oneleggedreplace = 0; /* Call with no bridge, propably IVR or voice message */ 13730 struct ast_channel *c = p->owner; /* Our incoming call */ 13731 struct ast_channel *replacecall = p->refer->refer_call->owner; /* The channel we're about to take over */ 13732 struct ast_channel *targetcall; /* The bridge to the take-over target */ 13733 13734 /* Check if we're in ring state */ 13735 if (replacecall->_state == AST_STATE_RING) 13736 earlyreplace = 1; 13737 13738 /* Check if we have a bridge */ 13739 if (!(targetcall = ast_bridged_channel(replacecall))) { 13740 /* We have no bridge */ 13741 if (!earlyreplace) { 13742 if (option_debug > 1) 13743 ast_log(LOG_DEBUG, " Attended transfer attempted to replace call with no bridge (maybe ringing). Channel %s!\n", replacecall->name); 13744 oneleggedreplace = 1; 13745 } 13746 } 13747 if (option_debug > 3 && targetcall && targetcall->_state == AST_STATE_RINGING) 13748 ast_log(LOG_DEBUG, "SIP transfer: Target channel is in ringing state\n"); 13749 13750 if (option_debug > 3) { 13751 if (targetcall) 13752 ast_log(LOG_DEBUG, "SIP transfer: Invite Replace incoming channel should bridge to channel %s while hanging up channel %s\n", targetcall->name, replacecall->name); 13753 else 13754 ast_log(LOG_DEBUG, "SIP transfer: Invite Replace incoming channel should replace and hang up channel %s (one call leg)\n", replacecall->name); 13755 } 13756 13757 if (ignore) { 13758 ast_log(LOG_NOTICE, "Ignoring this INVITE with replaces in a stupid way.\n"); 13759 /* We should answer something here. If we are here, the 13760 call we are replacing exists, so an accepted 13761 can't harm */ 13762 transmit_response_with_sdp(p, "200 OK", req, XMIT_RELIABLE); 13763 /* Do something more clever here */ 13764 ast_channel_unlock(c); 13765 ast_mutex_unlock(&p->refer->refer_call->lock); 13766 return 1; 13767 } 13768 if (!c) { 13769 /* What to do if no channel ??? */ 13770 ast_log(LOG_ERROR, "Unable to create new channel. Invite/replace failed.\n"); 13771 transmit_response_reliable(p, "503 Service Unavailable", req); 13772 append_history(p, "Xfer", "INVITE/Replace Failed. No new channel."); 13773 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 13774 ast_mutex_unlock(&p->refer->refer_call->lock); 13775 return 1; 13776 } 13777 append_history(p, "Xfer", "INVITE/Replace received"); 13778 /* We have three channels to play with 13779 channel c: New incoming call 13780 targetcall: Call from PBX to target 13781 p->refer->refer_call: SIP pvt dialog from transferer to pbx. 13782 replacecall: The owner of the previous 13783 We need to masq C into refer_call to connect to 13784 targetcall; 13785 If we are talking to internal audio stream, target call is null. 13786 */ 13787 13788 /* Fake call progress */ 13789 transmit_response(p, "100 Trying", req); 13790 ast_setstate(c, AST_STATE_RING); 13791 13792 /* Masquerade the new call into the referred call to connect to target call 13793 Targetcall is not touched by the masq */ 13794 13795 /* Answer the incoming call and set channel to UP state */ 13796 transmit_response_with_sdp(p, "200 OK", req, XMIT_RELIABLE); 13797 13798 ast_setstate(c, AST_STATE_UP); 13799 13800 /* Stop music on hold and other generators */ 13801 ast_quiet_chan(replacecall); 13802 ast_quiet_chan(targetcall); 13803 if (option_debug > 3) 13804 ast_log(LOG_DEBUG, "Invite/Replaces: preparing to masquerade %s into %s\n", c->name, replacecall->name); 13805 /* Unlock clone, but not original (replacecall) */ 13806 if (!oneleggedreplace) 13807 ast_channel_unlock(c); 13808 13809 /* Unlock PVT */ 13810 ast_mutex_unlock(&p->refer->refer_call->lock); 13811 13812 /* Make sure that the masq does not free our PVT for the old call */ 13813 if (! earlyreplace && ! oneleggedreplace ) 13814 ast_set_flag(&p->refer->refer_call->flags[0], SIP_DEFER_BYE_ON_TRANSFER); /* Delay hangup */ 13815 13816 /* Prepare the masquerade - if this does not happen, we will be gone */ 13817 if(ast_channel_masquerade(replacecall, c)) 13818 ast_log(LOG_ERROR, "Failed to masquerade C into Replacecall\n"); 13819 else if (option_debug > 3) 13820 ast_log(LOG_DEBUG, "Invite/Replaces: Going to masquerade %s into %s\n", c->name, replacecall->name); 13821 13822 /* The masquerade will happen as soon as someone reads a frame from the channel */ 13823 13824 /* C should now be in place of replacecall */ 13825 /* ast_read needs to lock channel */ 13826 ast_channel_unlock(c); 13827 13828 if (earlyreplace || oneleggedreplace ) { 13829 /* Force the masq to happen */ 13830 if ((f = ast_read(replacecall))) { /* Force the masq to happen */ 13831 ast_frfree(f); 13832 f = NULL; 13833 if (option_debug > 3) 13834 ast_log(LOG_DEBUG, "Invite/Replace: Could successfully read frame from RING channel!\n"); 13835 } else { 13836 ast_log(LOG_WARNING, "Invite/Replace: Could not read frame from RING channel \n"); 13837 } 13838 c->hangupcause = AST_CAUSE_SWITCH_CONGESTION; 13839 if (!oneleggedreplace) 13840 ast_channel_unlock(replacecall); 13841 } else { /* Bridged call, UP channel */ 13842 if ((f = ast_read(replacecall))) { /* Force the masq to happen */ 13843 /* Masq ok */ 13844 ast_frfree(f); 13845 f = NULL; 13846 if (option_debug > 2) 13847 ast_log(LOG_DEBUG, "Invite/Replace: Could successfully read frame from channel! Masq done.\n"); 13848 } else { 13849 ast_log(LOG_WARNING, "Invite/Replace: Could not read frame from channel. Transfer failed\n"); 13850 } 13851 ast_channel_unlock(replacecall); 13852 } 13853 ast_mutex_unlock(&p->refer->refer_call->lock); 13854 13855 ast_setstate(c, AST_STATE_DOWN); 13856 if (option_debug > 3) { 13857 struct ast_channel *test; 13858 ast_log(LOG_DEBUG, "After transfer:----------------------------\n"); 13859 ast_log(LOG_DEBUG, " -- C: %s State %s\n", c->name, ast_state2str(c->_state)); 13860 if (replacecall) 13861 ast_log(LOG_DEBUG, " -- replacecall: %s State %s\n", replacecall->name, ast_state2str(replacecall->_state)); 13862 if (p->owner) { 13863 ast_log(LOG_DEBUG, " -- P->owner: %s State %s\n", p->owner->name, ast_state2str(p->owner->_state)); 13864 test = ast_bridged_channel(p->owner); 13865 if (test) 13866 ast_log(LOG_DEBUG, " -- Call bridged to P->owner: %s State %s\n", test->name, ast_state2str(test->_state)); 13867 else 13868 ast_log(LOG_DEBUG, " -- No call bridged to C->owner \n"); 13869 } else 13870 ast_log(LOG_DEBUG, " -- No channel yet \n"); 13871 ast_log(LOG_DEBUG, "End After transfer:----------------------------\n"); 13872 } 13873 13874 ast_channel_unlock(p->owner); /* Unlock new owner */ 13875 if (!oneleggedreplace) 13876 ast_mutex_unlock(&p->lock); /* Unlock SIP structure */ 13877 13878 /* The call should be down with no ast_channel, so hang it up */ 13879 c->tech_pvt = NULL; 13880 ast_hangup(c); 13881 return 0; 13882 }
| static int handle_request | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| struct sockaddr_in * | sin, | |||
| int * | recount, | |||
| int * | nounlock | |||
| ) | [static] |
Handle incoming SIP requests (methods).
Definition at line 15702 of file chan_sip.c.
References __sip_ack(), append_history, ast_inet_ntoa(), ast_log(), ast_set_flag, ast_skip_blanks(), ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_verbose(), check_pendings(), debug, DEFAULT_TRANS_TIMEOUT, extract_uri(), FALSE, find_sdp(), FLAG_RESPONSE, sip_pvt::flags, 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_refer(), handle_request_register(), handle_request_subscribe(), handle_response(), sip_request::header, sip_request::headers, sip_pvt::icseq, cfsip_methods::id, sip_pvt::initreq, INV_TERMINATED, sip_pvt::invitestate, sip_pvt::lastinvite, sip_pvt::lastmsg, sip_pvt::lastnoninvite, len(), LOG_DEBUG, LOG_ERROR, LOG_NOTICE, LOG_WARNING, sip_pvt::method, sip_request::method, sip_pvt::ocseq, option_debug, sip_pvt::pendinginvite, process_sdp(), sip_pvt::randdata, sip_request::rlPart1, sip_request::rlPart2, sip_pvt::sa, SIP_ACK, SIP_ALREADYGONE, SIP_BYE, SIP_CANCEL, sip_debug_test_pvt(), SIP_INFO, SIP_INVITE, SIP_MESSAGE, sip_methods, SIP_NEEDDESTROY, SIP_NOTIFY, SIP_OPTIONS, SIP_PKT_DEBUG, SIP_PKT_IGNORE, SIP_PKT_IGNORE_REQ, SIP_PKT_IGNORE_RESP, SIP_PKT_WITH_TOTAG, SIP_REFER, SIP_REGISTER, SIP_RESPONSE, sip_scheddestroy(), SIP_SUBSCRIBE, sip_pvt::tag, cfsip_methods::text, sip_pvt::theirtag, transmit_response(), transmit_response_reliable(), transmit_response_with_allow(), TRUE, and sip_pvt::useragent.
Referenced by sipsock_read().
15703 { 15704 /* Called with p->lock held, as well as p->owner->lock if appropriate, keeping things 15705 relatively static */ 15706 const char *cmd; 15707 const char *cseq; 15708 const char *useragent; 15709 int seqno; 15710 int len; 15711 int ignore = FALSE; 15712 int respid; 15713 int res = 0; 15714 int debug = sip_debug_test_pvt(p); 15715 char *e; 15716 int error = 0; 15717 15718 /* Get Method and Cseq */ 15719 cseq = get_header(req, "Cseq"); 15720 cmd = req->header[0]; 15721 15722 /* Must have Cseq */ 15723 if (ast_strlen_zero(cmd) || ast_strlen_zero(cseq)) { 15724 ast_log(LOG_ERROR, "Missing Cseq. Dropping this SIP message, it's incomplete.\n"); 15725 error = 1; 15726 } 15727 if (!error && sscanf(cseq, "%d%n", &seqno, &len) != 1) { 15728 ast_log(LOG_ERROR, "No seqno in '%s'. Dropping incomplete message.\n", cmd); 15729 error = 1; 15730 } 15731 if (error) { 15732 if (!p->initreq.headers) /* New call */ 15733 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); /* Make sure we destroy this dialog */ 15734 return -1; 15735 } 15736 /* Get the command XXX */ 15737 15738 cmd = req->rlPart1; 15739 e = req->rlPart2; 15740 15741 /* Save useragent of the client */ 15742 useragent = get_header(req, "User-Agent"); 15743 if (!ast_strlen_zero(useragent)) 15744 ast_string_field_set(p, useragent, useragent); 15745 15746 /* Find out SIP method for incoming request */ 15747 if (req->method == SIP_RESPONSE) { /* Response to our request */ 15748 /* Response to our request -- Do some sanity checks */ 15749 if (!p->initreq.headers) { 15750 if (option_debug) 15751 ast_log(LOG_DEBUG, "That's odd... Got a response on a call we dont know about. Cseq %d Cmd %s\n", seqno, cmd); 15752 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 15753 return 0; 15754 } else if (p->ocseq && (p->ocseq < seqno) && (seqno != p->lastnoninvite)) { 15755 if (option_debug) 15756 ast_log(LOG_DEBUG, "Ignoring out of order response %d (expecting %d)\n", seqno, p->ocseq); 15757 return -1; 15758 } else if (p->ocseq && (p->ocseq != seqno) && (seqno != p->lastnoninvite)) { 15759 /* ignore means "don't do anything with it" but still have to 15760 respond appropriately */ 15761 ignore = TRUE; 15762 ast_set_flag(req, SIP_PKT_IGNORE); 15763 ast_set_flag(req, SIP_PKT_IGNORE_RESP); 15764 append_history(p, "Ignore", "Ignoring this retransmit\n"); 15765 } else if (e) { 15766 e = ast_skip_blanks(e); 15767 if (sscanf(e, "%d %n", &respid, &len) != 1) { 15768 ast_log(LOG_WARNING, "Invalid response: '%s'\n", e); 15769 } else { 15770 if (respid <= 0) { 15771 ast_log(LOG_WARNING, "Invalid SIP response code: '%d'\n", respid); 15772 return 0; 15773 } 15774 /* More SIP ridiculousness, we have to ignore bogus contacts in 100 etc responses */ 15775 if ((respid == 200) || ((respid >= 300) && (respid <= 399))) 15776 extract_uri(p, req); 15777 handle_response(p, respid, e + len, req, ignore, seqno); 15778 } 15779 } 15780 return 0; 15781 } 15782 15783 /* New SIP request coming in 15784 (could be new request in existing SIP dialog as well...) 15785 */ 15786 15787 p->method = req->method; /* Find out which SIP method they are using */ 15788 if (option_debug > 3) 15789 ast_log(LOG_DEBUG, "**** Received %s (%d) - Command in SIP %s\n", sip_methods[p->method].text, sip_methods[p->method].id, cmd); 15790 15791 if (p->icseq && (p->icseq > seqno) ) { 15792 if (p->pendinginvite && seqno == p->pendinginvite && (req->method == SIP_ACK || req->method == SIP_CANCEL)) { 15793 if (option_debug > 2) 15794 ast_log(LOG_DEBUG, "Got CANCEL or ACK on INVITE with transactions in between.\n"); 15795 } else { 15796 if (option_debug) 15797 ast_log(LOG_DEBUG, "Ignoring too old SIP packet packet %d (expecting >= %d)\n", seqno, p->icseq); 15798 if (req->method != SIP_ACK) 15799 transmit_response(p, "503 Server error", req); /* We must respond according to RFC 3261 sec 12.2 */ 15800 return -1; 15801 } 15802 } else if (p->icseq && 15803 p->icseq == seqno && 15804 req->method != SIP_ACK && 15805 (p->method != SIP_CANCEL || ast_test_flag(&p->flags[0], SIP_ALREADYGONE))) { 15806 /* ignore means "don't do anything with it" but still have to 15807 respond appropriately. We do this if we receive a repeat of 15808 the last sequence number */ 15809 ignore = 2; 15810 ast_set_flag(req, SIP_PKT_IGNORE); 15811 ast_set_flag(req, SIP_PKT_IGNORE_REQ); 15812 if (option_debug > 2) 15813 ast_log(LOG_DEBUG, "Ignoring SIP message because of retransmit (%s Seqno %d, ours %d)\n", sip_methods[p->method].text, p->icseq, seqno); 15814 } 15815 15816 if (seqno >= p->icseq) 15817 /* Next should follow monotonically (but not necessarily 15818 incrementally -- thanks again to the genius authors of SIP -- 15819 increasing */ 15820 p->icseq = seqno; 15821 15822 /* Find their tag if we haven't got it */ 15823 if (ast_strlen_zero(p->theirtag)) { 15824 char tag[128]; 15825 15826 gettag(req, "From", tag, sizeof(tag)); 15827 ast_string_field_set(p, theirtag, tag); 15828 } 15829 snprintf(p->lastmsg, sizeof(p->lastmsg), "Rx: %s", cmd); 15830 15831 if (pedanticsipchecking) { 15832 /* If this is a request packet without a from tag, it's not 15833 correct according to RFC 3261 */ 15834 /* Check if this a new request in a new dialog with a totag already attached to it, 15835 RFC 3261 - section 12.2 - and we don't want to mess with recovery */ 15836 if (!p->initreq.headers && ast_test_flag(req, SIP_PKT_WITH_TOTAG)) { 15837 /* If this is a first request and it got a to-tag, it is not for us */ 15838 if (!ast_test_flag(req, SIP_PKT_IGNORE) && req->method == SIP_INVITE) { 15839 transmit_response_reliable(p, "481 Call/Transaction Does Not Exist", req); 15840 /* Will cease to exist after ACK */ 15841 } else if (req->method != SIP_ACK) { 15842 transmit_response(p, "481 Call/Transaction Does Not Exist", req); 15843 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 15844 } 15845 return res; 15846 } 15847 } 15848 15849 if (!e && (p->method == SIP_INVITE || p->method == SIP_SUBSCRIBE || p->method == SIP_REGISTER || p->method == SIP_NOTIFY)) { 15850 transmit_response(p, "400 Bad request", req); 15851 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 15852 return -1; 15853 } 15854 15855 /* Handle various incoming SIP methods in requests */ 15856 switch (p->method) { 15857 case SIP_OPTIONS: 15858 res = handle_request_options(p, req); 15859 break; 15860 case SIP_INVITE: 15861 res = handle_request_invite(p, req, debug, seqno, sin, recount, e, nounlock); 15862 break; 15863 case SIP_REFER: 15864 res = handle_request_refer(p, req, debug, ignore, seqno, nounlock); 15865 break; 15866 case SIP_CANCEL: 15867 res = handle_request_cancel(p, req); 15868 break; 15869 case SIP_BYE: 15870 res = handle_request_bye(p, req); 15871 break; 15872 case SIP_MESSAGE: 15873 res = handle_request_message(p, req); 15874 break; 15875 case SIP_SUBSCRIBE: 15876 res = handle_request_subscribe(p, req, sin, seqno, e); 15877 break; 15878 case SIP_REGISTER: 15879 res = handle_request_register(p, req, sin, e); 15880 break; 15881 case SIP_INFO: 15882 if (ast_test_flag(req, SIP_PKT_DEBUG)) 15883 ast_verbose("Receiving INFO!\n"); 15884 if (!ignore) 15885 handle_request_info(p, req); 15886 else /* if ignoring, transmit response */ 15887 transmit_response(p, "200 OK", req); 15888 break; 15889 case SIP_NOTIFY: 15890 res = handle_request_notify(p, req, sin, seqno, e); 15891 break; 15892 case SIP_ACK: 15893 /* Make sure we don't ignore this */ 15894 if (seqno == p->pendinginvite) { 15895 p->invitestate = INV_TERMINATED; 15896 p->pendinginvite = 0; 15897 __sip_ack(p, seqno, FLAG_RESPONSE, 0); 15898 if (find_sdp(req)) { 15899 if (process_sdp(p, req)) 15900 return -1; 15901 } 15902 check_pendings(p); 15903 } 15904 /* Got an ACK that we did not match. Ignore silently */ 15905 if (!p->lastinvite && ast_strlen_zero(p->randdata)) 15906 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 15907 break; 15908 default: 15909 transmit_response_with_allow(p, "501 Method Not Implemented", req, 0); 15910 ast_log(LOG_NOTICE, "Unknown SIP command '%s' from '%s'\n", 15911 cmd, ast_inet_ntoa(p->sa.sin_addr)); 15912 /* If this is some new method, and we don't have a call, destroy it now */ 15913 if (!p->initreq.headers) 15914 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 15915 break; 15916 } 15917 return res; 15918 }
| static int handle_request_bye | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Handle incoming BYE request.
Definition at line 15263 of file chan_sip.c.
References __sip_pretend_ack(), append_history, ast_async_goto(), ast_bridged_channel(), ast_clear_flag, AST_CONTROL_UNHOLD, ast_inet_ntoa(), ast_log(), ast_queue_control(), ast_queue_hangup(), ast_rtp_get_quality(), ast_string_field_set, ast_strlen_zero(), ast_test_flag, check_via(), domain::context, sip_pvt::context, copy_request(), DEFAULT_TRANS_TIMEOUT, sip_pvt::flags, get_also_info(), get_header(), sip_pvt::initreq, INV_TERMINATED, sip_pvt::invitestate, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, option_debug, sip_pvt::owner, pbx_builtin_setvar_helper(), sip_pvt::pendinginvite, sip_pvt::recv, sip_pvt::refer, sip_refer::refer_to, sip_pvt::rtp, sip_alreadygone(), SIP_NO_HISTORY, SIP_OUTGOING, SIP_PAGE2_DIALOG_ESTABLISHED, SIP_PKT_IGNORE, sip_scheddestroy(), stop_media_flows(), transmit_response(), transmit_response_reliable(), and sip_pvt::vrtp.
Referenced by handle_request().
15264 { 15265 struct ast_channel *c=NULL; 15266 int res; 15267 struct ast_channel *bridged_to; 15268 15269 /* If we have an INCOMING invite that we haven't answered, terminate that transaction */ 15270 if (p->pendinginvite && !ast_test_flag(&p->flags[0], SIP_OUTGOING) && !ast_test_flag(req, SIP_PKT_IGNORE) && !p->owner) 15271 transmit_response_reliable(p, "487 Request Terminated", &p->initreq); 15272 15273 __sip_pretend_ack(p); 15274 15275 p->invitestate = INV_TERMINATED; 15276 15277 copy_request(&p->initreq, req); 15278 check_via(p, req); 15279 sip_alreadygone(p); 15280 15281 /* Get RTCP quality before end of call */ 15282 if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY) || p->owner) { 15283 char *audioqos, *videoqos; 15284 if (p->rtp) { 15285 audioqos = ast_rtp_get_quality(p->rtp, NULL); 15286 if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) 15287 append_history(p, "RTCPaudio", "Quality:%s", audioqos); 15288 if (p->owner) 15289 pbx_builtin_setvar_helper(p->owner, "RTPAUDIOQOS", audioqos); 15290 } 15291 if (p->vrtp) { 15292 videoqos = ast_rtp_get_quality(p->vrtp, NULL); 15293 if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) 15294 append_history(p, "RTCPvideo", "Quality:%s", videoqos); 15295 if (p->owner) 15296 pbx_builtin_setvar_helper(p->owner, "RTPVIDEOQOS", videoqos); 15297 } 15298 } 15299 15300 stop_media_flows(p); /* Immediately stop RTP, VRTP and UDPTL as applicable */ 15301 15302 if (!ast_strlen_zero(get_header(req, "Also"))) { 15303 ast_log(LOG_NOTICE, "Client '%s' using deprecated BYE/Also transfer method. Ask vendor to support REFER instead\n", 15304 ast_inet_ntoa(p->recv.sin_addr)); 15305 if (ast_strlen_zero(p->context)) 15306 ast_string_field_set(p, context, default_context); 15307 res = get_also_info(p, req); 15308 if (!res) { 15309 c = p->owner; 15310 if (c) { 15311 bridged_to = ast_bridged_channel(c); 15312 if (bridged_to) { 15313 /* Don't actually hangup here... */ 15314 ast_queue_control(c, AST_CONTROL_UNHOLD); 15315 ast_async_goto(bridged_to, p->context, p->refer->refer_to,1); 15316 } else 15317 ast_queue_hangup(p->owner); 15318 } 15319 } else { 15320 ast_log(LOG_WARNING, "Invalid transfer information from '%s'\n", ast_inet_ntoa(p->recv.sin_addr)); 15321 if (p->owner) 15322 ast_queue_hangup(p->owner); 15323 } 15324 } else if (p->owner) { 15325 ast_queue_hangup(p->owner); 15326 if (option_debug > 2) 15327 ast_log(LOG_DEBUG, "Received bye, issuing owner hangup\n"); 15328 } else { 15329 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 15330 if (option_debug > 2) 15331 ast_log(LOG_DEBUG, "Received bye, no owner, selfdestruct soon.\n"); 15332 } 15333 ast_clear_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 15334 transmit_response(p, "200 OK", req); 15335 15336 return 1; 15337 }
| static int handle_request_cancel | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Handle incoming CANCEL request.
Definition at line 15157 of file chan_sip.c.
References __sip_pretend_ack(), ast_channel::_state, ast_log(), ast_queue_hangup(), AST_STATE_UP, ast_test_flag, check_via(), DEC_CALL_LIMIT, DEFAULT_TRANS_TIMEOUT, sip_pvt::flags, sip_pvt::initreq, INV_CANCELLED, INV_TERMINATED, sip_pvt::invitestate, sip_request::len, LOG_DEBUG, option_debug, sip_pvt::owner, sip_alreadygone(), SIP_INC_COUNT, SIP_PAGE2_CALL_ONHOLD, sip_scheddestroy(), stop_media_flows(), transmit_response(), transmit_response_reliable(), and update_call_counter().
Referenced by handle_request().
15158 { 15159 15160 check_via(p, req); 15161 sip_alreadygone(p); 15162 15163 /* At this point, we could have cancelled the invite at the same time 15164 as the other side sends a CANCEL. Our final reply with error code 15165 might not have been received by the other side before the CANCEL 15166 was sent, so let's just give up retransmissions and waiting for 15167 ACK on our error code. The call is hanging up any way. */ 15168 if (p->invitestate == INV_TERMINATED) 15169 __sip_pretend_ack(p); 15170 else 15171 p->invitestate = INV_CANCELLED; 15172 15173 if (p->owner && p->owner->_state == AST_STATE_UP) { 15174 /* This call is up, cancel is ignored, we need a bye */ 15175 transmit_response(p, "200 OK", req); 15176 if (option_debug) 15177 ast_log(LOG_DEBUG, "Got CANCEL on an answered call. Ignoring... \n"); 15178 return 0; 15179 } 15180 15181 if (ast_test_flag(&p->flags[0], SIP_INC_COUNT) || ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD)) 15182 update_call_counter(p, DEC_CALL_LIMIT); 15183 15184 stop_media_flows(p); /* Immediately stop RTP, VRTP and UDPTL as applicable */ 15185 if (p->owner) 15186 ast_queue_hangup(p->owner); 15187 else 15188 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 15189 if (p->initreq.len > 0) { 15190 transmit_response_reliable(p, "487 Request Terminated", &p->initreq); 15191 transmit_response(p, "200 OK", req); 15192 return 1; 15193 } else { 15194 transmit_response(p, "481 Call Leg Does Not Exist", req); 15195 return 0; 15196 } 15197 }
| static void handle_request_info | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Receive SIP INFO Message.
Definition at line 11313 of file chan_sip.c.
References ast_bridged_channel(), ast_cdr_setuserfield(), AST_CONTROL_FLASH, AST_CONTROL_VIDUPDATE, ast_copy_string(), AST_FRAME_CONTROL, AST_FRAME_DTMF, ast_log(), ast_queue_control(), ast_queue_frame(), ast_strlen_zero(), ast_test_flag, ast_verbose(), sip_pvt::callid, ast_channel::cdr, DEFAULT_TRANS_TIMEOUT, sip_history::event, sip_pvt::flags, get_body(), get_header(), ast_frame::len, LOG_WARNING, sip_pvt::owner, sip_scheddestroy(), SIP_USECLIENTCODE, sipdebug, ast_frame::subclass, and transmit_response().
Referenced by handle_request().
11314 { 11315 char buf[1024]; 11316 unsigned int event; 11317 const char *c = get_header(req, "Content-Type"); 11318 11319 /* Need to check the media/type */ 11320 if (!strcasecmp(c, "application/dtmf-relay") || 11321 !strcasecmp(c, "application/vnd.nortelnetworks.digits")) { 11322 unsigned int duration = 0; 11323 11324 /* Try getting the "signal=" part */ 11325 if (ast_strlen_zero(c = get_body(req, "Signal")) && ast_strlen_zero(c = get_body(req, "d"))) { 11326 ast_log(LOG_WARNING, "Unable to retrieve DTMF signal from INFO message from %s\n", p->callid); 11327 transmit_response(p, "200 OK", req); /* Should return error */ 11328 return; 11329 } else { 11330 ast_copy_string(buf, c, sizeof(buf)); 11331 } 11332 11333 if (!ast_strlen_zero((c = get_body(req, "Duration")))) 11334 duration = atoi(c); 11335 if (!duration) 11336 duration = 100; /* 100 ms */ 11337 11338 if (!p->owner) { /* not a PBX call */ 11339 transmit_response(p, "481 Call leg/transaction does not exist", req); 11340 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 11341 return; 11342 } 11343 11344 if (ast_strlen_zero(buf)) { 11345 transmit_response(p, "200 OK", req); 11346 return; 11347 } 11348 11349 if (buf[0] == '*') 11350 event = 10; 11351 else if (buf[0] == '#') 11352 event = 11; 11353 else if ((buf[0] >= 'A') && (buf[0] <= 'D')) 11354 event = 12 + buf[0] - 'A'; 11355 else 11356 event = atoi(buf); 11357 if (event == 16) { 11358 /* send a FLASH event */ 11359 struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_FLASH, }; 11360 ast_queue_frame(p->owner, &f); 11361 if (sipdebug) 11362 ast_verbose("* DTMF-relay event received: FLASH\n"); 11363 } else { 11364 /* send a DTMF event */ 11365 struct ast_frame f = { AST_FRAME_DTMF, }; 11366 if (event < 10) { 11367 f.subclass = '0' + event; 11368 } else if (event < 11) { 11369 f.subclass = '*'; 11370 } else if (event < 12) { 11371 f.subclass = '#'; 11372 } else if (event < 16) { 11373 f.subclass = 'A' + (event - 12); 11374 } 11375 f.len = duration; 11376 ast_queue_frame(p->owner, &f); 11377 if (sipdebug) 11378 ast_verbose("* DTMF-relay event received: %c\n", f.subclass); 11379 } 11380 transmit_response(p, "200 OK", req); 11381 return; 11382 } else if (!strcasecmp(c, "application/media_control+xml")) { 11383 /* Eh, we'll just assume it's a fast picture update for now */ 11384 if (p->owner) 11385 ast_queue_control(p->owner, AST_CONTROL_VIDUPDATE); 11386 transmit_response(p, "200 OK", req); 11387 return; 11388 } else if (!ast_strlen_zero(c = get_header(req, "X-ClientCode"))) { 11389 /* Client code (from SNOM phone) */ 11390 if (ast_test_flag(&p->flags[0], SIP_USECLIENTCODE)) { 11391 if (p->owner && p->owner->cdr) 11392 ast_cdr_setuserfield(p->owner, c); 11393 if (p->owner && ast_bridged_channel(p->owner) && ast_bridged_channel(p->owner)->cdr) 11394 ast_cdr_setuserfield(ast_bridged_channel(p->owner), c); 11395 transmit_response(p, "200 OK", req); 11396 } else { 11397 transmit_response(p, "403 Unauthorized", req); 11398 } 11399 return; 11400 } else if (ast_strlen_zero(c = get_header(req, "Content-Length")) || !strcasecmp(c, "0")) { 11401 /* This is probably just a packet making sure the signalling is still up, just send back a 200 OK */ 11402 transmit_response(p, "200 OK", req); 11403 return; 11404 } 11405 11406 /* Other type of INFO message, not really understood by Asterisk */ 11407 /* if (get_msg_text(buf, sizeof(buf), req)) { */ 11408 11409 ast_log(LOG_WARNING, "Unable to parse INFO message from %s. Content %s\n", p->callid, buf); 11410 transmit_response(p, "415 Unsupported media type", req); 11411 return; 11412 }
| static int handle_request_invite | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| int | debug, | |||
| int | seqno, | |||
| struct sockaddr_in * | sin, | |||
| int * | recount, | |||
| char * | e, | |||
| int * | nounlock | |||
| ) | [static] |
Handle incoming INVITE request.
XXX: we should also check here does the other side supports t38 at all !!! XXX
Definition at line 14150 of file chan_sip.c.
References ast_channel::_state, append_history, ast_bridged_channel(), AST_CAUSE_CALL_REJECTED, AST_CAUSE_NORMAL_CLEARING, ast_channel_lock, ast_channel_unlock, ast_check_hangup(), ast_clear_flag, ast_hangup(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_null_frame, AST_PBX_CALL_LIMIT, AST_PBX_FAILED, ast_pbx_start(), AST_PBX_SUCCESS, ast_pickup_call(), ast_pickup_ext(), ast_queue_frame(), ast_rtp_setdtmf(), ast_rtp_setdtmfcompensate(), AST_SCHED_DEL, ast_set_flag, ast_setstate(), ast_skip_blanks(), AST_STATE_DOWN, AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, ast_strdupa, ast_string_field_free, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_uri_decode(), ast_verbose(), AUTH_CHALLENGE_SENT, AUTH_FAKE_AUTH, sip_pvt::autokillid, build_contact(), build_route(), sip_pvt::callid, sip_pvt::capability, change_hold_state(), check_user(), check_via(), domain::context, sip_pvt::context, copy_request(), create_addr(), DEC_CALL_LIMIT, DEFAULT_TRANS_TIMEOUT, exten, sip_pvt::exten, extract_uri(), FALSE, find_sdp(), sip_pvt::flags, get_destination(), get_header(), get_rdnis(), get_sip_pvt_byid_locked(), handle_invite_replaces(), ast_channel::hangupcause, sip_request::headers, sip_pvt::icseq, INC_CALL_LIMIT, sip_pvt::initreq, INV_COMPLETED, INV_PROCEEDING, INV_TERMINATED, sip_pvt::invitestate, sip_pvt::jointcapability, sip_pvt::lastinvite, ast_channel::lock, sip_pvt::lock, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, make_our_tag(), sip_pkt::method, ast_channel::name, sip_pkt::next, option_debug, sip_pvt::owner, sip_pvt::packets, parse_ok_contact(), parse_sip_options(), sip_pvt::peername, sip_pvt::pendinginvite, process_sdp(), sip_pvt::refer, sip_refer::refer_call, sip_pkt::retransid, sip_request::rlPart2, sip_pvt::rtp, S_OR, sip_pkt::seqno, sip_alreadygone(), sip_cancel_destroy(), SIP_DTMF, SIP_DTMF_RFC2833, sip_handle_t38_reinvite(), SIP_INVITE, sip_new(), SIP_NO_HISTORY, SIP_OPT_REPLACES, SIP_OUTGOING, SIP_PAGE2_ALLOWOVERLAP, SIP_PAGE2_CALL_ONHOLD, SIP_PAGE2_DIALOG_ESTABLISHED, SIP_PAGE2_RFC2833_COMPENSATE, SIP_PKT_IGNORE, sip_refer_allocate(), sip_scheddestroy(), sip_uri_cmp(), sipdebug, sip_pvt::sipoptions, t38properties::state, sip_pvt::t38, T38_DISABLED, T38_ENABLED, T38_PEER_REINVITE, sip_pvt::tag, ast_channel::tech, ast_channel::tech_pvt, transmit_fake_auth_response(), transmit_invite(), transmit_response(), transmit_response_reliable(), transmit_response_with_sdp(), transmit_response_with_t38_sdp(), transmit_response_with_unsupported(), TRUE, sip_pvt::udptl, update_call_counter(), sip_pvt::username, XMIT_CRITICAL, XMIT_RELIABLE, and XMIT_UNRELIABLE.
Referenced by handle_request().
14151 { 14152 int res = 1; 14153 int gotdest; 14154 const char *p_replaces; 14155 char *replace_id = NULL; 14156 const char *required; 14157 unsigned int required_profile = 0; 14158 struct ast_channel *c = NULL; /* New channel */ 14159 int reinvite = 0; 14160 14161 /* Find out what they support */ 14162 if (!p->sipoptions) { 14163 const char *supported = get_header(req, "Supported"); 14164 if (!ast_strlen_zero(supported)) 14165 parse_sip_options(p, supported); 14166 } 14167 14168 /* Find out what they require */ 14169 required = get_header(req, "Require"); 14170 if (!ast_strlen_zero(required)) { 14171 required_profile = parse_sip_options(NULL, required); 14172 if (required_profile && required_profile != SIP_OPT_REPLACES) { 14173 /* At this point we only support REPLACES */ 14174 transmit_response_with_unsupported(p, "420 Bad extension (unsupported)", req, required); 14175 ast_log(LOG_WARNING,"Received SIP INVITE with unsupported required extension: %s\n", required); 14176 p->invitestate = INV_COMPLETED; 14177 if (!p->lastinvite) 14178 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 14179 return -1; 14180 } 14181 } 14182 14183 /* Check if this is a loop */ 14184 if (ast_test_flag(&p->flags[0], SIP_OUTGOING) && p->owner && (p->owner->_state != AST_STATE_UP)) { 14185 /* This is a call to ourself. Send ourselves an error code and stop 14186 processing immediately, as SIP really has no good mechanism for 14187 being able to call yourself */ 14188 /* If pedantic is on, we need to check the tags. If they're different, this is 14189 in fact a forked call through a SIP proxy somewhere. */ 14190 int different; 14191 if (pedanticsipchecking) 14192 different = sip_uri_cmp(p->initreq.rlPart2, req->rlPart2); 14193 else 14194 different = strcmp(p->initreq.rlPart2, req->rlPart2); 14195 if (!different) { 14196 transmit_response(p, "482 Loop Detected", req); 14197 p->invitestate = INV_COMPLETED; 14198 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 14199 return 0; 14200 } else { 14201 /* This is a spiral. What we need to do is to just change the outgoing INVITE 14202 * so that it now routes to the new Request URI. Since we created the INVITE ourselves 14203 * that should be all we need to do. 14204 */ 14205 char *uri = ast_strdupa(req->rlPart2); 14206 char *at = strchr(uri, '@'); 14207 char *peerorhost; 14208 struct sip_pkt *pkt = NULL; 14209 if (option_debug > 2) { 14210 ast_log(LOG_DEBUG, "Potential spiral detected. Original RURI was %s, new RURI is %s\n", p->initreq.rlPart2, req->rlPart2); 14211 } 14212 if (at) { 14213 *at = '\0'; 14214 } 14215 /* Parse out "sip:" */ 14216 if ((peerorhost = strchr(uri, ':'))) { 14217 *peerorhost++ = '\0'; 14218 } 14219 create_addr(p, peerorhost); 14220 ast_string_field_free(p, theirtag); 14221 for (pkt = p->packets; pkt; pkt = pkt->next) { 14222 if (pkt->seqno == p->icseq && pkt->method == SIP_INVITE) { 14223 AST_SCHED_DEL(sched, pkt->retransid); 14224 } 14225 } 14226 return transmit_invite(p, SIP_INVITE, 1, 3); 14227 } 14228 } 14229 14230 if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->pendinginvite) { 14231 /* We already have a pending invite. Sorry. You are on hold. */ 14232 transmit_response_reliable(p, "491 Request Pending", req); 14233 if (option_debug) 14234 ast_log(LOG_DEBUG, "Got INVITE on call where we already have pending INVITE, deferring that - %s\n", p->callid); 14235 /* Don't destroy dialog here */ 14236 return 0; 14237 } 14238 14239 p_replaces = get_header(req, "Replaces"); 14240 if (!ast_strlen_zero(p_replaces)) { 14241 /* We have a replaces header */ 14242 char *ptr; 14243 char *fromtag = NULL; 14244 char *totag = NULL; 14245 char *start, *to; 14246 int error = 0; 14247 14248 if (p->owner) { 14249 if (option_debug > 2) 14250 ast_log(LOG_DEBUG, "INVITE w Replaces on existing call? Refusing action. [%s]\n", p->callid); 14251 transmit_response_reliable(p, "400 Bad request", req); /* The best way to not not accept the transfer */ 14252 /* Do not destroy existing call */ 14253 return -1; 14254 } 14255 14256 if (sipdebug && option_debug > 2) 14257 ast_log(LOG_DEBUG, "INVITE part of call transfer. Replaces [%s]\n", p_replaces); 14258 /* Create a buffer we can manipulate */ 14259 replace_id = ast_strdupa(p_replaces); 14260 ast_uri_decode(replace_id); 14261 14262 if (!p->refer && !sip_refer_allocate(p)) { 14263 transmit_response_reliable(p, "500 Server Internal Error", req); 14264 append_history(p, "Xfer", "INVITE/Replace Failed. Out of memory."); 14265 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 14266 p->invitestate = INV_COMPLETED; 14267 return -1; 14268 } 14269 14270 /* Todo: (When we find phones that support this) 14271 if the replaces header contains ";early-only" 14272 we can only replace the call in early 14273 stage, not after it's up. 14274 14275 If it's not in early mode, 486 Busy. 14276 */ 14277 14278 /* Skip leading whitespace */ 14279 replace_id = ast_skip_blanks(replace_id); 14280 14281 start = replace_id; 14282 while ( (ptr = strsep(&start, ";")) ) { 14283 ptr = ast_skip_blanks(ptr); /* XXX maybe unnecessary ? */ 14284 if ( (to = strcasestr(ptr, "to-tag=") ) ) 14285 totag = to + 7; /* skip the keyword */ 14286 else if ( (to = strcasestr(ptr, "from-tag=") ) ) { 14287 fromtag = to + 9; /* skip the keyword */ 14288 fromtag = strsep(&fromtag, "&"); /* trim what ? */ 14289 } 14290 } 14291 14292 if (sipdebug && option_debug > 3) 14293 ast_log(LOG_DEBUG,"Invite/replaces: Will use Replace-Call-ID : %s Fromtag: %s Totag: %s\n", replace_id, fromtag ? fromtag : "<no from tag>", totag ? totag : "<no to tag>"); 14294 14295 14296 /* Try to find call that we are replacing 14297 If we have a Replaces header, we need to cancel that call if we succeed with this call 14298 */ 14299 if ((p->refer->refer_call = get_sip_pvt_byid_locked(replace_id, totag, fromtag)) == NULL) { 14300 ast_log(LOG_NOTICE, "Supervised transfer attempted to replace non-existent call id (%s)!\n", replace_id); 14301 transmit_response_reliable(p, "481 Call Leg Does Not Exist (Replaces)", req); 14302 error = 1; 14303 } 14304 14305 /* At this point, bot the pvt and the owner of the call to be replaced is locked */ 14306 14307 /* The matched call is the call from the transferer to Asterisk . 14308 We want to bridge the bridged part of the call to the 14309 incoming invite, thus taking over the refered call */ 14310 14311 if (p->refer->refer_call == p) { 14312 ast_log(LOG_NOTICE, "INVITE with replaces into it's own call id (%s == %s)!\n", replace_id, p->callid); 14313 p->refer->refer_call = NULL; 14314 transmit_response_reliable(p, "400 Bad request", req); /* The best way to not not accept the transfer */ 14315 error = 1; 14316 } 14317 14318 if (!error && !p->refer->refer_call->owner) { 14319 /* Oops, someting wrong anyway, no owner, no call */ 14320 ast_log(LOG_NOTICE, "Supervised transfer attempted to replace non-existing call id (%s)!\n", replace_id); 14321 /* Check for better return code */ 14322 transmit_response_reliable(p, "481 Call Leg Does Not Exist (Replace)", req); 14323 error = 1; 14324 } 14325 14326 if (!error && 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 ) { 14327 ast_log(LOG_NOTICE, "Supervised transfer attempted to replace non-ringing or active call id (%s)!\n", replace_id); 14328 transmit_response_reliable(p, "603 Declined (Replaces)", req); 14329 error = 1; 14330 } 14331 14332 if (error) { /* Give up this dialog */ 14333 append_history(p, "Xfer", "INVITE/Replace Failed."); 14334 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 14335 ast_mutex_unlock(&p->lock); 14336 if (p->refer->refer_call) { 14337 ast_mutex_unlock(&p->refer->refer_call->lock); 14338 if (p->refer->refer_call->owner) { 14339 ast_channel_unlock(p->refer->refer_call->owner); 14340 } 14341 } 14342 p->invitestate = INV_COMPLETED; 14343 return -1; 14344 } 14345 } 14346 14347 14348 /* Check if this is an INVITE that sets up a new dialog or 14349 a re-invite in an existing dialog */ 14350 14351 if (!ast_test_flag(req, SIP_PKT_IGNORE)) { 14352 int newcall = (p->initreq.headers ? TRUE : FALSE); 14353 14354 if (sip_cancel_destroy(p)) 14355 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 14356 /* This also counts as a pending invite */ 14357 p->pendinginvite = seqno; 14358 check_via(p, req); 14359 14360 copy_request(&p->initreq, req); /* Save this INVITE as the transaction basis */ 14361 if (!p->owner) { /* Not a re-invite */ 14362 if (debug) 14363 ast_verbose("Using INVITE request as basis request - %s\n", p->callid); 14364 if (newcall) 14365 append_history(p, "Invite", "New call: %s", p->callid); 14366 parse_ok_contact(p, req); 14367 } else { /* Re-invite on existing call */ 14368 ast_clear_flag(&p->flags[0], SIP_OUTGOING); /* This is now an inbound dialog */ 14369 /* Handle SDP here if we already have an owner */ 14370 if (find_sdp(req)) { 14371 if (process_sdp(p, req)) { 14372 transmit_response_reliable(p, "488 Not acceptable here", req); 14373 if (!p->lastinvite) 14374 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 14375 return -1; 14376 } 14377 } else { 14378 p->jointcapability = p->capability; 14379 if (option_debug > 2) 14380 ast_log(LOG_DEBUG, "Hm.... No sdp for the moment\n"); 14381 /* Some devices signal they want to be put off hold by sending a re-invite 14382 *without* an SDP, which is supposed to mean "Go back to your state" 14383 and since they put os on remote hold, we go back to off hold */ 14384 if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD)) 14385 change_hold_state(p, req, FALSE, 0); 14386 } 14387 if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) /* This is a response, note what it was for */ 14388 append_history(p, "ReInv", "Re-invite received"); 14389 } 14390 } else if (debug) 14391 ast_verbose("Ignoring this INVITE request\n"); 14392 14393 14394 if (!p->lastinvite && !ast_test_flag(req, SIP_PKT_IGNORE) && !p->owner) { 14395 /* This is a new invite */ 14396 /* Handle authentication if this is our first invite */ 14397 res = check_user(p, req, SIP_INVITE, e, XMIT_RELIABLE, sin); 14398 if (res == AUTH_CHALLENGE_SENT) { 14399 p->invitestate = INV_COMPLETED; /* Needs to restart in another INVITE transaction */ 14400 return 0; 14401 } 14402 if (res < 0) { /* Something failed in authentication */ 14403 if (res == AUTH_FAKE_AUTH) { 14404 ast_log(LOG_NOTICE, "Sending fake auth rejection for user %s\n", get_header(req, "From")); 14405 transmit_fake_auth_response(p, req, 1); 14406 } else { 14407 ast_log(LOG_NOTICE, "Failed to authenticate user %s\n", get_header(req, "From")); 14408 transmit_response_reliable(p, "403 Forbidden", req); 14409 } 14410 p->invitestate = INV_COMPLETED; 14411 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 14412 ast_string_field_free(p, theirtag); 14413 return 0; 14414 } 14415 14416 /* We have a succesful authentication, process the SDP portion if there is one */ 14417 if (find_sdp(req)) { 14418 if (process_sdp(p, req)) { 14419 /* Unacceptable codecs */ 14420 transmit_response_reliable(p, "488 Not acceptable here", req); 14421 p->invitestate = INV_COMPLETED; 14422 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 14423 if (option_debug) 14424 ast_log(LOG_DEBUG, "No compatible codecs for this SIP call.\n"); 14425 return -1; 14426 } 14427 } else { /* No SDP in invite, call control session */ 14428 p->jointcapability = p->capability; 14429 if (option_debug > 1) 14430 ast_log(LOG_DEBUG, "No SDP in Invite, third party call control\n"); 14431 } 14432 14433 /* Queue NULL frame to prod ast_rtp_bridge if appropriate */ 14434 /* This seems redundant ... see !p-owner above */ 14435 if (p->owner) 14436 ast_queue_frame(p->owner, &ast_null_frame); 14437 14438 14439 /* Initialize the context if it hasn't been already */ 14440 if (ast_strlen_zero(p->context)) 14441 ast_string_field_set(p, context, default_context); 14442 14443 14444 /* Check number of concurrent calls -vs- incoming limit HERE */ 14445 if (option_debug) 14446 ast_log(LOG_DEBUG, "Checking SIP call limits for device %s\n", p->username); 14447 if ((res = update_call_counter(p, INC_CALL_LIMIT))) { 14448 if (res < 0) { 14449 ast_log(LOG_NOTICE, "Failed to place call for user %s, too many calls\n", p->username); 14450 transmit_response_reliable(p, "480 Temporarily Unavailable (Call limit) ", req); 14451 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 14452 p->invitestate = INV_COMPLETED; 14453 } 14454 return 0; 14455 } 14456 gotdest = get_destination(p, NULL); /* Get destination right away */ 14457 get_rdnis(p, NULL); /* Get redirect information */ 14458 extract_uri(p, req); /* Get the Contact URI */ 14459 build_contact(p); /* Build our contact header */ 14460 14461 if (p->rtp) { 14462 ast_rtp_setdtmf(p->rtp, ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833); 14463 ast_rtp_setdtmfcompensate(p->rtp, ast_test_flag(&p->flags[1], SIP_PAGE2_RFC2833_COMPENSATE)); 14464 } 14465 14466 if (!replace_id && gotdest) { /* No matching extension found */ 14467 if (gotdest == 1 && ast_test_flag(&p->flags[1], SIP_PAGE2_ALLOWOVERLAP)) 14468 transmit_response_reliable(p, "484 Address Incomplete", req); 14469 else { 14470 char *decoded_exten = ast_strdupa(p->exten); 14471 14472 transmit_response_reliable(p, "404 Not Found", req); 14473 ast_uri_decode(decoded_exten); 14474 ast_log(LOG_NOTICE, "Call from '%s' to extension" 14475 " '%s' rejected because extension not found.\n", 14476 S_OR(p->username, p->peername), decoded_exten); 14477 } 14478 p->invitestate = INV_COMPLETED; 14479 update_call_counter(p, DEC_CALL_LIMIT); 14480 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 14481 return 0; 14482 } else { 14483 /* If no extension was specified, use the s one */ 14484 /* Basically for calling to IP/Host name only */ 14485 if (ast_strlen_zero(p->exten)) 14486 ast_string_field_set(p, exten, "s"); 14487 /* Initialize our tag */ 14488 14489 make_our_tag(p->tag, sizeof(p->tag)); 14490 /* First invitation - create the channel */ 14491 c = sip_new(p, AST_STATE_DOWN, S_OR(p->username, NULL)); 14492 *recount = 1; 14493 14494 /* Save Record-Route for any later requests we make on this dialogue */ 14495 build_route(p, req, 0); 14496 14497 if (c) { 14498 /* Pre-lock the call */ 14499 ast_channel_lock(c); 14500 } 14501 } 14502 } else { 14503 if (option_debug > 1 && sipdebug) { 14504 if (!ast_test_flag(req, SIP_PKT_IGNORE)) 14505 ast_log(LOG_DEBUG, "Got a SIP re-invite for call %s\n", p->callid); 14506 else 14507 ast_log(LOG_DEBUG, "Got a SIP re-transmit of INVITE for call %s\n", p->callid); 14508 } 14509 if (!ast_test_flag(req, SIP_PKT_IGNORE)) 14510 reinvite = 1; 14511 c = p->owner; 14512 } 14513 14514 if (!ast_test_flag(req, SIP_PKT_IGNORE) && p) 14515 p->lastinvite = seqno; 14516 14517 if (replace_id) { /* Attended transfer or call pickup - we're the target */ 14518 /* Go and take over the target call */ 14519 if (sipdebug && option_debug > 3) 14520 ast_log(LOG_DEBUG, "Sending this call to the invite/replcaes handler %s\n", p->callid); 14521 return handle_invite_replaces(p, req, debug, ast_test_flag(req, SIP_PKT_IGNORE), seqno, sin); 14522 } 14523 14524 14525 if (c) { /* We have a call -either a new call or an old one (RE-INVITE) */ 14526 switch(c->_state) { 14527 case AST_STATE_DOWN: 14528 if (option_debug > 1) 14529 ast_log(LOG_DEBUG, "%s: New call is still down.... Trying... \n", c->name); 14530 transmit_response(p, "100 Trying", req); 14531 p->invitestate = INV_PROCEEDING; 14532 ast_setstate(c, AST_STATE_RING); 14533 if (strcmp(p->exten, ast_pickup_ext())) { /* Call to extension -start pbx on this call */ 14534 enum ast_pbx_result res; 14535 14536 res = ast_pbx_start(c); 14537 14538 switch(res) { 14539 case AST_PBX_FAILED: 14540 ast_log(LOG_WARNING, "Failed to start PBX :(\n"); 14541 p->invitestate = INV_COMPLETED; 14542 if (ast_test_flag(req, SIP_PKT_IGNORE)) 14543 transmit_response(p, "503 Unavailable", req); 14544 else 14545 transmit_response_reliable(p, "503 Unavailable", req); 14546 break; 14547 case AST_PBX_CALL_LIMIT: 14548 ast_log(LOG_WARNING, "Failed to start PBX (call limit reached) \n"); 14549 p->invitestate = INV_COMPLETED; 14550 if (ast_test_flag(req, SIP_PKT_IGNORE)) 14551 transmit_response(p, "480 Temporarily Unavailable", req); 14552 else 14553 transmit_response_reliable(p, "480 Temporarily Unavailable", req); 14554 break; 14555 case AST_PBX_SUCCESS: 14556 /* nothing to do */ 14557 break; 14558 } 14559 14560 if (res) { 14561 14562 /* Unlock locks so ast_hangup can do its magic */ 14563 ast_mutex_unlock(&c->lock); 14564 ast_mutex_unlock(&p->lock); 14565 ast_hangup(c); 14566 ast_mutex_lock(&p->lock); 14567 c = NULL; 14568 } 14569 } else { /* Pickup call in call group */ 14570 ast_channel_unlock(c); 14571 *nounlock = 1; 14572 if (ast_pickup_call(c)) { 14573 ast_log(LOG_NOTICE, "Nothing to pick up for %s\n", p->callid); 14574 if (ast_test_flag(req, SIP_PKT_IGNORE)) 14575 transmit_response(p, "503 Unavailable", req); /* OEJ - Right answer? */ 14576 else 14577 transmit_response_reliable(p, "503 Unavailable", req); 14578 sip_alreadygone(p); 14579 /* Unlock locks so ast_hangup can do its magic */ 14580 ast_mutex_unlock(&p->lock); 14581 c->hangupcause = AST_CAUSE_CALL_REJECTED; 14582 } else { 14583 ast_mutex_unlock(&p->lock); 14584 ast_setstate(c, AST_STATE_DOWN); 14585 c->hangupcause = AST_CAUSE_NORMAL_CLEARING; 14586 } 14587 p->invitestate = INV_COMPLETED; 14588 ast_hangup(c); 14589 ast_mutex_lock(&p->lock); 14590 c = NULL; 14591 } 14592 break; 14593 case AST_STATE_RING: 14594 transmit_response(p, "100 Trying", req); 14595 p->invitestate = INV_PROCEEDING; 14596 break; 14597 case AST_STATE_RINGING: 14598 transmit_response(p, "180 Ringing", req); 14599 p->invitestate = INV_PROCEEDING; 14600 break; 14601 case AST_STATE_UP: 14602 if (option_debug > 1) 14603 ast_log(LOG_DEBUG, "%s: This call is UP.... \n", c->name); 14604 14605 transmit_response(p, "100 Trying", req); 14606 14607 if (p->t38.state == T38_PEER_REINVITE) { 14608 struct ast_channel *bridgepeer = NULL; 14609 struct sip_pvt *bridgepvt = NULL; 14610 14611 if ((bridgepeer = ast_bridged_channel(p->owner))) { 14612 /* We have a bridge, and this is re-invite to switchover to T38 so we send re-invite with T38 SDP, to other side of bridge*/ 14613 /*! XXX: we should also check here does the other side supports t38 at all !!! XXX */ 14614 if (bridgepeer->tech == &sip_tech || bridgepeer->tech == &sip_tech_info) { 14615 bridgepvt = (struct sip_pvt*)bridgepeer->tech_pvt; 14616 if (bridgepvt->t38.state == T38_DISABLED) { 14617 if (bridgepvt->udptl) { /* If everything is OK with other side's udptl struct */ 14618 /* Send re-invite to the bridged channel */ 14619 sip_handle_t38_reinvite(bridgepeer, p, 1); 14620 } else { /* Something is wrong with peers udptl struct */ 14621 ast_log(LOG_WARNING, "Strange... The other side of the bridge don't have udptl struct\n"); 14622 ast_mutex_lock(&bridgepvt->lock); 14623 bridgepvt->t38.state = T38_DISABLED; 14624 ast_mutex_unlock(&bridgepvt->lock); 14625 if (option_debug > 1) 14626 ast_log(LOG_DEBUG,"T38 state changed to %d on channel %s\n", bridgepvt->t38.state, bridgepeer->name); 14627 if (ast_test_flag(req, SIP_PKT_IGNORE)) 14628 transmit_response(p, "488 Not acceptable here", req); 14629 else 14630 transmit_response_reliable(p, "488 Not acceptable here", req); 14631 14632 } 14633 } else { 14634 /* The other side is already setup for T.38 most likely so we need to acknowledge this too */ 14635 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 14636 transmit_response_with_t38_sdp(p, "200 OK", req, XMIT_CRITICAL); 14637 p->t38.state = T38_ENABLED; 14638 if (option_debug) 14639 ast_log(LOG_DEBUG, "T38 state changed to %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "<none>"); 14640 } 14641 } else { 14642 /* Other side is not a SIP channel */ 14643 if (ast_test_flag(req, SIP_PKT_IGNORE)) 14644 transmit_response(p, "488 Not acceptable here", req); 14645 else 14646 transmit_response_reliable(p, "488 Not acceptable here", req); 14647 p->t38.state = T38_DISABLED; 14648 if (option_debug > 1) 14649 ast_log(LOG_DEBUG,"T38 state changed to %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "<none>"); 14650 14651 if (!p->lastinvite) /* Only destroy if this is *not* a re-invite */ 14652 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 14653 } 14654 } else { 14655 /* we are not bridged in a call */ 14656 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 14657 transmit_response_with_t38_sdp(p, "200 OK", req, XMIT_CRITICAL); 14658 p->t38.state = T38_ENABLED; 14659 if (option_debug) 14660 ast_log(LOG_DEBUG,"T38 state changed to %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "<none>"); 14661 } 14662 } else if (p->t38.state == T38_DISABLED) { /* Channel doesn't have T38 offered or enabled */ 14663 int sendok = TRUE; 14664 14665 /* If we are bridged to a channel that has T38 enabled than this is a case of RTP re-invite after T38 session */ 14666 /* so handle it here (re-invite other party to RTP) */ 14667 struct ast_channel *bridgepeer = NULL; 14668 struct sip_pvt *bridgepvt = NULL; 14669 if ((bridgepeer = ast_bridged_channel(p->owner))) { 14670 if ((bridgepeer->tech == &sip_tech || bridgepeer->tech == &sip_tech_info) && !ast_check_hangup(bridgepeer)) { 14671 bridgepvt = (struct sip_pvt*)bridgepeer->tech_pvt; 14672 /* Does the bridged peer have T38 ? */ 14673 if (bridgepvt->t38.state == T38_ENABLED) { 14674 ast_log(LOG_WARNING, "RTP re-invite after T38 session not handled yet !\n"); 14675 /* Insted of this we should somehow re-invite the other side of the bridge to RTP */ 14676 if (ast_test_flag(req, SIP_PKT_IGNORE)) 14677 transmit_response(p, "488 Not Acceptable Here (unsupported)", req); 14678 else 14679 transmit_response_reliable(p, "488 Not Acceptable Here (unsupported)", req); 14680 sendok = FALSE; 14681 } 14682 /* No bridged peer with T38 enabled*/ 14683 } 14684 } 14685 /* Respond to normal re-invite */ 14686 if (sendok) { 14687 /* If this is not a re-invite or something to ignore - it's critical */ 14688 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 14689 transmit_response_with_sdp(p, "200 OK", req, (reinvite ? XMIT_RELIABLE : (ast_test_flag(req, SIP_PKT_IGNORE) ? XMIT_UNRELIABLE : XMIT_CRITICAL))); 14690 } 14691 } 14692 p->invitestate = INV_TERMINATED; 14693 break; 14694 default: 14695 ast_log(LOG_WARNING, "Don't know how to handle INVITE in state %d\n", c->_state); 14696 transmit_response(p, "100 Trying", req); 14697 break; 14698 } 14699 } else { 14700 if (p && (p->autokillid == -1)) { 14701 const char *msg; 14702 14703 if (!p->jointcapability) 14704 msg = "488 Not Acceptable Here (codec error)"; 14705 else { 14706 ast_log(LOG_NOTICE, "Unable to create/find SIP channel for this INVITE\n"); 14707 msg = "503 Unavailable"; 14708 } 14709 if (ast_test_flag(req, SIP_PKT_IGNORE)) 14710 transmit_response(p, msg, req); 14711 else 14712 transmit_response_reliable(p, msg, req); 14713 p->invitestate = INV_COMPLETED; 14714 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 14715 } 14716 } 14717 return res; 14718 }
| static int handle_request_message | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Handle incoming MESSAGE request.
Definition at line 15340 of file chan_sip.c.
References ast_test_flag, ast_verbose(), receive_message(), SIP_PKT_DEBUG, SIP_PKT_IGNORE, and transmit_response().
Referenced by handle_request().
15341 { 15342 if (!ast_test_flag(req, SIP_PKT_IGNORE)) { 15343 if (ast_test_flag(req, SIP_PKT_DEBUG)) 15344 ast_verbose("Receiving message!\n"); 15345 receive_message(p, req); 15346 } else 15347 transmit_response(p, "202 Accepted", req); 15348 return 1; 15349 }
| static int handle_request_notify | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| struct sockaddr_in * | sin, | |||
| int | seqno, | |||
| char * | e | |||
| ) | [static] |
Handle incoming notifications.
Definition at line 13558 of file chan_sip.c.
References ast_log(), ast_skip_blanks(), sip_pvt::callid, DEFAULT_TRANS_TIMEOUT, FALSE, get_header(), get_msg_text(), sip_pvt::lastinvite, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, option_debug, sip_scheddestroy(), sipdebug, transmit_response(), and TRUE.
Referenced by handle_request().
13559 { 13560 /* This is mostly a skeleton for future improvements */ 13561 /* Mostly created to return proper answers on notifications on outbound REFER's */ 13562 int res = 0; 13563 const char *event = get_header(req, "Event"); 13564 char *eventid = NULL; 13565 char *sep; 13566 13567 if( (sep = strchr(event, ';')) ) { /* XXX bug here - overwriting string ? */ 13568 *sep++ = '\0'; 13569 eventid = sep; 13570 } 13571 13572 if (option_debug > 1 && sipdebug) 13573 ast_log(LOG_DEBUG, "Got NOTIFY Event: %s\n", event); 13574 13575 if (strcmp(event, "refer")) { 13576 /* We don't understand this event. */ 13577 /* Here's room to implement incoming voicemail notifications :-) */ 13578 transmit_response(p, "489 Bad event", req); 13579 res = -1; 13580 } else { 13581 /* Save nesting depth for now, since there might be other events we will 13582 support in the future */ 13583 13584 /* Handle REFER notifications */ 13585 13586 char buf[1024]; 13587 char *cmd, *code; 13588 int respcode; 13589 int success = TRUE; 13590 13591 /* EventID for each transfer... EventID is basically the REFER cseq 13592 13593 We are getting notifications on a call that we transfered 13594 We should hangup when we are getting a 200 OK in a sipfrag 13595 Check if we have an owner of this event */ 13596 13597 /* Check the content type */ 13598 if (strncasecmp(get_header(req, "Content-Type"), "message/sipfrag", strlen("message/sipfrag"))) { 13599 /* We need a sipfrag */ 13600 transmit_response(p, "400 Bad request", req); 13601 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 13602 return -1; 13603 } 13604 13605 /* Get the text of the attachment */ 13606 if (get_msg_text(buf, sizeof(buf), req)) { 13607 ast_log(LOG_WARNING, "Unable to retrieve attachment from NOTIFY %s\n", p->callid); 13608 transmit_response(p, "400 Bad request", req); 13609 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 13610 return -1; 13611 } 13612 13613 /* 13614 From the RFC... 13615 A minimal, but complete, implementation can respond with a single 13616 NOTIFY containing either the body: 13617 SIP/2.0 100 Trying 13618 13619 if the subscription is pending, the body: 13620 SIP/2.0 200 OK 13621 if the reference was successful, the body: 13622 SIP/2.0 503 Service Unavailable 13623 if the reference failed, or the body: 13624 SIP/2.0 603 Declined 13625 13626 if the REFER request was accepted before approval to follow the 13627 reference could be obtained and that approval was subsequently denied 13628 (see Section 2.4.7). 13629 13630 If there are several REFERs in the same dialog, we need to 13631 match the ID of the event header... 13632 */ 13633 if (option_debug > 2) 13634 ast_log(LOG_DEBUG, "* SIP Transfer NOTIFY Attachment: \n---%s\n---\n", buf); 13635 cmd = ast_skip_blanks(buf); 13636 code = cmd; 13637 /* We are at SIP/2.0 */ 13638 while(*code && (*code > 32)) { /* Search white space */ 13639 code++; 13640 } 13641 *code++ = '\0'; 13642 code = ast_skip_blanks(code); 13643 sep = code; 13644 sep++; 13645 while(*sep && (*sep > 32)) { /* Search white space */ 13646 sep++; 13647 } 13648 *sep++ = '\0'; /* Response string */ 13649 respcode = atoi(code); 13650 switch (respcode) { 13651 case 100: /* Trying: */ 13652 case 101: /* dialog establishment */ 13653 /* Don't do anything yet */ 13654 break; 13655 case 183: /* Ringing: */ 13656 /* Don't do anything yet */ 13657 break; 13658 case 200: /* OK: The new call is up, hangup this call */ 13659 /* Hangup the call that we are replacing */ 13660 break; 13661 case 301: /* Moved permenantly */ 13662 case 302: /* Moved temporarily */ 13663 /* Do we get the header in the packet in this case? */ 13664 success = FALSE; 13665 break; 13666 case 503: /* Service Unavailable: The new call failed */ 13667 /* Cancel transfer, continue the call */ 13668 success = FALSE; 13669 break; 13670 case 603: /* Declined: Not accepted */ 13671 /* Cancel transfer, continue the current call */ 13672 success = FALSE; 13673 break; 13674 } 13675 if (!success) { 13676 ast_log(LOG_NOTICE, "Transfer failed. Sorry. Nothing further to do with this call\n"); 13677 } 13678 13679 /* Confirm that we received this packet */ 13680 transmit_response(p, "200 OK", req); 13681 }; 13682 13683 if (!p->lastinvite) 13684 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 13685 13686 return res; 13687 }
| static int handle_request_options | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Handle incoming OPTIONS request.
Definition at line 13690 of file chan_sip.c.
References ast_shutting_down(), ast_string_field_set, ast_strlen_zero(), build_contact(), domain::context, sip_pvt::context, DEFAULT_TRANS_TIMEOUT, get_destination(), sip_pvt::lastinvite, sip_scheddestroy(), and transmit_response_with_allow().
Referenced by handle_request().
13691 { 13692 int res; 13693 13694 13695 /* XXX Should we authenticate OPTIONS? XXX */ 13696 13697 if (p->lastinvite) { 13698 /* if this is a request in an active dialog, just confirm that the dialog exists. */ 13699 transmit_response_with_allow(p, "200 OK", req, 0); 13700 return 0; 13701 } 13702 13703 res = get_destination(p, req); 13704 build_contact(p); 13705 13706 if (ast_strlen_zero(p->context)) 13707 ast_string_field_set(p, context, default_context); 13708 13709 if (ast_shutting_down()) 13710 transmit_response_with_allow(p, "503 Unavailable", req, 0); 13711 else if (res < 0) 13712 transmit_response_with_allow(p, "404 Not Found", req, 0); 13713 else 13714 transmit_response_with_allow(p, "200 OK", req, 0); 13715 13716 /* Destroy if this OPTIONS was the opening request, but not if 13717 it's in the middle of a normal call flow. */ 13718 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 13719 13720 return res; 13721 }
| static int handle_request_refer | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| int | debug, | |||
| int | ignore, | |||
| int | seqno, | |||
| int * | nounlock | |||
| ) | [static] |
Definition at line 14886 of file chan_sip.c.
References sip_pvt::allowtransfer, append_history, ast_async_goto(), ast_bridged_channel(), AST_CAUSE_NORMAL_CLEARING, ast_channel_unlock, ast_clear_flag, AST_CONTROL_UNHOLD, AST_LIST_EMPTY, ast_log(), ast_parking_ext(), ast_queue_control(), ast_set_flag, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_verbose(), sip_refer::attendedtransfer, sip_pvt::callid, sip_dual::chan1, sip_dual::chan2, check_sip_domain(), domain::context, sip_pvt::context, copy_request(), FALSE, sip_pvt::flags, get_refer_info(), ast_channel::hangupcause, local_attended_transfer(), sip_refer::localtransfer, LOG_DEBUG, ast_channel::name, option_debug, sip_pvt::owner, pbx_builtin_setvar_helper(), sip_pvt::refer, REFER_200OK, REFER_FAILED, REFER_SENT, sip_refer::refer_to, sip_refer::refer_to_context, sip_refer::refer_to_domain, sip_refer::referred_by, sip_refer::replaces_callid, sip_refer::replaces_callid_fromtag, sip_refer::replaces_callid_totag, sip_dual::req, sip_alreadygone(), SIP_DEFER_BYE_ON_TRANSFER, SIP_GOTREFER, SIP_NEEDDESTROY, SIP_OUTGOING, sip_park(), SIP_PKT_DEBUG, SIP_PKT_IGNORE, sip_refer_allocate(), SIPBUFSIZE, sipdebug, sip_refer::status, TRANSFER_CLOSED, transmit_notify_with_sipfrag(), transmit_response(), and TRUE.
Referenced by handle_request().
14887 { 14888 struct sip_dual current; /* Chan1: Call between asterisk and transferer */ 14889 /* Chan2: Call between asterisk and transferee */ 14890 14891 int res = 0; 14892 14893 if (ast_test_flag(req, SIP_PKT_DEBUG)) 14894 ast_verbose("Call %s got a SIP call transfer from %s: (REFER)!\n", p->callid, ast_test_flag(&p->flags[0], SIP_OUTGOING) ? "callee" : "caller"); 14895 14896 if (!p->owner) { 14897 /* This is a REFER outside of an existing SIP dialog */ 14898 /* We can't handle that, so decline it */ 14899 if (option_debug > 2) 14900 ast_log(LOG_DEBUG, "Call %s: Declined REFER, outside of dialog...\n", p->callid); 14901 transmit_response(p, "603 Declined (No dialog)", req); 14902 if (!ast_test_flag(req, SIP_PKT_IGNORE)) { 14903 append_history(p, "Xfer", "Refer failed. Outside of dialog."); 14904 sip_alreadygone(p); 14905 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 14906 } 14907 return 0; 14908 } 14909 14910 14911 /* Check if transfer is allowed from this device */ 14912 if (p->allowtransfer == TRANSFER_CLOSED ) { 14913 /* Transfer not allowed, decline */ 14914 transmit_response(p, "603 Declined (policy)", req); 14915 append_history(p, "Xfer", "Refer failed. Allowtransfer == closed."); 14916 /* Do not destroy SIP session */ 14917 return 0; 14918 } 14919 14920 if(!ignore && ast_test_flag(&p->flags[0], SIP_GOTREFER)) { 14921 /* Already have a pending REFER */ 14922 transmit_response(p, "491 Request pending", req); 14923 append_history(p, "Xfer", "Refer failed. Request pending."); 14924 return 0; 14925 } 14926 14927 /* Allocate memory for call transfer data */ 14928 if (!p->refer && !sip_refer_allocate(p)) { 14929 transmit_response(p, "500 Internal Server Error", req); 14930 append_history(p, "Xfer", "Refer failed. Memory allocation error."); 14931 return -3; 14932 } 14933 14934 res = get_refer_info(p, req); /* Extract headers */ 14935 14936 p->refer->status = REFER_SENT; 14937 14938 if (res != 0) { 14939 switch (res) { 14940 case -2: /* Syntax error */ 14941 transmit_response(p, "400 Bad Request (Refer-to missing)", req); 14942 append_history(p, "Xfer", "Refer failed. Refer-to missing."); 14943 if (ast_test_flag(req, SIP_PKT_DEBUG) && option_debug) 14944 ast_log(LOG_DEBUG, "SIP transfer to black hole can't be handled (no refer-to: )\n"); 14945 break; 14946 case -3: 14947 transmit_response(p, "603 Declined (Non sip: uri)", req); 14948 append_history(p, "Xfer", "Refer failed. Non SIP uri"); 14949 if (ast_test_flag(req, SIP_PKT_DEBUG) && option_debug) 14950 ast_log(LOG_DEBUG, "SIP transfer to non-SIP uri denied\n"); 14951 break; 14952 default: 14953 /* Refer-to extension not found, fake a failed transfer */ 14954 transmit_response(p, "202 Accepted", req); 14955 append_history(p, "Xfer", "Refer failed. Bad extension."); 14956 transmit_notify_with_sipfrag(p, seqno, "404 Not found", TRUE); 14957 ast_clear_flag(&p->flags[0], SIP_GOTREFER); 14958 if (ast_test_flag(req, SIP_PKT_DEBUG) && option_debug) 14959 ast_log(LOG_DEBUG, "SIP transfer to bad extension: %s\n", p->refer->refer_to); 14960 break; 14961 } 14962 return 0; 14963 } 14964 if (ast_strlen_zero(p->context)) 14965 ast_string_field_set(p, context, default_context); 14966 14967 /* If we do not support SIP domains, all transfers are local */ 14968 if (allow_external_domains && check_sip_domain(p->refer->refer_to_domain, NULL, 0)) { 14969 p->refer->localtransfer = 1; 14970 if (sipdebug && option_debug > 2) 14971 ast_log(LOG_DEBUG, "This SIP transfer is local : %s\n", p->refer->refer_to_domain); 14972 } else if (AST_LIST_EMPTY(&domain_list) || check_sip_domain(p->refer->refer_to_domain, NULL, 0)) { 14973 /* This PBX doesn't bother with SIP domains or domain is local, so this transfer is local */ 14974 p->refer->localtransfer = 1; 14975 } else if (sipdebug && option_debug > 2) 14976 ast_log(LOG_DEBUG, "This SIP transfer is to a remote SIP extension (remote domain %s)\n", p->refer->refer_to_domain); 14977 14978 /* Is this a repeat of a current request? Ignore it */ 14979 /* Don't know what else to do right now. */ 14980 if (ignore) 14981 return res; 14982 14983 /* If this is a blind transfer, we have the following 14984 channels to work with: 14985 - chan1, chan2: The current call between transferer and transferee (2 channels) 14986 - target_channel: A new call from the transferee to the target (1 channel) 14987 We need to stay tuned to what happens in order to be able 14988 to bring back the call to the transferer */ 14989 14990 /* If this is a attended transfer, we should have all call legs within reach: 14991 - chan1, chan2: The call between the transferer and transferee (2 channels) 14992 - target_channel, targetcall_pvt: The call between the transferer and the target (2 channels) 14993 We want to bridge chan2 with targetcall_pvt! 14994 14995 The replaces call id in the refer message points 14996 to the call leg between Asterisk and the transferer. 14997 So we need to connect the target and the transferee channel 14998 and hangup the two other channels silently 14999 15000 If the target is non-local, the call ID could be on a remote 15001 machine and we need to send an INVITE with replaces to the 15002 target. We basically handle this as a blind transfer 15003 and let the sip_call function catch that we need replaces 15004 header in the INVITE. 15005 */ 15006 15007 15008 /* Get the transferer's channel */ 15009 current.chan1 = p->owner; 15010 15011 /* Find the other part of the bridge (2) - transferee */ 15012 current.chan2 = ast_bridged_channel(current.chan1); 15013 15014 if (sipdebug && option_debug > 2) 15015 ast_log(LOG_DEBUG, "SIP %s transfer: Transferer channel %s, transferee channel %s\n", p->refer->attendedtransfer ? "attended" : "blind", current.chan1->name, current.chan2 ? current.chan2->name : "<none>"); 15016 15017 if (!current.chan2 && !p->refer->attendedtransfer) { 15018 /* No bridged channel, propably IVR or echo or similar... */ 15019 /* Guess we should masquerade or something here */ 15020 /* Until we figure it out, refuse transfer of such calls */ 15021 if (sipdebug && option_debug > 2) 15022 ast_log(LOG_DEBUG,"Refused SIP transfer on non-bridged channel.\n"); 15023 p->refer->status = REFER_FAILED; 15024 append_history(p, "Xfer", "Refer failed. Non-bridged channel."); 15025 transmit_response(p, "603 Declined", req); 15026 return -1; 15027 } 15028 15029 if (current.chan2) { 15030 if (sipdebug && option_debug > 3) 15031 ast_log(LOG_DEBUG, "Got SIP transfer, applying to bridged peer '%s'\n", current.chan2->name); 15032 15033 ast_queue_control(current.chan1, AST_CONTROL_UNHOLD); 15034 } 15035 15036 ast_set_flag(&p->flags[0], SIP_GOTREFER); 15037 15038 /* Attended transfer: Find all call legs and bridge transferee with target*/ 15039 if (p->refer->attendedtransfer) { 15040 if ((res = local_attended_transfer(p, ¤t, req, seqno))) 15041 return res; /* We're done with the transfer */ 15042 /* Fall through for remote transfers that we did not find locally */ 15043 if (sipdebug && option_debug > 3) 15044 ast_log(LOG_DEBUG, "SIP attended transfer: Still not our call - generating INVITE with replaces\n"); 15045 /* Fallthrough if we can't find the call leg internally */ 15046 } 15047 15048 15049 /* Parking a call */ 15050 if (p->refer->localtransfer && !strcmp(p->refer->refer_to, ast_parking_ext())) { 15051 /* Must release c's lock now, because it will not longer be accessible after the transfer! */ 15052 *nounlock = 1; 15053 ast_channel_unlock(current.chan1); 15054 copy_request(¤t.req, req); 15055 ast_clear_flag(&p->flags[0], SIP_GOTREFER); 15056 p->refer->status = REFER_200OK; 15057 append_history(p, "Xfer", "REFER to call parking."); 15058 if (sipdebug && option_debug > 3) 15059 ast_log(LOG_DEBUG, "SIP transfer to parking: trying to park %s. Parked by %s\n", current.chan2->name, current.chan1->name); 15060 sip_park(current.chan2, current.chan1, req, seqno); 15061 return res; 15062 } 15063 15064 /* Blind transfers and remote attended xfers */ 15065 transmit_response(p, "202 Accepted", req); 15066 15067 if (current.chan1 && current.chan2) { 15068 if (option_debug > 2) 15069 ast_log(LOG_DEBUG, "chan1->name: %s\n", current.chan1->name); 15070 pbx_builtin_setvar_helper(current.chan1, "BLINDTRANSFER", current.chan2->name); 15071 } 15072 if (current.chan2) { 15073 pbx_builtin_setvar_helper(current.chan2, "BLINDTRANSFER", current.chan1->name); 15074 pbx_builtin_setvar_helper(current.chan2, "SIPDOMAIN", p->refer->refer_to_domain); 15075 pbx_builtin_setvar_helper(current.chan2, "SIPTRANSFER", "yes"); 15076 /* One for the new channel */ 15077 pbx_builtin_setvar_helper(current.chan2, "_SIPTRANSFER", "yes"); 15078 /* Attended transfer to remote host, prepare headers for the INVITE */ 15079 if (p->refer->referred_by) 15080 pbx_builtin_setvar_helper(current.chan2, "_SIPTRANSFER_REFERER", p->refer->referred_by); 15081 } 15082 /* Generate a Replaces string to be used in the INVITE during attended transfer */ 15083 if (p->refer->replaces_callid && !ast_strlen_zero(p->refer->replaces_callid)) { 15084 char tempheader[SIPBUFSIZE]; 15085 snprintf(tempheader, sizeof(tempheader), "%s%s%s%s%s", p->refer->replaces_callid, 15086 p->refer->replaces_callid_totag ? ";to-tag=" : "", 15087 p->refer->replaces_callid_totag, 15088 p->refer->replaces_callid_fromtag ? ";from-tag=" : "", 15089 p->refer->replaces_callid_fromtag); 15090 if (current.chan2) 15091 pbx_builtin_setvar_helper(current.chan2, "_SIPTRANSFER_REPLACES", tempheader); 15092 } 15093 /* Must release lock now, because it will not longer 15094 be accessible after the transfer! */ 15095 *nounlock = 1; 15096 ast_channel_unlock(current.chan1); 15097 15098 /* Connect the call */ 15099 15100 /* FAKE ringing if not attended transfer */ 15101 if (!p->refer->attendedtransfer) 15102 transmit_notify_with_sipfrag(p, seqno, "183 Ringing", FALSE); 15103 15104 /* For blind transfer, this will lead to a new call */ 15105 /* For attended transfer to remote host, this will lead to 15106 a new SIP call with a replaces header, if the dial plan allows it 15107 */ 15108 if (!current.chan2) { 15109 /* We have no bridge, so we're talking with Asterisk somehow */ 15110 /* We need to masquerade this call */ 15111 /* What to do to fix this situation: 15112 * Set up the new call in a new channel 15113 * Let the new channel masq into this channel 15114 Please add that code here :-) 15115 */ 15116 p->refer->status = REFER_FAILED; 15117 transmit_notify_with_sipfrag(p, seqno, "503 Service Unavailable (can't handle one-legged xfers)", TRUE); 15118 ast_clear_flag(&p->flags[0], SIP_GOTREFER); 15119 append_history(p, "Xfer", "Refer failed (only bridged calls)."); 15120 return -1; 15121 } 15122 ast_set_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER); /* Delay hangup */ 15123 15124 /* For blind transfers, move the call to the new extensions. For attended transfers on multiple 15125 servers - generate an INVITE with Replaces. Either way, let the dial plan decided */ 15126 res = ast_async_goto(current.chan2, p->refer->refer_to_context, p->refer->refer_to, 1); 15127 15128 if (!res) { 15129 /* Success - we have a new channel */ 15130 if (option_debug > 2) 15131 ast_log(LOG_DEBUG, "%s transfer succeeded. Telling transferer.\n", p->refer->attendedtransfer? "Attended" : "Blind"); 15132 transmit_notify_with_sipfrag(p, seqno, "200 Ok", TRUE); 15133 if (p->refer->localtransfer) 15134 p->refer->status = REFER_200OK; 15135 if (p->owner) 15136 p->owner->hangupcause = AST_CAUSE_NORMAL_CLEARING; 15137 append_history(p, "Xfer", "Refer succeeded."); 15138 ast_clear_flag(&p->flags[0], SIP_GOTREFER); 15139 /* Do not hangup call, the other side do that when we say 200 OK */ 15140 /* We could possibly implement a timer here, auto congestion */ 15141 res = 0; 15142 } else { 15143 ast_clear_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER); /* Don't delay hangup */ 15144 if (option_debug > 2) 15145 ast_log(LOG_DEBUG, "%s transfer failed. Resuming original call.\n", p->refer->attendedtransfer? "Attended" : "Blind"); 15146 append_history(p, "Xfer", "Refer failed."); 15147 /* Failure of some kind */ 15148 p->refer->status = REFER_FAILED; 15149 transmit_notify_with_sipfrag(p, seqno, "503 Service Unavailable", TRUE); 15150 ast_clear_flag(&p->flags[0], SIP_GOTREFER); 15151 res = -1; 15152 } 15153 return res; 15154 }
| static int handle_request_register | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| struct sockaddr_in * | sin, | |||
| char * | e | |||
| ) | [static] |
Handle incoming REGISTER request.
Definition at line 15649 of file chan_sip.c.
References append_history, ast_inet_ntoa(), ast_log(), ast_test_flag, ast_verbose(), AUTH_ACL_FAILED, AUTH_NOT_FOUND, AUTH_PEER_NOT_DYNAMIC, AUTH_SECRET_FAILED, AUTH_UNKNOWN_DOMAIN, AUTH_USERNAME_MISMATCH, check_via(), copy_request(), DEFAULT_TRANS_TIMEOUT, get_header(), sip_pvt::initreq, LOG_NOTICE, register_verify(), SIP_PKT_DEBUG, and sip_scheddestroy().
Referenced by handle_request().
15650 { 15651 enum check_auth_result res; 15652 15653 /* Use this as the basis */ 15654 if (ast_test_flag(req, SIP_PKT_DEBUG)) 15655 ast_verbose("Using latest REGISTER request as basis request\n"); 15656 copy_request(&p->initreq, req); 15657 check_via(p, req); 15658 if ((res = register_verify(p, sin, req, e)) < 0) { 15659 const char *reason; 15660 15661 switch (res) { 15662 case AUTH_SECRET_FAILED: 15663 reason = "Wrong password"; 15664 break; 15665 case AUTH_USERNAME_MISMATCH: 15666 reason = "Username/auth name mismatch"; 15667 break; 15668 case AUTH_NOT_FOUND: 15669 reason = "No matching peer found"; 15670 break; 15671 case AUTH_UNKNOWN_DOMAIN: 15672 reason = "Not a local domain"; 15673 break; 15674 case AUTH_PEER_NOT_DYNAMIC: 15675 reason = "Peer is not supposed to register"; 15676 break; 15677 case AUTH_ACL_FAILED: 15678 reason = "Device does not match ACL"; 15679 break; 15680 default: 15681 reason = "Unknown failure"; 15682 break; 15683 } 15684 ast_log(LOG_NOTICE, "Registration from '%s' failed for '%s' - %s\n", 15685 get_header(req, "To"), ast_inet_ntoa(sin->sin_addr), 15686 reason); 15687 append_history(p, "RegRequest", "Failed : Account %s : %s", get_header(req, "To"), reason); 15688 } else 15689 append_history(p, "RegRequest", "Succeeded : Account %s", get_header(req, "To")); 15690 15691 if (res < 1) { 15692 /* Destroy the session, but keep us around for just a bit in case they don't 15693 get our 200 OK */ 15694 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 15695 } 15696 return res; 15697 }
| static int handle_request_subscribe | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| struct sockaddr_in * | sin, | |||
| int | seqno, | |||
| char * | e | |||
| ) | [static] |
Handle incoming SUBSCRIBE request.
Definition at line 15352 of file chan_sip.c.
References append_history, AST_EXTENSION_REMOVED, ast_extension_state(), ast_extension_state2str(), ast_extension_state_add(), ast_extension_state_del(), ast_inet_ntoa(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_set_flag, ast_strdupa, ast_string_field_build, ast_strlen_zero(), ast_test_flag, ast_verbose(), ASTOBJ_REF, ASTOBJ_UNLOCK, ASTOBJ_UNREF, ASTOBJ_WRLOCK, AUTH_CHALLENGE_SENT, AUTH_FAKE_AUTH, sip_pvt::autokillid, build_contact(), sip_pvt::callid, cb_extensionstate(), check_user_full(), check_via(), sip_pvt::context, copy_request(), CPIM_PIDF_XML, DIALOG_INFO_XML, sip_pvt::dialogver, sip_pvt::expiry, sip_pvt::exten, FALSE, sip_pvt::flags, get_destination(), get_header(), gettag(), sip_request::headers, iflist, iflock, sip_pvt::initreq, sip_pvt::lastinvite, sip_pvt::laststate, sip_pvt::lock, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, sip_peer::mailbox, make_our_tag(), sip_request::method, MWI_NOTIFICATION, sip_peer::mwipvt, sip_peer::name, sip_pvt::next, NONE, option_debug, parse_ok_contact(), PIDF_XML, sip_pvt::relatedpeer, sip_pvt::sa, sip_cancel_destroy(), sip_destroy(), sip_destroy_peer(), sip_methods, SIP_NEEDDESTROY, SIP_PAGE2_ALLOWSUBSCRIBE, SIP_PAGE2_DIALOG_ESTABLISHED, SIP_PKT_DEBUG, SIP_PKT_IGNORE, sip_scheddestroy(), sip_send_mwi_to_peer(), SIP_SUBSCRIBE, sipdebug, sip_pvt::stateid, sip_pvt::subscribecontext, sip_pvt::subscribed, sip_pvt::subscribeuri, sip_pvt::tag, cfsip_methods::text, transmit_fake_auth_response(), transmit_response(), transmit_response_reliable(), transmit_state_notify(), sip_pvt::useragent, sip_pvt::username, and XPIDF_XML.
Referenced by handle_request().
15353 { 15354 int gotdest; 15355 int res = 0; 15356 int firststate = AST_EXTENSION_REMOVED; 15357 struct sip_peer *authpeer = NULL; 15358 const char *eventheader = get_header(req, "Event"); /* Get Event package name */ 15359 const char *accept = get_header(req, "Accept"); 15360 int resubscribe = (p->subscribed != NONE); 15361 char *temp, *event; 15362 15363 if (p->initreq.headers) { 15364 /* We already have a dialog */ 15365 if (p->initreq.method != SIP_SUBSCRIBE) { 15366 /* This is a SUBSCRIBE within another SIP dialog, which we do not support */ 15367 /* For transfers, this could happen, but since we haven't seen it happening, let us just refuse this */ 15368 transmit_response(p, "403 Forbidden (within dialog)", req); 15369 /* Do not destroy session, since we will break the call if we do */ 15370 if (option_debug) 15371 ast_log(LOG_DEBUG, "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); 15372 return 0; 15373 } else if (ast_test_flag(req, SIP_PKT_DEBUG)) { 15374 if (option_debug) { 15375 if (resubscribe) 15376 ast_log(LOG_DEBUG, "Got a re-subscribe on existing subscription %s\n", p->callid); 15377 else 15378 ast_log(LOG_DEBUG, "Got a new subscription %s (possibly with auth)\n", p->callid); 15379 } 15380 } 15381 } 15382 15383 /* Check if we have a global disallow setting on subscriptions. 15384 if so, we don't have to check peer/user settings after auth, which saves a lot of processing 15385 */ 15386 if (!global_allowsubscribe) { 15387 transmit_response(p, "403 Forbidden (policy)", req); 15388 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 15389 return 0; 15390 } 15391 15392 if (!ast_test_flag(req, SIP_PKT_IGNORE) && !resubscribe) { /* Set up dialog, new subscription */ 15393 const char *to = get_header(req, "To"); 15394 char totag[128]; 15395 15396 /* Check to see if a tag was provided, if so this is actually a resubscription of a dialog we no longer know about */ 15397 if (!ast_strlen_zero(to) && gettag(req, "To", totag, sizeof(totag))) { 15398 if (ast_test_flag(req, SIP_PKT_DEBUG)) 15399 ast_verbose("Received resubscription for a dialog we no longer know about. Telling remote side to subscribe again.\n"); 15400 transmit_response(p, "481 Subscription does not exist", req); 15401 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 15402 return 0; 15403 } 15404 15405 /* Use this as the basis */ 15406 if (ast_test_flag(req, SIP_PKT_DEBUG)) 15407 ast_verbose("Creating new subscription\n"); 15408 15409 copy_request(&p->initreq, req); 15410 check_via(p, req); 15411 } else if (ast_test_flag(req, SIP_PKT_DEBUG) && ast_test_flag(req, SIP_PKT_IGNORE)) 15412 ast_verbose("Ignoring this SUBSCRIBE request\n"); 15413 15414 /* Find parameters to Event: header value and remove them for now */ 15415 if (ast_strlen_zero(eventheader)) { 15416 transmit_response(p, "489 Bad Event", req); 15417 if (option_debug > 1) 15418 ast_log(LOG_DEBUG, "Received SIP subscribe for unknown event package: <none>\n"); 15419 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 15420 return 0; 15421 } 15422 15423 if ( (strchr(eventheader, ';'))) { 15424 event = ast_strdupa(eventheader); /* Since eventheader is a const, we can't change it */ 15425 temp = strchr(event, ';'); 15426 *temp = '\0'; /* Remove any options for now */ 15427 /* We might need to use them later :-) */ 15428 } else 15429 event = (char *) eventheader; /* XXX is this legal ? */ 15430 15431 /* Handle authentication */ 15432 res = check_user_full(p, req, SIP_SUBSCRIBE, e, 0, sin, &authpeer); 15433 /* if an authentication response was sent, we are done here */ 15434 if (res == AUTH_CHALLENGE_SENT) { 15435 if (authpeer) 15436 ASTOBJ_UNREF(authpeer, sip_destroy_peer); 15437 return 0; 15438 } 15439 if (res < 0) { 15440 if (res == AUTH_FAKE_AUTH) { 15441 ast_log(LOG_NOTICE, "Sending fake auth rejection for user %s\n", get_header(req, "From")); 15442 transmit_fake_auth_response(p, req, 1); 15443 } else { 15444 ast_log(LOG_NOTICE, "Failed to authenticate user %s for SUBSCRIBE\n", get_header(req, "From")); 15445 transmit_response_reliable(p, "403 Forbidden", req); 15446 } 15447 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 15448 if (authpeer) 15449 ASTOBJ_UNREF(authpeer, sip_destroy_peer); 15450 return 0; 15451 } 15452 15453 /* Check if this user/peer is allowed to subscribe at all */ 15454 if (!ast_test_flag(&p->flags[1], SIP_PAGE2_ALLOWSUBSCRIBE)) { 15455 transmit_response(p, "403 Forbidden (policy)", req); 15456 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 15457 if (authpeer) 15458 ASTOBJ_UNREF(authpeer, sip_destroy_peer); 15459 return 0; 15460 } 15461 15462 /* Get destination right away */ 15463 gotdest = get_destination(p, NULL); 15464 15465 /* Get full contact header - this needs to be used as a request URI in NOTIFY's */ 15466 parse_ok_contact(p, req); 15467 15468 build_contact(p); 15469 if (gotdest) { 15470 transmit_response(p, "404 Not Found", req); 15471 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 15472 if (authpeer) 15473 ASTOBJ_UNREF(authpeer, sip_destroy_peer); 15474 return 0; 15475 } 15476 15477 /* Initialize tag for new subscriptions */ 15478 if (ast_strlen_zero(p->tag)) 15479 make_our_tag(p->tag, sizeof(p->tag)); 15480 15481 if (!strcmp(event, "presence") || !strcmp(event, "dialog")) { /* Presence, RFC 3842 */ 15482 if (authpeer) /* No need for authpeer here */ 15483 ASTOBJ_UNREF(authpeer, sip_destroy_peer); 15484 15485 /* Header from Xten Eye-beam Accept: multipart/related, application/rlmi+xml, application/pidf+xml, application/xpidf+xml */ 15486 /* Polycom phones only handle xpidf+xml, even if they say they can 15487 handle pidf+xml as well 15488 */ 15489 if (strstr(p->useragent, "Polycom")) { 15490 p->subscribed = XPIDF_XML; 15491 } else if (strstr(accept, "application/pidf+xml")) { 15492 p->subscribed = PIDF_XML; /* RFC 3863 format */ 15493 } else if (strstr(accept, "application/dialog-info+xml")) { 15494 p->subscribed = DIALOG_INFO_XML; 15495 /* IETF draft: draft-ietf-sipping-dialog-package-05.txt */ 15496 } else if (strstr(accept, "application/cpim-pidf+xml")) { 15497 p->subscribed = CPIM_PIDF_XML; /* RFC 3863 format */ 15498 } else if (strstr(accept, "application/xpidf+xml")) { 15499 p->subscribed = XPIDF_XML; /* Early pre-RFC 3863 format with MSN additions (Microsoft Messenger) */ 15500 } else if (ast_strlen_zero(accept)) { 15501 if (p->subscribed == NONE) { /* if the subscribed field is not already set, and there is no accept header... */ 15502 transmit_response(p, "489 Bad Event", req); 15503 15504 ast_log(LOG_WARNING,"SUBSCRIBE failure: no Accept header: pvt: stateid: %d, laststate: %d, dialogver: %d, subscribecont: '%s', subscribeuri: '%s'\n", 15505 p->stateid, p->laststate, p->dialogver, p->subscribecontext, p->subscribeuri); 15506 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 15507 return 0; 15508 } 15509 /* if p->subscribed is non-zero, then accept is not obligatory; according to rfc 3265 section 3.1.3, at least. 15510 so, we'll just let it ride, keeping the value from a previous subscription, and not abort the subscription */ 15511 } else { 15512 /* Can't find a format for events that we know about */ 15513 char mybuf[200]; 15514 snprintf(mybuf,sizeof(mybuf),"489 Bad Event (format %s)", accept); 15515 transmit_response(p, mybuf, req); 15516 15517 ast_log(LOG_WARNING,"SUBSCRIBE failure: unrecognized format: '%s' pvt: subscribed: %d, stateid: %d, laststate: %d, dialogver: %d, subscribecont: '%s', subscribeuri: '%s'\n", 15518 accept, (int)p->subscribed, p->stateid, p->laststate, p->dialogver, p->subscribecontext, p->subscribeuri); 15519 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 15520 return 0; 15521 } 15522 } else if (!strcmp(event, "message-summary")) { 15523 if (!ast_strlen_zero(accept) && strcmp(accept, "application/simple-message-summary")) { 15524 /* Format requested that we do not support */ 15525 transmit_response(p, "406 Not Acceptable", req); 15526 if (option_debug > 1) 15527 ast_log(LOG_DEBUG, "Received SIP mailbox subscription for unknown format: %s\n", accept); 15528 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 15529 if (authpeer) /* No need for authpeer here */ 15530 ASTOBJ_UNREF(authpeer, sip_destroy_peer); 15531 return 0; 15532 } 15533 /* Looks like they actually want a mailbox status 15534 This version of Asterisk supports mailbox subscriptions 15535 The subscribed URI needs to exist in the dial plan 15536 In most devices, this is configurable to the voicemailmain extension you use 15537 */ 15538 if (!authpeer || ast_strlen_zero(authpeer->mailbox)) { 15539 transmit_response(p, "404 Not found (no mailbox)", req); 15540 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 15541 ast_log(LOG_NOTICE, "Received SIP subscribe for peer without mailbox: %s\n", authpeer->name); 15542 if (authpeer) /* No need for authpeer here */ 15543 ASTOBJ_UNREF(authpeer, sip_destroy_peer); 15544 return 0; 15545 } 15546 15547 p->subscribed = MWI_NOTIFICATION; 15548 if (authpeer->mwipvt && authpeer->mwipvt != p) /* Destroy old PVT if this is a new one */ 15549 /* We only allow one subscription per peer */ 15550 sip_destroy(authpeer->mwipvt); 15551 authpeer->mwipvt = p; /* Link from peer to pvt */ 15552 p->relatedpeer = ASTOBJ_REF(authpeer); /* Link from pvt to peer */ 15553 } else { /* At this point, Asterisk does not understand the specified event */ 15554 transmit_response(p, "489 Bad Event", req); 15555 if (option_debug > 1) 15556 ast_log(LOG_DEBUG, "Received SIP subscribe for unknown event package: %s\n", event); 15557 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 15558 if (authpeer) /* No need for authpeer here */ 15559 ASTOBJ_UNREF(authpeer, sip_destroy_peer); 15560 return 0; 15561 } 15562 15563 if (p->subscribed != MWI_NOTIFICATION && !resubscribe) { 15564 if (p->stateid > -1) 15565 ast_extension_state_del(p->stateid, cb_extensionstate); 15566 p->stateid = ast_extension_state_add(p->context, p->exten, cb_extensionstate, p); 15567 } 15568 15569 if (!ast_test_flag(req, SIP_PKT_IGNORE) && p) 15570 p->lastinvite = seqno; 15571 if (p && !ast_test_flag(&p->flags[0], SIP_NEEDDESTROY)) { 15572 p->expiry = atoi(get_header(req, "Expires")); 15573 15574 /* check if the requested expiry-time is within the approved limits from sip.conf */ 15575 if (p->expiry > max_expiry) 15576 p->expiry = max_expiry; 15577 if (p->expiry < min_expiry && p->expiry > 0) 15578 p->expiry = min_expiry; 15579 15580 if (sipdebug || option_debug > 1) { 15581 if (p->subscribed == MWI_NOTIFICATION && p->relatedpeer) 15582 ast_log(LOG_DEBUG, "Adding subscription for mailbox notification - peer %s Mailbox %s\n", p->relatedpeer->name, p->relatedpeer->mailbox); 15583 else 15584 ast_log(LOG_DEBUG, "Adding subscription for extension %s context %s for peer %s\n", p->exten, p->context, p->username); 15585 } 15586 if (p->autokillid > -1 && sip_cancel_destroy(p)) /* Remove subscription expiry for renewals */ 15587 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 15588 if (p->expiry > 0) 15589 sip_scheddestroy(p, (p->expiry + 10) * 1000); /* Set timer for destruction of call at expiration */ 15590 15591 if (p->subscribed == MWI_NOTIFICATION) { 15592 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 15593 transmit_response(p, "200 OK", req); 15594 if (p->relatedpeer) { /* Send first notification */ 15595 ASTOBJ_WRLOCK(p->relatedpeer); 15596 sip_send_mwi_to_peer(p->relatedpeer); 15597 ASTOBJ_UNLOCK(p->relatedpeer); 15598 } 15599 } else { 15600 struct sip_pvt *p_old; 15601 15602 if ((firststate = ast_extension_state(NULL, p->context, p->exten)) < 0) { 15603 15604 ast_log(LOG_NOTICE, "Got SUBSCRIBE for extension %s@%s from %s, but there is no hint for that extension.\n", p->exten, p->context, ast_inet_ntoa(p->sa.sin_addr)); 15605 transmit_response(p, "404 Not found", req); 15606 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 15607 return 0; 15608 } 15609 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 15610 transmit_response(p, "200 OK", req); 15611 transmit_state_notify(p, firststate, 1, FALSE); /* Send first notification */ 15612 append_history(p, "Subscribestatus", "%s", ast_extension_state2str(firststate)); 15613 /* hide the 'complete' exten/context in the refer_to field for later display */ 15614 ast_string_field_build(p, subscribeuri, "%s@%s", p->exten, p->context); 15615 15616 /* remove any old subscription from this peer for the same exten/context, 15617 as the peer has obviously forgotten about it and it's wasteful to wait 15618 for it to expire and send NOTIFY messages to the peer only to have them 15619 ignored (or generate errors) 15620 */ 15621 ast_mutex_lock(&iflock); 15622 for (p_old = iflist; p_old; p_old = p_old->next) { 15623 if (p_old == p) 15624 continue; 15625 if (p_old->initreq.method != SIP_SUBSCRIBE) 15626 continue; 15627 if (p_old->subscribed == NONE) 15628 continue; 15629 ast_mutex_lock(&p_old->lock); 15630 if (!strcmp(p_old->username, p->username)) { 15631 if (!strcmp(p_old->exten, p->exten) && 15632 !strcmp(p_old->context, p->context)) { 15633 ast_set_flag(&p_old->flags[0], SIP_NEEDDESTROY); 15634 ast_mutex_unlock(&p_old->lock); 15635 break; 15636 } 15637 } 15638 ast_mutex_unlock(&p_old->lock); 15639 } 15640 ast_mutex_unlock(&iflock); 15641 } 15642 if (!p->expiry) 15643 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 15644 } 15645 return 1; 15646 }
| static void handle_response | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| char * | rest, | |||
| struct sip_request * | req, | |||
| int | ignore, | |||
| int | seqno | |||
| ) | [static] |
Handle SIP response in dialogue.
Definition at line 12838 of file chan_sip.c.
References __sip_ack(), __sip_semi_ack(), ast_clear_flag, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_PROGRESS, ast_inet_ntoa(), ast_log(), ast_queue_control(), ast_queue_hangup(), ast_set_flag, ast_skip_blanks(), ast_skip_nonblanks(), ast_strdupa, ast_string_field_build, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_verbose(), sip_pvt::authname, sip_pvt::authtries, ast_channel::call_forward, sip_pvt::callid, cb_extensionstate(), sip_pvt::context, do_proxy_auth(), sip_pvt::exten, FALSE, find_sdp(), find_sip_method(), sip_pvt::flags, get_header(), gettag(), handle_response_invite(), handle_response_peerpoke(), handle_response_refer(), handle_response_register(), hangup_sip2cause(), ast_channel::hangupcause, sip_pvt::initreq, sip_pvt::laststate, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, MAX_AUTHTRIES, sip_pvt::method, ast_channel::name, NONE, option_debug, option_verbose, sip_pvt::owner, parse_moved_contact(), sip_pvt::pendinginvite, process_sdp(), sip_pvt::recv, sip_pvt::refer, sip_pvt::registry, sip_pvt::relatedpeer, sip_pvt::sa, SIP_ACK, sip_alreadygone(), SIP_BYE, SIP_CANCEL, sip_cancel_destroy(), SIP_INFO, SIP_INVITE, SIP_MESSAGE, sip_methods, SIP_NEEDDESTROY, SIP_NOTIFY, SIP_OPTIONS, SIP_OUTGOING, SIP_PAGE2_DIALOG_ESTABLISHED, SIP_PAGE2_STATECHANGEQUEUE, SIP_PKT_DEBUG, SIP_PKT_IGNORE, SIP_REFER, SIP_REGISTER, SIP_SUBSCRIBE, sipdebug, stop_media_flows(), sip_pvt::subscribed, text, sip_pvt::theirtag, transmit_request(), sip_pvt::username, VERBOSE_PREFIX_3, and XMIT_UNRELIABLE.
Referenced by handle_request().
12839 { 12840 struct ast_channel *owner; 12841 int sipmethod; 12842 int res = 1; 12843 const char *c = get_header(req, "Cseq"); 12844 /* 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 */ 12845 char *c_copy = ast_strdupa(c); 12846 /* Skip the Cseq and its subsequent spaces */ 12847 const char *msg = ast_skip_blanks(ast_skip_nonblanks(c_copy)); 12848 12849 if (!msg) 12850 msg = ""; 12851 12852 sipmethod = find_sip_method(msg); 12853 12854 owner = p->owner; 12855 if (owner) 12856 owner->hangupcause = hangup_sip2cause(resp); 12857 12858 /* Acknowledge whatever it is destined for */ 12859 if ((resp >= 100) && (resp <= 199)) 12860 __sip_semi_ack(p, seqno, 0, sipmethod); 12861 else 12862 __sip_ack(p, seqno, 0, sipmethod); 12863 12864 /* If this is a NOTIFY for a subscription clear the flag that indicates that we have a NOTIFY pending */ 12865 if (!p->owner && sipmethod == SIP_NOTIFY && p->pendinginvite) 12866 p->pendinginvite = 0; 12867 12868 /* Get their tag if we haven't already */ 12869 if (ast_strlen_zero(p->theirtag) || (resp >= 200)) { 12870 char tag[128]; 12871 12872 gettag(req, "To", tag, sizeof(tag)); 12873 ast_string_field_set(p, theirtag, tag); 12874 } 12875 12876 /* RFC 3261 Section 15 specifies that if we receive a 408 or 481 12877 * in response to a BYE, then we should end the current dialog 12878 * and session. It is known that at least one phone manufacturer 12879 * potentially will send a 404 in response to a BYE, so we'll be 12880 * liberal in what we accept and end the dialog and session if we 12881 * receive any of those responses to a BYE. 12882 */ 12883 if ((resp == 404 || resp == 408 || resp == 481) && sipmethod == SIP_BYE) { 12884 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12885 return; 12886 } 12887 12888 if (p->relatedpeer && p->method == SIP_OPTIONS) { 12889 /* We don't really care what the response is, just that it replied back. 12890 Well, as long as it's not a 100 response... since we might 12891 need to hang around for something more "definitive" */ 12892 if (resp != 100) 12893 handle_response_peerpoke(p, resp, req); 12894 } else if (ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 12895 switch(resp) { 12896 case 100: /* 100 Trying */ 12897 case 101: /* 101 Dialog establishment */ 12898 if (sipmethod == SIP_INVITE) 12899 handle_response_invite(p, resp, rest, req, seqno); 12900 break; 12901 case 183: /* 183 Session Progress */ 12902 if (sipmethod == SIP_INVITE) 12903 handle_response_invite(p, resp, rest, req, seqno); 12904 break; 12905 case 180: /* 180 Ringing */ 12906 if (sipmethod == SIP_INVITE) 12907 handle_response_invite(p, resp, rest, req, seqno); 12908 break; 12909 case 182: /* 182 Queued */ 12910 if (sipmethod == SIP_INVITE) 12911 handle_response_invite(p, resp, rest, req, seqno); 12912 break; 12913 case 200: /* 200 OK */ 12914 p->authtries = 0; /* Reset authentication counter */ 12915 if (sipmethod == SIP_MESSAGE || sipmethod == SIP_INFO) { 12916 /* We successfully transmitted a message 12917 or a video update request in INFO */ 12918 /* Nothing happens here - the message is inside a dialog */ 12919 } else if (sipmethod == SIP_INVITE) { 12920 handle_response_invite(p, resp, rest, req, seqno); 12921 } else if (sipmethod == SIP_NOTIFY) { 12922 /* They got the notify, this is the end */ 12923 if (p->owner) { 12924 if (!p->refer) { 12925 ast_log(LOG_WARNING, "Notify answer on an owned channel? - %s\n", p->owner->name); 12926 ast_queue_hangup(p->owner); 12927 } else if (option_debug > 3) 12928 ast_log(LOG_DEBUG, "Got OK on REFER Notify message\n"); 12929 } else { 12930 if (p->subscribed == NONE) 12931 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12932 if (ast_test_flag(&p->flags[1], SIP_PAGE2_STATECHANGEQUEUE)) { 12933 /* Ready to send the next state we have on queue */ 12934 ast_clear_flag(&p->flags[1], SIP_PAGE2_STATECHANGEQUEUE); 12935 cb_extensionstate((char *)p->context, (char *)p->exten, p->laststate, (void *) p); 12936 } 12937 } 12938 } else if (sipmethod == SIP_REGISTER) 12939 res = handle_response_register(p, resp, rest, req, ignore, seqno); 12940 else if (sipmethod == SIP_BYE) { /* Ok, we're ready to go */ 12941 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12942 ast_clear_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 12943 } else if (sipmethod == SIP_SUBSCRIBE) 12944 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 12945 break; 12946 case 202: /* Transfer accepted */ 12947 if (sipmethod == SIP_REFER) 12948 handle_response_refer(p, resp, rest, req, seqno); 12949 break; 12950 case 401: /* Not www-authorized on SIP method */ 12951 if (sipmethod == SIP_INVITE) 12952 handle_response_invite(p, resp, rest, req, seqno); 12953 else if (sipmethod == SIP_REFER) 12954 handle_response_refer(p, resp, rest, req, seqno); 12955 else if (p->registry && sipmethod == SIP_REGISTER) 12956 res = handle_response_register(p, resp, rest, req, ignore, seqno); 12957 else if (sipmethod == SIP_BYE) { 12958 if (ast_strlen_zero(p->authname)) { 12959 ast_log(LOG_WARNING, "Asked to authenticate %s, to %s:%d but we have no matching peer!\n", 12960 msg, ast_inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port)); 12961 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12962 } else if ((p->authtries == MAX_AUTHTRIES) || do_proxy_auth(p, req, "WWW-Authenticate", "Authorization", sipmethod, 0)) { 12963 ast_log(LOG_NOTICE, "Failed to authenticate on %s to '%s'\n", msg, get_header(&p->initreq, "From")); 12964 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12965 /* We fail to auth bye on our own call, but still needs to tear down the call. 12966 Life, they call it. */ 12967 } 12968 } else { 12969 ast_log(LOG_WARNING, "Got authentication request (401) on unknown %s to '%s'\n", sip_methods[sipmethod].text, get_header(req, "To")); 12970 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12971 } 12972 break; 12973 case 403: /* Forbidden - we failed authentication */ 12974 if (sipmethod == SIP_INVITE) 12975 handle_response_invite(p, resp, rest, req, seqno); 12976 else if (p->registry && sipmethod == SIP_REGISTER) 12977 res = handle_response_register(p, resp, rest, req, ignore, seqno); 12978 else { 12979 ast_log(LOG_WARNING, "Forbidden - maybe wrong password on authentication for %s\n", msg); 12980 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12981 } 12982 break; 12983 case 404: /* Not found */ 12984 if (p->registry && sipmethod == SIP_REGISTER) 12985 res = handle_response_register(p, resp, rest, req, ignore, seqno); 12986 else if (sipmethod == SIP_INVITE) 12987 handle_response_invite(p, resp, rest, req, seqno); 12988 else if (owner) 12989 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 12990 break; 12991 case 407: /* Proxy auth required */ 12992 if (sipmethod == SIP_INVITE) 12993 handle_response_invite(p, resp, rest, req, seqno); 12994 else if (sipmethod == SIP_REFER) 12995 handle_response_refer(p, resp, rest, req, seqno); 12996 else if (p->registry && sipmethod == SIP_REGISTER) 12997 res = handle_response_register(p, resp, rest, req, ignore, seqno); 12998 else if (sipmethod == SIP_BYE) { 12999 if (ast_strlen_zero(p->authname)) { 13000 ast_log(LOG_WARNING, "Asked to authenticate %s, to %s:%d but we have no matching peer!\n", 13001 msg, ast_inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port)); 13002 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 13003 } else if ((p->authtries == MAX_AUTHTRIES) || do_proxy_auth(p, req, "Proxy-Authenticate", "Proxy-Authorization", sipmethod, 0)) { 13004 ast_log(LOG_NOTICE, "Failed to authenticate on %s to '%s'\n", msg, get_header(&p->initreq, "From")); 13005 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 13006 } 13007 } else /* We can't handle this, giving up in a bad way */ 13008 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 13009 13010 break; 13011 case 408: /* Request timeout - terminate dialog */ 13012 if (sipmethod == SIP_INVITE) 13013 handle_response_invite(p, resp, rest, req, seqno); 13014 else if (sipmethod == SIP_REGISTER) 13015 res = handle_response_register(p, resp, rest, req, ignore, seqno); 13016 else if (sipmethod == SIP_BYE) { 13017 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 13018 if (option_debug) 13019 ast_log(LOG_DEBUG, "Got timeout on bye. Thanks for the answer. Now, kill this call\n"); 13020 } else { 13021 if (owner) 13022 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 13023 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 13024 } 13025 break; 13026 case 481: /* Call leg does not exist */ 13027 if (sipmethod == SIP_INVITE) { 13028 handle_response_invite(p, resp, rest, req, seqno); 13029 } else if (sipmethod == SIP_REFER) { 13030 handle_response_refer(p, resp, rest, req, seqno); 13031 } else if (sipmethod == SIP_BYE) { 13032 /* The other side has no transaction to bye, 13033 just assume it's all right then */ 13034 ast_log(LOG_WARNING, "Remote host can't match request %s to call '%s'. Giving up.\n", sip_methods[sipmethod].text, p->callid); 13035 } else if (sipmethod == SIP_CANCEL) { 13036 /* The other side has no transaction to cancel, 13037 just assume it's all right then */ 13038 ast_log(LOG_WARNING, "Remote host can't match request %s to call '%s'. Giving up.\n", sip_methods[sipmethod].text, p->callid); 13039 } else { 13040 ast_log(LOG_WARNING, "Remote host can't match request %s to call '%s'. Giving up.\n", sip_methods[sipmethod].text, p->callid); 13041 /* Guessing that this is not an important request */ 13042 } 13043 break; 13044 case 487: 13045 if (sipmethod == SIP_INVITE) 13046 handle_response_invite(p, resp, rest, req, seqno); 13047 break; 13048 case 488: /* Not acceptable here - codec error */ 13049 if (sipmethod == SIP_INVITE) 13050 handle_response_invite(p, resp, rest, req, seqno); 13051 break; 13052 case 491: /* Pending */ 13053 if (sipmethod == SIP_INVITE) 13054 handle_response_invite(p, resp, rest, req, seqno); 13055 else { 13056 if (option_debug) 13057 ast_log(LOG_DEBUG, "Got 491 on %s, unspported. Call ID %s\n", sip_methods[sipmethod].text, p->callid); 13058 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 13059 } 13060 break; 13061 case 501: /* Not Implemented */ 13062 if (sipmethod == SIP_INVITE) 13063 handle_response_invite(p, resp, rest, req, seqno); 13064 else if (sipmethod == SIP_REFER) 13065 handle_response_refer(p, resp, rest, req, seqno); 13066 else 13067 ast_log(LOG_WARNING, "Host '%s' does not implement '%s'\n", ast_inet_ntoa(p->sa.sin_addr), msg); 13068 break; 13069 case 603: /* Declined transfer */ 13070 if (sipmethod == SIP_REFER) { 13071 handle_response_refer(p, resp, rest, req, seqno); 13072 break; 13073 } 13074 /* Fallthrough */ 13075 default: 13076 if ((resp >= 300) && (resp < 700)) { 13077 /* Fatal response */ 13078 if ((option_verbose > 2) && (resp != 487)) 13079 ast_verbose(VERBOSE_PREFIX_3 "Got SIP response %d \"%s\" back from %s\n", resp, rest, ast_inet_ntoa(p->sa.sin_addr)); 13080 13081 if (sipmethod == SIP_INVITE) 13082 stop_media_flows(p); /* Immediately stop RTP, VRTP and UDPTL as applicable */ 13083 13084 /* XXX Locking issues?? XXX */ 13085 switch(resp) { 13086 case 300: /* Multiple Choices */ 13087 case 301: /* Moved permenantly */ 13088 case 302: /* Moved temporarily */ 13089 case 305: /* Use Proxy */ 13090 parse_moved_contact(p, req); 13091 /* Fall through */ 13092 case 486: /* Busy here */ 13093 case 600: /* Busy everywhere */ 13094 case 603: /* Decline */ 13095 if (p->owner) 13096 ast_queue_control(p->owner, AST_CONTROL_BUSY); 13097 break; 13098 case 482: /* 13099 \note SIP is incapable of performing a hairpin call, which 13100 is yet another failure of not having a layer 2 (again, YAY 13101 IETF for thinking ahead). So we treat this as a call 13102 forward and hope we end up at the right place... */ 13103 if (option_debug) 13104 ast_log(LOG_DEBUG, "Hairpin detected, setting up call forward for what it's worth\n"); 13105 if (p->owner) 13106 ast_string_field_build(p->owner, call_forward, 13107 "Local/%s@%s", p->username, p->context); 13108 /* Fall through */ 13109 case 480: /* Temporarily Unavailable */ 13110 case 404: /* Not Found */ 13111 case 410: /* Gone */ 13112 case 400: /* Bad Request */ 13113 case 500: /* Server error */ 13114 if (sipmethod == SIP_REFER) { 13115 handle_response_refer(p, resp, rest, req, seqno); 13116 break; 13117 } 13118 /* Fall through */ 13119 case 502: /* Bad gateway */ 13120 case 503: /* Service Unavailable */ 13121 case 504: /* Server Timeout */ 13122 if (owner) 13123 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 13124 break; 13125 default: 13126 /* Send hangup */ 13127 if (owner && sipmethod != SIP_MESSAGE && sipmethod != SIP_INFO && sipmethod != SIP_BYE) 13128 ast_queue_hangup(p->owner); 13129 break; 13130 } 13131 /* ACK on invite */ 13132 if (sipmethod == SIP_INVITE) 13133 transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 13134 if (sipmethod != SIP_MESSAGE && sipmethod != SIP_INFO) 13135 sip_alreadygone(p); 13136 if (!p->owner) 13137 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 13138 } else if ((resp >= 100) && (resp < 200)) { 13139 if (sipmethod == SIP_INVITE) { 13140 if (!ast_test_flag(req, SIP_PKT_IGNORE) && sip_cancel_destroy(p)) 13141 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 13142 if (find_sdp(req)) 13143 process_sdp(p, req); 13144 if (p->owner) { 13145 /* Queue a progress frame */ 13146 ast_queue_control(p->owner, AST_CONTROL_PROGRESS); 13147 } 13148 } 13149 } else 13150 ast_log(LOG_NOTICE, "Dont know how to handle a %d %s response from %s\n", resp, rest, p->owner ? p->owner->name : ast_inet_ntoa(p->sa.sin_addr)); 13151 } 13152 } else { 13153 /* Responses to OUTGOING SIP requests on INCOMING calls 13154 get handled here. As well as out-of-call message responses */ 13155 if (ast_test_flag(req, SIP_PKT_DEBUG)) 13156 ast_verbose("SIP Response message for INCOMING dialog %s arrived\n", msg); 13157 13158 if (sipmethod == SIP_INVITE && resp == 200) { 13159 /* Tags in early session is replaced by the tag in 200 OK, which is 13160 the final reply to our INVITE */ 13161 char tag[128]; 13162 13163 gettag(req, "To", tag, sizeof(tag)); 13164 ast_string_field_set(p, theirtag, tag); 13165 } 13166 13167 switch(resp) { 13168 case 200: 13169 if (sipmethod == SIP_INVITE) { 13170 handle_response_invite(p, resp, rest, req, seqno); 13171 } else if (sipmethod == SIP_CANCEL) { 13172 if (option_debug) 13173 ast_log(LOG_DEBUG, "Got 200 OK on CANCEL\n"); 13174 13175 /* Wait for 487, then destroy */ 13176 } else if (sipmethod == SIP_NOTIFY) { 13177 /* They got the notify, this is the end */ 13178 if (p->owner) { 13179 if (p->refer) { 13180 if (option_debug) 13181 ast_log(LOG_DEBUG, "Got 200 OK on NOTIFY for transfer\n"); 13182 } else 13183 ast_log(LOG_WARNING, "Notify answer on an owned channel?\n"); 13184 /* ast_queue_hangup(p->owner); Disabled */ 13185 } else { 13186 if (!p->subscribed && !p->refer) 13187 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 13188 if (ast_test_flag(&p->flags[1], SIP_PAGE2_STATECHANGEQUEUE)) { 13189 /* Ready to send the next state we have on queue */ 13190 ast_clear_flag(&p->flags[1], SIP_PAGE2_STATECHANGEQUEUE); 13191 cb_extensionstate((char *)p->context, (char *)p->exten, p->laststate, (void *) p); 13192 } 13193 } 13194 } else if (sipmethod == SIP_BYE) 13195 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 13196 else if (sipmethod == SIP_MESSAGE || sipmethod == SIP_INFO) 13197 /* We successfully transmitted a message or 13198 a video update request in INFO */ 13199 ; 13200 else if (sipmethod == SIP_BYE) 13201 /* Ok, we're ready to go */ 13202 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 13203 break; 13204 case 202: /* Transfer accepted */ 13205 if (sipmethod == SIP_REFER) 13206 handle_response_refer(p, resp, rest, req, seqno); 13207 break; 13208 case 401: /* www-auth */ 13209 case 407: 13210 if (sipmethod == SIP_REFER) 13211 handle_response_refer(p, resp, rest, req, seqno); 13212 else if (sipmethod == SIP_INVITE) 13213 handle_response_invite(p, resp, rest, req, seqno); 13214 else if (sipmethod == SIP_BYE) { 13215 char *auth, *auth2; 13216 13217 auth = (resp == 407 ? "Proxy-Authenticate" : "WWW-Authenticate"); 13218 auth2 = (resp == 407 ? "Proxy-Authorization" : "Authorization"); 13219 if ((p->authtries == MAX_AUTHTRIES) || do_proxy_auth(p, req, auth, auth2, sipmethod, 0)) { 13220 ast_log(LOG_NOTICE, "Failed to authenticate on %s to '%s'\n", msg, get_header(&p->initreq, "From")); 13221 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 13222 } 13223 } 13224 break; 13225 case 481: /* Call leg does not exist */ 13226 if (sipmethod == SIP_INVITE) { 13227 /* Re-invite failed */ 13228 handle_response_invite(p, resp, rest, req, seqno); 13229 } else if (sipmethod == SIP_BYE) { 13230 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 13231 } else if (sipdebug) { 13232 ast_log (LOG_DEBUG, "Remote host can't match request %s to call '%s'. Giving up\n", sip_methods[sipmethod].text, p->callid); 13233 } 13234 break; 13235 case 501: /* Not Implemented */ 13236 if (sipmethod == SIP_INVITE) 13237 handle_response_invite(p, resp, rest, req, seqno); 13238 else if (sipmethod == SIP_REFER) 13239 handle_response_refer(p, resp, rest, req, seqno); 13240 break; 13241 case 603: /* Declined transfer */ 13242 if (sipmethod == SIP_REFER) { 13243 handle_response_refer(p, resp, rest, req, seqno); 13244 break; 13245 } 13246 /* Fallthrough */ 13247 default: /* Errors without handlers */ 13248 if ((resp >= 100) && (resp < 200)) { 13249 if (sipmethod == SIP_INVITE) { /* re-invite */ 13250 if (!ast_test_flag(req, SIP_PKT_IGNORE) && sip_cancel_destroy(p)) 13251 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 13252 } 13253 } 13254 if ((resp >= 300) && (resp < 700)) { 13255 if ((option_verbose > 2) && (resp != 487)) 13256 ast_verbose(VERBOSE_PREFIX_3 "Incoming call: Got SIP response %d \"%s\" back from %s\n", resp, rest, ast_inet_ntoa(p->sa.sin_addr)); 13257 switch(resp) { 13258 case 488: /* Not acceptable here - codec error */ 13259 case 603: /* Decline */ 13260 case 500: /* Server error */ 13261 case 502: /* Bad gateway */ 13262 case 503: /* Service Unavailable */ 13263 case 504: /* Server timeout */ 13264 13265 /* re-invite failed */ 13266 if (sipmethod == SIP_INVITE && sip_cancel_destroy(p)) 13267 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 13268 break; 13269 } 13270 } 13271 break; 13272 } 13273 } 13274 }
| static void handle_response_invite | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| char * | rest, | |||
| struct sip_request * | req, | |||
| int | seqno | |||
| ) | [static] |
Handle SIP response to INVITE dialogue.
Definition at line 12253 of file chan_sip.c.
References ast_channel::_state, append_history, ast_bridged_channel(), AST_CONTROL_ANSWER, AST_CONTROL_CONGESTION, AST_CONTROL_PROGRESS, AST_CONTROL_RINGING, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_null_frame, ast_queue_control(), ast_queue_frame(), ast_queue_hangup(), ast_random(), ast_rtp_set_rtptimers_onhold(), ast_sched_add(), AST_SCHED_DEL, ast_set_flag, ast_setstate(), AST_STATE_RINGING, AST_STATE_UP, ast_string_field_free, ast_test_flag, sip_invite_param::auth_type, authenticate(), sip_pvt::authtries, build_route(), sip_pvt::callid, check_pendings(), DEC_CALL_LIMIT, DEC_CALL_RINGING, DEFAULT_TRANS_TIMEOUT, do_proxy_auth(), FALSE, find_sdp(), sip_pvt::flags, get_header(), sip_pvt::initid, sip_pvt::initreq, INV_CALLING, INV_CANCELLED, INV_COMPLETED, INV_EARLY_MEDIA, INV_PROCEEDING, INV_TERMINATED, sip_pvt::invitestate, sip_pvt::lock, LOG_DEBUG, LOG_ERROR, LOG_NOTICE, LOG_WARNING, MAX_AUTHTRIES, ast_channel::name, option_debug, sip_pvt::options, sip_pvt::owner, parse_ok_contact(), process_sdp(), PROXY_AUTH, sip_pvt::route, sip_pvt::rtp, set_address_from_contact(), SIP_ACK, sip_alreadygone(), SIP_ALREADYGONE, sip_cancel_destroy(), sip_handle_t38_reinvite(), SIP_INVITE, SIP_NEEDDESTROY, SIP_OUTGOING, SIP_PAGE2_DIALOG_ESTABLISHED, SIP_PENDINGBYE, SIP_PKT_IGNORE, sip_reinvite_retry(), sip_scheddestroy(), t38properties::state, sip_pvt::t38, T38_DISABLED, T38_ENABLED, T38_LOCAL_DIRECT, T38_LOCAL_REINVITE, T38_PEER_REINVITE, ast_channel::tech, ast_channel::tech_pvt, sip_pvt::theirtag, transmit_request(), TRUE, ast_channel_tech::type, sip_pvt::udptl, update_call_counter(), sip_pvt::vrtp, sip_pvt::waitid, WWW_AUTH, XMIT_ERROR, and XMIT_UNRELIABLE.
Referenced by handle_response().
12254 { 12255 int outgoing = ast_test_flag(&p->flags[0], SIP_OUTGOING); 12256 int res = 0; 12257 int xmitres = 0; 12258 int reinvite = (p->owner && p->owner->_state == AST_STATE_UP); 12259 struct ast_channel *bridgepeer = NULL; 12260 12261 if (option_debug > 3) { 12262 if (reinvite) 12263 ast_log(LOG_DEBUG, "SIP response %d to RE-invite on %s call %s\n", resp, outgoing ? "outgoing" : "incoming", p->callid); 12264 else 12265 ast_log(LOG_DEBUG, "SIP response %d to standard invite\n", resp); 12266 } 12267 12268 if (ast_test_flag(&p->flags[0], SIP_ALREADYGONE)) { /* This call is already gone */ 12269 if (option_debug) 12270 ast_log(LOG_DEBUG, "Got response on call that is already terminated: %s (ignoring)\n", p->callid); 12271 return; 12272 } 12273 12274 /* Acknowledge sequence number - This only happens on INVITE from SIP-call */ 12275 /* Don't auto congest anymore since we've gotten something useful back */ 12276 AST_SCHED_DEL(sched, p->initid); 12277 12278 /* RFC3261 says we must treat every 1xx response (but not 100) 12279 that we don't recognize as if it was 183. 12280 */ 12281 if (resp > 100 && resp < 200 && resp!=101 && resp != 180 && resp != 182 && resp != 183) 12282 resp = 183; 12283 12284 /* Any response between 100 and 199 is PROCEEDING */ 12285 if (resp >= 100 && resp < 200 && p->invitestate == INV_CALLING) 12286 p->invitestate = INV_PROCEEDING; 12287 12288 /* Final response, not 200 ? */ 12289 if (resp >= 300 && (p->invitestate == INV_CALLING || p->invitestate == INV_PROCEEDING || p->invitestate == INV_EARLY_MEDIA )) 12290 p->invitestate = INV_COMPLETED; 12291 12292 12293 switch (resp) { 12294 case 100: /* Trying */ 12295 case 101: /* Dialog establishment */ 12296 if (!ast_test_flag(req, SIP_PKT_IGNORE) && (p->invitestate != INV_CANCELLED) && sip_cancel_destroy(p)) 12297 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 12298 check_pendings(p); 12299 break; 12300 12301 case 180: /* 180 Ringing */ 12302 case 182: /* 182 Queued */ 12303 if (!ast_test_flag(req, SIP_PKT_IGNORE) && (p->invitestate != INV_CANCELLED) && sip_cancel_destroy(p)) 12304 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 12305 if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner) { 12306 ast_queue_control(p->owner, AST_CONTROL_RINGING); 12307 if (p->owner->_state != AST_STATE_UP) { 12308 ast_setstate(p->owner, AST_STATE_RINGING); 12309 } 12310 } 12311 if (find_sdp(req)) { 12312 if (p->invitestate != INV_CANCELLED) 12313 p->invitestate = INV_EARLY_MEDIA; 12314 res = process_sdp(p, req); 12315 if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner) { 12316 /* Queue a progress frame only if we have SDP in 180 or 182 */ 12317 ast_queue_control(p->owner, AST_CONTROL_PROGRESS); 12318 } 12319 } 12320 check_pendings(p); 12321 break; 12322 12323 case 183: /* Session progress */ 12324 if (!ast_test_flag(req, SIP_PKT_IGNORE) && (p->invitestate != INV_CANCELLED) && sip_cancel_destroy(p)) 12325 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 12326 /* Ignore 183 Session progress without SDP */ 12327 if (find_sdp(req)) { 12328 if (p->invitestate != INV_CANCELLED) 12329 p->invitestate = INV_EARLY_MEDIA; 12330 res = process_sdp(p, req); 12331 if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner) { 12332 /* Queue a progress frame */ 12333 ast_queue_control(p->owner, AST_CONTROL_PROGRESS); 12334 } 12335 } 12336 check_pendings(p); 12337 break; 12338 12339 case 200: /* 200 OK on invite - someone's answering our call */ 12340 if (!ast_test_flag(req, SIP_PKT_IGNORE) && (p->invitestate != INV_CANCELLED) && sip_cancel_destroy(p)) 12341 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 12342 p->authtries = 0; 12343 if (find_sdp(req)) { 12344 if ((res = process_sdp(p, req)) && !ast_test_flag(req, SIP_PKT_IGNORE)) 12345 if (!reinvite) 12346 /* This 200 OK's SDP is not acceptable, so we need to ack, then hangup */ 12347 /* For re-invites, we try to recover */ 12348 ast_set_flag(&p->flags[0], SIP_PENDINGBYE); 12349 } 12350 12351 /* Parse contact header for continued conversation */ 12352 /* When we get 200 OK, we know which device (and IP) to contact for this call */ 12353 /* This is important when we have a SIP proxy between us and the phone */ 12354 if (outgoing) { 12355 update_call_counter(p, DEC_CALL_RINGING); 12356 parse_ok_contact(p, req); 12357 /* Save Record-Route for any later requests we make on this dialogue */ 12358 if (!reinvite) 12359 build_route(p, req, 1); 12360 12361 if(set_address_from_contact(p)) { 12362 /* Bad contact - we don't know how to reach this device */ 12363 /* We need to ACK, but then send a bye */ 12364 if (!p->route && !ast_test_flag(req, SIP_PKT_IGNORE)) 12365 ast_set_flag(&p->flags[0], SIP_PENDINGBYE); 12366 } 12367 12368 } 12369 12370 if (p->owner && (p->owner->_state == AST_STATE_UP) && (bridgepeer = ast_bridged_channel(p->owner))) { /* if this is a re-invite */ 12371 struct sip_pvt *bridgepvt = NULL; 12372 12373 if (!bridgepeer->tech) { 12374 ast_log(LOG_WARNING, "Ooooh.. no tech! That's REALLY bad\n"); 12375 break; 12376 } 12377 if (bridgepeer->tech == &sip_tech || bridgepeer->tech == &sip_tech_info) { 12378 bridgepvt = (struct sip_pvt*)(bridgepeer->tech_pvt); 12379 if (bridgepvt->udptl) { 12380 if (p->t38.state == T38_PEER_REINVITE) { 12381 sip_handle_t38_reinvite(bridgepeer, p, 0); 12382 ast_rtp_set_rtptimers_onhold(p->rtp); 12383 if (p->vrtp) 12384 ast_rtp_set_rtptimers_onhold(p->vrtp); /* Turn off RTP timers while we send fax */ 12385 } else if (p->t38.state == T38_DISABLED && bridgepeer && (bridgepvt->t38.state == T38_ENABLED)) { 12386 ast_log(LOG_WARNING, "RTP re-invite after T38 session not handled yet !\n"); 12387 /* Insted of this we should somehow re-invite the other side of the bridge to RTP */ 12388 /* XXXX Should we really destroy this session here, without any response at all??? */ 12389 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 12390 } 12391 } else { 12392 if (option_debug > 1) 12393 ast_log(LOG_DEBUG, "Strange... The other side of the bridge does not have a udptl struct\n"); 12394 ast_mutex_lock(&bridgepvt->lock); 12395 bridgepvt->t38.state = T38_DISABLED; 12396 ast_mutex_unlock(&bridgepvt->lock); 12397 if (option_debug) 12398 ast_log(LOG_DEBUG,"T38 state changed to %d on channel %s\n", bridgepvt->t38.state, bridgepeer->tech->type); 12399 p->t38.state = T38_DISABLED; 12400 if (option_debug > 1) 12401 ast_log(LOG_DEBUG,"T38 state changed to %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "<none>"); 12402 } 12403 } else { 12404 /* Other side is not a SIP channel */ 12405 if (option_debug > 1) 12406 ast_log(LOG_DEBUG, "Strange... The other side of the bridge is not a SIP channel\n"); 12407 p->t38.state = T38_DISABLED; 12408 if (option_debug > 1) 12409 ast_log(LOG_DEBUG,"T38 state changed to %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "<none>"); 12410 } 12411 } 12412 if ((p->t38.state == T38_LOCAL_REINVITE) || (p->t38.state == T38_LOCAL_DIRECT)) { 12413 /* If there was T38 reinvite and we are supposed to answer with 200 OK than this should set us to T38 negotiated mode */ 12414 p->t38.state = T38_ENABLED; 12415 if (option_debug) 12416 ast_log(LOG_DEBUG, "T38 changed state to %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "<none>"); 12417 } 12418 12419 if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner) { 12420 if (!reinvite) { 12421 ast_queue_control(p->owner, AST_CONTROL_ANSWER); 12422 } else { /* RE-invite */ 12423 ast_queue_frame(p->owner, &ast_null_frame); 12424 } 12425 } else { 12426 /* It's possible we're getting an 200 OK after we've tried to disconnect 12427 by sending CANCEL */ 12428 /* First send ACK, then send bye */ 12429 if (!ast_test_flag(req, SIP_PKT_IGNORE)) 12430 ast_set_flag(&p->flags[0], SIP_PENDINGBYE); 12431 } 12432 /* If I understand this right, the branch is different for a non-200 ACK only */ 12433 p->invitestate = INV_TERMINATED; 12434 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 12435 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, TRUE); 12436 check_pendings(p); 12437 break; 12438 case 407: /* Proxy authentication */ 12439 case 401: /* Www auth */ 12440 /* First we ACK */ 12441 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 12442 if (p->options) 12443 p->options->auth_type = (resp == 401 ? WWW_AUTH : PROXY_AUTH); 12444 12445 /* Then we AUTH */ 12446 ast_string_field_free(p, theirtag); /* forget their old tag, so we don't match tags when getting response */ 12447 if (!ast_test_flag(req, SIP_PKT_IGNORE)) { 12448 char *authenticate = (resp == 401 ? "WWW-Authenticate" : "Proxy-Authenticate"); 12449 char *authorization = (resp == 401 ? "Authorization" : "Proxy-Authorization"); 12450 if (p->authtries < MAX_AUTHTRIES) 12451 p->invitestate = INV_CALLING; 12452 if ((p->authtries == MAX_AUTHTRIES) || do_proxy_auth(p, req, authenticate, authorization, SIP_INVITE, 1)) { 12453 ast_log(LOG_NOTICE, "Failed to authenticate on INVITE to '%s'\n", get_header(&p->initreq, "From")); 12454 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12455 sip_alreadygone(p); 12456 if (p->owner) 12457 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 12458 } 12459 } 12460 break; 12461 12462 case 403: /* Forbidden */ 12463 /* First we ACK */ 12464 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 12465 ast_log(LOG_WARNING, "Received response: \"Forbidden\" from '%s'\n", get_header(&p->initreq, "From")); 12466 if (!ast_test_flag(req, SIP_PKT_IGNORE) && p->owner) 12467 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 12468 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12469 sip_alreadygone(p); 12470 break; 12471 12472 case 404: /* Not found */ 12473 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 12474 if (p->owner && !ast_test_flag(req, SIP_PKT_IGNORE)) 12475 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 12476 sip_alreadygone(p); 12477 break; 12478 12479 case 408: /* Request timeout */ 12480 case 481: /* Call leg does not exist */ 12481 /* Could be REFER caused INVITE with replaces */ 12482 ast_log(LOG_WARNING, "Re-invite to non-existing call leg on other UA. SIP dialog '%s'. Giving up.\n", p->callid); 12483 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 12484 if (p->owner) 12485 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 12486 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 12487 break; 12488 case 487: /* Cancelled transaction */ 12489 /* We have sent CANCEL on an outbound INVITE 12490 This transaction is already scheduled to be killed by sip_hangup(). 12491 */ 12492 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 12493 if (p->owner && !ast_test_flag(req, SIP_PKT_IGNORE)) { 12494 ast_queue_hangup(p->owner); 12495 append_history(p, "Hangup", "Got 487 on CANCEL request from us. Queued AST hangup request"); 12496 } else if (!ast_test_flag(req, SIP_PKT_IGNORE)) { 12497 update_call_counter(p, DEC_CALL_LIMIT); 12498 append_history(p, "Hangup", "Got 487 on CANCEL request from us on call without owner. Killing this dialog."); 12499 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12500 sip_alreadygone(p); 12501 } 12502 break; 12503 case 488: /* Not acceptable here */ 12504 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 12505 if (reinvite && p->udptl) { 12506 /* If this is a T.38 call, we should go back to 12507 audio. If this is an audio call - something went 12508 terribly wrong since we don't renegotiate codecs, 12509 only IP/port . 12510 */ 12511 p->t38.state = T38_DISABLED; 12512 /* Try to reset RTP timers */ 12513 ast_rtp_set_rtptimers_onhold(p->rtp); 12514 ast_log(LOG_ERROR, "Got error on T.38 re-invite. Bad configuration. Peer needs to have T.38 disabled.\n"); 12515 12516 /*! \bug Is there any way we can go back to the audio call on both 12517 sides here? 12518 */ 12519 /* While figuring that out, hangup the call */ 12520 if (p->owner && !ast_test_flag(req, SIP_PKT_IGNORE)) 12521 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 12522 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12523 } else if (p->udptl && p->t38.state == T38_LOCAL_DIRECT) { 12524 /* We tried to send T.38 out in an initial INVITE and the remote side rejected it, 12525 right now we can't fall back to audio so totally abort. 12526 */ 12527 p->t38.state = T38_DISABLED; 12528 /* Try to reset RTP timers */ 12529 ast_rtp_set_rtptimers_onhold(p->rtp); 12530 ast_log(LOG_ERROR, "Got error on T.38 initial invite. Bailing out.\n"); 12531 12532 /* The dialog is now terminated */ 12533 if (p->owner && !ast_test_flag(req, SIP_PKT_IGNORE)) 12534 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 12535 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12536 sip_alreadygone(p); 12537 } else { 12538 /* We can't set up this call, so give up */ 12539 if (p->owner && !ast_test_flag(req, SIP_PKT_IGNORE)) 12540 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 12541 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12542 /* If there's no dialog to end, then mark p as already gone */ 12543 if (!reinvite) 12544 sip_alreadygone(p); 12545 } 12546 break; 12547 case 491: /* Pending */ 12548 /* we really should have to wait a while, then retransmit 12549 * We should support the retry-after at some point 12550 * At this point, we treat this as a congestion if the call is not in UP state 12551 */ 12552 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 12553 if (p->owner && !ast_test_flag(req, SIP_PKT_IGNORE)) { 12554 if (p->owner->_state != AST_STATE_UP) { 12555 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 12556 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12557 } else { 12558 /* This is a re-invite that failed. 12559 * Reset the flag after a while 12560 */ 12561 int wait = 3 + ast_random() % 5; 12562 p->waitid = ast_sched_add(sched, wait, sip_reinvite_retry, p); 12563 if (option_debug > 2) 12564 ast_log(LOG_DEBUG, "Reinvite race. Waiting %d secs before retry\n", wait); 12565 } 12566 } 12567 break; 12568 12569 case 501: /* Not implemented */ 12570 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 12571 if (p->owner) 12572 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 12573 break; 12574 } 12575 if (xmitres == XMIT_ERROR) 12576 ast_log(LOG_WARNING, "Could not transmit message in dialog %s\n", p->callid); 12577 }
| static void handle_response_peerpoke | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| struct sip_request * | req | |||
| ) | [static] |
Handle qualification responses (OPTIONS).
Definition at line 12771 of file chan_sip.c.
References ast_device_state_changed(), ast_log(), ast_sched_add(), AST_SCHED_DEL, ast_set_flag, ast_tvdiff_ms(), ast_tvnow(), ASTOBJ_REF, ASTOBJ_UNREF, sip_peer::call, DEFAULT_FREQ_NOTOK, DEFAULT_FREQ_OK, EVENT_FLAG_SYSTEM, sip_pvt::flags, sip_peer::lastms, LOG_NOTICE, manager_event(), sip_peer::maxms, sip_peer::name, sip_peer::pokeexpire, sip_peer::ps, sip_pvt::relatedpeer, s, sip_destroy_peer(), SIP_NEEDDESTROY, and sip_poke_peer_s().
Referenced by handle_response().
12772 { 12773 struct sip_peer *peer = p->relatedpeer; 12774 int statechanged, is_reachable, was_reachable; 12775 int pingtime = ast_tvdiff_ms(ast_tvnow(), peer->ps); 12776 12777 /* 12778 * Compute the response time to a ping (goes in peer->lastms.) 12779 * -1 means did not respond, 0 means unknown, 12780 * 1..maxms is a valid response, >maxms means late response. 12781 */ 12782 if (pingtime < 1) /* zero = unknown, so round up to 1 */ 12783 pingtime = 1; 12784 12785 /* Now determine new state and whether it has changed. 12786 * Use some helper variables to simplify the writing 12787 * of the expressions. 12788 */ 12789 was_reachable = peer->lastms > 0 && peer->lastms <= peer->maxms; 12790 is_reachable = pingtime <= peer->maxms; 12791 statechanged = peer->lastms == 0 /* yes, unknown before */ 12792 || was_reachable != is_reachable; 12793 12794 peer->lastms = pingtime; 12795 peer->call = NULL; 12796 if (statechanged) { 12797 const char *s = is_reachable ? "Reachable" : "Lagged"; 12798 12799 ast_log(LOG_NOTICE, "Peer '%s' is now %s. (%dms / %dms)\n", 12800 peer->name, s, pingtime, peer->maxms); 12801 ast_device_state_changed("SIP/%s", peer->name); 12802 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", 12803 "Peer: SIP/%s\r\nPeerStatus: %s\r\nTime: %d\r\n", 12804 peer->name, s, pingtime); 12805 } 12806 12807 if (!AST_SCHED_DEL(sched, peer->pokeexpire)) { 12808 struct sip_peer *peer_ptr = peer; 12809 ASTOBJ_UNREF(peer_ptr, sip_destroy_peer); 12810 } 12811 12812 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12813 12814 /* Try again eventually */ 12815 peer->pokeexpire = ast_sched_add(sched, 12816 is_reachable ? DEFAULT_FREQ_OK : DEFAULT_FREQ_NOTOK, 12817 sip_poke_peer_s, ASTOBJ_REF(peer)); 12818 12819 if (peer->pokeexpire == -1) { 12820 ASTOBJ_UNREF(peer, sip_destroy_peer); 12821 } 12822 }
| static void handle_response_refer | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| char * | rest, | |||
| struct sip_request * | req, | |||
| int | seqno | |||
| ) | [static] |
Definition at line 12582 of file chan_sip.c.
References AST_CONTROL_CONGESTION, ast_inet_ntoa(), ast_log(), ast_queue_control(), ast_set_flag, ast_strlen_zero(), sip_pvt::authname, sip_pvt::authtries, sip_pvt::callid, do_proxy_auth(), sip_pvt::flags, get_header(), sip_pvt::initreq, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, option_debug, sip_pvt::owner, sip_pvt::recv, sip_pvt::refer, REFER_ACCEPTED, REFER_FAILED, REFER_NOAUTH, sip_refer::refer_to, SIP_NEEDDESTROY, SIP_REFER, and sip_refer::status.
Referenced by handle_response().
12583 { 12584 char *auth = "Proxy-Authenticate"; 12585 char *auth2 = "Proxy-Authorization"; 12586 12587 /* If no refer structure exists, then do nothing */ 12588 if (!p->refer) 12589 return; 12590 12591 switch (resp) { 12592 case 202: /* Transfer accepted */ 12593 /* We need to do something here */ 12594 /* The transferee is now sending INVITE to target */ 12595 p->refer->status = REFER_ACCEPTED; 12596 /* Now wait for next message */ 12597 if (option_debug > 2) 12598 ast_log(LOG_DEBUG, "Got 202 accepted on transfer\n"); 12599 /* We should hang along, waiting for NOTIFY's here */ 12600 break; 12601 12602 case 401: /* Not www-authorized on SIP method */ 12603 case 407: /* Proxy auth */ 12604 if (ast_strlen_zero(p->authname)) { 12605 ast_log(LOG_WARNING, "Asked to authenticate REFER to %s:%d but we have no matching peer or realm auth!\n", 12606 ast_inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port)); 12607 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12608 } 12609 if (resp == 401) { 12610 auth = "WWW-Authenticate"; 12611 auth2 = "Authorization"; 12612 } 12613 if ((p->authtries > 1) || do_proxy_auth(p, req, auth, auth2, SIP_REFER, 0)) { 12614 ast_log(LOG_NOTICE, "Failed to authenticate on REFER to '%s'\n", get_header(&p->initreq, "From")); 12615 p->refer->status = REFER_NOAUTH; 12616 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12617 } 12618 break; 12619 case 481: /* Call leg does not exist */ 12620 12621 /* A transfer with Replaces did not work */ 12622 /* OEJ: We should Set flag, cancel the REFER, go back 12623 to original call - but right now we can't */ 12624 ast_log(LOG_WARNING, "Remote host can't match REFER request to call '%s'. Giving up.\n", p->callid); 12625 if (p->owner) 12626 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 12627 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12628 break; 12629 12630 case 500: /* Server error */ 12631 case 501: /* Method not implemented */ 12632 /* Return to the current call onhold */ 12633 /* Status flag needed to be reset */ 12634 ast_log(LOG_NOTICE, "SIP transfer to %s failed, call miserably fails. \n", p->refer->refer_to); 12635 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12636 p->refer->status = REFER_FAILED; 12637 break; 12638 case 603: /* Transfer declined */ 12639 ast_log(LOG_NOTICE, "SIP transfer to %s declined, call miserably fails. \n", p->refer->refer_to); 12640 p->refer->status = REFER_FAILED; 12641 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12642 break; 12643 } 12644 }
| static int handle_response_register | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| char * | rest, | |||
| struct sip_request * | req, | |||
| int | ignore, | |||
| int | seqno | |||
| ) | [static] |
Handle responses on REGISTER to services.
Definition at line 12647 of file chan_sip.c.
References __get_header(), ast_log(), ast_sched_add(), AST_SCHED_DEL, ast_set_flag, ast_strlen_zero(), ASTOBJ_UNREF, sip_pvt::authtries, sip_registry::call, sip_registry::contact, DEFAULT_TRANS_TIMEOUT, do_register_auth(), EVENT_FLAG_SYSTEM, sip_registry::expire, EXPIRY_GUARD_LIMIT, EXPIRY_GUARD_MIN, EXPIRY_GUARD_PCT, EXPIRY_GUARD_SECS, sip_pvt::flags, get_header(), sip_registry::hostname, sip_pvt::initreq, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, manager_event(), MAX, MAX_AUTHTRIES, option_debug, sip_pvt::our_contact, sip_pvt::peername, sip_registry::refresh, REG_STATE_REGISTERED, sip_registry::regattempts, sip_pvt::registry, sip_registry::regstate, regstate2str(), sip_registry::regtime, S_OR, SIP_NEEDDESTROY, sip_registry_destroy(), sip_reregister(), sip_scheddestroy(), sipdebug, sip_registry::timeout, sip_pvt::username, and sip_registry::username.
Referenced by handle_response().
12648 { 12649 int expires, expires_ms; 12650 struct sip_registry *r; 12651 r=p->registry; 12652 12653 switch (resp) { 12654 case 401: /* Unauthorized */ 12655 if ((p->authtries == MAX_AUTHTRIES) || do_register_auth(p, req, "WWW-Authenticate", "Authorization")) { 12656 ast_log(LOG_NOTICE, "Failed to authenticate on REGISTER to '%s@%s' (Tries %d)\n", p->registry->username, p->registry->hostname, p->authtries); 12657 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12658 } 12659 break; 12660 case 403: /* Forbidden */ 12661 ast_log(LOG_WARNING, "Forbidden - wrong password on authentication for REGISTER for '%s' to '%s'\n", p->registry->username, p->registry->hostname); 12662 if (global_regattempts_max) 12663 p->registry->regattempts = global_regattempts_max+1; 12664 AST_SCHED_DEL(sched, r->timeout); 12665 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12666 break; 12667 case 404: /* Not found */ 12668 ast_log(LOG_WARNING, "Got 404 Not found on SIP register to service %s@%s, giving up\n", p->registry->username,p->registry->hostname); 12669 if (global_regattempts_max) 12670 p->registry->regattempts = global_regattempts_max+1; 12671 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12672 r->call = NULL; 12673 AST_SCHED_DEL(sched, r->timeout); 12674 break; 12675 case 407: /* Proxy auth */ 12676 if ((p->authtries == MAX_AUTHTRIES) || do_register_auth(p, req, "Proxy-Authenticate", "Proxy-Authorization")) { 12677 ast_log(LOG_NOTICE, "Failed to authenticate on REGISTER to '%s' (tries '%d')\n", get_header(&p->initreq, "From"), p->authtries); 12678 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12679 } 12680 break; 12681 case 408: /* Request timeout */ 12682 /* Got a timeout response, so reset the counter of failed responses */ 12683 r->regattempts = 0; 12684 break; 12685 case 479: /* SER: Not able to process the URI - address is wrong in register*/ 12686 ast_log(LOG_WARNING, "Got error 479 on register to %s@%s, giving up (check config)\n", p->registry->username,p->registry->hostname); 12687 if (global_regattempts_max) 12688 p->registry->regattempts = global_regattempts_max+1; 12689 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12690 r->call = NULL; 12691 AST_SCHED_DEL(sched, r->timeout); 12692 break; 12693 case 200: /* 200 OK */ 12694 if (!r) { 12695 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)); 12696 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 12697 return 0; 12698 } 12699 12700 r->regstate = REG_STATE_REGISTERED; 12701 r->regtime = time(NULL); /* Reset time of last succesful registration */ 12702 manager_event(EVENT_FLAG_SYSTEM, "Registry", "ChannelDriver: SIP\r\nDomain: %s\r\nStatus: %s\r\n", r->hostname, regstate2str(r->regstate)); 12703 r->regattempts = 0; 12704 if (option_debug) 12705 ast_log(LOG_DEBUG, "Registration successful\n"); 12706 if (r->timeout > -1) { 12707 if (option_debug) 12708 ast_log(LOG_DEBUG, "Cancelling timeout %d\n", r->timeout); 12709 } 12710 AST_SCHED_DEL(sched, r->timeout); 12711 r->call = NULL; 12712 p->registry = NULL; 12713 /* Let this one hang around until we have all the responses */ 12714 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 12715 /* ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); */ 12716 12717 /* set us up for re-registering */ 12718 /* figure out how long we got registered for */ 12719 AST_SCHED_DEL(sched, r->expire); 12720 /* according to section 6.13 of RFC, contact headers override 12721 expires headers, so check those first */ 12722 expires = 0; 12723 12724 /* XXX todo: try to save the extra call */ 12725 if (!ast_strlen_zero(get_header(req, "Contact"))) { 12726 const char *contact = NULL; 12727 const char *tmptmp = NULL; 12728 int start = 0; 12729 for(;;) { 12730 contact = __get_header(req, "Contact", &start); 12731 /* this loop ensures we get a contact header about our register request */ 12732 if(!ast_strlen_zero(contact)) { 12733 if( (tmptmp=strstr(contact, p->our_contact))) { 12734 contact=tmptmp; 12735 break; 12736 } 12737 } else 12738 break; 12739 } 12740 tmptmp = strcasestr(contact, "expires="); 12741 if (tmptmp) { 12742 if (sscanf(tmptmp + 8, "%d;", &expires) != 1) 12743 expires = 0; 12744 } 12745 12746 } 12747 if (!expires) 12748 expires=atoi(get_header(req, "expires")); 12749 if (!expires) 12750 expires=default_expiry; 12751 12752 expires_ms = expires * 1000; 12753 if (expires <= EXPIRY_GUARD_LIMIT) 12754 expires_ms -= MAX((expires_ms * EXPIRY_GUARD_PCT),EXPIRY_GUARD_MIN); 12755 else 12756 expires_ms -= EXPIRY_GUARD_SECS * 1000; 12757 if (sipdebug) 12758 ast_log(LOG_NOTICE, "Outbound Registration: Expiry for %s is %d sec (Scheduling reregistration in %d s)\n", r->hostname, expires, expires_ms/1000); 12759 12760 r->refresh= (int) expires_ms / 1000; 12761 12762 /* Schedule re-registration before we expire */ 12763 AST_SCHED_DEL(sched, r->expire); 12764 r->expire = ast_sched_add(sched, expires_ms, sip_reregister, r); 12765 ASTOBJ_UNREF(r, sip_registry_destroy); 12766 } 12767 return 1; 12768 }
| static const char * hangup_cause2sip | ( | int | cause | ) | [static] |
Convert Asterisk hangup causes to SIP codes.
Possible values from causes.h
AST_CAUSE_NOTDEFINED AST_CAUSE_NORMAL AST_CAUSE_BUSY
AST_CAUSE_FAILURE AST_CAUSE_CONGESTION AST_CAUSE_UNALLOCATED
In addition to these, a lot of PRI codes is defined in causes.h
...should we take care of them too ?
Quote RFC 3398
ISUP Cause value SIP response
---------------- ------------
1 unallocated number 404 Not Found
2 no route to network 404 Not found
3 no route to destination 404 Not found
16 normal call clearing --- (*)
17 user busy 486 Busy here
18 no user responding 408 Request Timeout
19 no answer from the user 480 Temporarily unavailable
20 subscriber absent 480 Temporarily unavailable
21 call rejected 403 Forbidden (+)
22 number changed (w/o diagnostic) 410 Gone
22 number changed (w/ diagnostic) 301 Moved Permanently
23 redirection to new destination 410 Gone
26 non-selected user clearing 404 Not Found (=)
27 destination out of order 502 Bad Gateway
28 address incomplete 484 Address incomplete
29 facility rejected 501 Not implemented
31 normal unspecified 480 Temporarily unavailable
Definition at line 3469 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, ast_log(), LOG_DEBUG, and option_debug.
Referenced by sip_hangup().
03470 { 03471 switch (cause) { 03472 case AST_CAUSE_UNALLOCATED: /* 1 */ 03473 case AST_CAUSE_NO_ROUTE_DESTINATION: /* 3 IAX2: Can't find extension in context */ 03474 case AST_CAUSE_NO_ROUTE_TRANSIT_NET: /* 2 */ 03475 return "404 Not Found"; 03476 case AST_CAUSE_CONGESTION: /* 34 */ 03477 case AST_CAUSE_SWITCH_CONGESTION: /* 42 */ 03478 return "503 Service Unavailable"; 03479 case AST_CAUSE_NO_USER_RESPONSE: /* 18 */ 03480 return "408 Request Timeout"; 03481 case AST_CAUSE_NO_ANSWER: /* 19 */ 03482 case AST_CAUSE_UNREGISTERED: /* 20 */ 03483 return "480 Temporarily unavailable"; 03484 case AST_CAUSE_CALL_REJECTED: /* 21 */ 03485 return "403 Forbidden"; 03486 case AST_CAUSE_NUMBER_CHANGED: /* 22 */ 03487 return "410 Gone"; 03488 case AST_CAUSE_NORMAL_UNSPECIFIED: /* 31 */ 03489 return "480 Temporarily unavailable"; 03490 case AST_CAUSE_INVALID_NUMBER_FORMAT: 03491 return "484 Address incomplete"; 03492 case AST_CAUSE_USER_BUSY: 03493 return "486 Busy here"; 03494 case AST_CAUSE_FAILURE: 03495 return "500 Server internal failure"; 03496 case AST_CAUSE_FACILITY_REJECTED: /* 29 */ 03497 return "501 Not Implemented"; 03498 case AST_CAUSE_CHAN_NOT_IMPLEMENTED: 03499 return "503 Service Unavailable"; 03500 /* Used in chan_iax2 */ 03501 case AST_CAUSE_DESTINATION_OUT_OF_ORDER: 03502 return "502 Bad Gateway"; 03503 case AST_CAUSE_BEARERCAPABILITY_NOTAVAIL: /* Can't find codec to connect to host */ 03504 return "488 Not Acceptable Here"; 03505 03506 case AST_CAUSE_NOTDEFINED: 03507 default: 03508 if (option_debug) 03509 ast_log(LOG_DEBUG, "AST hangup cause %d (no match found in SIP)\n", cause); 03510 return NULL; 03511 } 03512 03513 /* Never reached */ 03514 return 0; 03515 }
| static int hangup_sip2cause | ( | int | cause | ) | [static] |
Convert SIP hangup causes to Asterisk hangup causes.
Definition at line 3357 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_RECOVERY_ON_TIMER_EXPIRE, AST_CAUSE_UNALLOCATED, and AST_CAUSE_USER_BUSY.
Referenced by handle_response().
03358 { 03359 /* Possible values taken from causes.h */ 03360 03361 switch(cause) { 03362 case 401: /* Unauthorized */ 03363 return AST_CAUSE_CALL_REJECTED; 03364 case 403: /* Not found */ 03365 return AST_CAUSE_CALL_REJECTED; 03366 case 404: /* Not found */ 03367 return AST_CAUSE_UNALLOCATED; 03368 case 405: /* Method not allowed */ 03369 return AST_CAUSE_INTERWORKING; 03370 case 407: /* Proxy authentication required */ 03371 return AST_CAUSE_CALL_REJECTED; 03372 case 408: /* No reaction */ 03373 return AST_CAUSE_NO_USER_RESPONSE; 03374 case 409: /* Conflict */ 03375 return AST_CAUSE_NORMAL_TEMPORARY_FAILURE; 03376 case 410: /* Gone */ 03377 return AST_CAUSE_UNALLOCATED; 03378 case 411: /* Length required */ 03379 return AST_CAUSE_INTERWORKING; 03380 case 413: /* Request entity too large */ 03381 return AST_CAUSE_INTERWORKING; 03382 case 414: /* Request URI too large */ 03383 return AST_CAUSE_INTERWORKING; 03384 case 415: /* Unsupported media type */ 03385 return AST_CAUSE_INTERWORKING; 03386 case 420: /* Bad extension */ 03387 return AST_CAUSE_NO_ROUTE_DESTINATION; 03388 case 480: /* No answer */ 03389 return AST_CAUSE_NO_ANSWER; 03390 case 481: /* No answer */ 03391 return AST_CAUSE_INTERWORKING; 03392 case 482: /* Loop detected */ 03393 return AST_CAUSE_INTERWORKING; 03394 case 483: /* Too many hops */ 03395 return AST_CAUSE_NO_ANSWER; 03396 case 484: /* Address incomplete */ 03397 return AST_CAUSE_INVALID_NUMBER_FORMAT; 03398 case 485: /* Ambigous */ 03399 return AST_CAUSE_UNALLOCATED; 03400 case 486: /* Busy everywhere */ 03401 return AST_CAUSE_BUSY; 03402 case 487: /* Request terminated */ 03403 return AST_CAUSE_INTERWORKING; 03404 case 488: /* No codecs approved */ 03405 return AST_CAUSE_BEARERCAPABILITY_NOTAVAIL; 03406 case 491: /* Request pending */ 03407 return AST_CAUSE_INTERWORKING; 03408 case 493: /* Undecipherable */ 03409 return AST_CAUSE_INTERWORKING; 03410 case 500: /* Server internal failure */ 03411 return AST_CAUSE_FAILURE; 03412 case 501: /* Call rejected */ 03413 return AST_CAUSE_FACILITY_REJECTED; 03414 case 502: 03415 return AST_CAUSE_DESTINATION_OUT_OF_ORDER; 03416 case 503: /* Service unavailable */ 03417 return AST_CAUSE_CONGESTION; 03418 case 504: /* Gateway timeout */ 03419 return AST_CAUSE_RECOVERY_ON_TIMER_EXPIRE; 03420 case 505: /* SIP version not supported */ 03421 return AST_CAUSE_INTERWORKING; 03422 case 600: /* Busy everywhere */ 03423 return AST_CAUSE_USER_BUSY; 03424 case 603: /* Decline */ 03425 return AST_CAUSE_CALL_REJECTED; 03426 case 604: /* Does not exist anywhere */ 03427 return AST_CAUSE_UNALLOCATED; 03428 case 606: /* Not acceptable */ 03429 return AST_CAUSE_BEARERCAPABILITY_NOTAVAIL; 03430 default: 03431 return AST_CAUSE_NORMAL; 03432 } 03433 /* Never reached */ 03434 return 0; 03435 }
| static int init_req | ( | struct sip_request * | req, | |
| int | sipmethod, | |||
| const char * | recip | |||
| ) | [static] |
Initialize SIP request.
Definition at line 5944 of file chan_sip.c.
References sip_request::data, sip_request::header, sip_request::headers, sip_request::len, sip_request::method, sip_methods, and cfsip_methods::text.
Referenced by initreqprep(), reqprep(), and transmit_register().
05945 { 05946 /* Initialize a request */ 05947 memset(req, 0, sizeof(*req)); 05948 req->method = sipmethod; 05949 req->header[0] = req->data; 05950 snprintf(req->header[0], sizeof(req->data), "%s %s SIP/2.0\r\n", sip_methods[sipmethod].text, recip); 05951 req->len = strlen(req->header[0]); 05952 req->headers++; 05953 return 0; 05954 }
| static int init_resp | ( | struct sip_request * | resp, | |
| const char * | msg | |||
| ) | [static] |
Initialize SIP response, based on SIP request.
Definition at line 5931 of file chan_sip.c.
References sip_request::data, sip_request::header, sip_request::headers, sip_request::len, sip_request::method, and SIP_RESPONSE.
Referenced by respprep().
05932 { 05933 /* Initialize a response */ 05934 memset(resp, 0, sizeof(*resp)); 05935 resp->method = SIP_RESPONSE; 05936 resp->header[0] = resp->data; 05937 snprintf(resp->header[0], sizeof(resp->data), "SIP/2.0 %s\r\n", msg); 05938 resp->len = strlen(resp->header[0]); 05939 resp->headers++; 05940 return 0; 05941 }
| 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 1656 of file chan_sip.c.
References ast_log(), ast_test_flag, ast_verbose(), sip_pvt::callid, copy_request(), sip_request::headers, sip_pvt::initreq, sip_request::lines, LOG_DEBUG, option_debug, parse_request(), and SIP_PKT_DEBUG.
Referenced by transmit_invite(), transmit_notify_with_mwi(), transmit_notify_with_sipfrag(), transmit_register(), transmit_reinvite_with_sdp(), transmit_reinvite_with_t38_sdp(), and transmit_sip_request().
01657 { 01658 if (p->initreq.headers && option_debug) { 01659 ast_log(LOG_DEBUG, "Initializing already initialized SIP dialog %s (presumably reinvite)\n", p->callid); 01660 } 01661 /* Use this as the basis */ 01662 copy_request(&p->initreq, req); 01663 parse_request(&p->initreq); 01664 if (ast_test_flag(req, SIP_PKT_DEBUG)) 01665 ast_verbose("%d headers, %d lines\n", p->initreq.headers, p->initreq.lines); 01666 }
| static void initreqprep | ( | struct sip_request * | req, | |
| struct sip_pvt * | p, | |||
| int | sipmethod | |||
| ) | [static] |
Initiate new SIP request to peer/user.
Definition at line 7034 of file chan_sip.c.
References add_header(), ast_build_string(), AST_DIGIT_ANYNUM, ast_inet_ntoa(), AST_PRES_ALLOWED, AST_PRES_RESTRICTION, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_uri_encode(), build_contact(), build_rpid(), CALLERID_UNKNOWN, sip_pvt::callid, sip_pvt::callingpres, ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, DEFAULT_MAX_FORWARDS, exten, sip_pvt::flags, sip_pvt::fromdomain, sip_pvt::fromname, sip_pvt::fromuser, sip_pvt::fullcontact, init_req(), sip_pvt::lastmsg, sip_pvt::ocseq, sip_pvt::options, sip_pvt::our_contact, sip_pvt::ourip, sip_pvt::owner, sip_pvt::rpid, sip_pvt::rpid_from, s, S_OR, sip_pvt::sa, SIP_INVITE, sip_methods, SIP_NOTIFY, SIP_SENDRPID, SIP_USEREQPHONE, SIPBUFSIZE, STANDARD_SIP_PORT, sip_pvt::tag, cfsip_methods::text, sip_pvt::theirtag, sip_pvt::tohost, sip_pvt::uri, sip_invite_param::uri_options, sip_pvt::username, sip_pvt::via, and sip_invite_param::vxml_url.
Referenced by sip_notify(), transmit_invite(), and transmit_notify_with_mwi().
07035 { 07036 char invite_buf[256] = ""; 07037 char *invite = invite_buf; 07038 size_t invite_max = sizeof(invite_buf); 07039 char from[256]; 07040 char to[256]; 07041 char tmp[SIPBUFSIZE/2]; 07042 char tmp2[SIPBUFSIZE/2]; 07043 const char *l = NULL, *n = NULL; 07044 const char *urioptions = ""; 07045 07046 if (ast_test_flag(&p->flags[0], SIP_USEREQPHONE)) { 07047 const char *s = p->username; /* being a string field, cannot be NULL */ 07048 07049 /* Test p->username against allowed characters in AST_DIGIT_ANY 07050 If it matches the allowed characters list, then sipuser = ";user=phone" 07051 If not, then sipuser = "" 07052 */ 07053 /* + is allowed in first position in a tel: uri */ 07054 if (*s == '+') 07055 s++; 07056 for (; *s; s++) { 07057 if (!strchr(AST_DIGIT_ANYNUM, *s) ) 07058 break; 07059 } 07060 /* If we have only digits, add ;user=phone to the uri */ 07061 if (!*s) 07062 urioptions = ";user=phone"; 07063 } 07064 07065 07066 snprintf(p->lastmsg, sizeof(p->lastmsg), "Init: %s", sip_methods[sipmethod].text); 07067 07068 if (p->owner) { 07069 l = p->owner->cid.cid_num; 07070 n = p->owner->cid.cid_name; 07071 } 07072 /* if we are not sending RPID and user wants his callerid restricted */ 07073 if (!ast_test_flag(&p->flags[0], SIP_SENDRPID) && 07074 ((p->callingpres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED)) { 07075 l = CALLERID_UNKNOWN; 07076 n = l; 07077 } 07078 if (ast_strlen_zero(l)) 07079 l = default_callerid; 07080 if (ast_strlen_zero(n)) 07081 n = l; 07082 /* Allow user to be overridden */ 07083 if (!ast_strlen_zero(p->fromuser)) 07084 l = p->fromuser; 07085 else /* Save for any further attempts */ 07086 ast_string_field_set(p, fromuser, l); 07087 07088 /* Allow user to be overridden */ 07089 if (!ast_strlen_zero(p->fromname)) 07090 n = p->fromname; 07091 else /* Save for any further attempts */ 07092 ast_string_field_set(p, fromname, n); 07093 07094 if (pedanticsipchecking) { 07095 ast_uri_encode(n, tmp, sizeof(tmp), 0); 07096 n = tmp; 07097 ast_uri_encode(l, tmp2, sizeof(tmp2), 0); 07098 l = tmp2; 07099 } 07100 07101 if (ourport != STANDARD_SIP_PORT && ast_strlen_zero(p->fromdomain)) 07102 snprintf(from, sizeof(from), "\"%s\" <sip:%s@%s:%d>;tag=%s", n, l, S_OR(p->fromdomain, ast_inet_ntoa(p->ourip)), ourport, p->tag); 07103 else 07104 snprintf(from, sizeof(from), "\"%s\" <sip:%s@%s>;tag=%s", n, l, S_OR(p->fromdomain, ast_inet_ntoa(p->ourip)), p->tag); 07105 07106 /* If we're calling a registered SIP peer, use the fullcontact to dial to the peer */ 07107 if (!ast_strlen_zero(p->fullcontact)) { 07108 /* If we have full contact, trust it */ 07109 ast_build_string(&invite, &invite_max, "%s", p->fullcontact); 07110 } else { 07111 /* Otherwise, use the username while waiting for registration */ 07112 ast_build_string(&invite, &invite_max, "sip:"); 07113 if (!ast_strlen_zero(p->username)) { 07114 n = p->username; 07115 if (pedanticsipchecking) { 07116 ast_uri_encode(n, tmp, sizeof(tmp), 0); 07117 n = tmp; 07118 } 07119 ast_build_string(&invite, &invite_max, "%s@", n); 07120 } 07121 ast_build_string(&invite, &invite_max, "%s", p->tohost); 07122 if (ntohs(p->sa.sin_port) != STANDARD_SIP_PORT) 07123 ast_build_string(&invite, &invite_max, ":%d", ntohs(p->sa.sin_port)); 07124 ast_build_string(&invite, &invite_max, "%s", urioptions); 07125 } 07126 07127 /* If custom URI options have been provided, append them */ 07128 if (p->options && !ast_strlen_zero(p->options->uri_options)) 07129 ast_build_string(&invite, &invite_max, ";%s", p->options->uri_options); 07130 07131 ast_string_field_set(p, uri, invite_buf); 07132 07133 if (sipmethod == SIP_NOTIFY && !ast_strlen_zero(p->theirtag)) { 07134 /* If this is a NOTIFY, use the From: tag in the subscribe (RFC 3265) */ 07135 snprintf(to, sizeof(to), "<%s%s>;tag=%s", (!strncasecmp(p->uri, "sip:", 4) ? "" : "sip:"), p->uri, p->theirtag); 07136 } else if (p->options && p->options->vxml_url) { 07137 /* If there is a VXML URL append it to the SIP URL */ 07138 snprintf(to, sizeof(to), "<%s>;%s", p->uri, p->options->vxml_url); 07139 } else 07140 snprintf(to, sizeof(to), "<%s>", p->uri); 07141 07142 init_req(req, sipmethod, p->uri); 07143 snprintf(tmp, sizeof(tmp), "%d %s", ++p->ocseq, sip_methods[sipmethod].text); 07144 07145 add_header(req, "Via", p->via); 07146 /* SLD: FIXME?: do Route: here too? I think not cos this is the first request. 07147 * OTOH, then we won't have anything in p->route anyway */ 07148 /* Build Remote Party-ID and From */ 07149 if (ast_test_flag(&p->flags[0], SIP_SENDRPID) && (sipmethod == SIP_INVITE)) { 07150 build_rpid(p); 07151 add_header(req, "From", p->rpid_from); 07152 } else 07153 add_header(req, "From", from); 07154 add_header(req, "To", to); 07155 ast_string_field_set(p, exten, l); 07156 build_contact(p); 07157 add_header(req, "Contact", p->our_contact); 07158 add_header(req, "Call-ID", p->callid); 07159 add_header(req, "CSeq", tmp); 07160 if (!ast_strlen_zero(global_useragent)) 07161 add_header(req, "User-Agent", global_useragent); 07162 add_header(req, "Max-Forwards", DEFAULT_MAX_FORWARDS); 07163 if (!ast_strlen_zero(p->rpid)) 07164 add_header(req, "Remote-Party-ID", p->rpid); 07165 }
| static const char * insecure2str | ( | int | port, | |
| int | invite | |||
| ) | [static] |
Convert Insecure setting to printable string.
Definition at line 10257 of file chan_sip.c.
Referenced by _sip_show_peer().
10258 { 10259 if (port && invite) 10260 return "port,invite"; 10261 else if (port) 10262 return "port"; 10263 else if (invite) 10264 return "invite"; 10265 else 10266 return "no"; 10267 }
| static void list_route | ( | struct sip_route * | route | ) | [static] |
List all routes - mostly for debugging.
Definition at line 8391 of file chan_sip.c.
References ast_verbose(), sip_route::hop, and sip_route::next.
Referenced by build_route().
08392 { 08393 if (!route) 08394 ast_verbose("list_route: no route\n"); 08395 else { 08396 for (;route; route = route->next) 08397 ast_verbose("list_route: hop: <%s>\n", route->hop); 08398 } 08399 }
| static int load_module | ( | void | ) | [static] |
PBX load module - initialization.
Definition at line 18638 of file chan_sip.c.
References ast_channel_register(), ast_cli_register_multiple(), ast_custom_function_register(), ast_log(), ast_manager_register2(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_register_application(), ast_rtp_proto_register(), ast_udptl_proto_register(), ASTOBJ_CONTAINER_INIT, CHANNEL_MODULE_LOAD, checksipdomain_function, EVENT_FLAG_SYSTEM, io_context_create(), io_context_destroy(), LOG_ERROR, manager_sip_show_peer(), manager_sip_show_peers(), peerl, regl, reload_config(), restart_monitor(), sched_context_create(), sched_context_destroy(), sip_addheader(), sip_dtmfmode(), sip_header_function, sip_poke_all_peers(), sip_send_all_registers(), sipchaninfo_function, sippeer_function, and userl.
18639 { 18640 ASTOBJ_CONTAINER_INIT(&userl); /* User object list */ 18641 ASTOBJ_CONTAINER_INIT(&peerl); /* Peer object list */ 18642 ASTOBJ_CONTAINER_INIT(®l); /* Registry object list */ 18643 18644 if (!(sched = sched_context_create())) { 18645 ast_log(LOG_ERROR, "Unable to create scheduler context\n"); 18646 return AST_MODULE_LOAD_FAILURE; 18647 } 18648 18649 if (!(io = io_context_create())) { 18650 ast_log(LOG_ERROR, "Unable to create I/O context\n"); 18651 sched_context_destroy(sched); 18652 return AST_MODULE_LOAD_FAILURE; 18653 } 18654 18655 sip_reloadreason = CHANNEL_MODULE_LOAD; 18656 18657 if(reload_config(sip_reloadreason)) /* Load the configuration from sip.conf */ 18658 return AST_MODULE_LOAD_DECLINE; 18659 18660 /* Make sure we can register our sip channel type */ 18661 if (ast_channel_register(&sip_tech)) { 18662 ast_log(LOG_ERROR, "Unable to register channel type 'SIP'\n"); 18663 io_context_destroy(io); 18664 sched_context_destroy(sched); 18665 return AST_MODULE_LOAD_FAILURE; 18666 } 18667 18668 /* Register all CLI functions for SIP */ 18669 ast_cli_register_multiple(cli_sip, sizeof(cli_sip)/ sizeof(struct ast_cli_entry)); 18670 18671 /* Tell the RTP subdriver that we're here */ 18672 ast_rtp_proto_register(&sip_rtp); 18673 18674 /* Tell the UDPTL subdriver that we're here */ 18675 ast_udptl_proto_register(&sip_udptl); 18676 18677 /* Register dialplan applications */ 18678 ast_register_application(app_dtmfmode, sip_dtmfmode, synopsis_dtmfmode, descrip_dtmfmode); 18679 ast_register_application(app_sipaddheader, sip_addheader, synopsis_sipaddheader, descrip_sipaddheader); 18680 18681 /* Register dialplan functions */ 18682 ast_custom_function_register(&sip_header_function); 18683 ast_custom_function_register(&sippeer_function); 18684 ast_custom_function_register(&sipchaninfo_function); 18685 ast_custom_function_register(&checksipdomain_function); 18686 18687 /* Register manager commands */ 18688 ast_manager_register2("SIPpeers", EVENT_FLAG_SYSTEM, manager_sip_show_peers, 18689 "List SIP peers (text format)", mandescr_show_peers); 18690 ast_manager_register2("SIPshowpeer", EVENT_FLAG_SYSTEM, manager_sip_show_peer, 18691 "Show SIP peer (text format)", mandescr_show_peer); 18692 18693 sip_poke_all_peers(); 18694 sip_send_all_registers(); 18695 18696 /* And start the monitor for the first time */ 18697 restart_monitor(); 18698 18699 return AST_MODULE_LOAD_SUCCESS; 18700 }
| static int local_attended_transfer | ( | struct sip_pvt * | transferer, | |
| struct sip_dual * | current, | |||
| struct sip_request * | req, | |||
| int | seqno | |||
| ) | [static] |
Find all call legs and bridge transferee with target called from handle_request_refer.
Definition at line 14722 of file chan_sip.c.
References ast_channel::_state, append_history, ast_bridged_channel(), ast_channel_unlock, ast_clear_flag, ast_hangup(), ast_log(), ast_mutex_unlock(), ast_set_flag, ast_state2str(), AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, attempt_transfer(), sip_dual::chan1, sip_dual::chan2, sip_pvt::flags, get_sip_pvt_byid_locked(), sip_refer::localtransfer, sip_pvt::lock, LOG_DEBUG, ast_channel::name, option_debug, sip_pvt::owner, sip_pvt::refer, REFER_200OK, REFER_FAILED, sip_refer::replaces_callid, sip_refer::replaces_callid_fromtag, sip_refer::replaces_callid_totag, SIP_DEFER_BYE_ON_TRANSFER, SIP_GOTREFER, sipdebug, sip_refer::status, transmit_notify_with_sipfrag(), transmit_response(), and TRUE.
Referenced by handle_request_refer().
14723 { 14724 struct sip_dual target; /* Chan 1: Call from tranferer to Asterisk */ 14725 /* Chan 2: Call from Asterisk to target */ 14726 int res = 0; 14727 struct sip_pvt *targetcall_pvt; 14728 14729 /* Check if the call ID of the replaces header does exist locally */ 14730 if (!(targetcall_pvt = get_sip_pvt_byid_locked(transferer->refer->replaces_callid, transferer->refer->replaces_callid_totag, 14731 transferer->refer->replaces_callid_fromtag))) { 14732 if (transferer->refer->localtransfer) { 14733 /* We did not find the refered call. Sorry, can't accept then */ 14734 transmit_response(transferer, "202 Accepted", req); 14735 /* Let's fake a response from someone else in order 14736 to follow the standard */ 14737 transmit_notify_with_sipfrag(transferer, seqno, "481 Call leg/transaction does not exist", TRUE); 14738 append_history(transferer, "Xfer", "Refer failed"); 14739 ast_clear_flag(&transferer->flags[0], SIP_GOTREFER); 14740 transferer->refer->status = REFER_FAILED; 14741 return -1; 14742 } 14743 /* Fall through for remote transfers that we did not find locally */ 14744 if (option_debug > 2) 14745 ast_log(LOG_DEBUG, "SIP attended transfer: Not our call - generating INVITE with replaces\n"); 14746 return 0; 14747 } 14748 14749 /* Ok, we can accept this transfer */ 14750 transmit_response(transferer, "202 Accepted", req); 14751 append_history(transferer, "Xfer", "Refer accepted"); 14752 if (!targetcall_pvt->owner) { /* No active channel */ 14753 if (option_debug > 3) 14754 ast_log(LOG_DEBUG, "SIP attended transfer: Error: No owner of target call\n"); 14755 /* Cancel transfer */ 14756 transmit_notify_with_sipfrag(transferer, seqno, "503 Service Unavailable", TRUE); 14757 append_history(transferer, "Xfer", "Refer failed"); 14758 ast_clear_flag(&transferer->flags[0], SIP_GOTREFER); 14759 transferer->refer->status = REFER_FAILED; 14760 ast_mutex_unlock(&targetcall_pvt->lock); 14761 ast_channel_unlock(current->chan1); 14762 return -1; 14763 } 14764 14765 /* We have a channel, find the bridge */ 14766 target.chan1 = targetcall_pvt->owner; /* Transferer to Asterisk */ 14767 target.chan2 = ast_bridged_channel(targetcall_pvt->owner); /* Asterisk to target */ 14768 14769 if (!target.chan2 || !(target.chan2->_state == AST_STATE_UP || target.chan2->_state == AST_STATE_RINGING) ) { 14770 /* Wrong state of new channel */ 14771 if (option_debug > 3) { 14772 if (target.chan2) 14773 ast_log(LOG_DEBUG, "SIP attended transfer: Error: Wrong state of target call: %s\n", ast_state2str(target.chan2->_state)); 14774 else if (target.chan1->_state != AST_STATE_RING) 14775 ast_log(LOG_DEBUG, "SIP attended transfer: Error: No target channel\n"); 14776 else 14777 ast_log(LOG_DEBUG, "SIP attended transfer: Attempting transfer in ringing state\n"); 14778 } 14779 } 14780 14781 /* Transfer */ 14782 if (option_debug > 3 && sipdebug) { 14783 if (current->chan2) /* We have two bridges */ 14784 ast_log(LOG_DEBUG, "SIP attended transfer: trying to bridge %s and %s\n", target.chan1->name, current->chan2->name); 14785 else /* One bridge, propably transfer of IVR/voicemail etc */ 14786 ast_log(LOG_DEBUG, "SIP attended transfer: trying to make %s take over (masq) %s\n", target.chan1->name, current->chan1->name); 14787 } 14788 14789 ast_set_flag(&transferer->flags[0], SIP_DEFER_BYE_ON_TRANSFER); /* Delay hangup */ 14790 14791 /* Perform the transfer */ 14792 res = attempt_transfer(current, &target); 14793 ast_mutex_unlock(&targetcall_pvt->lock); 14794 if (res) { 14795 /* Failed transfer */ 14796 transmit_notify_with_sipfrag(transferer, seqno, "486 Busy Here", TRUE); 14797 append_history(transferer, "Xfer", "Refer failed"); 14798 transferer->refer->status = REFER_FAILED; 14799 if (targetcall_pvt->owner) 14800 ast_channel_unlock(targetcall_pvt->owner); 14801 /* Right now, we have to hangup, sorry. Bridge is destroyed */ 14802 if (res != -2) 14803 ast_hangup(transferer->owner); 14804 else 14805 ast_clear_flag(&transferer->flags[0], SIP_DEFER_BYE_ON_TRANSFER); 14806 } else { 14807 /* Transfer succeeded! */ 14808 14809 /* Tell transferer that we're done. */ 14810 transmit_notify_with_sipfrag(transferer, seqno, "200 OK", TRUE); 14811 append_history(transferer, "Xfer", "Refer succeeded"); 14812 transferer->refer->status = REFER_200OK; 14813 if (targetcall_pvt->owner) { 14814 if (option_debug) 14815 ast_log(LOG_DEBUG, "SIP attended transfer: Unlocking channel %s\n", targetcall_pvt->owner->name); 14816 ast_channel_unlock(targetcall_pvt->owner); 14817 } 14818 } 14819 return 1; 14820 }
| static int lws2sws | ( | char * | msgbuf, | |
| int | len | |||
| ) | [static] |
Parse multiline SIP headers into one header This is enabled if pedanticsipchecking is enabled.
Definition at line 4817 of file chan_sip.c.
References t.
Referenced by sipsock_read().
04818 { 04819 int h = 0, t = 0; 04820 int lws = 0; 04821 04822 for (; h < len;) { 04823 /* Eliminate all CRs */ 04824 if (msgbuf[h] == '\r') { 04825 h++; 04826 continue; 04827 } 04828 /* Check for end-of-line */ 04829 if (msgbuf[h] == '\n') { 04830 /* Check for end-of-message */ 04831 if (h + 1 == len) 04832 break; 04833 /* Check for a continuation line */ 04834 if (msgbuf[h + 1] == ' ' || msgbuf[h + 1] == '\t') { 04835 /* Merge continuation line */ 04836 h++; 04837 continue; 04838 } 04839 /* Propagate LF and start new line */ 04840 msgbuf[t++] = msgbuf[h++]; 04841 lws = 0; 04842 continue; 04843 } 04844 if (msgbuf[h] == ' ' || msgbuf[h] == '\t') { 04845 if (lws) { 04846 h++; 04847 continue; 04848 } 04849 msgbuf[t++] = msgbuf[h++]; 04850 lws = 1; 04851 continue; 04852 } 04853 msgbuf[t++] = msgbuf[h++]; 04854 if (lws) 04855 lws = 0; 04856 } 04857 msgbuf[t] = '\0'; 04858 return t; 04859 }
| static void make_our_tag | ( | char * | tagbuf, | |
| size_t | len | |||
| ) | [static] |
Make our SIP dialog tag.
Definition at line 4485 of file chan_sip.c.
References ast_random().
Referenced by handle_request_invite(), handle_request_subscribe(), sip_alloc(), transmit_register(), and transmit_response_using_temp().
04486 { 04487 snprintf(tagbuf, len, "as%08lx", ast_random()); 04488 }
| static int manager_sip_show_peer | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Show SIP peers in the manager API.
Definition at line 10502 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().
10503 { 10504 const char *a[4]; 10505 const char *peer; 10506 int ret; 10507 10508 peer = astman_get_header(m,"Peer"); 10509 if (ast_strlen_zero(peer)) { 10510 astman_send_error(s, m, "Peer: <name> missing."); 10511 return 0; 10512 } 10513 a[0] = "sip"; 10514 a[1] = "show"; 10515 a[2] = "peer"; 10516 a[3] = peer; 10517 10518 ret = _sip_show_peer(1, -1, s, m, 4, a); 10519 astman_append(s, "\r\n\r\n" ); 10520 return ret; 10521 }
| static int manager_sip_show_peers | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Show SIP peers in the manager API.
Definition at line 10053 of file chan_sip.c.
References _sip_show_peers(), ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_ack(), and total.
Referenced by load_module().
10054 { 10055 const char *id = astman_get_header(m,"ActionID"); 10056 const char *a[] = {"sip", "show", "peers"}; 10057 char idtext[256] = ""; 10058 int total = 0; 10059 10060 if (!ast_strlen_zero(id)) 10061 snprintf(idtext, sizeof(idtext), "ActionID: %s\r\n", id); 10062 10063 astman_send_ack(s, m, "Peer status list will follow"); 10064 /* List the peers in separate manager events */ 10065 _sip_show_peers(-1, &total, s, m, 3, a); 10066 /* Send final confirmation */ 10067 astman_append(s, 10068 "Event: PeerlistComplete\r\n" 10069 "ListItems: %d\r\n" 10070 "%s" 10071 "\r\n", total, idtext); 10072 return 0; 10073 }
| 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 1682 of file chan_sip.c.
References len(), sip_methods, and text.
Referenced by __sip_semi_ack(), and find_sip_method().
01683 { 01684 int len = strlen(sip_methods[id].text); 01685 int l_name = name ? strlen(name) : 0; 01686 /* true if the string is long enough, and ends with whitespace, and matches */ 01687 return (l_name >= len && name[len] < 33 && 01688 !strncasecmp(sip_methods[id].text, name, len)); 01689 }
| static char * nat2str | ( | int | nat | ) | [static] |
Convert NAT setting to text string.
Definition at line 9956 of file chan_sip.c.
References SIP_NAT_ALWAYS, SIP_NAT_NEVER, SIP_NAT_RFC3581, and SIP_NAT_ROUTE.
Referenced by _sip_show_peer(), sip_show_channel(), sip_show_settings(), and sip_show_users().
09957 { 09958 switch(nat) { 09959 case SIP_NAT_NEVER: 09960 return "No"; 09961 case SIP_NAT_ROUTE: 09962 return "Route"; 09963 case SIP_NAT_ALWAYS: 09964 return "Always"; 09965 case SIP_NAT_RFC3581: 09966 return "RFC3581"; 09967 default: 09968 return "Unknown"; 09969 } 09970 }
| static void parse_copy | ( | struct sip_request * | dst, | |
| const struct sip_request * | src | |||
| ) | [static] |
Copy SIP request, parse it.
Definition at line 2261 of file chan_sip.c.
References sip_request::data, sip_request::len, and parse_request().
Referenced by send_request(), and send_response().
02262 { 02263 memset(dst, 0, sizeof(*dst)); 02264 memcpy(dst->data, src->data, sizeof(dst->data)); 02265 dst->len = src->len; 02266 parse_request(dst); 02267 }
| static void parse_moved_contact | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Parse 302 Moved temporalily response.
Definition at line 12154 of file chan_sip.c.
References ast_copy_string(), ast_log(), ast_strdupa, ast_string_field_build, ast_string_field_set, ast_test_flag, sip_pvt::flags, get_header(), get_in_brackets(), LOG_DEBUG, option_debug, sip_pvt::owner, pbx_builtin_setvar_helper(), s, SIP_PROMISCREDIR, SIPBUFSIZE, and t.
Referenced by handle_response().
12155 { 12156 char tmp[SIPBUFSIZE]; 12157 char *s, *e, *uri, *t; 12158 char *domain; 12159 12160 ast_copy_string(tmp, get_header(req, "Contact"), sizeof(tmp)); 12161 if ((t = strchr(tmp, ','))) 12162 *t = '\0'; 12163 s = get_in_brackets(tmp); 12164 uri = ast_strdupa(s); 12165 if (ast_test_flag(&p->flags[0], SIP_PROMISCREDIR)) { 12166 if (!strncasecmp(s, "sip:", 4)) 12167 s += 4; 12168 e = strchr(s, ';'); 12169 if (e) 12170 *e = '\0'; 12171 if (option_debug) 12172 ast_log(LOG_DEBUG, "Found promiscuous redirection to 'SIP/%s'\n", s); 12173 if (p->owner) 12174 ast_string_field_build(p->owner, call_forward, "SIP/%s", s); 12175 } else { 12176 e = strchr(tmp, '@'); 12177 if (e) { 12178 *e++ = '\0'; 12179 domain = e; 12180 } else { 12181 /* No username part */ 12182 domain = tmp; 12183 } 12184 e = strchr(s, ';'); /* Strip of parameters in the username part */ 12185 if (e) 12186 *e = '\0'; 12187 e = strchr(domain, ';'); /* Strip of parameters in the domain part */ 12188 if (e) 12189 *e = '\0'; 12190 12191 if (!strncasecmp(s, "sip:", 4)) 12192 s += 4; 12193 if (option_debug > 1) 12194 ast_log(LOG_DEBUG, "Received 302 Redirect to extension '%s' (domain %s)\n", s, domain); 12195 if (p->owner) { 12196 pbx_builtin_setvar_helper(p->owner, "SIPREDIRECTURI", uri); 12197 pbx_builtin_setvar_helper(p->owner, "SIPDOMAIN", domain); 12198 ast_string_field_set(p->owner, call_forward, s); 12199 } 12200 } 12201 }
| 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 8120 of file chan_sip.c.
References ast_copy_string(), ast_string_field_set, sip_peer::fullcontact, get_header(), get_in_brackets(), SIPBUFSIZE, and TRUE.
Referenced by handle_request_invite(), handle_request_subscribe(), and handle_response_invite().
08121 { 08122 char contact[SIPBUFSIZE]; 08123 char *c; 08124 08125 /* Look for brackets */ 08126 ast_copy_string(contact, get_header(req, "Contact"), sizeof(contact)); 08127 c = get_in_brackets(contact); 08128 08129 /* Save full contact to call pvt for later bye or re-invite */ 08130 ast_string_field_set(pvt, fullcontact, c); 08131 08132 /* Save URI for later ACKs, BYE or RE-invites */ 08133 ast_string_field_set(pvt, okcontacturi, c); 08134 08135 /* We should return false for URI:s we can't handle, 08136 like sips:, tel:, mailto:,ldap: etc */ 08137 return TRUE; 08138 }
| 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 8209 of file chan_sip.c.
References sip_peer::addr, ast_apply_ha(), ast_copy_string(), ast_db_put(), ast_gethostbyname(), ast_inet_ntoa(), ast_log(), ast_sched_add(), AST_SCHED_DEL, ast_sched_when(), AST_SENSE_ALLOW, ast_string_field_build, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_verbose(), ASTOBJ_REF, ASTOBJ_UNREF, sip_peer::contactha, destroy_association(), EVENT_FLAG_SYSTEM, sip_peer::expire, expire_register(), sip_pvt::expiry, sip_peer::flags, sip_peer::fullcontact, get_header(), get_in_brackets(), hp, inaddrcmp(), sip_peer::lastms, LOG_NOTICE, LOG_WARNING, manager_event(), sip_peer::name, option_verbose, PARSE_REGISTER_FAILED, PARSE_REGISTER_QUERY, PARSE_REGISTER_UPDATE, sip_pvt::recv, register_peer_exten(), sip_destroy_peer(), SIP_NAT_ROUTE, SIP_PAGE2_RT_FROMCONTACT, SIP_PAGE2_RTCACHEFRIENDS, sip_poke_peer(), SIP_REALTIME, SIPBUFSIZE, sip_pvt::sipoptions, sip_peer::sipoptions, STANDARD_SIP_PORT, sip_peer::useragent, sip_peer::username, and VERBOSE_PREFIX_3.
Referenced by register_verify().
08210 { 08211 char contact[SIPBUFSIZE]; 08212 char data[SIPBUFSIZE]; 08213 const char *expires = get_header(req, "Expires"); 08214 int expiry = atoi(expires); 08215 char *curi, *n, *pt; 08216 int port; 08217 const char *useragent; 08218 struct hostent *hp; 08219 struct ast_hostent ahp; 08220 struct sockaddr_in oldsin, testsin; 08221 08222 ast_copy_string(contact, get_header(req, "Contact"), sizeof(contact)); 08223 08224 if (ast_strlen_zero(expires)) { /* No expires header */ 08225 expires = strcasestr(contact, ";expires="); 08226 if (expires) { 08227 /* XXX bug here, we overwrite the string */ 08228 expires = strsep((char **) &expires, ";"); /* trim ; and beyond */ 08229 if (sscanf(expires + 9, "%d", &expiry) != 1) 08230 expiry = default_expiry; 08231 } else { 08232 /* Nothing has been specified */ 08233 expiry = default_expiry; 08234 } 08235 } 08236 08237 /* Look for brackets */ 08238 curi = contact; 08239 if (strchr(contact, '<') == NULL) /* No <, check for ; and strip it */ 08240 strsep(&curi, ";"); /* This is Header options, not URI options */ 08241 curi = get_in_brackets(contact); 08242 08243 /* if they did not specify Contact: or Expires:, they are querying 08244 what we currently have stored as their contact address, so return 08245 it 08246 */ 08247 if (ast_strlen_zero(curi) && ast_strlen_zero(expires)) { 08248 /* If we have an active registration, tell them when the registration is going to expire */ 08249 if (peer->expire > -1 && !ast_strlen_zero(peer->fullcontact)) 08250 pvt->expiry = ast_sched_when(sched, peer->expire); 08251 return PARSE_REGISTER_QUERY; 08252 } else if (!strcasecmp(curi, "*") || !expiry) { /* Unregister this peer */ 08253 /* This means remove all registrations and return OK */ 08254 memset(&peer->addr, 0, sizeof(peer->addr)); 08255 if (!AST_SCHED_DEL(sched, peer->expire)) { 08256 struct sip_peer *peer_ptr = peer; 08257 ASTOBJ_UNREF(peer_ptr, sip_destroy_peer); 08258 } 08259 08260 destroy_association(peer); 08261 08262 register_peer_exten(peer, 0); /* Add extension from regexten= setting in sip.conf */ 08263 peer->fullcontact[0] = '\0'; 08264 peer->useragent[0] = '\0'; 08265 peer->sipoptions = 0; 08266 peer->lastms = 0; 08267 pvt->expiry = 0; 08268 08269 if (option_verbose > 2) 08270 ast_verbose(VERBOSE_PREFIX_3 "Unregistered SIP '%s'\n", peer->name); 08271 08272 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: SIP/%s\r\nPeerStatus: Unregistered\r\n", peer->name); 08273 return PARSE_REGISTER_UPDATE; 08274 } 08275 08276 /* Store whatever we got as a contact from the client */ 08277 ast_copy_string(peer->fullcontact, curi, sizeof(peer->fullcontact)); 08278 08279 /* For the 200 OK, we should use the received contact */ 08280 ast_string_field_build(pvt, our_contact, "<%s>", curi); 08281 08282 /* Make sure it's a SIP URL */ 08283 if (strncasecmp(curi, "sip:", 4)) { 08284 ast_log(LOG_NOTICE, "'%s' is not a valid SIP contact (missing sip:) trying to use anyway\n", curi); 08285 } else 08286 curi += 4; 08287 /* Ditch q */ 08288 curi = strsep(&curi, ";"); 08289 /* Grab host */ 08290 n = strchr(curi, '@'); 08291 if (!n) { 08292 n = curi; 08293 curi = NULL; 08294 } else 08295 *n++ = '\0'; 08296 pt = strchr(n, ':'); 08297 if (pt) { 08298 *pt++ = '\0'; 08299 port = atoi(pt); 08300 } else 08301 port = STANDARD_SIP_PORT; 08302 oldsin = peer->addr; 08303 08304 /* Check that they're allowed to register at this IP */ 08305 /* XXX This could block for a long time XXX */ 08306 hp = ast_gethostbyname(n, &ahp); 08307 if (!hp) { 08308 ast_log(LOG_WARNING, "Invalid host '%s'\n", n); 08309 *peer->fullcontact = '\0'; 08310 ast_string_field_set(pvt, our_contact, ""); 08311 return PARSE_REGISTER_FAILED; 08312 } 08313 memcpy(&testsin.sin_addr, hp->h_addr, sizeof(testsin.sin_addr)); 08314 if ( ast_apply_ha(global_contact_ha, &testsin) != AST_SENSE_ALLOW || 08315 ast_apply_ha(peer->contactha, &testsin) != AST_SENSE_ALLOW) { 08316 ast_log(LOG_WARNING, "Host '%s' disallowed by rule\n", n); 08317 *peer->fullcontact = '\0'; 08318 ast_string_field_set(pvt, our_contact, ""); 08319 return PARSE_REGISTER_FAILED; 08320 } 08321 08322 if (!ast_test_flag(&peer->flags[0], SIP_NAT_ROUTE)) { 08323 peer->addr.sin_family = AF_INET; 08324 memcpy(&peer->addr.sin_addr, hp->h_addr, sizeof(peer->addr.sin_addr)); 08325 peer->addr.sin_port = htons(port); 08326 } else { 08327 /* Don't trust the contact field. Just use what they came to us 08328 with */ 08329 peer->addr = pvt->recv; 08330 } 08331 08332 /* Save SIP options profile */ 08333 peer->sipoptions = pvt->sipoptions; 08334 08335 if (curi && ast_strlen_zero(peer->username)) 08336 ast_copy_string(peer->username, curi, sizeof(peer->username)); 08337 08338 if (!AST_SCHED_DEL(sched, peer->expire)) { 08339 struct sip_peer *peer_ptr = peer; 08340 ASTOBJ_UNREF(peer_ptr, sip_destroy_peer); 08341 } 08342 if (expiry > max_expiry) 08343 expiry = max_expiry; 08344 if (expiry < min_expiry) 08345 expiry = min_expiry; 08346 if (ast_test_flag(&peer->flags[0], SIP_REALTIME) && !ast_test_flag(&peer->flags[1], SIP_PAGE2_RTCACHEFRIENDS)) { 08347 peer->expire = -1; 08348 } else { 08349 peer->expire = ast_sched_add(sched, (expiry + 10) * 1000, expire_register, ASTOBJ_REF(peer)); 08350 if (peer->expire == -1) { 08351 struct sip_peer *peer_ptr = peer; 08352 ASTOBJ_UNREF(peer_ptr, sip_destroy_peer); 08353 } 08354 } 08355 pvt->expiry = expiry; 08356 snprintf(data, sizeof(data), "%s:%d:%d:%s:%s", ast_inet_ntoa(peer->addr.sin_addr), ntohs(peer->addr.sin_port), expiry, peer->username, peer->fullcontact); 08357 if (!ast_test_flag(&peer->flags[1], SIP_PAGE2_RT_FROMCONTACT)) 08358 ast_db_put("SIP/Registry", peer->name, data); 08359 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: SIP/%s\r\nPeerStatus: Registered\r\n", peer->name); 08360 08361 /* Is this a new IP address for us? */ 08362 if (option_verbose > 2 && inaddrcmp(&peer->addr, &oldsin)) { 08363 ast_verbose(VERBOSE_PREFIX_3 "Registered SIP '%s' at %s port %d\n", peer->name, ast_inet_ntoa(peer->addr.sin_addr), ntohs(peer->addr.sin_port)); 08364 } 08365 sip_poke_peer(peer); 08366 register_peer_exten(peer, 1); 08367 08368 /* Save User agent */ 08369 useragent = get_header(req, "User-Agent"); 08370 if (strcasecmp(useragent, peer->useragent)) { /* XXX copy if they are different ? */ 08371 ast_copy_string(peer->useragent, useragent, sizeof(peer->useragent)); 08372 if (option_verbose > 3) 08373 ast_verbose(VERBOSE_PREFIX_3 "Saved useragent \"%s\" for peer %s\n", peer->useragent, peer->name); 08374 } 08375 return PARSE_REGISTER_UPDATE; 08376 }
| static int parse_request | ( | struct sip_request * | req | ) | [static] |
Parse a SIP message.
Definition at line 4864 of file chan_sip.c.
References ast_log(), ast_strlen_zero(), sip_request::data, determine_firstline_parts(), f, sip_request::header, sip_request::headers, sip_request::line, sip_request::lines, LOG_DEBUG, LOG_WARNING, option_debug, SIP_MAX_HEADERS, SIP_MAX_LINES, and sipdebug.
Referenced by initialize_initreq(), parse_copy(), and sipsock_read().
04865 { 04866 /* Divide fields by NULL's */ 04867 char *c; 04868 int f = 0; 04869 04870 c = req->data; 04871 04872 /* First header starts immediately */ 04873 req->header[f] = c; 04874 while(*c) { 04875 if (*c == '\n') { 04876 /* We've got a new header */ 04877 *c = 0; 04878 04879 if (sipdebug && option_debug > 3) 04880 ast_log(LOG_DEBUG, "Header %d: %s (%d)\n", f, req->header[f], (int) strlen(req->header[f])); 04881 if (ast_strlen_zero(req->header[f])) { 04882 /* Line by itself means we're now in content */ 04883 c++; 04884 break; 04885 } 04886 if (f >= SIP_MAX_HEADERS - 1) { 04887 ast_log(LOG_WARNING, "Too many SIP headers. Ignoring.\n"); 04888 } else { 04889 f++; 04890 req->header[f] = c + 1; 04891 } 04892 } else if (*c == '\r') { 04893 /* Ignore but eliminate \r's */ 04894 *c = 0; 04895 } 04896 c++; 04897 } 04898 04899 req->headers = f; 04900 04901 /* Check a non-newline-terminated last header */ 04902 if (!ast_strlen_zero(req->header[f])) { 04903 if (sipdebug && option_debug > 3) 04904 ast_log(LOG_DEBUG, "Header %d: %s (%d)\n", f, req->header[f], (int) strlen(req->header[f])); 04905 req->headers++; 04906 } 04907 04908 /* Now we process any body content */ 04909 f = 0; 04910 req->line[f] = c; 04911 while (*c) { 04912 if (*c == '\n') { 04913 /* We've got a new line */ 04914 *c = 0; 04915 if (sipdebug && option_debug > 3) 04916 ast_log(LOG_DEBUG, "Line: %s (%d)\n", req->line[f], (int) strlen(req->line[f])); 04917 if (f == SIP_MAX_LINES - 1) { 04918 ast_log(LOG_WARNING, "Too many SDP lines. Ignoring.\n"); 04919 break; 04920 } else { 04921 f++; 04922 req->line[f] = c + 1; 04923 } 04924 } else if (*c == '\r') { 04925 /* Ignore and eliminate \r's */ 04926 *c = 0; 04927 } 04928 c++; 04929 } 04930 04931 req->lines = f; 04932 04933 /* Check a non-newline-terminated last line */ 04934 if (!ast_strlen_zero(req->line[f])) { 04935 req->lines++; 04936 } 04937 04938 if (*c) 04939 ast_log(LOG_WARNING, "Odd content, extra stuff left over ('%s')\n", c); 04940 04941 /* Split up the first line parts */ 04942 return determine_firstline_parts(req); 04943 }
| static unsigned int parse_sip_options | ( | struct sip_pvt * | pvt, | |
| const char * | supported | |||
| ) | [static] |
Parse supported header in incoming packet.
Definition at line 1706 of file chan_sip.c.
References ast_log(), ast_skip_blanks(), ast_strdupa, ast_strlen_zero(), FALSE, cfsip_options::id, LOG_DEBUG, domain::next, option_debug, sip_options, sipdebug, sip_pvt::sipoptions, text, and TRUE.
Referenced by handle_request_invite().
01707 { 01708 char *next, *sep; 01709 char *temp; 01710 unsigned int profile = 0; 01711 int i, found; 01712 01713 if (ast_strlen_zero(supported) ) 01714 return 0; 01715 temp = ast_strdupa(supported); 01716 01717 if (option_debug > 2 && sipdebug) 01718 ast_log(LOG_DEBUG, "Begin: parsing SIP \"Supported: %s\"\n", supported); 01719 01720 for (next = temp; next; next = sep) { 01721 found = FALSE; 01722 if ( (sep = strchr(next, ',')) != NULL) 01723 *sep++ = '\0'; 01724 next = ast_skip_blanks(next); 01725 if (option_debug > 2 && sipdebug) 01726 ast_log(LOG_DEBUG, "Found SIP option: -%s-\n", next); 01727 for (i=0; i < (sizeof(sip_options) / sizeof(sip_options[0])); i++) { 01728 if (!strcasecmp(next, sip_options[i].text)) { 01729 profile |= sip_options[i].id; 01730 found = TRUE; 01731 if (option_debug > 2 && sipdebug) 01732 ast_log(LOG_DEBUG, "Matched SIP option: %s\n", next); 01733 break; 01734 } 01735 } 01736 if (!found && option_debug > 2 && sipdebug) { 01737 if (!strncasecmp(next, "x-", 2)) 01738 ast_log(LOG_DEBUG, "Found private SIP option, not supported: %s\n", next); 01739 else 01740 ast_log(LOG_DEBUG, "Found no match for SIP option: %s (Please file bug report!)\n", next); 01741 } 01742 } 01743 01744 if (pvt) 01745 pvt->sipoptions = profile; 01746 return profile; 01747 }
| static int peer_status | ( | struct sip_peer * | peer, | |
| char * | status, | |||
| int | statuslen | |||
| ) | [static] |
Report Peer status in character string.
Definition at line 9975 of file chan_sip.c.
References ast_copy_string(), sip_peer::lastms, and sip_peer::maxms.
Referenced by _sip_show_peer(), _sip_show_peers(), and function_sippeer().
09976 { 09977 int res = 0; 09978 if (peer->maxms) { 09979 if (peer->lastms < 0) { 09980 ast_copy_string(status, "UNREACHABLE", statuslen); 09981 } else if (peer->lastms > peer->maxms) { 09982 snprintf(status, statuslen, "LAGGED (%d ms)", peer->lastms); 09983 res = 1; 09984 } else if (peer->lastms) { 09985 snprintf(status, statuslen, "OK (%d ms)", peer->lastms); 09986 res = 1; 09987 } else { 09988 ast_copy_string(status, "UNKNOWN", statuslen); 09989 } 09990 } else { 09991 ast_copy_string(status, "Unmonitored", statuslen); 09992 /* Checking if port is 0 */ 09993 res = -1; 09994 } 09995 return res; 09996 }
| 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 10443 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().
10444 { 10445 int x, codec; 10446 10447 for(x = 0; x < 32 ; x++) { 10448 codec = ast_codec_pref_index(pref, x); 10449 if (!codec) 10450 break; 10451 ast_cli(fd, "%s", ast_getformatname(codec)); 10452 ast_cli(fd, ":%d", pref->framing[x]); 10453 if (x < 31 && ast_codec_pref_index(pref, x + 1)) 10454 ast_cli(fd, ","); 10455 } 10456 if (!x) 10457 ast_cli(fd, "none"); 10458 }
| static void print_group | ( | int | fd, | |
| ast_group_t | group, | |||
| int | crlf | |||
| ) | [static] |
Print call group and pickup group.
Definition at line 10234 of file chan_sip.c.
References ast_cli(), and ast_print_group().
Referenced by _sip_show_peer(), and sip_show_user().
10235 { 10236 char buf[256]; 10237 ast_cli(fd, crlf ? "%s\r\n" : "%s\n", ast_print_group(buf, sizeof(buf), group) ); 10238 }
| static int process_sdp | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Process SIP SDP offer, select formats and activate RTP channels If offer is rejected, we will not change any properties of the call Return 0 on success, a negative value on errors. Must be called after find_sdp().
< RTP Audio port number
< RTP Video port number
< media socket address
< Video socket address
< RTP Audio host IP
< RTP video host IP
Definition at line 5076 of file chan_sip.c.
References ast_clear_flag, ast_codec_choose(), ast_codec_pref_setsize(), AST_CONTROL_HOLD, AST_CONTROL_UNHOLD, AST_FORMAT_AUDIO_MASK, ast_getformatname_multiple(), ast_gethostbyname(), ast_inet_ntoa(), ast_log(), ast_null_frame, ast_queue_control(), ast_queue_control_data(), ast_queue_frame(), ast_rtp_alloc_size(), ast_rtp_codec_getformat(), ast_rtp_codec_getpref(), ast_rtp_codec_setpref(), AST_RTP_DTMF, ast_rtp_get_current_formats(), ast_rtp_get_peer(), ast_rtp_lookup_mime_multiple(), ast_rtp_new_init(), AST_RTP_OPT_G726_NONSTANDARD, ast_rtp_pt_clear(), ast_rtp_pt_copy(), ast_rtp_set_m_type(), ast_rtp_set_peer(), ast_rtp_set_rtpmap_type(), ast_rtp_setdtmf(), ast_rtp_setdtmfcompensate(), ast_rtp_stop(), ast_rtp_unset_m_type(), ast_set_flag, ast_set_read_format(), ast_set_write_format(), ast_skip_blanks(), ast_strdupa, ast_strlen_zero(), ast_test_flag, ast_threadstorage_get(), ast_udptl_set_error_correction_scheme(), ast_udptl_set_far_max_datagram(), ast_udptl_set_local_max_datagram(), ast_udptl_set_peer(), ast_udptl_stop(), ast_verbose(), sip_pvt::autoframing, sip_pvt::callid, sip_pvt::capability, t38properties::capability, change_hold_state(), debug, FALSE, sip_pvt::flags, format, get_sdp(), get_sdp_iterate(), hp, sip_pvt::jointcapability, t38properties::jointcapability, sip_pvt::jointnoncodeccapability, sip_pvt::lastinvite, sip_pvt::lastrtprx, sip_pvt::lastrtptx, len(), LOG_DEBUG, LOG_ERROR, LOG_NOTICE, LOG_WARNING, MAX_RTP_PT, sip_pvt::mohsuggest, ast_channel::name, ast_channel::nativeformats, sip_pvt::noncodeccapability, option_debug, sip_pvt::owner, sip_pvt::peercapability, t38properties::peercapability, portno, sip_pvt::prefs, ast_channel::readformat, sip_pvt::rtp, s, S_OR, SDP_MAX_RTPMAP_CODECS, sip_request::sdp_start, sip_debug_test_pvt(), SIP_DTMF, SIP_DTMF_AUTO, SIP_DTMF_INBAND, SIP_DTMF_RFC2833, SIP_G726_NONSTANDARD, SIP_NAT, SIP_NOVIDEO, SIP_PAGE2_CALL_ONHOLD, SIP_PAGE2_RFC2833_COMPENSATE, SIP_PAGE2_UDPTL_DESTINATION, SIPBUFSIZE, t38properties::state, sip_pvt::t38, T38_DISABLED, T38_PEER_DIRECT, T38_PEER_REINVITE, T38FAX_FILL_BIT_REMOVAL, T38FAX_RATE_12000, T38FAX_RATE_14400, T38FAX_RATE_2400, T38FAX_RATE_4800, T38FAX_RATE_7200, T38FAX_RATE_9600, T38FAX_RATE_MANAGEMENT_LOCAL_TCF, T38FAX_RATE_MANAGEMENT_TRANSFERED_TCF, T38FAX_TRANSCODING_JBIG, T38FAX_TRANSCODING_MMR, T38FAX_UDP_EC_FEC, T38FAX_UDP_EC_NONE, T38FAX_UDP_EC_REDUNDANCY, T38FAX_VERSION_0, T38FAX_VERSION_1, TRUE, sip_pvt::udptl, UDPTL_ERROR_CORRECTION_FEC, UDPTL_ERROR_CORRECTION_NONE, UDPTL_ERROR_CORRECTION_REDUNDANCY, sip_pvt::vrtp, and ast_channel::writeformat.
Referenced by handle_request(), handle_request_invite(), handle_response(), and handle_response_invite().
05077 { 05078 const char *m; /* SDP media offer */ 05079 const char *c; 05080 const char *a; 05081 char host[258]; 05082 int len = -1; 05083 int portno = -1; /*!< RTP Audio port number */ 05084 int vportno = -1; /*!< RTP Video port number */ 05085 int udptlportno = -1; 05086 int peert38capability = 0; 05087 char s[256]; 05088 int old = 0; 05089 05090 /* Peer capability is the capability in the SDP, non codec is RFC2833 DTMF (101) */ 05091 int peercapability = 0, peernoncodeccapability = 0; 05092 int vpeercapability = 0, vpeernoncodeccapability = 0; 05093 struct sockaddr_in sin; /*!< media socket address */ 05094 struct sockaddr_in vsin; /*!< Video socket address */ 05095 05096 const char *codecs; 05097 struct hostent *hp; /*!< RTP Audio host IP */ 05098 struct hostent *vhp = NULL; /*!< RTP video host IP */ 05099 struct ast_hostent audiohp; 05100 struct ast_hostent videohp; 05101 int codec; 05102 int destiterator = 0; 05103 int iterator; 05104 int sendonly = -1; 05105 int numberofports; 05106 struct ast_rtp *newaudiortp, *newvideortp; /* Buffers for codec handling */ 05107 int newjointcapability; /* Negotiated capability */ 05108 int newpeercapability; 05109 int newnoncodeccapability; 05110 int numberofmediastreams = 0; 05111 int debug = sip_debug_test_pvt(p); 05112 05113 int found_rtpmap_codecs[SDP_MAX_RTPMAP_CODECS]; 05114 int last_rtpmap_codec=0; 05115 05116 if (!p->rtp) { 05117 ast_log(LOG_ERROR, "Got SDP but have no RTP session allocated.\n"); 05118 return -1; 05119 } 05120 05121 /* Initialize the temporary RTP structures we use to evaluate the offer from the peer */ 05122 #ifdef LOW_MEMORY 05123 newaudiortp = ast_threadstorage_get(&ts_audio_rtp, ast_rtp_alloc_size()); 05124 #else 05125 newaudiortp = alloca(ast_rtp_alloc_size()); 05126 #endif 05127 memset(newaudiortp, 0, ast_rtp_alloc_size()); 05128 ast_rtp_new_init(newaudiortp); 05129 ast_rtp_pt_clear(newaudiortp); 05130 05131 #ifdef LOW_MEMORY 05132 newvideortp = ast_threadstorage_get(&ts_video_rtp, ast_rtp_alloc_size()); 05133 #else 05134 newvideortp = alloca(ast_rtp_alloc_size()); 05135 #endif 05136 memset(newvideortp, 0, ast_rtp_alloc_size()); 05137 ast_rtp_new_init(newvideortp); 05138 ast_rtp_pt_clear(newvideortp); 05139 05140 /* Update our last rtprx when we receive an SDP, too */ 05141 p->lastrtprx = p->lastrtptx = time(NULL); /* XXX why both ? */ 05142 05143 05144 /* Try to find first media stream */ 05145 m = get_sdp(req, "m"); 05146 destiterator = req->sdp_start; 05147 c = get_sdp_iterate(&destiterator, req, "c"); 05148 if (ast_strlen_zero(m) || ast_strlen_zero(c)) { 05149 ast_log(LOG_WARNING, "Insufficient information for SDP (m = '%s', c = '%s')\n", m, c); 05150 return -1; 05151 } 05152 05153 /* Check for IPv4 address (not IPv6 yet) */ 05154 if (sscanf(c, "IN IP4 %256s", host) != 1) { 05155 ast_log(LOG_WARNING, "Invalid host in c= line, '%s'\n", c); 05156 return -1; 05157 } 05158 05159 /* XXX This could block for a long time, and block the main thread! XXX */ 05160 hp = ast_gethostbyname(host, &audiohp); 05161 if (!hp) { 05162 ast_log(LOG_WARNING, "Unable to lookup host in c= line, '%s'\n", c); 05163 return -1; 05164 } 05165 vhp = hp; /* Copy to video address as default too */ 05166 05167 iterator = req->sdp_start; 05168 ast_set_flag(&p->flags[0], SIP_NOVIDEO); 05169 05170 05171 /* Find media streams in this SDP offer */ 05172 while ((m = get_sdp_iterate(&iterator, req, "m"))[0] != '\0') { 05173 int x; 05174 int audio = FALSE; 05175 05176 numberofports = 1; 05177 len = -1; 05178 if ((sscanf(m, "audio %d/%d RTP/AVP %n", &x, &numberofports, &len) == 2 && len > 0) || 05179 (sscanf(m, "audio %d RTP/AVP %n", &x, &len) == 1 && len > 0)) { 05180 audio = TRUE; 05181 numberofmediastreams++; 05182 /* Found audio stream in this media definition */ 05183 portno = x; 05184 /* Scan through the RTP payload types specified in a "m=" line: */ 05185 for (codecs = m + len; !ast_strlen_zero(codecs); codecs = ast_skip_blanks(codecs + len)) { 05186 if (sscanf(codecs, "%d%n", &codec, &len) != 1) { 05187 ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs); 05188 return -1; 05189 } 05190 if (debug) 05191 ast_verbose("Found RTP audio format %d\n", codec); 05192 ast_rtp_set_m_type(newaudiortp, codec); 05193 } 05194 } else if ((sscanf(m, "video %d/%d RTP/AVP %n", &x, &numberofports, &len) == 2 && len > 0) || 05195 (sscanf(m, "video %d RTP/AVP %n", &x, &len) == 1 && len >= 0)) { 05196 /* If it is not audio - is it video ? */ 05197 ast_clear_flag(&p->flags[0], SIP_NOVIDEO); 05198 numberofmediastreams++; 05199 vportno = x; 05200 /* Scan through the RTP payload types specified in a "m=" line: */ 05201 for (codecs = m + len; !ast_strlen_zero(codecs); codecs = ast_skip_blanks(codecs + len)) { 05202 if (sscanf(codecs, "%d%n", &codec, &len) != 1) { 05203 ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs); 05204 return -1; 05205 } 05206 if (debug) 05207 ast_verbose("Found RTP video format %d\n", codec); 05208 ast_rtp_set_m_type(newvideortp, codec); 05209 } 05210 } else if (p->udptl && ( (sscanf(m, "image %d udptl t38%n", &x, &len) == 1 && len > 0) || 05211 (sscanf(m, "image %d UDPTL t38%n", &x, &len) == 1 && len >= 0) )) { 05212 if (debug) 05213 ast_verbose("Got T.38 offer in SDP in dialog %s\n", p->callid); 05214 udptlportno = x; 05215 numberofmediastreams++; 05216 05217 if (p->owner && p->lastinvite) { 05218 p->t38.state = T38_PEER_REINVITE; /* T38 Offered in re-invite from remote party */ 05219 if (option_debug > 1) 05220 ast_log(LOG_DEBUG, "T38 state changed to %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "<none>" ); 05221 } else { 05222 p->t38.state = T38_PEER_DIRECT; /* T38 Offered directly from peer in first invite */ 05223 if (option_debug > 1) 05224 ast_log(LOG_DEBUG, "T38 state changed to %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "<none>"); 05225 } 05226 } else 05227 ast_log(LOG_WARNING, "Unsupported SDP media type in offer: %s\n", m); 05228 if (numberofports > 1) 05229 ast_log(LOG_WARNING, "SDP offered %d ports for media, not supported by Asterisk. Will try anyway...\n", numberofports); 05230 05231 05232 /* Check for Media-description-level-address for audio */ 05233 c = get_sdp_iterate(&destiterator, req, "c"); 05234 if (!ast_strlen_zero(c)) { 05235 if (sscanf(c, "IN IP4 %256s", host) != 1) { 05236 ast_log(LOG_WARNING, "Invalid secondary host in c= line, '%s'\n", c); 05237 } else { 05238 /* XXX This could block for a long time, and block the main thread! XXX */ 05239 if (audio) { 05240 if ( !(hp = ast_gethostbyname(host, &audiohp))) { 05241 ast_log(LOG_WARNING, "Unable to lookup RTP Audio host in secondary c= line, '%s'\n", c); 05242 return -2; 05243 } 05244 } else if (!(vhp = ast_gethostbyname(host, &videohp))) { 05245 ast_log(LOG_WARNING, "Unable to lookup RTP video host in secondary c= line, '%s'\n", c); 05246 return -2; 05247 } 05248 } 05249 05250 } 05251 } 05252 if (portno == -1 && vportno == -1 && udptlportno == -1) 05253 /* No acceptable offer found in SDP - we have no ports */ 05254 /* Do not change RTP or VRTP if this is a re-invite */ 05255 return -2; 05256 05257 if (numberofmediastreams > 2) 05258 /* We have too many fax, audio and/or video media streams, fail this offer */ 05259 return -3; 05260 05261 /* RTP addresses and ports for audio and video */ 05262 sin.sin_family = AF_INET; 05263 vsin.sin_family = AF_INET; 05264 memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr)); 05265 if (vhp) 05266 memcpy(&vsin.sin_addr, vhp->h_addr, sizeof(vsin.sin_addr)); 05267 05268 /* Setup UDPTL port number */ 05269 if (p->udptl) { 05270 if (udptlportno > 0) { 05271 sin.sin_port = htons(udptlportno); 05272 if (ast_test_flag(&p->flags[0], SIP_NAT) && ast_test_flag(&p->flags[1], SIP_PAGE2_UDPTL_DESTINATION)) { 05273 struct sockaddr_in peer; 05274 ast_rtp_get_peer(p->rtp, &peer); 05275 if (peer.sin_addr.s_addr) { 05276 memcpy(&sin.sin_addr, &peer.sin_addr, sizeof(sin.sin_addr)); 05277 if (debug) { 05278 ast_log(LOG_DEBUG, "Peer T.38 UDPTL is set behind NAT and with destination, destination address now %s\n", ast_inet_ntoa(sin.sin_addr)); 05279 } 05280 } 05281 } 05282 ast_udptl_set_peer(p->udptl, &sin); 05283 if (debug) 05284 ast_log(LOG_DEBUG,"Peer T.38 UDPTL is at port %s:%d\n",ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); 05285 } else { 05286 ast_udptl_stop(p->udptl); 05287 if (debug) 05288 ast_log(LOG_DEBUG, "Peer doesn't provide T.38 UDPTL\n"); 05289 } 05290 } 05291 05292 05293 if (p->rtp) { 05294 if (portno > 0) { 05295 sin.sin_port = htons(portno); 05296 ast_rtp_set_peer(p->rtp, &sin); 05297 if (debug) 05298 ast_verbose("Peer audio RTP is at port %s:%d\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); 05299 } else { 05300 if (udptlportno > 0) { 05301 if (debug) 05302 ast_verbose("Got T.38 Re-invite without audio. Keeping RTP active during T.38 session. Callid %s\n", p->callid); 05303 } else { 05304 ast_rtp_stop(p->rtp); 05305 if (debug) 05306 ast_verbose("Peer doesn't provide audio. Callid %s\n", p->callid); 05307 } 05308 } 05309 } 05310 /* Setup video port number */ 05311 if (vportno != -1) 05312 vsin.sin_port = htons(vportno); 05313 05314 /* Next, scan through each "a=rtpmap:" line, noting each 05315 * specified RTP payload type (with corresponding MIME subtype): 05316 */ 05317 /* XXX This needs to be done per media stream, since it's media stream specific */ 05318 iterator = req->sdp_start; 05319 while ((a = get_sdp_iterate(&iterator, req, "a"))[0] != '\0') { 05320 char* mimeSubtype = ast_strdupa(a); /* ensures we have enough space */ 05321 if (option_debug > 1) { 05322 int breakout = FALSE; 05323 05324 /* If we're debugging, check for unsupported sdp options */ 05325 if (!strncasecmp(a, "rtcp:", (size_t) 5)) { 05326 if (debug) 05327 ast_verbose("Got unsupported a:rtcp in SDP offer \n"); 05328 breakout = TRUE; 05329 } else if (!strncasecmp(a, "fmtp:", (size_t) 5)) { 05330 /* Format parameters: Not supported */ 05331 /* Note: This is used for codec parameters, like bitrate for 05332 G722 and video formats for H263 and H264 05333 See RFC2327 for an example */ 05334 if (debug) 05335 ast_verbose("Got unsupported a:fmtp in SDP offer \n"); 05336 breakout = TRUE; 05337 } else if (!strncasecmp(a, "framerate:", (size_t) 10)) { 05338 /* Video stuff: Not supported */ 05339 if (debug) 05340 ast_verbose("Got unsupported a:framerate in SDP offer \n"); 05341 breakout = TRUE; 05342 } else if (!strncasecmp(a, "maxprate:", (size_t) 9)) { 05343 /* Video stuff: Not supported */ 05344 if (debug) 05345 ast_verbose("Got unsupported a:maxprate in SDP offer \n"); 05346 breakout = TRUE; 05347 } else if (!strncasecmp(a, "crypto:", (size_t) 7)) { 05348 /* SRTP stuff, not yet supported */ 05349 if (debug) 05350 ast_verbose("Got unsupported a:crypto in SDP offer \n"); 05351 breakout = TRUE; 05352 } 05353 if (breakout) /* We have a match, skip to next header */ 05354 continue; 05355 } 05356 if (!strcasecmp(a, "sendonly")) { 05357 if (sendonly == -1) 05358 sendonly = 1; 05359 continue; 05360 } else if (!strcasecmp(a, "inactive")) { 05361 if (sendonly == -1) 05362 sendonly = 2; 05363 continue; 05364 } else if (!strcasecmp(a, "sendrecv")) { 05365 if (sendonly == -1) 05366 sendonly = 0; 05367 continue; 05368 } else if (strlen(a) > 5 && !strncasecmp(a, "ptime", 5)) { 05369 char *tmp = strrchr(a, ':'); 05370 long int framing = 0; 05371 if (tmp) { 05372 tmp++; 05373 framing = strtol(tmp, NULL, 10); 05374 if (framing == LONG_MIN || framing == LONG_MAX) { 05375 framing = 0; 05376 if (option_debug) 05377 ast_log(LOG_DEBUG, "Can't read framing from SDP: %s\n", a); 05378 } 05379 } 05380 if (framing && p->autoframing) { 05381 struct ast_codec_pref *pref = ast_rtp_codec_getpref(p->rtp); 05382 int codec_n; 05383 int format = 0; 05384 for (codec_n = 0; codec_n < MAX_RTP_PT; codec_n++) { 05385 format = ast_rtp_codec_getformat(codec_n); 05386 if (!format) /* non-codec or not found */ 05387 continue; 05388 if (option_debug) 05389 ast_log(LOG_DEBUG, "Setting framing for %d to %ld\n", format, framing); 05390 ast_codec_pref_setsize(pref, format, framing); 05391 } 05392 ast_rtp_codec_setpref(p->rtp, pref); 05393 } 05394 continue; 05395 } else if (sscanf(a, "rtpmap: %u %[^/]/", &codec, mimeSubtype) == 2) { 05396 /* We have a rtpmap to handle */ 05397 int found = FALSE; 05398 /* We should propably check if this is an audio or video codec 05399 so we know where to look */ 05400 05401 if (last_rtpmap_codec < SDP_MAX_RTPMAP_CODECS) { 05402 /* Note: should really look at the 'freq' and '#chans' params too */ 05403 if(ast_rtp_set_rtpmap_type(newaudiortp, codec, "audio", mimeSubtype, 05404 ast_test_flag(&p->flags[0], SIP_G726_NONSTANDARD) ? AST_RTP_OPT_G726_NONSTANDARD : 0) != -1) { 05405 if (debug) 05406 ast_verbose("Found audio description format %s for ID %d\n", mimeSubtype, codec); 05407 found_rtpmap_codecs[last_rtpmap_codec] = codec; 05408 last_rtpmap_codec++; 05409 found = TRUE; 05410 05411 } else if (p->vrtp) { 05412 if(ast_rtp_set_rtpmap_type(newvideortp, codec, "video", mimeSubtype, 0) != -1) { 05413 if (debug) 05414 ast_verbose("Found video description format %s for ID %d\n", mimeSubtype, codec); 05415 found_rtpmap_codecs[last_rtpmap_codec] = codec; 05416 last_rtpmap_codec++; 05417 found = TRUE; 05418 } 05419 } 05420 } else { 05421 if (debug) 05422 ast_verbose("Discarded description format %s for ID %d\n", mimeSubtype, codec); 05423 } 05424 05425 if (!found) { 05426 /* Remove this codec since it's an unknown media type for us */ 05427 /* XXX This is buggy since the media line for audio and video can have the 05428 same numbers. We need to check as described above, but for testing this works... */ 05429 ast_rtp_unset_m_type(newaudiortp, codec); 05430 ast_rtp_unset_m_type(newvideortp, codec); 05431 if (debug) 05432 ast_verbose("Found unknown media description format %s for ID %d\n", mimeSubtype, codec); 05433 } 05434 } 05435 } 05436 05437 if (udptlportno != -1) { 05438 int found = 0, x; 05439 05440 old = 0; 05441 05442 /* Scan trough the a= lines for T38 attributes and set apropriate fileds */ 05443 iterator = req->sdp_start; 05444 while ((a = get_sdp_iterate(&iterator, req, "a"))[0] != '\0') { 05445 if ((sscanf(a, "T38FaxMaxBuffer:%d", &x) == 1)) { 05446 found = 1; 05447 if (option_debug > 2) 05448 ast_log(LOG_DEBUG, "MaxBufferSize:%d\n",x); 05449 } else if ((sscanf(a, "T38MaxBitRate:%d", &x) == 1)) { 05450 found = 1; 05451 if (option_debug > 2) 05452 ast_log(LOG_DEBUG,"T38MaxBitRate: %d\n",x); 05453 switch (x) { 05454 case 14400: 05455 peert38capability |= T38FAX_RATE_14400 | T38FAX_RATE_12000 | T38FAX_RATE_9600 | T38FAX_RATE_7200 | T38FAX_RATE_4800 | T38FAX_RATE_2400; 05456 break; 05457 case 12000: 05458 peert38capability |= T38FAX_RATE_12000 | T38FAX_RATE_9600 | T38FAX_RATE_7200 | T38FAX_RATE_4800 | T38FAX_RATE_2400; 05459 break; 05460 case 9600: 05461 peert38capability |= T38FAX_RATE_9600 | T38FAX_RATE_7200 | T38FAX_RATE_4800 | T38FAX_RATE_2400; 05462 break; 05463 case 7200: 05464 peert38capability |= T38FAX_RATE_7200 | T38FAX_RATE_4800 | T38FAX_RATE_2400; 05465 break; 05466 case 4800: 05467 peert38capability |= T38FAX_RATE_4800 | T38FAX_RATE_2400; 05468 break; 05469 case 2400: 05470 peert38capability |= T38FAX_RATE_2400; 05471 break; 05472 } 05473 } else if ((sscanf(a, "T38FaxVersion:%d", &x) == 1)) { 05474 found = 1; 05475 if (option_debug > 2) 05476 ast_log(LOG_DEBUG, "FaxVersion: %d\n",x); 05477 if (x == 0) 05478 peert38capability |= T38FAX_VERSION_0; 05479 else if (x == 1) 05480 peert38capability |= T38FAX_VERSION_1; 05481 } else if ((sscanf(a, "T38FaxMaxDatagram:%d", &x) == 1)) { 05482 found = 1; 05483 if (option_debug > 2) 05484 ast_log(LOG_DEBUG, "FaxMaxDatagram: %d\n",x); 05485 ast_udptl_set_far_max_datagram(p->udptl, x); 05486 ast_udptl_set_local_max_datagram(p->udptl, x); 05487 } else if ((sscanf(a, "T38FaxFillBitRemoval:%d", &x) == 1)) { 05488 found = 1; 05489 if (option_debug > 2) 05490 ast_log(LOG_DEBUG, "FillBitRemoval: %d\n",x); 05491 if (x == 1) 05492 peert38capability |= T38FAX_FILL_BIT_REMOVAL; 05493 } else if ((sscanf(a, "T38FaxTranscodingMMR:%d", &x) == 1)) { 05494 found = 1; 05495 if (option_debug > 2) 05496 ast_log(LOG_DEBUG, "Transcoding MMR: %d\n",x); 05497 if (x == 1) 05498 peert38capability |= T38FAX_TRANSCODING_MMR; 05499 } 05500 if ((sscanf(a, "T38FaxTranscodingJBIG:%d", &x) == 1)) { 05501 found = 1; 05502 if (option_debug > 2) 05503 ast_log(LOG_DEBUG, "Transcoding JBIG: %d\n",x); 05504 if (x == 1) 05505 peert38capability |= T38FAX_TRANSCODING_JBIG; 05506 } else if ((sscanf(a, "T38FaxRateManagement:%255s", s) == 1)) { 05507 found = 1; 05508 if (option_debug > 2) 05509 ast_log(LOG_DEBUG, "RateManagement: %s\n", s); 05510 if (!strcasecmp(s, "localTCF")) 05511 peert38capability |= T38FAX_RATE_MANAGEMENT_LOCAL_TCF; 05512 else if (!strcasecmp(s, "transferredTCF")) 05513 peert38capability |= T38FAX_RATE_MANAGEMENT_TRANSFERED_TCF; 05514 } else if ((sscanf(a, "T38FaxUdpEC:%255s", s) == 1)) { 05515 found = 1; 05516 if (option_debug > 2) 05517 ast_log(LOG_DEBUG, "UDP EC: %s\n", s); 05518 if (!strcasecmp(s, "t38UDPRedundancy")) { 05519 peert38capability |= T38FAX_UDP_EC_REDUNDANCY; 05520 ast_udptl_set_error_correction_scheme(p->udptl, UDPTL_ERROR_CORRECTION_REDUNDANCY); 05521 } else if (!strcasecmp(s, "t38UDPFEC")) { 05522 peert38capability |= T38FAX_UDP_EC_FEC; 05523 ast_udptl_set_error_correction_scheme(p->udptl, UDPTL_ERROR_CORRECTION_FEC); 05524 } else { 05525 peert38capability |= T38FAX_UDP_EC_NONE; 05526 ast_udptl_set_error_correction_scheme(p->udptl, UDPTL_ERROR_CORRECTION_NONE); 05527 } 05528 } 05529 } 05530 if (found) { /* Some cisco equipment returns nothing beside c= and m= lines in 200 OK T38 SDP */ 05531 p->t38.peercapability = peert38capability; 05532 p->t38.jointcapability = (peert38capability & 255); /* Put everything beside supported speeds settings */ 05533 peert38capability &= (T38FAX_RATE_14400 | T38FAX_RATE_12000 | T38FAX_RATE_9600 | T38FAX_RATE_7200 | T38FAX_RATE_4800 | T38FAX_RATE_2400); 05534 p->t38.jointcapability |= (peert38capability & p->t38.capability); /* Put the lower of our's and peer's speed */ 05535 } 05536 if (debug) 05537 ast_log(LOG_DEBUG, "Our T38 capability = (%d), peer T38 capability (%d), joint T38 capability (%d)\n", 05538 p->t38.capability, 05539 p->t38.peercapability, 05540 p->t38.jointcapability); 05541 } else { 05542 p->t38.state = T38_DISABLED; 05543 if (option_debug > 2) 05544 ast_log(LOG_DEBUG, "T38 state changed to %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "<none>"); 05545 } 05546 05547 /* Now gather all of the codecs that we are asked for: */ 05548 ast_rtp_get_current_formats(newaudiortp, &peercapability, &peernoncodeccapability); 05549 ast_rtp_get_current_formats(newvideortp, &vpeercapability, &vpeernoncodeccapability); 05550 05551 newjointcapability = p->capability & (peercapability | vpeercapability); 05552 newpeercapability = (peercapability | vpeercapability); 05553 newnoncodeccapability = p->noncodeccapability & peernoncodeccapability; 05554 05555 05556 if (debug) { 05557 /* shame on whoever coded this.... */ 05558 char s1[SIPBUFSIZE], s2[SIPBUFSIZE], s3[SIPBUFSIZE], s4[SIPBUFSIZE]; 05559 05560 ast_verbose("Capabilities: us - %s, peer - audio=%s/video=%s, combined - %s\n", 05561 ast_getformatname_multiple(s1, SIPBUFSIZE, p->capability), 05562 ast_getformatname_multiple(s2, SIPBUFSIZE, newpeercapability), 05563 ast_getformatname_multiple(s3, SIPBUFSIZE, vpeercapability), 05564 ast_getformatname_multiple(s4, SIPBUFSIZE, newjointcapability)); 05565 05566 ast_verbose("Non-codec capabilities (dtmf): us - %s, peer - %s, combined - %s\n", 05567 ast_rtp_lookup_mime_multiple(s1, SIPBUFSIZE, p->noncodeccapability, 0, 0), 05568 ast_rtp_lookup_mime_multiple(s2, SIPBUFSIZE, peernoncodeccapability, 0, 0), 05569 ast_rtp_lookup_mime_multiple(s3, SIPBUFSIZE, newnoncodeccapability, 0, 0)); 05570 } 05571 if (!newjointcapability) { 05572 /* If T.38 was not negotiated either, totally bail out... */ 05573 if (!p->t38.jointcapability || !udptlportno) { 05574 ast_log(LOG_NOTICE, "No compatible codecs, not accepting this offer!\n"); 05575 /* Do NOT Change current setting */ 05576 return -1; 05577 } else { 05578 if (option_debug > 2) 05579 ast_log(LOG_DEBUG, "Have T.38 but no audio codecs, accepting offer anyway\n"); 05580 return 0; 05581 } 05582 } 05583 05584 /* We are now ready to change the sip session and p->rtp and p->vrtp with the offered codecs, since 05585 they are acceptable */ 05586 p->jointcapability = newjointcapability; /* Our joint codec profile for this call */ 05587 p->peercapability = newpeercapability; /* The other sides capability in latest offer */ 05588 p->jointnoncodeccapability = newnoncodeccapability; /* DTMF capabilities */ 05589 05590 ast_rtp_pt_copy(p->rtp, newaudiortp); 05591 if (p->vrtp) 05592 ast_rtp_pt_copy(p->vrtp, newvideortp); 05593 05594 if (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO) { 05595 ast_clear_flag(&p->flags[0], SIP_DTMF); 05596 if (newnoncodeccapability & AST_RTP_DTMF) { 05597 /* XXX Would it be reasonable to drop the DSP at this point? XXX */ 05598 ast_set_flag(&p->flags[0], SIP_DTMF_RFC2833); 05599 /* Since RFC2833 is now negotiated we need to change some properties of the RTP stream */ 05600 ast_rtp_setdtmf(p->rtp, 1); 05601 ast_rtp_setdtmfcompensate(p->rtp, ast_test_flag(&p->flags[1], SIP_PAGE2_RFC2833_COMPENSATE)); 05602 } else { 05603 ast_set_flag(&p->flags[0], SIP_DTMF_INBAND); 05604 } 05605 } 05606 05607 /* Setup audio port number */ 05608 if (p->rtp && sin.sin_port) { 05609 ast_rtp_set_peer(p->rtp, &sin); 05610 if (debug) 05611 ast_verbose("Peer audio RTP is at port %s:%d\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); 05612 } 05613 05614 /* Setup video port number */ 05615 if (p->vrtp && vsin.sin_port) { 05616 ast_rtp_set_peer(p->vrtp, &vsin); 05617 if (debug) 05618 ast_verbose("Peer video RTP is at port %s:%d\n", ast_inet_ntoa(vsin.sin_addr), ntohs(vsin.sin_port)); 05619 } 05620 05621 /* Ok, we're going with this offer */ 05622 if (option_debug > 1) { 05623 char buf[SIPBUFSIZE]; 05624 ast_log(LOG_DEBUG, "We're settling with these formats: %s\n", ast_getformatname_multiple(buf, SIPBUFSIZE, p->jointcapability)); 05625 } 05626 05627 if (!p->owner) /* There's no open channel owning us so we can return here. For a re-invite or so, we proceed */ 05628 return 0; 05629 05630 if (option_debug > 3) 05631 ast_log(LOG_DEBUG, "We have an owner, now see if we need to change this call\n"); 05632 05633 if (!(p->owner->nativeformats & p->jointcapability) && (p->jointcapability & AST_FORMAT_AUDIO_MASK)) { 05634 if (debug) { 05635 char s1[SIPBUFSIZE], s2[SIPBUFSIZE]; 05636 ast_log(LOG_DEBUG, "Oooh, we need to change our audio formats since our peer supports only %s and not %s\n", 05637 ast_getformatname_multiple(s1, SIPBUFSIZE, p->jointcapability), 05638 ast_getformatname_multiple(s2, SIPBUFSIZE, p->owner->nativeformats)); 05639 } 05640 p->owner->nativeformats = ast_codec_choose(&p->prefs, p->jointcapability, 1) | (p->capability & vpeercapability); 05641 ast_set_read_format(p->owner, p->owner->readformat); 05642 ast_set_write_format(p->owner, p->owner->writeformat); 05643 } 05644 05645 if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD) && sin.sin_addr.s_addr && (!sendonly || sendonly == -1)) { 05646 ast_queue_control(p->owner, AST_CONTROL_UNHOLD); 05647 /* Activate a re-invite */ 05648 ast_queue_frame(p->owner, &ast_null_frame); 05649 } else if (!sin.sin_addr.s_addr || (sendonly && sendonly != -1)) { 05650 ast_queue_control_data(p->owner, AST_CONTROL_HOLD, 05651 S_OR(p->mohsuggest, NULL), 05652 !ast_strlen_zero(p->mohsuggest) ? strlen(p->mohsuggest) + 1 : 0); 05653 if (sendonly) 05654 ast_rtp_stop(p->rtp); 05655 /* RTCP needs to go ahead, even if we're on hold!!! */ 05656 /* Activate a re-invite */ 05657 ast_queue_frame(p->owner, &ast_null_frame); 05658 } 05659 05660 /* Manager Hold and Unhold events must be generated, if necessary */ 05661 if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD) && sin.sin_addr.s_addr && (!sendonly || sendonly == -1)) 05662 change_hold_state(p, req, FALSE, sendonly); 05663 else if (!sin.sin_addr.s_addr || (sendonly && sendonly != -1)) 05664 change_hold_state(p, req, TRUE, sendonly); 05665 return 0; 05666 }
| static struct sip_peer * realtime_peer | ( | const char * | newpeername, | |
| struct sockaddr_in * | sin, | |||
| int | devstate_only | |||
| ) | [static, read] |
realtime_peer: Get peer from realtime storage Checks the "sippeers" realtime family from extconfig.conf
Definition at line 2529 of file chan_sip.c.
References ast_category_browse(), ast_category_root(), ast_config_destroy(), ast_copy_flags, ast_gethostbyname(), ast_inet_ntoa(), ast_load_realtime(), ast_load_realtime_multientry(), ast_log(), ast_sched_add(), AST_SCHED_DEL, ast_set_flag, ast_test_flag, ast_variable_retrieve(), ast_variables_destroy(), ASTOBJ_CONTAINER_LINK, ASTOBJ_REF, ASTOBJ_UNREF, build_peer(), sip_peer::expire, expire_register(), sip_peer::flags, hp, LOG_WARNING, ast_variable::name, ast_variable::next, peerl, set_insecure_flags(), sip_destroy_peer(), SIP_INSECURE_PORT, SIP_PAGE2_RTAUTOCLEAR, SIP_PAGE2_RTCACHEFRIENDS, SIP_REALTIME, ast_variable::value, and var.
Referenced by find_peer().
02530 { 02531 struct sip_peer *peer=NULL; 02532 struct ast_variable *var = NULL; 02533 struct ast_config *peerlist = NULL; 02534 struct ast_variable *tmp; 02535 struct ast_flags flags = {0}; 02536 const char *iabuf = NULL; 02537 char portstring[6]; /*up to five digits plus null terminator*/ 02538 const char *insecure; 02539 char *cat = NULL; 02540 unsigned short portnum; 02541 02542 /* First check on peer name */ 02543 if (newpeername) { 02544 var = ast_load_realtime("sippeers", "name", newpeername, "host", "dynamic", NULL); 02545 if (!var && sin) 02546 var = ast_load_realtime("sippeers", "name", newpeername, "host", ast_inet_ntoa(sin->sin_addr), NULL); 02547 if (!var) { 02548 var = ast_load_realtime("sippeers", "name", newpeername, NULL); 02549 /*!\note 02550 * If this one loaded something, then we need to ensure that the host 02551 * field matched. The only reason why we can't have this as a criteria 02552 * is because we only have the IP address and the host field might be 02553 * set as a name (and the reverse PTR might not match). 02554 */ 02555 if (var && sin) { 02556 for (tmp = var; tmp; tmp = tmp->next) { 02557 if (!strcasecmp(tmp->name, "host")) { 02558 struct hostent *hp; 02559 struct ast_hostent ahp; 02560 if (!(hp = ast_gethostbyname(tmp->value, &ahp)) || (memcmp(&hp->h_addr, &sin->sin_addr, sizeof(hp->h_addr)))) { 02561 /* No match */ 02562 ast_variables_destroy(var); 02563 var = NULL; 02564 } 02565 break; 02566 } 02567 } 02568 } 02569 } 02570 } 02571 02572 if (!var && sin) { /* Then check on IP address */ 02573 iabuf = ast_inet_ntoa(sin->sin_addr); 02574 portnum = ntohs(sin->sin_port); 02575 sprintf(portstring, "%d", portnum); 02576 var = ast_load_realtime("sippeers", "host", iabuf, "port", portstring, NULL); /* First check for fixed IP hosts */ 02577 if (!var) 02578 var = ast_load_realtime("sippeers", "ipaddr", iabuf, "port", portstring, NULL); /* Then check for registered hosts */ 02579 if (!var) { 02580 peerlist = ast_load_realtime_multientry("sippeers", "host", iabuf, NULL); /*No exact match, see if port is insecure, try host match first*/ 02581 if(peerlist){ 02582 while((cat = ast_category_browse(peerlist, cat))) 02583 { 02584 insecure = ast_variable_retrieve(peerlist, cat, "insecure"); 02585 set_insecure_flags(&flags, insecure, -1); 02586 if(ast_test_flag(&flags, SIP_INSECURE_PORT)) { 02587 var = ast_category_root(peerlist, cat); 02588 break; 02589 } 02590 } 02591 } 02592 if(!var) { 02593 ast_config_destroy(peerlist); 02594 peerlist = NULL; /*for safety's sake*/ 02595 cat = NULL; 02596 peerlist = ast_load_realtime_multientry("sippeers", "ipaddr", iabuf, NULL); /*No exact match, see if port is insecure, now try ip address match*/ 02597 if(peerlist) { 02598 while((cat = ast_category_browse(peerlist, cat))) 02599 { 02600 insecure = ast_variable_retrieve(peerlist, cat, "insecure"); 02601 set_insecure_flags(&flags, insecure, -1); 02602 if(ast_test_flag(&flags, SIP_INSECURE_PORT)) { 02603 var = ast_category_root(peerlist, cat); 02604 break; 02605 } 02606 } 02607 } 02608 } 02609 } 02610 } 02611 02612 if (!var) { 02613 if(peerlist) 02614 ast_config_destroy(peerlist); 02615 return NULL; 02616 } 02617 02618 for (tmp = var; tmp; tmp = tmp->next) { 02619 /* If this is type=user, then skip this object. */ 02620 if (!strcasecmp(tmp->name, "type") && 02621 !strcasecmp(tmp->value, "user")) { 02622 ast_variables_destroy(var); 02623 return NULL; 02624 } else if (!newpeername && !strcasecmp(tmp->name, "name")) { 02625 newpeername = tmp->value; 02626 } 02627 } 02628 02629 if (!newpeername) { /* Did not find peer in realtime */ 02630 ast_log(LOG_WARNING, "Cannot Determine peer name ip=%s\n", iabuf); 02631 if(peerlist) 02632 ast_config_destroy(peerlist); 02633 else 02634 ast_variables_destroy(var); 02635 return NULL; 02636 } 02637 02638 /* Peer found in realtime, now build it in memory */ 02639 peer = build_peer(newpeername, var, NULL, 1); 02640 if (!peer) { 02641 if(peerlist) 02642 ast_config_destroy(peerlist); 02643 else 02644 ast_variables_destroy(var); 02645 return NULL; 02646 } 02647 02648 if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS) && !devstate_only) { 02649 /* Cache peer */ 02650 ast_copy_flags(&peer->flags[1],&global_flags[1], SIP_PAGE2_RTAUTOCLEAR|SIP_PAGE2_RTCACHEFRIENDS); 02651 if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTAUTOCLEAR)) { 02652 if (!AST_SCHED_DEL(sched, peer->expire)) { 02653 struct sip_peer *peer_ptr = peer; 02654 ASTOBJ_UNREF(peer_ptr, sip_destroy_peer); 02655 } 02656 peer->expire = ast_sched_add(sched, (global_rtautoclear) * 1000, expire_register, ASTOBJ_REF(peer)); 02657 if (peer->expire == -1) { 02658 struct sip_peer *peer_ptr = peer; 02659 ASTOBJ_UNREF(peer_ptr, sip_destroy_peer); 02660 } 02661 } 02662 ASTOBJ_CONTAINER_LINK(&peerl,peer); 02663 } 02664 ast_set_flag(&peer->flags[0], SIP_REALTIME); 02665 if(peerlist) 02666 ast_config_destroy(peerlist); 02667 else 02668 ast_variables_destroy(var); 02669 return peer; 02670 }
| static void realtime_update_peer | ( | const char * | peername, | |
| struct sockaddr_in * | sin, | |||
| const char * | username, | |||
| const char * | fullcontact, | |||
| int | expirey | |||
| ) | [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 2415 of file chan_sip.c.
References ast_config_AST_SYSTEM_NAME, ast_copy_string(), ast_inet_ntoa(), ast_strlen_zero(), ast_test_flag, ast_update_realtime(), ipaddr, and SIP_PAGE2_RTSAVE_SYSNAME.
Referenced by update_peer().
02416 { 02417 char port[10]; 02418 char ipaddr[INET_ADDRSTRLEN]; 02419 char regseconds[20]; 02420 02421 char *sysname = ast_config_AST_SYSTEM_NAME; 02422 char *syslabel = NULL; 02423 02424 time_t nowtime = time(NULL) + expirey; 02425 const char *fc = fullcontact ? "fullcontact" : NULL; 02426 02427 snprintf(regseconds, sizeof(regseconds), "%d", (int)nowtime); /* Expiration time */ 02428 ast_copy_string(ipaddr, ast_inet_ntoa(sin->sin_addr), sizeof(ipaddr)); 02429 snprintf(port, sizeof(port), "%d", ntohs(sin->sin_port)); 02430 02431 if (ast_strlen_zero(sysname)) /* No system name, disable this */ 02432 sysname = NULL; 02433 else if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTSAVE_SYSNAME)) 02434 syslabel = "regserver"; 02435 02436 if (fc) 02437 ast_update_realtime("sippeers", "name", peername, "ipaddr", ipaddr, 02438 "port", port, "regseconds", regseconds, 02439 "username", username, fc, fullcontact, syslabel, sysname, NULL); /* note fc and syslabel _can_ be NULL */ 02440 else 02441 ast_update_realtime("sippeers", "name", peername, "ipaddr", ipaddr, 02442 "port", port, "regseconds", regseconds, 02443 "username", username, syslabel, sysname, NULL); /* note syslabel _can_ be NULL */ 02444 }
| static struct sip_user * realtime_user | ( | const char * | username | ) | [static, read] |
Load user from realtime storage Loads user from "sipusers" category in realtime (extconfig.conf) Users are matched on From: user name (the domain in skipped).
Definition at line 2720 of file chan_sip.c.
References ast_load_realtime(), ast_set_flag, ast_test_flag, ast_variables_destroy(), ASTOBJ_CONTAINER_LINK, build_user(), sip_user::flags, ast_variable::name, ast_variable::next, SIP_PAGE2_RTCACHEFRIENDS, SIP_REALTIME, userl, ast_variable::value, and var.
Referenced by find_user().
02721 { 02722 struct ast_variable *var; 02723 struct ast_variable *tmp; 02724 struct sip_user *user = NULL; 02725 02726 var = ast_load_realtime("sipusers", "name", username, NULL); 02727 02728 if (!var) 02729 return NULL; 02730 02731 for (tmp = var; tmp; tmp = tmp->next) { 02732 if (!strcasecmp(tmp->name, "type") && 02733 !strcasecmp(tmp->value, "peer")) { 02734 ast_variables_destroy(var); 02735 return NULL; 02736 } 02737 } 02738 02739 user = build_user(username, var, NULL, !ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS)); 02740 02741 if (!user) { /* No user found */ 02742 ast_variables_destroy(var); 02743 return NULL; 02744 } 02745 02746 if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS)) { 02747 ast_set_flag(&user->flags[1], SIP_PAGE2_RTCACHEFRIENDS); 02748 suserobjs++; 02749 ASTOBJ_CONTAINER_LINK(&userl,user); 02750 } else { 02751 /* Move counter from s to r... */ 02752 suserobjs--; 02753 ruserobjs++; 02754 } 02755 ast_set_flag(&user->flags[0], SIP_REALTIME); 02756 ast_variables_destroy(var); 02757 return user; 02758 }
| static void receive_message | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Receive SIP MESSAGE method messages.
Definition at line 9858 of file chan_sip.c.
References AST_FRAME_TEXT, ast_log(), ast_queue_frame(), ast_verbose(), sip_pvt::callid, ast_frame::data, ast_frame::datalen, DEFAULT_TRANS_TIMEOUT, ast_frame::frametype, get_header(), get_msg_text(), LOG_WARNING, ast_frame::offset, sip_pvt::owner, sip_debug_test_pvt(), sip_scheddestroy(), ast_frame::subclass, and transmit_response().
Referenced by handle_request_message().
09859 { 09860 char buf[1024]; 09861 struct ast_frame f; 09862 const char *content_type = get_header(req, "Content-Type"); 09863 09864 if (strncmp(content_type, "text/plain", strlen("text/plain"))) { /* No text/plain attachment */ 09865 transmit_response(p, "415 Unsupported Media Type", req); /* Good enough, or? */ 09866 if (!p->owner) 09867 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 09868 return; 09869 } 09870 09871 if (get_msg_text(buf, sizeof(buf), req)) { 09872 ast_log(LOG_WARNING, "Unable to retrieve text from %s\n", p->callid); 09873 transmit_response(p, "202 Accepted", req); 09874 if (!p->owner) 09875 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 09876 return; 09877 } 09878 09879 if (p->owner) { 09880 if (sip_debug_test_pvt(p)) 09881 ast_verbose("Message received: '%s'\n", buf); 09882 memset(&f, 0, sizeof(f)); 09883 f.frametype = AST_FRAME_TEXT; 09884 f.subclass = 0; 09885 f.offset = 0; 09886 f.data = buf; 09887 f.datalen = strlen(buf); 09888 ast_queue_frame(p->owner, &f); 09889 transmit_response(p, "202 Accepted", req); /* We respond 202 accepted, since we relay the message */ 09890 } else { /* Message outside of a call, we do not support that */ 09891 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); 09892 transmit_response(p, "405 Method Not Allowed", req); /* Good enough, or? */ 09893 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 09894 } 09895 return; 09896 }
| static char * referstatus2str | ( | enum referstatus | rstatus | ) | [static] |
Convert transfer status to string.
Definition at line 1641 of file chan_sip.c.
References referstatusstrings, and c_referstatusstring::text.
Referenced by __sip_show_channels().
01642 { 01643 int i = (sizeof(referstatusstrings) / sizeof(referstatusstrings[0])); 01644 int x; 01645 01646 for (x = 0; x < i; x++) { 01647 if (referstatusstrings[x].status == rstatus) 01648 return (char *) referstatusstrings[x].text; 01649 } 01650 return ""; 01651 }
| static void reg_source_db | ( | struct sip_peer * | peer | ) | [static] |
Get registration details from Asterisk DB.
Definition at line 8048 of file chan_sip.c.
References sip_peer::addr, ast_copy_string(), ast_db_get(), ast_inet_ntoa(), ast_log(), ast_random(), ast_sched_add(), AST_SCHED_DEL, ast_test_flag, ASTOBJ_REF, ASTOBJ_UNREF, sip_peer::expire, expire_register(), sip_peer::flags, sip_peer::fullcontact, LOG_DEBUG, sip_peer::name, option_debug, sip_peer::pokeexpire, register_peer_exten(), sip_destroy_peer(), SIP_PAGE2_RT_FROMCONTACT, sip_poke_peer(), sip_poke_peer_s(), TRUE, sip_peer::username, and username.
Referenced by build_peer(), and temp_peer().
08049 { 08050 char data[256]; 08051 struct in_addr in; 08052 int expiry; 08053 int port; 08054 char *scan, *addr, *port_str, *expiry_str, *username, *contact; 08055 08056 if (ast_test_flag(&peer->flags[1], SIP_PAGE2_RT_FROMCONTACT)) 08057 return; 08058 if (ast_db_get("SIP/Registry", peer->name, data, sizeof(data))) 08059 return; 08060 08061 scan = data; 08062 addr = strsep(&scan, ":"); 08063 port_str = strsep(&scan, ":"); 08064 expiry_str = strsep(&scan, ":"); 08065 username = strsep(&scan, ":"); 08066 contact = scan; /* Contact include sip: and has to be the last part of the database entry as long as we use : as a separator */ 08067 08068 if (!inet_aton(addr, &in)) 08069 return; 08070 08071 if (port_str) 08072 port = atoi(port_str); 08073 else 08074 return; 08075 08076 if (expiry_str) 08077 expiry = atoi(expiry_str); 08078 else 08079 return; 08080 08081 if (username) 08082 ast_copy_string(peer->username, username, sizeof(peer->username)); 08083 if (contact) 08084 ast_copy_string(peer->fullcontact, contact, sizeof(peer->fullcontact)); 08085 08086 if (option_debug > 1) 08087 ast_log(LOG_DEBUG, "SIP Seeding peer from astdb: '%s' at %s@%s:%d for %d\n", 08088 peer->name, peer->username, ast_inet_ntoa(in), port, expiry); 08089 08090 memset(&peer->addr, 0, sizeof(peer->addr)); 08091 peer->addr.sin_family = AF_INET; 08092 peer->addr.sin_addr = in; 08093 peer->addr.sin_port = htons(port); 08094 if (sipsock < 0) { 08095 /* SIP isn't up yet, so schedule a poke only, pretty soon */ 08096 if (!AST_SCHED_DEL(sched, peer->pokeexpire)) { 08097 struct sip_peer *peer_ptr = peer; 08098 ASTOBJ_UNREF(peer_ptr, sip_destroy_peer); 08099 } 08100 peer->pokeexpire = ast_sched_add(sched, ast_random() % 5000 + 1, sip_poke_peer_s, ASTOBJ_REF(peer)); 08101 if (peer->pokeexpire == -1) { 08102 struct sip_peer *peer_ptr = peer; 08103 ASTOBJ_UNREF(peer_ptr, sip_destroy_peer); 08104 } 08105 } else 08106 sip_poke_peer(peer); 08107 if (!AST_SCHED_DEL(sched, peer->expire)) { 08108 struct sip_peer *peer_ptr = peer; 08109 ASTOBJ_UNREF(peer_ptr, sip_destroy_peer); 08110 } 08111 peer->expire = ast_sched_add(sched, (expiry + 10) * 1000, expire_register, ASTOBJ_REF(peer)); 08112 if (peer->expire == -1) { 08113 struct sip_peer *peer_ptr = peer; 08114 ASTOBJ_UNREF(peer_ptr, sip_destroy_peer); 08115 } 08116 register_peer_exten(peer, TRUE); 08117 }
| static void register_peer_exten | ( | struct sip_peer * | peer, | |
| int | onoff | |||
| ) | [static] |
Automatically add peer extension to dial plan.
Definition at line 2447 of file chan_sip.c.
References ast_add_extension(), ast_context_find(), ast_context_remove_extension(), ast_copy_string(), ast_exists_extension(), ast_free, ast_log(), ast_strdup, ast_strlen_zero(), domain::context, ext, LOG_WARNING, sip_peer::name, sip_peer::regexten, and S_OR.
Referenced by expire_register(), parse_register_contact(), reg_source_db(), and sip_destroy_peer().
02448 { 02449 char multi[256]; 02450 char *stringp, *ext, *context; 02451 02452 /* XXX note that global_regcontext is both a global 'enable' flag and 02453 * the name of the global regexten context, if not specified 02454 * individually. 02455 */ 02456 if (ast_strlen_zero(global_regcontext)) 02457 return; 02458 02459 ast_copy_string(multi, S_OR(peer->regexten, peer->name), sizeof(multi)); 02460 stringp = multi; 02461 while ((ext = strsep(&stringp, "&"))) { 02462 if ((context = strchr(ext, '@'))) { 02463 *context++ = '\0'; /* split ext@context */ 02464 if (!ast_context_find(context)) { 02465 ast_log(LOG_WARNING, "Context %s must exist in regcontext= in sip.conf!\n", context); 02466 continue; 02467 } 02468 } else { 02469 context = global_regcontext; 02470 } 02471 if (onoff) { 02472 if (!ast_exists_extension(NULL, context, ext, 1, NULL)) { 02473 ast_add_extension(context, 1, ext, 1, NULL, NULL, "Noop", 02474 ast_strdup(peer->name), ast_free, "SIP"); 02475 } 02476 } else { 02477 ast_context_remove_extension(context, ext, 1, NULL); 02478 } 02479 } 02480 }
| static enum check_auth_result register_verify | ( | struct sip_pvt * | p, | |
| struct sockaddr_in * | sin, | |||
| struct sip_request * | req, | |||
| char * | uri | |||
| ) | [static] |
Verify registration of user
Definition at line 8764 of file chan_sip.c.
References ast_apply_ha(), ast_copy_flags, ast_copy_string(), ast_device_state_changed(), ast_inet_ntoa(), AST_LIST_EMPTY, ast_log(), ast_rtp_codec_setpref(), ast_string_field_set, ast_test_flag, ast_uri_decode(), ASTOBJ_CONTAINER_LINK, ASTOBJ_UNREF, AUTH_ACL_FAILED, AUTH_NOT_FOUND, AUTH_PEER_NOT_DYNAMIC, AUTH_SECRET_FAILED, AUTH_UNKNOWN_DOMAIN, AUTH_USERNAME_MISMATCH, sip_peer::autoframing, sip_pvt::autoframing, build_contact(), check_auth(), check_sip_domain(), EVENT_FLAG_SYSTEM, sip_pvt::expiry, exten, find_peer(), sip_pvt::flags, sip_peer::flags, get_header(), get_in_brackets(), sip_peer::ha, sip_pvt::initreq, sip_peer::lastmsgssent, LOG_ERROR, LOG_NOTICE, LOG_WARNING, manager_event(), sip_peer::md5secret, sip_peer::name, name, parse_register_contact(), PARSE_REGISTER_FAILED, PARSE_REGISTER_QUERY, PARSE_REGISTER_UPDATE, peerl, sip_peer::prefs, sip_pvt::rtp, sip_peer::secret, sip_cancel_destroy(), sip_destroy_peer(), SIP_NAT, SIP_PAGE2_DYNAMIC, SIP_PAGE2_SUBSCRIBEMWIONLY, SIP_PKT_IGNORE, SIP_REGISTER, t, temp_peer(), transmit_fake_auth_response(), transmit_response(), transmit_response_with_date(), update_peer(), and XMIT_UNRELIABLE.
Referenced by handle_request_register().
08766 { 08767 enum check_auth_result res = AUTH_NOT_FOUND; 08768 struct sip_peer *peer; 08769 char tmp[256]; 08770 char *name, *c; 08771 char *t; 08772 char *domain; 08773 08774 /* Terminate URI */ 08775 t = uri; 08776 while(*t && (*t > 32) && (*t != ';')) 08777 t++; 08778 *t = '\0'; 08779 08780 ast_copy_string(tmp, get_header(req, "To"), sizeof(tmp)); 08781 if (pedanticsipchecking) 08782 ast_uri_decode(tmp); 08783 08784 c = get_in_brackets(tmp); 08785 c = strsep(&c, ";"); /* Ditch ;user=phone */ 08786 08787 if (!strncasecmp(c, "sip:", 4)) { 08788 name = c + 4; 08789 } else { 08790 name = c; 08791 ast_log(LOG_NOTICE, "Invalid to address: '%s' from %s (missing sip:) trying to use anyway...\n", c, ast_inet_ntoa(sin->sin_addr)); 08792 } 08793 08794 /* Strip off the domain name */ 08795 if ((c = strchr(name, '@'))) { 08796 *c++ = '\0'; 08797 domain = c; 08798 if ((c = strchr(domain, ':'))) /* Remove :port */ 08799 *c = '\0'; 08800 if (!AST_LIST_EMPTY(&domain_list)) { 08801 if (!check_sip_domain(domain, NULL, 0)) { 08802 transmit_response(p, "404 Not found (unknown domain)", &p->initreq); 08803 return AUTH_UNKNOWN_DOMAIN; 08804 } 08805 } 08806 } 08807 08808 ast_string_field_set(p, exten, name); 08809 build_contact(p); 08810 peer = find_peer(name, NULL, 1, 0); 08811 if (!(peer && ast_apply_ha(peer->ha, sin))) { 08812 /* Peer fails ACL check */ 08813 if (peer) { 08814 ASTOBJ_UNREF(peer, sip_destroy_peer); 08815 res = AUTH_ACL_FAILED; 08816 } else 08817 res = AUTH_NOT_FOUND; 08818 } 08819 if (peer) { 08820 /* Set Frame packetization */ 08821 if (p->rtp) { 08822 ast_rtp_codec_setpref(p->rtp, &peer->prefs); 08823 p->autoframing = peer->autoframing; 08824 } 08825 if (!ast_test_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC)) { 08826 ast_log(LOG_ERROR, "Peer '%s' is trying to register, but not configured as host=dynamic\n", peer->name); 08827 res = AUTH_PEER_NOT_DYNAMIC; 08828 } else { 08829 ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_NAT); 08830 transmit_response(p, "100 Trying", req); 08831 if (!(res = check_auth(p, req, peer->name, peer->secret, peer->md5secret, SIP_REGISTER, uri, XMIT_UNRELIABLE, ast_test_flag(req, SIP_PKT_IGNORE)))) { 08832 if (sip_cancel_destroy(p)) 08833 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 08834 08835 /* We have a succesful registration attemp with proper authentication, 08836 now, update the peer */ 08837 switch (parse_register_contact(p, peer, req)) { 08838 case PARSE_REGISTER_FAILED: 08839 ast_log(LOG_WARNING, "Failed to parse contact info\n"); 08840 transmit_response_with_date(p, "400 Bad Request", req); 08841 peer->lastmsgssent = -1; 08842 res = 0; 08843 break; 08844 case PARSE_REGISTER_QUERY: 08845 transmit_response_with_date(p, "200 OK", req); 08846 peer->lastmsgssent = -1; 08847 res = 0; 08848 break; 08849 case PARSE_REGISTER_UPDATE: 08850 update_peer(peer, p->expiry); 08851 /* Say OK and ask subsystem to retransmit msg counter */ 08852 transmit_response_with_date(p, "200 OK", req); 08853 if (!ast_test_flag((&peer->flags[1]), SIP_PAGE2_SUBSCRIBEMWIONLY)) 08854 peer->lastmsgssent = -1; 08855 res = 0; 08856 break; 08857 } 08858 } 08859 } 08860 } 08861 if (!peer && autocreatepeer) { 08862 /* Create peer if we have autocreate mode enabled */ 08863 peer = temp_peer(name); 08864 if (peer) { 08865 ASTOBJ_CONTAINER_LINK(&peerl, peer); 08866 if (sip_cancel_destroy(p)) 08867 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 08868 switch (parse_register_contact(p, peer, req)) { 08869 case PARSE_REGISTER_FAILED: 08870 ast_log(LOG_WARNING, "Failed to parse contact info\n"); 08871 transmit_response_with_date(p, "400 Bad Request", req); 08872 peer->lastmsgssent = -1; 08873 res = 0; 08874 break; 08875 case PARSE_REGISTER_QUERY: 08876 transmit_response_with_date(p, "200 OK", req); 08877 peer->lastmsgssent = -1; 08878 res = 0; 08879 break; 08880 case PARSE_REGISTER_UPDATE: 08881 /* Say OK and ask subsystem to retransmit msg counter */ 08882 transmit_response_with_date(p, "200 OK", req); 08883 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: SIP/%s\r\nPeerStatus: Registered\r\n", peer->name); 08884 peer->lastmsgssent = -1; 08885 res = 0; 08886 break; 08887 } 08888 } 08889 } 08890 if (!res) { 08891 ast_device_state_changed("SIP/%s", peer->name); 08892 } 08893 if (res < 0) { 08894 switch (res) { 08895 case AUTH_SECRET_FAILED: 08896 /* Wrong password in authentication. Go away, don't try again until you fixed it */ 08897 transmit_response(p, "403 Forbidden (Bad auth)", &p->initreq); 08898 break; 08899 case AUTH_USERNAME_MISMATCH: 08900 /* Username and digest username does not match. 08901 Asterisk uses the From: username for authentication. We need the 08902 users to use the same authentication user name until we support 08903 proper authentication by digest auth name */ 08904 transmit_response(p, "403 Authentication user name does not match account name", &p->initreq); 08905 break; 08906 case AUTH_NOT_FOUND: 08907 case AUTH_PEER_NOT_DYNAMIC: 08908 case AUTH_ACL_FAILED: 08909 if (global_alwaysauthreject) { 08910 transmit_fake_auth_response(p, &p->initreq, 1); 08911 } else { 08912 /* URI not found */ 08913 if (res == AUTH_PEER_NOT_DYNAMIC) 08914 transmit_response(p, "403 Forbidden", &p->initreq); 08915 else 08916 transmit_response(p, "404 Not found", &p->initreq); 08917 } 08918 break; 08919 default: 08920 break; 08921 } 08922 } 08923 if (peer) 08924 ASTOBJ_UNREF(peer, sip_destroy_peer); 08925 08926 return res; 08927 }
| static char * regstate2str | ( | enum sipregistrystate | regstate | ) | [static] |
Convert registration state status to string.
Definition at line 7527 of file chan_sip.c.
References REG_STATE_AUTHSENT, REG_STATE_FAILED, REG_STATE_NOAUTH, REG_STATE_REGISTERED, REG_STATE_REGSENT, REG_STATE_REJECTED, REG_STATE_TIMEOUT, and REG_STATE_UNREGISTERED.
Referenced by handle_response_register(), sip_reg_timeout(), and sip_show_registry().
07528 { 07529 switch(regstate) { 07530 case REG_STATE_FAILED: 07531 return "Failed"; 07532 case REG_STATE_UNREGISTERED: 07533 return "Unregistered"; 07534 case REG_STATE_REGSENT: 07535 return "Request Sent"; 07536 case REG_STATE_AUTHSENT: 07537 return "Auth. Sent"; 07538 case REG_STATE_REGISTERED: 07539 return "Registered"; 07540 case REG_STATE_REJECTED: 07541 return "Rejected"; 07542 case REG_STATE_TIMEOUT: 07543 return "Timeout"; 07544 case REG_STATE_NOAUTH: 07545 return "No Authentication"; 07546 default: 07547 return "Unknown"; 07548 } 07549 }
| static int reload | ( | void | ) | [static] |
Part of Asterisk module interface.
Definition at line 18524 of file chan_sip.c.
References sip_reload().
18525 { 18526 return sip_reload(0, 0, NULL); 18527 }
| static int reload_config | ( | enum channelreloadreason | reason | ) | [static] |
Re-read SIP.conf config file.
< Default DTMF setting: RFC2833
< NAT support if requested by device with rport
< Allow re-invites
Definition at line 17402 of file chan_sip.c.
References __ourip, add_realm_authentication(), add_sip_domain(), ast_append_ha(), ast_category_browse(), ast_clear_flag, ast_config_AST_SYSTEM_NAME, ast_config_destroy(), ast_config_load(), ast_context_create(), ast_context_find(), ast_copy_flags, ast_copy_string(), ast_device_state_changed(), ast_enable_packet_fragmentation(), ast_find_ourip(), AST_FLAGS_ALL, ast_free_ha(), ast_get_ip_or_srv(), ast_gethostbyname(), ast_inet_ntoa(), ast_jb_read_conf(), AST_LIST_EMPTY, ast_log(), AST_MAX_CONTEXT, ast_mutex_lock(), ast_mutex_unlock(), ast_parse_allow_disallow(), ast_set2_flag, ast_set_flag, ast_str2tos(), ast_strdupa, ast_strip(), ast_strlen_zero(), ast_tos2str(), ast_true(), ast_variable_browse(), ast_variable_retrieve(), ast_verbose(), ASTOBJ_CONTAINER_DESTROYALL, ASTOBJ_CONTAINER_LINK, ASTOBJ_CONTAINER_MARKALL, ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_RDLOCK, ASTOBJ_UNLOCK, ASTOBJ_UNREF, build_peer(), build_user(), channelreloadreason2txt(), cleanup_stale_contexts(), clear_realm_authentication(), clear_sip_domains(), domain::context, DEFAULT_ALLOW_EXT_DOM, DEFAULT_ALLOWGUEST, DEFAULT_AUTOCREATEPEER, DEFAULT_CALLERID, DEFAULT_COMPACTHEADERS, DEFAULT_CONTEXT, DEFAULT_DEFAULT_EXPIRY, DEFAULT_EXPIRY, DEFAULT_MAX_CALL_BITRATE, DEFAULT_MAX_EXPIRY, DEFAULT_MAXMS, DEFAULT_MIN_EXPIRY, DEFAULT_MOHINTERPRET, DEFAULT_MOHSUGGEST, DEFAULT_MWITIME, DEFAULT_NOTIFYMIME, DEFAULT_NOTIFYRINGING, DEFAULT_PEDANTIC, default_prefs, DEFAULT_QUALIFY, DEFAULT_REALM, DEFAULT_REGISTRATION_TIMEOUT, DEFAULT_SRVLOOKUP, DEFAULT_T1MIN, DEFAULT_TOS_AUDIO, DEFAULT_TOS_SIP, DEFAULT_TOS_VIDEO, DEFAULT_USERAGENT, DEFAULT_VMEXTEN, errno, EVENT_FLAG_SYSTEM, externip, FALSE, gen, global_jbconf, handle_common_options(), hp, ast_variable::lineno, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, manager_event(), sip_peer::name, ast_variable::name, netlock, ast_variable::next, option_debug, option_verbose, outboundproxyip, peerl, regl, secret, SIP_CAN_REINVITE, sip_destroy(), sip_destroy_peer(), sip_destroy_user(), SIP_DOMAIN_AUTO, SIP_DOMAIN_CONFIG, SIP_DTMF_RFC2833, SIP_NAT_RFC3581, SIP_PAGE2_ALLOWOVERLAP, SIP_PAGE2_ALLOWSUBSCRIBE, SIP_PAGE2_DEBUG_CONFIG, SIP_PAGE2_DEBUG_CONSOLE, SIP_PAGE2_IGNOREREGEXPIRE, SIP_PAGE2_RTAUTOCLEAR, SIP_PAGE2_RTCACHEFRIENDS, SIP_PAGE2_RTSAVE_SYSNAME, SIP_PAGE2_RTUPDATE, SIP_PAGE2_VIDEOSUPPORT, sip_register(), sip_registry_destroy(), SIP_USEREQPHONE, STANDARD_SIP_PORT, TRANSFER_CLOSED, TRANSFER_OPENFORALL, userl, username, ast_variable::value, and VERBOSE_PREFIX_2.
17403 { 17404 struct ast_config *cfg, *ucfg; 17405 struct ast_variable *v; 17406 struct sip_peer *peer; 17407 struct sip_user *user; 17408 struct ast_hostent ahp; 17409 char *cat, *stringp, *context, *oldregcontext; 17410 char newcontexts[AST_MAX_CONTEXT], oldcontexts[AST_MAX_CONTEXT]; 17411 struct hostent *hp; 17412 int format; 17413 struct ast_flags dummy[2]; 17414 int auto_sip_domains = FALSE; 17415 struct sockaddr_in old_bindaddr = bindaddr; 17416 int registry_count = 0, peer_count = 0, user_count = 0; 17417 unsigned int temp_tos = 0; 17418 struct ast_flags debugflag = {0}; 17419 17420 cfg = ast_config_load(config); 17421 17422 /* We *must* have a config file otherwise stop immediately */ 17423 if (!cfg) { 17424 ast_log(LOG_NOTICE, "Unable to load config %s\n", config); 17425 return -1; 17426 } 17427 17428 if (option_debug > 3) 17429 ast_log(LOG_DEBUG, "--------------- SIP reload started\n"); 17430 17431 clear_realm_authentication(authl); 17432 clear_sip_domains(); 17433 authl = NULL; 17434 17435 ast_free_ha(global_contact_ha); 17436 global_contact_ha = NULL; 17437 17438 /* First, destroy all outstanding registry calls */ 17439 /* This is needed, since otherwise active registry entries will not be destroyed */ 17440 ASTOBJ_CONTAINER_TRAVERSE(®l, 1, do { 17441 ASTOBJ_RDLOCK(iterator); 17442 if (iterator->call) { 17443 if (option_debug > 2) 17444 ast_log(LOG_DEBUG, "Destroying active SIP dialog for registry %s@%s\n", iterator->username, iterator->hostname); 17445 /* This will also remove references to the registry */ 17446 sip_destroy(iterator->call); 17447 } 17448 ASTOBJ_UNLOCK(iterator); 17449 17450 } while(0)); 17451 17452 /* Then, actually destroy users and registry */ 17453 ASTOBJ_CONTAINER_DESTROYALL(&userl, sip_destroy_user); 17454 if (option_debug > 3) 17455 ast_log(LOG_DEBUG, "--------------- Done destroying user list\n"); 17456 ASTOBJ_CONTAINER_DESTROYALL(®l, sip_registry_destroy); 17457 if (option_debug > 3) 17458 ast_log(LOG_DEBUG, "--------------- Done destroying registry list\n"); 17459 ASTOBJ_CONTAINER_MARKALL(&peerl); 17460 17461 /* Initialize copy of current global_regcontext for later use in removing stale contexts */ 17462 ast_copy_string(oldcontexts, global_regcontext, sizeof(oldcontexts)); 17463 oldregcontext = oldcontexts; 17464 17465 /* Clear all flags before setting default values */ 17466 /* Preserve debugging settings for console */ 17467 ast_copy_flags(&debugflag, &global_flags[1], SIP_PAGE2_DEBUG_CONSOLE); 17468 ast_clear_flag(&global_flags[0], AST_FLAGS_ALL); 17469 ast_clear_flag(&global_flags[1], AST_FLAGS_ALL); 17470 ast_copy_flags(&global_flags[1], &debugflag, SIP_PAGE2_DEBUG_CONSOLE); 17471 17472 /* Reset IP addresses */ 17473 memset(&bindaddr, 0, sizeof(bindaddr)); 17474 ast_free_ha(localaddr); 17475 memset(&localaddr, 0, sizeof(localaddr)); 17476 memset(&externip, 0, sizeof(externip)); 17477 memset(&default_prefs, 0 , sizeof(default_prefs)); 17478 outboundproxyip.sin_port = htons(STANDARD_SIP_PORT); 17479 outboundproxyip.sin_family = AF_INET; /* Type of address: IPv4 */ 17480 ourport = STANDARD_SIP_PORT; 17481 srvlookup = DEFAULT_SRVLOOKUP; 17482 global_tos_sip = DEFAULT_TOS_SIP; 17483 global_tos_audio = DEFAULT_TOS_AUDIO; 17484 global_tos_video = DEFAULT_TOS_VIDEO; 17485 externhost[0] = '\0'; /* External host name (for behind NAT DynDNS support) */ 17486 externexpire = 0; /* Expiration for DNS re-issuing */ 17487 externrefresh = 10; 17488 memset(&outboundproxyip, 0, sizeof(outboundproxyip)); 17489 17490 /* Reset channel settings to default before re-configuring */ 17491 allow_external_domains = DEFAULT_ALLOW_EXT_DOM; /* Allow external invites */ 17492 global_regcontext[0] = '\0'; 17493 expiry = DEFAULT_EXPIRY; 17494 global_notifyringing = DEFAULT_NOTIFYRINGING; 17495 global_limitonpeers = FALSE; 17496 global_directrtpsetup = FALSE; /* Experimental feature, disabled by default */ 17497 global_notifyhold = FALSE; 17498 global_alwaysauthreject = 0; 17499 global_allowsubscribe = FALSE; 17500 ast_copy_string(global_useragent, DEFAULT_USERAGENT, sizeof(global_useragent)); 17501 ast_copy_string(default_notifymime, DEFAULT_NOTIFYMIME, sizeof(default_notifymime)); 17502 if (ast_strlen_zero(ast_config_AST_SYSTEM_NAME)) 17503 ast_copy_string(global_realm, DEFAULT_REALM, sizeof(global_realm)); 17504 else 17505 ast_copy_string(global_realm, ast_config_AST_SYSTEM_NAME, sizeof(global_realm)); 17506 ast_copy_string(default_callerid, DEFAULT_CALLERID, sizeof(default_callerid)); 17507 compactheaders = DEFAULT_COMPACTHEADERS; 17508 global_reg_timeout = DEFAULT_REGISTRATION_TIMEOUT; 17509 global_regattempts_max = 0; 17510 pedanticsipchecking = DEFAULT_PEDANTIC; 17511 global_mwitime = DEFAULT_MWITIME; 17512 autocreatepeer = DEFAULT_AUTOCREATEPEER; 17513 global_autoframing = 0; 17514 global_allowguest = DEFAULT_ALLOWGUEST; 17515 global_rtptimeout = 0; 17516 global_rtpholdtimeout = 0; 17517 global_rtpkeepalive = 0; 17518 global_allowtransfer = TRANSFER_OPENFORALL; /* Merrily accept all transfers by default */ 17519 global_rtautoclear = 120; 17520 ast_set_flag(&global_flags[1], SIP_PAGE2_ALLOWSUBSCRIBE); /* Default for peers, users: TRUE */ 17521 ast_set_flag(&global_flags[1], SIP_PAGE2_ALLOWOVERLAP); /* Default for peers, users: TRUE */ 17522 ast_set_flag(&global_flags[1], SIP_PAGE2_RTUPDATE); 17523 17524 /* Initialize some reasonable defaults at SIP reload (used both for channel and as default for peers and users */ 17525 ast_copy_string(default_context, DEFAULT_CONTEXT, sizeof(default_context)); 17526 default_subscribecontext[0] = '\0'; 17527 default_language[0] = '\0'; 17528 default_fromdomain[0] = '\0'; 17529 default_qualify = DEFAULT_QUALIFY; 17530 default_maxcallbitrate = DEFAULT_MAX_CALL_BITRATE; 17531 ast_copy_string(default_mohinterpret, DEFAULT_MOHINTERPRET, sizeof(default_mohinterpret)); 17532 ast_copy_string(default_mohsuggest, DEFAULT_MOHSUGGEST, sizeof(default_mohsuggest)); 17533 ast_copy_string(default_vmexten, DEFAULT_VMEXTEN, sizeof(default_vmexten)); 17534 ast_set_flag(&global_flags[0], SIP_DTMF_RFC2833); /*!< Default DTMF setting: RFC2833 */ 17535 ast_set_flag(&global_flags[0], SIP_NAT_RFC3581); /*!< NAT support if requested by device with rport */ 17536 ast_set_flag(&global_flags[0], SIP_CAN_REINVITE); /*!< Allow re-invites */ 17537 17538 /* Debugging settings, always default to off */ 17539 dumphistory = FALSE; 17540 recordhistory = FALSE; 17541 ast_clear_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONFIG); 17542 17543 /* Misc settings for the channel */ 17544 global_relaxdtmf = FALSE; 17545 global_callevents = FALSE; 17546 global_t1min = DEFAULT_T1MIN; 17547 17548 global_matchexterniplocally = FALSE; 17549 17550 /* Copy the default jb config over global_jbconf */ 17551 memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf)); 17552 17553 ast_clear_flag(&global_flags[1], SIP_PAGE2_VIDEOSUPPORT); 17554 17555 /* Read the [general] config section of sip.conf (or from realtime config) */ 17556 for (v = ast_variable_browse(cfg, "general"); v; v = v->next) { 17557 if (handle_common_options(&global_flags[0], &dummy[0], v)) 17558 continue; 17559 /* handle jb conf */ 17560 if (!ast_jb_read_conf(&global_jbconf, v->name, v->value)) 17561 continue; 17562 17563 /* Create the interface list */ 17564 if (!strcasecmp(v->name, "context")) { 17565 ast_copy_string(default_context, v->value, sizeof(default_context)); 17566 } else if (!strcasecmp(v->name, "subscribecontext")) { 17567 ast_copy_string(default_subscribecontext, v->value, sizeof(default_subscribecontext)); 17568 } else if (!strcasecmp(v->name, "allowguest")) { 17569 global_allowguest = ast_true(v->value) ? 1 : 0; 17570 } else if (!strcasecmp(v->name, "realm")) { 17571 ast_copy_string(global_realm, v->value, sizeof(global_realm)); 17572 } else if (!strcasecmp(v->name, "useragent")) { 17573 ast_copy_string(global_useragent, v->value, sizeof(global_useragent)); 17574 if (option_debug) 17575 ast_log(LOG_DEBUG, "Setting SIP channel User-Agent Name to %s\n", global_useragent); 17576 } else if (!strcasecmp(v->name, "allowtransfer")) { 17577 global_allowtransfer = ast_true(v->value) ? TRANSFER_OPENFORALL : TRANSFER_CLOSED; 17578 } else if (!strcasecmp(v->name, "rtcachefriends")) { 17579 ast_set2_flag(&global_flags[1], ast_true(v->value), SIP_PAGE2_RTCACHEFRIENDS); 17580 } else if (!strcasecmp(v->name, "rtsavesysname")) { 17581 ast_set2_flag(&global_flags[1], ast_true(v->value), SIP_PAGE2_RTSAVE_SYSNAME); 17582 } else if (!strcasecmp(v->name, "rtupdate")) { 17583 ast_set2_flag(&global_flags[1], ast_true(v->value), SIP_PAGE2_RTUPDATE); 17584 } else if (!strcasecmp(v->name, "ignoreregexpire")) { 17585 ast_set2_flag(&global_flags[1], ast_true(v->value), SIP_PAGE2_IGNOREREGEXPIRE); 17586 } else if (!strcasecmp(v->name, "t1min")) { 17587 global_t1min = atoi(v->value); 17588 } else if (!strcasecmp(v->name, "dynamic_exclude_static") || !strcasecmp(v->name, "dynamic_excludes_static")) { 17589 global_dynamic_exclude_static = ast_true(v->value); 17590 } else if (!strcasecmp(v->name, "contactpermit") || !strcasecmp(v->name, "contactdeny")) { 17591 global_contact_ha = ast_append_ha(v->name + 7, v->value, global_contact_ha); 17592 } else if (!strcasecmp(v->name, "rtautoclear")) { 17593 int i = atoi(v->value); 17594 if (i > 0) 17595 global_rtautoclear = i; 17596 else 17597 i = 0; 17598 ast_set2_flag(&global_flags[1], i || ast_true(v->value), SIP_PAGE2_RTAUTOCLEAR); 17599 } else if (!strcasecmp(v->name, "usereqphone")) { 17600 ast_set2_flag(&global_flags[0], ast_true(v->value), SIP_USEREQPHONE); 17601 } else if (!strcasecmp(v->name, "relaxdtmf")) { 17602 global_relaxdtmf = ast_true(v->value); 17603 } else if (!strcasecmp(v->name, "checkmwi")) { 17604 if ((sscanf(v->value, "%d", &global_mwitime) != 1) || (global_mwitime < 0)) { 17605 ast_log(LOG_WARNING, "'%s' is not a valid MWI time setting at line %d. Using default (10).\n", v->value, v->lineno); 17606 global_mwitime = DEFAULT_MWITIME; 17607 } 17608 } else if (!strcasecmp(v->name, "vmexten")) { 17609 ast_copy_string(default_vmexten, v->value, sizeof(default_vmexten)); 17610 } else if (!strcasecmp(v->name, "rtptimeout")) { 17611 if ((sscanf(v->value, "%d", &global_rtptimeout) != 1) || (global_rtptimeout < 0)) { 17612 ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno); 17613 global_rtptimeout = 0; 17614 } 17615 } else if (!strcasecmp(v->name, "rtpholdtimeout")) { 17616 if ((sscanf(v->value, "%d", &global_rtpholdtimeout) != 1) || (global_rtpholdtimeout < 0)) { 17617 ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno); 17618 global_rtpholdtimeout = 0; 17619 } 17620 } else if (!strcasecmp(v->name, "rtpkeepalive")) { 17621 if ((sscanf(v->value, "%d", &global_rtpkeepalive) != 1) || (global_rtpkeepalive < 0)) { 17622 ast_log(LOG_WARNING, "'%s' is not a valid RTP keepalive time at line %d. Using default.\n", v->value, v->lineno); 17623 global_rtpkeepalive = 0; 17624 } 17625 } else if (!strcasecmp(v->name, "compactheaders")) { 17626 compactheaders = ast_true(v->value); 17627 } else if (!strcasecmp(v->name, "notifymimetype")) { 17628 ast_copy_string(default_notifymime, v->value, sizeof(default_notifymime)); 17629 } else if (!strncasecmp(v->name, "limitonpeer", 11)) { 17630 global_limitonpeers = ast_true(v->value); 17631 } else if (!strcasecmp(v->name, "directrtpsetup")) { 17632 global_directrtpsetup = ast_true(v->value); 17633 } else if (!strcasecmp(v->name, "notifyringing")) { 17634 global_notifyringing = ast_true(v->value); 17635 } else if (!strcasecmp(v->name, "notifyhold")) { 17636 global_notifyhold = ast_true(v->value); 17637 } else if (!strcasecmp(v->name, "alwaysauthreject")) { 17638 global_alwaysauthreject = ast_true(v->value); 17639 } else if (!strcasecmp(v->name, "mohinterpret") 17640 || !strcasecmp(v->name, "musicclass") || !strcasecmp(v->name, "musiconhold")) { 17641 ast_copy_string(default_mohinterpret, v->value, sizeof(default_mohinterpret)); 17642 } else if (!strcasecmp(v->name, "mohsuggest")) { 17643 ast_copy_string(default_mohsuggest, v->value, sizeof(default_mohsuggest)); 17644 } else if (!strcasecmp(v->name, "language")) { 17645 ast_copy_string(default_language, v->value, sizeof(default_language)); 17646 } else if (!strcasecmp(v->name, "regcontext")) { 17647 ast_copy_string(newcontexts, v->value, sizeof(newcontexts)); 17648 stringp = newcontexts; 17649 /* Let's remove any contexts that are no longer defined in regcontext */ 17650 cleanup_stale_contexts(stringp, oldregcontext); 17651 /* Create contexts if they don't exist already */ 17652 while ((context = strsep(&stringp, "&"))) { 17653 if (!ast_context_find(context)) 17654 ast_context_create(NULL, context,"SIP"); 17655 } 17656 ast_copy_string(global_regcontext, v->value, sizeof(global_regcontext)); 17657 } else if (!strcasecmp(v->name, "callerid")) { 17658 ast_copy_string(default_callerid, v->value, sizeof(default_callerid)); 17659 } else if (!strcasecmp(v->name, "fromdomain")) { 17660 ast_copy_string(default_fromdomain, v->value, sizeof(default_fromdomain)); 17661 } else if (!strcasecmp(v->name, "outboundproxy")) { 17662 if (ast_get_ip_or_srv(&outboundproxyip, v->value, srvlookup ? "_sip._udp" : NULL) < 0) 17663 ast_log(LOG_WARNING, "Unable to locate host '%s'\n", v->value); 17664 } else if (!strcasecmp(v->name, "outboundproxyport")) { 17665 /* Port needs to be after IP */ 17666 sscanf(v->value, "%d", &format); 17667 outboundproxyip.sin_port = htons(format); 17668 } else if (!strcasecmp(v->name, "autocreatepeer")) { 17669 autocreatepeer = ast_true(v->value); 17670 } else if (!strcasecmp(v->name, "srvlookup")) { 17671 srvlookup = ast_true(v->value); 17672 } else if (!strcasecmp(v->name, "pedantic")) { 17673 pedanticsipchecking = ast_true(v->value); 17674 } else if (!strcasecmp(v->name, "maxexpirey") || !strcasecmp(v->name, "maxexpiry")) { 17675 max_expiry = atoi(v->value); 17676 if (max_expiry < 1) 17677 max_expiry = DEFAULT_MAX_EXPIRY; 17678 } else if (!strcasecmp(v->name, "minexpirey") || !strcasecmp(v->name, "minexpiry")) { 17679 min_expiry = atoi(v->value); 17680 if (min_expiry < 1) 17681 min_expiry = DEFAULT_MIN_EXPIRY; 17682 } else if (!strcasecmp(v->name, "defaultexpiry") || !strcasecmp(v->name, "defaultexpirey")) { 17683 default_expiry = atoi(v->value); 17684 if (default_expiry < 1) 17685 default_expiry = DEFAULT_DEFAULT_EXPIRY; 17686 } else if (!strcasecmp(v->name, "sipdebug")) { /* XXX maybe ast_set2_flags ? */ 17687 if (ast_true(v->value)) 17688 ast_set_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONFIG); 17689 } else if (!strcasecmp(v->name, "dumphistory")) { 17690 dumphistory = ast_true(v->value); 17691 } else if (!strcasecmp(v->name, "recordhistory")) { 17692 recordhistory = ast_true(v->value); 17693 } else if (!strcasecmp(v->name, "registertimeout")) { 17694 global_reg_timeout = atoi(v->value); 17695 if (global_reg_timeout < 1) 17696 global_reg_timeout = DEFAULT_REGISTRATION_TIMEOUT; 17697 } else if (!strcasecmp(v->name, "registerattempts")) { 17698 global_regattempts_max = atoi(v->value); 17699 } else if (!strcasecmp(v->name, "bindaddr")) { 17700 if (!(hp = ast_gethostbyname(v->value, &ahp))) { 17701 ast_log(LOG_WARNING, "Invalid address: %s\n", v->value); 17702 } else { 17703 memcpy(&bindaddr.sin_addr, hp->h_addr, sizeof(bindaddr.sin_addr)); 17704 } 17705 } else if (!strcasecmp(v->name, "localnet")) { 17706 struct ast_ha *na; 17707 if (!(na = ast_append_ha("d", v->value, localaddr))) 17708 ast_log(LOG_WARNING, "Invalid localnet value: %s\n", v->value); 17709 else 17710 localaddr = na; 17711 } else if (!strcasecmp(v->name, "localmask")) { 17712 ast_log(LOG_WARNING, "Use of localmask is no long supported -- use localnet with mask syntax\n"); 17713 } else if (!strcasecmp(v->name, "externip")) { 17714 if (!(hp = ast_gethostbyname(v->value, &ahp))) 17715 ast_log(LOG_WARNING, "Invalid address for externip keyword: %s\n", v->value); 17716 else 17717 memcpy(&externip.sin_addr, hp->h_addr, sizeof(externip.sin_addr)); 17718 externexpire = 0; 17719 } else if (!strcasecmp(v->name, "externhost")) { 17720 ast_copy_string(externhost, v->value, sizeof(externhost)); 17721 if (!(hp = ast_gethostbyname(externhost, &ahp))) 17722 ast_log(LOG_WARNING, "Invalid address for externhost keyword: %s\n", externhost); 17723 else 17724 memcpy(&externip.sin_addr, hp->h_addr, sizeof(externip.sin_addr)); 17725 externexpire = time(NULL); 17726 } else if (!strcasecmp(v->name, "externrefresh")) { 17727 if (sscanf(v->value, "%d", &externrefresh) != 1) { 17728 ast_log(LOG_WARNING, "Invalid externrefresh value '%s', must be an integer >0 at line %d\n", v->value, v->lineno); 17729 externrefresh = 10; 17730 } 17731 } else if (!strcasecmp(v->name, "allow")) { 17732 ast_parse_allow_disallow(&default_prefs, &global_capability, v->value, 1); 17733 } else if (!strcasecmp(v->name, "disallow")) { 17734 ast_parse_allow_disallow(&default_prefs, &global_capability, v->value, 0); 17735 } else if (!strcasecmp(v->name, "autoframing")) { 17736 global_autoframing = ast_true(v->value); 17737 } else if (!strcasecmp(v->name, "allowexternaldomains")) { 17738 allow_external_domains = ast_true(v->value); 17739 } else if (!strcasecmp(v->name, "autodomain")) { 17740 auto_sip_domains = ast_true(v->value); 17741 } else if (!strcasecmp(v->name, "domain")) { 17742 char *domain = ast_strdupa(v->value); 17743 char *context = strchr(domain, ','); 17744 17745 if (context) 17746 *context++ = '\0'; 17747 17748 if (option_debug && ast_strlen_zero(context)) 17749 ast_log(LOG_DEBUG, "No context specified at line %d for domain '%s'\n", v->lineno, domain); 17750 if (ast_strlen_zero(domain)) 17751 ast_log(LOG_WARNING, "Empty domain specified at line %d\n", v->lineno); 17752 else 17753 add_sip_domain(ast_strip(domain), SIP_DOMAIN_CONFIG, context ? ast_strip(context) : ""); 17754 } else if (!strcasecmp(v->name, "register")) { 17755 if (sip_register(v->value, v->lineno) == 0) 17756 registry_count++; 17757 } else if (!strcasecmp(v->name, "tos")) { 17758 if (!ast_str2tos(v->value, &temp_tos)) { 17759 global_tos_sip = temp_tos; 17760 global_tos_audio = temp_tos; 17761 global_tos_video = temp_tos; 17762 ast_log(LOG_WARNING, "tos value at line %d is deprecated. See doc/ip-tos.txt for more information.\n", v->lineno); 17763 } else 17764 ast_log(LOG_WARNING, "Invalid tos value at line %d, See doc/ip-tos.txt for more information.\n", v->lineno); 17765 } else if (!strcasecmp(v->name, "tos_sip")) { 17766 if (ast_str2tos(v->value, &global_tos_sip)) 17767 ast_log(LOG_WARNING, "Invalid tos_sip value at line %d, recommended value is 'cs3'. See doc/ip-tos.txt.\n", v->lineno); 17768 } else if (!strcasecmp(v->name, "tos_audio")) { 17769 if (ast_str2tos(v->value, &global_tos_audio)) 17770 ast_log(LOG_WARNING, "Invalid tos_audio value at line %d, recommended value is 'ef'. See doc/ip-tos.txt.\n", v->lineno); 17771 } else if (!strcasecmp(v->name, "tos_video")) { 17772 if (ast_str2tos(v->value, &global_tos_video)) 17773 ast_log(LOG_WARNING, "Invalid tos_video value at line %d, recommended value is 'af41'. See doc/ip-tos.txt.\n", v->lineno); 17774 } else if (!strcasecmp(v->name, "bindport")) { 17775 if (sscanf(v->value, "%d", &ourport) == 1) { 17776 bindaddr.sin_port = htons(ourport); 17777 } else { 17778 ast_log(LOG_WARNING, "Invalid port number '%s' at line %d of %s\n", v->value, v->lineno, config); 17779 } 17780 } else if (!strcasecmp(v->name, "qualify")) { 17781 if (!strcasecmp(v->value, "no")) { 17782 default_qualify = 0; 17783 } else if (!strcasecmp(v->value, "yes")) { 17784 default_qualify = DEFAULT_MAXMS; 17785 } else if (sscanf(v->value, "%d", &default_qualify) != 1) { 17786 ast_log(LOG_WARNING, "Qualification default should be 'yes', 'no', or a number of milliseconds at line %d of sip.conf\n", v->lineno); 17787 default_qualify = 0; 17788 } 17789 } else if (!strcasecmp(v->name, "callevents")) { 17790 global_callevents = ast_true(v->value); 17791 } else if (!strcasecmp(v->name, "maxcallbitrate")) { 17792 default_maxcallbitrate = atoi(v->value); 17793 if (default_maxcallbitrate < 0) 17794 default_maxcallbitrate = DEFAULT_MAX_CALL_BITRATE; 17795 } else if (!strcasecmp(v->name, "matchexterniplocally")) { 17796 global_matchexterniplocally = ast_true(v->value); 17797 } 17798 } 17799 17800 if (!allow_external_domains && AST_LIST_EMPTY(&domain_list)) { 17801 ast_log(LOG_WARNING, "To disallow external domains, you need to configure local SIP domains.\n"); 17802 allow_external_domains = 1; 17803 } 17804 17805 /* Build list of authentication to various SIP realms, i.e. service providers */ 17806 for (v = ast_variable_browse(cfg, "authentication"); v ; v = v->next) { 17807 /* Format for authentication is auth = username:password@realm */ 17808 if (!strcasecmp(v->name, "auth")) 17809 authl = add_realm_authentication(authl, v->value, v->lineno); 17810 } 17811 17812 ucfg = ast_config_load("users.conf"); 17813 if (ucfg) { 17814 struct ast_variable *gen; 17815 int genhassip, genregistersip; 17816 const char *hassip, *registersip; 17817 17818 genhassip = ast_true(ast_variable_retrieve(ucfg, "general", "hassip")); 17819 genregistersip = ast_true(ast_variable_retrieve(ucfg, "general", "registersip")); 17820 gen = ast_variable_browse(ucfg, "general"); 17821 cat = ast_category_browse(ucfg, NULL); 17822 while (cat) { 17823 if (strcasecmp(cat, "general")) { 17824 hassip = ast_variable_retrieve(ucfg, cat, "hassip"); 17825 registersip = ast_variable_retrieve(ucfg, cat, "registersip"); 17826 if (ast_true(hassip) || (!hassip && genhassip)) { 17827 user = build_user(cat, gen, ast_variable_browse(ucfg, cat), 0); 17828 if (user) { 17829 ASTOBJ_CONTAINER_LINK(&userl,user); 17830 ASTOBJ_UNREF(user, sip_destroy_user); 17831 user_count++; 17832 } 17833 peer = build_peer(cat, gen, ast_variable_browse(ucfg, cat), 0); 17834 if (peer) { 17835 ast_device_state_changed("SIP/%s", peer->name); 17836 ASTOBJ_CONTAINER_LINK(&peerl,peer); 17837 ASTOBJ_UNREF(peer, sip_destroy_peer); 17838 peer_count++; 17839 } 17840 } 17841 if (ast_true(registersip) || (!registersip && genregistersip)) { 17842 char tmp[256]; 17843 const char *host = ast_variable_retrieve(ucfg, cat, "host"); 17844 const char *username = ast_variable_retrieve(ucfg, cat, "username"); 17845 const char *secret = ast_variable_retrieve(ucfg, cat, "secret"); 17846 const char *contact = ast_variable_retrieve(ucfg, cat, "contact"); 17847 if (!host) 17848 host = ast_variable_retrieve(ucfg, "general", "host"); 17849 if (!username) 17850 username = ast_variable_retrieve(ucfg, "general", "username"); 17851 if (!secret) 17852 secret = ast_variable_retrieve(ucfg, "general", "secret"); 17853 if (!contact) 17854 contact = "s"; 17855 if (!ast_strlen_zero(username) && !ast_strlen_zero(host)) { 17856 if (!ast_strlen_zero(secret)) 17857 snprintf(tmp, sizeof(tmp), "%s:%s@%s/%s", username, secret, host, contact); 17858 else 17859 snprintf(tmp, sizeof(tmp), "%s@%s/%s", username, host, contact); 17860 if (sip_register(tmp, 0) == 0) 17861 registry_count++; 17862 } 17863 } 17864 } 17865 cat = ast_category_browse(ucfg, cat); 17866 } 17867 ast_config_destroy(ucfg); 17868 } 17869 17870 17871 /* Load peers, users and friends */ 17872 cat = NULL; 17873 while ( (cat = ast_category_browse(cfg, cat)) ) { 17874 const char *utype; 17875 if (!strcasecmp(cat, "general") || !strcasecmp(cat, "authentication")) 17876 continue; 17877 utype = ast_variable_retrieve(cfg, cat, "type"); 17878 if (!utype) { 17879 ast_log(LOG_WARNING, "Section '%s' lacks type\n", cat); 17880 continue; 17881 } else { 17882 int is_user = 0, is_peer = 0; 17883 if (!strcasecmp(utype, "user")) 17884 is_user = 1; 17885 else if (!strcasecmp(utype, "friend")) 17886 is_user = is_peer = 1; 17887 else if (!strcasecmp(utype, "peer")) 17888 is_peer = 1; 17889 else { 17890 ast_log(LOG_WARNING, "Unknown type '%s' for '%s' in %s\n", utype, cat, "sip.conf"); 17891 continue; 17892 } 17893 if (is_user) { 17894 user = build_user(cat, ast_variable_browse(cfg, cat), NULL, 0); 17895 if (user) { 17896 ASTOBJ_CONTAINER_LINK(&userl,user); 17897 ASTOBJ_UNREF(user, sip_destroy_user); 17898 user_count++; 17899 } 17900 } 17901 if (is_peer) { 17902 peer = build_peer(cat, ast_variable_browse(cfg, cat), NULL, 0); 17903 if (peer) { 17904 ASTOBJ_CONTAINER_LINK(&peerl,peer); 17905 ASTOBJ_UNREF(peer, sip_destroy_peer); 17906 peer_count++; 17907 } 17908 } 17909 } 17910 } 17911 if (ast_find_ourip(&__ourip, bindaddr)) { 17912 ast_log(LOG_WARNING, "Unable to get own IP address, SIP disabled\n"); 17913 ast_config_destroy(cfg); 17914 return 0; 17915 } 17916 if (!ntohs(bindaddr.sin_port)) 17917 bindaddr.sin_port = ntohs(STANDARD_SIP_PORT); 17918 bindaddr.sin_family = AF_INET; 17919 ast_mutex_lock(&netlock); 17920 if ((sipsock > -1) && (memcmp(&old_bindaddr, &bindaddr, sizeof(struct sockaddr_in)))) { 17921 close(sipsock); 17922 sipsock = -1; 17923 } 17924 if (sipsock < 0) { 17925 sipsock = socket(AF_INET, SOCK_DGRAM, 0); 17926 if (sipsock < 0) { 17927 ast_log(LOG_WARNING, "Unable to create SIP socket: %s\n", strerror(errno)); 17928 ast_config_destroy(cfg); 17929 return -1; 17930 } else { 17931 /* Allow SIP clients on the same host to access us: */ 17932 const int reuseFlag = 1; 17933 17934 setsockopt(sipsock, SOL_SOCKET, SO_REUSEADDR, 17935 (const char*)&reuseFlag, 17936 sizeof reuseFlag); 17937 17938 ast_enable_packet_fragmentation(sipsock); 17939 17940 if (bind(sipsock, (struct sockaddr *)&bindaddr, sizeof(bindaddr)) < 0) { 17941 ast_log(LOG_WARNING, "Failed to bind to %s:%d: %s\n", 17942 ast_inet_ntoa(bindaddr.sin_addr), ntohs(bindaddr.sin_port), 17943 strerror(errno)); 17944 close(sipsock); 17945 sipsock = -1; 17946 } else { 17947 if (option_verbose > 1) { 17948 ast_verbose(VERBOSE_PREFIX_2 "SIP Listening on %s:%d\n", 17949 ast_inet_ntoa(bindaddr.sin_addr), ntohs(bindaddr.sin_port)); 17950 ast_verbose(VERBOSE_PREFIX_2 "Using SIP TOS: %s\n", ast_tos2str(global_tos_sip)); 17951 } 17952 if (setsockopt(sipsock, IPPROTO_IP, IP_TOS, &global_tos_sip, sizeof(global_tos_sip))) 17953 ast_log(LOG_WARNING, "Unable to set SIP TOS to %s\n", ast_tos2str(global_tos_sip)); 17954 } 17955 } 17956 } 17957 ast_mutex_unlock(&netlock); 17958 17959 /* Add default domains - host name, IP address and IP:port */ 17960 /* Only do this if user added any sip domain with "localdomains" */ 17961 /* In order to *not* break backwards compatibility */ 17962 /* Some phones address us at IP only, some with additional port number */ 17963 if (auto_sip_domains) { 17964 char temp[MAXHOSTNAMELEN]; 17965 17966 /* First our default IP address */ 17967 if (bindaddr.sin_addr.s_addr) 17968 add_sip_domain(ast_inet_ntoa(bindaddr.sin_addr), SIP_DOMAIN_AUTO, NULL); 17969 else 17970 ast_log(LOG_NOTICE, "Can't add wildcard IP address to domain list, please add IP address to domain manually.\n"); 17971 17972 /* Our extern IP address, if configured */ 17973 if (externip.sin_addr.s_addr) 17974 add_sip_domain(ast_inet_ntoa(externip.sin_addr), SIP_DOMAIN_AUTO, NULL); 17975 17976 /* Extern host name (NAT traversal support) */ 17977 if (!ast_strlen_zero(externhost)) 17978 add_sip_domain(externhost, SIP_DOMAIN_AUTO, NULL); 17979 17980 /* Our host name */ 17981 if (!gethostname(temp, sizeof(temp))) 17982 add_sip_domain(temp, SIP_DOMAIN_AUTO, NULL); 17983 } 17984 17985 /* Release configuration from memory */ 17986 ast_config_destroy(cfg); 17987 17988 /* Load the list of manual NOTIFY types to support */ 17989 if (notify_types) 17990 ast_config_destroy(notify_types); 17991 notify_types = ast_config_load(notify_config); 17992 17993 /* Done, tell the manager */ 17994 manager_event(EVENT_FLAG_SYSTEM, "ChannelReload", "Channel: SIP\r\nReloadReason: %s\r\nRegistry_Count: %d\r\nPeer_Count: %d\r\nUser_Count: %d\r\n", channelreloadreason2txt(reason), registry_count, peer_count, user_count); 17995 17996 return 0; 17997 }
| 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 11656 of file chan_sip.c.
References ast_copy_string(), ast_log(), ast_skip_blanks(), ast_string_field_index, ast_string_field_index_set, ast_string_field_set, ast_strlen_zero(), build_reply_digest(), sip_pvt::domain, get_header(), keys, LOG_WARNING, sip_registry::nonce, sip_pvt::nonce, sip_registry::noncecount, sip_pvt::noncecount, sip_pvt::opaque, sip_registry::opaque, sip_pvt::qop, sip_registry::qop, sip_pvt::realm, sip_registry::realm, and sip_pvt::registry.
Referenced by do_proxy_auth(), and do_register_auth().
11657 { 11658 char tmp[512]; 11659 char *c; 11660 char oldnonce[256]; 11661 11662 /* table of recognised keywords, and places where they should be copied */ 11663 const struct x { 11664 const char *key; 11665 int field_index; 11666 } *i, keys[] = { 11667 { "realm=", ast_string_field_index(p, realm) }, 11668 { "nonce=", ast_string_field_index(p, nonce) }, 11669 { "opaque=", ast_string_field_index(p, opaque) }, 11670 { "qop=", ast_string_field_index(p, qop) }, 11671 { "domain=", ast_string_field_index(p, domain) }, 11672 { NULL, 0 }, 11673 }; 11674 11675 ast_copy_string(tmp, get_header(req, header), sizeof(tmp)); 11676 if (ast_strlen_zero(tmp)) 11677 return -1; 11678 if (strncasecmp(tmp, "Digest ", strlen("Digest "))) { 11679 ast_log(LOG_WARNING, "missing Digest.\n"); 11680 return -1; 11681 } 11682 c = tmp + strlen("Digest "); 11683 ast_copy_string(oldnonce, p->nonce, sizeof(oldnonce)); 11684 while (c && *(c = ast_skip_blanks(c))) { /* lookup for keys */ 11685 for (i = keys; i->key != NULL; i++) { 11686 char *src, *separator; 11687 if (strncasecmp(c, i->key, strlen(i->key)) != 0) 11688 continue; 11689 /* Found. Skip keyword, take text in quotes or up to the separator. */ 11690 c += strlen(i->key); 11691 if (*c == '"') { 11692 src = ++c; 11693 separator = "\""; 11694 } else { 11695 src = c; 11696 separator = ","; 11697 } 11698 strsep(&c, separator); /* clear separator and move ptr */ 11699 ast_string_field_index_set(p, i->field_index, src); 11700 break; 11701 } 11702 if (i->key == NULL) /* not found, try ',' */ 11703 strsep(&c, ","); 11704 } 11705 /* Reset nonce count */ 11706 if (strcmp(p->nonce, oldnonce)) 11707 p->noncecount = 0; 11708 11709 /* Save auth data for following registrations */ 11710 if (p->registry) { 11711 struct sip_registry *r = p->registry; 11712 11713 if (strcmp(r->nonce, p->nonce)) { 11714 ast_string_field_set(r, realm, p->realm); 11715 ast_string_field_set(r, nonce, p->nonce); 11716 ast_string_field_set(r, domain, p->domain); 11717 ast_string_field_set(r, opaque, p->opaque); 11718 ast_string_field_set(r, qop, p->qop); 11719 r->noncecount = 0; 11720 } 11721 } 11722 return build_reply_digest(p, sipmethod, digest, digest_len); 11723 }
| static int reqprep | ( | struct sip_request * | req, | |
| struct sip_pvt * | p, | |||
| int | sipmethod, | |||
| int | seqno, | |||
| int | newbranch | |||
| ) | [static] |
Initialize a SIP request message (not the initial one in a dialog).
< Strict routing flag
Definition at line 6006 of file chan_sip.c.
References add_header(), add_route(), ast_copy_string(), ast_log(), ast_random(), ast_strlen_zero(), ast_test_flag, sip_pvt::branch, build_via(), sip_pvt::callid, copy_header(), DEFAULT_MAX_FORWARDS, FALSE, sip_pvt::flags, get_header(), get_in_brackets(), sip_route::hop, init_req(), sip_pvt::initreq, sip_pvt::invite_branch, sip_pvt::lastmsg, LOG_DEBUG, sip_route::next, sip_pvt::ocseq, sip_pvt::okcontacturi, sip_pvt::our_contact, sip_request::rlPart2, sip_pvt::route, sip_pvt::rpid, set_destination(), SIP_ACK, SIP_BYE, SIP_CANCEL, SIP_MESSAGE, sip_methods, SIP_OUTGOING, sipdebug, sip_pvt::tag, text, cfsip_methods::text, sip_pvt::theirtag, TRUE, sip_pvt::uri, and sip_pvt::via.
Referenced by transmit_info_with_digit(), transmit_info_with_vidupdate(), transmit_invite(), transmit_message_with_text(), transmit_notify_with_sipfrag(), transmit_refer(), transmit_reinvite_with_sdp(), transmit_reinvite_with_t38_sdp(), transmit_request(), transmit_request_with_auth(), and transmit_state_notify().
06007 { 06008 struct sip_request *orig = &p->initreq; 06009 char stripped[80]; 06010 char tmp[80]; 06011 char newto[256]; 06012 const char *c; 06013 const char *ot, *of; 06014 int is_strict = FALSE; /*!< Strict routing flag */ 06015 06016 memset(req, 0, sizeof(struct sip_request)); 06017 06018 snprintf(p->lastmsg, sizeof(p->lastmsg), "Tx: %s", sip_methods[sipmethod].text); 06019 06020 if (!seqno) { 06021 p->ocseq++; 06022 seqno = p->ocseq; 06023 } 06024 06025 if (sipmethod == SIP_CANCEL) { 06026 p->branch = p->invite_branch; 06027 build_via(p); 06028 } else if (newbranch) { 06029 p->branch ^= ast_random(); 06030 build_via(p); 06031 } 06032 06033 /* Check for strict or loose router */ 06034 if (p->route && !ast_strlen_zero(p->route->hop) && strstr(p->route->hop,";lr") == NULL) { 06035 is_strict = TRUE; 06036 if (sipdebug) 06037 ast_log(LOG_DEBUG, "Strict routing enforced for session %s\n", p->callid); 06038 } 06039 06040 if (sipmethod == SIP_CANCEL) 06041 c = p->initreq.rlPart2; /* Use original URI */ 06042 else if (sipmethod == SIP_ACK) { 06043 /* Use URI from Contact: in 200 OK (if INVITE) 06044 (we only have the contacturi on INVITEs) */ 06045 if (!ast_strlen_zero(p->okcontacturi)) 06046 c = is_strict ? p->route->hop : p->okcontacturi; 06047 else 06048 c = p->initreq.rlPart2; 06049 } else if (!ast_strlen_zero(p->okcontacturi)) 06050 c = is_strict ? p->route->hop : p->okcontacturi; /* Use for BYE or REINVITE */ 06051 else if (!ast_strlen_zero(p->uri)) 06052 c = p->uri; 06053 else { 06054 char *n; 06055 /* We have no URI, use To: or From: header as URI (depending on direction) */ 06056 ast_copy_string(stripped, get_header(orig, (ast_test_flag(&p->flags[0], SIP_OUTGOING)) ? "To" : "From"), 06057 sizeof(stripped)); 06058 n = get_in_brackets(stripped); 06059 c = strsep(&n, ";"); /* trim ; and beyond */ 06060 } 06061 init_req(req, sipmethod, c); 06062 06063 snprintf(tmp, sizeof(tmp), "%d %s", seqno, sip_methods[sipmethod].text); 06064 06065 add_header(req, "Via", p->via); 06066 if (p->route) { 06067 set_destination(p, p->route->hop); 06068 add_route(req, is_strict ? p->route->next : p->route); 06069 } 06070 06071 ot = get_header(orig, "To"); 06072 of = get_header(orig, "From"); 06073 06074 /* Add tag *unless* this is a CANCEL, in which case we need to send it exactly 06075 as our original request, including tag (or presumably lack thereof) */ 06076 if (!strcasestr(ot, "tag=") && sipmethod != SIP_CANCEL) { 06077 /* Add the proper tag if we don't have it already. If they have specified 06078 their tag, use it. Otherwise, use our own tag */ 06079 if (ast_test_flag(&p->flags[0], SIP_OUTGOING) && !ast_strlen_zero(p->theirtag)) 06080 snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->theirtag); 06081 else if (!ast_test_flag(&p->flags[0], SIP_OUTGOING)) 06082 snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->tag); 06083 else 06084 snprintf(newto, sizeof(newto), "%s", ot); 06085 ot = newto; 06086 } 06087 06088 if (ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 06089 add_header(req, "From", of); 06090 add_header(req, "To", ot); 06091 } else { 06092 add_header(req, "From", ot); 06093 add_header(req, "To", of); 06094 } 06095 /* Do not add Contact for MESSAGE, BYE and Cancel requests */ 06096 if (sipmethod != SIP_BYE && sipmethod != SIP_CANCEL && sipmethod != SIP_MESSAGE) 06097 add_header(req, "Contact", p->our_contact); 06098 06099 copy_header(req, orig, "Call-ID"); 06100 add_header(req, "CSeq", tmp); 06101 06102 if (!ast_strlen_zero(global_useragent)) 06103 add_header(req, "User-Agent", global_useragent); 06104 add_header(req, "Max-Forwards", DEFAULT_MAX_FORWARDS); 06105 06106 if (!ast_strlen_zero(p->rpid)) 06107 add_header(req, "Remote-Party-ID", p->rpid); 06108 06109 return 0; 06110 }
| 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 5958 of file chan_sip.c.
References add_header(), ALLOWED_METHODS, ast_copy_string(), ast_strlen_zero(), ast_test_flag, copy_all_header(), copy_header(), copy_via_headers(), sip_pvt::expiry, sip_pvt::flags, get_header(), init_resp(), sip_pvt::method, sip_pvt::our_contact, SIP_OUTGOING, SIP_REGISTER, SIP_SUBSCRIBE, SIPBUFSIZE, SUPPORTED_EXTENSIONS, sip_pvt::tag, and sip_pvt::theirtag.
Referenced by __transmit_response(), transmit_response_with_allow(), transmit_response_with_auth(), transmit_response_with_date(), transmit_response_with_sdp(), transmit_response_with_t38_sdp(), and transmit_response_with_unsupported().
05959 { 05960 char newto[256]; 05961 const char *ot; 05962 05963 init_resp(resp, msg); 05964 copy_via_headers(p, resp, req, "Via"); 05965 if (msg[0] == '1' || msg[0] == '2') 05966 copy_all_header(resp, req, "Record-Route"); 05967 copy_header(resp, req, "From"); 05968 ot = get_header(req, "To"); 05969 if (!strcasestr(ot, "tag=") && strncmp(msg, "100", 3)) { 05970 /* Add the proper tag if we don't have it already. If they have specified 05971 their tag, use it. Otherwise, use our own tag */ 05972 if (!ast_strlen_zero(p->theirtag) && ast_test_flag(&p->flags[0], SIP_OUTGOING)) 05973 snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->theirtag); 05974 else if (p->tag && !ast_test_flag(&p->flags[0], SIP_OUTGOING)) 05975 snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->tag); 05976 else 05977 ast_copy_string(newto, ot, sizeof(newto)); 05978 ot = newto; 05979 } 05980 add_header(resp, "To", ot); 05981 copy_header(resp, req, "Call-ID"); 05982 copy_header(resp, req, "CSeq"); 05983 if (!ast_strlen_zero(global_useragent)) 05984 add_header(resp, "User-Agent", global_useragent); 05985 add_header(resp, "Allow", ALLOWED_METHODS); 05986 add_header(resp, "Supported", SUPPORTED_EXTENSIONS); 05987 if (msg[0] == '2' && (p->method == SIP_SUBSCRIBE || p->method == SIP_REGISTER)) { 05988 /* For registration responses, we also need expiry and 05989 contact info */ 05990 char tmp[256]; 05991 05992 snprintf(tmp, sizeof(tmp), "%d", p->expiry); 05993 add_header(resp, "Expires", tmp); 05994 if (p->expiry) { /* Only add contact if we have an expiry time */ 05995 char contact[SIPBUFSIZE]; 05996 snprintf(contact, sizeof(contact), "%s;expires=%d", p->our_contact, p->expiry); 05997 add_header(resp, "Contact", contact); /* Not when we unregister */ 05998 } 05999 } else if (msg[0] != '4' && !ast_strlen_zero(p->our_contact)) { 06000 add_header(resp, "Contact", p->our_contact); 06001 } 06002 return 0; 06003 }
| static int restart_monitor | ( | void | ) | [static] |
Start the channel monitor thread.
Definition at line 2734 of file chan_ooh323.c.
References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_pthread_create, AST_PTHREADT_NULL, AST_PTHREADT_STOP, do_monitor(), LOG_ERROR, LOG_WARNING, monitor_thread, and monlock.
02735 { 02736 pthread_attr_t attr; 02737 02738 /* If we're supposed to be stopped -- stay stopped */ 02739 if (monitor_thread == AST_PTHREADT_STOP) 02740 return 0; 02741 if (ast_mutex_lock(&monlock)) { 02742 ast_log(LOG_WARNING, "Unable to lock monitor\n"); 02743 return -1; 02744 } 02745 if (monitor_thread == pthread_self()) { 02746 ast_mutex_unlock(&monlock); 02747 ast_log(LOG_WARNING, "Cannot kill myself\n"); 02748 return -1; 02749 } 02750 if (monitor_thread != AST_PTHREADT_NULL) { 02751 /* Wake up the thread */ 02752 pthread_kill(monitor_thread, SIGURG); 02753 } 02754 else { 02755 pthread_attr_init(&attr); 02756 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); 02757 /* Start a new monitor */ 02758 if (ast_pthread_create(&monitor_thread, &attr, do_monitor, NULL) < 0) { 02759 ast_mutex_unlock(&monlock); 02760 ast_log(LOG_ERROR, "Unable to start monitor thread.\n"); 02761 return -1; 02762 } 02763 } 02764 ast_mutex_unlock(&monlock); 02765 return 0; 02766 }
| static int retrans_pkt | ( | const void * | data | ) | [static] |
Retransmit SIP message if no answer (Called from scheduler).
Definition at line 1910 of file chan_sip.c.
References __sip_xmit(), append_history, AST_CAUSE_NO_USER_RESPONSE, ast_channel_trylock, ast_channel_unlock, ast_inet_ntoa(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_queue_hangup(), ast_set_flag, ast_test_flag, ast_verbose(), sip_pvt::callid, sip_pkt::data, DEADLOCK_AVOIDANCE, DEFAULT_RETRANS, FLAG_FATAL, FLAG_RESPONSE, sip_pvt::flags, free, ast_channel::hangupcause, sip_pvt::lock, LOG_DEBUG, LOG_WARNING, MAX_RETRANS, sip_pkt::method, sip_pkt::next, option_debug, sip_pvt::owner, sip_pkt::owner, sip_pkt::packetlen, sip_pvt::packets, sip_pkt::retrans, sip_pkt::retransid, sip_pkt::seqno, sip_alreadygone(), SIP_BYE, sip_debug_test_pvt(), SIP_INVITE, sip_methods, sip_nat_mode(), SIP_NEEDDESTROY, SIP_OPTIONS, sip_real_dst(), sipdebug, cfsip_methods::text, sip_pkt::timer_a, sip_pkt::timer_t1, and XMIT_ERROR.
Referenced by __sip_reliable_xmit().
01911 { 01912 struct sip_pkt *pkt = (struct sip_pkt *)data, *prev, *cur = NULL; 01913 int reschedule = DEFAULT_RETRANS; 01914 int xmitres = 0; 01915 01916 /* Lock channel PVT */ 01917 ast_mutex_lock(&pkt->owner->lock); 01918 01919 if (pkt->retrans < MAX_RETRANS) { 01920 pkt->retrans++; 01921 if (!pkt->timer_t1) { /* Re-schedule using timer_a and timer_t1 */ 01922 if (sipdebug && option_debug > 3) 01923 ast_log(LOG_DEBUG, "SIP TIMER: Not rescheduling id #%d:%s (Method %d) (No timer T1)\n", pkt->retransid, sip_methods[pkt->method].text, pkt->method); 01924 } else { 01925 int siptimer_a; 01926 01927 if (sipdebug && option_debug > 3) 01928 ast_log(LOG_DEBUG, "SIP TIMER: Rescheduling retransmission #%d (%d) %s - %d\n", pkt->retransid, pkt->retrans, sip_methods[pkt->method].text, pkt->method); 01929 if (!pkt->timer_a) 01930 pkt->timer_a = 2 ; 01931 else 01932 pkt->timer_a = 2 * pkt->timer_a; 01933 01934 /* For non-invites, a maximum of 4 secs */ 01935 siptimer_a = pkt->timer_t1 * pkt->timer_a; /* Double each time */ 01936 if (pkt->method != SIP_INVITE && siptimer_a > 4000) 01937 siptimer_a = 4000; 01938 01939 /* Reschedule re-transmit */ 01940 reschedule = siptimer_a; 01941 if (option_debug > 3) 01942 ast_log(LOG_DEBUG, "** SIP timers: Rescheduling retransmission %d to %d ms (t1 %d ms (Retrans id #%d)) \n", pkt->retrans +1, siptimer_a, pkt->timer_t1, pkt->retransid); 01943 } 01944 01945 if (sip_debug_test_pvt(pkt->owner)) { 01946 const struct sockaddr_in *dst = sip_real_dst(pkt->owner); 01947 ast_verbose("Retransmitting #%d (%s) to %s:%d:\n%s\n---\n", 01948 pkt->retrans, sip_nat_mode(pkt->owner), 01949 ast_inet_ntoa(dst->sin_addr), 01950 ntohs(dst->sin_port), pkt->data); 01951 } 01952 01953 append_history(pkt->owner, "ReTx", "%d %s", reschedule, pkt->data); 01954 xmitres = __sip_xmit(pkt->owner, pkt->data, pkt->packetlen); 01955 ast_mutex_unlock(&pkt->owner->lock); 01956 if (xmitres == XMIT_ERROR) 01957 ast_log(LOG_WARNING, "Network error on retransmit in dialog %s\n", pkt->owner->callid); 01958 else 01959 return reschedule; 01960 } 01961 /* Too many retries */ 01962 if (pkt->owner && pkt->method != SIP_OPTIONS && xmitres == 0) { 01963 if (ast_test_flag(pkt, FLAG_FATAL) || sipdebug) /* Tell us if it's critical or if we're debugging */ 01964 ast_log(LOG_WARNING, "Maximum retries exceeded on transmission %s for seqno %d (%s %s) -- See doc/sip-retransmit.txt.\n", pkt->owner->callid, pkt->seqno, (ast_test_flag(pkt, FLAG_FATAL)) ? "Critical" : "Non-critical", (ast_test_flag(pkt, FLAG_RESPONSE)) ? "Response" : "Request"); 01965 } else if ((pkt->method == SIP_OPTIONS) && sipdebug) { 01966 ast_log(LOG_WARNING, "Cancelling retransmit of OPTIONs (call id %s) -- See doc/sip-retransmit.txt.\n", pkt->owner->callid); 01967 } 01968 if (xmitres == XMIT_ERROR) { 01969 ast_log(LOG_WARNING, "Transmit error :: Cancelling transmission of transaction in call id %s \n", pkt->owner->callid); 01970 append_history(pkt->owner, "XmitErr", "%s", (ast_test_flag(pkt, FLAG_FATAL)) ? "(Critical)" : "(Non-critical)"); 01971 } else 01972 append_history(pkt->owner, "MaxRetries", "%s", (ast_test_flag(pkt, FLAG_FATAL)) ? "(Critical)" : "(Non-critical)"); 01973 01974 pkt->retransid = -1; 01975 01976 if (ast_test_flag(pkt, FLAG_FATAL)) { 01977 while(pkt->owner->owner && ast_channel_trylock(pkt->owner->owner)) { 01978 DEADLOCK_AVOIDANCE(&pkt->owner->lock); /* SIP_PVT, not channel */ 01979 } 01980 01981 if (pkt->owner->owner && !pkt->owner->owner->hangupcause) 01982 pkt->owner->owner->hangupcause = AST_CAUSE_NO_USER_RESPONSE; 01983 01984 if (pkt->owner->owner) { 01985 sip_alreadygone(pkt->owner); 01986 ast_log(LOG_WARNING, "Hanging up call %s - no reply to our critical packet (see doc/sip-retransmit.txt).\n", pkt->owner->callid); 01987 ast_queue_hangup(pkt->owner->owner); 01988 ast_channel_unlock(pkt->owner->owner); 01989 } else { 01990 /* If no channel owner, destroy now */ 01991 01992 /* Let the peerpoke system expire packets when the timer expires for poke_noanswer */ 01993 if (pkt->method != SIP_OPTIONS) { 01994 ast_set_flag(&pkt->owner->flags[0], SIP_NEEDDESTROY); 01995 sip_alreadygone(pkt->owner); 01996 if (option_debug) 01997 append_history(pkt->owner, "DialogKill", "Killing this failed dialog immediately"); 01998 } 01999 } 02000 } 02001 02002 if (pkt->method == SIP_BYE) { 02003 /* We're not getting answers on SIP BYE's. Tear down the call anyway. */ 02004 if (pkt->owner->owner) 02005 ast_channel_unlock(pkt->owner->owner); 02006 append_history(pkt->owner, "ByeFailure", "Remote peer doesn't respond to bye. Destroying call anyway."); 02007 ast_set_flag(&pkt->owner->flags[0], SIP_NEEDDESTROY); 02008 } 02009 02010 /* In any case, go ahead and remove the packet */ 02011 for (prev = NULL, cur = pkt->owner->packets; cur; prev = cur, cur = cur->next) { 02012 if (cur == pkt) 02013 break; 02014 } 02015 if (cur) { 02016 if (prev) 02017 prev->next = cur->next; 02018 else 02019 pkt->owner->packets = cur->next; 02020 ast_mutex_unlock(&pkt->owner->lock); 02021 free(cur); 02022 pkt = NULL; 02023 } else 02024 ast_log(LOG_WARNING, "Weird, couldn't find packet owner!\n"); 02025 if (pkt) 02026 ast_mutex_unlock(&pkt->owner->lock); 02027 return 0; 02028 }
| static int send_request | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| enum xmittype | reliable, | |||
| int | seqno | |||
| ) | [static] |
Send SIP Request to the other part of the dialogue.
Definition at line 2308 of file chan_sip.c.
References __sip_reliable_xmit(), __sip_xmit(), add_blank(), append_history, ast_inet_ntoa(), ast_test_flag, ast_verbose(), sip_request::data, sip_pvt::flags, get_header(), sip_request::len, sip_request::method, parse_copy(), sip_pvt::recv, sip_pvt::sa, sip_debug_test_pvt(), sip_methods, SIP_NAT_ROUTE, SIP_NO_HISTORY, cfsip_methods::text, and XMIT_CRITICAL.
Referenced by 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_reinvite_with_t38_sdp(), transmit_request(), transmit_request_with_auth(), transmit_sip_request(), and transmit_state_notify().
02309 { 02310 int res; 02311 02312 add_blank(req); 02313 if (sip_debug_test_pvt(p)) { 02314 if (ast_test_flag(&p->flags[0], SIP_NAT_ROUTE)) 02315 ast_verbose("%sTransmitting (NAT) to %s:%d:\n%s\n---\n", reliable ? "Reliably " : "", ast_inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port), req->data); 02316 else 02317 ast_verbose("%sTransmitting (no NAT) to %s:%d:\n%s\n---\n", reliable ? "Reliably " : "", ast_inet_ntoa(p->sa.sin_addr), ntohs(p->sa.sin_port), req->data); 02318 } 02319 if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) { 02320 struct sip_request tmp; 02321 parse_copy(&tmp, req); 02322 append_history(p, reliable ? "TxReqRel" : "TxReq", "%s / %s - %s", tmp.data, get_header(&tmp, "CSeq"), sip_methods[tmp.method].text); 02323 } 02324 res = (reliable) ? 02325 __sip_reliable_xmit(p, seqno, 0, req->data, req->len, (reliable == XMIT_CRITICAL), req->method) : 02326 __sip_xmit(p, req->data, req->len); 02327 return res; 02328 }
| static int send_response | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| enum xmittype | reliable, | |||
| int | seqno | |||
| ) | [static] |
Transmit response on SIP request.
Definition at line 2280 of file chan_sip.c.
References __sip_reliable_xmit(), __sip_xmit(), add_blank(), append_history, ast_inet_ntoa(), ast_test_flag, ast_verbose(), sip_request::data, sip_pvt::flags, get_header(), sip_request::len, sip_request::method, parse_copy(), sip_request::rlPart2, sip_debug_test_pvt(), sip_methods, sip_nat_mode(), SIP_NO_HISTORY, sip_real_dst(), SIP_RESPONSE, SIP_UNKNOWN, cfsip_methods::text, and XMIT_CRITICAL.
Referenced by __transmit_response(), transmit_response_with_allow(), transmit_response_with_auth(), transmit_response_with_date(), transmit_response_with_sdp(), transmit_response_with_t38_sdp(), and transmit_response_with_unsupported().
02281 { 02282 int res; 02283 02284 add_blank(req); 02285 if (sip_debug_test_pvt(p)) { 02286 const struct sockaddr_in *dst = sip_real_dst(p); 02287 02288 ast_verbose("\n<--- %sTransmitting (%s) to %s:%d --->\n%s\n<------------>\n", 02289 reliable ? "Reliably " : "", sip_nat_mode(p), 02290 ast_inet_ntoa(dst->sin_addr), 02291 ntohs(dst->sin_port), req->data); 02292 } 02293 if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) { 02294 struct sip_request tmp; 02295 parse_copy(&tmp, req); 02296 append_history(p, reliable ? "TxRespRel" : "TxResp", "%s / %s - %s", tmp.data, get_header(&tmp, "CSeq"), 02297 (tmp.method == SIP_RESPONSE || tmp.method == SIP_UNKNOWN) ? tmp.rlPart2 : sip_methods[tmp.method].text); 02298 } 02299 res = (reliable) ? 02300 __sip_reliable_xmit(p, seqno, 1, req->data, req->len, (reliable == XMIT_CRITICAL), req->method) : 02301 __sip_xmit(p, req->data, req->len); 02302 if (res > 0) 02303 return 0; 02304 return res; 02305 }
| static int set_address_from_contact | ( | struct sip_pvt * | pvt | ) | [static] |
Change the other partys IP address based on given contact.
Definition at line 8195 of file chan_sip.c.
References __set_address_from_contact(), ast_test_flag, sip_pvt::flags, sip_pvt::fullcontact, sip_pvt::recv, sip_pvt::sa, and SIP_NAT_ROUTE.
Referenced by handle_response_invite().
08196 { 08197 if (ast_test_flag(&pvt->flags[0], SIP_NAT_ROUTE)) { 08198 /* NAT: Don't trust the contact field. Just use what they came to us 08199 with. */ 08200 pvt->sa = pvt->recv; 08201 return 0; 08202 } 08203 08204 return __set_address_from_contact(pvt->fullcontact, &pvt->sa); 08205 }
| static void set_destination | ( | struct sip_pvt * | p, | |
| char * | uri | |||
| ) | [static] |
Set destination from SIP URI.
Definition at line 5867 of file chan_sip.c.
References ast_copy_string(), ast_gethostbyname(), ast_inet_ntoa(), ast_log(), ast_verbose(), debug, hostname, hp, LOG_WARNING, sip_pvt::sa, sip_debug_test_pvt(), and STANDARD_SIP_PORT.
Referenced by reqprep().
05868 { 05869 char *h, *maddr, hostname[256]; 05870 int port, hn; 05871 struct hostent *hp; 05872 struct ast_hostent ahp; 05873 int debug=sip_debug_test_pvt(p); 05874 05875 /* Parse uri to h (host) and port - uri is already just the part inside the <> */ 05876 /* general form we are expecting is sip[s]:username[:password]@host[:port][;...] */ 05877 05878 if (debug) 05879 ast_verbose("set_destination: Parsing <%s> for address/port to send to\n", uri); 05880 05881 /* Find and parse hostname */ 05882 h = strchr(uri, '@'); 05883 if (h) 05884 ++h; 05885 else { 05886 h = uri; 05887 if (strncasecmp(h, "sip:", 4) == 0) 05888 h += 4; 05889 else if (strncasecmp(h, "sips:", 5) == 0) 05890 h += 5; 05891 } 05892 hn = strcspn(h, ":;>") + 1; 05893 if (hn > sizeof(hostname)) 05894 hn = sizeof(hostname); 05895 ast_copy_string(hostname, h, hn); 05896 /* XXX bug here if string has been trimmed to sizeof(hostname) */ 05897 h += hn - 1; 05898 05899 /* Is "port" present? if not default to STANDARD_SIP_PORT */ 05900 if (*h == ':') { 05901 /* Parse port */ 05902 ++h; 05903 port = strtol(h, &h, 10); 05904 } 05905 else 05906 port = STANDARD_SIP_PORT; 05907 05908 /* Got the hostname:port - but maybe there's a "maddr=" to override address? */ 05909 maddr = strstr(h, "maddr="); 05910 if (maddr) { 05911 maddr += 6; 05912 hn = strspn(maddr, "0123456789.") + 1; 05913 if (hn > sizeof(hostname)) 05914 hn = sizeof(hostname); 05915 ast_copy_string(hostname, maddr, hn); 05916 } 05917 05918 hp = ast_gethostbyname(hostname, &ahp); 05919 if (hp == NULL) { 05920 ast_log(LOG_WARNING, "Can't find address for host '%s'\n", hostname); 05921 return; 05922 } 05923 p->sa.sin_family = AF_INET; 05924 memcpy(&p->sa.sin_addr, hp->h_addr, sizeof(p->sa.sin_addr)); 05925 p->sa.sin_port = htons(port); 05926 if (debug) 05927 ast_verbose("set_destination: set destination to %s, port %d\n", ast_inet_ntoa(p->sa.sin_addr), port); 05928 }
| static void set_insecure_flags | ( | struct ast_flags * | flags, | |
| const char * | value, | |||
| int | lineno | |||
| ) | [static] |
Parse the "insecure" setting from sip.conf or from realtime.
| flags | a pointer to an ast_flags structure | |
| value | the value of the SIP insecure setting | |
| lineno | linenumber in sip.conf or -1 for realtime |
Definition at line 16615 of file chan_sip.c.
References ast_copy_string(), ast_false(), ast_log(), ast_set_flag, ast_strlen_zero(), ast_true(), LOG_WARNING, domain::next, SIP_INSECURE_INVITE, and SIP_INSECURE_PORT.
Referenced by handle_common_options(), and realtime_peer().
16616 { 16617 static int dep_insecure_very = 0; 16618 static int dep_insecure_yes = 0; 16619 16620 if (ast_strlen_zero(value)) 16621 return; 16622 16623 if (!strcasecmp(value, "very")) { 16624 ast_set_flag(flags, SIP_INSECURE_PORT | SIP_INSECURE_INVITE); 16625 if(!dep_insecure_very) { 16626 if(lineno != -1) 16627 ast_log(LOG_WARNING, "insecure=very at line %d is deprecated; use insecure=port,invite instead\n", lineno); 16628 else 16629 ast_log(LOG_WARNING, "insecure=very is deprecated; use insecure=port,invite instead\n"); 16630 dep_insecure_very = 1; 16631 } 16632 } 16633 else if (ast_true(value)) { 16634 ast_set_flag(flags, SIP_INSECURE_PORT); 16635 if(!dep_insecure_yes) { 16636 if(lineno != -1) 16637 ast_log(LOG_WARNING, "insecure=%s at line %d is deprecated; use insecure=port instead\n", value, lineno); 16638 else 16639 ast_log(LOG_WARNING, "insecure=%s is deprecated; use insecure=port instead\n", value); 16640 dep_insecure_yes = 1; 16641 } 16642 } 16643 else if (!ast_false(value)) { 16644 char buf[64]; 16645 char *word, *next; 16646 ast_copy_string(buf, value, sizeof(buf)); 16647 next = buf; 16648 while ((word = strsep(&next, ","))) { 16649 if (!strcasecmp(word, "port")) 16650 ast_set_flag(flags, SIP_INSECURE_PORT); 16651 else if (!strcasecmp(word, "invite")) 16652 ast_set_flag(flags, SIP_INSECURE_INVITE); 16653 else 16654 ast_log(LOG_WARNING, "Unknown insecure mode '%s' on line %d\n", value, lineno); 16655 } 16656 } 16657 }
| static void set_peer_defaults | ( | struct sip_peer * | peer | ) | [static] |
Set peer defaults before configuring specific configurations.
Definition at line 17046 of file chan_sip.c.
References sip_peer::addr, sip_peer::allowtransfer, ast_copy_flags, sip_peer::autoframing, sip_peer::callgroup, sip_peer::capability, sip_peer::cid_name, sip_peer::cid_num, sip_peer::context, sip_peer::defaddr, default_prefs, sip_peer::expire, sip_peer::flags, sip_peer::fromdomain, sip_peer::fromuser, sip_peer::language, sip_peer::mailbox, sip_peer::maxcallbitrate, sip_peer::maxms, sip_peer::md5secret, sip_peer::mohinterpret, sip_peer::mohsuggest, sip_peer::pickupgroup, sip_peer::pokeexpire, sip_peer::prefs, sip_peer::regexten, sip_peer::rtpholdtimeout, sip_peer::rtpkeepalive, sip_peer::rtptimeout, sip_peer::secret, SIP_FLAGS_TO_COPY, SIP_PAGE2_FLAGS_TO_COPY, STANDARD_SIP_PORT, sip_peer::subscribecontext, and sip_peer::vmexten.
Referenced by build_peer(), and temp_peer().
17047 { 17048 if (peer->expire == 0) { 17049 /* Don't reset expire or port time during reload 17050 if we have an active registration 17051 */ 17052 peer->expire = -1; 17053 peer->pokeexpire = -1; 17054 peer->addr.sin_port = htons(STANDARD_SIP_PORT); 17055 } 17056 ast_copy_flags(&peer->flags[0], &global_flags[0], SIP_FLAGS_TO_COPY); 17057 ast_copy_flags(&peer->flags[1], &global_flags[1], SIP_PAGE2_FLAGS_TO_COPY); 17058 strcpy(peer->context, default_context); 17059 strcpy(peer->subscribecontext, default_subscribecontext); 17060 strcpy(peer->language, default_language); 17061 strcpy(peer->mohinterpret, default_mohinterpret); 17062 strcpy(peer->mohsuggest, default_mohsuggest); 17063 peer->addr.sin_family = AF_INET; 17064 peer->defaddr.sin_family = AF_INET; 17065 peer->capability = global_capability; 17066 peer->maxcallbitrate = default_maxcallbitrate; 17067 peer->rtptimeout = global_rtptimeout; 17068 peer->rtpholdtimeout = global_rtpholdtimeout; 17069 peer->rtpkeepalive = global_rtpkeepalive; 17070 peer->allowtransfer = global_allowtransfer; 17071 peer->autoframing = global_autoframing; 17072 strcpy(peer->vmexten, default_vmexten); 17073 peer->secret[0] = '\0'; 17074 peer->md5secret[0] = '\0'; 17075 peer->cid_num[0] = '\0'; 17076 peer->cid_name[0] = '\0'; 17077 peer->fromdomain[0] = '\0'; 17078 peer->fromuser[0] = '\0'; 17079 peer->regexten[0] = '\0'; 17080 peer->mailbox[0] = '\0'; 17081 peer->callgroup = 0; 17082 peer->pickupgroup = 0; 17083 peer->maxms = default_qualify; 17084 peer->prefs = default_prefs; 17085 }
| static int sip_addheader | ( | struct ast_channel * | chan, | |
| void * | data | |||
| ) | [static] |
Add a SIP header to an outbound INVITE.
Definition at line 18336 of file chan_sip.c.
References ast_channel_lock, ast_channel_unlock, ast_log(), ast_strlen_zero(), FALSE, inbuf(), LOG_DEBUG, LOG_WARNING, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), sipdebug, and TRUE.
Referenced by load_module().
18337 { 18338 int no = 0; 18339 int ok = FALSE; 18340 char varbuf[30]; 18341 char *inbuf = (char *) data; 18342 18343 if (ast_strlen_zero(inbuf)) { 18344 ast_log(LOG_WARNING, "This application requires the argument: Header\n"); 18345 return 0; 18346 } 18347 ast_channel_lock(chan); 18348 18349 /* Check for headers */ 18350 while (!ok && no <= 50) { 18351 no++; 18352 snprintf(varbuf, sizeof(varbuf), "__SIPADDHEADER%.2d", no); 18353 18354 /* Compare without the leading underscores */ 18355 if( (pbx_builtin_getvar_helper(chan, (const char *) varbuf + 2) == (const char *) NULL) ) 18356 ok = TRUE; 18357 } 18358 if (ok) { 18359 pbx_builtin_setvar_helper (chan, varbuf, inbuf); 18360 if (sipdebug) 18361 ast_log(LOG_DEBUG,"SIP Header added \"%s\" as %s\n", inbuf, varbuf); 18362 } else { 18363 ast_log(LOG_WARNING, "Too many SIP headers added, max 50\n"); 18364 } 18365 ast_channel_unlock(chan); 18366 return 0; 18367 }
| static int sip_addrcmp | ( | char * | name, | |
| struct sockaddr_in * | sin | |||
| ) | [static] |
Support routine for find_peer.
Definition at line 2673 of file chan_sip.c.
References sip_peer::addr, ast_test_flag, sip_peer::flags, inaddrcmp(), and SIP_INSECURE_PORT.
Referenced by find_peer().
02674 { 02675 /* We know name is the first field, so we can cast */ 02676 struct sip_peer *p = (struct sip_peer *) name; 02677 return !(!inaddrcmp(&p->addr, sin) || 02678 (ast_test_flag(&p->flags[0], SIP_INSECURE_PORT) && 02679 (p->addr.sin_addr.s_addr == sin->sin_addr.s_addr))); 02680 }
| static struct sip_pvt * sip_alloc | ( | ast_string_field | callid, | |
| struct sockaddr_in * | sin, | |||
| int | useglobal_nat, | |||
| const int | intended_method | |||
| ) | [static, read] |
Allocate SIP_PVT structure and set defaults.
Definition at line 4491 of file chan_sip.c.
References __ourip, sip_pvt::allowtransfer, ast_calloc, ast_copy_flags, ast_log(), ast_mutex_destroy(), ast_mutex_init(), ast_mutex_lock(), ast_mutex_unlock(), ast_random(), ast_rtp_codec_setpref(), AST_RTP_DTMF, ast_rtp_new_with_bindaddr(), ast_rtp_set_rtpholdtimeout(), ast_rtp_set_rtpkeepalive(), ast_rtp_set_rtptimeout(), ast_rtp_setdtmf(), ast_rtp_setdtmfcompensate(), ast_rtp_settos(), ast_set2_flag, ast_sip_ouraddrfor(), ast_string_field_init, ast_string_field_set, ast_test_flag, ast_udptl_get_error_correction_scheme(), ast_udptl_new_with_bindaddr(), ast_udptl_settos(), ast_variables_destroy(), sip_pvt::autoframing, sip_pvt::autokillid, sip_pvt::branch, build_callid_pvt(), build_via(), t38properties::capability, sip_pvt::capability, sip_pvt::chanvars, domain::context, default_prefs, do_setnat(), errno, sip_pvt::flags, free, sip_pvt::fromdomain, iflist, iflock, INITIAL_CSEQ, sip_pvt::initid, t38properties::jointcapability, sip_pvt::lock, LOG_DEBUG, LOG_WARNING, make_our_tag(), sip_pvt::maxcallbitrate, sip_pvt::method, mohinterpret, mohsuggest, sip_pvt::next, sip_pvt::noncodeccapability, NONE, sip_pvt::ocseq, option_debug, sip_pvt::ourip, sip_pvt::prefs, sip_pvt::recv, sip_pvt::rtp, sip_pvt::sa, SIP_DTMF, SIP_DTMF_AUTO, SIP_DTMF_RFC2833, SIP_FLAGS_TO_COPY, sip_methods, SIP_NAT, SIP_NAT_ROUTE, SIP_NO_HISTORY, SIP_OPTIONS, SIP_PAGE2_FLAGS_TO_COPY, SIP_PAGE2_RFC2833_COMPENSATE, SIP_PAGE2_T38SUPPORT, SIP_PAGE2_VIDEOSUPPORT, SIP_REGISTER, sip_pvt::stateid, sip_pvt::subscribed, sip_pvt::t38, T38FAX_RATE_MANAGEMENT_TRANSFERED_TCF, T38FAX_UDP_EC_FEC, T38FAX_UDP_EC_NONE, T38FAX_UDP_EC_REDUNDANCY, sip_pvt::tag, text, sip_pvt::timer_t1, sip_pvt::udptl, UDPTL_ERROR_CORRECTION_FEC, UDPTL_ERROR_CORRECTION_NONE, UDPTL_ERROR_CORRECTION_REDUNDANCY, sip_pvt::vrtp, and sip_pvt::waitid.
Referenced by find_call(), sip_notify(), sip_poke_peer(), sip_request_call(), sip_send_mwi_to_peer(), and transmit_register().
04493 { 04494 struct sip_pvt *p; 04495 04496 if (!(p = ast_calloc(1, sizeof(*p)))) 04497 return NULL; 04498 04499 if (ast_string_field_init(p, 512)) { 04500 free(p); 04501 return NULL; 04502 } 04503 04504 ast_mutex_init(&p->lock); 04505 04506 p->method = intended_method; 04507 p->initid = -1; 04508 p->waitid = -1; 04509 p->autokillid = -1; 04510 p->subscribed = NONE; 04511 p->stateid = -1; 04512 p->prefs = default_prefs; /* Set default codecs for this call */ 04513 04514 if (intended_method != SIP_OPTIONS) /* Peerpoke has it's own system */ 04515 p->timer_t1 = 500; /* Default SIP retransmission timer T1 (RFC 3261) */ 04516 04517 if (sin) { 04518 p->sa = *sin; 04519 if (ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip)) 04520 p->ourip = __ourip; 04521 } else 04522 p->ourip = __ourip; 04523 04524 /* Copy global flags to this PVT at setup. */ 04525 ast_copy_flags(&p->flags[0], &global_flags[0], SIP_FLAGS_TO_COPY); 04526 ast_copy_flags(&p->flags[1], &global_flags[1], SIP_PAGE2_FLAGS_TO_COPY); 04527 04528 ast_set2_flag(&p->flags[0], !recordhistory, SIP_NO_HISTORY); 04529 04530 p->branch = ast_random(); 04531 make_our_tag(p->tag, sizeof(p->tag)); 04532 p->ocseq = INITIAL_CSEQ; 04533 04534 if (sip_methods[intended_method].need_rtp) { 04535 p->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr); 04536 /* If the global videosupport flag is on, we always create a RTP interface for video */ 04537 if (ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT)) 04538 p->vrtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr); 04539 if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT)) 04540 p->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, bindaddr.sin_addr); 04541 if (!p->rtp || (ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) && !p->vrtp)) { 04542 ast_log(LOG_WARNING, "Unable to create RTP audio %s session: %s\n", 04543 ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) ? "and video" : "", strerror(errno)); 04544 ast_mutex_destroy(&p->lock); 04545 if (p->chanvars) { 04546 ast_variables_destroy(p->chanvars); 04547 p->chanvars = NULL; 04548 } 04549 free(p); 04550 return NULL; 04551 } 04552 ast_rtp_setdtmf(p->rtp, ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833); 04553 ast_rtp_setdtmfcompensate(p->rtp, ast_test_flag(&p->flags[1], SIP_PAGE2_RFC2833_COMPENSATE)); 04554 ast_rtp_settos(p->rtp, global_tos_audio); 04555 ast_rtp_set_rtptimeout(p->rtp, global_rtptimeout); 04556 ast_rtp_set_rtpholdtimeout(p->rtp, global_rtpholdtimeout); 04557 ast_rtp_set_rtpkeepalive(p->rtp, global_rtpkeepalive); 04558 if (p->vrtp) { 04559 ast_rtp_settos(p->vrtp, global_tos_video); 04560 ast_rtp_setdtmf(p->vrtp, 0); 04561 ast_rtp_setdtmfcompensate(p->vrtp, 0); 04562 ast_rtp_set_rtptimeout(p->vrtp, global_rtptimeout); 04563 ast_rtp_set_rtpholdtimeout(p->vrtp, global_rtpholdtimeout); 04564 ast_rtp_set_rtpkeepalive(p->vrtp, global_rtpkeepalive); 04565 } 04566 if (p->udptl) 04567 ast_udptl_settos(p->udptl, global_tos_audio); 04568 p->maxcallbitrate = default_maxcallbitrate; 04569 p->autoframing = global_autoframing; 04570 ast_rtp_codec_setpref(p->rtp, &p->prefs); 04571 } 04572 04573 if (useglobal_nat && sin) { 04574 /* Setup NAT structure according to global settings if we have an address */ 04575 ast_copy_flags(&p->flags[0], &global_flags[0], SIP_NAT); 04576 p->recv = *sin; 04577 do_setnat(p, ast_test_flag(&p->flags[0], SIP_NAT) & SIP_NAT_ROUTE); 04578 } 04579 04580 if (p->method != SIP_REGISTER) 04581 ast_string_field_set(p, fromdomain, default_fromdomain); 04582 build_via(p); 04583 if (!callid) 04584 build_callid_pvt(p); 04585 else 04586 ast_string_field_set(p, callid, callid); 04587 /* Assign default music on hold class */ 04588 ast_string_field_set(p, mohinterpret, default_mohinterpret); 04589 ast_string_field_set(p, mohsuggest, default_mohsuggest); 04590 p->capability = global_capability; 04591 p->allowtransfer = global_allowtransfer; 04592 if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) || 04593 (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) 04594 p->noncodeccapability |= AST_RTP_DTMF; 04595 if (p->udptl) { 04596 p->t38.capability = global_t38_capability; 04597 if (ast_udptl_get_error_correction_scheme(p->udptl) == UDPTL_ERROR_CORRECTION_REDUNDANCY) 04598 p->t38.capability |= T38FAX_UDP_EC_REDUNDANCY; 04599 else if (ast_udptl_get_error_correction_scheme(p->udptl) == UDPTL_ERROR_CORRECTION_FEC) 04600 p->t38.capability |= T38FAX_UDP_EC_FEC; 04601 else if (ast_udptl_get_error_correction_scheme(p->udptl) == UDPTL_ERROR_CORRECTION_NONE) 04602 p->t38.capability |= T38FAX_UDP_EC_NONE; 04603 p->t38.capability |= T38FAX_RATE_MANAGEMENT_TRANSFERED_TCF; 04604 p->t38.jointcapability = p->t38.capability; 04605 } 04606 ast_string_field_set(p, context, default_context); 04607 04608 /* Add to active dialog list */ 04609 ast_mutex_lock(&iflock); 04610 p->next = iflist; 04611 iflist = p; 04612 ast_mutex_unlock(&iflock); 04613 if (option_debug) 04614 ast_log(LOG_DEBUG, "Allocating new SIP dialog for %s - %s (%s)\n", callid ? callid : "(No Call-ID)", sip_methods[intended_method].text, p->rtp ? "With RTP" : "No RTP"); 04615 return p; 04616 }
| static void sip_alreadygone | ( | struct sip_pvt * | dialog | ) | [static] |
Definition at line 1668 of file chan_sip.c.
References ast_log(), ast_set_flag, sip_pvt::callid, sip_pvt::flags, LOG_DEBUG, option_debug, and SIP_ALREADYGONE.
Referenced by handle_request_bye(), handle_request_cancel(), handle_request_invite(), handle_request_refer(), handle_response(), handle_response_invite(), retrans_pkt(), sip_indicate(), and sip_sipredirect().
01669 { 01670 if (option_debug > 2) 01671 ast_log(LOG_DEBUG, "Setting SIP_ALREADYGONE on dialog %s\n", dialog->callid); 01672 ast_set_flag(&dialog->flags[0], SIP_ALREADYGONE); 01673 }
| 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 3705 of file chan_sip.c.
References ast_channel::_state, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_set_flag, ast_setstate(), AST_STATE_UP, sip_pvt::flags, sip_pvt::initreq, sip_pvt::lock, LOG_DEBUG, ast_channel::name, option_debug, SIP_PAGE2_DIALOG_ESTABLISHED, t38properties::state, sip_pvt::t38, T38_ENABLED, T38_PEER_DIRECT, ast_channel::tech_pvt, transmit_response_with_sdp(), transmit_response_with_t38_sdp(), try_suggested_sip_codec(), and XMIT_CRITICAL.
03706 { 03707 int res = 0; 03708 struct sip_pvt *p = ast->tech_pvt; 03709 03710 ast_mutex_lock(&p->lock); 03711 if (ast->_state != AST_STATE_UP) { 03712 try_suggested_sip_codec(p); 03713 03714 ast_setstate(ast, AST_STATE_UP); 03715 if (option_debug) 03716 ast_log(LOG_DEBUG, "SIP answering channel: %s\n", ast->name); 03717 if (p->t38.state == T38_PEER_DIRECT) { 03718 p->t38.state = T38_ENABLED; 03719 if (option_debug > 1) 03720 ast_log(LOG_DEBUG,"T38State change to %d on channel %s\n", p->t38.state, ast->name); 03721 res = transmit_response_with_t38_sdp(p, "200 OK", &p->initreq, XMIT_CRITICAL); 03722 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 03723 } else { 03724 res = transmit_response_with_sdp(p, "200 OK", &p->initreq, XMIT_CRITICAL); 03725 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 03726 } 03727 } 03728 ast_mutex_unlock(&p->lock); 03729 return res; 03730 }
| 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 2982 of file chan_sip.c.
References ast_channel::_state, sip_invite_param::addsipheaders, AST_CAUSE_USER_BUSY, AST_FORMAT_AUDIO_MASK, AST_LIST_TRAVERSE, ast_log(), ast_sched_add(), AST_SCHED_DEL, ast_set_flag, AST_STATE_DOWN, AST_STATE_RESERVED, ast_string_field_set, ast_translate_available_formats(), ast_var_name(), ast_var_value(), auto_congest(), sip_pvt::callingpres, t38properties::capability, sip_pvt::capability, ast_channel::cid, cid_name, sip_pvt::cid_name, ast_callerid::cid_pres, sip_invite_param::distinctive_ring, ast_var_t::entries, sip_pvt::flags, ast_channel::hangupcause, INC_CALL_RINGING, sip_pvt::initid, INV_CALLING, sip_pvt::invitestate, t38properties::jointcapability, sip_pvt::jointcapability, sip_pvt::jointnoncodeccapability, LOG_DEBUG, LOG_WARNING, sip_pvt::maxtime, ast_channel::name, sip_pvt::noncodeccapability, option_debug, sip_pvt::options, sip_pvt::prefcodec, sip_invite_param::replaces, SIP_INVITE, SIP_OUTGOING, SIP_TRANS_TIMEOUT, SIPBUFSIZE, sipdebug, t38properties::state, sip_pvt::t38, T38_LOCAL_DIRECT, ast_channel::tech_pvt, sip_invite_param::transfer, transmit_invite(), update_call_counter(), sip_invite_param::uri_options, sip_pvt::username, ast_channel::varshead, sip_invite_param::vxml_url, and XMIT_ERROR.
02983 { 02984 int res, xmitres = 0; 02985 struct sip_pvt *p; 02986 struct varshead *headp; 02987 struct ast_var_t *current; 02988 const char *referer = NULL; /* SIP refererer */ 02989 02990 p = ast->tech_pvt; 02991 if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) { 02992 ast_log(LOG_WARNING, "sip_call called on %s, neither down nor reserved\n", ast->name); 02993 return -1; 02994 } 02995 02996 /* Check whether there is vxml_url, distinctive ring variables */ 02997 headp=&ast->varshead; 02998 AST_LIST_TRAVERSE(headp,current,entries) { 02999 /* Check whether there is a VXML_URL variable */ 03000 if (!p->options->vxml_url && !strcasecmp(ast_var_name(current), "VXML_URL")) { 03001 p->options->vxml_url = ast_var_value(current); 03002 } else if (!p->options->uri_options && !strcasecmp(ast_var_name(current), "SIP_URI_OPTIONS")) { 03003 p->options->uri_options = ast_var_value(current); 03004 } else if (!p->options->distinctive_ring && !strcasecmp(ast_var_name(current), "ALERT_INFO")) { 03005 /* Check whether there is a ALERT_INFO variable */ 03006 p->options->distinctive_ring = ast_var_value(current); 03007 } else if (!p->options->addsipheaders && !strncasecmp(ast_var_name(current), "SIPADDHEADER", strlen("SIPADDHEADER"))) { 03008 /* Check whether there is a variable with a name starting with SIPADDHEADER */ 03009 p->options->addsipheaders = 1; 03010 } else if (!strcasecmp(ast_var_name(current), "SIPTRANSFER")) { 03011 /* This is a transfered call */ 03012 p->options->transfer = 1; 03013 } else if (!strcasecmp(ast_var_name(current), "SIPTRANSFER_REFERER")) { 03014 /* This is the referer */ 03015 referer = ast_var_value(current); 03016 } else if (!strcasecmp(ast_var_name(current), "SIPTRANSFER_REPLACES")) { 03017 /* We're replacing a call. */ 03018 p->options->replaces = ast_var_value(current); 03019 } else if (!strcasecmp(ast_var_name(current), "T38CALL")) { 03020 p->t38.state = T38_LOCAL_DIRECT; 03021 if (option_debug) 03022 ast_log(LOG_DEBUG,"T38State change to %d on channel %s\n", p->t38.state, ast->name); 03023 } 03024 03025 } 03026 03027 res = 0; 03028 ast_set_flag(&p->flags[0], SIP_OUTGOING); 03029 03030 if (p->options->transfer) { 03031 char buf[SIPBUFSIZE/2]; 03032 03033 if (referer) { 03034 if (sipdebug && option_debug > 2) 03035 ast_log(LOG_DEBUG, "Call for %s transfered by %s\n", p->username, referer); 03036 snprintf(buf, sizeof(buf)-1, "-> %s (via %s)", p->cid_name, referer); 03037 } else 03038 snprintf(buf, sizeof(buf)-1, "-> %s", p->cid_name); 03039 ast_string_field_set(p, cid_name, buf); 03040 } 03041 if (option_debug) 03042 ast_log(LOG_DEBUG, "Outgoing Call for %s\n", p->username); 03043 03044 res = update_call_counter(p, INC_CALL_RINGING); 03045 if ( res != -1 ) { 03046 p->callingpres = ast->cid.cid_pres; 03047 p->jointcapability = ast_translate_available_formats(p->capability, p->prefcodec); 03048 p->jointnoncodeccapability = p->noncodeccapability; 03049 03050 /* If there are no audio formats left to offer, punt */ 03051 if (!(p->jointcapability & AST_FORMAT_AUDIO_MASK)) { 03052 ast_log(LOG_WARNING, "No audio format found to offer. Cancelling call to %s\n", p->username); 03053 res = -1; 03054 } else { 03055 p->t38.jointcapability = p->t38.capability; 03056 if (option_debug > 1) 03057 ast_log(LOG_DEBUG,"Our T38 capability (%d), joint T38 capability (%d)\n", p->t38.capability, p->t38.jointcapability); 03058 xmitres = transmit_invite(p, SIP_INVITE, 1, 2); 03059 if (xmitres == XMIT_ERROR) 03060 return -1; /* Transmission error */ 03061 03062 p->invitestate = INV_CALLING; 03063 03064 /* Initialize auto-congest time */ 03065 AST_SCHED_DEL(sched, p->initid); 03066 p->initid = ast_sched_add(sched, p->maxtime ? (p->maxtime * 4) : SIP_TRANS_TIMEOUT, auto_congest, p); 03067 } 03068 } else { 03069 ast->hangupcause = AST_CAUSE_USER_BUSY; 03070 } 03071 return res; 03072 }
| static int sip_cancel_destroy | ( | struct sip_pvt * | p | ) | [static] |
Cancel destruction of SIP dialog.
Definition at line 2150 of file chan_sip.c.
References append_history, ast_sched_del(), and sip_pvt::autokillid.
Referenced by cb_extensionstate(), check_user_full(), handle_request_invite(), handle_request_subscribe(), handle_response(), handle_response_invite(), register_verify(), and sip_hangup().
02151 { 02152 int res = 0; 02153 if (p->autokillid > -1) { 02154 if (!(res = ast_sched_del(sched, p->autokillid))) { 02155 append_history(p, "CancelDestroy", ""); 02156 p->autokillid = -1; 02157 } 02158 } 02159 return res; 02160 }
| static int sip_debug_test_addr | ( | const struct sockaddr_in * | addr | ) | [inline, static] |
See if we pass debug IP filter.
Definition at line 1750 of file chan_sip.c.
References debugaddr, and sipdebug.
Referenced by check_user_full(), sip_debug_test_pvt(), and sipsock_read().
01751 { 01752 if (!sipdebug) 01753 return 0; 01754 if (debugaddr.sin_addr.s_addr) { 01755 if (((ntohs(debugaddr.sin_port) != 0) 01756 && (debugaddr.sin_port != addr->sin_port)) 01757 || (debugaddr.sin_addr.s_addr != addr->sin_addr.s_addr)) 01758 return 0; 01759 } 01760 return 1; 01761 }
| static int sip_debug_test_pvt | ( | struct sip_pvt * | p | ) | [inline, static] |
Test PVT for debugging output.
Definition at line 1776 of file chan_sip.c.
References sip_debug_test_addr(), sip_real_dst(), and sipdebug.
Referenced by __sip_destroy(), add_sdp(), add_t38_sdp(), build_route(), check_via(), do_register_auth(), get_also_info(), get_destination(), get_rdnis(), get_refer_info(), handle_request(), process_sdp(), receive_message(), retrans_pkt(), send_request(), send_response(), set_destination(), sip_scheddestroy(), sip_sendtext(), and transmit_register().
01777 { 01778 if (!sipdebug) 01779 return 0; 01780 return sip_debug_test_addr(sip_real_dst(p)); 01781 }
| static void sip_destroy | ( | struct sip_pvt * | p | ) | [static] |
Destroy SIP call structure.
Definition at line 3347 of file chan_sip.c.
References __sip_destroy(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), sip_pvt::callid, iflock, LOG_DEBUG, and option_debug.
Referenced by __sip_autodestruct(), handle_request_subscribe(), reload_config(), sip_destroy_peer(), sip_notify(), sip_poke_noanswer(), sip_poke_peer(), sip_registry_destroy(), sip_request_call(), sip_send_mwi_to_peer(), and transmit_register().
03348 { 03349 ast_mutex_lock(&iflock); 03350 if (option_debug > 2) 03351 ast_log(LOG_DEBUG, "Destroying SIP dialog %s\n", p->callid); 03352 __sip_destroy(p, 1); 03353 ast_mutex_unlock(&iflock); 03354 }
| static void sip_destroy_peer | ( | struct sip_peer * | peer | ) | [static] |
Destroy peer object from memory.
Definition at line 2483 of file chan_sip.c.
References ast_free_ha(), ast_log(), ast_test_flag, ast_variables_destroy(), sip_peer::auth, sip_peer::call, sip_peer::chanvars, clear_realm_authentication(), FALSE, sip_peer::flags, free, sip_peer::ha, LOG_DEBUG, sip_peer::mwipvt, sip_peer::name, option_debug, register_peer_exten(), sip_destroy(), SIP_PAGE2_SELFDESTRUCT, and SIP_REALTIME.
Referenced by __sip_autodestruct(), __sip_destroy(), _sip_show_peer(), build_peer(), check_user_full(), create_addr(), do_monitor(), expire_register(), function_sippeer(), handle_request_subscribe(), handle_response_peerpoke(), parse_register_contact(), realtime_peer(), reg_source_db(), register_verify(), reload_config(), sip_devicestate(), sip_do_debug_peer(), sip_do_reload(), sip_poke_all_peers(), sip_poke_noanswer(), sip_poke_peer(), sip_poke_peer_s(), sip_prune_realtime(), unload_module(), and update_call_counter().
02484 { 02485 if (option_debug > 2) 02486 ast_log(LOG_DEBUG, "Destroying SIP peer %s\n", peer->name); 02487 02488 /* Delete it, it needs to disappear */ 02489 if (peer->call) 02490 sip_destroy(peer->call); 02491 02492 if (peer->mwipvt) /* We have an active subscription, delete it */ 02493 sip_destroy(peer->mwipvt); 02494 02495 if (peer->chanvars) { 02496 ast_variables_destroy(peer->chanvars); 02497 peer->chanvars = NULL; 02498 } 02499 02500 register_peer_exten(peer, FALSE); 02501 ast_free_ha(peer->ha); 02502 if (ast_test_flag(&peer->flags[1], SIP_PAGE2_SELFDESTRUCT)) 02503 apeerobjs--; 02504 else if (ast_test_flag(&peer->flags[0], SIP_REALTIME)) 02505 rpeerobjs--; 02506 else 02507 speerobjs--; 02508 clear_realm_authentication(peer->auth); 02509 peer->auth = NULL; 02510 free(peer); 02511 }
| static void sip_destroy_user | ( | struct sip_user * | user | ) | [static] |
Remove user object from in-memory storage.
Definition at line 2701 of file chan_sip.c.
References ast_free_ha(), ast_log(), ast_test_flag, ast_variables_destroy(), sip_user::chanvars, sip_user::flags, free, sip_user::ha, LOG_DEBUG, sip_user::name, option_debug, and SIP_REALTIME.
Referenced by check_user_full(), reload_config(), sip_prune_realtime(), sip_show_user(), unload_module(), and update_call_counter().
02702 { 02703 if (option_debug > 2) 02704 ast_log(LOG_DEBUG, "Destroying user object from memory: %s\n", user->name); 02705 ast_free_ha(user->ha); 02706 if (user->chanvars) { 02707 ast_variables_destroy(user->chanvars); 02708 user->chanvars = NULL; 02709 } 02710 if (ast_test_flag(&user->flags[0], SIP_REALTIME)) 02711 ruserobjs--; 02712 else 02713 suserobjs--; 02714 free(user); 02715 }
| static int sip_devicestate | ( | void * | data | ) | [static] |
Part of PBX channel interface.
For peers with call limit:
For peers without call limit:
Peers that does not have a known call and can't be reached by OPTIONS
If we return AST_DEVICE_UNKNOWN, the device state engine will try to find out a state by walking the channel list.
The queue system (app_queue.c) treats a member as "active" if devicestate is != AST_DEVICE_UNAVAILBALE && != AST_DEVICE_INVALID
When placing a call to the queue member, queue system sets a member to busy if != AST_DEVICE_NOT_INUSE and != AST_DEVICE_UNKNOWN
Definition at line 16450 of file chan_sip.c.
References sip_peer::addr, AST_DEVICE_BUSY, AST_DEVICE_INUSE, AST_DEVICE_INVALID, AST_DEVICE_NOT_INUSE, AST_DEVICE_ONHOLD, AST_DEVICE_RINGING, AST_DEVICE_RINGINUSE, AST_DEVICE_UNAVAILABLE, AST_DEVICE_UNKNOWN, ast_gethostbyname(), ast_log(), ast_strdupa, ASTOBJ_UNREF, sip_peer::call_limit, sip_peer::defaddr, find_peer(), hp, sip_peer::inRinging, sip_peer::inUse, sip_peer::lastms, LOG_DEBUG, sip_peer::maxms, sip_peer::onHold, option_debug, and sip_destroy_peer().
16451 { 16452 char *host; 16453 char *tmp; 16454 16455 struct hostent *hp; 16456 struct ast_hostent ahp; 16457 struct sip_peer *p; 16458 16459 int res = AST_DEVICE_INVALID; 16460 16461 /* make sure data is not null. Maybe unnecessary, but better be safe */ 16462 host = ast_strdupa(data ? data : ""); 16463 if ((tmp = strchr(host, '@'))) 16464 host = tmp + 1; 16465 16466 if (option_debug > 2) 16467 ast_log(LOG_DEBUG, "Checking device state for peer %s\n", host); 16468 16469 /* If find_peer asks for a realtime peer, then this breaks rtautoclear. This 16470 * is because when a peer tries to autoexpire, the last thing it does is to 16471 * queue up an event telling the system that the devicestate has changed 16472 * (presumably to unavailable). If we ask for a realtime peer here, this would 16473 * load it BACK into memory, thus defeating the point of trying to trying to 16474 * clear dead hosts out of memory. 16475 */ 16476 if ((p = find_peer(host, NULL, 0, 1))) { 16477 if (p->addr.sin_addr.s_addr || p->defaddr.sin_addr.s_addr) { 16478 /* we have an address for the peer */ 16479 16480 /* Check status in this order 16481 - Hold 16482 - Ringing 16483 - Busy (enforced only by call limit) 16484 - Inuse (we have a call) 16485 - Unreachable (qualify) 16486 If we don't find any of these state, report AST_DEVICE_NOT_INUSE 16487 for registered devices */ 16488 16489 if (p->onHold) 16490 /* First check for hold or ring states */ 16491 res = AST_DEVICE_ONHOLD; 16492 else if (p->inRinging) { 16493 if (p->inRinging == p->inUse) 16494 res = AST_DEVICE_RINGING; 16495 else 16496 res = AST_DEVICE_RINGINUSE; 16497 } else if (p->call_limit && (p->inUse == p->call_limit)) 16498 /* check call limit */ 16499 res = AST_DEVICE_BUSY; 16500 else if (p->call_limit && p->inUse) 16501 /* Not busy, but we do have a call */ 16502 res = AST_DEVICE_INUSE; 16503 else if (p->maxms && ((p->lastms > p->maxms) || (p->lastms < 0))) 16504 /* We don't have a call. Are we reachable at all? Requires qualify= */ 16505 res = AST_DEVICE_UNAVAILABLE; 16506 else /* Default reply if we're registered and have no other data */ 16507 res = AST_DEVICE_NOT_INUSE; 16508 } else { 16509 /* there is no address, it's unavailable */ 16510 res = AST_DEVICE_UNAVAILABLE; 16511 } 16512 ASTOBJ_UNREF(p,sip_destroy_peer); 16513 } else { 16514 char *port = strchr(host, ':'); 16515 if (port) 16516 *port = '\0'; 16517 hp = ast_gethostbyname(host, &ahp); 16518 if (hp) 16519 res = AST_DEVICE_UNKNOWN; 16520 } 16521 16522 return res; 16523 }
| static int sip_do_debug | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Turn on SIP debugging (CLI command).
Definition at line 11469 of file chan_sip.c.
References ast_cli(), ast_set_flag, debugaddr, RESULT_SHOWUSAGE, RESULT_SUCCESS, sip_do_debug_ip(), sip_do_debug_peer(), SIP_PAGE2_DEBUG_CONSOLE, and sipdebug_console.
11470 { 11471 int oldsipdebug = sipdebug_console; 11472 if (argc != 3) { 11473 if (argc != 5) 11474 return RESULT_SHOWUSAGE; 11475 else if (strcmp(argv[3], "ip") == 0) 11476 return sip_do_debug_ip(fd, argc, argv); 11477 else if (strcmp(argv[3], "peer") == 0) 11478 return sip_do_debug_peer(fd, argc, argv); 11479 else 11480 return RESULT_SHOWUSAGE; 11481 } 11482 ast_set_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONSOLE); 11483 memset(&debugaddr, 0, sizeof(debugaddr)); 11484 ast_cli(fd, "SIP Debugging %senabled\n", oldsipdebug ? "re-" : ""); 11485 return RESULT_SUCCESS; 11486 }
| static int sip_do_debug_deprecated | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 11488 of file chan_sip.c.
References ast_cli(), ast_set_flag, debugaddr, RESULT_SHOWUSAGE, RESULT_SUCCESS, sip_do_debug_ip(), sip_do_debug_peer(), SIP_PAGE2_DEBUG_CONSOLE, and sipdebug_console.
11489 { 11490 int oldsipdebug = sipdebug_console; 11491 char *newargv[6] = { "sip", "set", "debug", NULL }; 11492 if (argc != 2) { 11493 if (argc != 4) 11494 return RESULT_SHOWUSAGE; 11495 else if (strcmp(argv[2], "ip") == 0) { 11496 newargv[3] = argv[2]; 11497 newargv[4] = argv[3]; 11498 return sip_do_debug_ip(fd, argc + 1, newargv); 11499 } else if (strcmp(argv[2], "peer") == 0) { 11500 newargv[3] = argv[2]; 11501 newargv[4] = argv[3]; 11502 return sip_do_debug_peer(fd, argc + 1, newargv); 11503 } else 11504 return RESULT_SHOWUSAGE; 11505 } 11506 ast_set_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONSOLE); 11507 memset(&debugaddr, 0, sizeof(debugaddr)); 11508 ast_cli(fd, "SIP Debugging %senabled\n", oldsipdebug ? "re-" : ""); 11509 return RESULT_SUCCESS; 11510 }
| static int sip_do_debug_ip | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Enable SIP Debugging in CLI.
Definition at line 11415 of file chan_sip.c.
References ast_cli(), ast_gethostbyname(), ast_inet_ntoa(), ast_set_flag, debugaddr, hp, RESULT_SHOWUSAGE, RESULT_SUCCESS, and SIP_PAGE2_DEBUG_CONSOLE.
Referenced by sip_do_debug(), and sip_do_debug_deprecated().
11416 { 11417 struct hostent *hp; 11418 struct ast_hostent ahp; 11419 int port = 0; 11420 char *p, *arg; 11421 11422 /* sip set debug ip <ip> */ 11423 if (argc != 5) 11424 return RESULT_SHOWUSAGE; 11425 p = arg = argv[4]; 11426 strsep(&p, ":"); 11427 if (p) 11428 port = atoi(p); 11429 hp = ast_gethostbyname(arg, &ahp); 11430 if (hp == NULL) 11431 return RESULT_SHOWUSAGE; 11432 11433 debugaddr.sin_family = AF_INET; 11434 memcpy(&debugaddr.sin_addr, hp->h_addr, sizeof(debugaddr.sin_addr)); 11435 debugaddr.sin_port = htons(port); 11436 if (port == 0) 11437 ast_cli(fd, "SIP Debugging Enabled for IP: %s\n", ast_inet_ntoa(debugaddr.sin_addr)); 11438 else 11439 ast_cli(fd, "SIP Debugging Enabled for IP: %s:%d\n", ast_inet_ntoa(debugaddr.sin_addr), port); 11440 11441 ast_set_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONSOLE); 11442 11443 return RESULT_SUCCESS; 11444 }
| static int sip_do_debug_peer | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
sip_do_debug_peer: Turn on SIP debugging with peer mask
Definition at line 11447 of file chan_sip.c.
References sip_peer::addr, ast_cli(), ast_inet_ntoa(), ast_set_flag, ASTOBJ_UNREF, debugaddr, find_peer(), RESULT_SHOWUSAGE, RESULT_SUCCESS, sip_destroy_peer(), and SIP_PAGE2_DEBUG_CONSOLE.
Referenced by sip_do_debug(), and sip_do_debug_deprecated().
11448 { 11449 struct sip_peer *peer; 11450 if (argc != 5) 11451 return RESULT_SHOWUSAGE; 11452 peer = find_peer(argv[4], NULL, 1, 0); 11453 if (peer) { 11454 if (peer->addr.sin_addr.s_addr) { 11455 debugaddr.sin_family = AF_INET; 11456 debugaddr.sin_addr = peer->addr.sin_addr; 11457 debugaddr.sin_port = peer->addr.sin_port; 11458 ast_cli(fd, "SIP Debugging Enabled for IP: %s:%d\n", ast_inet_ntoa(debugaddr.sin_addr), ntohs(debugaddr.sin_port)); 11459 ast_set_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONSOLE); 11460 } else 11461 ast_cli(fd, "Unable to get IP address of peer '%s'\n", argv[4]); 11462 ASTOBJ_UNREF(peer,sip_destroy_peer); 11463 } else 11464 ast_cli(fd, "No such peer '%s'\n", argv[4]); 11465 return RESULT_SUCCESS; 11466 }
| static int sip_do_history | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Enable SIP History logging (CLI).
Definition at line 11588 of file chan_sip.c.
References ast_cli(), RESULT_SHOWUSAGE, RESULT_SUCCESS, and TRUE.
11589 { 11590 if (argc != 2) { 11591 return RESULT_SHOWUSAGE; 11592 } 11593 recordhistory = TRUE; 11594 ast_cli(fd, "SIP History Recording Enabled (use 'sip show history')\n"); 11595 return RESULT_SUCCESS; 11596 }
| static int sip_do_reload | ( | enum channelreloadreason | reason | ) | [static] |
Reload module.
Definition at line 18483 of file chan_sip.c.
References ast_log(), ASTOBJ_CONTAINER_PRUNE_MARKED, LOG_DEBUG, option_debug, peerl, reload_config(), sip_destroy_peer(), sip_poke_all_peers(), and sip_send_all_registers().
Referenced by do_monitor().
18484 { 18485 reload_config(reason); 18486 18487 /* Prune peers who still are supposed to be deleted */ 18488 ASTOBJ_CONTAINER_PRUNE_MARKED(&peerl, sip_destroy_peer); 18489 if (option_debug > 3) 18490 ast_log(LOG_DEBUG, "--------------- Done destroying pruned peers\n"); 18491 18492 /* Send qualify (OPTIONS) to all peers */ 18493 sip_poke_all_peers(); 18494 18495 /* Register with all services */ 18496 sip_send_all_registers(); 18497 18498 if (option_debug > 3) 18499 ast_log(LOG_DEBUG, "--------------- SIP reload done\n"); 18500 18501 return 0; 18502 }
| static int sip_dtmfmode | ( | struct ast_channel * | chan, | |
| void * | data | |||
| ) | [static] |
Set the DTMFmode for an outbound SIP call (application).
Definition at line 18281 of file chan_sip.c.
References ast_channel_lock, ast_channel_unlock, ast_clear_flag, ast_dsp_free(), ast_dsp_new(), ast_dsp_set_features(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), AST_RTP_DTMF, ast_rtp_setdtmf(), ast_set_flag, ast_test_flag, DSP_FEATURE_DTMF_DETECT, sip_pvt::flags, sip_pvt::jointnoncodeccapability, sip_pvt::lock, LOG_WARNING, domain::mode, sip_pvt::rtp, SIP_DTMF, SIP_DTMF_INBAND, SIP_DTMF_INFO, SIP_DTMF_RFC2833, ast_channel::tech, ast_channel::tech_pvt, and sip_pvt::vad.
Referenced by load_module().
18282 { 18283 struct sip_pvt *p; 18284 char *mode; 18285 if (data) 18286 mode = (char *)data; 18287 else { 18288 ast_log(LOG_WARNING, "This application requires the argument: info, inband, rfc2833\n"); 18289 return 0; 18290 } 18291 ast_channel_lock(chan); 18292 if (chan->tech != &sip_tech && chan->tech != &sip_tech_info) { 18293 ast_log(LOG_WARNING, "Call this application only on SIP incoming calls\n"); 18294 ast_channel_unlock(chan); 18295 return 0; 18296 } 18297 p = chan->tech_pvt; 18298 if (!p) { 18299 ast_channel_unlock(chan); 18300 return 0; 18301 } 18302 ast_mutex_lock(&p->lock); 18303 if (!strcasecmp(mode,"info")) { 18304 ast_clear_flag(&p->flags[0], SIP_DTMF); 18305 ast_set_flag(&p->flags[0], SIP_DTMF_INFO); 18306 p->jointnoncodeccapability &= ~AST_RTP_DTMF; 18307 } else if (!strcasecmp(mode,"rfc2833")) { 18308 ast_clear_flag(&p->flags[0], SIP_DTMF); 18309 ast_set_flag(&p->flags[0], SIP_DTMF_RFC2833); 18310 p->jointnoncodeccapability |= AST_RTP_DTMF; 18311 } else if (!strcasecmp(mode,"inband")) { 18312 ast_clear_flag(&p->flags[0], SIP_DTMF); 18313 ast_set_flag(&p->flags[0], SIP_DTMF_INBAND); 18314 p->jointnoncodeccapability &= ~AST_RTP_DTMF; 18315 } else 18316 ast_log(LOG_WARNING, "I don't know about this dtmf mode: %s\n",mode); 18317 if (p->rtp) 18318 ast_rtp_setdtmf(p->rtp, ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833); 18319 if (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_INBAND) { 18320 if (!p->vad) { 18321 p->vad = ast_dsp_new(); 18322 ast_dsp_set_features(p->vad, DSP_FEATURE_DTMF_DETECT); 18323 } 18324 } else { 18325 if (p->vad) { 18326 ast_dsp_free(p->vad); 18327 p->vad = NULL; 18328 } 18329 } 18330 ast_mutex_unlock(&p->lock); 18331 ast_channel_unlock(chan); 18332 return 0; 18333 }
| 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 11280 of file chan_sip.c.
References AST_LIST_TRAVERSE, ast_log(), sip_pvt::callid, sip_history::event, sip_pvt::history, LOG_DEBUG, LOG_NOTICE, option_debug, sipdebug, and sip_pvt::subscribed.
Referenced by __sip_destroy().
11281 { 11282 int x = 0; 11283 struct sip_history *hist; 11284 static int errmsg = 0; 11285 11286 if (!dialog) 11287 return; 11288 11289 if (!option_debug && !sipdebug) { 11290 if (!errmsg) { 11291 ast_log(LOG_NOTICE, "You must have debugging enabled (SIP or Asterisk) in order to dump SIP history.\n"); 11292 errmsg = 1; 11293 } 11294 return; 11295 } 11296 11297 ast_log(LOG_DEBUG, "\n---------- SIP HISTORY for '%s' \n", dialog->callid); 11298 if (dialog->subscribed) 11299 ast_log(LOG_DEBUG, " * Subscription\n"); 11300 else 11301 ast_log(LOG_DEBUG, " * SIP Call\n"); 11302 if (dialog->history) 11303 AST_LIST_TRAVERSE(dialog->history, hist, list) 11304 ast_log(LOG_DEBUG, " %-3.3d. %s\n", ++x, hist->event); 11305 if (!x) 11306 ast_log(LOG_DEBUG, "Call '%s' has no history\n", dialog->callid); 11307 ast_log(LOG_DEBUG, "\n---------- END SIP HISTORY for '%s' \n", dialog->callid); 11308 }
| 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 3815 of file chan_sip.c.
References append_history, AST_FLAG_ZOMBIE, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_test_flag, sip_pvt::callid, sip_pvt::lock, LOG_DEBUG, LOG_WARNING, ast_channel::name, option_debug, sip_pvt::owner, sip_set_rtp_peer(), and ast_channel::tech_pvt.
03816 { 03817 int ret = -1; 03818 struct sip_pvt *p; 03819 03820 if (newchan && ast_test_flag(newchan, AST_FLAG_ZOMBIE) && option_debug) 03821 ast_log(LOG_DEBUG, "New channel is zombie\n"); 03822 if (oldchan && ast_test_flag(oldchan, AST_FLAG_ZOMBIE) && option_debug) 03823 ast_log(LOG_DEBUG, "Old channel is zombie\n"); 03824 03825 if (!newchan || !newchan->tech_pvt) { 03826 if (!newchan) 03827 ast_log(LOG_WARNING, "No new channel! Fixup of %s failed.\n", oldchan->name); 03828 else 03829 ast_log(LOG_WARNING, "No SIP tech_pvt! Fixup of %s failed.\n", oldchan->name); 03830 return -1; 03831 } 03832 p = newchan->tech_pvt; 03833 03834 if (!p) { 03835 ast_log(LOG_WARNING, "No pvt after masquerade. Strange things may happen\n"); 03836 return -1; 03837 } 03838 03839 ast_mutex_lock(&p->lock); 03840 append_history(p, "Masq", "Old channel: %s\n", oldchan->name); 03841 append_history(p, "Masq (cont)", "...new owner: %s\n", newchan->name); 03842 if (p->owner != oldchan) 03843 ast_log(LOG_WARNING, "old channel wasn't %p but was %p\n", oldchan, p->owner); 03844 else { 03845 p->owner = newchan; 03846 /* Re-invite RTP back to Asterisk. Needed if channel is masqueraded out of a native 03847 RTP bridge (i.e., RTP not going through Asterisk): RTP bridge code might not be 03848 able to do this if the masquerade happens before the bridge breaks (e.g., AMI 03849 redirect of both channels). Note that a channel can not be masqueraded *into* 03850 a native bridge. So there is no danger that this breaks a native bridge that 03851 should stay up. */ 03852 sip_set_rtp_peer(newchan, NULL, NULL, 0, 0); 03853 ret = 0; 03854 } 03855 if (option_debug > 2) 03856 ast_log(LOG_DEBUG, "SIP Fixup: New owner for dialogue %s: %s (Old parent: %s)\n", p->callid, p->owner->name, oldchan->name); 03857 03858 ast_mutex_unlock(&p->lock); 03859 return ret; 03860 }
| static int sip_get_codec | ( | struct ast_channel * | chan | ) | [static] |
Return SIP UA's codec (part of the RTP interface).
Definition at line 18427 of file chan_sip.c.
References sip_pvt::capability, sip_pvt::jointcapability, and ast_channel::tech_pvt.
18428 { 18429 struct sip_pvt *p = chan->tech_pvt; 18430 return p->jointcapability ? p->jointcapability : p->capability; 18431 }
| static enum ast_rtp_get_result sip_get_rtp_peer | ( | struct ast_channel * | chan, | |
| struct ast_rtp ** | rtp | |||
| ) | [static] |
Returns null if we can't reinvite audio (part of RTP interface).
Definition at line 18134 of file chan_sip.c.
References AST_JB_FORCED, ast_mutex_lock(), ast_mutex_unlock(), AST_RTP_GET_FAILED, ast_rtp_getnat(), AST_RTP_TRY_NATIVE, AST_RTP_TRY_PARTIAL, ast_test_flag, sip_pvt::flags, global_jbconf, sip_pvt::lock, sip_pvt::rtp, SIP_CAN_REINVITE, SIP_CAN_REINVITE_NAT, and ast_channel::tech_pvt.
18135 { 18136 struct sip_pvt *p = NULL; 18137 enum ast_rtp_get_result res = AST_RTP_TRY_PARTIAL; 18138 18139 if (!(p = chan->tech_pvt)) 18140 return AST_RTP_GET_FAILED; 18141 18142 ast_mutex_lock(&p->lock); 18143 if (!(p->rtp)) { 18144 ast_mutex_unlock(&p->lock); 18145 return AST_RTP_GET_FAILED; 18146 } 18147 18148 *rtp = p->rtp; 18149 18150 if (ast_rtp_getnat(*rtp) && !ast_test_flag(&p->flags[0], SIP_CAN_REINVITE_NAT)) 18151 res = AST_RTP_TRY_PARTIAL; 18152 else if (ast_test_flag(&p->flags[0], SIP_CAN_REINVITE)) 18153 res = AST_RTP_TRY_NATIVE; 18154 else if (ast_test_flag(&global_jbconf, AST_JB_FORCED)) 18155 res = AST_RTP_GET_FAILED; 18156 18157 ast_mutex_unlock(&p->lock); 18158 18159 return res; 18160 }
| static struct ast_udptl * sip_get_udptl_peer | ( | struct ast_channel * | chan | ) | [static, read] |
Definition at line 17999 of file chan_sip.c.
References ast_mutex_lock(), ast_mutex_unlock(), ast_test_flag, sip_pvt::flags, sip_pvt::lock, SIP_CAN_REINVITE, ast_channel::tech_pvt, and sip_pvt::udptl.
18000 { 18001 struct sip_pvt *p; 18002 struct ast_udptl *udptl = NULL; 18003 18004 p = chan->tech_pvt; 18005 if (!p) 18006 return NULL; 18007 18008 ast_mutex_lock(&p->lock); 18009 if (p->udptl && ast_test_flag(&p->flags[0], SIP_CAN_REINVITE)) 18010 udptl = p->udptl; 18011 ast_mutex_unlock(&p->lock); 18012 return udptl; 18013 }
| static enum ast_rtp_get_result sip_get_vrtp_peer | ( | struct ast_channel * | chan, | |
| struct ast_rtp ** | rtp | |||
| ) | [static] |
Returns null if we can't reinvite video (part of RTP interface).
Definition at line 18163 of file chan_sip.c.
References ast_mutex_lock(), ast_mutex_unlock(), AST_RTP_GET_FAILED, AST_RTP_TRY_NATIVE, AST_RTP_TRY_PARTIAL, ast_test_flag, sip_pvt::flags, sip_pvt::lock, SIP_CAN_REINVITE, ast_channel::tech_pvt, and sip_pvt::vrtp.
18164 { 18165 struct sip_pvt *p = NULL; 18166 enum ast_rtp_get_result res = AST_RTP_TRY_PARTIAL; 18167 18168 if (!(p = chan->tech_pvt)) 18169 return AST_RTP_GET_FAILED; 18170 18171 ast_mutex_lock(&p->lock); 18172 if (!(p->vrtp)) { 18173 ast_mutex_unlock(&p->lock); 18174 return AST_RTP_GET_FAILED; 18175 } 18176 18177 *rtp = p->vrtp; 18178 18179 if (ast_test_flag(&p->flags[0], SIP_CAN_REINVITE)) 18180 res = AST_RTP_TRY_NATIVE; 18181 18182 ast_mutex_unlock(&p->lock); 18183 18184 return res; 18185 }
| static int sip_handle_t38_reinvite | ( | struct ast_channel * | chan, | |
| struct sip_pvt * | pvt, | |||
| int | reinvite | |||
| ) | [static] |
Handle T38 reinvite.
T38 negotiation helper function
Definition at line 18051 of file chan_sip.c.
References ast_inet_ntoa(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_set_flag, ast_test_flag, ast_udptl_get_error_correction_scheme(), ast_udptl_get_local_max_datagram(), ast_udptl_get_peer(), ast_udptl_set_error_correction_scheme(), ast_udptl_set_far_max_datagram(), ast_udptl_set_local_max_datagram(), sip_pvt::callid, sip_pvt::flags, sip_pvt::initreq, t38properties::jointcapability, sip_pvt::lastrtprx, sip_pvt::lastrtptx, sip_pvt::lock, LOG_DEBUG, ast_channel::name, option_debug, sip_pvt::ourip, sip_pvt::owner, t38properties::peercapability, sip_pvt::pendinginvite, SIP_CAN_REINVITE, SIP_GOTREFER, SIP_NEEDREINVITE, SIP_PENDINGBYE, t38properties::state, sip_pvt::t38, T38_ENABLED, ast_channel::tech_pvt, transmit_reinvite_with_t38_sdp(), transmit_response_with_t38_sdp(), sip_pvt::udptl, sip_pvt::udptlredirip, and XMIT_CRITICAL.
Referenced by handle_request_invite(), and handle_response_invite().
18052 { 18053 struct sip_pvt *p; 18054 int flag = 0; 18055 18056 p = chan->tech_pvt; 18057 if (!p || !pvt->udptl) 18058 return -1; 18059 18060 /* Setup everything on the other side like offered/responded from first side */ 18061 ast_mutex_lock(&p->lock); 18062 18063 /*! \todo check if this is not set earlier when setting up the PVT. If not 18064 maybe it should move there. */ 18065 p->t38.jointcapability = p->t38.peercapability = pvt->t38.jointcapability; 18066 18067 ast_udptl_set_far_max_datagram(p->udptl, ast_udptl_get_local_max_datagram(pvt->udptl)); 18068 ast_udptl_set_local_max_datagram(p->udptl, ast_udptl_get_local_max_datagram(pvt->udptl)); 18069 ast_udptl_set_error_correction_scheme(p->udptl, ast_udptl_get_error_correction_scheme(pvt->udptl)); 18070 18071 if (reinvite) { /* If we are handling sending re-invite to the other side of the bridge */ 18072 /*! \note The SIP_CAN_REINVITE flag is for RTP media redirects, 18073 not really T38 re-invites which are different. In this 18074 case it's used properly, to see if we can reinvite over 18075 NAT 18076 */ 18077 if (ast_test_flag(&p->flags[0], SIP_CAN_REINVITE) && ast_test_flag(&pvt->flags[0], SIP_CAN_REINVITE)) { 18078 ast_udptl_get_peer(pvt->udptl, &p->udptlredirip); 18079 flag =1; 18080 } else { 18081 memset(&p->udptlredirip, 0, sizeof(p->udptlredirip)); 18082 } 18083 if (!ast_test_flag(&p->flags[0], SIP_GOTREFER)) { 18084 if (!p->pendinginvite) { 18085 if (option_debug > 2) { 18086 if (flag) 18087 ast_log(LOG_DEBUG, "Sending reinvite on SIP '%s' - It's UDPTL soon redirected to IP %s:%d\n", p->callid, ast_inet_ntoa(p->udptlredirip.sin_addr), ntohs(p->udptlredirip.sin_port)); 18088 else 18089 ast_log(LOG_DEBUG, "Sending reinvite on SIP '%s' - It's UDPTL soon redirected to us (IP %s)\n", p->callid, ast_inet_ntoa(p->ourip)); 18090 } 18091 transmit_reinvite_with_t38_sdp(p); 18092 } else if (!ast_test_flag(&p->flags[0], SIP_PENDINGBYE)) { 18093 if (option_debug > 2) { 18094 if (flag) 18095 ast_log(LOG_DEBUG, "Deferring reinvite on SIP '%s' - It's UDPTL will be redirected to IP %s:%d\n", p->callid, ast_inet_ntoa(p->udptlredirip.sin_addr), ntohs(p->udptlredirip.sin_port)); 18096 else 18097 ast_log(LOG_DEBUG, "Deferring reinvite on SIP '%s' - It's UDPTL will be redirected to us (IP %s)\n", p->callid, ast_inet_ntoa(p->ourip)); 18098 } 18099 ast_set_flag(&p->flags[0], SIP_NEEDREINVITE); 18100 } 18101 } 18102 /* Reset lastrtprx timer */ 18103 p->lastrtprx = p->lastrtptx = time(NULL); 18104 ast_mutex_unlock(&p->lock); 18105 return 0; 18106 } else { /* If we are handling sending 200 OK to the other side of the bridge */ 18107 if (ast_test_flag(&p->flags[0], SIP_CAN_REINVITE) && ast_test_flag(&pvt->flags[0], SIP_CAN_REINVITE)) { 18108 ast_udptl_get_peer(pvt->udptl, &p->udptlredirip); 18109 flag = 1; 18110 } else { 18111 memset(&p->udptlredirip, 0, sizeof(p->udptlredirip)); 18112 } 18113 if (option_debug > 2) { 18114 if (flag) 18115 ast_log(LOG_DEBUG, "Responding 200 OK on SIP '%s' - It's UDPTL soon redirected to IP %s:%d\n", p->callid, ast_inet_ntoa(p->udptlredirip.sin_addr), ntohs(p->udptlredirip.sin_port)); 18116 else 18117 ast_log(LOG_DEBUG, "Responding 200 OK on SIP '%s' - It's UDPTL soon redirected to us (IP %s)\n", p->callid, ast_inet_ntoa(p->ourip)); 18118 } 18119 pvt->t38.state = T38_ENABLED; 18120 p->t38.state = T38_ENABLED; 18121 if (option_debug > 1) { 18122 ast_log(LOG_DEBUG, "T38 changed state to %d on channel %s\n", pvt->t38.state, pvt->owner ? pvt->owner->name : "<none>"); 18123 ast_log(LOG_DEBUG, "T38 changed state to %d on channel %s\n", p->t38.state, chan ? chan->name : "<none>"); 18124 } 18125 transmit_response_with_t38_sdp(p, "200 OK", &p->initreq, XMIT_CRITICAL); 18126 p->lastrtprx = p->lastrtptx = time(NULL); 18127 ast_mutex_unlock(&p->lock); 18128 return 0; 18129 } 18130 }
| 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 3520 of file chan_sip.c.
References __sip_pretend_ack(), ast_channel::_state, append_history, ast_cause2str(), ast_clear_flag, ast_dsp_free(), AST_FLAG_ZOMBIE, ast_log(), ast_module_unref(), ast_mutex_lock(), ast_mutex_unlock(), ast_rtp_get_quality(), AST_SCHED_DEL, ast_set_flag, ast_state2str(), AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, ast_strlen_zero(), ast_test_flag, sip_pvt::autokillid, sip_pvt::callid, sip_request::data, DEC_CALL_LIMIT, DEFAULT_TRANS_TIMEOUT, FALSE, sip_pvt::flags, hangup_cause2sip(), ast_channel::hangupcause, INC_CALL_LIMIT, sip_pvt::initid, sip_pvt::initreq, INV_CALLING, INV_CANCELLED, INV_COMPLETED, INV_TERMINATED, sip_pvt::invitestate, sip_pvt::lastinvite, sip_pvt::lock, LOG_DEBUG, LOG_WARNING, ast_channel::name, option_debug, sip_pvt::owner, pbx_builtin_setvar_helper(), sip_pvt::pendinginvite, sip_pvt::refer, sip_pvt::rtp, SIP_ALREADYGONE, SIP_BYE, SIP_CANCEL, sip_cancel_destroy(), SIP_DEFER_BYE_ON_TRANSFER, SIP_INC_COUNT, SIP_NEEDDESTROY, SIP_NEEDREINVITE, SIP_NO_HISTORY, SIP_OUTGOING, SIP_PAGE2_CALL_ONHOLD, SIP_PENDINGBYE, sip_scheddestroy(), sipdebug, stop_media_flows(), ast_channel::tech_pvt, transmit_request(), transmit_request_with_auth(), transmit_response_reliable(), TRUE, update_call_counter(), sip_pvt::username, sip_pvt::vad, sip_pvt::vrtp, sip_pvt::waitid, and XMIT_RELIABLE.
03521 { 03522 struct sip_pvt *p = ast->tech_pvt; 03523 int needcancel = FALSE; 03524 int needdestroy = 0; 03525 struct ast_channel *oldowner = ast; 03526 03527 if (!p) { 03528 if (option_debug) 03529 ast_log(LOG_DEBUG, "Asked to hangup channel that was not connected\n"); 03530 return 0; 03531 } 03532 03533 if (ast_test_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER)) { 03534 if (ast_test_flag(&p->flags[0], SIP_INC_COUNT) || ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD)) { 03535 if (option_debug && sipdebug) 03536 ast_log(LOG_DEBUG, "update_call_counter(%s) - decrement call limit counter on hangup\n", p->username); 03537 update_call_counter(p, DEC_CALL_LIMIT); 03538 } 03539 if (option_debug >3) 03540 ast_log(LOG_DEBUG, "SIP Transfer: Not hanging up right now... Rescheduling hangup for %s.\n", p->callid); 03541 if (p->autokillid > -1 && sip_cancel_destroy(p)) 03542 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 03543 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 03544 ast_clear_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER); /* Really hang up next time */ 03545 ast_clear_flag(&p->flags[0], SIP_NEEDDESTROY); 03546 p->owner->tech_pvt = NULL; 03547 p->owner = NULL; /* Owner will be gone after we return, so take it away */ 03548 return 0; 03549 } 03550 if (option_debug) { 03551 if (ast_test_flag(ast, AST_FLAG_ZOMBIE) && p->refer && option_debug) 03552 ast_log(LOG_DEBUG, "SIP Transfer: Hanging up Zombie channel %s after transfer ... Call-ID: %s\n", ast->name, p->callid); 03553 else { 03554 if (option_debug) 03555 ast_log(LOG_DEBUG, "Hangup call %s, SIP callid %s)\n", ast->name, p->callid); 03556 } 03557 } 03558 if (option_debug && ast_test_flag(ast, AST_FLAG_ZOMBIE)) 03559 ast_log(LOG_DEBUG, "Hanging up zombie call. Be scared.\n"); 03560 03561 ast_mutex_lock(&p->lock); 03562 if (ast_test_flag(&p->flags[0], SIP_INC_COUNT) || ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD)) { 03563 if (option_debug && sipdebug) 03564 ast_log(LOG_DEBUG, "update_call_counter(%s) - decrement call limit counter on hangup\n", p->username); 03565 update_call_counter(p, DEC_CALL_LIMIT); 03566 } 03567 03568 /* Determine how to disconnect */ 03569 if (p->owner != ast) { 03570 ast_log(LOG_WARNING, "Huh? We aren't the owner? Can't hangup call.\n"); 03571 ast_mutex_unlock(&p->lock); 03572 return 0; 03573 } 03574 /* If the call is not UP, we need to send CANCEL instead of BYE */ 03575 if (ast->_state == AST_STATE_RING || ast->_state == AST_STATE_RINGING || (p->invitestate < INV_COMPLETED && ast->_state != AST_STATE_UP)) { 03576 needcancel = TRUE; 03577 if (option_debug > 3) 03578 ast_log(LOG_DEBUG, "Hanging up channel in state %s (not UP)\n", ast_state2str(ast->_state)); 03579 } 03580 03581 stop_media_flows(p); /* Immediately stop RTP, VRTP and UDPTL as applicable */ 03582 03583 append_history(p, needcancel ? "Cancel" : "Hangup", "Cause %s", p->owner ? ast_cause2str(p->owner->hangupcause) : "Unknown"); 03584 03585 /* Disconnect */ 03586 if (p->vad) 03587 ast_dsp_free(p->vad); 03588 03589 p->owner = NULL; 03590 ast->tech_pvt = NULL; 03591 03592 ast_module_unref(ast_module_info->self); 03593 03594 /* Do not destroy this pvt until we have timeout or 03595 get an answer to the BYE or INVITE/CANCEL 03596 If we get no answer during retransmit period, drop the call anyway. 03597 (Sorry, mother-in-law, you can't deny a hangup by sending 03598 603 declined to BYE...) 03599 */ 03600 if (ast_test_flag(&p->flags[0], SIP_ALREADYGONE)) 03601 needdestroy = 1; /* Set destroy flag at end of this function */ 03602 else if (p->invitestate != INV_CALLING) 03603 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 03604 03605 /* Start the process if it's not already started */ 03606 if (!ast_test_flag(&p->flags[0], SIP_ALREADYGONE) && !ast_strlen_zero(p->initreq.data)) { 03607 if (needcancel) { /* Outgoing call, not up */ 03608 if (ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 03609 /* stop retransmitting an INVITE that has not received a response */ 03610 __sip_pretend_ack(p); 03611 p->invitestate = INV_CANCELLED; 03612 03613 /* if we can't send right now, mark it pending */ 03614 if (p->invitestate == INV_CALLING) { 03615 /* We can't send anything in CALLING state */ 03616 ast_set_flag(&p->flags[0], SIP_PENDINGBYE); 03617 /* 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. */ 03618 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 03619 append_history(p, "DELAY", "Not sending cancel, waiting for timeout"); 03620 } else { 03621 /* Send a new request: CANCEL */ 03622 transmit_request(p, SIP_CANCEL, p->lastinvite, XMIT_RELIABLE, FALSE); 03623 /* Actually don't destroy us yet, wait for the 487 on our original 03624 INVITE, but do set an autodestruct just in case we never get it. */ 03625 needdestroy = 0; 03626 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 03627 } 03628 if ( p->initid != -1 ) { 03629 /* channel still up - reverse dec of inUse counter 03630 only if the channel is not auto-congested */ 03631 update_call_counter(p, INC_CALL_LIMIT); 03632 } 03633 } else { /* Incoming call, not up */ 03634 const char *res; 03635 if (ast->hangupcause && (res = hangup_cause2sip(ast->hangupcause))) 03636 transmit_response_reliable(p, res, &p->initreq); 03637 else 03638 transmit_response_reliable(p, "603 Declined", &p->initreq); 03639 p->invitestate = INV_TERMINATED; 03640 } 03641 } else { /* Call is in UP state, send BYE */ 03642 if (!p->pendinginvite) { 03643 char *audioqos = ""; 03644 char *videoqos = ""; 03645 if (p->rtp) 03646 audioqos = ast_rtp_get_quality(p->rtp, NULL); 03647 if (p->vrtp) 03648 videoqos = ast_rtp_get_quality(p->vrtp, NULL); 03649 /* Send a hangup */ 03650 transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, 1); 03651 03652 /* Get RTCP quality before end of call */ 03653 if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) { 03654 if (p->rtp) 03655 append_history(p, "RTCPaudio", "Quality:%s", audioqos); 03656 if (p->vrtp) 03657 append_history(p, "RTCPvideo", "Quality:%s", videoqos); 03658 } 03659 if (p->rtp && oldowner) 03660 pbx_builtin_setvar_helper(oldowner, "RTPAUDIOQOS", audioqos); 03661 if (p->vrtp && oldowner) 03662 pbx_builtin_setvar_helper(oldowner, "RTPVIDEOQOS", videoqos); 03663 } else { 03664 /* Note we will need a BYE when this all settles out 03665 but we can't send one while we have "INVITE" outstanding. */ 03666 ast_set_flag(&p->flags[0], SIP_PENDINGBYE); 03667 ast_clear_flag(&p->flags[0], SIP_NEEDREINVITE); 03668 AST_SCHED_DEL(sched, p->waitid); 03669 if (sip_cancel_destroy(p)) 03670 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 03671 } 03672 } 03673 } 03674 if (needdestroy) 03675 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 03676 ast_mutex_unlock(&p->lock); 03677 return 0; 03678 }
| 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 3931 of file chan_sip.c.
References ast_channel::_state, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HOLD, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RINGING, AST_CONTROL_SRCUPDATE, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, ast_log(), ast_moh_start(), ast_moh_stop(), ast_mutex_lock(), ast_mutex_unlock(), ast_rtp_new_source(), ast_set_flag, AST_SOFTHANGUP_DEV, ast_softhangup_nolock(), AST_STATE_RING, AST_STATE_UP, ast_test_flag, sip_pvt::flags, sip_pvt::initreq, INV_COMPLETED, INV_EARLY_MEDIA, INV_PROCEEDING, sip_pvt::invitestate, sip_pvt::lock, LOG_WARNING, sip_pvt::mohinterpret, sip_pvt::rtp, sip_alreadygone(), SIP_NOVIDEO, SIP_OUTGOING, SIP_PROG_INBAND, SIP_PROG_INBAND_NEVER, SIP_PROG_INBAND_YES, SIP_PROGRESS_SENT, SIP_RINGING, ast_channel::tech_pvt, transmit_info_with_vidupdate(), transmit_response(), transmit_response_reliable(), transmit_response_with_sdp(), sip_pvt::vrtp, and XMIT_UNRELIABLE.
03932 { 03933 struct sip_pvt *p = ast->tech_pvt; 03934 int res = 0; 03935 03936 ast_mutex_lock(&p->lock); 03937 switch(condition) { 03938 case AST_CONTROL_RINGING: 03939 if (ast->_state == AST_STATE_RING) { 03940 p->invitestate = INV_EARLY_MEDIA; 03941 if (!ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT) || 03942 (ast_test_flag(&p->flags[0], SIP_PROG_INBAND) == SIP_PROG_INBAND_NEVER)) { 03943 /* Send 180 ringing if out-of-band seems reasonable */ 03944 transmit_response(p, "180 Ringing", &p->initreq); 03945 ast_set_flag(&p->flags[0], SIP_RINGING); 03946 if (ast_test_flag(&p->flags[0], SIP_PROG_INBAND) != SIP_PROG_INBAND_YES) 03947 break; 03948 } else { 03949 /* Well, if it's not reasonable, just send in-band */ 03950 } 03951 } 03952 res = -1; 03953 break; 03954 case AST_CONTROL_BUSY: 03955 if (ast->_state != AST_STATE_UP) { 03956 transmit_response_reliable(p, "486 Busy Here", &p->initreq); 03957 p->invitestate = INV_COMPLETED; 03958 sip_alreadygone(p); 03959 ast_softhangup_nolock(ast, AST_SOFTHANGUP_DEV); 03960 break; 03961 } 03962 res = -1; 03963 break; 03964 case AST_CONTROL_CONGESTION: 03965 if (ast->_state != AST_STATE_UP) { 03966 transmit_response_reliable(p, "503 Service Unavailable", &p->initreq); 03967 p->invitestate = INV_COMPLETED; 03968 sip_alreadygone(p); 03969 ast_softhangup_nolock(ast, AST_SOFTHANGUP_DEV); 03970 break; 03971 } 03972 res = -1; 03973 break; 03974 case AST_CONTROL_PROCEEDING: 03975 if ((ast->_state != AST_STATE_UP) && 03976 !ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT) && 03977 !ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 03978 transmit_response(p, "100 Trying", &p->initreq); 03979 p->invitestate = INV_PROCEEDING; 03980 break; 03981 } 03982 res = -1; 03983 break; 03984 case AST_CONTROL_PROGRESS: 03985 if ((ast->_state != AST_STATE_UP) && 03986 !ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT) && 03987 !ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 03988 p->invitestate = INV_EARLY_MEDIA; 03989 transmit_response_with_sdp(p, "183 Session Progress", &p->initreq, XMIT_UNRELIABLE); 03990 ast_set_flag(&p->flags[0], SIP_PROGRESS_SENT); 03991 break; 03992 } 03993 res = -1; 03994 break; 03995 case AST_CONTROL_HOLD: 03996 ast_rtp_new_source(p->rtp); 03997 ast_moh_start(ast, data, p->mohinterpret); 03998 break; 03999 case AST_CONTROL_UNHOLD: 04000 ast_rtp_new_source(p->rtp); 04001 ast_moh_stop(ast); 04002 break; 04003 case AST_CONTROL_VIDUPDATE: /* Request a video frame update */ 04004 if (p->vrtp && !ast_test_flag(&p->flags[0], SIP_NOVIDEO)) { 04005 transmit_info_with_vidupdate(p); 04006 /* ast_rtcp_send_h261fur(p->vrtp); */ 04007 } else 04008 res = -1; 04009 break; 04010 case AST_CONTROL_SRCUPDATE: 04011 ast_rtp_new_source(p->rtp); 04012 break; 04013 case -1: 04014 res = -1; 04015 break; 04016 default: 04017 ast_log(LOG_WARNING, "Don't know how to indicate condition %d\n", condition); 04018 res = -1; 04019 break; 04020 } 04021 ast_mutex_unlock(&p->lock); 04022 return res; 04023 }
| static const char * sip_nat_mode | ( | const struct sip_pvt * | p | ) | [static] |
Display SIP nat mode.
Definition at line 1770 of file chan_sip.c.
References ast_test_flag, sip_pvt::flags, SIP_NAT, and SIP_NAT_ROUTE.
Referenced by check_via(), retrans_pkt(), and send_response().
01771 { 01772 return ast_test_flag(&p->flags[0], SIP_NAT) & SIP_NAT_ROUTE ? "NAT" : "no NAT"; 01773 }
| static struct ast_channel* sip_new | ( | struct sip_pvt * | i, | |
| int | state, | |||
| const char * | title | |||
| ) | [static, read] |
Initiate a call in the SIP channel called from sip_request_call (calls from the pbx ) for outbound channels and from handle_request_invite for inbound channels.
Definition at line 4031 of file chan_sip.c.
References accountcode, sip_pvt::accountcode, ast_channel::adsicpe, ast_channel::amaflags, sip_pvt::amaflags, append_history, AST_ADSI_UNAVAILABLE, ast_best_codec(), AST_CAUSE_SWITCH_CONGESTION, ast_channel_alloc(), ast_codec_choose(), ast_copy_string(), ast_dsp_digitmode(), ast_dsp_new(), ast_dsp_set_features(), AST_FORMAT_VIDEO_MASK, ast_getformatname_multiple(), ast_hangup(), ast_jb_configure(), ast_log(), ast_module_ref(), ast_mutex_lock(), ast_mutex_unlock(), ast_pbx_start(), ast_rtcp_fd(), ast_rtp_fd(), AST_STATE_DOWN, AST_STATE_RING, ast_strdup, ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_udptl_fd(), ast_uri_decode(), sip_pvt::callgroup, ast_channel::callgroup, sip_pvt::callid, sip_pvt::callingpres, sip_pvt::capability, sip_pvt::chanvars, ast_channel::cid, ast_callerid::cid_ani, ast_callerid::cid_dnid, sip_pvt::cid_name, sip_pvt::cid_num, ast_callerid::cid_pres, ast_callerid::cid_rdnis, ast_channel::context, sip_pvt::context, sip_pvt::domain, DSP_DIGITMODE_DTMF, DSP_DIGITMODE_RELAXDTMF, DSP_FEATURE_DTMF_DETECT, ast_channel::exten, sip_pvt::exten, ast_channel::fds, sip_pvt::flags, sip_pvt::fromdomain, global_jbconf, ast_channel::hangupcause, sip_pvt::jointcapability, language, sip_pvt::language, sip_pvt::lock, LOG_DEBUG, LOG_WARNING, ast_channel::name, ast_variable::name, ast_channel::nativeformats, ast_variable::next, option_debug, sip_pvt::owner, pbx_builtin_setvar_helper(), sip_pvt::pickupgroup, ast_channel::pickupgroup, sip_pvt::prefcodec, sip_pvt::prefs, ast_channel::priority, ast_channel::rawreadformat, ast_channel::rawwriteformat, sip_pvt::rdnis, ast_channel::readformat, ast_channel::rings, sip_pvt::rtp, SIP_DTMF, SIP_DTMF_INBAND, SIP_DTMF_INFO, SIP_NO_HISTORY, SIPBUFSIZE, t38properties::state, sip_pvt::t38, T38_PEER_DIRECT, ast_channel::tech, ast_channel::tech_pvt, sip_pvt::udptl, sip_pvt::uri, sip_pvt::useragent, sip_pvt::vad, ast_variable::value, sip_pvt::vrtp, and ast_channel::writeformat.
Referenced by handle_request_invite(), and sip_request_call().
04032 { 04033 struct ast_channel *tmp; 04034 struct ast_variable *v = NULL; 04035 int fmt; 04036 int what; 04037 int needvideo = 0, video = 0; 04038 char *decoded_exten; 04039 { 04040 const char *my_name; /* pick a good name */ 04041 04042 if (title) 04043 my_name = title; 04044 else if ( (my_name = strchr(i->fromdomain,':')) ) 04045 my_name++; /* skip ':' */ 04046 else 04047 my_name = i->fromdomain; 04048 04049 ast_mutex_unlock(&i->lock); 04050 /* Don't hold a sip pvt lock while we allocate a channel */ 04051 tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, i->accountcode, i->exten, i->context, i->amaflags, "SIP/%s-%08x", my_name, (int)(long) i); 04052 04053 } 04054 if (!tmp) { 04055 ast_log(LOG_WARNING, "Unable to allocate AST channel structure for SIP channel\n"); 04056 ast_mutex_lock(&i->lock); 04057 return NULL; 04058 } 04059 ast_mutex_lock(&i->lock); 04060 04061 if (ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_INFO) 04062 tmp->tech = &sip_tech_info; 04063 else 04064 tmp->tech = &sip_tech; 04065 04066 /* Select our native format based on codec preference until we receive 04067 something from another device to the contrary. */ 04068 if (i->jointcapability) { /* The joint capabilities of us and peer */ 04069 what = i->jointcapability; 04070 video = i->jointcapability & AST_FORMAT_VIDEO_MASK; 04071 } else if (i->capability) { /* Our configured capability for this peer */ 04072 what = i->capability; 04073 video = i->capability & AST_FORMAT_VIDEO_MASK; 04074 } else { 04075 what = global_capability; /* Global codec support */ 04076 video = global_capability & AST_FORMAT_VIDEO_MASK; 04077 } 04078 04079 /* Set the native formats for audio and merge in video */ 04080 tmp->nativeformats = ast_codec_choose(&i->prefs, what, 1) | video; 04081 if (option_debug > 2) { 04082 char buf[SIPBUFSIZE]; 04083 ast_log(LOG_DEBUG, "*** Our native formats are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, tmp->nativeformats)); 04084 ast_log(LOG_DEBUG, "*** Joint capabilities are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, i->jointcapability)); 04085 ast_log(LOG_DEBUG, "*** Our capabilities are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, i->capability)); 04086 ast_log(LOG_DEBUG, "*** AST_CODEC_CHOOSE formats are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, ast_codec_choose(&i->prefs, what, 1))); 04087 if (i->prefcodec) 04088 ast_log(LOG_DEBUG, "*** Our preferred formats from the incoming channel are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, i->prefcodec)); 04089 } 04090 04091 /* XXX Why are we choosing a codec from the native formats?? */ 04092 fmt = ast_best_codec(tmp->nativeformats); 04093 04094 /* If we have a prefcodec setting, we have an inbound channel that set a 04095 preferred format for this call. Otherwise, we check the jointcapability 04096 We also check for vrtp. If it's not there, we are not allowed do any video anyway. 04097 */ 04098 if (i->vrtp) { 04099 if (i->prefcodec) 04100 needvideo = i->prefcodec & AST_FORMAT_VIDEO_MASK; /* Outbound call */ 04101 else 04102 needvideo = i->jointcapability & AST_FORMAT_VIDEO_MASK; /* Inbound call */ 04103 } 04104 04105 if (option_debug > 2) { 04106 if (needvideo) 04107 ast_log(LOG_DEBUG, "This channel can handle video! HOLLYWOOD next!\n"); 04108 else 04109 ast_log(LOG_DEBUG, "This channel will not be able to handle video.\n"); 04110 } 04111 04112 04113 04114 if (ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_INBAND) { 04115 i->vad = ast_dsp_new(); 04116 ast_dsp_set_features(i->vad, DSP_FEATURE_DTMF_DETECT); 04117 if (global_relaxdtmf) 04118 ast_dsp_digitmode(i->vad, DSP_DIGITMODE_DTMF | DSP_DIGITMODE_RELAXDTMF); 04119 } 04120 if (i->rtp) { 04121 tmp->fds[0] = ast_rtp_fd(i->rtp); 04122 tmp->fds[1] = ast_rtcp_fd(i->rtp); 04123 } 04124 if (needvideo && i->vrtp) { 04125 tmp->fds[2] = ast_rtp_fd(i->vrtp); 04126 tmp->fds[3] = ast_rtcp_fd(i->vrtp); 04127 } 04128 if (i->udptl) { 04129 tmp->fds[5] = ast_udptl_fd(i->udptl); 04130 } 04131 if (state == AST_STATE_RING) 04132 tmp->rings = 1; 04133 tmp->adsicpe = AST_ADSI_UNAVAILABLE; 04134 tmp->writeformat = fmt; 04135 tmp->rawwriteformat = fmt; 04136 tmp->readformat = fmt; 04137 tmp->rawreadformat = fmt; 04138 tmp->tech_pvt = i; 04139 04140 tmp->callgroup = i->callgroup; 04141 tmp->pickupgroup = i->pickupgroup; 04142 tmp->cid.cid_pres = i->callingpres; 04143 if (!ast_strlen_zero(i->accountcode)) 04144 ast_string_field_set(tmp, accountcode, i->accountcode); 04145 if (i->amaflags) 04146 tmp->amaflags = i->amaflags; 04147 if (!ast_strlen_zero(i->language)) 04148 ast_string_field_set(tmp, language, i->language); 04149 i->owner = tmp; 04150 ast_module_ref(ast_module_info->self); 04151 ast_copy_string(tmp->context, i->context, sizeof(tmp->context)); 04152 /*Since it is valid to have extensions in the dialplan that have unescaped characters in them 04153 * we should decode the uri before storing it in the channel, but leave it encoded in the sip_pvt 04154 * structure so that there aren't issues when forming URI's 04155 */ 04156 decoded_exten = ast_strdupa(i->exten); 04157 ast_uri_decode(decoded_exten); 04158 ast_copy_string(tmp->exten, decoded_exten, sizeof(tmp->exten)); 04159 04160 /* Don't use ast_set_callerid() here because it will 04161 * generate an unnecessary NewCallerID event */ 04162 tmp->cid.cid_ani = ast_strdup(i->cid_num); 04163 if (!ast_strlen_zero(i->rdnis)) 04164 tmp->cid.cid_rdnis = ast_strdup(i->rdnis); 04165 04166 if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s")) 04167 tmp->cid.cid_dnid = ast_strdup(i->exten); 04168 04169 tmp->priority = 1; 04170 if (!ast_strlen_zero(i->uri)) 04171 pbx_builtin_setvar_helper(tmp, "SIPURI", i->uri); 04172 if (!ast_strlen_zero(i->domain)) 04173 pbx_builtin_setvar_helper(tmp, "SIPDOMAIN", i->domain); 04174 if (!ast_strlen_zero(i->useragent)) 04175 pbx_builtin_setvar_helper(tmp, "SIPUSERAGENT", i->useragent); 04176 if (!ast_strlen_zero(i->callid)) 04177 pbx_builtin_setvar_helper(tmp, "SIPCALLID", i->callid); 04178 if (i->rtp) 04179 ast_jb_configure(tmp, &global_jbconf); 04180 04181 /* If the INVITE contains T.38 SDP information set the proper channel variable so a created outgoing call will also have T.38 */ 04182 if (i->udptl && i->t38.state == T38_PEER_DIRECT) 04183 pbx_builtin_setvar_helper(tmp, "_T38CALL", "1"); 04184 04185 /* Set channel variables for this call from configuration */ 04186 for (v = i->chanvars ; v ; v = v->next) 04187 pbx_builtin_setvar_helper(tmp, v->name, v->value); 04188 04189 if (state != AST_STATE_DOWN && ast_pbx_start(tmp)) { 04190 ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name); 04191 tmp->hangupcause = AST_CAUSE_SWITCH_CONGESTION; 04192 ast_hangup(tmp); 04193 tmp = NULL; 04194 } 04195 04196 if (!ast_test_flag(&i->flags[0], SIP_NO_HISTORY)) 04197 append_history(i, "NewChan", "Channel %s - from %s", tmp->name, i->callid); 04198 04199 return tmp; 04200 }
| static int sip_no_debug | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Disable SIP Debugging in CLI.
Definition at line 11569 of file chan_sip.c.
References ast_clear_flag, ast_cli(), RESULT_SHOWUSAGE, RESULT_SUCCESS, and SIP_PAGE2_DEBUG_CONSOLE.
11570 { 11571 if (argc != 4) 11572 return RESULT_SHOWUSAGE; 11573 ast_clear_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONSOLE); 11574 ast_cli(fd, "SIP Debugging Disabled\n"); 11575 return RESULT_SUCCESS; 11576 }
| static int sip_no_debug_deprecated | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Definition at line 11578 of file chan_sip.c.
References ast_clear_flag, ast_cli(), RESULT_SHOWUSAGE, RESULT_SUCCESS, and SIP_PAGE2_DEBUG_CONSOLE.
11579 { 11580 if (argc != 3) 11581 return RESULT_SHOWUSAGE; 11582 ast_clear_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONSOLE); 11583 ast_cli(fd, "SIP Debugging Disabled\n"); 11584 return RESULT_SUCCESS; 11585 }
| static int sip_no_history | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Disable SIP History logging (CLI).
Definition at line 11599 of file chan_sip.c.
References ast_cli(), FALSE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
11600 { 11601 if (argc != 3) { 11602 return RESULT_SHOWUSAGE; 11603 } 11604 recordhistory = FALSE; 11605 ast_cli(fd, "SIP History Recording Disabled\n"); 11606 return RESULT_SUCCESS; 11607 }
| static int sip_notify | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Cli command to send SIP notify to peer.
Definition at line 11513 of file chan_sip.c.
References __ourip, add_header(), ast_cli(), ast_log(), ast_sip_ouraddrfor(), ast_unescape_semicolon(), ast_variable_browse(), build_callid_pvt(), build_via(), create_addr(), DEFAULT_TRANS_TIMEOUT, initreqprep(), LOG_WARNING, ast_variable::name, ast_variable::next, sip_pvt::ourip, RESULT_FAILURE, RESULT_SHOWUSAGE, RESULT_SUCCESS, sip_pvt::sa, sip_alloc(), sip_destroy(), SIP_NOTIFY, sip_scheddestroy(), transmit_sip_request(), ast_variable::value, and var.
11514 { 11515 struct ast_variable *varlist; 11516 int i; 11517 11518 if (argc < 4) 11519 return RESULT_SHOWUSAGE; 11520 11521 if (!notify_types) { 11522 ast_cli(fd, "No %s file found, or no types listed there\n", notify_config); 11523 return RESULT_FAILURE; 11524 } 11525 11526 varlist = ast_variable_browse(notify_types, argv[2]); 11527 11528 if (!varlist) { 11529 ast_cli(fd, "Unable to find notify type '%s'\n", argv[2]); 11530 return RESULT_FAILURE; 11531 } 11532 11533 for (i = 3; i < argc; i++) { 11534 struct sip_pvt *p; 11535 struct sip_request req; 11536 struct ast_variable *var; 11537 11538 if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY))) { 11539 ast_log(LOG_WARNING, "Unable to build sip pvt data for notify (memory/socket error)\n"); 11540 return RESULT_FAILURE; 11541 } 11542 11543 if (create_addr(p, argv[i])) { 11544 /* Maybe they're not registered, etc. */ 11545 sip_destroy(p); 11546 ast_cli(fd, "Could not create address for '%s'\n", argv[i]); 11547 continue; 11548 } 11549 11550 initreqprep(&req, p, SIP_NOTIFY); 11551 11552 for (var = varlist; var; var = var->next) 11553 add_header(&req, var->name, ast_unescape_semicolon(var->value)); 11554 11555 /* Recalculate our side, and recalculate Call ID */ 11556 if (ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip)) 11557 p->ourip = __ourip; 11558 build_via(p); 11559 build_callid_pvt(p); 11560 ast_cli(fd, "Sending NOTIFY of type '%s' to '%s'\n", argv[2], argv[i]); 11561 transmit_sip_request(p, &req); 11562 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 11563 } 11564 11565 return RESULT_SUCCESS; 11566 }
| static int sip_park | ( | struct ast_channel * | chan1, | |
| struct ast_channel * | chan2, | |||
| struct sip_request * | req, | |||
| int | seqno | |||
| ) | [static] |
Park a call using the subsystem in res_features.c This is executed in a separate thread.
Definition at line 13349 of file chan_sip.c.
References ast_channel::accountcode, ast_channel::amaflags, ast_calloc, AST_CAUSE_SWITCH_CONGESTION, ast_channel_alloc(), ast_channel_lock, ast_channel_masquerade(), ast_channel_trylock, ast_channel_unlock, ast_copy_string(), ast_do_masquerade(), ast_hangup(), ast_log(), ast_pthread_create_background, AST_STATE_DOWN, sip_dual::chan1, sip_dual::chan2, ast_channel::context, copy_request(), DEADLOCK_AVOIDANCE, ast_channel::exten, free, ast_channel::hangupcause, sip_pvt::lock, LOG_DEBUG, LOG_WARNING, ast_channel::name, option_debug, ast_channel::priority, ast_channel::readformat, sip_dual::req, sip_dual::seqno, sip_park_thread(), ast_channel::tech_pvt, and ast_channel::writeformat.
Referenced by handle_request_refer().
13350 { 13351 struct sip_dual *d; 13352 struct ast_channel *transferee, *transferer; 13353 /* Chan2m: The transferer, chan1m: The transferee */ 13354 pthread_t th; 13355 13356 transferee = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, chan1->accountcode, chan1->exten, chan1->context, chan1->amaflags, "Parking/%s", chan1->name); 13357 transferer = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, chan2->accountcode, chan2->exten, chan2->context, chan2->amaflags, "SIPPeer/%s", chan2->name); 13358 if ((!transferer) || (!transferee)) { 13359 if (transferee) { 13360 transferee->hangupcause = AST_CAUSE_SWITCH_CONGESTION; 13361 ast_hangup(transferee); 13362 } 13363 if (transferer) { 13364 transferer->hangupcause = AST_CAUSE_SWITCH_CONGESTION; 13365 ast_hangup(transferer); 13366 } 13367 return -1; 13368 } 13369 13370 /* Make formats okay */ 13371 transferee->readformat = chan1->readformat; 13372 transferee->writeformat = chan1->writeformat; 13373 13374 /* Prepare for taking over the channel */ 13375 ast_channel_masquerade(transferee, chan1); 13376 13377 /* Setup the extensions and such */ 13378 ast_copy_string(transferee->context, chan1->context, sizeof(transferee->context)); 13379 ast_copy_string(transferee->exten, chan1->exten, sizeof(transferee->exten)); 13380 transferee->priority = chan1->priority; 13381 13382 /* We make a clone of the peer channel too, so we can play 13383 back the announcement */ 13384 13385 /* Make formats okay */ 13386 transferer->readformat = chan2->readformat; 13387 transferer->writeformat = chan2->writeformat; 13388 13389 /* Prepare for taking over the channel. Go ahead and grab this channel 13390 * lock here to avoid a deadlock with callbacks into the channel driver 13391 * that hold the channel lock and want the pvt lock. */ 13392 while (ast_channel_trylock(chan2)) { 13393 struct sip_pvt *pvt = chan2->tech_pvt; 13394 DEADLOCK_AVOIDANCE(&pvt->lock); 13395 } 13396 ast_channel_masquerade(transferer, chan2); 13397 ast_channel_unlock(chan2); 13398 13399 /* Setup the extensions and such */ 13400 ast_copy_string(transferer->context, chan2->context, sizeof(transferer->context)); 13401 ast_copy_string(transferer->exten, chan2->exten, sizeof(transferer->exten)); 13402 transferer->priority = chan2->priority; 13403 13404 ast_channel_lock(transferer); 13405 if (ast_do_masquerade(transferer)) { 13406 ast_log(LOG_WARNING, "Masquerade failed :(\n"); 13407 ast_channel_unlock(transferer); 13408 transferer->hangupcause = AST_CAUSE_SWITCH_CONGESTION; 13409 ast_hangup(transferer); 13410 return -1; 13411 } 13412 ast_channel_unlock(transferer); 13413 if (!transferer || !transferee) { 13414 if (!transferer) { 13415 if (option_debug) 13416 ast_log(LOG_DEBUG, "No transferer channel, giving up parking\n"); 13417 } 13418 if (!transferee) { 13419 if (option_debug) 13420 ast_log(LOG_DEBUG, "No transferee channel, giving up parking\n"); 13421 } 13422 return -1; 13423 } 13424 if ((d = ast_calloc(1, sizeof(*d)))) { 13425 pthread_attr_t attr; 13426 13427 pthread_attr_init(&attr); 13428 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); 13429 13430 /* Save original request for followup */ 13431 copy_request(&d->req, req); 13432 d->chan1 = transferee; /* Transferee */ 13433 d->chan2 = transferer; /* Transferer */ 13434 d->seqno = seqno; 13435 if (ast_pthread_create_background(&th, &attr, sip_park_thread, d) < 0) { 13436 /* Could not start thread */ 13437 free(d); /* We don't need it anymore. If thread is created, d will be free'd 13438 by sip_park_thread() */ 13439 pthread_attr_destroy(&attr); 13440 return 0; 13441 } 13442 pthread_attr_destroy(&attr); 13443 } 13444 return -1; 13445 }
| 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 13282 of file chan_sip.c.
References append_history, AST_CAUSE_NORMAL_CLEARING, ast_channel_lock, ast_channel_unlock, ast_do_masquerade(), ast_hangup(), ast_log(), ast_park_call(), sip_dual::chan1, sip_dual::chan2, copy_request(), ext, free, ast_channel::hangupcause, LOG_DEBUG, LOG_ERROR, LOG_WARNING, ast_channel::name, option_debug, sip_dual::req, sip_dual::seqno, ast_channel::tech_pvt, transmit_message_with_text(), transmit_notify_with_sipfrag(), transmit_response(), and TRUE.
Referenced by sip_park().
13283 { 13284 struct ast_channel *transferee, *transferer; /* Chan1: The transferee, Chan2: The transferer */ 13285 struct sip_dual *d; 13286 struct sip_request req; 13287 int ext; 13288 int res; 13289 13290 d = stuff; 13291 transferee = d->chan1; 13292 transferer = d->chan2; 13293 copy_request(&req, &d->req); 13294 13295 if (!transferee || !transferer) { 13296 ast_log(LOG_ERROR, "Missing channels for parking! Transferer %s Transferee %s\n", transferer ? "<available>" : "<missing>", transferee ? "<available>" : "<missing>" ); 13297 return NULL; 13298 } 13299 if (option_debug > 3) 13300 ast_log(LOG_DEBUG, "SIP Park: Transferer channel %s, Transferee %s\n", transferer->name, transferee->name); 13301 13302 ast_channel_lock(transferee); 13303 if (ast_do_masquerade(transferee)) { 13304 ast_log(LOG_WARNING, "Masquerade failed.\n"); 13305 transmit_response(transferer->tech_pvt, "503 Internal error", &req); 13306 ast_channel_unlock(transferee); 13307 return NULL; 13308 } 13309 ast_channel_unlock(transferee); 13310 13311 res = ast_park_call(transferee, transferer, 0, &ext); 13312 13313 13314 #ifdef WHEN_WE_KNOW_THAT_THE_CLIENT_SUPPORTS_MESSAGE 13315 if (!res) { 13316 transmit_message_with_text(transferer->tech_pvt, "Unable to park call.\n"); 13317 } else { 13318 /* Then tell the transferer what happened */ 13319 sprintf(buf, "Call parked on extension '%d'", ext); 13320 transmit_message_with_text(transferer->tech_pvt, buf); 13321 } 13322 #endif 13323 13324 /* Any way back to the current call??? */ 13325 /* Transmit response to the REFER request */ 13326 transmit_response(transferer->tech_pvt, "202 Accepted", &req); 13327 if (!res) { 13328 /* Transfer succeeded */ 13329 append_history(transferer->tech_pvt, "SIPpark","Parked call on %d", ext); 13330 transmit_notify_with_sipfrag(transferer->tech_pvt, d->seqno, "200 OK", TRUE); 13331 transferer->hangupcause = AST_CAUSE_NORMAL_CLEARING; 13332 ast_hangup(transferer); /* This will cause a BYE */ 13333 if (option_debug) 13334 ast_log(LOG_DEBUG, "SIP Call parked on extension '%d'\n", ext); 13335 } else { 13336 transmit_notify_with_sipfrag(transferer->tech_pvt, d->seqno, "503 Service Unavailable", TRUE); 13337 append_history(transferer->tech_pvt, "SIPpark","Parking failed\n"); 13338 if (option_debug) 13339 ast_log(LOG_DEBUG, "SIP Call parked failed \n"); 13340 /* Do not hangup call */ 13341 } 13342 free(d); 13343 return NULL; 13344 }
| 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 8688 of file chan_sip.c.
References ast_device_state_changed(), find_peer(), sip_peer::name, sip_peer::onHold, and sip_pvt::peername.
Referenced by change_hold_state(), and update_call_counter().
08689 { 08690 struct sip_peer *peer = find_peer(p->peername, NULL, 1, 0); 08691 08692 if (!peer) 08693 return; 08694 08695 /* If they put someone on hold, increment the value... otherwise decrement it */ 08696 if (hold) 08697 peer->onHold++; 08698 else 08699 peer->onHold--; 08700 08701 /* Request device state update */ 08702 ast_device_state_changed("SIP/%s", peer->name); 08703 08704 return; 08705 }
| static void sip_poke_all_peers | ( | void | ) | [static] |
Send a poke to all known peers Space them out 100 ms apart XXX We might have a cool algorithm for this or use random - any suggestions?
Definition at line 18437 of file chan_sip.c.
References ast_sched_add(), AST_SCHED_DEL, ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_REF, ASTOBJ_UNLOCK, ASTOBJ_UNREF, ASTOBJ_WRLOCK, peerl, sip_destroy_peer(), and sip_poke_peer_s().
Referenced by load_module(), and sip_do_reload().
18438 { 18439 int ms = 0; 18440 18441 if (!speerobjs) /* No peers, just give up */ 18442 return; 18443 18444 ASTOBJ_CONTAINER_TRAVERSE(&peerl, 1, do { 18445 ASTOBJ_WRLOCK(iterator); 18446 if (!AST_SCHED_DEL(sched, iterator->pokeexpire)) { 18447 struct sip_peer *peer_ptr = iterator; 18448 ASTOBJ_UNREF(peer_ptr, sip_destroy_peer); 18449 } 18450 ms += 100; 18451 iterator->pokeexpire = ast_sched_add(sched, ms, sip_poke_peer_s, ASTOBJ_REF(iterator)); 18452 if (iterator->pokeexpire == -1) { 18453 struct sip_peer *peer_ptr = iterator; 18454 ASTOBJ_UNREF(peer_ptr, sip_destroy_peer); 18455 } 18456 ASTOBJ_UNLOCK(iterator); 18457 } while (0) 18458 ); 18459 }
| static int sip_poke_noanswer | ( | const void * | data | ) | [static] |
React to lack of answer to Qualify poke.
Definition at line 16308 of file chan_sip.c.
References ast_device_state_changed(), ast_log(), ast_sched_add(), AST_SCHED_DEL, ASTOBJ_UNREF, sip_peer::call, DEFAULT_FREQ_NOTOK, EVENT_FLAG_SYSTEM, sip_peer::lastms, LOG_NOTICE, manager_event(), sip_peer::name, sip_peer::pokeexpire, sip_destroy(), sip_destroy_peer(), and sip_poke_peer_s().
Referenced by sip_poke_peer().
16309 { 16310 struct sip_peer *peer = (struct sip_peer *)data; 16311 16312 peer->pokeexpire = -1; 16313 if (peer->lastms > -1) { 16314 ast_log(LOG_NOTICE, "Peer '%s' is now UNREACHABLE! Last qualify: %d\n", peer->name, peer->lastms); 16315 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: SIP/%s\r\nPeerStatus: Unreachable\r\nTime: %d\r\n", peer->name, -1); 16316 } 16317 if (peer->call) 16318 sip_destroy(peer->call); 16319 peer->call = NULL; 16320 peer->lastms = -1; 16321 ast_device_state_changed("SIP/%s", peer->name); 16322 16323 /* This function gets called one place outside of the scheduler ... */ 16324 if (!AST_SCHED_DEL(sched, peer->pokeexpire)) { 16325 struct sip_peer *peer_ptr = peer; 16326 ASTOBJ_UNREF(peer_ptr, sip_destroy_peer); 16327 } 16328 16329 /* There is no need to ASTOBJ_REF() here. Just let the scheduled callback 16330 * inherit the reference that the current callback already has. */ 16331 peer->pokeexpire = ast_sched_add(sched, DEFAULT_FREQ_NOTOK, sip_poke_peer_s, peer); 16332 if (peer->pokeexpire == -1) { 16333 ASTOBJ_UNREF(peer, sip_destroy_peer); 16334 } 16335 16336 return 0; 16337 }
| static int sip_poke_peer | ( | struct sip_peer * | peer | ) | [static] |
Check availability of peer, also keep NAT open.
Definition at line 16342 of file chan_sip.c.
References __ourip, sip_peer::addr, ast_copy_flags, ast_copy_string(), ast_inet_ntoa(), ast_log(), ast_sched_add(), AST_SCHED_DEL, ast_set_flag, ast_sip_ouraddrfor(), ast_string_field_set, ast_strlen_zero(), ASTOBJ_REF, ASTOBJ_UNREF, build_callid_pvt(), build_via(), sip_peer::call, sip_peer::flags, sip_pvt::flags, sip_peer::fullcontact, sip_peer::lastms, LOG_NOTICE, sip_peer::maxms, sip_pvt::ourip, sip_peer::pokeexpire, sip_peer::ps, sip_pvt::recv, sip_pvt::relatedpeer, sip_pvt::sa, sip_alloc(), sip_destroy(), sip_destroy_peer(), SIP_FLAGS_TO_COPY, SIP_INVITE, SIP_OPTIONS, SIP_OUTGOING, SIP_PAGE2_FLAGS_TO_COPY, sip_poke_noanswer(), sipdebug, sip_peer::tohost, transmit_invite(), sip_pvt::username, and XMIT_ERROR.
Referenced by parse_register_contact(), reg_source_db(), and sip_poke_peer_s().
16343 { 16344 struct sip_pvt *p; 16345 int xmitres = 0; 16346 16347 if (!peer->maxms || !peer->addr.sin_addr.s_addr) { 16348 /* IF we have no IP, or this isn't to be monitored, return 16349 imeediately after clearing things out */ 16350 if (!AST_SCHED_DEL(sched, peer->pokeexpire)) { 16351 struct sip_peer *peer_ptr = peer; 16352 ASTOBJ_UNREF(peer_ptr, sip_destroy_peer); 16353 } 16354 peer->lastms = 0; 16355 peer->call = NULL; 16356 return 0; 16357 } 16358 if (peer->call) { 16359 if (sipdebug) 16360 ast_log(LOG_NOTICE, "Still have a QUALIFY dialog active, deleting\n"); 16361 sip_destroy(peer->call); 16362 } 16363 if (!(p = peer->call = sip_alloc(NULL, NULL, 0, SIP_OPTIONS))) 16364 return -1; 16365 16366 p->sa = peer->addr; 16367 p->recv = peer->addr; 16368 ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY); 16369 ast_copy_flags(&p->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY); 16370 16371 /* Send OPTIONs to peer's fullcontact */ 16372 if (!ast_strlen_zero(peer->fullcontact)) 16373 ast_string_field_set(p, fullcontact, peer->fullcontact); 16374 16375 if (!ast_strlen_zero(peer->tohost)) 16376 ast_string_field_set(p, tohost, peer->tohost); 16377 else 16378 ast_string_field_set(p, tohost, ast_inet_ntoa(peer->addr.sin_addr)); 16379 16380 /* Recalculate our side, and recalculate Call ID */ 16381 if (ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip)) 16382 p->ourip = __ourip; 16383 build_via(p); 16384 build_callid_pvt(p); 16385 16386 if (!AST_SCHED_DEL(sched, peer->pokeexpire)) { 16387 struct sip_peer *peer_ptr = peer; 16388 ASTOBJ_UNREF(peer_ptr, sip_destroy_peer); 16389 } 16390 16391 p->relatedpeer = ASTOBJ_REF(peer); 16392 ast_set_flag(&p->flags[0], SIP_OUTGOING); 16393 #ifdef VOCAL_DATA_HACK 16394 ast_copy_string(p->username, "__VOCAL_DATA_SHOULD_READ_THE_SIP_SPEC__", sizeof(p->username)); 16395 xmitres = transmit_invite(p, SIP_INVITE, 0, 2); 16396 #else 16397 xmitres = transmit_invite(p, SIP_OPTIONS, 0, 2); 16398 #endif 16399 gettimeofday(&peer->ps, NULL); 16400 if (xmitres == XMIT_ERROR) { 16401 sip_poke_noanswer(ASTOBJ_REF(peer)); /* Immediately unreachable, network problems */ 16402 } else { 16403 if (!AST_SCHED_DEL(sched, peer->pokeexpire)) { 16404 struct sip_peer *peer_ptr = peer; 16405 ASTOBJ_UNREF(peer_ptr, sip_destroy_peer); 16406 } 16407 peer->pokeexpire = ast_sched_add(sched, peer->maxms * 2, sip_poke_noanswer, ASTOBJ_REF(peer)); 16408 if (peer->pokeexpire == -1) { 16409 struct sip_peer *peer_ptr = peer; 16410 ASTOBJ_UNREF(peer_ptr, sip_destroy_peer); 16411 } 16412 } 16413 16414 return 0; 16415 }
| 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 8034 of file chan_sip.c.
References ASTOBJ_UNREF, sip_peer::pokeexpire, sip_destroy_peer(), and sip_poke_peer().
Referenced by handle_response_peerpoke(), reg_source_db(), sip_poke_all_peers(), and sip_poke_noanswer().
08035 { 08036 struct sip_peer *peer = (struct sip_peer *) data; 08037 08038 peer->pokeexpire = -1; 08039 08040 sip_poke_peer(peer); 08041 08042 ASTOBJ_UNREF(peer, sip_destroy_peer); 08043 08044 return 0; 08045 }
| static int sip_prune_realtime | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Remove temporary realtime objects from memory (CLI).
Definition at line 10296 of file chan_sip.c.
References ast_cli(), ast_test_flag, ASTOBJ_CONTAINER_FIND_UNLINK, ASTOBJ_CONTAINER_LINK, ASTOBJ_CONTAINER_PRUNE_MARKED, ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_CONTAINER_UNLOCK, ASTOBJ_CONTAINER_WRLOCK, ASTOBJ_MARK, ASTOBJ_RDLOCK, ASTOBJ_UNLOCK, ASTOBJ_UNREF, FALSE, sip_user::flags, sip_peer::flags, name, peerl, RESULT_SHOWUSAGE, RESULT_SUCCESS, sip_destroy_peer(), sip_destroy_user(), SIP_PAGE2_RTCACHEFRIENDS, TRUE, and userl.
10297 { 10298 struct sip_peer *peer; 10299 struct sip_user *user; 10300 int pruneuser = FALSE; 10301 int prunepeer = FALSE; 10302 int multi = FALSE; 10303 char *name = NULL; 10304 regex_t regexbuf; 10305 10306 switch (argc) { 10307 case 4: 10308 if (!strcasecmp(argv[3], "user")) 10309 return RESULT_SHOWUSAGE; 10310 if (!strcasecmp(argv[3], "peer")) 10311 return RESULT_SHOWUSAGE; 10312 if (!strcasecmp(argv[3], "like")) 10313 return RESULT_SHOWUSAGE; 10314 if (!strcasecmp(argv[3], "all")) { 10315 multi = TRUE; 10316 pruneuser = prunepeer = TRUE; 10317 } else { 10318 pruneuser = prunepeer = TRUE; 10319 name = argv[3]; 10320 } 10321 break; 10322 case 5: 10323 if (!strcasecmp(argv[4], "like")) 10324 return RESULT_SHOWUSAGE; 10325 if (!strcasecmp(argv[3], "all")) 10326 return RESULT_SHOWUSAGE; 10327 if (!strcasecmp(argv[3], "like")) { 10328 multi = TRUE; 10329 name = argv[4]; 10330 pruneuser = prunepeer = TRUE; 10331 } else if (!strcasecmp(argv[3], "user")) { 10332 pruneuser = TRUE; 10333 if (!strcasecmp(argv[4], "all")) 10334 multi = TRUE; 10335 else 10336 name = argv[4]; 10337 } else if (!strcasecmp(argv[3], "peer")) { 10338 prunepeer = TRUE; 10339 if (!strcasecmp(argv[4], "all")) 10340 multi = TRUE; 10341 else 10342 name = argv[4]; 10343 } else 10344 return RESULT_SHOWUSAGE; 10345 break; 10346 case 6: 10347 if (strcasecmp(argv[4], "like")) 10348 return RESULT_SHOWUSAGE; 10349 if (!strcasecmp(argv[3], "user")) { 10350 pruneuser = TRUE; 10351 name = argv[5]; 10352 } else if (!strcasecmp(argv[3], "peer")) { 10353 prunepeer = TRUE; 10354 name = argv[5]; 10355 } else 10356 return RESULT_SHOWUSAGE; 10357 break; 10358 default: 10359 return RESULT_SHOWUSAGE; 10360 } 10361 10362 if (multi && name) { 10363 if (regcomp(®exbuf, name, REG_EXTENDED | REG_NOSUB)) 10364 return RESULT_SHOWUSAGE; 10365 } 10366 10367 if (multi) { 10368 if (prunepeer) { 10369 int pruned = 0; 10370 10371 ASTOBJ_CONTAINER_WRLOCK(&peerl); 10372 ASTOBJ_CONTAINER_TRAVERSE(&peerl, 1, do { 10373 ASTOBJ_RDLOCK(iterator); 10374 if (name && regexec(®exbuf, iterator->name, 0, NULL, 0)) { 10375 ASTOBJ_UNLOCK(iterator); 10376 continue; 10377 }; 10378 if (ast_test_flag(&iterator->flags[1], SIP_PAGE2_RTCACHEFRIENDS)) { 10379 ASTOBJ_MARK(iterator); 10380 pruned++; 10381 } 10382 ASTOBJ_UNLOCK(iterator); 10383 } while (0) ); 10384 if (pruned) { 10385 ASTOBJ_CONTAINER_PRUNE_MARKED(&peerl, sip_destroy_peer); 10386 ast_cli(fd, "%d peers pruned.\n", pruned); 10387 } else 10388 ast_cli(fd, "No peers found to prune.\n"); 10389 ASTOBJ_CONTAINER_UNLOCK(&peerl); 10390 } 10391 if (pruneuser) { 10392 int pruned = 0; 10393 10394 ASTOBJ_CONTAINER_WRLOCK(&userl); 10395 ASTOBJ_CONTAINER_TRAVERSE(&userl, 1, do { 10396 ASTOBJ_RDLOCK(iterator); 10397 if (name && regexec(®exbuf, iterator->name, 0, NULL, 0)) { 10398 ASTOBJ_UNLOCK(iterator); 10399 continue; 10400 }; 10401 if (ast_test_flag(&iterator->flags[1], SIP_PAGE2_RTCACHEFRIENDS)) { 10402 ASTOBJ_MARK(iterator); 10403 pruned++; 10404 } 10405 ASTOBJ_UNLOCK(iterator); 10406 } while (0) ); 10407 if (pruned) { 10408 ASTOBJ_CONTAINER_PRUNE_MARKED(&userl, sip_destroy_user); 10409 ast_cli(fd, "%d users pruned.\n", pruned); 10410 } else 10411 ast_cli(fd, "No users found to prune.\n"); 10412 ASTOBJ_CONTAINER_UNLOCK(&userl); 10413 } 10414 } else { 10415 if (prunepeer) { 10416 if ((peer = ASTOBJ_CONTAINER_FIND_UNLINK(&peerl, name))) { 10417 if (!ast_test_flag(&peer->flags[1], SIP_PAGE2_RTCACHEFRIENDS)) { 10418 ast_cli(fd, "Peer '%s' is not a Realtime peer, cannot be pruned.\n", name); 10419 ASTOBJ_CONTAINER_LINK(&peerl, peer); 10420 } else 10421 ast_cli(fd, "Peer '%s' pruned.\n", name); 10422 ASTOBJ_UNREF(peer, sip_destroy_peer); 10423 } else 10424 ast_cli(fd, "Peer '%s' not found.\n", name); 10425 } 10426 if (pruneuser) { 10427 if ((user = ASTOBJ_CONTAINER_FIND_UNLINK(&userl, name))) { 10428 if (!ast_test_flag(&user->flags[1], SIP_PAGE2_RTCACHEFRIENDS)) { 10429 ast_cli(fd, "User '%s' is not a Realtime user, cannot be pruned.\n", name); 10430 ASTOBJ_CONTAINER_LINK(&userl, user); 10431 } else 10432 ast_cli(fd, "User '%s' pruned.\n", name); 10433 ASTOBJ_UNREF(user, sip_destroy_user); 10434 } else 10435 ast_cli(fd, "User '%s' not found.\n", name); 10436 } 10437 } 10438 10439 return RESULT_SUCCESS; 10440 }
| static struct ast_frame * sip_read | ( | struct ast_channel * | ast | ) | [static, read] |
Read SIP RTP from channel.
Definition at line 4403 of file chan_sip.c.
References ast_channel::_state, ast_bridged_channel(), AST_FRAME_VOICE, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_null_frame, ast_set_flag, AST_STATE_UP, ast_test_flag, FALSE, sip_pvt::flags, ast_frame::frametype, INV_EARLY_MEDIA, sip_pvt::invitestate, sip_pvt::lastrtprx, sip_pvt::lock, LOG_DEBUG, ast_channel::name, option_debug, sip_pvt::pendinginvite, SIP_GOTREFER, SIP_NEEDREINVITE, SIP_PAGE2_T38SUPPORT_UDPTL, SIP_PENDINGBYE, sip_rtp_read(), t38properties::state, sip_pvt::t38, T38_DISABLED, T38_LOCAL_REINVITE, t38properties::t38support, ast_channel::tech_pvt, and transmit_reinvite_with_t38_sdp().
04404 { 04405 struct ast_frame *fr; 04406 struct sip_pvt *p; 04407 04408 if( ast == NULL ) 04409 return NULL; 04410 04411 p = ast->tech_pvt; 04412 int faxdetected = FALSE; 04413 04414 if( p == NULL ) 04415 return NULL; 04416 04417 ast_mutex_lock(&p->lock); 04418 fr = sip_rtp_read(ast, p, &faxdetected); 04419 p->lastrtprx = time(NULL); 04420 04421 /* If we are NOT bridged to another channel, and we have detected fax tone we issue T38 re-invite to a peer */ 04422 /* If we are bridged then it is the responsibility of the SIP device to issue T38 re-invite if it detects CNG or fax preamble */ 04423 if (faxdetected && ast_test_flag(&p->t38.t38support, SIP_PAGE2_T38SUPPORT_UDPTL) && (p->t38.state == T38_DISABLED) && !(ast_bridged_channel(ast))) { 04424 if (!ast_test_flag(&p->flags[0], SIP_GOTREFER)) { 04425 if (!p->pendinginvite) { 04426 if (option_debug > 2) 04427 ast_log(LOG_DEBUG, "Sending reinvite on SIP (%s) for T.38 negotiation.\n",ast->name); 04428 p->t38.state = T38_LOCAL_REINVITE; 04429 transmit_reinvite_with_t38_sdp(p); 04430 if (option_debug > 1) 04431 ast_log(LOG_DEBUG, "T38 state changed to %d on channel %s\n", p->t38.state, ast->name); 04432 } 04433 } else if (!ast_test_flag(&p->flags[0], SIP_PENDINGBYE)) { 04434 if (option_debug > 2) 04435 ast_log(LOG_DEBUG, "Deferring reinvite on SIP (%s) - it will be re-negotiated for T.38\n", ast->name); 04436 ast_set_flag(&p->flags[0], SIP_NEEDREINVITE); 04437 } 04438 } 04439 04440 /* Only allow audio through if they sent progress with SDP, or if the channel is actually answered */ 04441 if (fr && fr->frametype == AST_FRAME_VOICE && p->invitestate != INV_EARLY_MEDIA && ast->_state != AST_STATE_UP) { 04442 fr = &ast_null_frame; 04443 } 04444 04445 ast_mutex_unlock(&p->lock); 04446 return fr; 04447 }
| static struct sockaddr_in * sip_real_dst | ( | const struct sip_pvt * | p | ) | [static, read] |
The real destination address for a write.
Definition at line 1764 of file chan_sip.c.
References ast_test_flag, sip_pvt::flags, sip_pvt::recv, sip_pvt::sa, SIP_NAT, and SIP_NAT_ROUTE.
Referenced by __sip_xmit(), check_via(), retrans_pkt(), send_response(), and sip_debug_test_pvt().
01765 { 01766 return ast_test_flag(&p->flags[0], SIP_NAT) & SIP_NAT_ROUTE ? &p->recv : &p->sa; 01767 }
| static int sip_refer_allocate | ( | struct sip_pvt * | p | ) | [static] |
Allocate SIP refer structure.
Definition at line 7839 of file chan_sip.c.
References ast_calloc, and sip_pvt::refer.
Referenced by get_also_info(), handle_request_invite(), handle_request_refer(), and transmit_refer().
07840 { 07841 p->refer = ast_calloc(1, sizeof(struct sip_refer)); 07842 return p->refer ? 1 : 0; 07843 }
| static int sip_reg_timeout | ( | const void * | data | ) | [static] |
Registration timeout, register again.
Definition at line 7584 of file chan_sip.c.
References __sip_pretend_ack(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_set_flag, ASTOBJ_REF, ASTOBJ_UNREF, sip_registry::call, EVENT_FLAG_SYSTEM, sip_pvt::flags, sip_registry::hostname, sip_pvt::lock, LOG_NOTICE, manager_event(), REG_STATE_FAILED, REG_STATE_UNREGISTERED, sip_registry::regattempts, sip_pvt::registry, sip_registry::regstate, regstate2str(), SIP_NEEDDESTROY, SIP_REGISTER, sip_registry_destroy(), sip_registry::timeout, transmit_register(), and sip_registry::username.
Referenced by transmit_register().
07585 { 07586 07587 /* if we are here, our registration timed out, so we'll just do it over */ 07588 struct sip_registry *r = ASTOBJ_REF((struct sip_registry *) data); 07589 struct sip_pvt *p; 07590 int res; 07591 07592 /* if we couldn't get a reference to the registry object, punt */ 07593 if (!r) 07594 return 0; 07595 07596 ast_log(LOG_NOTICE, " -- Registration for '%s@%s' timed out, trying again (Attempt #%d)\n", r->username, r->hostname, r->regattempts); 07597 if (r->call) { 07598 /* Unlink us, destroy old call. Locking is not relevant here because all this happens 07599 in the single SIP manager thread. */ 07600 p = r->call; 07601 ast_mutex_lock(&p->lock); 07602 if (p->registry) 07603 ASTOBJ_UNREF(p->registry, sip_registry_destroy); 07604 r->call = NULL; 07605 ast_set_flag(&p->flags[0], SIP_NEEDDESTROY); 07606 /* Pretend to ACK anything just in case */ 07607 __sip_pretend_ack(p); 07608 ast_mutex_unlock(&p->lock); 07609 } 07610 /* If we have a limit, stop registration and give up */ 07611 if (global_regattempts_max && (r->regattempts > global_regattempts_max)) { 07612 /* Ok, enough is enough. Don't try any more */ 07613 /* We could add an external notification here... 07614 steal it from app_voicemail :-) */ 07615 ast_log(LOG_NOTICE, " -- Giving up forever trying to register '%s@%s'\n", r->username, r->hostname); 07616 r->regstate = REG_STATE_FAILED; 07617 } else { 07618 r->regstate = REG_STATE_UNREGISTERED; 07619 r->timeout = -1; 07620 res=transmit_register(r, SIP_REGISTER, NULL, NULL); 07621 } 07622 manager_event(EVENT_FLAG_SYSTEM, "Registry", "ChannelDriver: SIP\r\nUsername: %s\r\nDomain: %s\r\nStatus: %s\r\n", r->username, r->hostname, regstate2str(r->regstate)); 07623 ASTOBJ_UNREF(r, sip_registry_destroy); 07624 return 0; 07625 }
| static int sip_register | ( | char * | value, | |
| int | lineno | |||
| ) | [static] |
Parse register=> line in sip.conf and add to registry.
Definition at line 4739 of file chan_sip.c.
References ast_calloc, ast_copy_string(), ast_log(), ast_string_field_init, ast_string_field_set, ast_strlen_zero(), ASTOBJ_CONTAINER_LINK, ASTOBJ_INIT, ASTOBJ_UNREF, sip_registry::authuser, sip_registry::callid_valid, sip_registry::contact, sip_registry::expire, FALSE, free, hostname, INITIAL_CSEQ, LOG_ERROR, LOG_WARNING, sip_registry::ocseq, sip_registry::portno, sip_registry::refresh, regl, secret, sip_registry_destroy(), sip_registry::timeout, and username.
Referenced by reload_config().
04740 { 04741 struct sip_registry *reg; 04742 int portnum = 0; 04743 char username[256] = ""; 04744 char *hostname=NULL, *secret=NULL, *authuser=NULL; 04745 char *porta=NULL; 04746 char *contact=NULL; 04747 04748 if (!value) 04749 return -1; 04750 ast_copy_string(username, value, sizeof(username)); 04751 /* First split around the last '@' then parse the two components. */ 04752 hostname = strrchr(username, '@'); /* allow @ in the first part */ 04753 if (hostname) 04754 *hostname++ = '\0'; 04755 if (ast_strlen_zero(username) || ast_strlen_zero(hostname)) { 04756 ast_log(LOG_WARNING, "Format for registration is user[:secret[:authuser]]@host[:port][/contact] at line %d\n", lineno); 04757 return -1; 04758 } 04759 /* split user[:secret[:authuser]] */ 04760 secret = strchr(username, ':'); 04761 if (secret) { 04762 *secret++ = '\0'; 04763 authuser = strchr(secret, ':'); 04764 if (authuser) 04765 *authuser++ = '\0'; 04766 } 04767 /* split host[:port][/contact] */ 04768 contact = strchr(hostname, '/'); 04769 if (contact) 04770 *contact++ = '\0'; 04771 if (ast_strlen_zero(contact)) 04772 contact = "s"; 04773 porta = strchr(hostname, ':'); 04774 if (porta) { 04775 *porta++ = '\0'; 04776 portnum = atoi(porta); 04777 if (portnum == 0) { 04778 ast_log(LOG_WARNING, "%s is not a valid port number at line %d\n", porta, lineno); 04779 return -1; 04780 } 04781 } 04782 if (!(reg = ast_calloc(1, sizeof(*reg)))) { 04783 ast_log(LOG_ERROR, "Out of memory. Can't allocate SIP registry entry\n"); 04784 return -1; 04785 } 04786 04787 if (ast_string_field_init(reg, 256)) { 04788 ast_log(LOG_ERROR, "Out of memory. Can't allocate SIP registry strings\n"); 04789 free(reg); 04790 return -1; 04791 } 04792 04793 regobjs++; 04794 ASTOBJ_INIT(reg); 04795 ast_string_field_set(reg, contact, contact); 04796 if (!ast_strlen_zero(username)) 04797 ast_string_field_set(reg, username, username); 04798 if (hostname) 04799 ast_string_field_set(reg, hostname, hostname); 04800 if (authuser) 04801 ast_string_field_set(reg, authuser, authuser); 04802 if (secret) 04803 ast_string_field_set(reg, secret, secret); 04804 reg->expire = -1; 04805 reg->timeout = -1; 04806 reg->refresh = default_expiry; 04807 reg->portno = portnum; 04808 reg->callid_valid = FALSE; 04809 reg->ocseq = INITIAL_CSEQ; 04810 ASTOBJ_CONTAINER_LINK(®l, reg); /* Add the new registry entry to the list */ 04811 ASTOBJ_UNREF(reg,sip_registry_destroy); 04812 return 0; 04813 }
| 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 3076 of file chan_sip.c.
References ast_log(), AST_SCHED_DEL, ast_string_field_free_memory, sip_registry::call, sip_registry::expire, free, sip_registry::hostname, LOG_DEBUG, option_debug, sip_pvt::registry, sip_destroy(), sip_registry::timeout, and sip_registry::username.
Referenced by __sip_destroy(), handle_response_register(), reload_config(), sip_reg_timeout(), sip_register(), sip_reregister(), and unload_module().
03077 { 03078 /* Really delete */ 03079 if (option_debug > 2) 03080 ast_log(LOG_DEBUG, "Destroying registry entry for %s@%s\n", reg->username, reg->hostname); 03081 03082 if (reg->call) { 03083 /* Clear registry before destroying to ensure 03084 we don't get reentered trying to grab the registry lock */ 03085 reg->call->registry = NULL; 03086 if (option_debug > 2) 03087 ast_log(LOG_DEBUG, "Destroying active SIP dialog for registry %s@%s\n", reg->username, reg->hostname); 03088 sip_destroy(reg->call); 03089 } 03090 AST_SCHED_DEL(sched, reg->expire); 03091 AST_SCHED_DEL(sched, reg->timeout); 03092 ast_string_field_free_memory(reg); 03093 regobjs--; 03094 free(reg); 03095 03096 }
| 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 12242 of file chan_sip.c.
References ast_set_flag, sip_pvt::flags, SIP_NEEDREINVITE, and sip_pvt::waitid.
Referenced by handle_response_invite().
12243 { 12244 struct sip_pvt *p = (struct sip_pvt *) data; 12245 12246 ast_set_flag(&p->flags[0], SIP_NEEDREINVITE); 12247 p->waitid = -1; 12248 return 0; 12249 }
| static int sip_reload | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Force reload of module from cli.
Definition at line 18505 of file chan_sip.c.
References ast_mutex_lock(), ast_mutex_unlock(), ast_verbose(), CHANNEL_CLI_RELOAD, CHANNEL_MODULE_RELOAD, restart_monitor(), sip_reload_lock, and TRUE.
Referenced by reload().
18506 { 18507 ast_mutex_lock(&sip_reload_lock); 18508 if (sip_reloading) 18509 ast_verbose("Previous SIP reload not yet done\n"); 18510 else { 18511 sip_reloading = TRUE; 18512 if (fd) 18513 sip_reloadreason = CHANNEL_CLI_RELOAD; 18514 else 18515 sip_reloadreason = CHANNEL_MODULE_RELOAD; 18516 } 18517 ast_mutex_unlock(&sip_reload_lock); 18518 restart_monitor(); 18519 18520 return 0; 18521 }
| static struct ast_channel * sip_request_call | ( | const char * | type, | |
| int | format, | |||
| void * | data, | |||
| int * | cause | |||
| ) | [static, read] |
PBX interface function -build SIP pvt structure SIP calls initiated by the PBX arrive here.
Definition at line 16527 of file chan_sip.c.
References __ourip, ast_calloc, AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, AST_CAUSE_SWITCH_CONGESTION, AST_CAUSE_UNREGISTERED, ast_copy_string(), AST_FORMAT_MAX_AUDIO, ast_getformatname(), ast_getformatname_multiple(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_set_flag, ast_sip_ouraddrfor(), AST_STATE_DOWN, ast_string_field_free, ast_string_field_set, ast_strlen_zero(), ast_update_use_count(), build_callid_pvt(), build_via(), create_addr(), ext, sip_pvt::flags, sip_pvt::lock, LOG_DEBUG, LOG_ERROR, LOG_NOTICE, option_debug, sip_pvt::options, sip_pvt::ourip, sip_pvt::peername, sip_pvt::prefcodec, restart_monitor(), sip_pvt::sa, sip_alloc(), sip_destroy(), SIP_INVITE, sip_new(), SIP_PAGE2_OUTGOING_CALL, and username.
16528 { 16529 int oldformat; 16530 struct sip_pvt *p; 16531 struct ast_channel *tmpc = NULL; 16532 char *ext, *host; 16533 char tmp[256]; 16534 char *dest = data; 16535 16536 oldformat = format; 16537 if (!(format &= ((AST_FORMAT_MAX_AUDIO << 1) - 1))) { 16538 ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format %s while capability is %s\n", ast_getformatname(oldformat), ast_getformatname(global_capability)); 16539 *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL; /* Can't find codec to connect to host */ 16540 return NULL; 16541 } 16542 if (option_debug) 16543 ast_log(LOG_DEBUG, "Asked to create a SIP channel with formats: %s\n", ast_getformatname_multiple(tmp, sizeof(tmp), oldformat)); 16544 16545 if (!(p = sip_alloc(NULL, NULL, 0, SIP_INVITE))) { 16546 ast_log(LOG_ERROR, "Unable to build sip pvt data for '%s' (Out of memory or socket error)\n", (char *)data); 16547 *cause = AST_CAUSE_SWITCH_CONGESTION; 16548 return NULL; 16549 } 16550 16551 ast_set_flag(&p->flags[1], SIP_PAGE2_OUTGOING_CALL); 16552 16553 if (!(p->options = ast_calloc(1, sizeof(*p->options)))) { 16554 sip_destroy(p); 16555 ast_log(LOG_ERROR, "Unable to build option SIP data structure - Out of memory\n"); 16556 *cause = AST_CAUSE_SWITCH_CONGESTION; 16557 return NULL; 16558 } 16559 16560 ast_copy_string(tmp, dest, sizeof(tmp)); 16561 host = strchr(tmp, '@'); 16562 if (host) { 16563 *host++ = '\0'; 16564 ext = tmp; 16565 } else { 16566 ext = strchr(tmp, '/'); 16567 if (ext) 16568 *ext++ = '\0'; 16569 host = tmp; 16570 } 16571 16572 if (create_addr(p, host)) { 16573 *cause = AST_CAUSE_UNREGISTERED; 16574 if (option_debug > 2) 16575 ast_log(LOG_DEBUG, "Cant create SIP call - target device not registred\n"); 16576 sip_destroy(p); 16577 return NULL; 16578 } 16579 if (ast_strlen_zero(p->peername) && ext) 16580 ast_string_field_set(p, peername, ext); 16581 /* Recalculate our side, and recalculate Call ID */ 16582 if (ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip)) 16583 p->ourip = __ourip; 16584 build_via(p); 16585 build_callid_pvt(p); 16586 16587 /* We have an extension to call, don't use the full contact here */ 16588 /* This to enable dialing registered peers with extension dialling, 16589 like SIP/peername/extension 16590 SIP/peername will still use the full contact */ 16591 if (ext) { 16592 ast_string_field_set(p, username, ext); 16593 ast_string_field_free(p, fullcontact); 16594 } 16595 #if 0 16596 printf("Setting up to call extension '%s' at '%s'\n", ext ? ext : "<none>", host); 16597 #endif 16598 p->prefcodec = oldformat; /* Format for this call */ 16599 ast_mutex_lock(&p->lock); 16600 tmpc = sip_new(p, AST_STATE_DOWN, host); /* Place the call */ 16601 ast_mutex_unlock(&p->lock); 16602 if (!tmpc) 16603 sip_destroy(p); 16604 ast_update_use_count(); 16605 restart_monitor(); 16606 return tmpc; 16607 }
| static int sip_reregister | ( | const void * | data | ) | [static] |
Update registration with SIP Proxy.
Definition at line 7552 of file chan_sip.c.
References __sip_do_register(), append_history, ast_log(), ast_test_flag, ASTOBJ_REF, ASTOBJ_UNREF, sip_registry::call, sip_registry::expire, sip_pvt::flags, sip_registry::hostname, LOG_NOTICE, SIP_NO_HISTORY, sip_registry_destroy(), sipdebug, and sip_registry::username.
Referenced by handle_response_register(), and sip_send_all_registers().
07553 { 07554 /* if we are here, we know that we need to reregister. */ 07555 struct sip_registry *r= ASTOBJ_REF((struct sip_registry *) data); 07556 07557 /* if we couldn't get a reference to the registry object, punt */ 07558 if (!r) 07559 return 0; 07560 07561 if (r->call && !ast_test_flag(&r->call->flags[0], SIP_NO_HISTORY)) 07562 append_history(r->call, "RegistryRenew", "Account: %s@%s", r->username, r->hostname); 07563 /* Since registry's are only added/removed by the the monitor thread, this 07564 may be overkill to reference/dereference at all here */ 07565 if (sipdebug) 07566 ast_log(LOG_NOTICE, " -- Re-registration for %s@%s\n", r->username, r->hostname); 07567 07568 r->expire = -1; 07569 __sip_do_register(r); 07570 ASTOBJ_UNREF(r, sip_registry_destroy); 07571 return 0; 07572 }
| 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 4333 of file chan_sip.c.
References ast_dsp_process(), AST_FORMAT_AUDIO_MASK, AST_FORMAT_VIDEO_MASK, AST_FRAME_DTMF, AST_FRAME_VOICE, ast_getformatname(), ast_log(), ast_null_frame, ast_rtcp_read(), ast_rtp_read(), ast_set_read_format(), ast_set_write_format(), ast_test_flag, ast_udptl_read(), f, ast_channel::fdno, sip_pvt::flags, ast_frame::frametype, sip_pvt::jointcapability, LOG_DEBUG, ast_channel::name, ast_channel::nativeformats, option_debug, sip_pvt::owner, ast_channel::readformat, sip_pvt::rtp, SIP_DTMF, SIP_DTMF_INBAND, SIP_DTMF_RFC2833, SIP_PAGE2_T38SUPPORT_UDPTL, ast_frame::subclass, sip_pvt::t38, t38properties::t38support, sip_pvt::udptl, sip_pvt::vad, sip_pvt::vrtp, and ast_channel::writeformat.
Referenced by sip_read().
04334 { 04335 /* Retrieve audio/etc from channel. Assumes p->lock is already held. */ 04336 struct ast_frame *f; 04337 04338 if (!p->rtp) { 04339 /* We have no RTP allocated for this channel */ 04340 return &ast_null_frame; 04341 } 04342 04343 switch(ast->fdno) { 04344 case 0: 04345 f = ast_rtp_read(p->rtp); /* RTP Audio */ 04346 break; 04347 case 1: 04348 f = ast_rtcp_read(p->rtp); /* RTCP Control Channel */ 04349 break; 04350 case 2: 04351 f = ast_rtp_read(p->vrtp); /* RTP Video */ 04352 break; 04353 case 3: 04354 f = ast_rtcp_read(p->vrtp); /* RTCP Control Channel for video */ 04355 break; 04356 case 5: 04357 f = ast_udptl_read(p->udptl); /* UDPTL for T.38 */ 04358 break; 04359 default: 04360 f = &ast_null_frame; 04361 } 04362 /* Don't forward RFC2833 if we're not supposed to */ 04363 if (f && (f->frametype == AST_FRAME_DTMF) && 04364 (ast_test_flag(&p->flags[0], SIP_DTMF) != SIP_DTMF_RFC2833)) 04365 return &ast_null_frame; 04366 04367 /* We already hold the channel lock */ 04368 if (!p->owner || (f && f->frametype != AST_FRAME_VOICE)) 04369 return f; 04370 04371 if (f && f->subclass != (p->owner->nativeformats & AST_FORMAT_AUDIO_MASK)) { 04372 if (!(f->subclass & p->jointcapability)) { 04373 if (option_debug) { 04374 ast_log(LOG_DEBUG, "Bogus frame of format '%s' received from '%s'!\n", 04375 ast_getformatname(f->subclass), p->owner->name); 04376 } 04377 return &ast_null_frame; 04378 } 04379 if (option_debug) 04380 ast_log(LOG_DEBUG, "Oooh, format changed to %d\n", f->subclass); 04381 p->owner->nativeformats = (p->owner->nativeformats & AST_FORMAT_VIDEO_MASK) | f->subclass; 04382 ast_set_read_format(p->owner, p->owner->readformat); 04383 ast_set_write_format(p->owner, p->owner->writeformat); 04384 } 04385 04386 if (f && (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_INBAND) && p->vad) { 04387 f = ast_dsp_process(p->owner, p->vad, f); 04388 if (f && f->frametype == AST_FRAME_DTMF) { 04389 if (ast_test_flag(&p->t38.t38support, SIP_PAGE2_T38SUPPORT_UDPTL) && f->subclass == 'f') { 04390 if (option_debug) 04391 ast_log(LOG_DEBUG, "Fax CNG detected on %s\n", ast->name); 04392 *faxdetect = 1; 04393 } else if (option_debug) { 04394 ast_log(LOG_DEBUG, "* Detected inband DTMF '%c'\n", f->subclass); 04395 } 04396 } 04397 } 04398 04399 return f; 04400 }
| static void sip_scheddestroy | ( | struct sip_pvt * | p, | |
| int | ms | |||
| ) | [static] |
Schedule destruction of SIP dialog.
Definition at line 2133 of file chan_sip.c.
References __sip_autodestruct(), append_history, ast_sched_add(), AST_SCHED_DEL, ast_test_flag, ast_verbose(), sip_pvt::autokillid, sip_pvt::callid, sip_pvt::flags, sip_pvt::method, sip_debug_test_pvt(), sip_methods, SIP_NO_HISTORY, cfsip_methods::text, and sip_pvt::timer_t1.
Referenced by __sip_autodestruct(), cb_extensionstate(), check_auth(), check_pendings(), handle_invite_replaces(), handle_request(), handle_request_bye(), handle_request_cancel(), handle_request_info(), handle_request_invite(), handle_request_notify(), handle_request_options(), handle_request_register(), handle_request_subscribe(), handle_response_invite(), handle_response_register(), receive_message(), sip_hangup(), sip_notify(), sip_send_mwi_to_peer(), and sip_sipredirect().
02134 { 02135 if (ms < 0) { 02136 if (p->timer_t1 == 0) 02137 p->timer_t1 = 500; /* Set timer T1 if not set (RFC 3261) */ 02138 ms = p->timer_t1 * 64; 02139 } 02140 if (sip_debug_test_pvt(p)) 02141 ast_verbose("Scheduling destruction of SIP dialog '%s' in %d ms (Method: %s)\n", p->callid, ms, sip_methods[p->method].text); 02142 if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) 02143 append_history(p, "SchedDestroy", "%d ms", ms); 02144 02145 AST_SCHED_DEL(sched, p->autokillid); 02146 p->autokillid = ast_sched_add(sched, ms, __sip_autodestruct, p); 02147 }
| static void sip_send_all_registers | ( | void | ) | [static] |
Send all known registrations.
Definition at line 18462 of file chan_sip.c.
References ast_sched_add(), AST_SCHED_DEL, ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_UNLOCK, ASTOBJ_WRLOCK, regl, and sip_reregister().
Referenced by load_module(), and sip_do_reload().
18463 { 18464 int ms; 18465 int regspacing; 18466 if (!regobjs) 18467 return; 18468 regspacing = default_expiry * 1000/regobjs; 18469 if (regspacing > 100) 18470 regspacing = 100; 18471 ms = regspacing; 18472 ASTOBJ_CONTAINER_TRAVERSE(®l, 1, do { 18473 ASTOBJ_WRLOCK(iterator); 18474 AST_SCHED_DEL(sched, iterator->expire); 18475 ms += regspacing; 18476 iterator->expire = ast_sched_add(sched, ms, sip_reregister, iterator); 18477 ASTOBJ_UNLOCK(iterator); 18478 } while (0) 18479 ); 18480 }
| static int sip_send_mwi_to_peer | ( | struct sip_peer * | peer | ) | [static] |
Send message waiting indication to alert peer that they've got voicemail.
Definition at line 16038 of file chan_sip.c.
References __ourip, sip_peer::addr, ast_app_inboxcount(), ast_set_flag, ast_sip_ouraddrfor(), build_callid_pvt(), build_via(), create_addr_from_peer(), sip_peer::defaddr, DEFAULT_TRANS_TIMEOUT, sip_pvt::flags, sip_peer::lastmsgcheck, sip_peer::lastmsgssent, sip_peer::mailbox, sip_peer::mwipvt, sip_pvt::ourip, sip_pvt::sa, sip_alloc(), sip_destroy(), SIP_NOTIFY, SIP_OUTGOING, sip_scheddestroy(), transmit_notify_with_mwi(), and sip_peer::vmexten.
Referenced by do_monitor(), and handle_request_subscribe().
16039 { 16040 /* Called with peerl lock, but releases it */ 16041 struct sip_pvt *p; 16042 int newmsgs, oldmsgs; 16043 16044 /* Do we have an IP address? If not, skip this peer */ 16045 if (!peer->addr.sin_addr.s_addr && !peer->defaddr.sin_addr.s_addr) 16046 return 0; 16047 16048 /* Check for messages */ 16049 ast_app_inboxcount(peer->mailbox, &newmsgs, &oldmsgs); 16050 16051 peer->lastmsgcheck = time(NULL); 16052 16053 /* Return now if it's the same thing we told them last time */ 16054 if (((newmsgs > 0x7fff ? 0x7fff0000 : (newmsgs << 16)) | (oldmsgs > 0xffff ? 0xffff : oldmsgs)) == peer->lastmsgssent) { 16055 return 0; 16056 } 16057 16058 16059 peer->lastmsgssent = ((newmsgs > 0x7fff ? 0x7fff0000 : (newmsgs << 16)) | (oldmsgs > 0xffff ? 0xffff : oldmsgs)); 16060 16061 if (peer->mwipvt) { 16062 /* Base message on subscription */ 16063 p = peer->mwipvt; 16064 } else { 16065 /* Build temporary dialog for this message */ 16066 if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY))) 16067 return -1; 16068 if (create_addr_from_peer(p, peer)) { 16069 /* Maybe they're not registered, etc. */ 16070 sip_destroy(p); 16071 return 0; 16072 } 16073 /* Recalculate our side, and recalculate Call ID */ 16074 if (ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip)) 16075 p->ourip = __ourip; 16076 build_via(p); 16077 build_callid_pvt(p); 16078 /* Destroy this session after 32 secs */ 16079 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 16080 } 16081 /* Send MWI */ 16082 ast_set_flag(&p->flags[0], SIP_OUTGOING); 16083 transmit_notify_with_mwi(p, newmsgs, oldmsgs, peer->vmexten); 16084 return 0; 16085 }
| static int sip_senddigit_begin | ( | struct ast_channel * | ast, | |
| char | digit | |||
| ) | [static] |
Definition at line 3862 of file chan_sip.c.
References ast_mutex_lock(), ast_mutex_unlock(), ast_rtp_senddigit_begin(), ast_test_flag, sip_pvt::flags, sip_pvt::lock, sip_pvt::rtp, SIP_DTMF, SIP_DTMF_INBAND, SIP_DTMF_RFC2833, and ast_channel::tech_pvt.
03863 { 03864 struct sip_pvt *p = ast->tech_pvt; 03865 int res = 0; 03866 03867 ast_mutex_lock(&p->lock); 03868 switch (ast_test_flag(&p->flags[0], SIP_DTMF)) { 03869 case SIP_DTMF_INBAND: 03870 res = -1; /* Tell Asterisk to generate inband indications */ 03871 break; 03872 case SIP_DTMF_RFC2833: 03873 if (p->rtp) 03874 ast_rtp_senddigit_begin(p->rtp, digit); 03875 break; 03876 default: 03877 break; 03878 } 03879 ast_mutex_unlock(&p->lock); 03880 03881 return res; 03882 }
| 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 3886 of file chan_sip.c.
References ast_mutex_lock(), ast_mutex_unlock(), ast_rtp_senddigit_end(), ast_test_flag, sip_pvt::flags, sip_pvt::lock, sip_pvt::rtp, SIP_DTMF, SIP_DTMF_INBAND, SIP_DTMF_INFO, SIP_DTMF_RFC2833, ast_channel::tech_pvt, and transmit_info_with_digit().
03887 { 03888 struct sip_pvt *p = ast->tech_pvt; 03889 int res = 0; 03890 03891 ast_mutex_lock(&p->lock); 03892 switch (ast_test_flag(&p->flags[0], SIP_DTMF)) { 03893 case SIP_DTMF_INFO: 03894 transmit_info_with_digit(p, digit, duration); 03895 break; 03896 case SIP_DTMF_RFC2833: 03897 if (p->rtp) 03898 ast_rtp_senddigit_end(p->rtp, digit); 03899 break; 03900 case SIP_DTMF_INBAND: 03901 res = -1; /* Tell Asterisk to stop inband indications */ 03902 break; 03903 } 03904 ast_mutex_unlock(&p->lock); 03905 03906 return res; 03907 }
| static int sip_sendtext | ( | struct ast_channel * | ast, | |
| const char * | text | |||
| ) | [static] |
Send SIP MESSAGE text within a call Called from PBX core sendtext() application.
Definition at line 2393 of file chan_sip.c.
References ast_strlen_zero(), ast_verbose(), debug, ast_channel::name, sip_debug_test_pvt(), ast_channel::tech_pvt, and transmit_message_with_text().
02394 { 02395 struct sip_pvt *p = ast->tech_pvt; 02396 int debug = sip_debug_test_pvt(p); 02397 02398 if (debug) 02399 ast_verbose("Sending text %s on %s\n", text, ast->name); 02400 if (!p) 02401 return -1; 02402 if (ast_strlen_zero(text)) 02403 return 0; 02404 if (debug) 02405 ast_verbose("Really sending text %s on %s\n", text, ast->name); 02406 transmit_message_with_text(p, text); 02407 return 0; 02408 }
| static int sip_set_rtp_peer | ( | struct ast_channel * | chan, | |
| struct ast_rtp * | rtp, | |||
| struct ast_rtp * | vrtp, | |||
| int | codecs, | |||
| int | nat_active | |||
| ) | [static] |
Set the RTP peer for this call.
Definition at line 18188 of file chan_sip.c.
References ast_channel::_state, append_history, ast_inet_ntoa(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_rtp_get_peer(), ast_set_flag, AST_STATE_UP, ast_test_flag, sip_pvt::callid, sip_pvt::capability, sip_pvt::flags, sip_pvt::jointcapability, sip_pvt::lastrtprx, sip_pvt::lastrtptx, sip_pvt::lock, LOG_DEBUG, option_debug, sip_pvt::ourip, sip_pvt::pendinginvite, sip_pvt::redircodecs, sip_pvt::redirip, SIP_ALREADYGONE, SIP_CAN_REINVITE_NAT, SIP_DEFER_BYE_ON_TRANSFER, SIP_GOTREFER, SIP_NEEDREINVITE, SIP_NO_HISTORY, SIP_PENDINGBYE, ast_channel::tech_pvt, transmit_reinvite_with_sdp(), and sip_pvt::vredirip.
Referenced by sip_fixup().
18189 { 18190 struct sip_pvt *p; 18191 int changed = 0; 18192 18193 p = chan->tech_pvt; 18194 if (!p) 18195 return -1; 18196 18197 /* Disable early RTP bridge */ 18198 if (chan->_state != AST_STATE_UP && !global_directrtpsetup) /* We are in early state */ 18199 return 0; 18200 18201 ast_mutex_lock(&p->lock); 18202 if (ast_test_flag(&p->flags[0], SIP_ALREADYGONE)) { 18203 /* If we're destroyed, don't bother */ 18204 ast_mutex_unlock(&p->lock); 18205 return 0; 18206 } 18207 18208 /* if this peer cannot handle reinvites of the media stream to devices 18209 that are known to be behind a NAT, then stop the process now 18210 */ 18211 if (nat_active && !ast_test_flag(&p->flags[0], SIP_CAN_REINVITE_NAT)) { 18212 ast_mutex_unlock(&p->lock); 18213 return 0; 18214 } 18215 18216 if (rtp) { 18217 changed |= ast_rtp_get_peer(rtp, &p->redirip); 18218 } else if (p->redirip.sin_addr.s_addr || ntohs(p->redirip.sin_port) != 0) { 18219 memset(&p->redirip, 0, sizeof(p->redirip)); 18220 changed = 1; 18221 } 18222 if (vrtp) { 18223 changed |= ast_rtp_get_peer(vrtp, &p->vredirip); 18224 } else if (p->vredirip.sin_addr.s_addr || ntohs(p->vredirip.sin_port) != 0) { 18225 memset(&p->vredirip, 0, sizeof(p->vredirip)); 18226 changed = 1; 18227 } 18228 if (codecs) { 18229 if ((p->redircodecs != codecs)) { 18230 p->redircodecs = codecs; 18231 changed = 1; 18232 } 18233 if ((p->capability & codecs) != p->capability) { 18234 p->jointcapability &= codecs; 18235 p->capability &= codecs; 18236 changed = 1; 18237 } 18238 } 18239 if (changed && !ast_test_flag(&p->flags[0], SIP_GOTREFER) && !ast_test_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER)) { 18240 if (chan->_state != AST_STATE_UP) { /* We are in early state */ 18241 if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) 18242 append_history(p, "ExtInv", "Initial invite sent with remote bridge proposal."); 18243 if (option_debug) 18244 ast_log(LOG_DEBUG, "Early remote bridge setting SIP '%s' - Sending media to %s\n", p->callid, ast_inet_ntoa(rtp ? p->redirip.sin_addr : p->ourip)); 18245 } else if (!p->pendinginvite) { /* We are up, and have no outstanding invite */ 18246 if (option_debug > 2) { 18247 ast_log(LOG_DEBUG, "Sending reinvite on SIP '%s' - It's audio soon redirected to IP %s\n", p->callid, ast_inet_ntoa(rtp ? p->redirip.sin_addr : p->ourip)); 18248 } 18249 transmit_reinvite_with_sdp(p); 18250 } else if (!ast_test_flag(&p->flags[0], SIP_PENDINGBYE)) { 18251 if (option_debug > 2) { 18252 ast_log(LOG_DEBUG, "Deferring reinvite on SIP '%s' - It's audio will be redirected to IP %s\n", p->callid, ast_inet_ntoa(rtp ? p->redirip.sin_addr : p->ourip)); 18253 } 18254 /* We have a pending Invite. Send re-invite when we're done with the invite */ 18255 ast_set_flag(&p->flags[0], SIP_NEEDREINVITE); 18256 } 18257 } 18258 /* Reset lastrtprx timer */ 18259 p->lastrtprx = p->lastrtptx = time(NULL); 18260 ast_mutex_unlock(&p->lock); 18261 return 0; 18262 }
| static int sip_set_udptl_peer | ( | struct ast_channel * | chan, | |
| struct ast_udptl * | udptl | |||
| ) | [static] |
Definition at line 18015 of file chan_sip.c.
References ast_inet_ntoa(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_set_flag, ast_test_flag, ast_udptl_get_peer(), sip_pvt::callid, sip_pvt::flags, sip_pvt::lastrtprx, sip_pvt::lastrtptx, sip_pvt::lock, LOG_DEBUG, option_debug, sip_pvt::ourip, sip_pvt::pendinginvite, SIP_GOTREFER, SIP_NEEDREINVITE, SIP_PENDINGBYE, ast_channel::tech_pvt, transmit_reinvite_with_t38_sdp(), and sip_pvt::udptlredirip.
18016 { 18017 struct sip_pvt *p; 18018 18019 p = chan->tech_pvt; 18020 if (!p) 18021 return -1; 18022 ast_mutex_lock(&p->lock); 18023 if (udptl) 18024 ast_udptl_get_peer(udptl, &p->udptlredirip); 18025 else 18026 memset(&p->udptlredirip, 0, sizeof(p->udptlredirip)); 18027 if (!ast_test_flag(&p->flags[0], SIP_GOTREFER)) { 18028 if (!p->pendinginvite) { 18029 if (option_debug > 2) { 18030 ast_log(LOG_DEBUG, "Sending reinvite on SIP '%s' - It's UDPTL soon redirected to IP %s:%d\n", p->callid, ast_inet_ntoa(udptl ? p->udptlredirip.sin_addr : p->ourip), udptl ? ntohs(p->udptlredirip.sin_port) : 0); 18031 } 18032 transmit_reinvite_with_t38_sdp(p); 18033 } else if (!ast_test_flag(&p->flags[0], SIP_PENDINGBYE)) { 18034 if (option_debug > 2) { 18035 ast_log(LOG_DEBUG, "Deferring reinvite on SIP '%s' - It's UDPTL will be redirected to IP %s:%d\n", p->callid, ast_inet_ntoa(udptl ? p->udptlredirip.sin_addr : p->ourip), udptl ? ntohs(p->udptlredirip.sin_port) : 0); 18036 } 18037 ast_set_flag(&p->flags[0], SIP_NEEDREINVITE); 18038 } 18039 } 18040 /* Reset lastrtprx timer */ 18041 p->lastrtprx = p->lastrtptx = time(NULL); 18042 ast_mutex_unlock(&p->lock); 18043 return 0; 18044 }
| static int sip_show_channel | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Show details of one active dialog.
Definition at line 11175 of file chan_sip.c.
References sip_pvt::allowtransfer, ast_cli(), ast_getformatname_multiple(), ast_inet_ntoa(), ast_mutex_lock(), ast_mutex_unlock(), ast_strlen_zero(), ast_test_flag, sip_pvt::callid, sip_pvt::capability, sip_pvt::cid_num, dtmfmode2str(), sip_pvt::flags, sip_route::hop, cfsip_options::id, iflist, iflock, sip_pvt::jointcapability, sip_pvt::lastmsg, len(), sip_pvt::maxcallbitrate, ast_channel::name, nat2str(), ast_channel::nativeformats, sip_pvt::next, sip_pvt::noncodeccapability, NONE, sip_pvt::ourip, sip_pvt::owner, sip_pvt::peercapability, sip_pvt::peername, sip_pvt::recv, sip_pvt::redirip, RESULT_SHOWUSAGE, RESULT_SUCCESS, sip_pvt::route, sip_pvt::sa, SIP_DTMF, SIP_NAT, SIP_NEEDDESTROY, sip_options, SIP_OUTGOING, SIP_PROMISCREDIR, SIPBUFSIZE, sip_pvt::sipoptions, sip_pvt::subscribed, subscription_type2str(), sip_pvt::tag, text, sip_pvt::theirtag, transfermode2str(), sip_pvt::uri, sip_pvt::useragent, and sip_pvt::username.
11176 { 11177 struct sip_pvt *cur; 11178 size_t len; 11179 int found = 0; 11180 11181 if (argc != 4) 11182 return RESULT_SHOWUSAGE; 11183 len = strlen(argv[3]); 11184 ast_mutex_lock(&iflock); 11185 for (cur = iflist; cur; cur = cur->next) { 11186 if (!strncasecmp(cur->callid, argv[3], len)) { 11187 char formatbuf[SIPBUFSIZE/2]; 11188 ast_cli(fd,"\n"); 11189 if (cur->subscribed != NONE) 11190 ast_cli(fd, " * Subscription (type: %s)\n", subscription_type2str(cur->subscribed)); 11191 else 11192 ast_cli(fd, " * SIP Call\n"); 11193 ast_cli(fd, " Curr. trans. direction: %s\n", ast_test_flag(&cur->flags[0], SIP_OUTGOING) ? "Outgoing" : "Incoming"); 11194 ast_cli(fd, " Call-ID: %s\n", cur->callid); 11195 ast_cli(fd, " Owner channel ID: %s\n", cur->owner ? cur->owner->name : "<none>"); 11196 ast_cli(fd, " Our Codec Capability: %d\n", cur->capability); 11197 ast_cli(fd, " Non-Codec Capability (DTMF): %d\n", cur->noncodeccapability); 11198 ast_cli(fd, " Their Codec Capability: %d\n", cur->peercapability); 11199 ast_cli(fd, " Joint Codec Capability: %d\n", cur->jointcapability); 11200 ast_cli(fd, " Format: %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->owner ? cur->owner->nativeformats : 0) ); 11201 ast_cli(fd, " MaxCallBR: %d kbps\n", cur->maxcallbitrate); 11202 ast_cli(fd, " Theoretical Address: %s:%d\n", ast_inet_ntoa(cur->sa.sin_addr), ntohs(cur->sa.sin_port)); 11203 ast_cli(fd, " Received Address: %s:%d\n", ast_inet_ntoa(cur->recv.sin_addr), ntohs(cur->recv.sin_port)); 11204 ast_cli(fd, " SIP Transfer mode: %s\n", transfermode2str(cur->allowtransfer)); 11205 ast_cli(fd, " NAT Support: %s\n", nat2str(ast_test_flag(&cur->flags[0], SIP_NAT))); 11206 ast_cli(fd, " Audio IP: %s %s\n", ast_inet_ntoa(cur->redirip.sin_addr.s_addr ? cur->redirip.sin_addr : cur->ourip), cur->redirip.sin_addr.s_addr ? "(Outside bridge)" : "(local)" ); 11207 ast_cli(fd, " Our Tag: %s\n", cur->tag); 11208 ast_cli(fd, " Their Tag: %s\n", cur->theirtag); 11209 ast_cli(fd, " SIP User agent: %s\n", cur->useragent); 11210 if (!ast_strlen_zero(cur->username)) 11211 ast_cli(fd, " Username: %s\n", cur->username); 11212 if (!ast_strlen_zero(cur->peername)) 11213 ast_cli(fd, " Peername: %s\n", cur->peername); 11214 if (!ast_strlen_zero(cur->uri)) 11215 ast_cli(fd, " Original uri: %s\n", cur->uri); 11216 if (!ast_strlen_zero(cur->cid_num)) 11217 ast_cli(fd, " Caller-ID: %s\n", cur->cid_num); 11218 ast_cli(fd, " Need Destroy: %d\n", ast_test_flag(&cur->flags[0], SIP_NEEDDESTROY)); 11219 ast_cli(fd, " Last Message: %s\n", cur->lastmsg); 11220 ast_cli(fd, " Promiscuous Redir: %s\n", ast_test_flag(&cur->flags[0], SIP_PROMISCREDIR) ? "Yes" : "No"); 11221 ast_cli(fd, " Route: %s\n", cur->route ? cur->route->hop : "N/A"); 11222 ast_cli(fd, " DTMF Mode: %s\n", dtmfmode2str(ast_test_flag(&cur->flags[0], SIP_DTMF))); 11223 ast_cli(fd, " SIP Options: "); 11224 if (cur->sipoptions) { 11225 int x; 11226 for (x=0 ; (x < (sizeof(sip_options) / sizeof(sip_options[0]))); x++) { 11227 if (cur->sipoptions & sip_options[x].id) 11228 ast_cli(fd, "%s ", sip_options[x].text); 11229 } 11230 } else 11231 ast_cli(fd, "(none)\n"); 11232 ast_cli(fd, "\n\n"); 11233 found++; 11234 } 11235 } 11236 ast_mutex_unlock(&iflock); 11237 if (!found) 11238 ast_cli(fd, "No such SIP Call ID starting with '%s'\n", argv[3]); 11239 return RESULT_SUCCESS; 11240 }
| static int sip_show_channels | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Show active SIP channels.
Definition at line 10968 of file chan_sip.c.
References __sip_show_channels().
10969 { 10970 return __sip_show_channels(fd, argc, argv, 0); 10971 }
| static int sip_show_domains | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
CLI command to list local domains.
Definition at line 10474 of file chan_sip.c.
References ast_cli(), AST_LIST_EMPTY, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, domain::context, domain::domain, domain_mode_to_text(), FORMAT, domain::mode, RESULT_SUCCESS, and S_OR.
10475 { 10476 struct domain *d; 10477 #define FORMAT "%-40.40s %-20.20s %-16.16s\n" 10478 10479 if (AST_LIST_EMPTY(&domain_list)) { 10480 ast_cli(fd, "SIP Domain support not enabled.\n\n"); 10481 return RESULT_SUCCESS; 10482 } else { 10483 ast_cli(fd, FORMAT, "Our local SIP domains:", "Context", "Set by"); 10484 AST_LIST_LOCK(&domain_list); 10485 AST_LIST_TRAVERSE(&domain_list, d, list) 10486 ast_cli(fd, FORMAT, d->domain, S_OR(d->context, "(default)"), 10487 domain_mode_to_text(d->mode)); 10488 AST_LIST_UNLOCK(&domain_list); 10489 ast_cli(fd, "\n"); 10490 return RESULT_SUCCESS; 10491 } 10492 }
| static int sip_show_history | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Show history details of one dialog.
Definition at line 11243 of file chan_sip.c.
References ast_cli(), AST_LIST_TRAVERSE, ast_mutex_lock(), ast_mutex_unlock(), sip_pvt::callid, sip_history::event, sip_pvt::history, iflist, iflock, len(), sip_pvt::next, NONE, RESULT_SHOWUSAGE, RESULT_SUCCESS, and sip_pvt::subscribed.
11244 { 11245 struct sip_pvt *cur; 11246 size_t len; 11247 int found = 0; 11248 11249 if (argc != 4) 11250 return RESULT_SHOWUSAGE; 11251 if (!recordhistory) 11252 ast_cli(fd, "\n***Note: History recording is currently DISABLED. Use 'sip history' to ENABLE.\n"); 11253 len = strlen(argv[3]); 11254 ast_mutex_lock(&iflock); 11255 for (cur = iflist; cur; cur = cur->next) { 11256 if (!strncasecmp(cur->callid, argv[3], len)) { 11257 struct sip_history *hist; 11258 int x = 0; 11259 11260 ast_cli(fd,"\n"); 11261 if (cur->subscribed != NONE) 11262 ast_cli(fd, " * Subscription\n"); 11263 else 11264 ast_cli(fd, " * SIP Call\n"); 11265 if (cur->history) 11266 AST_LIST_TRAVERSE(cur->history, hist, list) 11267 ast_cli(fd, "%d. %s\n", ++x, hist->event); 11268 if (x == 0) 11269 ast_cli(fd, "Call '%s' has no history\n", cur->callid); 11270 found++; 11271 } 11272 } 11273 ast_mutex_unlock(&iflock); 11274 if (!found) 11275 ast_cli(fd, "No such SIP Call ID starting with '%s'\n", argv[3]); 11276 return RESULT_SUCCESS; 11277 }
| static int sip_show_inuse | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
CLI Command to show calls within limits set by call_limit.
Definition at line 9899 of file chan_sip.c.
References ast_cli(), ast_copy_string(), ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_RDLOCK, ASTOBJ_UNLOCK, FALSE, FORMAT, FORMAT2, peerl, RESULT_SHOWUSAGE, RESULT_SUCCESS, TRUE, and userl.
09900 { 09901 #define FORMAT "%-25.25s %-15.15s %-15.15s \n" 09902 #define FORMAT2 "%-25.25s %-15.15s %-15.15s \n" 09903 char ilimits[40]; 09904 char iused[40]; 09905 int showall = FALSE; 09906 09907 if (argc < 3) 09908 return RESULT_SHOWUSAGE; 09909 09910 if (argc == 4 && !strcmp(argv[3],"all")) 09911 showall = TRUE; 09912 09913 ast_cli(fd, FORMAT, "* User name", "In use", "Limit"); 09914 ASTOBJ_CONTAINER_TRAVERSE(&userl, 1, do { 09915 ASTOBJ_RDLOCK(iterator); 09916 if (iterator->call_limit) 09917 snprintf(ilimits, sizeof(ilimits), "%d", iterator->call_limit); 09918 else 09919 ast_copy_string(ilimits, "N/A", sizeof(ilimits)); 09920 snprintf(iused, sizeof(iused), "%d", iterator->inUse); 09921 if (showall || iterator->call_limit) 09922 ast_cli(fd, FORMAT2, iterator->name, iused, ilimits); 09923 ASTOBJ_UNLOCK(iterator); 09924 } while (0) ); 09925 09926 ast_cli(fd, FORMAT, "* Peer name", "In use", "Limit"); 09927 09928 ASTOBJ_CONTAINER_TRAVERSE(&peerl, 1, do { 09929 ASTOBJ_RDLOCK(iterator); 09930 if (iterator->call_limit) 09931 snprintf(ilimits, sizeof(ilimits), "%d", iterator->call_limit); 09932 else 09933 ast_copy_string(ilimits, "N/A", sizeof(ilimits)); 09934 snprintf(iused, sizeof(iused), "%d/%d", iterator->inUse, iterator->inRinging); 09935 if (showall || iterator->call_limit) 09936 ast_cli(fd, FORMAT2, iterator->name, iused, ilimits); 09937 ASTOBJ_UNLOCK(iterator); 09938 } while (0) ); 09939 09940 return RESULT_SUCCESS; 09941 #undef FORMAT 09942 #undef FORMAT2 09943 }
| static int sip_show_objects | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
List all allocated SIP Objects (realtime or static).
Definition at line 10220 of file chan_sip.c.
References ast_cli(), ASTOBJ_CONTAINER_DUMP, peerl, regl, RESULT_SHOWUSAGE, RESULT_SUCCESS, and userl.
10221 { 10222 char tmp[256]; 10223 if (argc != 3) 10224 return RESULT_SHOWUSAGE; 10225 ast_cli(fd, "-= User objects: %d static, %d realtime =-\n\n", suserobjs, ruserobjs); 10226 ASTOBJ_CONTAINER_DUMP(fd, tmp, sizeof(tmp), &userl); 10227 ast_cli(fd, "-= Peer objects: %d static, %d realtime, %d autocreate =-\n\n", speerobjs, rpeerobjs, apeerobjs); 10228 ASTOBJ_CONTAINER_DUMP(fd, tmp, sizeof(tmp), &peerl); 10229 ast_cli(fd, "-= Registry objects: %d =-\n\n", regobjs); 10230 ASTOBJ_CONTAINER_DUMP(fd, tmp, sizeof(tmp), ®l); 10231 return RESULT_SUCCESS; 10232 }
| static int sip_show_peer | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Show one peer in detail.
Definition at line 10526 of file chan_sip.c.
References _sip_show_peer().
10527 { 10528 return _sip_show_peer(0, fd, NULL, NULL, argc, (const char **) argv); 10529 }
| static int sip_show_peers | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
CLI Show Peers command.
Definition at line 10076 of file chan_sip.c.
References _sip_show_peers().
10077 { 10078 return _sip_show_peers(fd, NULL, NULL, NULL, argc, (const char **) argv); 10079 }
| static int sip_show_registry | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Show SIP Registry (registrations with other SIP proxies.
Definition at line 10799 of file chan_sip.c.
References ast_cli(), ast_localtime(), ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_RDLOCK, ASTOBJ_UNLOCK, FORMAT, FORMAT2, regl, regstate2str(), RESULT_SHOWUSAGE, RESULT_SUCCESS, and STANDARD_SIP_PORT.
10800 { 10801 #define FORMAT2 "%-30.30s %-12.12s %8.8s %-20.20s %-25.25s\n" 10802 #define FORMAT "%-30.30s %-12.12s %8d %-20.20s %-25.25s\n" 10803 char host[80]; 10804 char tmpdat[256]; 10805 struct tm tm; 10806 10807 10808 if (argc != 3) 10809 return RESULT_SHOWUSAGE; 10810 ast_cli(fd, FORMAT2, "Host", "Username", "Refresh", "State", "Reg.Time"); 10811 ASTOBJ_CONTAINER_TRAVERSE(®l, 1, do { 10812 ASTOBJ_RDLOCK(iterator); 10813 snprintf(host, sizeof(host), "%s:%d", iterator->hostname, iterator->portno ? iterator->portno : STANDARD_SIP_PORT); 10814 if (iterator->regtime) { 10815 ast_localtime(&iterator->regtime, &tm, NULL); 10816 strftime(tmpdat, sizeof(tmpdat), "%a, %d %b %Y %T", &tm); 10817 } else { 10818 tmpdat[0] = 0; 10819 } 10820 ast_cli(fd, FORMAT, host, iterator->username, iterator->refresh, regstate2str(iterator->regstate), tmpdat); 10821 ASTOBJ_UNLOCK(iterator); 10822 } while(0)); 10823 return RESULT_SUCCESS; 10824 #undef FORMAT 10825 #undef FORMAT2 10826 }
| static int sip_show_settings | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
List global settings for the SIP channel.
Definition at line 10829 of file chan_sip.c.
References ast_check_realtime(), ast_cli(), ast_getformatname_multiple(), ast_inet_ntoa(), AST_JB_ENABLED, AST_JB_FORCED, AST_JB_LOG, AST_LIST_EMPTY, ast_test_flag, ast_tos2str(), default_prefs, dtmfmode2str(), global_jbconf, ast_jb_conf::impl, ast_jb_conf::max_size, nat2str(), print_codec_to_cli(), RESULT_SHOWUSAGE, RESULT_SUCCESS, ast_jb_conf::resync_threshold, S_OR, SIP_DTMF, SIP_NAT, SIP_PAGE2_ALLOWOVERLAP, SIP_PAGE2_ALLOWSUBSCRIBE, SIP_PAGE2_IGNOREREGEXPIRE, SIP_PAGE2_RFC2833_COMPENSATE, SIP_PAGE2_RTCACHEFRIENDS, SIP_PAGE2_RTSAVE_SYSNAME, SIP_PAGE2_RTUPDATE, SIP_PAGE2_T38SUPPORT_RTP, SIP_PAGE2_T38SUPPORT_TCP, SIP_PAGE2_T38SUPPORT_UDPTL, SIP_PAGE2_VIDEOSUPPORT, SIP_PROG_INBAND, SIP_PROG_INBAND_NEVER, SIP_PROG_INBAND_NO, SIP_PROMISCREDIR, SIP_USECLIENTCODE, SIP_USEREQPHONE, SIPBUFSIZE, and transfermode2str().
10830 { 10831 int realtimepeers; 10832 int realtimeusers; 10833 char codec_buf[SIPBUFSIZE]; 10834 10835 realtimepeers = ast_check_realtime("sippeers"); 10836 realtimeusers = ast_check_realtime("sipusers"); 10837 10838 if (argc != 3) 10839 return RESULT_SHOWUSAGE; 10840 ast_cli(fd, "\n\nGlobal Settings:\n"); 10841 ast_cli(fd, "----------------\n"); 10842 ast_cli(fd, " SIP Port: %d\n", ntohs(bindaddr.sin_port)); 10843 ast_cli(fd, " Bindaddress: %s\n", ast_inet_ntoa(bindaddr.sin_addr)); 10844 ast_cli(fd, " Videosupport: %s\n", ast_test_flag(&global_flags[1], SIP_PAGE2_VIDEOSUPPORT) ? "Yes" : "No"); 10845 ast_cli(fd, " AutoCreatePeer: %s\n", autocreatepeer ? "Yes" : "No"); 10846 ast_cli(fd, " Allow unknown access: %s\n", global_allowguest ? "Yes" : "No"); 10847 ast_cli(fd, " Allow subscriptions: %s\n", ast_test_flag(&global_flags[1], SIP_PAGE2_ALLOWSUBSCRIBE) ? "Yes" : "No"); 10848 ast_cli(fd, " Allow overlap dialing: %s\n", ast_test_flag(&global_flags[1], SIP_PAGE2_ALLOWOVERLAP) ? "Yes" : "No"); 10849 ast_cli(fd, " Promsic. redir: %s\n", ast_test_flag(&global_flags[0], SIP_PROMISCREDIR) ? "Yes" : "No"); 10850 ast_cli(fd, " SIP domain support: %s\n", AST_LIST_EMPTY(&domain_list) ? "No" : "Yes"); 10851 ast_cli(fd, " Call to non-local dom.: %s\n", allow_external_domains ? "Yes" : "No"); 10852 ast_cli(fd, " URI user is phone no: %s\n", ast_test_flag(&global_flags[0], SIP_USEREQPHONE) ? "Yes" : "No"); 10853 ast_cli(fd, " Our auth realm %s\n", global_realm); 10854 ast_cli(fd, " Realm. auth: %s\n", authl ? "Yes": "No"); 10855 ast_cli(fd, " Always auth rejects: %s\n", global_alwaysauthreject ? "Yes" : "No"); 10856 ast_cli(fd, " Call limit peers only: %s\n", global_limitonpeers ? "Yes" : "No"); 10857 ast_cli(fd, " Direct RTP setup: %s\n", global_directrtpsetup ? "Yes" : "No"); 10858 ast_cli(fd, " User Agent: %s\n", global_useragent); 10859 ast_cli(fd, " MWI checking interval: %d secs\n", global_mwitime); 10860 ast_cli(fd, " Reg. context: %s\n", S_OR(global_regcontext, "(not set)")); 10861 ast_cli(fd, " Caller ID: %s\n", default_callerid); 10862 ast_cli(fd, " From: Domain: %s\n", default_fromdomain); 10863 ast_cli(fd, " Record SIP history: %s\n", recordhistory ? "On" : "Off"); 10864 ast_cli(fd, " Call Events: %s\n", global_callevents ? "On" : "Off"); 10865 ast_cli(fd, " IP ToS SIP: %s\n", ast_tos2str(global_tos_sip)); 10866 ast_cli(fd, " IP ToS RTP audio: %s\n", ast_tos2str(global_tos_audio)); 10867 ast_cli(fd, " IP ToS RTP video: %s\n", ast_tos2str(global_tos_video)); 10868 ast_cli(fd, " T38 fax pt UDPTL: %s\n", ast_test_flag(&global_flags[1], SIP_PAGE2_T38SUPPORT_UDPTL) ? "Yes" : "No"); 10869 #ifdef WHEN_WE_HAVE_T38_FOR_OTHER_TRANSPORTS 10870 ast_cli(fd, " T38 fax pt RTP: %s\n", ast_test_flag(&global_flags[1], SIP_PAGE2_T38SUPPORT_RTP) ? "Yes" : "No"); 10871 ast_cli(fd, " T38 fax pt TCP: %s\n", ast_test_flag(&global_flags[1], SIP_PAGE2_T38SUPPORT_TCP) ? "Yes" : "No"); 10872 #endif 10873 ast_cli(fd, " RFC2833 Compensation: %s\n", ast_test_flag(&global_flags[1], SIP_PAGE2_RFC2833_COMPENSATE) ? "Yes" : "No"); 10874 ast_cli(fd, " Jitterbuffer enabled: %s\n", ast_test_flag(&global_jbconf, AST_JB_ENABLED) ? "Yes" : "No"); 10875 ast_cli(fd, " Jitterbuffer forced: %s\n", ast_test_flag(&global_jbconf, AST_JB_FORCED) ? "Yes" : "No"); 10876 ast_cli(fd, " Jitterbuffer max size: %ld\n", global_jbconf.max_size); 10877 ast_cli(fd, " Jitterbuffer resync: %ld\n", global_jbconf.resync_threshold); 10878 ast_cli(fd, " Jitterbuffer impl: %s\n", global_jbconf.impl); 10879 ast_cli(fd, " Jitterbuffer log: %s\n", ast_test_flag(&global_jbconf, AST_JB_LOG) ? "Yes" : "No"); 10880 if (!realtimepeers && !realtimeusers) 10881 ast_cli(fd, " SIP realtime: Disabled\n" ); 10882 else 10883 ast_cli(fd, " SIP realtime: Enabled\n" ); 10884 10885 ast_cli(fd, "\nGlobal Signalling Settings:\n"); 10886 ast_cli(fd, "---------------------------\n"); 10887 ast_cli(fd, " Codecs: "); 10888 ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, global_capability); 10889 ast_cli(fd, "%s\n", codec_buf); 10890 ast_cli(fd, " Codec Order: "); 10891 print_codec_to_cli(fd, &default_prefs); 10892 ast_cli(fd, "\n"); 10893 ast_cli(fd, " T1 minimum: %d\n", global_t1min); 10894 ast_cli(fd, " Relax DTMF: %s\n", global_relaxdtmf ? "Yes" : "No"); 10895 ast_cli(fd, " Compact SIP headers: %s\n", compactheaders ? "Yes" : "No"); 10896 ast_cli(fd, " RTP Keepalive: %d %s\n", global_rtpkeepalive, global_rtpkeepalive ? "" : "(Disabled)" ); 10897 ast_cli(fd, " RTP Timeout: %d %s\n", global_rtptimeout, global_rtptimeout ? "" : "(Disabled)" ); 10898 ast_cli(fd, " RTP Hold Timeout: %d %s\n", global_rtpholdtimeout, global_rtpholdtimeout ? "" : "(Disabled)"); 10899 ast_cli(fd, " MWI NOTIFY mime type: %s\n", default_notifymime); 10900 ast_cli(fd, " DNS SRV lookup: %s\n", srvlookup ? "Yes" : "No"); 10901 ast_cli(fd, " Pedantic SIP support: %s\n", pedanticsipchecking ? "Yes" : "No"); 10902 ast_cli(fd, " Reg. min duration %d secs\n", min_expiry); 10903 ast_cli(fd, " Reg. max duration: %d secs\n", max_expiry); 10904 ast_cli(fd, " Reg. default duration: %d secs\n", default_expiry); 10905 ast_cli(fd, " Outbound reg. timeout: %d secs\n", global_reg_timeout); 10906 ast_cli(fd, " Outbound reg. attempts: %d\n", global_regattempts_max); 10907 ast_cli(fd, " Notify ringing state: %s\n", global_notifyringing ? "Yes" : "No"); 10908 ast_cli(fd, " Notify hold state: %s\n", global_notifyhold ? "Yes" : "No"); 10909 ast_cli(fd, " SIP Transfer mode: %s\n", transfermode2str(global_allowtransfer)); 10910 ast_cli(fd, " Max Call Bitrate: %d kbps\r\n", default_maxcallbitrate); 10911 ast_cli(fd, " Auto-Framing: %s \r\n", global_autoframing ? "Yes" : "No"); 10912 ast_cli(fd, "\nDefault Settings:\n"); 10913 ast_cli(fd, "-----------------\n"); 10914 ast_cli(fd, " Context: %s\n", default_context); 10915 ast_cli(fd, " Nat: %s\n", nat2str(ast_test_flag(&global_flags[0], SIP_NAT))); 10916 ast_cli(fd, " DTMF: %s\n", dtmfmode2str(ast_test_flag(&global_flags[0], SIP_DTMF))); 10917 ast_cli(fd, " Qualify: %d\n", default_qualify); 10918 ast_cli(fd, " Use ClientCode: %s\n", ast_test_flag(&global_flags[0], SIP_USECLIENTCODE) ? "Yes" : "No"); 10919 ast_cli(fd, " Progress inband: %s\n", (ast_test_flag(&global_flags[0], SIP_PROG_INBAND) == SIP_PROG_INBAND_NEVER) ? "Never" : (ast_test_flag(&global_flags[0], SIP_PROG_INBAND) == SIP_PROG_INBAND_NO) ? "No" : "Yes" ); 10920 ast_cli(fd, " Language: %s\n", S_OR(default_language, "(Defaults to English)")); 10921 ast_cli(fd, " MOH Interpret: %s\n", default_mohinterpret); 10922 ast_cli(fd, " MOH Suggest: %s\n", default_mohsuggest); 10923 ast_cli(fd, " Voice Mail Extension: %s\n", default_vmexten); 10924 10925 10926 if (realtimepeers || realtimeusers) { 10927 ast_cli(fd, "\nRealtime SIP Settings:\n"); 10928 ast_cli(fd, "----------------------\n"); 10929 ast_cli(fd, " Realtime Peers: %s\n", realtimepeers ? "Yes" : "No"); 10930 ast_cli(fd, " Realtime Users: %s\n", realtimeusers ? "Yes" : "No"); 10931 ast_cli(fd, " Cache Friends: %s\n", ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS) ? "Yes" : "No"); 10932 ast_cli(fd, " Update: %s\n", ast_test_flag(&global_flags[1], SIP_PAGE2_RTUPDATE) ? "Yes" : "No"); 10933 ast_cli(fd, " Ignore Reg. Expire: %s\n", ast_test_flag(&global_flags[1], SIP_PAGE2_IGNOREREGEXPIRE) ? "Yes" : "No"); 10934 ast_cli(fd, " Save sys. name: %s\n", ast_test_flag(&global_flags[1], SIP_PAGE2_RTSAVE_SYSNAME) ? "Yes" : "No"); 10935 ast_cli(fd, " Auto Clear: %d\n", global_rtautoclear); 10936 } 10937 ast_cli(fd, "\n----\n"); 10938 return RESULT_SUCCESS; 10939 }
| static int sip_show_subscriptions | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Show active SIP subscriptions.
Definition at line 10974 of file chan_sip.c.
References __sip_show_channels().
10975 { 10976 return __sip_show_channels(fd, argc, argv, 1); 10977 }
| static int sip_show_user | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
Show one user in detail.
Definition at line 10744 of file chan_sip.c.
References sip_user::accountcode, sip_user::allowtransfer, sip_user::amaflags, ast_callerid_merge(), ast_cdr_flags2str(), ast_cli(), ast_describe_caller_presentation(), ast_strlen_zero(), ASTOBJ_UNREF, sip_user::autoframing, sip_user::call_limit, sip_user::callgroup, sip_user::callingpres, sip_user::chanvars, sip_user::cid_name, sip_user::cid_num, sip_user::context, FALSE, find_user(), sip_user::ha, sip_user::language, sip_user::maxcallbitrate, sip_user::md5secret, ast_variable::name, sip_user::name, ast_variable::next, sip_user::pickupgroup, sip_user::prefs, print_codec_to_cli(), print_group(), RESULT_SHOWUSAGE, RESULT_SUCCESS, sip_user::secret, sip_destroy_user(), transfermode2str(), TRUE, and ast_variable::value.
10745 { 10746 char cbuf[256]; 10747 struct sip_user *user; 10748 struct ast_variable *v; 10749 int load_realtime; 10750 10751 if (argc < 4) 10752 return RESULT_SHOWUSAGE; 10753 10754 /* Load from realtime storage? */ 10755 load_realtime = (argc == 5 && !strcmp(argv[4], "load")) ? TRUE : FALSE; 10756 10757 user = find_user(argv[3], load_realtime); 10758 if (user) { 10759 ast_cli(fd,"\n\n"); 10760 ast_cli(fd, " * Name : %s\n", user->name); 10761 ast_cli(fd, " Secret : %s\n", ast_strlen_zero(user->secret)?"<Not set>":"<Set>"); 10762 ast_cli(fd, " MD5Secret : %s\n", ast_strlen_zero(user->md5secret)?"<Not set>":"<Set>"); 10763 ast_cli(fd, " Context : %s\n", user->context); 10764 ast_cli(fd, " Language : %s\n", user->language); 10765 if (!ast_strlen_zero(user->accountcode)) 10766 ast_cli(fd, " Accountcode : %s\n", user->accountcode); 10767 ast_cli(fd, " AMA flags : %s\n", ast_cdr_flags2str(user->amaflags)); 10768 ast_cli(fd, " Transfer mode: %s\n", transfermode2str(user->allowtransfer)); 10769 ast_cli(fd, " MaxCallBR : %d kbps\n", user->maxcallbitrate); 10770 ast_cli(fd, " CallingPres : %s\n", ast_describe_caller_presentation(user->callingpres)); 10771 ast_cli(fd, " Call limit : %d\n", user->call_limit); 10772 ast_cli(fd, " Callgroup : "); 10773 print_group(fd, user->callgroup, 0); 10774 ast_cli(fd, " Pickupgroup : "); 10775 print_group(fd, user->pickupgroup, 0); 10776 ast_cli(fd, " Callerid : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), user->cid_name, user->cid_num, "<unspecified>")); 10777 ast_cli(fd, " ACL : %s\n", (user->ha?"Yes":"No")); 10778 ast_cli(fd, " Codec Order : ("); 10779 print_codec_to_cli(fd, &user->prefs); 10780 ast_cli(fd, ")\n"); 10781 10782 ast_cli(fd, " Auto-Framing: %s \n", user->autoframing ? "Yes" : "No"); 10783 if (user->chanvars) { 10784 ast_cli(fd, " Variables :\n"); 10785 for (v = user->chanvars ; v ; v = v->next) 10786 ast_cli(fd, " %s = %s\n", v->name, v->value); 10787 } 10788 ast_cli(fd,"\n"); 10789 ASTOBJ_UNREF(user,sip_destroy_user); 10790 } else { 10791 ast_cli(fd,"User %s not found.\n", argv[3]); 10792 ast_cli(fd,"\n"); 10793 } 10794 10795 return RESULT_SUCCESS; 10796 }
| static int sip_show_users | ( | int | fd, | |
| int | argc, | |||
| char * | argv[] | |||
| ) | [static] |
CLI Command 'SIP Show Users'.
Definition at line 9999 of file chan_sip.c.
References ast_cli(), ast_test_flag, ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_RDLOCK, ASTOBJ_UNLOCK, FALSE, FORMAT, nat2str(), RESULT_SHOWUSAGE, RESULT_SUCCESS, SIP_NAT, TRUE, and userl.
10000 { 10001 regex_t regexbuf; 10002 int havepattern = FALSE; 10003 10004 #define FORMAT "%-25.25s %-15.15s %-15.15s %-15.15s %-5.5s%-10.10s\n" 10005 10006 switch (argc) { 10007 case 5: 10008 if (!strcasecmp(argv[3], "like")) { 10009 if (regcomp(®exbuf, argv[4], REG_EXTENDED | REG_NOSUB)) 10010 return RESULT_SHOWUSAGE; 10011 havepattern = TRUE; 10012 } else 10013 return RESULT_SHOWUSAGE; 10014 case 3: 10015 break; 10016 default: 10017 return RESULT_SHOWUSAGE; 10018 } 10019 10020 ast_cli(fd, FORMAT, "Username", "Secret", "Accountcode", "Def.Context", "ACL", "NAT"); 10021 ASTOBJ_CONTAINER_TRAVERSE(&userl, 1, do { 10022 ASTOBJ_RDLOCK(iterator); 10023 10024 if (havepattern && regexec(®exbuf, iterator->name, 0, NULL, 0)) { 10025 ASTOBJ_UNLOCK(iterator); 10026 continue; 10027 } 10028 10029 ast_cli(fd, FORMAT, iterator->name, 10030 iterator->secret, 10031 iterator->accountcode, 10032 iterator->context, 10033 iterator->ha ? "Yes" : "No", 10034 nat2str(ast_test_flag(&iterator->flags[0], SIP_NAT))); 10035 ASTOBJ_UNLOCK(iterator); 10036 } while (0) 10037 ); 10038 10039 if (havepattern) 10040 regfree(®exbuf); 10041 10042 return RESULT_SUCCESS; 10043 #undef FORMAT 10044 }
| static int sip_sipredirect | ( | struct sip_pvt * | p, | |
| const char * | dest | |||
| ) | [static] |
Transfer call before connect with a 302 redirect.
Definition at line 18375 of file chan_sip.c.
References ast_copy_string(), ast_log(), ast_strdupa, ast_string_field_build, ast_strlen_zero(), get_header(), sip_pvt::initreq, LOG_ERROR, sip_pvt::our_contact, sip_alreadygone(), sip_scheddestroy(), SIP_TRANS_TIMEOUT, and transmit_response_reliable().
Referenced by sip_transfer().
18376 { 18377 char *cdest; 18378 char *extension, *host, *port; 18379 char tmp[80]; 18380 18381 cdest = ast_strdupa(dest); 18382 18383 extension = strsep(&cdest, "@"); 18384 host = strsep(&cdest, ":"); 18385 port = strsep(&cdest, ":"); 18386 if (ast_strlen_zero(extension)) { 18387 ast_log(LOG_ERROR, "Missing mandatory argument: extension\n"); 18388 return 0; 18389 } 18390 18391 /* we'll issue the redirect message here */ 18392 if (!host) { 18393 char *localtmp; 18394 ast_copy_string(tmp, get_header(&p->initreq, "To"), sizeof(tmp)); 18395 if (ast_strlen_zero(tmp)) { 18396 ast_log(LOG_ERROR, "Cannot retrieve the 'To' header from the original SIP request!\n"); 18397 return 0; 18398 } 18399 if ((localtmp = strcasestr(tmp, "sip:")) && (localtmp = strchr(localtmp, '@'))) { 18400 char lhost[80], lport[80]; 18401 memset(lhost, 0, sizeof(lhost)); 18402 memset(lport, 0, sizeof(lport)); 18403 localtmp++; 18404 /* This is okey because lhost and lport are as big as tmp */ 18405 sscanf(localtmp, "%[^<>:; ]:%[^<>:; ]", lhost, lport); 18406 if (ast_strlen_zero(lhost)) { 18407 ast_log(LOG_ERROR, "Can't find the host address\n"); 18408 return 0; 18409 } 18410 host = ast_strdupa(lhost); 18411 if (!ast_strlen_zero(lport)) { 18412 port = ast_strdupa(lport); 18413 } 18414 } 18415 } 18416 18417 sip_alreadygone(p); 18418 ast_string_field_build(p, our_contact, "Transfer <sip:%s@%s%s%s>", extension, host, port ? ":" : "", port ? port : ""); 18419 transmit_response_reliable(p, "302 Moved Temporarily", &p->initreq); 18420 18421 sip_scheddestroy(p, SIP_TRANS_TIMEOUT); /* Make sure we stop send this reply. */ 18422 sip_alreadygone(p); 18423 return 0; 18424 }
| static int sip_transfer | ( | struct ast_channel * | ast, | |
| const char * | dest | |||
| ) | [static] |
Transfer SIP call.
Definition at line 3910 of file chan_sip.c.
References ast_channel::_state, ast_mutex_lock(), ast_mutex_unlock(), AST_STATE_RING, sip_pvt::lock, sip_sipredirect(), ast_channel::tech_pvt, and transmit_refer().
03911 { 03912 struct sip_pvt *p = ast->tech_pvt; 03913 int res; 03914 03915 if (dest == NULL) /* functions below do not take a NULL */ 03916 dest = ""; 03917 ast_mutex_lock(&p->lock); 03918 if (ast->_state == AST_STATE_RING) 03919 res = sip_sipredirect(p, dest); 03920 else 03921 res = transmit_refer(p, dest); 03922 ast_mutex_unlock(&p->lock); 03923 return res; 03924 }
| static int sip_uri_cmp | ( | const char * | input1, | |
| const char * | input2 | |||
| ) | [static] |
Definition at line 14061 of file chan_sip.c.
References ast_strdupa, S_OR, sip_uri_headers_cmp(), and sip_uri_params_cmp().
Referenced by handle_request_invite().
14062 { 14063 char *uri1 = ast_strdupa(input1); 14064 char *uri2 = ast_strdupa(input2); 14065 char *host1; 14066 char *host2; 14067 char *params1; 14068 char *params2; 14069 char *headers1; 14070 char *headers2; 14071 14072 /* Strip off "sip:" from the URI. We know this is present 14073 * because it was checked back in parse_request() 14074 */ 14075 strsep(&uri1, ":"); 14076 strsep(&uri2, ":"); 14077 14078 if ((host1 = strchr(uri1, '@'))) { 14079 *host1++ = '\0'; 14080 } 14081 if ((host2 = strchr(uri2, '@'))) { 14082 *host2++ = '\0'; 14083 } 14084 14085 /* Check for mismatched username and passwords. This is the 14086 * only case-sensitive comparison of a SIP URI 14087 */ 14088 if ((host1 && !host2) || 14089 (host2 && !host1) || 14090 (host1 && host2 && strcmp(uri1, uri2))) { 14091 return 1; 14092 } 14093 14094 if (!host1) 14095 host1 = uri1; 14096 if (!host2) 14097 host2 = uri2; 14098 14099 /* Strip off the parameters and headers so we can compare 14100 * host and port 14101 */ 14102 14103 if ((params1 = strchr(host1, ';'))) { 14104 *params1++ = '\0'; 14105 } 14106 if ((params2 = strchr(host2, ';'))) { 14107 *params2++ = '\0'; 14108 } 14109 14110 /* Headers come after parameters, but there may be headers without 14111 * parameters, thus the S_OR 14112 */ 14113 if ((headers1 = strchr(S_OR(params1, host1), '?'))) { 14114 *headers1++ = '\0'; 14115 } 14116 if ((headers2 = strchr(S_OR(params2, host2), '?'))) { 14117 *headers2++ = '\0'; 14118 } 14119 14120 /* Now the host/port are properly isolated. We can get by with a string comparison 14121 * because the SIP URI checking rules have some interesting exceptions that make 14122 * this possible. I will note 2 in particular 14123 * 1. hostnames which resolve to the same IP address as well as a hostname and its 14124 * IP address are not considered a match with SIP URI's. 14125 * 2. If one URI specifies a port and the other does not, then the URIs do not match. 14126 * This includes if one URI explicitly contains port 5060 and the other implies it 14127 * by not having a port specified. 14128 */ 14129 14130 if (strcasecmp(host1, host2)) { 14131 return 1; 14132 } 14133 14134 /* Headers have easier rules to follow, so do those first */ 14135 if (sip_uri_headers_cmp(headers1, headers2)) { 14136 return 1; 14137 } 14138 14139 /* And now the parameters. Ugh */ 14140 return sip_uri_params_cmp(params1, params2); 14141 }
| static int sip_uri_headers_cmp | ( | const char * | input1, | |
| const char * | input2 | |||
| ) | [static] |
helper routine for sip_uri_cmp
This takes the "headers" from two SIP URIs and determines if the URIs match. The rules for headers is simple. If a header appears in one URI, then it must also appear in the other URI. The order in which the headers appear does not matter.
| input1 | Headers from URI 1 | |
| input2 | Headers from URI 2 |
Definition at line 14027 of file chan_sip.c.
References ast_strdupa, and ast_strlen_zero().
Referenced by sip_uri_cmp().
14028 { 14029 char *headers1 = ast_strdupa(input1); 14030 char *headers2 = ast_strdupa(input2); 14031 int zerolength1 = ast_strlen_zero(headers1); 14032 int zerolength2 = ast_strlen_zero(headers2); 14033 int different = 0; 14034 char *header1; 14035 14036 if ((zerolength1 && !zerolength2) || 14037 (zerolength2 && !zerolength1)) 14038 return 1; 14039 14040 if (zerolength1 && zerolength2) 14041 return 0; 14042 14043 /* At this point, we can definitively state that both inputs are 14044 * not zero-length. First, one more optimization. If the length 14045 * of the headers is not equal, then we definitely have no match 14046 */ 14047 if (strlen(headers1) != strlen(headers2)) { 14048 return 1; 14049 } 14050 14051 for (header1 = strsep(&headers1, "&"); header1; header1 = strsep(&headers1, "&")) { 14052 if (!strcasestr(headers2, header1)) { 14053 different = 1; 14054 break; 14055 } 14056 } 14057 14058 return different; 14059 }
| static int sip_uri_params_cmp | ( | const char * | input1, | |
| const char * | input2 | |||
| ) | [static] |
helper routine for sip_uri_cmp
This takes the parameters from two SIP URIs and determines if the URIs match. The rules for parameters *suck*. Here's a breakdown 1. If a parameter appears in both URIs, then they must have the same value in order for the URIs to match 2. If one URI has a user, maddr, ttl, or method parameter, then the other URI must also have that parameter and must have the same value in order for the URIs to match 3. All other headers appearing in only one URI are not considered when determining if URIs match
| input1 | Parameters from URI 1 | |
| input2 | Parameters from URI 2 |
Definition at line 13900 of file chan_sip.c.
References ast_strdupa, and ast_strlen_zero().
Referenced by sip_uri_cmp().
13901 { 13902 char *params1 = ast_strdupa(input1); 13903 char *params2 = ast_strdupa(input2); 13904 char *pos1; 13905 char *pos2; 13906 int maddrmatch = 0; 13907 int ttlmatch = 0; 13908 int usermatch = 0; 13909 int methodmatch = 0; 13910 13911 /*Quick optimization. If both params are zero-length, then 13912 * they match 13913 */ 13914 if (ast_strlen_zero(params1) && ast_strlen_zero(params2)) { 13915 return 0; 13916 } 13917 13918 pos1 = params1; 13919 while (!ast_strlen_zero(pos1)) { 13920 char *name1 = pos1; 13921 char *value1 = strchr(pos1, '='); 13922 char *semicolon1 = strchr(pos1, ';'); 13923 int matched = 0; 13924 if (semicolon1) { 13925 *semicolon1++ = '\0'; 13926 } 13927 if (!value1) { 13928 goto fail; 13929 } 13930 *value1++ = '\0'; 13931 /* Checkpoint reached. We have the name and value parsed for param1 13932 * We have to duplicate params2 each time through the second loop 13933 * or else we can't search and replace the semicolons with \0 each 13934 * time 13935 */ 13936 pos2 = ast_strdupa(params2); 13937 while (!ast_strlen_zero(pos2)) { 13938 char *name2 = pos2; 13939 char *value2 = strchr(pos2, '='); 13940 char *semicolon2 = strchr(pos2, ';'); 13941 if (semicolon2) { 13942 *semicolon2++ = '\0'; 13943 } 13944 if (!value2) { 13945 goto fail; 13946 } 13947 *value2++ = '\0'; 13948 if (!strcasecmp(name1, name2)) { 13949 if (strcasecmp(value1, value2)) { 13950 goto fail; 13951 } else { 13952 matched = 1; 13953 break; 13954 } 13955 } 13956 pos2 = semicolon2; 13957 } 13958 /* Need to see if the parameter we're looking at is one of the 'must-match' parameters */ 13959 if (!strcasecmp(name1, "maddr")) { 13960 if (matched) { 13961 maddrmatch = 1; 13962 } else { 13963 goto fail; 13964 } 13965 } else if (!strcasecmp(name1, "ttl")) { 13966 if (matched) { 13967 ttlmatch = 1; 13968 } else { 13969 goto fail; 13970 } 13971 } else if (!strcasecmp(name1, "user")) { 13972 if (matched) { 13973 usermatch = 1; 13974 } else { 13975 goto fail; 13976 } 13977 } else if (!strcasecmp(name1, "method")) { 13978 if (matched) { 13979 methodmatch = 1; 13980 } else { 13981 goto fail; 13982 } 13983 } 13984 pos1 = semicolon1; 13985 } 13986 13987 /* We've made it out of that horrible O(m*n) construct and there are no 13988 * failures yet. We're not done yet, though, because params2 could have 13989 * an maddr, ttl, user, or method header and params1 did not. 13990 */ 13991 pos2 = params2; 13992 while (!ast_strlen_zero(pos2)) { 13993 char *name2 = pos2; 13994 char *value2 = strchr(pos2, '='); 13995 char *semicolon2 = strchr(pos2, ';'); 13996 if (semicolon2) { 13997 *semicolon2++ = '\0'; 13998 } 13999 if (!value2) { 14000 goto fail; 14001 } 14002 *value2++ = '\0'; 14003 if ((!strcasecmp(name2, "maddr") && !maddrmatch) || 14004 (!strcasecmp(name2, "ttl") && !ttlmatch) || 14005 (!strcasecmp(name2, "user") && !usermatch) || 14006 (!strcasecmp(name2, "method") && !methodmatch)) { 14007 goto fail; 14008 } 14009 } 14010 return 0; 14011 14012 fail: 14013 return 1; 14014 }
| static int sip_write | ( | struct ast_channel * | ast, | |
| struct ast_frame * | frame | |||
| ) | [static] |
Send frame to media channel (rtp).
Definition at line 3733 of file chan_sip.c.
References ast_channel::_state, ast_backtrace(), AST_FORMAT_AUDIO_MASK, ast_frame_dump(), AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_getformatname_multiple(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_rtp_new_source(), ast_rtp_write(), ast_set_flag, AST_STATE_UP, ast_test_flag, ast_udptl_write(), sip_pvt::flags, ast_frame::frametype, sip_pvt::initreq, INV_EARLY_MEDIA, sip_pvt::invitestate, sip_pvt::lastrtptx, sip_pvt::lock, LOG_WARNING, ast_channel::name, ast_channel::nativeformats, ast_channel::readformat, sip_pvt::rtp, SIP_OUTGOING, SIP_PROGRESS_SENT, ast_frame::subclass, ast_channel::tech_pvt, transmit_response_with_sdp(), sip_pvt::udptl, sip_pvt::vrtp, ast_channel::writeformat, and XMIT_UNRELIABLE.
03734 { 03735 struct sip_pvt *p = ast->tech_pvt; 03736 int res = 0; 03737 03738 switch (frame->frametype) { 03739 case AST_FRAME_VOICE: 03740 if (!(frame->subclass & ast->nativeformats)) { 03741 char s1[512], s2[512], s3[512]; 03742 ast_log(LOG_WARNING, "Asked to transmit frame type %d, while native formats is %s(%d) read/write = %s(%d)/%s(%d)\n", 03743 frame->subclass, 03744 ast_getformatname_multiple(s1, sizeof(s1) - 1, ast->nativeformats & AST_FORMAT_AUDIO_MASK), 03745 ast->nativeformats & AST_FORMAT_AUDIO_MASK, 03746 ast_getformatname_multiple(s2, sizeof(s2) - 1, ast->readformat), 03747 ast->readformat, 03748 ast_getformatname_multiple(s3, sizeof(s3) - 1, ast->writeformat), 03749 ast->writeformat); 03750 ast_frame_dump(ast->name, frame, "<<"); 03751 ast_backtrace(); 03752 return 0; 03753 } 03754 if (p) { 03755 ast_mutex_lock(&p->lock); 03756 if (p->rtp) { 03757 /* If channel is not up, activate early media session */ 03758 if ((ast->_state != AST_STATE_UP) && 03759 !ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT) && 03760 !ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 03761 ast_rtp_new_source(p->rtp); 03762 p->invitestate = INV_EARLY_MEDIA; 03763 transmit_response_with_sdp(p, "183 Session Progress", &p->initreq, XMIT_UNRELIABLE); 03764 ast_set_flag(&p->flags[0], SIP_PROGRESS_SENT); 03765 } 03766 p->lastrtptx = time(NULL); 03767 res = ast_rtp_write(p->rtp, frame); 03768 } 03769 ast_mutex_unlock(&p->lock); 03770 } 03771 break; 03772 case AST_FRAME_VIDEO: 03773 if (p) { 03774 ast_mutex_lock(&p->lock); 03775 if (p->vrtp) { 03776 /* Activate video early media */ 03777 if ((ast->_state != AST_STATE_UP) && 03778 !ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT) && 03779 !ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 03780 p->invitestate = INV_EARLY_MEDIA; 03781 transmit_response_with_sdp(p, "183 Session Progress", &p->initreq, XMIT_UNRELIABLE); 03782 ast_set_flag(&p->flags[0], SIP_PROGRESS_SENT); 03783 } 03784 p->lastrtptx = time(NULL); 03785 res = ast_rtp_write(p->vrtp, frame); 03786 } 03787 ast_mutex_unlock(&p->lock); 03788 } 03789 break; 03790 case AST_FRAME_IMAGE: 03791 return 0; 03792 break; 03793 case AST_FRAME_MODEM: 03794 if (p) { 03795 ast_mutex_lock(&p->lock); 03796 /* UDPTL requires two-way communication, so early media is not needed here. 03797 we simply forget the frames if we get modem frames before the bridge is up. 03798 Fax will re-transmit. 03799 */ 03800 if (p->udptl && ast->_state == AST_STATE_UP) 03801 res = ast_udptl_write(p->udptl, frame); 03802 ast_mutex_unlock(&p->lock); 03803 } 03804 break; 03805 default: 03806 ast_log(LOG_WARNING, "Can't send %d type frames with SIP write\n", frame->frametype); 03807 return 0; 03808 } 03809 03810 return res; 03811 }
| static int sipsock_read | ( | int * | id, | |
| int | fd, | |||
| short | events, | |||
| void * | ignore | |||
| ) | [static] |
Read data from SIP socket.
Definition at line 15925 of file chan_sip.c.
References append_history, ast_channel_trylock, ast_channel_unlock, ast_inet_ntoa(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_set_flag, ast_test_flag, ast_update_use_count(), ast_verbose(), sip_pvt::callid, sip_request::data, errno, find_call(), find_sip_method(), sip_pvt::flags, get_header(), handle_request(), sip_request::headers, sip_request::len, len(), sip_request::lines, sip_pvt::lock, LOG_DEBUG, LOG_ERROR, LOG_NOTICE, LOG_WARNING, lws2sws(), sip_request::method, ast_channel::name, netlock, option_debug, sip_pvt::owner, parse_request(), sip_pvt::recv, sip_request::rlPart1, sip_request::rlPart2, S_OR, SIP_ACK, sip_debug_test_addr(), SIP_NO_HISTORY, SIP_PKT_DEBUG, and transmit_response().
Referenced by do_monitor().
15926 { 15927 struct sip_request req; 15928 struct sockaddr_in sin = { 0, }; 15929 struct sip_pvt *p; 15930 int res; 15931 socklen_t len = sizeof(sin); 15932 int nounlock; 15933 int recount = 0; 15934 int lockretry; 15935 15936 memset(&req, 0, sizeof(req)); 15937 res = recvfrom(sipsock, req.data, sizeof(req.data) - 1, 0, (struct sockaddr *)&sin, &len); 15938 if (res < 0) { 15939 #if !defined(__FreeBSD__) 15940 if (errno == EAGAIN) 15941 ast_log(LOG_NOTICE, "SIP: Received packet with bad UDP checksum\n"); 15942 else 15943 #endif 15944 if (errno != ECONNREFUSED) 15945 ast_log(LOG_WARNING, "Recv error: %s\n", strerror(errno)); 15946 return 1; 15947 } 15948 if (option_debug && res == sizeof(req.data) - 1) 15949 ast_log(LOG_DEBUG, "Received packet exceeds buffer. Data is possibly lost\n"); 15950 15951 req.data[res] = '\0'; 15952 req.len = res; 15953 if(sip_debug_test_addr(&sin)) /* Set the debug flag early on packet level */ 15954 ast_set_flag(&req, SIP_PKT_DEBUG); 15955 if (pedanticsipchecking) 15956 req.len = lws2sws(req.data, req.len); /* Fix multiline headers */ 15957 if (ast_test_flag(&req, SIP_PKT_DEBUG)) 15958 ast_verbose("\n<--- SIP read from %s:%d --->\n%s\n<------------->\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), req.data); 15959 15960 if(parse_request(&req) == -1) /* Bad packet, can't parse */ 15961 return 1; 15962 15963 req.method = find_sip_method(req.rlPart1); 15964 15965 if (ast_test_flag(&req, SIP_PKT_DEBUG)) 15966 ast_verbose("--- (%d headers %d lines)%s ---\n", req.headers, req.lines, (req.headers + req.lines == 0) ? " Nat keepalive" : ""); 15967 15968 if (req.headers < 2) /* Must have at least two headers */ 15969 return 1; 15970 15971 /* Process request, with netlock held, and with usual deadlock avoidance */ 15972 for (lockretry = 100; lockretry > 0; lockretry--) { 15973 ast_mutex_lock(&netlock); 15974 15975 /* Find the active SIP dialog or create a new one */ 15976 p = find_call(&req, &sin, req.method); /* returns p locked */ 15977 if (p == NULL) { 15978 if (option_debug) 15979 ast_log(LOG_DEBUG, "Invalid SIP message - rejected , no callid, len %d\n", req.len); 15980 ast_mutex_unlock(&netlock); 15981 return 1; 15982 } 15983 /* Go ahead and lock the owner if it has one -- we may need it */ 15984 /* because this is deadlock-prone, we need to try and unlock if failed */ 15985 if (!p->owner || !ast_channel_trylock(p->owner)) 15986 break; /* locking succeeded */ 15987 if (lockretry == 1) { 15988 if (option_debug) { 15989 ast_log(LOG_DEBUG, "Failed to grab owner channel lock. (SIP call %s)\n", p->callid); 15990 } 15991 } else { 15992 if (option_debug) { 15993 ast_log(LOG_DEBUG, "Failed to grab owner channel lock, trying again. (SIP call %s)\n", p->callid); 15994 } 15995 ast_mutex_unlock(&p->lock); 15996 ast_mutex_unlock(&netlock); 15997 /* Sleep for a very short amount of time */ 15998 usleep(1); 15999 } 16000 } 16001 p->recv = sin; 16002 16003 if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) /* This is a request or response, note what it was for */ 16004 append_history(p, "Rx", "%s / %s / %s", req.data, get_header(&req, "CSeq"), req.rlPart2); 16005 16006 if (!lockretry) { 16007 /* XXX Wouldn't p->owner always exist here? */ 16008 /* This is unsafe, since p->owner wouldn't be locked. */ 16009 if (p->owner) 16010 ast_log(LOG_ERROR, "We could NOT get the channel lock for %s! \n", S_OR(p->owner->name, "- no channel name ??? - ")); 16011 ast_log(LOG_ERROR, "SIP transaction failed: %s \n", p->callid); 16012 if (req.method != SIP_ACK) 16013 transmit_response(p, "503 Server error", &req); /* We must respond according to RFC 3261 sec 12.2 */ 16014 /* XXX We could add retry-after to make sure they come back */ 16015 append_history(p, "LockFail", "Owner lock failed, transaction failed."); 16016 ast_mutex_unlock(&p->lock); 16017 ast_mutex_unlock(&netlock); 16018 return 1; 16019 } 16020 nounlock = 0; 16021 if (handle_request(p, &req, &sin, &recount, &nounlock) == -1) { 16022 /* Request failed */ 16023 if (option_debug) 16024 ast_log(LOG_DEBUG, "SIP message could not be handled, bad request: %-70.70s\n", p->callid[0] ? p->callid : "<no callid>"); 16025 } 16026 16027 if (p->owner && !nounlock) 16028 ast_channel_unlock(p->owner); 16029 ast_mutex_unlock(&p->lock); 16030 ast_mutex_unlock(&netlock); 16031 if (recount) 16032 ast_update_use_count(); 16033 16034 return 1; 16035 }
| static void stop_media_flows | ( | struct sip_pvt * | p | ) | [static] |
Immediately stop RTP, VRTP and UDPTL as applicable.
Definition at line 12825 of file chan_sip.c.
References ast_rtp_stop(), ast_udptl_stop(), sip_pvt::rtp, sip_pvt::udptl, and sip_pvt::vrtp.
Referenced by handle_request_bye(), handle_request_cancel(), handle_response(), and sip_hangup().
12826 { 12827 /* Immediately stop RTP, VRTP and UDPTL as applicable */ 12828 if (p->rtp) 12829 ast_rtp_stop(p->rtp); 12830 if (p->vrtp) 12831 ast_rtp_stop(p->vrtp); 12832 if (p->udptl) 12833 ast_udptl_stop(p->udptl); 12834 }
| static const char * subscription_type2str | ( | enum subscriptiontype | subtype | ) | [static] |
Show subscription type in string format.
Definition at line 10942 of file chan_sip.c.
References subscription_types, cfsubscription_types::text, and type.
Referenced by __sip_show_channels(), and sip_show_channel().
10943 { 10944 int i; 10945 10946 for (i = 1; (i < (sizeof(subscription_types) / sizeof(subscription_types[0]))); i++) { 10947 if (subscription_types[i].type == subtype) { 10948 return subscription_types[i].text; 10949 } 10950 } 10951 return subscription_types[0].text; 10952 }
| static int t38_get_rate | ( | int | t38cap | ) | [static] |
Get Max T.38 Transmission rate from T38 capabilities.
Definition at line 6361 of file chan_sip.c.
References ast_log(), LOG_DEBUG, option_debug, T38FAX_RATE_12000, T38FAX_RATE_14400, T38FAX_RATE_2400, T38FAX_RATE_4800, T38FAX_RATE_7200, and T38FAX_RATE_9600.
Referenced by add_t38_sdp().
06362 { 06363 int maxrate = (t38cap & (T38FAX_RATE_14400 | T38FAX_RATE_12000 | T38FAX_RATE_9600 | T38FAX_RATE_7200 | T38FAX_RATE_4800 | T38FAX_RATE_2400)); 06364 06365 if (maxrate & T38FAX_RATE_14400) { 06366 if (option_debug > 1) 06367 ast_log(LOG_DEBUG, "T38MaxFaxRate 14400 found\n"); 06368 return 14400; 06369 } else if (maxrate & T38FAX_RATE_12000) { 06370 if (option_debug > 1) 06371 ast_log(LOG_DEBUG, "T38MaxFaxRate 12000 found\n"); 06372 return 12000; 06373 } else if (maxrate & T38FAX_RATE_9600) { 06374 if (option_debug > 1) 06375 ast_log(LOG_DEBUG, "T38MaxFaxRate 9600 found\n"); 06376 return 9600; 06377 } else if (maxrate & T38FAX_RATE_7200) { 06378 if (option_debug > 1) 06379 ast_log(LOG_DEBUG, "T38MaxFaxRate 7200 found\n"); 06380 return 7200; 06381 } else if (maxrate & T38FAX_RATE_4800) { 06382 if (option_debug > 1) 06383 ast_log(LOG_DEBUG, "T38MaxFaxRate 4800 found\n"); 06384 return 4800; 06385 } else if (maxrate & T38FAX_RATE_2400) { 06386 if (option_debug > 1) 06387 ast_log(LOG_DEBUG, "T38MaxFaxRate 2400 found\n"); 06388 return 2400; 06389 } else { 06390 if (option_debug > 1) 06391 ast_log(LOG_DEBUG, "Strange, T38MaxFaxRate NOT found in peers T38 SDP.\n"); 06392 return 0; 06393 } 06394 }
| static struct sip_peer * temp_peer | ( | const char * | name | ) | [static, read] |
Create temporary peer (used in autocreatepeer mode).
Definition at line 17088 of file chan_sip.c.
References ast_calloc, ast_copy_string(), ast_set_flag, ASTOBJ_INIT, default_prefs, sip_peer::flags, sip_peer::name, sip_peer::prefs, reg_source_db(), set_peer_defaults(), SIP_PAGE2_DYNAMIC, and SIP_PAGE2_SELFDESTRUCT.
Referenced by register_verify().
17089 { 17090 struct sip_peer *peer; 17091 17092 if (!(peer = ast_calloc(1, sizeof(*peer)))) 17093 return NULL; 17094 17095 apeerobjs++; 17096 ASTOBJ_INIT(peer); 17097 set_peer_defaults(peer); 17098 17099 ast_copy_string(peer->name, name, sizeof(peer->name)); 17100 17101 ast_set_flag(&peer->flags[1], SIP_PAGE2_SELFDESTRUCT); 17102 ast_set_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC); 17103 peer->prefs = default_prefs; 17104 reg_source_db(peer); 17105 17106 return peer; 17107 }
| static void temp_pvt_cleanup | ( | void * | data | ) | [static] |
Definition at line 6136 of file chan_sip.c.
References ast_string_field_free_memory, and free.
06137 { 06138 struct sip_pvt *p = data; 06139 06140 ast_string_field_free_memory(p); 06141 06142 free(data); 06143 }
| static void temp_pvt_init | ( | void | ) | [static] |
| static char * transfermode2str | ( | enum transfermodes | mode | ) | [static] |
Convert transfer mode to text string.
Definition at line 9946 of file chan_sip.c.
References TRANSFER_CLOSED, and TRANSFER_OPENFORALL.
Referenced by _sip_show_peer(), sip_show_channel(), sip_show_settings(), and sip_show_user().
09947 { 09948 if (mode == TRANSFER_OPENFORALL) 09949 return "open"; 09950 else if (mode == TRANSFER_CLOSED) 09951 return "closed"; 09952 return "strict"; 09953 }
| static void transmit_fake_auth_response | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| int | reliable | |||
| ) | [static] |
Send a fake 401 Unauthorized response when the administrator wants to hide the names of local users/peers from fishers.
Definition at line 8753 of file chan_sip.c.
References ast_random(), ast_string_field_build, sip_pvt::randdata, and transmit_response_with_auth().
Referenced by handle_request_invite(), handle_request_subscribe(), and register_verify().
08754 { 08755 ast_string_field_build(p, randdata, "%08lx", ast_random()); /* Create nonce for challenge */ 08756 transmit_response_with_auth(p, "401 Unauthorized", req, p->randdata, reliable, "WWW-Authenticate", 0); 08757 }
| 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 7920 of file chan_sip.c.
References add_digit(), sip_pvt::ocseq, reqprep(), send_request(), SIP_INFO, and XMIT_RELIABLE.
Referenced by sip_senddigit_end().
07921 { 07922 struct sip_request req; 07923 07924 reqprep(&req, p, SIP_INFO, 0, 1); 07925 add_digit(&req, digit, duration); 07926 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 07927 }
| static int transmit_info_with_vidupdate | ( | struct sip_pvt * | p | ) | [static] |
Send SIP INFO with video update request.
Definition at line 7930 of file chan_sip.c.
References add_vidupdate(), sip_pvt::ocseq, reqprep(), send_request(), SIP_INFO, and XMIT_RELIABLE.
Referenced by sip_indicate().
07931 { 07932 struct sip_request req; 07933 07934 reqprep(&req, p, SIP_INFO, 0, 1); 07935 add_vidupdate(&req); 07936 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 07937 }
| static int transmit_invite | ( | struct sip_pvt * | p, | |
| int | sipmethod, | |||
| int | sdp, | |||
| int | init | |||
| ) | [static] |
Build REFER/INVITE/OPTIONS message and transmit it.
Definition at line 7168 of file chan_sip.c.
References add_header(), add_header_contentLength(), add_sdp(), add_t38_sdp(), sip_invite_param::addsipheaders, ALLOWED_METHODS, append_date(), ast_channel_lock, ast_channel_unlock, AST_LIST_TRAVERSE, ast_log(), ast_random(), ast_skip_blanks(), ast_strdupa, ast_strlen_zero(), ast_udptl_offered_from_local(), ast_var_name(), ast_var_value(), sip_invite_param::auth, sip_invite_param::authheader, sip_pvt::branch, build_via(), ast_var_t::entries, sip_request::headers, initialize_initreq(), sip_pvt::initreq, initreqprep(), sip_pvt::invite_branch, sip_pvt::lastinvite, LOG_DEBUG, LOG_WARNING, sip_request::method, ast_channel::name, sip_pvt::ocseq, option_debug, sip_pvt::options, sip_pvt::owner, sip_pvt::refer, sip_refer::refer_to, sip_refer::referred_by, sip_refer::referred_by_name, sip_invite_param::replaces, reqprep(), sip_pvt::rtp, send_request(), SIP_REFER, SIPBUFSIZE, sipdebug, t38properties::state, SUPPORTED_EXTENSIONS, sip_pvt::t38, T38_LOCAL_DIRECT, T38_LOCAL_REINVITE, sip_pvt::udptl, ast_channel::varshead, XMIT_CRITICAL, and XMIT_RELIABLE.
Referenced by do_proxy_auth(), handle_request_invite(), sip_call(), and sip_poke_peer().
07169 { 07170 struct sip_request req; 07171 07172 req.method = sipmethod; 07173 if (init) { /* Seems like init always is 2 */ 07174 /* Bump branch even on initial requests */ 07175 p->branch ^= ast_random(); 07176 p->invite_branch = p->branch; 07177 build_via(p); 07178 if (init > 1) 07179 initreqprep(&req, p, sipmethod); 07180 else 07181 reqprep(&req, p, sipmethod, 0, 1); 07182 } else 07183 reqprep(&req, p, sipmethod, 0, 1); 07184 07185 if (p->options && p->options->auth) 07186 add_header(&req, p->options->authheader, p->options->auth); 07187 append_date(&req); 07188 if (sipmethod == SIP_REFER) { /* Call transfer */ 07189 if (p->refer) { 07190 char buf[SIPBUFSIZE]; 07191 if (!ast_strlen_zero(p->refer->refer_to)) 07192 add_header(&req, "Refer-To", p->refer->refer_to); 07193 if (!ast_strlen_zero(p->refer->referred_by)) { 07194 snprintf(buf, sizeof(buf), "%s <%s>", p->refer->referred_by_name, p->refer->referred_by); 07195 add_header(&req, "Referred-By", buf); 07196 } 07197 } 07198 } 07199 /* This new INVITE is part of an attended transfer. Make sure that the 07200 other end knows and replace the current call with this new call */ 07201 if (p->options && p->options->replaces && !ast_strlen_zero(p->options->replaces)) { 07202 add_header(&req, "Replaces", p->options->replaces); 07203 add_header(&req, "Require", "replaces"); 07204 } 07205 07206 add_header(&req, "Allow", ALLOWED_METHODS); 07207 add_header(&req, "Supported", SUPPORTED_EXTENSIONS); 07208 if (p->options && p->options->addsipheaders && p->owner) { 07209 struct ast_channel *chan = p->owner; /* The owner channel */ 07210 struct varshead *headp; 07211 07212 ast_channel_lock(chan); 07213 07214 headp = &chan->varshead; 07215 07216 if (!headp) 07217 ast_log(LOG_WARNING,"No Headp for the channel...ooops!\n"); 07218 else { 07219 const struct ast_var_t *current; 07220 AST_LIST_TRAVERSE(headp, current, entries) { 07221 /* SIPADDHEADER: Add SIP header to outgoing call */ 07222 if (!strncasecmp(ast_var_name(current), "SIPADDHEADER", strlen("SIPADDHEADER"))) { 07223 char *content, *end; 07224 const char *header = ast_var_value(current); 07225 char *headdup = ast_strdupa(header); 07226 07227 /* Strip of the starting " (if it's there) */ 07228 if (*headdup == '"') 07229 headdup++; 07230 if ((content = strchr(headdup, ':'))) { 07231 *content++ = '\0'; 07232 content = ast_skip_blanks(content); /* Skip white space */ 07233 /* Strip the ending " (if it's there) */ 07234 end = content + strlen(content) -1; 07235 if (*end == '"') 07236 *end = '\0'; 07237 07238 add_header(&req, headdup, content); 07239 if (sipdebug) 07240 ast_log(LOG_DEBUG, "Adding SIP Header \"%s\" with content :%s: \n", headdup, content); 07241 } 07242 } 07243 } 07244 } 07245 07246 ast_channel_unlock(chan); 07247 } 07248 if (sdp) { 07249 if (p->udptl && (p->t38.state == T38_LOCAL_DIRECT || p->t38.state == T38_LOCAL_REINVITE)) { 07250 ast_udptl_offered_from_local(p->udptl, 1); 07251 if (option_debug) 07252 ast_log(LOG_DEBUG, "T38 is in state %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "<none>"); 07253 add_t38_sdp(&req, p); 07254 } else if (p->rtp) 07255 add_sdp(&req, p); 07256 } else { 07257 add_header_contentLength(&req, 0); 07258 } 07259 07260 if (!p->initreq.headers || init > 2) 07261 initialize_initreq(p, &req); 07262 p->lastinvite = p->ocseq; 07263 return send_request(p, &req, init ? XMIT_CRITICAL : XMIT_RELIABLE, p->ocseq); 07264 }
| static int transmit_message_with_text | ( | struct sip_pvt * | p, | |
| const char * | text | |||
| ) | [static] |
Transmit text with SIP MESSAGE method.
Definition at line 7829 of file chan_sip.c.
References add_text(), sip_pvt::ocseq, reqprep(), send_request(), SIP_MESSAGE, and XMIT_RELIABLE.
Referenced by sip_park_thread(), and sip_sendtext().
07830 { 07831 struct sip_request req; 07832 07833 reqprep(&req, p, SIP_MESSAGE, 0, 1); 07834 add_text(&req, text); 07835 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 07836 }
| static int transmit_notify_with_mwi | ( | struct sip_pvt * | p, | |
| int | newmsgs, | |||
| int | oldmsgs, | |||
| char * | vmexten | |||
| ) | [static] |
Notify user of messages waiting in voicemail.
Definition at line 7455 of file chan_sip.c.
References add_header(), add_header_contentLength(), add_line(), ast_build_string(), ast_inet_ntoa(), ast_log(), ast_test_flag, sip_pvt::expiry, sip_pvt::flags, sip_pvt::fromdomain, sip_request::headers, initialize_initreq(), sip_pvt::initreq, initreqprep(), LOG_WARNING, sip_pvt::ocseq, sip_pvt::ourip, S_OR, send_request(), SIP_NOTIFY, SIP_PAGE2_BUGGY_MWI, sip_pvt::subscribed, t, and XMIT_RELIABLE.
Referenced by sip_send_mwi_to_peer().
07456 { 07457 struct sip_request req; 07458 char tmp[500]; 07459 char *t = tmp; 07460 size_t maxbytes = sizeof(tmp); 07461 07462 initreqprep(&req, p, SIP_NOTIFY); 07463 add_header(&req, "Event", "message-summary"); 07464 add_header(&req, "Content-Type", default_notifymime); 07465 07466 ast_build_string(&t, &maxbytes, "Messages-Waiting: %s\r\n", newmsgs ? "yes" : "no"); 07467 ast_build_string(&t, &maxbytes, "Message-Account: sip:%s@%s\r\n", 07468 S_OR(vmexten, default_vmexten), S_OR(p->fromdomain, ast_inet_ntoa(p->ourip))); 07469 /* Cisco has a bug in the SIP stack where it can't accept the 07470 (0/0) notification. This can temporarily be disabled in 07471 sip.conf with the "buggymwi" option */ 07472 ast_build_string(&t, &maxbytes, "Voice-Message: %d/%d%s\r\n", newmsgs, oldmsgs, (ast_test_flag(&p->flags[1], SIP_PAGE2_BUGGY_MWI) ? "" : " (0/0)")); 07473 07474 if (p->subscribed) { 07475 if (p->expiry) 07476 add_header(&req, "Subscription-State", "active"); 07477 else /* Expired */ 07478 add_header(&req, "Subscription-State", "terminated;reason=timeout"); 07479 } 07480 07481 if (t > tmp + sizeof(tmp)) 07482 ast_log(LOG_WARNING, "Buffer overflow detected!! (Please file a bug report)\n"); 07483 07484 add_header_contentLength(&req, strlen(tmp)); 07485 add_line(&req, tmp); 07486 07487 if (!p->initreq.headers) 07488 initialize_initreq(p, &req); 07489 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 07490 }
| 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.
Definition at line 7501 of file chan_sip.c.
References add_header(), add_header_contentLength(), add_line(), ALLOWED_METHODS, sip_request::headers, initialize_initreq(), sip_pvt::initreq, sip_pvt::lastnoninvite, sip_pvt::ocseq, reqprep(), send_request(), SIP_NOTIFY, SIPBUFSIZE, SUPPORTED_EXTENSIONS, and XMIT_RELIABLE.
Referenced by handle_request_refer(), local_attended_transfer(), and sip_park_thread().
07502 { 07503 struct sip_request req; 07504 char tmp[SIPBUFSIZE/2]; 07505 07506 reqprep(&req, p, SIP_NOTIFY, 0, 1); 07507 snprintf(tmp, sizeof(tmp), "refer;id=%d", cseq); 07508 add_header(&req, "Event", tmp); 07509 add_header(&req, "Subscription-state", terminate ? "terminated;reason=noresource" : "active"); 07510 add_header(&req, "Content-Type", "message/sipfrag;version=2.0"); 07511 add_header(&req, "Allow", ALLOWED_METHODS); 07512 add_header(&req, "Supported", SUPPORTED_EXTENSIONS); 07513 07514 snprintf(tmp, sizeof(tmp), "SIP/2.0 %s\r\n", message); 07515 add_header_contentLength(&req, strlen(tmp)); 07516 add_line(&req, tmp); 07517 07518 if (!p->initreq.headers) 07519 initialize_initreq(p, &req); 07520 07521 p->lastnoninvite = p->ocseq; 07522 07523 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 07524 }
| 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 7850 of file chan_sip.c.
References add_header(), ALLOWED_METHODS, ast_copy_string(), ast_log(), ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_test_flag, sip_pvt::callid, sip_pvt::flags, get_header(), get_in_brackets(), sip_request::headers, sip_pvt::initreq, LOG_DEBUG, LOG_NOTICE, sip_pvt::ocseq, option_debug, sip_pvt::our_contact, sip_pvt::refer, REFER_SENT, sip_refer::refer_to, sip_refer::referred_by, reqprep(), send_request(), SIP_OUTGOING, SIP_REFER, sip_refer_allocate(), sipdebug, sip_refer::status, SUPPORTED_EXTENSIONS, sip_pvt::tag, sip_pvt::theirtag, and XMIT_RELIABLE.
Referenced by sip_transfer().
07851 { 07852 struct sip_request req = { 07853 .headers = 0, 07854 }; 07855 char from[256]; 07856 const char *of; 07857 char *c; 07858 char referto[256]; 07859 char *ttag, *ftag; 07860 char *theirtag = ast_strdupa(p->theirtag); 07861 07862 if (option_debug || sipdebug) 07863 ast_log(LOG_DEBUG, "SIP transfer of %s to %s\n", p->callid, dest); 07864 07865 /* Are we transfering an inbound or outbound call ? */ 07866 if (ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 07867 of = get_header(&p->initreq, "To"); 07868 ttag = theirtag; 07869 ftag = p->tag; 07870 } else { 07871 of = get_header(&p->initreq, "From"); 07872 ftag = theirtag; 07873 ttag = p->tag; 07874 } 07875 07876 ast_copy_string(from, of, sizeof(from)); 07877 of = get_in_brackets(from); 07878 ast_string_field_set(p, from, of); 07879 if (strncasecmp(of, "sip:", 4)) 07880 ast_log(LOG_NOTICE, "From address missing 'sip:', using it anyway\n"); 07881 else 07882 of += 4; 07883 /* Get just the username part */ 07884 if ((c = strchr(dest, '@'))) 07885 c = NULL; 07886 else if ((c = strchr(of, '@'))) 07887 *c++ = '\0'; 07888 if (c) 07889 snprintf(referto, sizeof(referto), "<sip:%s@%s>", dest, c); 07890 else 07891 snprintf(referto, sizeof(referto), "<sip:%s>", dest); 07892 07893 /* save in case we get 407 challenge */ 07894 sip_refer_allocate(p); 07895 ast_copy_string(p->refer->refer_to, referto, sizeof(p->refer->refer_to)); 07896 ast_copy_string(p->refer->referred_by, p->our_contact, sizeof(p->refer->referred_by)); 07897 p->refer->status = REFER_SENT; /* Set refer status */ 07898 07899 reqprep(&req, p, SIP_REFER, 0, 1); 07900 07901 add_header(&req, "Refer-To", referto); 07902 add_header(&req, "Allow", ALLOWED_METHODS); 07903 add_header(&req, "Supported", SUPPORTED_EXTENSIONS); 07904 if (!ast_strlen_zero(p->our_contact)) 07905 add_header(&req, "Referred-By", p->our_contact); 07906 07907 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 07908 /* We should propably wait for a NOTIFY here until we ack the transfer */ 07909 /* Maybe fork a new thread and wait for a STATUS of REFER_200OK on the refer status before returning to app_transfer */ 07910 07911 /*! \todo In theory, we should hang around and wait for a reply, before 07912 returning to the dial plan here. Don't know really how that would 07913 affect the transfer() app or the pbx, but, well, to make this 07914 useful we should have a STATUS code on transfer(). 07915 */ 07916 }
| static int transmit_register | ( | struct sip_registry * | r, | |
| int | sipmethod, | |||
| const char * | auth, | |||
| const char * | authheader | |||
| ) | [static] |
Transmit register to SIP proxy or UA.
Definition at line 7628 of file chan_sip.c.
References __ourip, add_header(), add_header_contentLength(), append_history, ast_log(), ast_random(), ast_sched_add(), AST_SCHED_DEL, ast_set_flag, ast_sip_ouraddrfor(), ast_string_field_free, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_verbose(), ASTOBJ_REF, sip_pvt::authname, sip_registry::authuser, sip_pvt::branch, build_callid_registry(), build_contact(), build_reply_digest(), build_via(), sip_registry::call, sip_pvt::callid, sip_registry::callid, sip_registry::callid_valid, sip_registry::contact, create_addr(), DEFAULT_MAX_FORWARDS, sip_registry::domain, exten, sip_pvt::flags, sip_pvt::fromdomain, sip_pvt::fromuser, sip_request::headers, sip_registry::hostname, init_req(), initialize_initreq(), sip_pvt::initreq, sip_request::lines, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, make_our_tag(), sip_registry::md5secret, sip_pvt::nonce, sip_registry::nonce, sip_pvt::noncecount, sip_registry::noncecount, sip_pvt::ocseq, sip_registry::ocseq, sip_registry::opaque, sip_pvt::opaque, option_debug, sip_pvt::our_contact, sip_pvt::ourip, sip_pvt::peermd5secret, sip_pvt::peername, sip_pvt::peersecret, sip_registry::portno, sip_registry::qop, sip_pvt::qop, sip_registry::realm, sip_pvt::realm, sip_pvt::recv, REG_STATE_AUTHSENT, REG_STATE_REGSENT, sip_registry::regattempts, sip_pvt::registry, sip_registry::regstate, sip_pvt::sa, sip_registry::secret, send_request(), sip_alloc(), sip_debug_test_pvt(), sip_destroy(), sip_methods, SIP_NO_HISTORY, SIP_OUTGOING, sip_reg_timeout(), SIP_REGISTER, sipdebug, STANDARD_SIP_PORT, sip_pvt::tag, cfsip_methods::text, sip_pvt::theirtag, sip_registry::timeout, sip_pvt::tohost, TRUE, sip_pvt::uri, username, sip_registry::username, sip_pvt::via, and XMIT_CRITICAL.
Referenced by __sip_do_register(), do_register_auth(), and sip_reg_timeout().
07629 { 07630 struct sip_request req; 07631 char from[256]; 07632 char to[256]; 07633 char tmp[80]; 07634 char addr[80]; 07635 struct sip_pvt *p; 07636 char *fromdomain; 07637 07638 /* exit if we are already in process with this registrar ?*/ 07639 if ( r == NULL || ((auth==NULL) && (r->regstate==REG_STATE_REGSENT || r->regstate==REG_STATE_AUTHSENT))) { 07640 if (r) { 07641 ast_log(LOG_NOTICE, "Strange, trying to register %s@%s when registration already pending\n", r->username, r->hostname); 07642 } 07643 return 0; 07644 } 07645 07646 if (r->call) { /* We have a registration */ 07647 if (!auth) { 07648 ast_log(LOG_WARNING, "Already have a REGISTER going on to %s@%s?? \n", r->username, r->hostname); 07649 return 0; 07650 } else { 07651 p = r->call; 07652 make_our_tag(p->tag, sizeof(p->tag)); /* create a new local tag for every register attempt */ 07653 ast_string_field_free(p, theirtag); /* forget their old tag, so we don't match tags when getting response */ 07654 } 07655 } else { 07656 /* Build callid for registration if we haven't registered before */ 07657 if (!r->callid_valid) { 07658 build_callid_registry(r, __ourip, default_fromdomain); 07659 r->callid_valid = TRUE; 07660 } 07661 /* Allocate SIP packet for registration */ 07662 if (!(p = sip_alloc( r->callid, NULL, 0, SIP_REGISTER))) { 07663 ast_log(LOG_WARNING, "Unable to allocate registration transaction (memory or socket error)\n"); 07664 return 0; 07665 } 07666 if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) 07667 append_history(p, "RegistryInit", "Account: %s@%s", r->username, r->hostname); 07668 /* Find address to hostname */ 07669 if (create_addr(p, r->hostname)) { 07670 /* we have what we hope is a temporary network error, 07671 * probably DNS. We need to reschedule a registration try */ 07672 sip_destroy(p); 07673 07674 if (r->timeout > -1) 07675 ast_log(LOG_WARNING, "Still have a registration timeout for %s@%s (create_addr() error), %d\n", r->username, r->hostname, r->timeout); 07676 else 07677 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); 07678 07679 AST_SCHED_DEL(sched, r->timeout); 07680 r->timeout = ast_sched_add(sched, global_reg_timeout * 1000, sip_reg_timeout, r); 07681 r->regattempts++; 07682 return 0; 07683 } 07684 /* Copy back Call-ID in case create_addr changed it */ 07685 ast_string_field_set(r, callid, p->callid); 07686 if (r->portno) { 07687 p->sa.sin_port = htons(r->portno); 07688 p->recv.sin_port = htons(r->portno); 07689 } else /* Set registry port to the port set from the peer definition/srv or default */ 07690 r->portno = ntohs(p->sa.sin_port); 07691 ast_set_flag(&p->flags[0], SIP_OUTGOING); /* Registration is outgoing call */ 07692 r->call=p; /* Save pointer to SIP packet */ 07693 p->registry = ASTOBJ_REF(r); /* Add pointer to registry in packet */ 07694 if (!ast_strlen_zero(r->secret)) /* Secret (password) */ 07695 ast_string_field_set(p, peersecret, r->secret); 07696 if (!ast_strlen_zero(r->md5secret)) 07697 ast_string_field_set(p, peermd5secret, r->md5secret); 07698 /* User name in this realm 07699 - if authuser is set, use that, otherwise use username */ 07700 if (!ast_strlen_zero(r->authuser)) { 07701 ast_string_field_set(p, peername, r->authuser); 07702 ast_string_field_set(p, authname, r->authuser); 07703 } else if (!ast_strlen_zero(r->username)) { 07704 ast_string_field_set(p, peername, r->username); 07705 ast_string_field_set(p, authname, r->username); 07706 ast_string_field_set(p, fromuser, r->username); 07707 } 07708 if (!ast_strlen_zero(r->username)) 07709 ast_string_field_set(p, username, r->username); 07710 /* Save extension in packet */ 07711 ast_string_field_set(p, exten, r->contact); 07712 07713 /* 07714 check which address we should use in our contact header 07715 based on whether the remote host is on the external or 07716 internal network so we can register through nat 07717 */ 07718 if (ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip)) 07719 p->ourip = bindaddr.sin_addr; 07720 build_contact(p); 07721 } 07722 07723 /* set up a timeout */ 07724 if (auth == NULL) { 07725 if (r->timeout > -1) 07726 ast_log(LOG_WARNING, "Still have a registration timeout, #%d - deleting it\n", r->timeout); 07727 AST_SCHED_DEL(sched, r->timeout); 07728 r->timeout = ast_sched_add(sched, global_reg_timeout * 1000, sip_reg_timeout, r); 07729 if (option_debug) 07730 ast_log(LOG_DEBUG, "Scheduled a registration timeout for %s id #%d \n", r->hostname, r->timeout); 07731 } 07732 07733 if ((fromdomain = strchr(r->username, '@'))) { 07734 /* We have a domain in the username for registration */ 07735 snprintf(from, sizeof(from), "<sip:%s>;tag=%s", r->username, p->tag); 07736 if (!ast_strlen_zero(p->theirtag)) 07737 snprintf(to, sizeof(to), "<sip:%s>;tag=%s", r->username, p->theirtag); 07738 else 07739 snprintf(to, sizeof(to), "<sip:%s>", r->username); 07740 07741 /* If the registration username contains '@', then the domain should be used as 07742 the equivalent of "fromdomain" for the registration */ 07743 if (ast_strlen_zero(p->fromdomain)) { 07744 ast_string_field_set(p, fromdomain, ++fromdomain); 07745 } 07746 } else { 07747 snprintf(from, sizeof(from), "<sip:%s@%s>;tag=%s", r->username, p->tohost, p->tag); 07748 if (!ast_strlen_zero(p->theirtag)) 07749 snprintf(to, sizeof(to), "<sip:%s@%s>;tag=%s", r->username, p->tohost, p->theirtag); 07750 else 07751 snprintf(to, sizeof(to), "<sip:%s@%s>", r->username, p->tohost); 07752 } 07753 07754 /* Fromdomain is what we are registering to, regardless of actual 07755 host name from SRV */ 07756 if (!ast_strlen_zero(p->fromdomain)) { 07757 if (r->portno && r->portno != STANDARD_SIP_PORT) 07758 snprintf(addr, sizeof(addr), "sip:%s:%d", p->fromdomain, r->portno); 07759 else 07760 snprintf(addr, sizeof(addr), "sip:%s", p->fromdomain); 07761 } else { 07762 if (r->portno && r->portno != STANDARD_SIP_PORT) 07763 snprintf(addr, sizeof(addr), "sip:%s:%d", r->hostname, r->portno); 07764 else 07765 snprintf(addr, sizeof(addr), "sip:%s", r->hostname); 07766 } 07767 ast_string_field_set(p, uri, addr); 07768 07769 p->branch ^= ast_random(); 07770 07771 init_req(&req, sipmethod, addr); 07772 07773 /* Add to CSEQ */ 07774 snprintf(tmp, sizeof(tmp), "%u %s", ++r->ocseq, sip_methods[sipmethod].text); 07775 p->ocseq = r->ocseq; 07776 07777 build_via(p); 07778 add_header(&req, "Via", p->via); 07779 add_header(&req, "From", from); 07780 add_header(&req, "To", to); 07781 add_header(&req, "Call-ID", p->callid); 07782 add_header(&req, "CSeq", tmp); 07783 if (!ast_strlen_zero(global_useragent)) 07784 add_header(&req, "User-Agent", global_useragent); 07785 add_header(&req, "Max-Forwards", DEFAULT_MAX_FORWARDS); 07786 07787 07788 if (auth) /* Add auth header */ 07789 add_header(&req, authheader, auth); 07790 else if (!ast_strlen_zero(r->nonce)) { 07791 char digest[1024]; 07792 07793 /* We have auth data to reuse, build a digest header! */ 07794 if (sipdebug) 07795 ast_log(LOG_DEBUG, " >>> Re-using Auth data for %s@%s\n", r->username, r->hostname); 07796 ast_string_field_set(p, realm, r->realm); 07797 ast_string_field_set(p, nonce, r->nonce); 07798 ast_string_field_set(p, domain, r->domain); 07799 ast_string_field_set(p, opaque, r->opaque); 07800 ast_string_field_set(p, qop, r->qop); 07801 r->noncecount++; 07802 p->noncecount = r->noncecount; 07803 07804 memset(digest,0,sizeof(digest)); 07805 if(!build_reply_digest(p, sipmethod, digest, sizeof(digest))) 07806 add_header(&req, "Authorization", digest); 07807 else 07808 ast_log(LOG_NOTICE, "No authorization available for authentication of registration to %s@%s\n", r->username, r->hostname); 07809 07810 } 07811 07812 snprintf(tmp, sizeof(tmp), "%d", default_expiry); 07813 add_header(&req, "Expires", tmp); 07814 add_header(&req, "Contact", p->our_contact); 07815 add_header(&req, "Event", "registration"); 07816 add_header_contentLength(&req, 0); 07817 07818 initialize_initreq(p, &req); 07819 if (sip_debug_test_pvt(p)) 07820 ast_verbose("REGISTER %d headers, %d lines\n", p->initreq.headers, p->initreq.lines); 07821 r->regstate = auth ? REG_STATE_AUTHSENT : REG_STATE_REGSENT; 07822 r->regattempts++; /* Another attempt */ 07823 if (option_debug > 3) 07824 ast_verbose("REGISTER attempt %d to %s@%s\n", r->regattempts, r->username, r->hostname); 07825 return send_request(p, &req, XMIT_CRITICAL, p->ocseq); 07826 }
| static int transmit_reinvite_with_sdp | ( | struct sip_pvt * | p | ) | [static] |
Transmit reinvite with SDP.
Definition at line 6888 of file chan_sip.c.
References add_header(), add_sdp(), ALLOWED_METHODS, append_history, ast_set_flag, ast_test_flag, sip_pvt::flags, initialize_initreq(), sip_pvt::lastinvite, sip_pvt::ocseq, reqprep(), send_request(), SIP_INVITE, SIP_NO_HISTORY, SIP_OUTGOING, SIP_REINVITE_UPDATE, SIP_UPDATE, sipdebug, SUPPORTED_EXTENSIONS, and XMIT_CRITICAL.
Referenced by check_pendings(), and sip_set_rtp_peer().
06889 { 06890 struct sip_request req; 06891 06892 reqprep(&req, p, ast_test_flag(&p->flags[0], SIP_REINVITE_UPDATE) ? SIP_UPDATE : SIP_INVITE, 0, 1); 06893 06894 add_header(&req, "Allow", ALLOWED_METHODS); 06895 add_header(&req, "Supported", SUPPORTED_EXTENSIONS); 06896 if (sipdebug) 06897 add_header(&req, "X-asterisk-Info", "SIP re-invite (External RTP bridge)"); 06898 if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) 06899 append_history(p, "ReInv", "Re-invite sent"); 06900 add_sdp(&req, p); 06901 /* Use this as the basis */ 06902 initialize_initreq(p, &req); 06903 p->lastinvite = p->ocseq; 06904 ast_set_flag(&p->flags[0], SIP_OUTGOING); /* Change direction of this dialog */ 06905 return send_request(p, &req, XMIT_CRITICAL, p->ocseq); 06906 }
| static int transmit_reinvite_with_t38_sdp | ( | struct sip_pvt * | p | ) | [static] |
Transmit reinvite with T38 SDP We reinvite so that the T38 processing can take place. SIP Signalling stays with * in the path.
Definition at line 6912 of file chan_sip.c.
References add_header(), add_t38_sdp(), ALLOWED_METHODS, ast_set_flag, ast_test_flag, ast_udptl_offered_from_local(), sip_pvt::flags, initialize_initreq(), sip_pvt::lastinvite, sip_pvt::ocseq, reqprep(), send_request(), SIP_INVITE, SIP_OUTGOING, SIP_REINVITE_UPDATE, SIP_UPDATE, sipdebug, SUPPORTED_EXTENSIONS, sip_pvt::udptl, and XMIT_CRITICAL.
Referenced by sip_handle_t38_reinvite(), sip_read(), and sip_set_udptl_peer().
06913 { 06914 struct sip_request req; 06915 06916 reqprep(&req, p, ast_test_flag(&p->flags[0], SIP_REINVITE_UPDATE) ? SIP_UPDATE : SIP_INVITE, 0, 1); 06917 06918 add_header(&req, "Allow", ALLOWED_METHODS); 06919 add_header(&req, "Supported", SUPPORTED_EXTENSIONS); 06920 if (sipdebug) 06921 add_header(&req, "X-asterisk-info", "SIP re-invite (T38 switchover)"); 06922 ast_udptl_offered_from_local(p->udptl, 1); 06923 add_t38_sdp(&req, p); 06924 /* Use this as the basis */ 06925 initialize_initreq(p, &req); 06926 ast_set_flag(&p->flags[0], SIP_OUTGOING); /* Change direction of this dialog */ 06927 p->lastinvite = p->ocseq; 06928 return send_request(p, &req, XMIT_CRITICAL, p->ocseq); 06929 }
| static int transmit_request | ( | struct sip_pvt * | p, | |
| int | sipmethod, | |||
| int | inc, | |||
| enum xmittype | reliable, | |||
| int | newbranch | |||
| ) | [static] |
Transmit generic SIP request returns XMIT_ERROR if transmit failed with a critical error (don't retry).
Definition at line 7942 of file chan_sip.c.
References add_header_contentLength(), INV_CONFIRMED, sip_pvt::invitestate, sip_pvt::ocseq, reqprep(), send_request(), and SIP_ACK.
Referenced by check_pendings(), handle_response(), handle_response_invite(), and sip_hangup().
07943 { 07944 struct sip_request resp; 07945 07946 if (sipmethod == SIP_ACK) 07947 p->invitestate = INV_CONFIRMED; 07948 07949 reqprep(&resp, p, sipmethod, seqno, newbranch); 07950 add_header_contentLength(&resp, 0); 07951 return send_request(p, &resp, reliable, seqno ? seqno : p->ocseq); 07952 }
| static int transmit_request_with_auth | ( | struct sip_pvt * | p, | |
| int | sipmethod, | |||
| int | seqno, | |||
| enum xmittype | reliable, | |||
| int | newbranch | |||
| ) | [static] |
Transmit SIP request, auth added.
Definition at line 7955 of file chan_sip.c.
References add_header(), add_header_contentLength(), ast_cause2str(), ast_log(), ast_strlen_zero(), sip_invite_param::auth_type, build_reply_digest(), sip_pvt::callid, ast_channel::hangupcause, LOG_WARNING, sip_pvt::ocseq, sip_pvt::options, sip_pvt::owner, PROXY_AUTH, sip_pvt::realm, reqprep(), send_request(), SIP_BYE, and WWW_AUTH.
Referenced by __sip_autodestruct(), check_pendings(), and sip_hangup().
07956 { 07957 struct sip_request resp; 07958 07959 reqprep(&resp, p, sipmethod, seqno, newbranch); 07960 if (!ast_strlen_zero(p->realm)) { 07961 char digest[1024]; 07962 07963 memset(digest, 0, sizeof(digest)); 07964 if(!build_reply_digest(p, sipmethod, digest, sizeof(digest))) { 07965 if (p->options && p->options->auth_type == PROXY_AUTH) 07966 add_header(&resp, "Proxy-Authorization", digest); 07967 else if (p->options && p->options->auth_type == WWW_AUTH) 07968 add_header(&resp, "Authorization", digest); 07969 else /* Default, to be backwards compatible (maybe being too careful, but leaving it for now) */ 07970 add_header(&resp, "Proxy-Authorization", digest); 07971 } else 07972 ast_log(LOG_WARNING, "No authentication available for call %s\n", p->callid); 07973 } 07974 /* If we are hanging up and know a cause for that, send it in clear text to make 07975 debugging easier. */ 07976 if (sipmethod == SIP_BYE && p->owner && p->owner->hangupcause) { 07977 char buf[10]; 07978 07979 add_header(&resp, "X-Asterisk-HangupCause", ast_cause2str(p->owner->hangupcause)); 07980 snprintf(buf, sizeof(buf), "%d", p->owner->hangupcause); 07981 add_header(&resp, "X-Asterisk-HangupCauseCode", buf); 07982 } 07983 07984 add_header_contentLength(&resp, 0); 07985 return send_request(p, &resp, reliable, seqno ? seqno : p->ocseq); 07986 }
| static int transmit_response | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req | |||
| ) | [static] |
Transmit response, no retransmits.
Definition at line 6197 of file chan_sip.c.
References __transmit_response(), and XMIT_UNRELIABLE.
Referenced by handle_invite_replaces(), handle_request(), handle_request_bye(), handle_request_cancel(), handle_request_info(), handle_request_invite(), handle_request_message(), handle_request_notify(), handle_request_refer(), handle_request_subscribe(), local_attended_transfer(), receive_message(), register_verify(), sip_indicate(), sip_park_thread(), and sipsock_read().
06198 { 06199 return __transmit_response(p, msg, req, XMIT_UNRELIABLE); 06200 }
| 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 6216 of file chan_sip.c.
References __transmit_response(), and XMIT_CRITICAL.
Referenced by handle_invite_replaces(), handle_request(), handle_request_bye(), handle_request_cancel(), handle_request_invite(), handle_request_subscribe(), sip_hangup(), sip_indicate(), and sip_sipredirect().
06217 { 06218 return __transmit_response(p, msg, req, XMIT_CRITICAL); 06219 }
| static int transmit_response_using_temp | ( | ast_string_field | callid, | |
| struct sockaddr_in * | sin, | |||
| int | useglobal_nat, | |||
| const int | intended_method, | |||
| const struct sip_request * | req, | |||
| const char * | msg | |||
| ) | [static] |
Transmit response, no retransmits, using a temporary pvt structure.
Definition at line 6146 of file chan_sip.c.
References __ourip, __transmit_response(), ast_copy_flags, ast_log(), ast_random(), ast_set_flag, ast_sip_ouraddrfor(), ast_string_field_init, ast_string_field_reset_all, ast_string_field_set, ast_test_flag, ast_threadstorage_get(), sip_pvt::branch, build_via(), check_via(), do_setnat(), sip_pvt::flags, sip_pvt::fromdomain, INITIAL_CSEQ, LOG_NOTICE, make_our_tag(), sip_pvt::method, sip_pvt::ocseq, sip_pvt::ourip, sip_pvt::recv, sip_pvt::sa, SIP_NAT, SIP_NAT_ROUTE, SIP_NO_HISTORY, sip_pvt::tag, ts_temp_pvt, and XMIT_UNRELIABLE.
Referenced by find_call().
06147 { 06148 struct sip_pvt *p = NULL; 06149 06150 if (!(p = ast_threadstorage_get(&ts_temp_pvt, sizeof(*p)))) { 06151 ast_log(LOG_NOTICE, "Failed to get temporary pvt\n"); 06152 return -1; 06153 } 06154 06155 /* if the structure was just allocated, initialize it */ 06156 if (!ast_test_flag(&p->flags[0], SIP_NO_HISTORY)) { 06157 ast_set_flag(&p->flags[0], SIP_NO_HISTORY); 06158 if (ast_string_field_init(p, 512)) 06159 return -1; 06160 } 06161 06162 /* Initialize the bare minimum */ 06163 p->method = intended_method; 06164 06165 if (sin) { 06166 p->sa = *sin; 06167 if (ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip)) 06168 p->ourip = __ourip; 06169 } else 06170 p->ourip = __ourip; 06171 06172 p->branch = ast_random(); 06173 make_our_tag(p->tag, sizeof(p->tag)); 06174 p->ocseq = INITIAL_CSEQ; 06175 06176 if (useglobal_nat && sin) { 06177 ast_copy_flags(&p->flags[0], &global_flags[0], SIP_NAT); 06178 p->recv = *sin; 06179 do_setnat(p, ast_test_flag(&p->flags[0], SIP_NAT) & SIP_NAT_ROUTE); 06180 } 06181 check_via(p, req); 06182 06183 ast_string_field_set(p, fromdomain, default_fromdomain); 06184 build_via(p); 06185 ast_string_field_set(p, callid, callid); 06186 06187 /* Use this temporary pvt structure to send the message */ 06188 __transmit_response(p, msg, req, XMIT_UNRELIABLE); 06189 06190 /* Free the string fields, but not the pool space */ 06191 ast_string_field_reset_all(p); 06192 06193 return 0; 06194 }
| 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 6244 of file chan_sip.c.
References add_header(), add_header_contentLength(), respprep(), and send_response().
Referenced by handle_request(), and handle_request_options().
06245 { 06246 struct sip_request resp; 06247 respprep(&resp, p, msg, req); 06248 add_header(&resp, "Accept", "application/sdp"); 06249 add_header_contentLength(&resp, 0); 06250 return send_response(p, &resp, reliable, 0); 06251 }
| 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 6254 of file chan_sip.c.
References add_header(), add_header_contentLength(), append_history, ast_log(), get_header(), LOG_WARNING, sip_pvt::noncecount, respprep(), send_response(), and sip_pvt::username.
Referenced by check_auth(), and transmit_fake_auth_response().
06255 { 06256 struct sip_request resp; 06257 char tmp[512]; 06258 int seqno = 0; 06259 06260 if (reliable && (sscanf(get_header(req, "CSeq"), "%d ", &seqno) != 1)) { 06261 ast_log(LOG_WARNING, "Unable to determine sequence number from '%s'\n", get_header(req, "CSeq")); 06262 return -1; 06263 } 06264 /* Stale means that they sent us correct authentication, but 06265 based it on an old challenge (nonce) */ 06266 snprintf(tmp, sizeof(tmp), "Digest algorithm=MD5, realm=\"%s\", nonce=\"%s\"%s", global_realm, randdata, stale ? ", stale=true" : ""); 06267 respprep(&resp, p, msg, req); 06268 add_header(&resp, header, tmp); 06269 add_header_contentLength(&resp, 0); 06270 append_history(p, "AuthChal", "Auth challenge sent for %s - nc %d", p->username, p->noncecount); 06271 return send_response(p, &resp, reliable, seqno); 06272 }
| 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 6234 of file chan_sip.c.
References add_header_contentLength(), append_date(), respprep(), send_response(), and XMIT_UNRELIABLE.
Referenced by register_verify().
06235 { 06236 struct sip_request resp; 06237 respprep(&resp, p, msg, req); 06238 append_date(&resp); 06239 add_header_contentLength(&resp, 0); 06240 return send_response(p, &resp, XMIT_UNRELIABLE, 0); 06241 }
| static int transmit_response_with_sdp | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req, | |||
| enum xmittype | reliable | |||
| ) | [static] |
Used for 200 OK and 183 early media.
Definition at line 6817 of file chan_sip.c.
References add_sdp(), ast_log(), ast_rtp_codec_setpref(), ast_test_flag, sip_pvt::autoframing, sip_pvt::callid, sip_pvt::flags, get_header(), LOG_DEBUG, LOG_ERROR, LOG_WARNING, option_debug, sip_pvt::pendinginvite, sip_pvt::prefs, respprep(), sip_pvt::rtp, send_response(), SIP_OUTGOING, and try_suggested_sip_codec().
Referenced by handle_invite_replaces(), handle_request_invite(), sip_answer(), sip_indicate(), and sip_write().
06818 { 06819 struct sip_request resp; 06820 int seqno; 06821 if (sscanf(get_header(req, "CSeq"), "%d ", &seqno) != 1) { 06822 ast_log(LOG_WARNING, "Unable to get seqno from '%s'\n", get_header(req, "CSeq")); 06823 return -1; 06824 } 06825 respprep(&resp, p, msg, req); 06826 if (p->rtp) { 06827 if (!p->autoframing && !ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 06828 if (option_debug) 06829 ast_log(LOG_DEBUG, "Setting framing from config on incoming call\n"); 06830 ast_rtp_codec_setpref(p->rtp, &p->prefs); 06831 } 06832 try_suggested_sip_codec(p); 06833 add_sdp(&resp, p); 06834 } else 06835 ast_log(LOG_ERROR, "Can't add SDP to response, since we have no RTP session allocated. Call-ID %s\n", p->callid); 06836 if (reliable && !p->pendinginvite) 06837 p->pendinginvite = seqno; /* Buggy clients sends ACK on RINGING too */ 06838 return send_response(p, &resp, reliable, seqno); 06839 }
| 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 6777 of file chan_sip.c.
References add_t38_sdp(), ast_log(), ast_udptl_offered_from_local(), sip_pvt::callid, get_header(), LOG_ERROR, LOG_WARNING, sip_pvt::pendinginvite, respprep(), send_response(), and sip_pvt::udptl.
Referenced by handle_request_invite(), sip_answer(), and sip_handle_t38_reinvite().
06778 { 06779 struct sip_request resp; 06780 int seqno; 06781 06782 if (sscanf(get_header(req, "CSeq"), "%d ", &seqno) != 1) { 06783 ast_log(LOG_WARNING, "Unable to get seqno from '%s'\n", get_header(req, "CSeq")); 06784 return -1; 06785 } 06786 respprep(&resp, p, msg, req); 06787 if (p->udptl) { 06788 ast_udptl_offered_from_local(p->udptl, 0); 06789 add_t38_sdp(&resp, p); 06790 } else 06791 ast_log(LOG_ERROR, "Can't add SDP to response, since we have no UDPTL session allocated. Call-ID %s\n", p->callid); 06792 if (retrans && !p->pendinginvite) 06793 p->pendinginvite = seqno; /* Buggy clients sends ACK on RINGING too */ 06794 return send_response(p, &resp, retrans, seqno); 06795 }
| 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 6203 of file chan_sip.c.
References add_header(), add_header_contentLength(), append_date(), respprep(), send_response(), and XMIT_UNRELIABLE.
Referenced by handle_request_invite().
06204 { 06205 struct sip_request resp; 06206 respprep(&resp, p, msg, req); 06207 append_date(&resp); 06208 add_header(&resp, "Unsupported", unsupported); 06209 add_header_contentLength(&resp, 0); 06210 return send_response(p, &resp, XMIT_UNRELIABLE, 0); 06211 }
| static int transmit_sip_request | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Transmit SIP request unreliably (only used in sip_notify subsystem).
Definition at line 7493 of file chan_sip.c.
References sip_request::headers, initialize_initreq(), sip_pvt::initreq, sip_pvt::ocseq, send_request(), and XMIT_UNRELIABLE.
Referenced by sip_notify().
07494 { 07495 if (!p->initreq.headers) /* Initialize first request before sending */ 07496 initialize_initreq(p, req); 07497 return send_request(p, req, XMIT_UNRELIABLE, p->ocseq); 07498 }
| static int transmit_state_notify | ( | struct sip_pvt * | p, | |
| int | state, | |||
| int | full, | |||
| int | timeout | |||
| ) | [static] |
Used in the SUBSCRIBE notification subsystem.
Definition at line 7267 of file chan_sip.c.
References add_header(), add_header_contentLength(), add_line(), ast_build_string(), ast_copy_string(), ast_device_state(), AST_DEVICE_UNAVAILABLE, AST_EXTENSION_BUSY, AST_EXTENSION_DEACTIVATED, AST_EXTENSION_INUSE, AST_EXTENSION_NOT_INUSE, AST_EXTENSION_ONHOLD, AST_EXTENSION_REMOVED, AST_EXTENSION_RINGING, AST_EXTENSION_UNAVAILABLE, ast_get_hint(), ast_log(), AST_MAX_EXTENSION, sip_pvt::context, CPIM_PIDF_XML, DIALOG_INFO_XML, sip_pvt::dialogver, cfsubscription_types::event, sip_pvt::expiry, sip_pvt::exten, find_subscription_type(), get_header(), get_in_brackets(), sip_pvt::initreq, LOG_WARNING, cfsubscription_types::mediatype, NONE, sip_pvt::ocseq, sip_pvt::pendinginvite, PIDF_XML, reqprep(), send_request(), SIP_NOTIFY, sip_pvt::subscribed, t, XMIT_RELIABLE, and XPIDF_XML.
Referenced by __sip_autodestruct(), cb_extensionstate(), and handle_request_subscribe().
07268 { 07269 char tmp[4000], from[256], to[256]; 07270 char *t = tmp, *c, *mfrom, *mto; 07271 size_t maxbytes = sizeof(tmp); 07272 struct sip_request req; 07273 char hint[AST_MAX_EXTENSION]; 07274 char *statestring = "terminated"; 07275 const struct cfsubscription_types *subscriptiontype; 07276 enum state { NOTIFY_OPEN, NOTIFY_INUSE, NOTIFY_CLOSED } local_state = NOTIFY_OPEN; 07277 char *pidfstate = "--"; 07278 char *pidfnote= "Ready"; 07279 07280 memset(from, 0, sizeof(from)); 07281 memset(to, 0, sizeof(to)); 07282 memset(tmp, 0, sizeof(tmp)); 07283 07284 switch (state) { 07285 case (AST_EXTENSION_RINGING | AST_EXTENSION_INUSE): 07286 statestring = (global_notifyringing) ? "early" : "confirmed"; 07287 local_state = NOTIFY_INUSE; 07288 pidfstate = "busy"; 07289 pidfnote = "Ringing"; 07290 break; 07291 case AST_EXTENSION_RINGING: 07292 statestring = "early"; 07293 local_state = NOTIFY_INUSE; 07294 pidfstate = "busy"; 07295 pidfnote = "Ringing"; 07296 break; 07297 case AST_EXTENSION_INUSE: 07298 statestring = "confirmed"; 07299 local_state = NOTIFY_INUSE; 07300 pidfstate = "busy"; 07301 pidfnote = "On the phone"; 07302 break; 07303 case AST_EXTENSION_BUSY: 07304 statestring = "confirmed"; 07305 local_state = NOTIFY_CLOSED; 07306 pidfstate = "busy"; 07307 pidfnote = "On the phone"; 07308 break; 07309 case AST_EXTENSION_UNAVAILABLE: 07310 statestring = "terminated"; 07311 local_state = NOTIFY_CLOSED; 07312 pidfstate = "away"; 07313 pidfnote = "Unavailable"; 07314 break; 07315 case AST_EXTENSION_ONHOLD: 07316 statestring = "confirmed"; 07317 local_state = NOTIFY_CLOSED; 07318 pidfstate = "busy"; 07319 pidfnote = "On Hold"; 07320 break; 07321 case AST_EXTENSION_NOT_INUSE: 07322 default: 07323 /* Default setting */ 07324 break; 07325 } 07326 07327 subscriptiontype = find_subscription_type(p->subscribed); 07328 07329 /* Check which device/devices we are watching and if they are registered */ 07330 if (ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, p->context, p->exten)) { 07331 char *hint2 = hint, *individual_hint = NULL; 07332 int hint_count = 0, unavailable_count = 0; 07333 07334 while ((individual_hint = strsep(&hint2, "&"))) { 07335 hint_count++; 07336 07337 if (ast_device_state(individual_hint) == AST_DEVICE_UNAVAILABLE) 07338 unavailable_count++; 07339 } 07340 07341 /* If none of the hinted devices are registered, we will 07342 * override notification and show no availability. 07343 */ 07344 if (hint_count > 0 && hint_count == unavailable_count) { 07345 local_state = NOTIFY_CLOSED; 07346 pidfstate = "away"; 07347 pidfnote = "Not online"; 07348 } 07349 } 07350 07351 ast_copy_string(from, get_header(&p->initreq, "From"), sizeof(from)); 07352 c = get_in_brackets(from); 07353 if (strncasecmp(c, "sip:", 4)) { 07354 ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", c); 07355 return -1; 07356 } 07357 mfrom = strsep(&c, ";"); /* trim ; and beyond */ 07358 07359 ast_copy_string(to, get_header(&p->initreq, "To"), sizeof(to)); 07360 c = get_in_brackets(to); 07361 if (strncasecmp(c, "sip:", 4)) { 07362 ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", c); 07363 return -1; 07364 } 07365 mto = strsep(&c, ";"); /* trim ; and beyond */ 07366 07367 reqprep(&req, p, SIP_NOTIFY, 0, 1); 07368 07369 07370 add_header(&req, "Event", subscriptiontype->event); 07371 add_header(&req, "Content-Type", subscriptiontype->mediatype); 07372 switch(state) { 07373 case AST_EXTENSION_DEACTIVATED: 07374 if (timeout) 07375 add_header(&req, "Subscription-State", "terminated;reason=timeout"); 07376 else { 07377 add_header(&req, "Subscription-State", "terminated;reason=probation"); 07378 add_header(&req, "Retry-After", "60"); 07379 } 07380 break; 07381 case AST_EXTENSION_REMOVED: 07382 add_header(&req, "Subscription-State", "terminated;reason=noresource"); 07383 break; 07384 default: 07385 if (p->expiry) 07386 add_header(&req, "Subscription-State", "active"); 07387 else /* Expired */ 07388 add_header(&req, "Subscription-State", "terminated;reason=timeout"); 07389 } 07390 switch (p->subscribed) { 07391 case XPIDF_XML: 07392 case CPIM_PIDF_XML: 07393 ast_build_string(&t, &maxbytes, "<?xml version=\"1.0\"?>\n"); 07394 ast_build_string(&t, &maxbytes, "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n"); 07395 ast_build_string(&t, &maxbytes, "<presence>\n"); 07396 ast_build_string(&t, &maxbytes, "<presentity uri=\"%s;method=SUBSCRIBE\" />\n", mfrom); 07397 ast_build_string(&t, &maxbytes, "<atom id=\"%s\">\n", p->exten); 07398 ast_build_string(&t, &maxbytes, "<address uri=\"%s;user=ip\" priority=\"0.800000\">\n", mto); 07399 ast_build_string(&t, &maxbytes, "<status status=\"%s\" />\n", (local_state == NOTIFY_OPEN) ? "open" : (local_state == NOTIFY_INUSE) ? "inuse" : "closed"); 07400 ast_build_string(&t, &maxbytes, "<msnsubstatus substatus=\"%s\" />\n", (local_state == NOTIFY_OPEN) ? "online" : (local_state == NOTIFY_INUSE) ? "onthephone" : "offline"); 07401 ast_build_string(&t, &maxbytes, "</address>\n</atom>\n</presence>\n"); 07402 break; 07403 case PIDF_XML: /* Eyebeam supports this format */ 07404 ast_build_string(&t, &maxbytes, "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"); 07405 ast_build_string(&t, &maxbytes, "<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); 07406 ast_build_string(&t, &maxbytes, "<pp:person><status>\n"); 07407 if (pidfstate[0] != '-') 07408 ast_build_string(&t, &maxbytes, "<ep:activities><ep:%s/></ep:activities>\n", pidfstate); 07409 ast_build_string(&t, &maxbytes, "</status></pp:person>\n"); 07410 ast_build_string(&t, &maxbytes, "<note>%s</note>\n", pidfnote); /* Note */ 07411 ast_build_string(&t, &maxbytes, "<tuple id=\"%s\">\n", p->exten); /* Tuple start */ 07412 ast_build_string(&t, &maxbytes, "<contact priority=\"1\">%s</contact>\n", mto); 07413 if (pidfstate[0] == 'b') /* Busy? Still open ... */ 07414 ast_build_string(&t, &maxbytes, "<status><basic>open</basic></status>\n"); 07415 else 07416 ast_build_string(&t, &maxbytes, "<status><basic>%s</basic></status>\n", (local_state != NOTIFY_CLOSED) ? "open" : "closed"); 07417 ast_build_string(&t, &maxbytes, "</tuple>\n</presence>\n"); 07418 break; 07419 case DIALOG_INFO_XML: /* SNOM subscribes in this format */ 07420 ast_build_string(&t, &maxbytes, "<?xml version=\"1.0\"?>\n"); 07421 ast_build_string(&t, &maxbytes, "<dialog-info xmlns=\"urn:ietf:params:xml:ns:dialog-info\" version=\"%d\" state=\"%s\" entity=\"%s\">\n", p->dialogver++, full ? "full":"partial", mto); 07422 if ((state & AST_EXTENSION_RINGING) && global_notifyringing) 07423 ast_build_string(&t, &maxbytes, "<dialog id=\"%s\" direction=\"recipient\">\n", p->exten); 07424 else 07425 ast_build_string(&t, &maxbytes, "<dialog id=\"%s\">\n", p->exten); 07426 ast_build_string(&t, &maxbytes, "<state>%s</state>\n", statestring); 07427 if (state == AST_EXTENSION_ONHOLD) { 07428 ast_build_string(&t, &maxbytes, "<local>\n<target uri=\"%s\">\n" 07429 "<param pname=\"+sip.rendering\" pvalue=\"no\"/>\n" 07430 "</target>\n</local>\n", mto); 07431 } 07432 ast_build_string(&t, &maxbytes, "</dialog>\n</dialog-info>\n"); 07433 break; 07434 case NONE: 07435 default: 07436 break; 07437 } 07438 07439 if (t > tmp + sizeof(tmp)) 07440 ast_log(LOG_WARNING, "Buffer overflow detected!! (Please file a bug report)\n"); 07441 07442 add_header_contentLength(&req, strlen(tmp)); 07443 add_line(&req, tmp); 07444 p->pendinginvite = p->ocseq; /* Remember that we have a pending NOTIFY in order not to confuse the NOTIFY subsystem */ 07445 07446 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 07447 }
| static void try_suggested_sip_codec | ( | struct sip_pvt * | p | ) | [static] |
Try setting codec suggested by the SIP_CODEC channel variable.
Definition at line 3681 of file chan_sip.c.
References ast_getformatbyname(), ast_log(), sip_pvt::capability, sip_pvt::jointcapability, LOG_NOTICE, sip_pvt::owner, and pbx_builtin_getvar_helper().
Referenced by sip_answer(), and transmit_response_with_sdp().
03682 { 03683 int fmt; 03684 const char *codec; 03685 03686 codec = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC"); 03687 if (!codec) 03688 return; 03689 03690 fmt = ast_getformatbyname(codec); 03691 if (fmt) { 03692 ast_log(LOG_NOTICE, "Changing codec to '%s' for this call because of ${SIP_CODEC} variable\n", codec); 03693 if (p->jointcapability & fmt) { 03694 p->jointcapability &= fmt; 03695 p->capability &= fmt; 03696 } else 03697 ast_log(LOG_NOTICE, "Ignoring ${SIP_CODEC} variable because it is not shared by both ends.\n"); 03698 } else 03699 ast_log(LOG_NOTICE, "Ignoring ${SIP_CODEC} variable because of unrecognized/not configured codec (check allow/disallow in sip.conf): %s\n", codec); 03700 return; 03701 }
| static int unload_module | ( | void | ) | [static] |
PBX unload module API.
Definition at line 18703 of file chan_sip.c.
References __sip_destroy(), ast_channel_unregister(), ast_cli_unregister_multiple(), ast_custom_function_unregister(), ast_free_ha(), ast_manager_unregister(), ast_mutex_lock(), ast_mutex_unlock(), AST_PTHREADT_NULL, AST_PTHREADT_STOP, ast_rtp_proto_unregister(), ast_softhangup(), AST_SOFTHANGUP_APPUNLOAD, ast_udptl_proto_unregister(), ast_unregister_application(), ASTOBJ_CONTAINER_DESTROY, ASTOBJ_CONTAINER_DESTROYALL, checksipdomain_function, clear_realm_authentication(), clear_sip_domains(), iflist, iflock, monlock, sip_pvt::next, sip_pvt::owner, peerl, regl, sched_context_destroy(), sip_destroy_peer(), sip_destroy_user(), sip_header_function, sip_registry_destroy(), sipchaninfo_function, sippeer_function, TRUE, and userl.
18704 { 18705 struct sip_pvt *p, *pl; 18706 18707 /* First, take us out of the channel type list */ 18708 ast_channel_unregister(&sip_tech); 18709 18710 /* Unregister dial plan functions */ 18711 ast_custom_function_unregister(&sipchaninfo_function); 18712 ast_custom_function_unregister(&sippeer_function); 18713 ast_custom_function_unregister(&sip_header_function); 18714 ast_custom_function_unregister(&checksipdomain_function); 18715 18716 /* Unregister dial plan applications */ 18717 ast_unregister_application(app_dtmfmode); 18718 ast_unregister_application(app_sipaddheader); 18719 18720 /* Unregister CLI commands */ 18721 ast_cli_unregister_multiple(cli_sip, sizeof(cli_sip) / sizeof(struct ast_cli_entry)); 18722 18723 /* Disconnect from the RTP subsystem */ 18724 ast_rtp_proto_unregister(&sip_rtp); 18725 18726 /* Disconnect from UDPTL */ 18727 ast_udptl_proto_unregister(&sip_udptl); 18728 18729 /* Unregister AMI actions */ 18730 ast_manager_unregister("SIPpeers"); 18731 ast_manager_unregister("SIPshowpeer"); 18732 18733 ast_mutex_lock(&iflock); 18734 /* Hangup all interfaces if they have an owner */ 18735 for (p = iflist; p ; p = p->next) { 18736 if (p->owner) 18737 ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD); 18738 } 18739 ast_mutex_unlock(&iflock); 18740 18741 ast_mutex_lock(&monlock); 18742 if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) { 18743 pthread_cancel(monitor_thread); 18744 pthread_kill(monitor_thread, SIGURG); 18745 pthread_join(monitor_thread, NULL); 18746 } 18747 monitor_thread = AST_PTHREADT_STOP; 18748 ast_mutex_unlock(&monlock); 18749 18750 restartdestroy: 18751 ast_mutex_lock(&iflock); 18752 /* Destroy all the interfaces and free their memory */ 18753 p = iflist; 18754 while (p) { 18755 pl = p; 18756 p = p->next; 18757 if (__sip_destroy(pl, TRUE) < 0) { 18758 /* Something is still bridged, let it react to getting a hangup */ 18759 iflist = p; 18760 ast_mutex_unlock(&iflock); 18761 usleep(1); 18762 goto restartdestroy; 18763 } 18764 } 18765 iflist = NULL; 18766 ast_mutex_unlock(&iflock); 18767 18768 /* Free memory for local network address mask */ 18769 ast_free_ha(localaddr); 18770 18771 ASTOBJ_CONTAINER_DESTROYALL(&userl, sip_destroy_user); 18772 ASTOBJ_CONTAINER_DESTROY(&userl); 18773 ASTOBJ_CONTAINER_DESTROYALL(&peerl, sip_destroy_peer); 18774 ASTOBJ_CONTAINER_DESTROY(&peerl); 18775 ASTOBJ_CONTAINER_DESTROYALL(®l, sip_registry_destroy); 18776 ASTOBJ_CONTAINER_DESTROY(®l); 18777 18778 clear_realm_authentication(authl); 18779 clear_sip_domains(); 18780 close(sipsock); 18781 sched_context_destroy(sched); 18782 18783 return 0; 18784 }
| static int update_call_counter | ( | struct sip_pvt * | fup, | |
| int | event | |||
| ) | [static] |
update_call_counter: Handle call_limit for SIP users 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 propably update storage with inuse counter...
Definition at line 3233 of file chan_sip.c.
References ast_clear_flag, ast_copy_string(), ast_device_state_changed(), ast_log(), ast_set_flag, ast_strlen_zero(), ast_test_flag, ASTOBJ_UNREF, sip_peer::call_limit, sip_user::call_limit, DEC_CALL_LIMIT, DEC_CALL_RINGING, FALSE, find_peer(), find_user(), sip_peer::flags, sip_pvt::flags, INC_CALL_LIMIT, INC_CALL_RINGING, sip_peer::inRinging, sip_peer::inUse, sip_user::inUse, inuse, LOG_DEBUG, LOG_ERROR, LOG_WARNING, sip_peer::name, name, option_debug, sip_pvt::peername, SIP_CALL_LIMIT, sip_destroy_peer(), sip_destroy_user(), SIP_INC_COUNT, SIP_PAGE2_CALL_ONHOLD, SIP_PAGE2_INC_RINGING, SIP_PAGE2_OUTGOING_CALL, SIP_PAGE2_RTCACHEFRIENDS, sip_peer_hold(), SIP_REALTIME, sipdebug, and sip_pvt::username.
Referenced by __sip_destroy(), handle_request_cancel(), handle_request_invite(), handle_response_invite(), sip_call(), and sip_hangup().
03234 { 03235 char name[256]; 03236 int *inuse = NULL, *call_limit = NULL, *inringing = NULL; 03237 int outgoing = ast_test_flag(&fup->flags[1], SIP_PAGE2_OUTGOING_CALL); 03238 struct sip_user *u = NULL; 03239 struct sip_peer *p = NULL; 03240 03241 if (option_debug > 2) 03242 ast_log(LOG_DEBUG, "Updating call counter for %s call\n", outgoing ? "outgoing" : "incoming"); 03243 03244 /* Test if we need to check call limits, in order to avoid 03245 realtime lookups if we do not need it */ 03246 if (!ast_test_flag(&fup->flags[0], SIP_CALL_LIMIT) && !ast_test_flag(&fup->flags[1], SIP_PAGE2_CALL_ONHOLD)) 03247 return 0; 03248 03249 ast_copy_string(name, fup->username, sizeof(name)); 03250 03251 /* Check the list of users only for incoming calls */ 03252 if (global_limitonpeers == FALSE && !outgoing && (u = find_user(name, 1))) { 03253 inuse = &u->inUse; 03254 call_limit = &u->call_limit; 03255 inringing = NULL; 03256 } else if ( (p = find_peer(ast_strlen_zero(fup->peername) ? name : fup->peername, NULL, 1, 0) ) ) { /* Try to find peer */ 03257 inuse = &p->inUse; 03258 call_limit = &p->call_limit; 03259 inringing = &p->inRinging; 03260 ast_copy_string(name, fup->peername, sizeof(name)); 03261 } 03262 if (!p && !u) { 03263 if (option_debug > 1) 03264 ast_log(LOG_DEBUG, "%s is not a local device, no call limit\n", name); 03265 return 0; 03266 } 03267 03268 switch(event) { 03269 /* incoming and outgoing affects the inUse counter */ 03270 case DEC_CALL_LIMIT: 03271 if ( *inuse > 0 ) { 03272 if (ast_test_flag(&fup->flags[0], SIP_INC_COUNT)) { 03273 (*inuse)--; 03274 ast_clear_flag(&fup->flags[0], SIP_INC_COUNT); 03275 } 03276 } else { 03277 *inuse = 0; 03278 } 03279 if (inringing) { 03280 if (ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) { 03281 if (*inringing > 0) 03282 (*inringing)--; 03283 else if (!ast_test_flag(&p->flags[0], SIP_REALTIME) || ast_test_flag(&p->flags[1], SIP_PAGE2_RTCACHEFRIENDS)) 03284 ast_log(LOG_WARNING, "Inringing for peer '%s' < 0?\n", fup->peername); 03285 ast_clear_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING); 03286 } 03287 } 03288 if (ast_test_flag(&fup->flags[1], SIP_PAGE2_CALL_ONHOLD) && global_notifyhold) { 03289 ast_clear_flag(&fup->flags[1], SIP_PAGE2_CALL_ONHOLD); 03290 sip_peer_hold(fup, 0); 03291 } 03292 if (option_debug > 1 || sipdebug) { 03293 ast_log(LOG_DEBUG, "Call %s %s '%s' removed from call limit %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit); 03294 } 03295 break; 03296 03297 case INC_CALL_RINGING: 03298 case INC_CALL_LIMIT: 03299 if (*call_limit > 0 ) { 03300 if (*inuse >= *call_limit) { 03301 ast_log(LOG_ERROR, "Call %s %s '%s' rejected due to usage limit of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit); 03302 if (u) 03303 ASTOBJ_UNREF(u, sip_destroy_user); 03304 else 03305 ASTOBJ_UNREF(p, sip_destroy_peer); 03306 return -1; 03307 } 03308 } 03309 if (inringing && (event == INC_CALL_RINGING)) { 03310 if (!ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) { 03311 (*inringing)++; 03312 ast_set_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING); 03313 } 03314 } 03315 /* Continue */ 03316 (*inuse)++; 03317 ast_set_flag(&fup->flags[0], SIP_INC_COUNT); 03318 if (option_debug > 1 || sipdebug) { 03319 ast_log(LOG_DEBUG, "Call %s %s '%s' is %d out of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *inuse, *call_limit); 03320 } 03321 break; 03322 03323 case DEC_CALL_RINGING: 03324 if (inringing) { 03325 if (ast_test_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING)) { 03326 if (*inringing > 0) 03327 (*inringing)--; 03328 else if (!ast_test_flag(&p->flags[0], SIP_REALTIME) || ast_test_flag(&p->flags[1], SIP_PAGE2_RTCACHEFRIENDS)) 03329 ast_log(LOG_WARNING, "Inringing for peer '%s' < 0?\n", p->name); 03330 ast_clear_flag(&fup->flags[1], SIP_PAGE2_INC_RINGING); 03331 } 03332 } 03333 break; 03334 03335 default: 03336 ast_log(LOG_ERROR, "update_call_counter(%s, %d) called with no event!\n", name, event); 03337 } 03338 if (p) { 03339 ast_device_state_changed("SIP/%s", p->name); 03340 ASTOBJ_UNREF(p, sip_destroy_peer); 03341 } else /* u must be set */ 03342 ASTOBJ_UNREF(u, sip_destroy_user); 03343 return 0; 03344 }
| static void update_peer | ( | struct sip_peer * | p, | |
| int | expiry | |||
| ) | [static] |
Update peer data in database (if used).
Definition at line 2514 of file chan_sip.c.
References sip_peer::addr, ast_test_flag, sip_peer::flags, sip_peer::fullcontact, sip_peer::name, realtime_update_peer(), SIP_PAGE2_RTCACHEFRIENDS, SIP_PAGE2_RTUPDATE, SIP_REALTIME, and sip_peer::username.
Referenced by register_verify().
02515 { 02516 int rtcachefriends = ast_test_flag(&p->flags[1], SIP_PAGE2_RTCACHEFRIENDS); 02517 if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTUPDATE) && 02518 (ast_test_flag(&p->flags[0], SIP_REALTIME) || rtcachefriends)) { 02519 realtime_update_peer(p->name, &p->addr, p->username, rtcachefriends ? p->fullcontact : NULL, expiry); 02520 } 02521 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Session Initiation Protocol (SIP)" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, } [static] |
Definition at line 18790 of file chan_sip.c.
struct in_addr __ourip [static] |
Definition at line 1223 of file chan_sip.c.
Referenced by reload_config(), sip_alloc(), sip_notify(), sip_poke_peer(), sip_request_call(), sip_send_mwi_to_peer(), transmit_register(), and transmit_response_using_temp().
int allow_external_domains [static] |
Accept calls to external SIP domains?
Definition at line 566 of file chan_sip.c.
int apeerobjs = 0 [static] |
Autocreated peer objects
Definition at line 586 of file chan_sip.c.
char* app_dtmfmode = "SIPDtmfMode" [static] |
Definition at line 18266 of file chan_sip.c.
char* app_sipaddheader = "SIPAddHeader" [static] |
Definition at line 18268 of file chan_sip.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 18790 of file chan_sip.c.
Authentication list for realm authentication
Definition at line 1212 of file chan_sip.c.
int autocreatepeer [static] |
Auto creation of peers at registration? Default off.
Definition at line 546 of file chan_sip.c.
struct sockaddr_in bindaddr = { 0, } [static] |
The address we bind to
Definition at line 1217 of file chan_sip.c.
struct ast_threadstorage check_auth_buf = { .once = PTHREAD_ONCE_INIT , .key_init = check_auth_buf_init , } [static] |
struct ast_custom_function checksipdomain_function [static] |
struct ast_cli_entry cli_sip[] [static] |
Definition at line 18539 of file chan_sip.c.
struct ast_cli_entry cli_sip_debug_deprecated [static] |
Initial value:
{ { "sip", "debug", NULL },
sip_do_debug_deprecated, "Enable SIP debugging",
debug_usage }
Definition at line 18529 of file chan_sip.c.
struct ast_cli_entry cli_sip_no_debug_deprecated [static] |
Initial value:
{ { "sip", "no", "debug", NULL },
sip_no_debug_deprecated, "Disable SIP debugging",
debug_usage }
Definition at line 18534 of file chan_sip.c.
int compactheaders [static] |
send compact sip headers
Definition at line 560 of file chan_sip.c.
const char config[] = "sip.conf" [static] |
Definition at line 232 of file chan_sip.c.
char debug_usage[] [static] |
Definition at line 11863 of file chan_sip.c.
struct sockaddr_in debugaddr [static] |
Definition at line 1226 of file chan_sip.c.
Referenced by sip_debug_test_addr(), sip_do_debug(), sip_do_debug_deprecated(), sip_do_debug_ip(), and sip_do_debug_peer().
char default_callerid[AST_MAX_EXTENSION] [static] |
Definition at line 526 of file chan_sip.c.
char default_context[AST_MAX_CONTEXT] [static] |
Definition at line 523 of file chan_sip.c.
int default_expiry = DEFAULT_DEFAULT_EXPIRY [static] |
Definition at line 193 of file chan_sip.c.
char default_fromdomain[AST_MAX_EXTENSION] [static] |
Definition at line 527 of file chan_sip.c.
struct ast_jb_conf default_jbconf [static] |
Global jitterbuffer configuration - by default, jb is disabled.
Definition at line 223 of file chan_sip.c.
char default_language[MAX_LANGUAGE] [static] |
Definition at line 525 of file chan_sip.c.
int default_maxcallbitrate [static] |
Maximum bitrate for call
Definition at line 534 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 531 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 532 of file chan_sip.c.
char default_notifymime[AST_MAX_EXTENSION] [static] |
Definition at line 528 of file chan_sip.c.
struct ast_codec_pref default_prefs [static] |
Default codec prefs
Definition at line 535 of file chan_sip.c.
Referenced by build_user(), reload_config(), set_peer_defaults(), sip_alloc(), sip_show_settings(), and temp_peer().
int default_qualify [static] |
Default Qualify= setting
Definition at line 529 of file chan_sip.c.
char default_subscribecontext[AST_MAX_CONTEXT] [static] |
Definition at line 524 of file chan_sip.c.
char default_vmexten[AST_MAX_EXTENSION] [static] |
Definition at line 530 of file chan_sip.c.
char* descrip_dtmfmode = "SIPDtmfMode(inband|info|rfc2833): Changes the dtmfmode for a SIP call\n" [static] |
Definition at line 18265 of file chan_sip.c.
char* descrip_sipaddheader [static] |
Definition at line 18271 of file chan_sip.c.
int dumphistory [static] |
Dump history to verbose before destroying SIP dialog
Definition at line 562 of file chan_sip.c.
int expiry = DEFAULT_EXPIRY [static] |
Definition at line 194 of file chan_sip.c.
Referenced by complete_dpreply(), process_clearcache(), and register_verify().
time_t externexpire = 0 [static] |
Expiration counter for re-resolving external host name in dynamic DNS
Definition at line 1220 of file chan_sip.c.
char externhost[MAXHOSTNAMELEN] [static] |
External host name (possibly with dynamic DNS and DHCP
Definition at line 1219 of file chan_sip.c.
struct sockaddr_in externip [static] |
External IP address if we are behind NAT
Definition at line 1218 of file chan_sip.c.
Referenced by ast_sip_ouraddrfor(), and reload_config().
int externrefresh = 10 [static] |
Definition at line 1221 of file chan_sip.c.
int global_allowguest [static] |
allow unauthenticated users/peers to connect?
Definition at line 553 of file chan_sip.c.
int global_allowsubscribe [static] |
Flag for disabling ALL subscriptions, this is FALSE only if all peers are FALSE the global setting is in globals_flags[1]
Definition at line 554 of file chan_sip.c.
enum transfermodes global_allowtransfer [static] |
SIP Refer restriction scheme
Definition at line 570 of file chan_sip.c.
int global_alwaysauthreject [static] |
Send 401 Unauthorized for all failing requests
Definition at line 543 of file chan_sip.c.
int global_autoframing [static] |
Turn autoframing on or off.
Definition at line 569 of file chan_sip.c.
int global_callevents [static] |
Whether we send manager events or not
Definition at line 567 of file chan_sip.c.
int global_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_GSM | AST_FORMAT_H263 [static] |
struct ast_ha* global_contact_ha = NULL [static] |
Global list of addresses dynamic peers are not allowed to use.
Definition at line 578 of file chan_sip.c.
int global_directrtpsetup [static] |
Enable support for Direct RTP setup (no re-invites)
Definition at line 538 of file chan_sip.c.
int global_dynamic_exclude_static = 0 [static] |
Definition at line 579 of file chan_sip.c.
struct ast_flags global_flags[2] = {{0}} [static] |
global SIP_ flags
Definition at line 589 of file chan_sip.c.
struct ast_jb_conf global_jbconf [static] |
Definition at line 230 of file chan_sip.c.
Referenced by reload_config(), sip_get_rtp_peer(), sip_new(), and sip_show_settings().
int global_limitonpeers [static] |
Match call limit on peers only
Definition at line 539 of file chan_sip.c.
int global_matchexterniplocally [static] |
Match externip/externhost setting against localnet setting
Definition at line 572 of file chan_sip.c.
int global_mwitime [static] |
Time between MWI checks for peers
Definition at line 556 of file chan_sip.c.
int global_notifyhold [static] |
Send notifications on hold
Definition at line 542 of file chan_sip.c.
int global_notifyringing [static] |
Send notifications on ringing
Definition at line 541 of file chan_sip.c.
char global_realm[MAXHOSTNAMELEN] [static] |
Default realm
Definition at line 563 of file chan_sip.c.
int global_reg_timeout [static] |
Definition at line 551 of file chan_sip.c.
int global_regattempts_max [static] |
Registration attempts before giving up
Definition at line 552 of file chan_sip.c.
char global_regcontext[AST_MAX_CONTEXT] [static] |
Context for auto-extensions
Definition at line 564 of file chan_sip.c.
int global_relaxdtmf [static] |
Relax DTMF
Definition at line 547 of file chan_sip.c.
int global_rtautoclear [static] |
Definition at line 540 of file chan_sip.c.
int global_rtpholdtimeout [static] |
Definition at line 549 of file chan_sip.c.
int global_rtpkeepalive [static] |
Send RTP keepalives
Definition at line 550 of file chan_sip.c.
int global_rtptimeout [static] |
Time out call if no RTP
Definition at line 548 of file chan_sip.c.
int global_t1min [static] |
T1 roundtrip time minimum
Definition at line 568 of file chan_sip.c.
int global_t38_capability = T38FAX_VERSION_0 | T38FAX_RATE_2400 | T38FAX_RATE_4800 | T38FAX_RATE_7200 | T38FAX_RATE_9600 [static] |
Definition at line 840 of file chan_sip.c.
unsigned int global_tos_audio [static] |
IP type of service for audio RTP packets
Definition at line 558 of file chan_sip.c.
unsigned int global_tos_sip [static] |
IP type of service for SIP packets
Definition at line 557 of file chan_sip.c.
unsigned int global_tos_video [static] |
IP type of service for video RTP packets
Definition at line 559 of file chan_sip.c.
char global_useragent[AST_MAX_EXTENSION] [static] |
Useragent for the SIP channel
Definition at line 565 of file chan_sip.c.
char history_usage[] [static] |
Initial value:
"Usage: sip history\n" " Enables recording of SIP dialog history for debugging purposes.\n" "Use 'sip show history' to view the history of a call number.\n"
Definition at line 11880 of file chan_sip.c.
sip_pvt: PVT structures are used for each SIP dialog, ie. a call, a registration, a subscribe
ast_mutex_t iflock = ((ast_mutex_t) PTHREAD_MUTEX_INITIALIZER ) [static] |
Protect the SIP dialog list (of sip_pvt's).
Definition at line 592 of file chan_sip.c.
Referenced by __sip_show_channels(), complete_sipch(), do_monitor(), find_call(), get_sip_pvt_byid_locked(), handle_request_subscribe(), sip_alloc(), sip_destroy(), sip_show_channel(), sip_show_history(), and unload_module().
struct io_context* io [static] |
The IO context
Definition at line 610 of file chan_sip.c.
List of local networks, on the same side of NAT as this Asterisk
Definition at line 1222 of file chan_sip.c.
char mandescr_show_peer[] [static] |
Initial value:
"Description: Show one SIP peer with details on current status.\n" "Variables: \n" " Peer: <name> The peer name you want to check.\n" " ActionID: <id> Optional action ID for this AMI transaction.\n"
Definition at line 10495 of file chan_sip.c.
char mandescr_show_peers[] [static] |
Initial value:
"Description: Lists SIP peers in text format with details on current status.\n" "Variables: \n" " ActionID: <id> Action ID for this transaction. Will be returned.\n"
Definition at line 10046 of file chan_sip.c.
int max_expiry = DEFAULT_MAX_EXPIRY [static] |
Maximum accepted registration time
Definition at line 192 of file chan_sip.c.
int min_expiry = DEFAULT_MIN_EXPIRY [static] |
Minimum accepted registration time
Definition at line 191 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 604 of file chan_sip.c.
ast_mutex_t monlock = ((ast_mutex_t) PTHREAD_MUTEX_INITIALIZER ) [static] |
ast_mutex_t netlock = ((ast_mutex_t) PTHREAD_MUTEX_INITIALIZER ) [static] |
Protect the monitoring thread, so only one process can kill or start it, and not when it's doing something critical.
Definition at line 596 of file chan_sip.c.
Referenced by reload_config(), and sipsock_read().
char no_debug_usage[] [static] |
Initial value:
"Usage: sip set debug off\n" " Disables dumping of SIP packets for debugging purposes\n"
Definition at line 11872 of file chan_sip.c.
char no_history_usage[] [static] |
Initial value:
"Usage: sip history off\n" " Disables recording of SIP dialog history for debugging purposes\n"
Definition at line 11876 of file chan_sip.c.
const char notify_config[] = "sip_notify.conf" [static] |
Definition at line 233 of file chan_sip.c.
struct ast_config* notify_types [static] |
The list of manual NOTIFY types we know how to send
Definition at line 1228 of file chan_sip.c.
char notify_usage[] [static] |
Initial value:
"Usage: sip notify <type> <peer> [<peer>...]\n" " Send a NOTIFY message to a SIP peer or peers\n" " Message types are defined in sip_notify.conf\n"
Definition at line 11812 of file chan_sip.c.
int ourport [static] |
Definition at line 1225 of file chan_sip.c.
struct sockaddr_in outboundproxyip [static] |
int pedanticsipchecking [static] |
Extra checking ? Default off
Definition at line 545 of file chan_sip.c.
struct ast_peer_list peerl [static] |
The peer list: Peers and Friends.
Referenced by _sip_show_peers(), build_peer(), complete_sip_peer(), do_monitor(), expire_register(), find_peer(), load_module(), realtime_peer(), register_verify(), reload_config(), sip_do_reload(), sip_poke_all_peers(), sip_prune_realtime(), sip_show_inuse(), sip_show_objects(), and unload_module().
char prune_realtime_usage[] [static] |
Initial value:
"Usage: sip prune realtime [peer|user] [<name>|all|like <pattern>]\n" " Prunes object(s) from the cache.\n" " Optional regular expression pattern is used to filter the objects.\n"
Definition at line 11854 of file chan_sip.c.
int recordhistory [static] |
Record SIP history. Off by default
Definition at line 561 of file chan_sip.c.
struct c_referstatusstring referstatusstrings[] [static] |
Referenced by referstatus2str().
struct ast_register_list regl [static] |
The register list: Other SIP proxys we register with and place calls to.
Referenced by load_module(), 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 587 of file chan_sip.c.
int rpeerobjs = 0 [static] |
Realtime peers
Definition at line 585 of file chan_sip.c.
int ruserobjs = 0 [static] |
Realtime users
Definition at line 583 of file chan_sip.c.
struct sched_context* sched [static] |
The scheduling context
Definition at line 609 of file chan_sip.c.
char show_channel_usage[] [static] |
Initial value:
"Usage: sip show channel <channel>\n" " Provides detailed status on a given SIP channel.\n"
Definition at line 11836 of file chan_sip.c.
char show_channels_usage[] [static] |
Initial value:
"Usage: sip show channels\n" " Lists all currently active SIP channels.\n"
Definition at line 11832 of file chan_sip.c.
char show_domains_usage[] [static] |
Initial value:
"Usage: sip show domains\n" " Lists all configured SIP local domains.\n" " Asterisk only responds to SIP messages to local domains.\n"
Definition at line 11807 of file chan_sip.c.
char show_history_usage[] [static] |
Initial value:
"Usage: sip show history <channel>\n" " Provides detailed dialog history on a given SIP channel.\n"
Definition at line 11840 of file chan_sip.c.
char show_inuse_usage[] [static] |
Initial value:
"Usage: sip show inuse [all]\n" " List all SIP users and peers usage counters and limits.\n" " Add option \"all\" to show all devices, not only those with a limit.\n"
Definition at line 11827 of file chan_sip.c.
char show_objects_usage[] [static] |
Initial value:
"Usage: sip show objects\n" " Lists status of known SIP objects\n"
Definition at line 11893 of file chan_sip.c.
char show_peer_usage[] [static] |
Initial value:
"Usage: sip show peer <name> [load]\n" " Shows all details on one SIP peer and the current status.\n" " Option \"load\" forces lookup of peer in realtime storage.\n"
Definition at line 11849 of file chan_sip.c.
char show_peers_usage[] [static] |
Initial value:
"Usage: sip show peers [like <pattern>]\n" " Lists all known SIP peers.\n" " Optional regular expression pattern is used to filter the peer list.\n"
Definition at line 11844 of file chan_sip.c.
char show_reg_usage[] [static] |
Initial value:
"Usage: sip show registry\n" " Lists all registration requests and status.\n"
Definition at line 11859 of file chan_sip.c.
char show_settings_usage[] [static] |
Initial value:
"Usage: sip show settings\n" " Provides detailed list of the configuration of the SIP channel.\n"
Definition at line 11897 of file chan_sip.c.
char show_subscriptions_usage[] [static] |
Initial value:
"Usage: sip show subscriptions\n" " Lists active SIP subscriptions for extension states\n"
Definition at line 11889 of file chan_sip.c.
char show_user_usage[] [static] |
Initial value:
"Usage: sip show user <name> [load]\n" " Shows all details on one SIP user and the current status.\n" " Option \"load\" forces lookup of peer in realtime storage.\n"
Definition at line 11822 of file chan_sip.c.
char show_users_usage[] [static] |
Initial value:
"Usage: sip show users [like <pattern>]\n" " Lists all known SIP users.\n" " Optional regular expression pattern is used to filter the user list.\n"
Definition at line 11817 of file chan_sip.c.
struct ast_custom_function sip_header_function [static] |
struct cfsip_methods sip_methods[] [static] |
XXX Note that sip_methods[i].id == i must hold or the code breaks
Referenced by __sip_ack(), __sip_autodestruct(), __sip_destroy(), __sip_pretend_ack(), __sip_semi_ack(), build_reply_digest(), check_auth(), do_proxy_auth(), find_call(), find_sip_method(), get_destination(), handle_request(), handle_request_subscribe(), handle_response(), init_req(), initreqprep(), method_match(), reqprep(), retrans_pkt(), send_request(), send_response(), sip_alloc(), sip_scheddestroy(), and transmit_register().
struct cfsip_options sip_options[] [static] |
List of well-known SIP options. If we get this in a require, we should check the list and answer accordingly.
Referenced by _sip_show_peer(), parse_sip_options(), and sip_show_channel().
ast_mutex_t sip_reload_lock = ((ast_mutex_t) PTHREAD_MUTEX_INITIALIZER ) [static] |
char sip_reload_usage[] [static] |
Initial value:
"Usage: sip reload\n" " Reloads SIP configuration from sip.conf\n"
Definition at line 11885 of file chan_sip.c.
int sip_reloading = FALSE [static] |
Flag for avoiding multiple reloads at the same time
Definition at line 606 of file chan_sip.c.
enum channelreloadreason sip_reloadreason [static] |
Reason for last reload/load of configuration
Definition at line 607 of file chan_sip.c.
struct ast_rtp_protocol sip_rtp [static] |
Interface structure with callbacks used to connect to RTP module.
Definition at line 1625 of file chan_sip.c.
struct ast_channel_tech sip_tech [static] |
Definition of this channel for PBX channel registration.
Definition at line 1567 of file chan_sip.c.
struct ast_channel_tech sip_tech_info [static] |
This version of the sip channel tech has no send_digit_begin callback. This is for use with channels using SIP INFO DTMF so that the core knows that the channel doesn't want DTMF BEGIN frames.
Definition at line 1593 of file chan_sip.c.
struct ast_udptl_protocol sip_udptl [static] |
Initial value:
{
type: "SIP",
get_udptl_info: sip_get_udptl_peer,
set_udptl_peer: sip_set_udptl_peer,
}
Definition at line 1634 of file chan_sip.c.
struct ast_custom_function sipchaninfo_function [static] |
Structure to declare a dialplan function: SIPCHANINFO.
Definition at line 12138 of file chan_sip.c.
Referenced by load_module(), and unload_module().
Structure to declare a dialplan function: SIPPEER.
Definition at line 12058 of file chan_sip.c.
Referenced by load_module(), and unload_module().
int sipsock = -1 [static] |
Main socket for SIP network communication
Definition at line 1216 of file chan_sip.c.
int* sipsock_read_id [static] |
ID of IO entry for sipsock FD
Definition at line 611 of file chan_sip.c.
int speerobjs = 0 [static] |
Statis peers
Definition at line 584 of file chan_sip.c.
int srvlookup [static] |
SRV Lookup on or off. Default is on
Definition at line 544 of file chan_sip.c.
struct cfsubscription_types subscription_types[] [static] |
Referenced by find_subscription_type(), and subscription_type2str().
int suserobjs = 0 [static] |
Static users
Definition at line 582 of file chan_sip.c.
char* synopsis_dtmfmode = "Change the dtmfmode for a SIP call" [static] |
Definition at line 18264 of file chan_sip.c.
char* synopsis_sipaddheader = "Add a SIP header to the outbound call" [static] |
Definition at line 18269 of file chan_sip.c.
struct ast_threadstorage ts_temp_pvt = { .once = PTHREAD_ONCE_INIT , .key_init = temp_pvt_init , } [static] |
struct ast_user_list userl [static] |
The user list: Users and friends.
Referenced by complete_sip_user(), find_user(), load_module(), realtime_user(), reload_config(), sip_prune_realtime(), sip_show_inuse(), sip_show_objects(), sip_show_users(), and unload_module().
1.5.9