Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions
dialog.h File Reference

sip dialog management header file More...

#include "sip.h"
Include dependency graph for dialog.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define dialog_ref(dialog, tag)   ao2_t_bump(dialog, tag)
 when we create or delete references, make sure to use these functions so we keep track of the refcounts. To simplify the code, we allow a NULL to be passed to dialog_unref(). More...
 
#define dialog_unref(dialog, tag)   ({ ao2_t_cleanup(dialog, tag); (NULL); })
 
#define sip_alloc(callid, addr, useglobal_nat, intended_method, req, logger_callid)   __sip_alloc(callid, addr, useglobal_nat, intended_method, req, logger_callid, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 

Functions

int __sip_ack (struct sip_pvt *p, uint32_t seqno, int resp, int sipmethod)
 Acknowledges receipt of a packet and stops retransmission called with p locked. More...
 
struct sip_pvt__sip_alloc (ast_string_field callid, struct ast_sockaddr *sin, int useglobal_nat, const int intended_method, struct sip_request *req, ast_callid logger_callid, const char *file, int line, const char *func)
 Allocate sip_pvt structure, set defaults and link in the container. Returns a reference to the object so whoever uses it later must remember to release the reference. More...
 
void __sip_pretend_ack (struct sip_pvt *p)
 Pretend to ack all packets called with p locked. More...
 
int __sip_semi_ack (struct sip_pvt *p, uint32_t seqno, int resp, int sipmethod)
 Acks receipt of packet, keep it around (used for provisional responses) More...
 
void dialog_unlink_all (struct sip_pvt *dialog)
 Unlink a dialog from the dialogs container, as well as any other places that it may be currently stored. More...
 
void sip_cancel_destroy (struct sip_pvt *pvt)
 Cancel destruction of SIP dialog. More...
 
void sip_scheddestroy (struct sip_pvt *p, int ms)
 Schedule destruction of SIP dialog. More...
 
void sip_scheddestroy_final (struct sip_pvt *p, int ms)
 Schedule final destruction of SIP dialog. More...
 

Detailed Description

sip dialog management header file

Definition in file dialog.h.

Macro Definition Documentation

◆ dialog_ref

#define dialog_ref (   dialog,
  tag 
)    ao2_t_bump(dialog, tag)

◆ dialog_unref

#define dialog_unref (   dialog,
  tag 
)    ({ ao2_t_cleanup(dialog, tag); (NULL); })

Definition at line 33 of file dialog.h.

Referenced by __cleanup_registration(), __dialog_unlink_sched_items(), __find_call(), __sched_check_pendings(), __sip_autodestruct(), __sip_cancel_destroy(), __sip_scheddestroy(), __sip_subscribe_mwi_do(), __start_session_timer(), __start_t38_abort_timer(), __stop_provisional_keepalive(), __stop_reinvite_retry(), __stop_reinviteid(), __stop_session_timer(), __stop_t38_abort_timer(), __update_provisional_keepalive_full(), AST_TEST_DEFINE(), auto_congest(), cb_extensionstate_destroy(), complete_sipch(), dialog_unlink_all(), do_cancel_destroy(), do_dialog_unlink_sched_items(), do_stop_session_timer(), forked_invite_init(), handle_request_subscribe(), handle_response_invite(), handle_response_peerpoke(), handle_response_register(), manager_sipnotify(), proc_session_timer(), reinvite_timeout(), sched_check_pendings(), send_provisional_keepalive_full(), sip_call(), sip_cancel_destroy(), sip_cc_agent_destructor(), sip_cli_notify(), sip_destroy_peer(), sip_hangup(), sip_monitor_instance_destructor(), sip_msg_send(), sip_pkt_dtor(), sip_poke_noanswer(), sip_poke_peer(), sip_pvt_dtor(), sip_reg_timeout(), sip_registry_destroy(), sip_reinvite_retry(), sip_request_call(), sip_scheddestroy_full(), sip_send_mwi_to_peer(), sip_subscribe_mwi_destroy(), sip_t38_abort(), start_session_timer(), start_t38_abort_timer(), stop_provisional_keepalive(), stop_reinvite_retry(), stop_reinviteid(), stop_session_timer(), stop_t38_abort_timer(), transmit_publish(), transmit_register(), and update_provisional_keepalive().

