Asterisk - The Open Source Telephony Project  GIT-master-a24979a
Functions | Variables
cli_commands.c File Reference

PJSIP channel CLI functions. More...

#include "asterisk.h"
#include <pjsip.h>
#include <pjlib.h>
#include <pjsip_ua.h>
#include "asterisk/astobj2.h"
#include "asterisk/channel.h"
#include "asterisk/format.h"
#include "asterisk/res_pjsip.h"
#include "asterisk/res_pjsip_session.h"
#include "asterisk/res_pjsip_cli.h"
#include "asterisk/stasis.h"
#include "asterisk/time.h"
#include "include/chan_pjsip.h"
#include "include/cli_functions.h"
Include dependency graph for cli_commands.c:

Go to the source code of this file.

Functions

static int cli_channel_compare (void *obj, void *arg, int flags)
 
static struct ao2_containercli_channel_get_container (const char *regex)
 
static const char * cli_channel_get_id (const void *obj)
 
static int cli_channel_iterate (void *endpoint, ao2_callback_fn callback, void *arg)
 
static int cli_channel_print_body (void *obj, void *arg, int flags)
 
static int cli_channel_print_header (void *obj, void *arg, int flags)
 
static void * cli_channel_retrieve_by_id (const char *id)
 
static int cli_channel_sort (const void *obj, const void *arg, int flags)
 
static int cli_channelstats_compare (void *obj, void *arg, int flags)
 
static struct ao2_containercli_channelstats_get_container (const char *regex)
 
static int cli_channelstats_iterate (void *endpoint, ao2_callback_fn callback, void *arg)
 
static int cli_channelstats_print_body (void *obj, void *arg, int flags)
 
static int cli_channelstats_print_header (void *obj, void *arg, int flags)
 
static int cli_channelstats_sort (const void *obj, const void *arg, int flags)
 
static int cli_filter_channels (void *obj, void *arg, int flags)
 
static int cli_message_to_snapshot (void *obj, void *arg, int flags)
 
static struct ao2_containerget_container (const char *regex, ao2_sort_fn sort_fn, ao2_callback_fn compare_fn)
 
int pjsip_channel_cli_register (void)
 Registers the channel cli commands. More...
 
void pjsip_channel_cli_unregister (void)
 Unregisters the channel cli commands. More...
 

Variables

struct ast_sip_cli_formatter_entrychannel_formatter
 
struct ast_sip_cli_formatter_entrychannelstats_formatter
 
static struct ast_cli_entry cli_commands []
 

Detailed Description

PJSIP channel CLI functions.

Author
George Joseph <george.joseph@fairview5.com> 

Definition in file cli_commands.c.

Function Documentation

◆ cli_channel_compare()

static int cli_channel_compare ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 109 of file cli_commands.c.

110 {
111  const struct ast_channel_snapshot *left_obj = obj;
112  const struct ast_channel_snapshot *right_obj = arg;
113  const char *right_key = arg;
114  int cmp = 0;
115 
116  switch (flags & OBJ_SEARCH_MASK) {
117  case OBJ_SEARCH_OBJECT:
118  right_key = right_obj->base->name;
119  /* Fall through */
120  case OBJ_SEARCH_KEY:
121  if (strcmp(left_obj->base->name, right_key) == 0) {
122  cmp = CMP_MATCH | CMP_STOP;
123  }
124  break;
126  if (strncmp(left_obj->base->name, right_key, strlen(right_key)) == 0) {
127  cmp = CMP_MATCH;
128  }
129  break;
130  default:
131  cmp = 0;
132  break;
133  }
134 
135  return cmp;
136 }
@ CMP_MATCH
Definition: astobj2.h:1027
@ CMP_STOP
Definition: astobj2.h:1028
@ OBJ_SEARCH_PARTIAL_KEY
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition: astobj2.h:1116
@ OBJ_SEARCH_OBJECT
The arg parameter is an object of the same type.
Definition: astobj2.h:1087
@ OBJ_SEARCH_MASK
Search option field mask.
Definition: astobj2.h:1072
@ OBJ_SEARCH_KEY
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1101
const ast_string_field name
Structure representing a snapshot of channel state.
struct ast_channel_snapshot_base * base
struct ast_flags flags

