Asterisk - The Open Source Telephony Project  21.4.1
Data Structures | Functions | Variables
dialplan_functions.c File Reference

PJSIP channel dialplan functions. More...

#include "asterisk.h"
#include <pjsip.h>
#include <pjlib.h>
#include <pjsip_ua.h>
#include "asterisk/astobj2.h"
#include "asterisk/module.h"
#include "asterisk/acl.h"
#include "asterisk/app.h"
#include "asterisk/conversions.h"
#include "asterisk/channel.h"
#include "asterisk/stream.h"
#include "asterisk/format.h"
#include "asterisk/dsp.h"
#include "asterisk/pbx.h"
#include "asterisk/res_pjsip.h"
#include "asterisk/res_pjsip_session.h"
#include "include/chan_pjsip.h"
#include "include/dialplan_functions.h"

Go to the source code of this file.

Data Structures

struct  hangup_data
 
struct  media_offer_data
 
struct  parse_uri_args
 Struct used to push PJSIP_PARSE_URI function arguments to task processor. More...
 
struct  pjsip_func_args
 Struct used to push function arguments to task processor. More...
 
struct  refresh_data
 
struct  session_refresh_state
 Session refresh state information. More...
 

Functions

static int channel_read_pjsip (struct ast_channel *chan, const char *type, const char *field, char *buf, size_t buflen)
 
static int channel_read_rtcp (struct ast_channel *chan, const char *type, const char *field, char *buf, size_t buflen)
 
static int channel_read_rtp (struct ast_channel *chan, const char *type, const char *field, char *buf, size_t buflen)
 
static int dtmf_mode_refresh_cb (void *obj)
 
static int media_offer_read_av (struct ast_sip_session *session, char *buf, size_t len, enum ast_media_type media_type)
 
static int media_offer_write_av (void *obj)
 
static int parse_uri_cb (void *data)
 
int pjsip_acf_channel_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 CHANNEL function read callback. More...
 
int pjsip_acf_dial_contacts_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 PJSIP_DIAL_CONTACTS function read callback. More...
 
int pjsip_acf_dtmf_mode_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 PJSIP_DTMF_MODE function read callback. More...
 
int pjsip_acf_dtmf_mode_write (struct ast_channel *chan, const char *cmd, char *data, const char *value)
 PJSIP_DTMF_MODE function write callback. More...
 
int pjsip_acf_media_offer_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 PJSIP_MEDIA_OFFER function read callback. More...
 
int pjsip_acf_media_offer_write (struct ast_channel *chan, const char *cmd, char *data, const char *value)
 PJSIP_MEDIA_OFFER function write callback. More...
 
int pjsip_acf_moh_passthrough_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 PJSIP_MOH_PASSTHROUGH function read callback. More...
 
int pjsip_acf_moh_passthrough_write (struct ast_channel *chan, const char *cmd, char *data, const char *value)
 PJSIP_MOH_PASSTHROUGH function write callback. More...
 
int pjsip_acf_parse_uri_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
 PJSIP_PARSE_URI function read callback. More...
 
int pjsip_acf_session_refresh_write (struct ast_channel *chan, const char *cmd, char *data, const char *value)
 PJSIP_SEND_SESSION_REFRESH function write callback. More...
 
int pjsip_action_hangup (struct mansession *s, const struct message *m)
 PJSIPHangup Manager Action. More...
 
int pjsip_app_hangup (struct ast_channel *chan, const char *data)
 PJSIPHangup Dialplan App. More...
 
static void pjsip_app_hangup_handler (struct ast_channel *chan, int response_code)
 Called by pjsip_app_hangup and pjsip_action_hangup to actually perform the hangup.
 
static int pjsip_hangup (void *obj)
 Serializer task to hangup channel.
 
static int print_escaped_uri (struct ast_channel *chan, const char *type, pjsip_uri_context_e context, const void *uri, char *buf, size_t size)
 
static int read_pjsip (void *data)
 
static int refresh_write_cb (void *obj)
 
static int response_code_validator (const char *channel_name, const char *response)
 Callback that validates the response code.
 
static void session_refresh_state_destroy (void *obj)
 Destructor for session refresh information.
 
static struct session_refresh_statesession_refresh_state_get_or_alloc (struct ast_sip_session *session)
 Helper function which retrieves or allocates a session refresh state information datastore.
 
