Wed Jan 8 2020 09:50:11

Asterisk developer's documentation


dialplan_functions.c File Reference

sip channel dialplan functions and unit tests More...

#include "asterisk.h"
#include <math.h>
#include "asterisk/channel.h"
#include "asterisk/rtp_engine.h"
#include "asterisk/pbx.h"
#include "asterisk/acl.h"
#include "include/sip.h"
#include "include/globals.h"
#include "include/dialog.h"
#include "include/dialplan_functions.h"
#include "include/sip_utils.h"

Go to the source code of this file.

Functions

int sip_acf_channel_read (struct ast_channel *chan, const char *funcname, char *preparse, char *buf, size_t buflen)
 
void sip_dialplan_function_register_tests (void)
 SIP test registration. More...
 
void sip_dialplan_function_unregister_tests (void)
 SIP test registration. More...
 

Detailed Description

sip channel dialplan functions and unit tests

Definition in file dialplan_functions.c.

Function Documentation

int sip_acf_channel_read ( struct ast_channel chan,
const char *  funcname,
char *  preparse,
char *  buf,
size_t  buflen 
)

Definition at line 44 of file dialplan_functions.c.

References args, AST_APP_ARG, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_log(), AST_MAX_USER_FIELD, ast_ouraddrfor(), ast_rtp_instance_get_local_address(), ast_rtp_instance_get_quality(), ast_rtp_instance_get_remote_address(), ast_rtp_instance_get_stats(), AST_RTP_INSTANCE_STAT_ALL, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, ast_sockaddr_isnull(), ast_sockaddr_stringify(), ast_sockaddr_stringify_addr(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_rtp_instance_stats::local_maxjitter, ast_rtp_instance_stats::local_maxrxploss, ast_rtp_instance_stats::local_minjitter, ast_rtp_instance_stats::local_minrxploss, ast_rtp_instance_stats::local_normdevjitter, ast_rtp_instance_stats::local_normdevrxploss, ast_rtp_instance_stats::local_ssrc, ast_rtp_instance_stats::local_stdevjitter, ast_rtp_instance_stats::local_stdevrxploss, LOG_ERROR, LOG_WARNING, ast_rtp_instance_stats::maxrtt, ast_rtp_instance_stats::minrtt, name, ast_rtp_instance_stats::normdevrtt, parse(), ast_rtp_instance_stats::remote_maxjitter, ast_rtp_instance_stats::remote_maxrxploss, ast_rtp_instance_stats::remote_minjitter, ast_rtp_instance_stats::remote_minrxploss, ast_rtp_instance_stats::remote_normdevjitter, ast_rtp_instance_stats::remote_normdevrxploss, ast_rtp_instance_stats::remote_ssrc, ast_rtp_instance_stats::remote_stdevjitter, ast_rtp_instance_stats::remote_stdevrxploss, ast_rtp_instance_stats::rtt, ast_rtp_instance_stats::rxcount, ast_rtp_instance_stats::rxjitter, ast_rtp_instance_stats::rxploss, ast_rtp_instance_stats::stdevrtt, ast_channel::tech, ast_channel::tech_pvt, ast_rtp_instance_stats::txcount, ast_rtp_instance_stats::txjitter, ast_rtp_instance_stats::txploss, and type.

45 {
46  struct sip_pvt *p = chan->tech_pvt;
47  char *parse = ast_strdupa(preparse);
48  int res = 0;
50  AST_APP_ARG(param);
52  AST_APP_ARG(field);
53  );
54 
55  /* Check for zero arguments */
56  if (ast_strlen_zero(parse)) {
57  ast_log(LOG_ERROR, "Cannot call %s without arguments\n", funcname);
58  return -1;
59  }
60 
62 
63  /* Sanity check */
64  if (!IS_SIP_TECH(chan->tech)) {
65  ast_log(LOG_ERROR, "Cannot call %s on a non-SIP channel\n", funcname);
66  return 0;
67  }
68 
69  memset(buf, 0, buflen);
70 
71  if (p == NULL) {
72  return -1;
73  }
74 
75  if (!strcasecmp(args.param, "peerip")) {
76  ast_copy_string(buf, ast_sockaddr_isnull(&p->sa) ? "" : ast_sockaddr_stringify_addr(&p->sa), buflen);
77  } else if (!strcasecmp(args.param, "recvip")) {
78  ast_copy_string(buf, ast_sockaddr_isnull(&p->recv) ? "" : ast_sockaddr_stringify_addr(&p->recv), buflen);
79  } else if (!strcasecmp(args.param, "from")) {
80  ast_copy_string(buf, p->from, buflen);
81  } else if (!strcasecmp(args.param, "uri")) {
82  ast_copy_string(buf, p->uri, buflen);
83  } else if (!strcasecmp(args.param, "useragent")) {
84  ast_copy_string(buf, p->useragent, buflen);
85  } else if (!strcasecmp(args.param, "peername")) {
86  ast_copy_string(buf, p->peername, buflen);
87  } else if (!strcasecmp(args.param, "t38passthrough")) {
88  ast_copy_string(buf, (p->t38.state == T38_DISABLED) ? "0" : "1", buflen);
89  } else if (!strcasecmp(args.param, "rtpdest")) {
90  struct ast_sockaddr addr;
91  struct ast_rtp_instance *stream;
92 
93  if (ast_strlen_zero(args.type))
94  args.type = "audio";
95 
96  if (!strcasecmp(args.type, "audio"))
97  stream = p->rtp;
98  else if (!strcasecmp(args.type, "video"))
99  stream = p->vrtp;
100  else if (!strcasecmp(args.type, "text"))
101  stream = p->trtp;
102  else
103  return -1;
104 
105  /* Return 0 to suppress a console warning message */
106  if (!stream) {
107  return 0;
108  }
109 
111  snprintf(buf, buflen, "%s", ast_sockaddr_stringify(&addr));
112  } else if (!strcasecmp(args.param, "rtpsource")) {
113  struct ast_sockaddr sa;
114  struct ast_rtp_instance *stream;
115 
116  if (ast_strlen_zero(args.type))
117  args.type = "audio";
118 
119  if (!strcasecmp(args.type, "audio"))
120  stream = p->rtp;
121  else if (!strcasecmp(args.type, "video"))
122  stream = p->vrtp;
123  else if (!strcasecmp(args.type, "text"))
124  stream = p->trtp;
125  else
126  return -1;
127 
128  /* Return 0 to suppress a console warning message */
129  if (!stream) {
130  return 0;
131  }
132 
134 
135  if (ast_sockaddr_isnull(&sa)) {
136  struct ast_sockaddr dest_sa;
137  ast_rtp_instance_get_remote_address(stream, &dest_sa);
138  ast_ouraddrfor(&dest_sa, &sa);
139  }
140 
141  snprintf(buf, buflen, "%s", ast_sockaddr_stringify(&sa));
142  } else if (!strcasecmp(args.param, "rtpqos")) {
143  struct ast_rtp_instance *rtp = NULL;
144 
145  if (ast_strlen_zero(args.type)) {
146  args.type = "audio";
147  }
148 
149  if (!strcasecmp(args.type, "audio")) {
150  rtp = p->rtp;
151  } else if (!strcasecmp(args.type, "video")) {
152  rtp = p->vrtp;
153  } else if (!strcasecmp(args.type, "text")) {
154  rtp = p->trtp;
155  } else {
156  return -1;
157  }
158 
159  if (ast_strlen_zero(args.field) || !strcasecmp(args.field, "all")) {
160  char quality_buf[AST_MAX_USER_FIELD];
161 
162  if (!ast_rtp_instance_get_quality(rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf))) {
163  return -1;
164  }
165 
166  ast_copy_string(buf, quality_buf, buflen);
167  return res;
168  } else {
169  struct ast_rtp_instance_stats stats;
170  int i;
171  struct {
172  const char *name;
173  enum { INT, DBL } type;
174  union {
175  unsigned int *i4;
176  double *d8;
177  };
178  } lookup[] = {
179  { "txcount", INT, { .i4 = &stats.txcount, }, },
180  { "rxcount", INT, { .i4 = &stats.rxcount, }, },
181  { "txjitter", DBL, { .d8 = &stats.txjitter, }, },
182  { "rxjitter", DBL, { .d8 = &stats.rxjitter, }, },
183  { "remote_maxjitter", DBL, { .d8 = &stats.remote_maxjitter, }, },
184  { "remote_minjitter", DBL, { .d8 = &stats.remote_minjitter, }, },
185  { "remote_normdevjitter", DBL, { .d8 = &stats.remote_normdevjitter, }, },
186  { "remote_stdevjitter", DBL, { .d8 = &stats.remote_stdevjitter, }, },
187  { "local_maxjitter", DBL, { .d8 = &stats.local_maxjitter, }, },
188  { "local_minjitter", DBL, { .d8 = &stats.local_minjitter, }, },
189  { "local_normdevjitter", DBL, { .d8 = &stats.local_normdevjitter, }, },
190  { "local_stdevjitter", DBL, { .d8 = &stats.local_stdevjitter, }, },
191  { "txploss", INT, { .i4 = &stats.txploss, }, },
192  { "rxploss", INT, { .i4 = &stats.rxploss, }, },
193  { "remote_maxrxploss", DBL, { .d8 = &stats.remote_maxrxploss, }, },
194  { "remote_minrxploss", DBL, { .d8 = &stats.remote_minrxploss, }, },
195  { "remote_normdevrxploss", DBL, { .d8 = &stats.remote_normdevrxploss, }, },
196  { "remote_stdevrxploss", DBL, { .d8 = &stats.remote_stdevrxploss, }, },
197  { "local_maxrxploss", DBL, { .d8 = &stats.local_maxrxploss, }, },
198  { "local_minrxploss", DBL, { .d8 = &stats.local_minrxploss, }, },
199  { "local_normdevrxploss", DBL, { .d8 = &stats.local_normdevrxploss, }, },
200  { "local_stdevrxploss", DBL, { .d8 = &stats.local_stdevrxploss, }, },
201  { "rtt", DBL, { .d8 = &stats.rtt, }, },
202  { "maxrtt", DBL, { .d8 = &stats.maxrtt, }, },
203  { "minrtt", DBL, { .d8 = &stats.minrtt, }, },
204  { "normdevrtt", DBL, { .d8 = &stats.normdevrtt, }, },
205  { "stdevrtt", DBL, { .d8 = &stats.stdevrtt, }, },
206  { "local_ssrc", INT, { .i4 = &stats.local_ssrc, }, },
207  { "remote_ssrc", INT, { .i4 = &stats.remote_ssrc, }, },
208  { NULL, },
209  };
210 
212  return -1;
213  }
214 
215  for (i = 0; !ast_strlen_zero(lookup[i].name); i++) {
216  if (!strcasecmp(args.field, lookup[i].name)) {
217  if (lookup[i].type == INT) {
218  snprintf(buf, buflen, "%u", *lookup[i].i4);
219  } else {
220  snprintf(buf, buflen, "%f", *lookup[i].d8);
221  }
222  return 0;
223  }
224  }
225  ast_log(LOG_WARNING, "Unrecognized argument '%s' to %s\n", preparse, funcname);
226  return -1;
227  }
228  } else if (!strcasecmp(args.param, "secure_signaling")) {
229  snprintf(buf, buflen, "%s", p->socket.type == SIP_TRANSPORT_TLS ? "1" : "");
230  } else if (!strcasecmp(args.param, "secure_media")) {
231  snprintf(buf, buflen, "%s", p->srtp ? "1" : "");
232  } else {
233  res = -1;
234  }
235  return res;
236 }
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
Definition: netsock2.h:240
#define AST_MAX_USER_FIELD
Definition: cdr.h:72
int ast_rtp_instance_get_stats(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat)
Retrieve statistics about an RTP instance.
Definition: rtp_engine.c:1604
void * tech_pvt
Definition: channel.h:744
#define LOG_WARNING
Definition: logger.h:144
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
Socket address structure.
Definition: netsock2.h:63
static int ast_sockaddr_isnull(const struct ast_sockaddr *addr)
Checks if the ast_sockaddr is null. &quot;null&quot; in this sense essentially means uninitialized, or having a 0 length.
Definition: netsock2.h:93
int ast_ouraddrfor(const struct ast_sockaddr *them, struct ast_sockaddr *us)
Get our local IP address when contacting a remote host.
Definition: acl.c:705
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
char * ast_rtp_instance_get_quality(struct ast_rtp_instance *instance, enum ast_rtp_instance_stat_field field, char *buf, size_t size)
Retrieve quality statistics about an RTP instance.
Definition: rtp_engine.c:1609
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
#define LOG_ERROR
Definition: logger.h:155
static struct @350 args
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
Definition: netsock2.h:210
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static void parse(struct mgcp_request *req)
Definition: chan_mgcp.c:1858
static const char name[]
void ast_rtp_instance_get_remote_address(struct ast_rtp_instance *instance, struct ast_sockaddr *address)
Get the address of the remote endpoint that we are sending RTP to.
Definition: rtp_engine.c:447
static const char type[]
Definition: chan_nbs.c:57
void ast_rtp_instance_get_local_address(struct ast_rtp_instance *instance, struct ast_sockaddr *address)
Get the local address that we are expecting RTP on.
Definition: rtp_engine.c:430
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
struct ast_channel_tech * tech
Definition: channel.h:743
void sip_dialplan_function_register_tests ( void  )

SIP test registration.

Definition at line 411 of file dialplan_functions.c.

References AST_TEST_REGISTER.

Referenced by sip_register_tests().

412 {
413  AST_TEST_REGISTER(test_sip_rtpqos_1);
414 }
#define AST_TEST_REGISTER(cb)
Definition: test.h:127
void sip_dialplan_function_unregister_tests ( void  )

SIP test registration.

Definition at line 417 of file dialplan_functions.c.

References AST_TEST_UNREGISTER.

Referenced by sip_unregister_tests().

418 {
419  AST_TEST_UNREGISTER(test_sip_rtpqos_1);
420 }
#define AST_TEST_UNREGISTER(cb)
Definition: test.h:128