References ast_channel_snapshot::base, CMP_MATCH, CMP_STOP, ast_channel_snapshot::flags, ast_channel_snapshot_base::name, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and OBJ_SEARCH_PARTIAL_KEY.

Referenced by cli_channel_get_container().

◆ cli_channel_get_container()

static struct ao2_container* cli_channel_get_container ( const char *  regex)
static

Definition at line 225 of file cli_commands.c.

226 {
228 }
static int cli_channel_compare(void *obj, void *arg, int flags)
Definition: cli_commands.c:109
static int cli_channel_sort(const void *obj, const void *arg, int flags)
Definition: cli_commands.c:55
static struct ao2_container * get_container(const char *regex, ao2_sort_fn sort_fn, ao2_callback_fn compare_fn)
Definition: cli_commands.c:196
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)

References cli_channel_compare(), cli_channel_sort(), get_container(), and regex().

Referenced by pjsip_channel_cli_register().

◆ cli_channel_get_id()

static const char* cli_channel_get_id ( const void *  obj)
static

Definition at line 235 of file cli_commands.c.

236 {
237  const struct ast_channel_snapshot *snapshot = obj;
238 
239  return snapshot->base->name;
240 }

References ast_channel_snapshot::base, and ast_channel_snapshot_base::name.

Referenced by pjsip_channel_cli_register().

◆ cli_channel_iterate()

static int cli_channel_iterate ( void *  endpoint,
ao2_callback_fn  callback,
void *  arg 
)
static

Definition at line 45 of file cli_commands.c.

46 {
47  return ast_sip_for_each_channel(endpoint, callback, arg);
48 }
int ast_sip_for_each_channel(const struct ast_sip_endpoint *endpoint, ao2_callback_fn on_channel_snapshot, void *arg)
For every channel snapshot on an endpoint all the given 'on_channel_snapshot' handler.

References ast_sip_for_each_channel().

Referenced by pjsip_channel_cli_register().

◆ cli_channel_print_body()

static int cli_channel_print_body ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 271 of file cli_commands.c.

272 {
273  const struct ast_channel_snapshot *snapshot = obj;
274  struct ast_sip_cli_context *context = arg;
275  char *print_name = NULL;
276  int print_name_len;
277  int indent;
278  int flexwidth;
279  char *print_time = alloca(32);
280 
281  ast_assert(context->output_buffer != NULL);
282 
283  print_name_len = strlen(snapshot->base->name) + strlen(snapshot->dialplan->appl) + 2;
284  print_name = alloca(print_name_len);
285 
286  /* Append the application */
287  snprintf(print_name, print_name_len, "%s/%s", snapshot->base->name, snapshot->dialplan->appl);
288 
289  indent = CLI_INDENT_TO_SPACES(context->indent_level);
290  flexwidth = CLI_LAST_TABSTOP - indent;
291 
292  ast_format_duration_hh_mm_ss(ast_tvnow().tv_sec - snapshot->base->creationtime.tv_sec, print_time, 32);
293 
294  ast_str_append(&context->output_buffer, 0, "%*s: %-*.*s %-12.12s %-11.11s\n",
295  CLI_INDENT_TO_SPACES(context->indent_level), "Channel",
296  flexwidth, flexwidth,
297  print_name,
298  ast_state2str(snapshot->state),
299  print_time);
300 
301  if (context->recurse) {
302  context->indent_level++;
303  indent = CLI_INDENT_TO_SPACES(context->indent_level);
304  flexwidth = CLI_LAST_TABSTOP - indent - 25;
305 
306  ast_str_append(&context->output_buffer, 0,
307  "%*s: %-*.*s CLCID: \"%s\" <%s>\n",
308  indent, "Exten",
309  flexwidth, flexwidth,
310  snapshot->dialplan->exten,
311  snapshot->connected->name,
312  snapshot->connected->number
313  );
314  context->indent_level--;
315  if (context->indent_level == 0) {
316  ast_str_append(&context->output_buffer, 0, "\n");
317  }
318  }
319 
320  return 0;
321 }
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:120
const char * ast_state2str(enum ast_channel_state state)
Gives the string form of a given channel state.
Definition: channel.c:636
#define CLI_LAST_TABSTOP
Definition: res_pjsip_cli.h:27
#define CLI_INDENT_TO_SPACES(x)
Definition: res_pjsip_cli.h:29
#define NULL
Definition: resample.c:96
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:1117
const ast_string_field exten
const ast_string_field appl
struct ast_channel_snapshot_connected * connected
struct ast_channel_snapshot_dialplan * dialplan
enum ast_channel_state state
CLI Formatter Context passed to all formatters.
Definition: res_pjsip_cli.h:34
void ast_format_duration_hh_mm_ss(int duration, char *buf, size_t length)
Formats a duration into HH:MM:SS.
Definition: main/utils.c:2195
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:157
#define ast_assert(a)
Definition: utils.h:734