static int sip_session_response_cb (struct ast_sip_session *session, pjsip_rx_data *rdata)
 

Variables

static const struct ast_datastore_info session_refresh_datastore
 Datastore for attaching session refresh state information. More...
 
static const char * t38state_to_string [T38_MAX_ENUM]
 String representations of the T.38 state enum.
 

Detailed Description

PJSIP channel dialplan functions.

Author
Joshua Colp <jcolp@digium.com> 
Matt Jordan <mjordan@digium.com> 

Definition in file dialplan_functions.c.

Function Documentation

int pjsip_acf_channel_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)

CHANNEL function read callback.

Parameters
chanThe channel the function is called on
cmdThe name of the function
dataArguments passed to the function
bufOut buffer that should be populated with the data
lenSize of the buffer
Return values
0on success
-1on failure

Definition at line 443 of file dialplan_functions.c.

References ao2_bump, ao2_ref, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_sip_push_task_wait_serializer(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_sip_session::serializer, and ast_sip_channel_pvt::session.

444 {
445  struct pjsip_func_args func_args = { 0, };
446  struct ast_sip_channel_pvt *channel;
447  char *parse = ast_strdupa(data);
448 
450  AST_APP_ARG(param);
451  AST_APP_ARG(type);
452  AST_APP_ARG(field);
453  );
454 
455  if (!chan) {
456  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
457  return -1;
458  }
459 
460  /* Check for zero arguments */
461  if (ast_strlen_zero(parse)) {
462  ast_log(LOG_ERROR, "Cannot call %s without arguments\n", cmd);
463  return -1;
464  }
465 
466  AST_STANDARD_APP_ARGS(args, parse);
467 
468  ast_channel_lock(chan);
469 
470  /* Sanity check */
471  if (strcmp(ast_channel_tech(chan)->type, "PJSIP")) {
472  ast_log(LOG_WARNING, "Cannot call %s on a non-PJSIP channel\n", cmd);
473  ast_channel_unlock(chan);
474  return 0;
475  }
476 
477  channel = ast_channel_tech_pvt(chan);
478  if (!channel) {
479  ast_log(LOG_WARNING, "Channel %s has no pvt!\n", ast_channel_name(chan));
480  ast_channel_unlock(chan);
481  return -1;
482  }
483 
484  if (!channel->session) {
485  ast_log(LOG_WARNING, "Channel %s has no session\n", ast_channel_name(chan));
486  ast_channel_unlock(chan);
487  return -1;
488  }
489 
490  func_args.session = ao2_bump(channel->session);
491  ast_channel_unlock(chan);
492 
493  memset(buf, 0, len);
494 
495  func_args.param = args.param;
496  func_args.type = args.type;
497  func_args.field = args.field;
498  func_args.buf = buf;
499  func_args.len = len;
500  if (ast_sip_push_task_wait_serializer(func_args.session->serializer, read_pjsip, &func_args)) {
501  ast_log(LOG_WARNING, "Unable to read properties of channel %s: failed to push task\n", ast_channel_name(chan));
502  ao2_ref(func_args.session, -1);
503  return -1;
504  }
505  ao2_ref(func_args.session, -1);
506 
507  return func_args.ret;
508 }
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
A structure which contains a channel implementation and session.
struct ast_sip_session * session
Pointer to session.
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
int ast_sip_push_task_wait_serializer(struct ast_taskprocessor *serializer, int(*sip_task)(void *), void *task_data)
Push a task to the serializer and wait for it to complete.
Definition: res_pjsip.c:2179
static char * func_args(char *function)
return a pointer to the arguments of the function, and terminates the function name with '\0' ...
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Definition: channel.h:628
struct ast_taskprocessor * serializer
Struct used to push function arguments to task processor.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_APP_ARG(name)
Define an application argument.
int pjsip_acf_dial_contacts_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)

PJSIP_DIAL_CONTACTS function read callback.

Parameters
chanThe channel the function is called on
cmdThe name of the function
dataArguments passed to the function
bufOut buffer that should be populated with the data
lenSize of the buffer
Return values
0on success
-1on failure

Definition at line 510 of file dialplan_functions.c.