◆ sip_alloc

#define sip_alloc (   callid,
  addr,
  useglobal_nat,
  intended_method,
  req,
  logger_callid 
)    __sip_alloc(callid, addr, useglobal_nat, intended_method, req, logger_callid, __FILE__, __LINE__, __PRETTY_FUNCTION__)

Function Documentation

◆ __sip_ack()

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

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

Definition at line 4570 of file chan_sip.c.

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

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

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

◆ __sip_alloc()

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

Allocate sip_pvt structure, set defaults and link in the container. Returns a reference to the object so whoever uses it later must remember to release the reference.

Definition at line 8942 of file chan_sip.c.

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

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

◆ __sip_pretend_ack()

void __sip_pretend_ack ( struct sip_pvt p)

Pretend to ack all packets called with p locked.

Definition at line 4615 of file chan_sip.c.

References __sip_ack(), ast_log, ast_str_buffer(), sip_pkt::data, find_sip_method(), sip_pkt::is_resp, LOG_WARNING, sip_pkt::method, method, NULL, sip_pvt::packets, sip_pkt::seqno, sip_methods, and cfsip_methods::text.

Referenced by __sip_autodestruct(), handle_request_bye(), handle_request_cancel(), and sip_reg_timeout().

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

◆ __sip_semi_ack()

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

Acks receipt of packet, keep it around (used for provisional responses)

Definition at line 4632 of file chan_sip.c.

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

Referenced by handle_response(), and sip_hangup().

4633 {
4634  struct sip_pkt *cur;
4635  int res = FALSE;
4636 
4637  for (cur = p->packets; cur; cur = cur->next) {
4638  if (cur->seqno == seqno && cur->is_resp == resp &&
4639  (cur->is_resp || method_match(sipmethod, ast_str_buffer(cur->data)))) {
4640  /* this is our baby */
4641  if (cur->retransid > -1) {
4642  if (sipdebug)
4643  ast_debug(4, "*** SIP TIMER: Cancelling retransmission #%d - %s (got response)\n", cur->retransid, sip_methods[sipmethod].text);
4644  }
4645  stop_retrans_pkt(cur);
4646  res = TRUE;
4647  break;
4648  }
4649  }
4650  ast_debug(1, "(Provisional) Stopping retransmission (but retaining packet) on '%s' %s %u: %s\n", p->callid, resp ? "Response" : "Request", seqno, res == -1 ? "Not Found" : "Found");
4651  return res;
4652 }
sip packet - raw format for outbound packets that are sent or scheduled for transmission Packets are ...
Definition: sip.h:1231
#define FALSE
Definition: app_minivm.c:521
static void stop_retrans_pkt(struct sip_pkt *pkt)
Definition: chan_sip.c:4251
static const struct cfsip_methods sip_methods[]
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
uint32_t seqno
Definition: sip.h:1235
static int method_match(enum sipmethod id, const char *name)
returns true if 'name' (with optional trailing whitespace) matches the sip method 'id'...
Definition: chan_sip.c:3584
int retransid
Definition: sip.h:1240
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
sipmethod
SIP Request methods known by Asterisk.
Definition: sip.h:612
struct ast_str * data
Definition: sip.h:1246
const ast_string_field callid
Definition: sip.h:1063
char is_resp
Definition: sip.h:1236
static enum sip_debug_e sipdebug
Definition: chan_sip.c:916
struct sip_pkt * next
Definition: sip.h:1232
struct sip_pkt * packets
Definition: sip.h:1177
char *const text
Definition: chan_sip.c:737
#define TRUE
Definition: app_minivm.c:518

◆ dialog_unlink_all()

void dialog_unlink_all ( struct sip_pvt dialog)

Unlink a dialog from the dialogs container, as well as any other places that it may be currently stored.

Note
A reference to the dialog must be held before calling this function, and this function does not release that reference.
The dialog must not be locked when called.
A reference to the dialog must be held before calling this function, and this function does not release that reference.

Definition at line 3367 of file chan_sip.c.