References ast_channel_snapshot_dialplan::appl, ast_assert, ast_format_duration_hh_mm_ss(), ast_state2str(), ast_str_append(), ast_tvnow(), ast_channel_snapshot::base, CLI_INDENT_TO_SPACES, CLI_LAST_TABSTOP, ast_channel_snapshot::connected, context, ast_channel_snapshot_base::creationtime, ast_channel_snapshot::dialplan, ast_channel_snapshot_dialplan::exten, ast_channel_snapshot_connected::name, ast_channel_snapshot_base::name, NULL, ast_channel_snapshot_connected::number, and ast_channel_snapshot::state.

Referenced by pjsip_channel_cli_register().

◆ cli_channel_print_header()

static int cli_channel_print_header ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 247 of file cli_commands.c.

248 {
249  struct ast_sip_cli_context *context = arg;
250  int indent = CLI_INDENT_TO_SPACES(context->indent_level);
251  int filler = CLI_LAST_TABSTOP - indent - 13;
252 
253  ast_assert(context->output_buffer != NULL);
254 
255  ast_str_append(&context->output_buffer, 0,
256  "%*s: <ChannelId%*.*s> <State.....> <Time.....>\n",
257  indent, "Channel", filler, filler, CLI_HEADER_FILLER);
258  if (context->recurse) {
259  context->indent_level++;
260  indent = CLI_INDENT_TO_SPACES(context->indent_level);
261  filler = CLI_LAST_TABSTOP - indent - 38;
262  ast_str_append(&context->output_buffer, 0,
263  "%*s: <DialedExten%*.*s> CLCID: <ConnectedLineCID.......>\n",
264  indent, "Exten", filler, filler, CLI_HEADER_FILLER);
265  context->indent_level--;
266  }
267 
268  return 0;
269 }
#define CLI_HEADER_FILLER
Definition: res_pjsip_cli.h:24

References ast_assert, ast_str_append(), CLI_HEADER_FILLER, CLI_INDENT_TO_SPACES, CLI_LAST_TABSTOP, context, and NULL.

Referenced by pjsip_channel_cli_register().

◆ cli_channel_retrieve_by_id()

static void* cli_channel_retrieve_by_id ( const char *  id)
static

Definition at line 242 of file cli_commands.c.

243 {
245 }
struct ast_channel_snapshot * ast_channel_snapshot_get_latest_by_name(const char *name)
Obtain the latest ast_channel_snapshot from the Stasis Message Bus API cache. This is an ao2 object,...

References ast_channel_snapshot_get_latest_by_name().

Referenced by pjsip_channel_cli_register().

◆ cli_channel_sort()

static int cli_channel_sort ( const void *  obj,
const void *  arg,
int  flags 
)
static

Definition at line 55 of file cli_commands.c.