References ao2_container_count(), ao2_iterator_destroy(), ao2_iterator_init(), ao2_ref, ast_sip_contact::aor, AST_APP_ARG, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_free_ptr(), ast_sorcery_retrieve_by_id(), AST_STANDARD_APP_ARGS, ast_str_append(), ast_str_buffer(), ast_str_create, ast_str_strlen(), ast_str_truncate(), ast_strdupa, ast_strip(), RAII_VAR, S_OR, and ast_sip_contact::uri.

511 {
512  RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
513  RAII_VAR(struct ast_str *, dial, NULL, ast_free_ptr);
514  const char *aor_name;
515  char *rest;
516 
518  AST_APP_ARG(endpoint_name);
519  AST_APP_ARG(aor_name);
520  AST_APP_ARG(request_user);
521  );
522 
523  AST_STANDARD_APP_ARGS(args, data);
524 
525  if (ast_strlen_zero(args.endpoint_name)) {
526  ast_log(LOG_WARNING, "An endpoint name must be specified when using the '%s' dialplan function\n", cmd);
527  return -1;
528  } else if (!(endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", args.endpoint_name))) {
529  ast_log(LOG_WARNING, "Specified endpoint '%s' was not found\n", args.endpoint_name);
530  return -1;
531  }
532 
533  aor_name = S_OR(args.aor_name, endpoint->aors);
534 
535  if (ast_strlen_zero(aor_name)) {
536  ast_log(LOG_WARNING, "No AOR has been provided and no AORs are configured on endpoint '%s'\n", args.endpoint_name);
537  return -1;
538  } else if (!(dial = ast_str_create(len))) {
539  ast_log(LOG_WARNING, "Could not get enough buffer space for dialing contacts\n");
540  return -1;
541  } else if (!(rest = ast_strdupa(aor_name))) {
542  ast_log(LOG_WARNING, "Could not duplicate provided AORs\n");
543  return -1;
544  }
545 
546  while ((aor_name = ast_strip(strsep(&rest, ",")))) {
547  RAII_VAR(struct ast_sip_aor *, aor, ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
548  RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
549  struct ao2_iterator it_contacts;
550  struct ast_sip_contact *contact;
551 
552  if (!aor) {
553  /* If the AOR provided is not found skip it, there may be more */
554  continue;
555  } else if (!(contacts = ast_sip_location_retrieve_aor_contacts_filtered(aor, AST_SIP_CONTACT_FILTER_REACHABLE))) {
556  /* No contacts are available, skip it as well */
557  continue;
558  } else if (!ao2_container_count(contacts)) {
559  /* We were given a container but no contacts are in it... */
560  continue;
561  }
562 
563  it_contacts = ao2_iterator_init(contacts, 0);
564  for (; (contact = ao2_iterator_next(&it_contacts)); ao2_ref(contact, -1)) {
565  ast_str_append(&dial, -1, "PJSIP/");
566 
567  if (!ast_strlen_zero(args.request_user)) {
568  ast_str_append(&dial, -1, "%s@", args.request_user);
569  }
570  ast_str_append(&dial, -1, "%s/%s&", args.endpoint_name, contact->uri);
571  }
572  ao2_iterator_destroy(&it_contacts);
573  }
574 
575  /* Trim the '&' at the end off */
576  ast_str_truncate(dial, ast_str_strlen(dial) - 1);
577 
578  ast_copy_string(buf, ast_str_buffer(dial), len);
579 
580  return 0;
581 }
A SIP address of record.
Definition: res_pjsip.h:478
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1139
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
void ast_free_ptr(void *ptr)
free() wrapper
Definition: main/astmm.c:1739
char * ast_str_truncate(struct ast_str *buf, ssize_t len)
Truncates the enclosed string to the given length.
Definition: strings.h:786
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition: sorcery.c:1853
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:223
An entity with which Asterisk communicates.
Definition: res_pjsip.h:949
Support for dynamic strings.
Definition: strings.h:623
Contact associated with an address of record.
Definition: res_pjsip.h:392
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:730
const ast_string_field aor
Definition: res_pjsip.h:414
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1821
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:80
Generic container type.
const ast_string_field uri
Definition: res_pjsip.h:414
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
#define AST_APP_ARG(name)
Define an application argument.
int pjsip_acf_dtmf_mode_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)

PJSIP_DTMF_MODE function read callback.