References __dialog_unlink_sched_items(), ao2_t_replace, ao2_t_unlink, append_history_full(), ast_channel_name(), ast_channel_tech_pvt(), ast_channel_tech_pvt_set(), ast_channel_unlock, ast_channel_unref, ast_debug, ast_extension_state_del(), ast_sched_add(), sip_peer::call, sip_registry::call, cb_extensionstate(), dialog_ref, dialog_unref, do_dialog_unlink_sched_items(), format, sip_peer::mwipvt, NULL, sip_pvt::registry, sip_pvt::relatedpeer, sip_pvt_lock_full(), sip_pvt_unlock, sip_set_owner(), and sip_pvt::stateid.

Referenced by __cleanup_registration(), __sip_autodestruct(), __sip_subscribe_mwi_do(), AST_TEST_DEFINE(), dialog_needdestroy(), handle_request_subscribe(), manager_sipnotify(), sip_cli_notify(), sip_destroy_peer(), sip_msg_send(), sip_poke_noanswer(), sip_poke_peer(), sip_registry_destroy(), sip_request_call(), sip_send_mwi_to_peer(), transmit_publish(), transmit_register(), and unload_module().

3368 {
3369  struct ast_channel *owner;
3370 
3371  dialog_ref(dialog, "Let's bump the count in the unlink so it doesn't accidentally become dead before we are done");
3372 
3373  ao2_t_unlink(dialogs, dialog, "unlinking dialog via ao2_unlink");
3374  ao2_t_unlink(dialogs_needdestroy, dialog, "unlinking dialog_needdestroy via ao2_unlink");
3375  ao2_t_unlink(dialogs_rtpcheck, dialog, "unlinking dialog_rtpcheck via ao2_unlink");
3376 
3377  /* Unlink us from the owner (channel) if we have one */
3378  owner = sip_pvt_lock_full(dialog);
3379  if (owner) {
3380  ast_debug(1, "Detaching from channel %s\n", ast_channel_name(owner));
3381  ast_channel_tech_pvt_set(owner, dialog_unref(ast_channel_tech_pvt(owner), "resetting channel dialog ptr in unlink_all"));
3382  ast_channel_unlock(owner);
3383  ast_channel_unref(owner);
3384  sip_set_owner(dialog, NULL);
3385  }
3386  sip_pvt_unlock(dialog);
3387 
3388  if (dialog->registry) {
3389  if (dialog->registry->call == dialog) {
3390  dialog->registry->call = dialog_unref(dialog->registry->call, "nulling out the registry's call dialog field in unlink_all");
3391  }
3392  ao2_t_replace(dialog->registry, NULL, "delete dialog->registry");
3393  }
3394  if (dialog->stateid != -1) {
3396  dialog->stateid = -1;
3397  }
3398  /* Remove link from peer to subscription of MWI */
3399  if (dialog->relatedpeer && dialog->relatedpeer->mwipvt == dialog) {
3400  dialog->relatedpeer->mwipvt = dialog_unref(dialog->relatedpeer->mwipvt, "delete ->relatedpeer->mwipvt");
3401  }
3402  if (dialog->relatedpeer && dialog->relatedpeer->call == dialog) {
3403  dialog->relatedpeer->call = dialog_unref(dialog->relatedpeer->call, "unset the relatedpeer->call field in tandem with relatedpeer field itself");
3404  }
3405 
3406  dialog_ref(dialog, "Stop scheduled items for unlink action");
3407  if (ast_sched_add(sched, 0, __dialog_unlink_sched_items, dialog) < 0) {
3408  /*
3409  * Uh Oh. Fall back to unscheduling things immediately
3410  * despite the potential deadlock risk.
3411  */
3412  dialog_unref(dialog, "Failed to schedule stop scheduled items for unlink action");
3414  }
3415 
3416  dialog_unref(dialog, "Let's unbump the count in the unlink so the poor pvt can disappear if it is time");
3417 }
static struct ao2_container * dialogs
Definition: chan_sip.c:1043
Main Channel structure associated with a channel.
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
struct ao2_container * dialogs_needdestroy
Definition: chan_sip.c:1024
struct sip_peer * relatedpeer
Definition: sip.h:1171
struct sip_pvt * call
Definition: sip.h:1424
int ast_extension_state_del(int id, ast_state_cb_type change_cb)
Deletes a state change watcher by ID.
Definition: pbx.c:3858
Definition: sched.c:76
#define ao2_t_replace(dst, src, tag)
Replace one object reference with another cleaning up the original.
Definition: astobj2.h:503
#define ao2_t_unlink(container, obj, tag)
Remove an object from a container.
Definition: astobj2.h:1596
static void sip_set_owner(struct sip_pvt *p, struct ast_channel *chan)
Set the owning channel on the sip_pvt object.
Definition: chan_sip.c:9450
#define NULL
Definition: resample.c:96
#define sip_pvt_unlock(x)
Definition: chan_sip.c:1046
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
struct sip_registry * registry
Definition: sip.h:1173
static int __dialog_unlink_sched_items(const void *data)
Definition: chan_sip.c:3351
#define dialog_unref(dialog, tag)
Definition: dialog.h:33
static int cb_extensionstate(const char *context, const char *exten, struct ast_state_cb_info *info, void *data)
Callback for the devicestate notification (SUBSCRIBE) support subsystem.
Definition: chan_sip.c:17692
static struct ast_channel * sip_pvt_lock_full(struct sip_pvt *pvt)
Definition: chan_sip.c:9400
#define ast_channel_unlock(chan)
Definition: channel.h:2946
int stateid
Definition: sip.h:1162
#define dialog_ref(dialog, tag)
when we create or delete references, make sure to use these functions so we keep track of the refcoun...
Definition: dialog.h:32
int ast_sched_add(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result
Adds a scheduled event.
Definition: sched.c:565
struct sip_pvt * call
Definition: sip.h:1354
struct sip_pvt * mwipvt
Definition: sip.h:1367
const char * ast_channel_name(const struct ast_channel *chan)
static void do_dialog_unlink_sched_items(struct sip_pvt *dialog)
Definition: chan_sip.c:3308
struct ao2_container * dialogs_rtpcheck
Definition: chan_sip.c:1032
void ast_channel_tech_pvt_set(struct ast_channel *chan, void *value)

◆ sip_cancel_destroy()

void sip_cancel_destroy ( struct sip_pvt pvt)

Cancel destruction of SIP dialog.

Definition at line 4464 of file chan_sip.c.

References __sip_cancel_destroy(), ast_log, ast_sched_add(), dialog_ref, dialog_unref, sip_pvt::final_destruction_scheduled, and LOG_WARNING.

Referenced by handle_request_invite(), handle_request_subscribe(), handle_response(), handle_response_invite(), register_verify(), and sip_hangup().

4465 {
4466  if (pvt->final_destruction_scheduled) {
4467  return;
4468  }
4469 
4470  dialog_ref(pvt, "Cancel destroy action");
4471  if (ast_sched_add(sched, 0, __sip_cancel_destroy, pvt) < 0) {
4472  /* Uh Oh. Expect bad behavior. */
4473  dialog_unref(pvt, "Failed to schedule cancel destroy action");
4474  ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n");
4475  }
4476 }
#define LOG_WARNING
Definition: logger.h:274
Definition: sched.c:76
#define ast_log
Definition: astobj2.c:42
#define dialog_unref(dialog, tag)
Definition: dialog.h:33
unsigned short final_destruction_scheduled
Definition: sip.h:1081
#define dialog_ref(dialog, tag)
when we create or delete references, make sure to use these functions so we keep track of the refcoun...
Definition: dialog.h:32
int ast_sched_add(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result
Adds a scheduled event.
Definition: sched.c:565
static int __sip_cancel_destroy(const void *data)
Definition: chan_sip.c:4453

◆ sip_scheddestroy()

void sip_scheddestroy ( struct sip_pvt p,
int  ms 
)

◆ sip_scheddestroy_final()

void sip_scheddestroy_final ( struct sip_pvt p,
int  ms 
)

Schedule final destruction of SIP dialog.

Note
This cannot be canceled.

This function is used to keep a dialog around for a period of time in order to properly respond to any retransmits.

Definition at line 4557 of file chan_sip.c.

References sip_pvt::final_destruction_scheduled, and sip_scheddestroy_full().

Referenced by handle_request_bye().

4558 {
4559  if (p->final_destruction_scheduled) {
4560  return; /* already set final destruction */
4561  }
4562 
4563  if (!sip_scheddestroy_full(p, ms)) {
4565  }
4566 }
unsigned short final_destruction_scheduled
Definition: sip.h:1081
static int sip_scheddestroy_full(struct sip_pvt *p, int ms)
Definition: chan_sip.c:4514