56 {
57  const struct ast_channel_snapshot *left_obj = obj;
58  const struct ast_channel_snapshot *right_obj = arg;
59  const char *right_key = arg;
60  int cmp;
61 
62  switch (flags & OBJ_SEARCH_MASK) {
63  case OBJ_SEARCH_OBJECT:
64  right_key = right_obj->base->name;
65  /* Fall through */
66  case OBJ_SEARCH_KEY:
67  cmp = strcmp(left_obj->base->name, right_key);
68  break;
70  cmp = strncmp(left_obj->base->name, right_key, strlen(right_key));
71  break;
72  default:
73  cmp = 0;
74  break;
75  }
76 
77  return cmp;
78 }

References ast_channel_snapshot::base, ast_channel_snapshot::flags, ast_channel_snapshot_base::name, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and OBJ_SEARCH_PARTIAL_KEY.

Referenced by cli_channel_get_container().

◆ cli_channelstats_compare()

static int cli_channelstats_compare ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 138 of file cli_commands.c.

139 {
140  const struct ast_channel_snapshot *left_obj = obj;
141  const struct ast_channel_snapshot *right_obj = arg;
142  const char *right_key = arg;
143  int cmp = 0;
144 
145  switch (flags & OBJ_SEARCH_MASK) {
146  case OBJ_SEARCH_OBJECT:
147  if (strcmp(left_obj->bridge->id, right_obj->bridge->id) == 0
148  && strcmp(left_obj->base->name, right_obj->base->name) == 0) {
149  return CMP_MATCH | CMP_STOP;
150  }
151  break;
152  case OBJ_SEARCH_KEY:
153  if (strcmp(left_obj->base->name, right_key) == 0) {
154  cmp = CMP_MATCH | CMP_STOP;
155  }
156  break;
158  if (strncmp(left_obj->base->name, right_key, strlen(right_key)) == 0) {
159  cmp = CMP_MATCH;
160  }
161  break;
162  default:
163  cmp = 0;
164  break;
165  }
166 
167  return cmp;
168 }
struct ast_channel_snapshot_bridge * bridge

References ast_channel_snapshot::base, ast_channel_snapshot::bridge, CMP_MATCH, CMP_STOP, ast_channel_snapshot::flags, ast_channel_snapshot_bridge::id, ast_channel_snapshot_base::name, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and OBJ_SEARCH_PARTIAL_KEY.

Referenced by cli_channelstats_get_container().

◆ cli_channelstats_get_container()

static struct ao2_container* cli_channelstats_get_container ( const char *  regex)
static

Definition at line 230 of file cli_commands.c.

231 {
233 }
static int cli_channelstats_compare(void *obj, void *arg, int flags)
Definition: cli_commands.c:138
static int cli_channelstats_sort(const void *obj, const void *arg, int flags)
Definition: cli_commands.c:80

References cli_channelstats_compare(), cli_channelstats_sort(), get_container(), and regex().

Referenced by pjsip_channel_cli_register().

◆ cli_channelstats_iterate()

static int cli_channelstats_iterate ( void *  endpoint,
ao2_callback_fn  callback,
void *  arg 
)
static

Definition at line 50 of file cli_commands.c.

51 {
52  return ast_sip_for_each_channel(endpoint, callback, arg);
53 }

References ast_sip_for_each_channel().

Referenced by pjsip_channel_cli_register().

◆ cli_channelstats_print_body()

static int cli_channelstats_print_body ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 337 of file cli_commands.c.