Parameters
chanThe channel the function is called on
cmdThe name of the function
dataArguments passed to the function
bufOut buffer that should be populated with the data
lenSize of the buffer
Return values
0on success
-1on failure

Definition at line 978 of file dialplan_functions.c.

References ast_sip_session::dtmf, and ast_sip_channel_pvt::session.

979 {
980  struct ast_sip_channel_pvt *channel;
981 
982  if (!chan) {
983  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
984  return -1;
985  }
986 
987  ast_channel_lock(chan);
988  if (strcmp(ast_channel_tech(chan)->type, "PJSIP")) {
989  ast_log(LOG_WARNING, "Cannot call %s on a non-PJSIP channel\n", cmd);
990  ast_channel_unlock(chan);
991  return -1;
992  }
993 
994  channel = ast_channel_tech_pvt(chan);
995 
996  if (ast_sip_dtmf_to_str(channel->session->dtmf, buf, len) < 0) {
997  ast_log(LOG_WARNING, "Unknown DTMF mode %d on PJSIP channel %s\n", channel->session->dtmf, ast_channel_name(chan));
998  ast_channel_unlock(chan);
999  return -1;
1000  }
1001 
1002  ast_channel_unlock(chan);
1003  return 0;
1004 }
A structure which contains a channel implementation and session.
struct ast_sip_session * session
Pointer to session.
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Definition: channel.h:628
enum ast_sip_dtmf_mode dtmf
int pjsip_acf_dtmf_mode_write ( struct ast_channel chan,
const char *  cmd,
char *  data,
const char *  value 
)

PJSIP_DTMF_MODE function write callback.

Parameters
chanThe channel the function is called on
cmdThe name of the function
dataArguments passed to the function
valueValue to be set by the function
Return values
0on success
-1on failure

Definition at line 1079 of file dialplan_functions.c.

References ast_sip_session::active_media_state, ast_dsp_get_features(), ast_dsp_new(), ast_dsp_set_features(), AST_RTP_DTMF_MODE_INBAND, AST_RTP_DTMF_MODE_NONE, AST_RTP_DTMF_MODE_RFC2833, ast_rtp_instance_dtmf_mode_get(), ast_rtp_instance_dtmf_mode_set(), ast_rtp_instance_set_prop(), AST_RTP_PROPERTY_DTMF, ast_sip_push_task_wait_serializer(), ast_sip_session_media_state::default_session, ast_sip_session::dsp, ast_sip_session::dtmf, ast_sip_session_media::rtp, ast_sip_session::serializer, and ast_sip_channel_pvt::session.

1080 {
1081  struct ast_sip_channel_pvt *channel;
1082  struct ast_sip_session_media *media;
1083  int dsp_features = 0;
1084  int dtmf = -1;
1085  struct refresh_data rdata = {
1086  .method = AST_SIP_SESSION_REFRESH_METHOD_INVITE,
1087  };
1088 
1089  if (!chan) {
1090  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
1091  return -1;
1092  }
1093 
1094  ast_channel_lock(chan);
1095  if (strcmp(ast_channel_tech(chan)->type, "PJSIP")) {
1096  ast_log(LOG_WARNING, "Cannot call %s on a non-PJSIP channel\n", cmd);
1097  ast_channel_unlock(chan);
1098  return -1;
1099  }
1100 
1101  channel = ast_channel_tech_pvt(chan);
1102  rdata.session = channel->session;
1103 
1104  dtmf = ast_sip_str_to_dtmf(value);
1105 
1106  if (dtmf == -1) {
1107  ast_log(LOG_WARNING, "Cannot set DTMF mode to '%s' on channel '%s' as value is invalid.\n", value,
1108  ast_channel_name(chan));
1109  ast_channel_unlock(chan);
1110  return -1;
1111  }
1112 
1113  if (channel->session->dtmf == dtmf) {
1114  /* DTMF mode unchanged, nothing to do! */
1115  ast_channel_unlock(chan);
1116  return 0;
1117  }
1118 
1119  channel->session->dtmf = dtmf;
1120 
1121  media = channel->session->active_media_state->default_session[AST_MEDIA_TYPE_AUDIO];
1122 
1123  if (media && media->rtp) {
1124  if (channel->session->dtmf == AST_SIP_DTMF_RFC_4733) {
1127  } else if (channel->session->dtmf == AST_SIP_DTMF_INFO) {
1130  } else if (channel->session->dtmf == AST_SIP_DTMF_INBAND) {
1133  } else if (channel->session->dtmf == AST_SIP_DTMF_NONE) {
1136  } else if (channel->session->dtmf == AST_SIP_DTMF_AUTO) {
1138  /* no RFC4733 negotiated, enable inband */
1140  }
1141  } else if (channel->session->dtmf == AST_SIP_DTMF_AUTO_INFO) {
1144  /* if inband, switch to INFO */
1146  }
1147  }
1148  }
1149 
1150  if (channel->session->dsp) {
1151  dsp_features = ast_dsp_get_features(channel->session->dsp);
1152  }
1153  if (channel->session->dtmf == AST_SIP_DTMF_INBAND ||
1154  channel->session->dtmf == AST_SIP_DTMF_AUTO) {
1155  dsp_features |= DSP_FEATURE_DIGIT_DETECT;
1156  } else {
1157  dsp_features &= ~DSP_FEATURE_DIGIT_DETECT;
1158  }
1159  if (dsp_features) {
1160  if (!channel->session->dsp) {
1161  if (!(channel->session->dsp = ast_dsp_new())) {
1162  ast_channel_unlock(chan);
1163  return 0;
1164  }
1165  }
1166  ast_dsp_set_features(channel->session->dsp, dsp_features);
1167  } else if (channel->session->dsp) {
1168  ast_dsp_free(channel->session->dsp);
1169  channel->session->dsp = NULL;
1170  }
1171 
1172  ast_channel_unlock(chan);
1173 
1174  return ast_sip_push_task_wait_serializer(channel->session->serializer, dtmf_mode_refresh_cb, &rdata);
1175 }
int ast_rtp_instance_dtmf_mode_set(struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode)
Set the DTMF mode that should be used.
Definition: rtp_engine.c:2247
struct ast_dsp * ast_dsp_new(void)
Allocates a new dsp, assumes 8khz for internal sample rate.
Definition: dsp.c:1758
struct ast_sip_session_media * default_session[AST_MEDIA_TYPE_END]
Default media sessions for each type.
A structure which contains a channel implementation and session.
struct ast_sip_session * session
Pointer to session.
struct ast_sip_session_media_state * active_media_state
struct ast_dsp * dsp
int ast_dsp_get_features(struct ast_dsp *dsp)
Get features.
Definition: dsp.c:1777
int ast_sip_push_task_wait_serializer(struct ast_taskprocessor *serializer, int(*sip_task)(void *), void *task_data)
Push a task to the serializer and wait for it to complete.
Definition: res_pjsip.c:2179
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Definition: channel.h:628
struct ast_taskprocessor * serializer
enum ast_sip_dtmf_mode dtmf
void ast_dsp_set_features(struct ast_dsp *dsp, int features)
Select feature set.
Definition: dsp.c:1768
A structure containing SIP session media information.
struct ast_rtp_instance * rtp
RTP instance itself.
enum ast_rtp_dtmf_mode ast_rtp_instance_dtmf_mode_get(struct ast_rtp_instance *instance)
Get the DTMF mode of an RTP instance.
Definition: rtp_engine.c:2261
void ast_rtp_instance_set_prop(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value)
Set the value of an RTP instance property.
Definition: rtp_engine.c:727
int pjsip_acf_media_offer_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)

PJSIP_MEDIA_OFFER function read callback.

Parameters
chanThe channel the function is called on
cmdThe name of the function
dataArguments passed to the function
bufOut buffer that should be populated with the data
lenSize of the buffer
Return values
0on success
-1on failure

Definition at line 921 of file dialplan_functions.c.

References ast_sip_channel_pvt::session.

922 {
923  struct ast_sip_channel_pvt *channel;
924 
925  if (!chan) {
926  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
927  return -1;
928  }
929 
930  if (strcmp(ast_channel_tech(chan)->type, "PJSIP")) {
931  ast_log(LOG_WARNING, "Cannot call %s on a non-PJSIP channel\n", cmd);
932  return -1;
933  }
934 
935  channel = ast_channel_tech_pvt(chan);
936 
937  if (!strcmp(data, "audio")) {
938  return media_offer_read_av(channel->session, buf, len, AST_MEDIA_TYPE_AUDIO);
939  } else if (!strcmp(data, "video")) {
940  return media_offer_read_av(channel->session, buf, len, AST_MEDIA_TYPE_VIDEO);
941  } else {
942  /* Ensure that the buffer is empty */
943  buf[0] = '\0';
944  }
945 
946  return 0;
947 }
A structure which contains a channel implementation and session.
struct ast_sip_session * session
Pointer to session.
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Definition: channel.h:628
int pjsip_acf_media_offer_write ( struct ast_channel chan,
const char *  cmd,
char *  data,
const char *  value 
)