338 {
339  struct ast_sip_cli_context *context = arg;
340  const struct ast_channel_snapshot *snapshot = obj;
342  struct ast_sip_channel_pvt *cpvt = NULL;
343  struct ast_sip_session *session;
344  struct ast_sip_session_media *media;
345  struct ast_rtp_instance_stats stats;
346  char *print_name = NULL;
347  char *print_time = alloca(32);
348  char codec_in_use[7];
349  int stats_res = -1;
350 
351  ast_assert(context->output_buffer != NULL);
352 
353  if (!channel) {
354  ast_str_append(&context->output_buffer, 0, " %s not valid\n", snapshot->base->name);
355  return 0;
356  }
357 
358  ast_channel_lock(channel);
359 
360  cpvt = ast_channel_tech_pvt(channel);
361  session = cpvt ? cpvt->session : NULL;
362  if (!session) {
363  ast_str_append(&context->output_buffer, 0, " %s not valid\n", snapshot->base->name);
364  ast_channel_unlock(channel);
365  ao2_cleanup(channel);
366  return 0;
367  }
368 
369  media = session->active_media_state->default_session[AST_MEDIA_TYPE_AUDIO];
370  if (!media || !media->rtp) {
371  ast_str_append(&context->output_buffer, 0, " %s not valid\n", snapshot->base->name);
372  ast_channel_unlock(channel);
373  ao2_cleanup(channel);
374  return 0;
375  }
376 
377  codec_in_use[0] = '\0';
378 
379  if (ast_channel_rawreadformat(channel)) {
380  ast_copy_string(codec_in_use, ast_format_get_name(ast_channel_rawreadformat(channel)), sizeof(codec_in_use));
381  }
382 
383  stats_res = ast_rtp_instance_get_stats(media->rtp, &stats, AST_RTP_INSTANCE_STAT_ALL);
384  ast_channel_unlock(channel);
385 
386  print_name = ast_strdupa(snapshot->base->name);
387  /* Skip the PJSIP/. We know what channel type it is and we need the space. */
388  print_name += 6;
389 
390  ast_format_duration_hh_mm_ss(ast_tvnow().tv_sec - snapshot->base->creationtime.tv_sec, print_time, 32);
391 
392  if (stats_res == -1) {
393  ast_str_append(&context->output_buffer, 0, "%s direct media\n", snapshot->base->name);
394  } else {
395  ast_str_append(&context->output_buffer, 0,
396  " %8.8s %-18.18s %-8.8s %-6.6s %6u%s %6u%s %3u %7.3f %6u%s %6u%s %3u %7.3f %7.3f\n",
397  snapshot->bridge->id,
398  print_name,
399  print_time,
400  codec_in_use,
401  stats.rxcount > 100000 ? stats.rxcount / 1000 : stats.rxcount,
402  stats.rxcount > 100000 ? "K": " ",
403  stats.rxploss > 100000 ? stats.rxploss / 1000 : stats.rxploss,
404  stats.rxploss > 100000 ? "K": " ",
405  stats.rxcount ? (stats.rxploss * 100) / stats.rxcount : 0,
406  MIN(stats.rxjitter, 999.999),
407  stats.txcount > 100000 ? stats.txcount / 1000 : stats.txcount,
408  stats.txcount > 100000 ? "K": " ",
409  stats.txploss > 100000 ? stats.txploss / 1000 : stats.txploss,
410  stats.txploss > 100000 ? "K": " ",
411  stats.txcount ? (stats.txploss * 100) / stats.txcount : 0,
412  MIN(stats.txjitter, 999.999),
413  MIN(stats.normdevrtt, 999.999)
414  );
415  }
416 
417  ao2_cleanup(channel);
418 
419  return 0;
420 }
static struct ast_mansession session
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
void * ast_channel_tech_pvt(const struct ast_channel *chan)
#define ast_channel_lock(chan)
Definition: channel.h:2922
struct ast_format * ast_channel_rawreadformat(struct ast_channel *chan)
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1448
#define ast_channel_unlock(chan)
Definition: channel.h:2923
@ AST_MEDIA_TYPE_AUDIO
Definition: codec.h:32
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
@ AST_RTP_INSTANCE_STAT_ALL
Definition: rtp_engine.h:182
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:2438
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:406
Main Channel structure associated with a channel.
struct ast_channel_snapshot * snapshot
A structure which contains a channel implementation and session.
struct ast_sip_session * session
Pointer to session.
A structure containing SIP session media information.
struct ast_rtp_instance * rtp
RTP instance itself.
A structure describing a SIP session.
#define MIN(a, b)
Definition: utils.h:226