PJSIP_MEDIA_OFFER function write callback.

Parameters
chanThe channel the function is called on
cmdThe name of the function
dataArguments passed to the function
valueValue to be set by the function
Return values
0on success
-1on failure

Definition at line 949 of file dialplan_functions.c.

References ast_sip_push_task_wait_serializer(), ast_sip_session::serializer, and ast_sip_channel_pvt::session.

950 {
951  struct ast_sip_channel_pvt *channel;
952  struct media_offer_data mdata = {
953  .value = value
954  };
955 
956  if (!chan) {
957  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
958  return -1;
959  }
960 
961  if (strcmp(ast_channel_tech(chan)->type, "PJSIP")) {
962  ast_log(LOG_WARNING, "Cannot call %s on a non-PJSIP channel\n", cmd);
963  return -1;
964  }
965 
966  channel = ast_channel_tech_pvt(chan);
967  mdata.session = channel->session;
968 
969  if (!strcmp(data, "audio")) {
970  mdata.media_type = AST_MEDIA_TYPE_AUDIO;
971  } else if (!strcmp(data, "video")) {
972  mdata.media_type = AST_MEDIA_TYPE_VIDEO;
973  }
974 
975  return ast_sip_push_task_wait_serializer(channel->session->serializer, media_offer_write_av, &mdata);
976 }
A structure which contains a channel implementation and session.
struct ast_sip_session * session
Pointer to session.
int ast_sip_push_task_wait_serializer(struct ast_taskprocessor *serializer, int(*sip_task)(void *), void *task_data)
Push a task to the serializer and wait for it to complete.
Definition: res_pjsip.c:2179
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Definition: channel.h:628
struct ast_taskprocessor * serializer
int pjsip_acf_moh_passthrough_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)

PJSIP_MOH_PASSTHROUGH function read callback.

Parameters
chanThe channel the function is called on
cmdThe name of the function
dataArguments passed to the function
bufOut buffer that should be populated with the data
lenSize of the buffer
Return values
0on success
-1on failure

Definition at line 1006 of file dialplan_functions.c.

References AST_YESNO, ast_sip_session::moh_passthrough, and ast_sip_channel_pvt::session.

1007 {
1008  struct ast_sip_channel_pvt *channel;
1009 
1010  if (!chan) {
1011  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
1012  return -1;
1013  }
1014 
1015  if (len < 3) {
1016  ast_log(LOG_WARNING, "%s: buffer too small\n", cmd);
1017  return -1;
1018  }
1019 
1020  ast_channel_lock(chan);
1021  if (strcmp(ast_channel_tech(chan)->type, "PJSIP")) {
1022  ast_log(LOG_WARNING, "Cannot call %s on a non-PJSIP channel\n", cmd);
1023  ast_channel_unlock(chan);
1024  return -1;
1025  }
1026 
1027  channel = ast_channel_tech_pvt(chan);
1028  strncpy(buf, AST_YESNO(channel->session->moh_passthrough), len);
1029 
1030  ast_channel_unlock(chan);
1031  return 0;
1032 }
A structure which contains a channel implementation and session.
struct ast_sip_session * session
Pointer to session.
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Definition: channel.h:628
#define AST_YESNO(x)
return Yes or No depending on the argument.
Definition: strings.h:143
unsigned int moh_passthrough
int pjsip_acf_moh_passthrough_write ( struct ast_channel chan,
const char *  cmd,
char *  data,
const char *  value 
)

PJSIP_MOH_PASSTHROUGH function write callback.

Parameters
chanThe channel the function is called on
cmdThe name of the function
dataArguments passed to the function
valueValue to be set by the function
Return values
0on success
-1on failure

Definition at line 1177 of file dialplan_functions.c.

References ast_true(), ast_sip_session::moh_passthrough, and ast_sip_channel_pvt::session.