References ao2_cleanup, ast_assert, ast_channel_get_by_name(), ast_channel_lock, ast_channel_rawreadformat(), ast_channel_tech_pvt(), ast_channel_unlock, ast_copy_string(), ast_format_duration_hh_mm_ss(), ast_format_get_name(), AST_MEDIA_TYPE_AUDIO, ast_rtp_instance_get_stats(), AST_RTP_INSTANCE_STAT_ALL, ast_str_append(), ast_strdupa, ast_tvnow(), ast_channel_snapshot::base, ast_channel_snapshot::bridge, context, ast_channel_snapshot_base::creationtime, ast_channel_snapshot_bridge::id, MIN, ast_channel_snapshot_base::name, ast_rtp_instance_stats::normdevrtt, NULL, ast_sip_session_media::rtp, ast_rtp_instance_stats::rxcount, ast_rtp_instance_stats::rxjitter, ast_rtp_instance_stats::rxploss, ast_sip_channel_pvt::session, session, ast_channel::snapshot, ast_rtp_instance_stats::txcount, ast_rtp_instance_stats::txjitter, and ast_rtp_instance_stats::txploss.

Referenced by pjsip_channel_cli_register().

◆ cli_channelstats_print_header()

static int cli_channelstats_print_header ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 323 of file cli_commands.c.

324 {
325  struct ast_sip_cli_context *context = arg;
326 
327  ast_assert(context->output_buffer != NULL);
328 
329  ast_str_append(&context->output_buffer, 0,
330  " ...........Receive......... .........Transmit..........\n"
331  " BridgeId ChannelId ........ UpTime.. Codec. Count Lost Pct Jitter Count Lost Pct Jitter RTT....\n"
332  " =================");
333 
334  return 0;
335 }

References ast_assert, ast_str_append(), context, and NULL.

Referenced by pjsip_channel_cli_register().

◆ cli_channelstats_sort()

static int cli_channelstats_sort ( const void *  obj,
const void *  arg,
int  flags 
)
static

Definition at line 80 of file cli_commands.c.

81 {
82  const struct ast_channel_snapshot *left_obj = obj;
83  const struct ast_channel_snapshot *right_obj = arg;
84  const char *right_key = arg;
85  int cmp;
86 
87  switch (flags & OBJ_SEARCH_MASK) {
88  case OBJ_SEARCH_OBJECT:
89  cmp = strcmp(left_obj->bridge->id, right_obj->bridge->id);
90  if (cmp) {
91  return cmp;
92  }
93  right_key = right_obj->base->name;
94  /* Fall through */
95  case OBJ_SEARCH_KEY:
96  cmp = strcmp(left_obj->base->name, right_key);
97  break;
99  cmp = strncmp(left_obj->base->name, right_key, strlen(right_key));
100  break;
101  default:
102  cmp = 0;
103  break;
104  }
105 
106  return cmp;
107 }

References ast_channel_snapshot::base, ast_channel_snapshot::bridge, ast_channel_snapshot::flags, ast_channel_snapshot_bridge::id, ast_channel_snapshot_base::name, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and OBJ_SEARCH_PARTIAL_KEY.

Referenced by cli_channelstats_get_container().

◆ cli_filter_channels()

static int cli_filter_channels ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 183 of file cli_commands.c.

184 {
185  struct ast_channel_snapshot *channel = obj;
186  regex_t *regexbuf = arg;
187 
188  if (!regexec(regexbuf, channel->base->name, 0, NULL, 0)
189  || !regexec(regexbuf, channel->dialplan->appl, 0, NULL, 0)) {
190  return 0;
191  }
192 
193  return CMP_MATCH;
194 }

References ast_channel_snapshot_dialplan::appl, ast_channel_snapshot::base, CMP_MATCH, ast_channel_snapshot::dialplan, ast_channel_snapshot_base::name, and NULL.

Referenced by get_container().

◆ cli_message_to_snapshot()

static int cli_message_to_snapshot ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 170 of file cli_commands.c.