1178 {
1179  struct ast_sip_channel_pvt *channel;
1180 
1181  if (!chan) {
1182  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
1183  return -1;
1184  }
1185 
1186  ast_channel_lock(chan);
1187  if (strcmp(ast_channel_tech(chan)->type, "PJSIP")) {
1188  ast_log(LOG_WARNING, "Cannot call %s on a non-PJSIP channel\n", cmd);
1189  ast_channel_unlock(chan);
1190  return -1;
1191  }
1192 
1193  channel = ast_channel_tech_pvt(chan);
1194  channel->session->moh_passthrough = ast_true(value);
1195 
1196  ast_channel_unlock(chan);
1197 
1198  return 0;
1199 }
A structure which contains a channel implementation and session.
struct ast_sip_session * session
Pointer to session.
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Definition: channel.h:628
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: utils.c:2199
unsigned int moh_passthrough
int pjsip_acf_parse_uri_read ( struct ast_channel chan,
const char *  cmd,
char *  data,
char *  buf,
size_t  len 
)

PJSIP_PARSE_URI function read callback.

Parameters
chanThe channel the function is called on
cmdThe name of the function
dataArguments passed to the function
bufOut buffer that should be populated with the data
lenSize of the buffer
Return values
0on success
-1on failure

Definition at line 724 of file dialplan_functions.c.

References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_sip_push_task_wait_serializer(), AST_STANDARD_APP_ARGS, ast_strdupa, and pbx_builtin_getvar_helper().

725 {
726  struct parse_uri_args func_args = { 0, };
727  int reading_uri_from_var;
728 
730  AST_APP_ARG(uri_str);
731  AST_APP_ARG(type);
732  );
733 
734  AST_STANDARD_APP_ARGS(args, data);
735 
736  reading_uri_from_var = !strcasecmp(cmd, "PJSIP_PARSE_URI_FROM");
737 
738  if (reading_uri_from_var) {
739  const char *var;
740 
741  if (ast_strlen_zero(args.uri_str)) {
742  ast_log(LOG_WARNING, "The name of a variable containing a URI must be specified when using the '%s' dialplan function\n", cmd);
743  return -1;
744  }
745 
746  ast_channel_lock(chan);
747  if ((var = pbx_builtin_getvar_helper(chan, args.uri_str))) {
748  args.uri_str = ast_strdupa(var);
749  }
750  ast_channel_unlock(chan);
751  }
752 
753  if (ast_strlen_zero(args.uri_str)) {
754  if (reading_uri_from_var) {
755  ast_log(LOG_WARNING, "The variable provided to the '%s' dialplan function must contain a URI\n", cmd);
756  } else {
757  ast_log(LOG_WARNING, "A URI must be specified when using the '%s' dialplan function\n", cmd);
758  }
759  return -1;
760  }
761 
762  if (ast_strlen_zero(args.type)) {
763  ast_log(LOG_WARNING, "A type part of the URI must be specified when using the '%s' dialplan function\n", cmd);
764  return -1;
765  }
766 
767  memset(buf, 0, buflen);
768 
769  func_args.uri = args.uri_str;
770  func_args.type = args.type;
771  func_args.buf = buf;
772  func_args.buflen = buflen;
773  if (ast_sip_push_task_wait_serializer(NULL, parse_uri_cb, &func_args)) {
774  ast_log(LOG_WARNING, "Unable to parse URI: failed to push task\n");
775  return -1;
776  }
777 
778  return func_args.ret;
779 }
Struct used to push PJSIP_PARSE_URI function arguments to task processor.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
int ast_sip_push_task_wait_serializer(struct ast_taskprocessor *serializer, int(*sip_task)(void *), void *task_data)
Push a task to the serializer and wait for it to complete.
Definition: res_pjsip.c:2179
static char * func_args(char *function)
return a pointer to the arguments of the function, and terminates the function name with '\0' ...
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_APP_ARG(name)
Define an application argument.
int pjsip_acf_session_refresh_write ( struct ast_channel chan,
const char *  cmd,
char *  data,
const char *  value 
)

PJSIP_SEND_SESSION_REFRESH function write callback.

Parameters
chanThe channel the function is called on
cmdthe Name of the function
dataArguments passed to the function
valueValue to be set by the function
Return values
0on success
-1on failure

Definition at line 1220 of file dialplan_functions.c.