171 {
172  struct ast_channel_snapshot *snapshot = obj;
173  struct ao2_container *snapshots = arg;
174 
175  if (!strcmp(snapshot->base->type, "PJSIP")) {
176  ao2_link(snapshots, snapshot);
177  return CMP_MATCH;
178  }
179 
180  return 0;
181 }
#define ao2_link(container, obj)
Add an object to a container.
Definition: astobj2.h:1532
Generic container type.
const ast_string_field type

References ao2_link, ast_channel_snapshot::base, CMP_MATCH, and ast_channel_snapshot_base::type.

Referenced by get_container().

◆ get_container()

static struct ao2_container* get_container ( const char *  regex,
ao2_sort_fn  sort_fn,
ao2_callback_fn  compare_fn 
)
static

Definition at line 196 of file cli_commands.c.

197 {
198  struct ao2_container *child_container;
199  regex_t regexbuf;
200  RAII_VAR(struct ao2_container *, parent_container, ast_channel_cache_by_name(), ao2_cleanup);
201 
202  if (!parent_container) {
203  return NULL;
204  }
205 
206  child_container = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, sort_fn, compare_fn);
207  if (!child_container) {
208  return NULL;
209  }
210 
211  ao2_callback(parent_container, OBJ_MULTIPLE | OBJ_NODATA, cli_message_to_snapshot, child_container);
212 
213  if (!ast_strlen_zero(regex)) {
214  if (regcomp(&regexbuf, regex, REG_EXTENDED | REG_NOSUB)) {
215  ao2_ref(child_container, -1);
216  return NULL;
217  }
218  ao2_callback(child_container, OBJ_UNLINK | OBJ_MULTIPLE | OBJ_NODATA, cli_filter_channels, &regexbuf);
219  regfree(&regexbuf);
220  }
221 
222  return child_container;
223 }
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition: astobj2.h:367
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
Definition: astobj2.h:1693
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
@ OBJ_NODATA
Definition: astobj2.h:1044
@ OBJ_MULTIPLE
Definition: astobj2.h:1049
@ OBJ_UNLINK
Definition: astobj2.h:1039
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a list container.
Definition: astobj2.h:1327
static int cli_message_to_snapshot(void *obj, void *arg, int flags)
Definition: cli_commands.c:170
static int cli_filter_channels(void *obj, void *arg, int flags)
Definition: cli_commands.c:183
struct ao2_container * ast_channel_cache_by_name(void)
Secondary channel cache, indexed by name.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
#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:936

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_callback, ao2_cleanup, ao2_container_alloc_list, ao2_ref, ast_channel_cache_by_name(), ast_strlen_zero(), cli_filter_channels(), cli_message_to_snapshot(), NULL, OBJ_MULTIPLE, OBJ_NODATA, OBJ_UNLINK, RAII_VAR, regex(), and ao2_container::sort_fn.

Referenced by cli_channel_get_container(), and cli_channelstats_get_container().

◆ pjsip_channel_cli_register()

int pjsip_channel_cli_register ( void  )

Registers the channel cli commands.

Since
13.9.0
Return values
0on success
-1on failure

Definition at line 448 of file cli_commands.c.

449 {
451  if (!channel_formatter) {
452  ast_log(LOG_ERROR, "Unable to allocate memory for channel_formatter\n");
453  return -1;
454  }
455  channel_formatter->name = "channel";
462 
464  if (!channelstats_formatter) {
466  ast_log(LOG_ERROR, "Unable to allocate memory for channelstats_formatter\n");
467  return -1;
468  }
469  channelstats_formatter->name = "channelstat";
476 
480 
481  return 0;
482 }
#define ast_log
Definition: astobj2.c:42
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
static void * cli_channel_retrieve_by_id(const char *id)
Definition: cli_commands.c:242
static int cli_channelstats_print_header(void *obj, void *arg, int flags)
Definition: cli_commands.c:323
static struct ast_cli_entry cli_commands[]
Definition: cli_commands.c:422
static int cli_channelstats_print_body(void *obj, void *arg, int flags)
Definition: cli_commands.c:337
static struct ao2_container * cli_channelstats_get_container(const char *regex)
Definition: cli_commands.c:230
static int cli_channel_print_header(void *obj, void *arg, int flags)
Definition: cli_commands.c:247
static int cli_channelstats_iterate(void *endpoint, ao2_callback_fn callback, void *arg)
Definition: cli_commands.c:50
static const char * cli_channel_get_id(const void *obj)
Definition: cli_commands.c:235
struct ast_sip_cli_formatter_entry * channelstats_formatter
Definition: cli_commands.c:445
struct ast_sip_cli_formatter_entry * channel_formatter
Definition: cli_commands.c:446
static int cli_channel_iterate(void *endpoint, ao2_callback_fn callback, void *arg)
Definition: cli_commands.c:45
static struct ao2_container * cli_channel_get_container(const char *regex)
Definition: cli_commands.c:225
static int cli_channel_print_body(void *obj, void *arg, int flags)
Definition: cli_commands.c:271
#define LOG_ERROR
int ast_sip_register_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Registers a CLI formatter.
Definition: pjsip_cli.c:310
CLI Formatter Registry Entry.
Definition: res_pjsip_cli.h:52
int(* iterate)(void *container, ao2_callback_fn callback, void *args)
Definition: res_pjsip_cli.h:66
ao2_callback_fn * print_header
Definition: res_pjsip_cli.h:60
const char *(* get_id)(const void *obj)
Definition: res_pjsip_cli.h:70
struct ao2_container *(* get_container)(const char *regex)
Definition: res_pjsip_cli.h:64
void *(* retrieve_by_id)(const char *id)
Definition: res_pjsip_cli.h:68
const char * name
Definition: res_pjsip_cli.h:58
ao2_callback_fn * print_body
Definition: res_pjsip_cli.h:62
#define ARRAY_LEN(a)
Definition: utils.h:661

References ao2_alloc, ao2_ref, ARRAY_LEN, ast_cli_register_multiple, ast_log, ast_sip_register_cli_formatter(), channel_formatter, channelstats_formatter, cli_channel_get_container(), cli_channel_get_id(), cli_channel_iterate(), cli_channel_print_body(), cli_channel_print_header(), cli_channel_retrieve_by_id(), cli_channelstats_get_container(), cli_channelstats_iterate(), cli_channelstats_print_body(), cli_channelstats_print_header(), cli_commands, ast_sip_cli_formatter_entry::get_container, ast_sip_cli_formatter_entry::get_id, ast_sip_cli_formatter_entry::iterate, LOG_ERROR, ast_sip_cli_formatter_entry::name, NULL, ast_sip_cli_formatter_entry::print_body, ast_sip_cli_formatter_entry::print_header, and ast_sip_cli_formatter_entry::retrieve_by_id.

Referenced by load_module().

◆ pjsip_channel_cli_unregister()

void pjsip_channel_cli_unregister ( void  )

Unregisters the channel cli commands.

Since
13.9.0

Definition at line 484 of file cli_commands.c.

485 {
489 }
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
int ast_sip_unregister_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Unregisters a CLI formatter.
Definition: pjsip_cli.c:326

References ARRAY_LEN, ast_cli_unregister_multiple(), ast_sip_unregister_cli_formatter(), channel_formatter, channelstats_formatter, and cli_commands.

Variable Documentation

◆ channel_formatter

struct ast_sip_cli_formatter_entry* channel_formatter

Definition at line 446 of file cli_commands.c.

Referenced by pjsip_channel_cli_register(), and pjsip_channel_cli_unregister().

◆ channelstats_formatter

struct ast_sip_cli_formatter_entry* channelstats_formatter

Definition at line 445 of file cli_commands.c.

Referenced by pjsip_channel_cli_register(), and pjsip_channel_cli_unregister().

◆ cli_commands

struct ast_cli_entry cli_commands[]
static

Definition at line 337 of file cli_commands.c.

Referenced by pjsip_channel_cli_register(), and pjsip_channel_cli_unregister().