References ast_sip_push_task_wait_serializer(), AST_STATE_UP, ast_sip_session::serializer, and ast_sip_channel_pvt::session.

1221 {
1222  struct ast_sip_channel_pvt *channel;
1223  struct refresh_data rdata = {
1224  .method = AST_SIP_SESSION_REFRESH_METHOD_INVITE,
1225  };
1226 
1227  if (!chan) {
1228  ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd);
1229  return -1;
1230  }
1231 
1232  if (ast_channel_state(chan) != AST_STATE_UP) {
1233  ast_log(LOG_WARNING, "'%s' not allowed on unanswered channel '%s'.\n", cmd, ast_channel_name(chan));
1234  return -1;
1235  }
1236 
1237  if (strcmp(ast_channel_tech(chan)->type, "PJSIP")) {
1238  ast_log(LOG_WARNING, "Cannot call %s on a non-PJSIP channel\n", cmd);
1239  return -1;
1240  }
1241 
1242  channel = ast_channel_tech_pvt(chan);
1243  rdata.session = channel->session;
1244 
1245  if (!strcmp(value, "invite")) {
1246  rdata.method = AST_SIP_SESSION_REFRESH_METHOD_INVITE;
1247  } else if (!strcmp(value, "update")) {
1248  rdata.method = AST_SIP_SESSION_REFRESH_METHOD_UPDATE;
1249  }
1250 
1251  return ast_sip_push_task_wait_serializer(channel->session->serializer, refresh_write_cb, &rdata);
1252 }
ast_channel_state
ast_channel states
Definition: channelstate.h:35
A structure which contains a channel implementation and session.
struct ast_sip_session * session
Pointer to session.
int ast_sip_push_task_wait_serializer(struct ast_taskprocessor *serializer, int(*sip_task)(void *), void *task_data)
Push a task to the serializer and wait for it to complete.
Definition: res_pjsip.c:2179
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Definition: channel.h:628
struct ast_taskprocessor * serializer
int pjsip_action_hangup ( struct mansession s,
const struct message m 
)

PJSIPHangup Manager Action.

Manager action to hang up an incoming PJSIP channel with a SIP response code.

Definition at line 1366 of file dialplan_functions.c.

References ast_manager_hangup_helper(), pjsip_app_hangup_handler(), and response_code_validator().

Referenced by load_module().

1367 {
1368  return ast_manager_hangup_helper(s, m,
1370 }
int ast_manager_hangup_helper(struct mansession *s, const struct message *m, manager_hangup_handler_t handler, manager_hangup_cause_validator_t cause_validator)
A manager helper function that hangs up a channel using a supplied channel type specific hangup funct...
Definition: manager.c:4762
static void pjsip_app_hangup_handler(struct ast_channel *chan, int response_code)
Called by pjsip_app_hangup and pjsip_action_hangup to actually perform the hangup.
static int response_code_validator(const char *channel_name, const char *response)
Callback that validates the response code.
int pjsip_app_hangup ( struct ast_channel chan,
const char *  data 
)

PJSIPHangup Dialplan App.

Hang up an incoming PJSIP channel with a SIP response code.

Definition at line 1346 of file dialplan_functions.c.

References pjsip_app_hangup_handler(), and response_code_validator().

Referenced by load_module().

1347 {
1348  int response_code;
1349  const char *tag = ast_channel_name(chan);
1350 
1351  if (ast_strlen_zero(data)) {
1352  ast_log(LOG_WARNING, "%s: Missing response code parameter\n", tag);
1353  return -1;
1354  }
1355 
1356  response_code = response_code_validator(tag, data);
1357 
1358  pjsip_app_hangup_handler(chan, response_code);
1359 
1360  return -1;
1361 }
static void pjsip_app_hangup_handler(struct ast_channel *chan, int response_code)
Called by pjsip_app_hangup and pjsip_action_hangup to actually perform the hangup.
static int response_code_validator(const char *channel_name, const char *response)
Callback that validates the response code.

Variable Documentation

const struct ast_datastore_info session_refresh_datastore
static
Initial value:
= {
.type = "pjsip_session_refresh",
}
static void session_refresh_state_destroy(void *obj)
Destructor for session refresh information.

Datastore for attaching session refresh state information.

Definition at line 599 of file dialplan_functions.c.