Asterisk - The Open Source Telephony Project  18.5.0
Functions | Variables
pjsip_cli.c File Reference
#include "asterisk.h"
#include <pjsip.h>
#include <pjsip_ua.h>
#include "asterisk/res_pjsip.h"
#include "include/res_pjsip_private.h"
#include "asterisk/res_pjsip_cli.h"
#include "asterisk/acl.h"
#include "asterisk/cli.h"
#include "asterisk/astobj2.h"
#include "asterisk/hashtab.h"
#include "asterisk/utils.h"
#include "asterisk/sorcery.h"
Include dependency graph for pjsip_cli.c:

Go to the source code of this file.

Functions

int ast_sip_cli_print_sorcery_objectset (void *obj, void *arg, int flags)
 Prints a sorcery object's ast_variable list. More...
 
char * ast_sip_cli_traverse_objects (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
void ast_sip_destroy_cli (void)
 
int ast_sip_initialize_cli (void)
 
struct ast_sip_cli_formatter_entryast_sip_lookup_cli_formatter (const char *name)
 Looks up a CLI formatter by type. More...
 
int ast_sip_register_cli_formatter (struct ast_sip_cli_formatter_entry *formatter)
 Registers a CLI formatter. More...
 
int ast_sip_unregister_cli_formatter (struct ast_sip_cli_formatter_entry *formatter)
 Unregisters a CLI formatter. More...
 
static void complete_show_sorcery_object (struct ao2_container *container, struct ast_sip_cli_formatter_entry *formatter_entry, const char *word)
 
static void dump_str_and_free (int fd, struct ast_str *buf)
 
static int formatter_compare (void *obj, void *arg, int flags)
 
static int formatter_hash (const void *obj, int flags)
 
static int formatter_sort (const void *obj, const void *arg, int flags)
 
static char * handle_pjsip_show_version (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 

Variables

static struct ao2_containerformatter_registry
 
static struct ast_cli_entry pjsip_cli []
 

Function Documentation

◆ ast_sip_cli_print_sorcery_objectset()

int ast_sip_cli_print_sorcery_objectset ( void *  obj,
void *  arg,
int  flags 
)

Prints a sorcery object's ast_variable list.

Parameters
objThe sorcery object
argThe ast_sip_cli_context.
Return values
0Success, non-zero on failure

Definition at line 36 of file pjsip_cli.c.

References ast_alloca, ast_sip_get_sorcery(), ast_sorcery_objectset_create, ast_str_append(), ast_variable_list_sort(), ast_variables_destroy(), context, ast_variable::name, ast_variable::next, ast_sip_cli_context::output_buffer, and ast_variable::value.

Referenced by cli_aor_print_body(), cli_endpoint_print_body(), cli_print_body(), sip_cli_print_global(), and sip_cli_print_system().

37 {
38  struct ast_sip_cli_context *context = arg;
39  struct ast_variable *i;
40  int max_name_width = 13;
41  int max_value_width = 14;
42  int width;
43  char *separator;
44  struct ast_variable *objset;
45 
46  if (!context->output_buffer) {
47  return -1;
48  }
49 
51  if (!objset) {
52  return -1;
53  }
54 
55  for (i = objset; i; i = i->next) {
56  if (i->name) {
57  width = strlen(i->name);
58  max_name_width = width > max_name_width ? width : max_name_width;
59  }
60  if (i->value) {
61  width = strlen(i->value);
62  max_value_width = width > max_value_width ? width : max_value_width;
63  }
64  }
65 
66  separator = ast_alloca(max_name_width + max_value_width + 8);
67 
68  memset(separator, '=', max_name_width + max_value_width + 3);
69  separator[max_name_width + max_value_width + 3] = 0;
70 
71  ast_str_append(&context->output_buffer, 0, " %-*s : %s\n", max_name_width, "ParameterName", "ParameterValue");
72  ast_str_append(&context->output_buffer, 0, " %s\n", separator);
73 
74  objset = ast_variable_list_sort(objset);
75 
76  for (i = objset; i; i = i->next) {
77  ast_str_append(&context->output_buffer, 0, " %-*s : %s\n", max_name_width, i->name, i->value);
78  }
79 
80  ast_variables_destroy(objset);
81 
82  return 0;
83 }
struct ast_str * output_buffer
Definition: res_pjsip_cli.h:36
struct ast_variable * next
struct ast_variable * ast_variable_list_sort(struct ast_variable *head)
Performs an in-place sort on the variable list by ascending name.
Definition: main/config.c:622
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1263
Structure for variables, used for configurations and for channel variables.
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:1091
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:290
#define ast_sorcery_objectset_create(sorcery, object)
Create an object set (KVP list) for an object.
Definition: sorcery.h:1136
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

◆ ast_sip_cli_traverse_objects()

char* ast_sip_cli_traverse_objects ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)

Definition at line 109 of file pjsip_cli.c.

References ao2_callback, ao2_cleanup, ao2_container_count(), ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_copy_string(), ast_ends_with(), ast_free, ast_log, ast_sip_lookup_cli_formatter(), ast_str_append(), ast_str_create, ast_strlen_zero, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::cmda, complete_show_sorcery_object(), container, dump_str_and_free(), ast_cli_args::fd, ast_sip_cli_context::indent_level, LOG_ERROR, NULL, OBJ_NODATA, ast_sip_cli_context::output_buffer, RAII_VAR, ast_sip_cli_context::recurse, regex(), ast_sip_cli_context::show_details_only_level_0, and ast_cli_args::word.

Referenced by my_cli_traverse_objects().

110 {
112  RAII_VAR(struct ast_sip_cli_formatter_entry *, formatter_entry, NULL, ao2_cleanup);
113  RAII_VAR(void *, object, NULL, ao2_cleanup);
114  int is_container = 0;
115  const char *cmd1;
116  const char *cmd2;
117  const char *object_id;
118  char formatter_type[64];
119  const char *regex;
120 
121  struct ast_sip_cli_context context = {
122  .indent_level = 0,
123  .show_details = 0,
124  .show_details_only_level_0 = 0,
125  .recurse = 0,
126  };
127 
128  if (cmd == CLI_INIT) {
129  return NULL;
130  }
131 
132  cmd1 = e->cmda[1];
133  cmd2 = e->cmda[2];
134  object_id = a->argv[3];
135 
136  if (!ast_ends_with(cmd2, "s")) {
137  ast_copy_string(formatter_type, cmd2, sizeof(formatter_type));
138  is_container = 0;
139  } else if (ast_ends_with(cmd2, "ies")) {
140  /* Take the plural "ies" off of the object name and re[place with "y". */
141  int l = strlen(cmd2);
142  snprintf(formatter_type, 64, "%*.*sy", l - 3, l - 3, cmd2);
143  is_container = 1;
144  } else {
145  /* Take the plural "s" off of the object name. */
146  ast_copy_string(formatter_type, cmd2, strlen(cmd2));
147  is_container = 1;
148  }
149 
150  if (!strcmp(cmd1, "show")) {
151  context.show_details_only_level_0 = !is_container;
152  context.recurse = 1;
153  } else {
154  is_container = 1;
155  }
156 
157  if (cmd != CLI_GENERATE
158  && is_container
159  && a->argc >= 4
160  && strcmp(object_id, "like") == 0) {
161  if (ast_strlen_zero(a->argv[4])) {
162  return CLI_SHOWUSAGE;
163  }
164  regex = a->argv[4];
165  } else {
166  regex = "";
167  }
168 
169  if (cmd == CLI_GENERATE
170  && (is_container
171  || a->argc > 4
172  || (a->argc == 4 && ast_strlen_zero(a->word)))) {
173  return CLI_SUCCESS;
174  }
175 
176  context.output_buffer = ast_str_create(256);
177  if (!context.output_buffer) {
178  return CLI_FAILURE;
179  }
180 
181  formatter_entry = ast_sip_lookup_cli_formatter(formatter_type);
182  if (!formatter_entry) {
183  ast_log(LOG_ERROR, "No formatter registered for object type %s.\n",
184  formatter_type);
185  ast_free(context.output_buffer);
186  return CLI_FAILURE;
187  }
188  ast_str_append(&context.output_buffer, 0, "\n");
189  formatter_entry->print_header(NULL, &context, 0);
190  ast_str_append(&context.output_buffer, 0,
191  "==========================================================================================\n\n");
192 
193  if (is_container || cmd == CLI_GENERATE) {
194  container = formatter_entry->get_container(regex);
195  if (!container) {
196  ast_cli(a->fd, "No container returned for object type %s.\n",
197  formatter_type);
198  ast_free(context.output_buffer);
199  return CLI_FAILURE;
200  }
201  }
202 
203  if (cmd == CLI_GENERATE) {
204  ast_free(context.output_buffer);
205  complete_show_sorcery_object(container, formatter_entry, a->word);
206  return NULL;
207  }
208 
209  if (is_container) {
211  ast_free(context.output_buffer);
212  ast_cli(a->fd, "No objects found.\n\n");
213  return CLI_SUCCESS;
214  }
215  ao2_callback(container, OBJ_NODATA, formatter_entry->print_body, &context);
216  ast_str_append(&context.output_buffer, 0, "\nObjects found: %d\n", ao2_container_count(container));
217 
218  } else {
219  if (ast_strlen_zero(object_id)) {
220  ast_free(context.output_buffer);
221  ast_cli(a->fd, "No object specified.\n");
222  return CLI_FAILURE;
223  }
224 
225  object = formatter_entry->retrieve_by_id(object_id);
226  if (!object) {
227  ast_free(context.output_buffer);
228  ast_cli(a->fd, "Unable to find object %s.\n\n", object_id);
229  return CLI_SUCCESS;
230  }
231  formatter_entry->print_body(object, &context, 0);
232  }
233 
234  ast_str_append(&context.output_buffer, 0, "\n");
235  dump_str_and_free(a->fd, context.output_buffer);
236  return CLI_SUCCESS;
237 }
struct ast_str * output_buffer
Definition: res_pjsip_cli.h:36
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
Definition: res_pjsip_cli.h:52
static int force_inline attribute_pure ast_ends_with(const char *str, const char *suffix)
Definition: strings.h:112
const int argc
Definition: cli.h:160
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
struct ast_sip_cli_formatter_entry * ast_sip_lookup_cli_formatter(const char *name)
Looks up a CLI formatter by type.
Definition: pjsip_cli.c:305
Definition: cli.h:152
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:1091
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
#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:911
const int fd
Definition: cli.h:159
struct ao2_container * container
Definition: res_fax.c:502
const char *const * argv
Definition: cli.h:161
static void dump_str_and_free(int fd, struct ast_str *buf)
Definition: pjsip_cli.c:103
#define LOG_ERROR
Definition: logger.h:285
#define CLI_SHOWUSAGE
Definition: cli.h:45
static void complete_show_sorcery_object(struct ao2_container *container, struct ast_sip_cli_formatter_entry *formatter_entry, const char *word)
Definition: pjsip_cli.c:85
#define CLI_FAILURE
Definition: cli.h:46
#define ast_free(a)
Definition: astmm.h:182
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:948
const char * word
Definition: cli.h:163
#define CLI_SUCCESS
Definition: cli.h:44
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
Generic container type.
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
const char *const cmda[AST_MAX_CMD_LEN]
Definition: cli.h:172
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620
unsigned show_details_only_level_0
Definition: res_pjsip_cli.h:46

◆ ast_sip_destroy_cli()

void ast_sip_destroy_cli ( void  )

Definition at line 375 of file pjsip_cli.c.

References ao2_ref, ARRAY_LEN, and ast_cli_unregister_multiple().

Referenced by ast_res_pjsip_destroy_configuration().

376 {
379 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
static struct ao2_container * formatter_registry
Definition: pjsip_cli.c:34
#define ao2_ref(o, delta)
Definition: astobj2.h:464
static struct ast_cli_entry pjsip_cli[]
Definition: pjsip_cli.c:356

◆ ast_sip_initialize_cli()

int ast_sip_initialize_cli ( void  )

Definition at line 360 of file pjsip_cli.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_container_alloc_hash, ARRAY_LEN, ast_cli_register_multiple, ast_log, formatter_compare(), formatter_hash(), formatter_sort(), and LOG_ERROR.

Referenced by ast_res_pjsip_initialize_configuration().

361 {
364 
365  if (!formatter_registry) {
366  ast_log(LOG_ERROR, "Unable to create formatter_registry.\n");
367  return -1;
368  }
369 
371 
372  return 0;
373 }
static int formatter_hash(const void *obj, int flags)
Definition: pjsip_cli.c:293
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static int formatter_compare(void *obj, void *arg, int flags)
Definition: pjsip_cli.c:264
static int formatter_sort(const void *obj, const void *arg, int flags)
Definition: pjsip_cli.c:239
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
#define ast_log
Definition: astobj2.c:42
static struct ao2_container * formatter_registry
Definition: pjsip_cli.c:34
static struct ast_cli_entry pjsip_cli[]
Definition: pjsip_cli.c:356
#define LOG_ERROR
Definition: logger.h:285
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Definition: astobj2.h:1310

◆ ast_sip_lookup_cli_formatter()

struct ast_sip_cli_formatter_entry* ast_sip_lookup_cli_formatter ( const char *  name)

Looks up a CLI formatter by type.

Parameters
nameThe name of the formatter, usually the sorcery object type.
Return values
Pointerto formatter entry structure

Definition at line 305 of file pjsip_cli.c.

References ao2_find, OBJ_NOLOCK, and OBJ_SEARCH_KEY.

Referenced by ast_sip_cli_traverse_objects(), cli_aor_print_body(), cli_aor_print_header(), cli_endpoint_print_child_body(), and cli_endpoint_print_child_header().

306 {
308 }
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
Assume that the ao2_container is already locked.
Definition: astobj2.h:1067
static struct ao2_container * formatter_registry
Definition: pjsip_cli.c:34
static const char name[]
Definition: cdr_mysql.c:74
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756

◆ ast_sip_register_cli_formatter()

int ast_sip_register_cli_formatter ( struct ast_sip_cli_formatter_entry formatter)

Registers a CLI formatter.

Parameters
nameThe name of the formatter, usually the sorcery object type.
formatterAn ao2_callback_fn that outputs the formatted data.
Return values
0Success, non-zero on failure

Definition at line 310 of file pjsip_cli.c.

References ao2_link, ast_assert, ast_sip_cli_formatter_entry::get_container, ast_sip_cli_formatter_entry::get_id, ast_sip_cli_formatter_entry::iterate, 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 ast_res_pjsip_initialize_configuration(), ast_sip_initialize_distributor(), ast_sip_initialize_sorcery_auth(), ast_sip_initialize_sorcery_location(), ast_sip_initialize_sorcery_transport(), load_module(), and pjsip_channel_cli_register().

311 {
312  ast_assert(formatter != NULL);
313  ast_assert(formatter->name != NULL);
314  ast_assert(formatter->print_body != NULL);
315  ast_assert(formatter->print_header != NULL);
316  ast_assert(formatter->get_container != NULL);
317  ast_assert(formatter->iterate != NULL);
318  ast_assert(formatter->get_id != NULL);
319  ast_assert(formatter->retrieve_by_id != NULL);
320 
321  ao2_link(formatter_registry, formatter);
322 
323  return 0;
324 }
struct ao2_container *(* get_container)(const char *regex)
Definition: res_pjsip_cli.h:64
int(* iterate)(void *container, ao2_callback_fn callback, void *args)
Definition: res_pjsip_cli.h:66
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
static struct ao2_container * formatter_registry
Definition: pjsip_cli.c:34
void *(* retrieve_by_id)(const char *id)
Definition: res_pjsip_cli.h:68
const char *(* get_id)(const void *obj)
Definition: res_pjsip_cli.h:70
ao2_callback_fn * print_header
Definition: res_pjsip_cli.h:60
ao2_callback_fn * print_body
Definition: res_pjsip_cli.h:62
const char * name
Definition: res_pjsip_cli.h:58
#define ao2_link(container, obj)
Definition: astobj2.h:1549

◆ ast_sip_unregister_cli_formatter()

int ast_sip_unregister_cli_formatter ( struct ast_sip_cli_formatter_entry formatter)

Unregisters a CLI formatter.

Parameters
nameThe name of the formatter, usually the sorcery object type.
Return values
0Success, non-zero on failure

Definition at line 326 of file pjsip_cli.c.

References ao2_ref, ao2_unlink_flags, ao2_unlock, ao2_wrlock, and OBJ_NOLOCK.

Referenced by ast_res_pjsip_destroy_configuration(), ast_sip_destroy_distributor(), ast_sip_destroy_sorcery_auth(), ast_sip_destroy_sorcery_location(), ast_sip_destroy_sorcery_transport(), pjsip_channel_cli_unregister(), and unload_module().

327 {
328  if (formatter) {
330  if (ao2_ref(formatter, -1) == 2) {
332  }
334  }
335  return 0;
336 }
Assume that the ao2_container is already locked.
Definition: astobj2.h:1067
#define ao2_unlock(a)
Definition: astobj2.h:730
#define ao2_wrlock(a)
Definition: astobj2.h:720
static struct ao2_container * formatter_registry
Definition: pjsip_cli.c:34
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ao2_unlink_flags(container, obj, flags)
Definition: astobj2.h:1622

◆ complete_show_sorcery_object()

static void complete_show_sorcery_object ( struct ao2_container container,
struct ast_sip_cli_formatter_entry formatter_entry,
const char *  word 
)
static

Definition at line 85 of file pjsip_cli.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_t_iterator_next, ao2_t_ref, ast_cli_completion_add(), ast_strdup, ast_sip_cli_formatter_entry::get_id, and ast_variable::object.

Referenced by ast_sip_cli_traverse_objects().

88 {
89  size_t wordlen = strlen(word);
90  void *object;
91  struct ao2_iterator i = ao2_iterator_init(container, 0);
92 
93  while ((object = ao2_t_iterator_next(&i, "iterate thru endpoints table"))) {
94  const char *id = formatter_entry->get_id(object);
95  if (!strncasecmp(word, id, wordlen)) {
97  }
98  ao2_t_ref(object, -1, "toss iterator endpoint ptr before break");
99  }
101 }
#define ao2_t_ref(o, delta, tag)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:463
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define ao2_t_iterator_next(iter, tag)
Definition: astobj2.h:1931
const char *(* get_id)(const void *obj)
Definition: res_pjsip_cli.h:70
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1841
int ast_cli_completion_add(char *value)
Add a result to a request for completion options.
Definition: main/cli.c:2726
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
short word

◆ dump_str_and_free()

static void dump_str_and_free ( int  fd,
struct ast_str buf 
)
static

Definition at line 103 of file pjsip_cli.c.

References ast_cli(), ast_free, and ast_str_buffer().

Referenced by ast_sip_cli_traverse_objects().

104 {
105  ast_cli(fd, "%s", ast_str_buffer(buf));
106  ast_free(buf);
107 }
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
#define ast_free(a)
Definition: astmm.h:182

◆ formatter_compare()

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

Definition at line 264 of file pjsip_cli.c.

References CMP_MATCH, CMP_STOP, ast_sip_cli_formatter_entry::name, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and OBJ_SEARCH_PARTIAL_KEY.

Referenced by ast_sip_initialize_cli().

265 {
266  const struct ast_sip_cli_formatter_entry *left_obj = obj;
267  const struct ast_sip_cli_formatter_entry *right_obj = arg;
268  const char *right_key = arg;
269  int cmp = 0;
270 
271  switch (flags & OBJ_SEARCH_MASK) {
272  case OBJ_SEARCH_OBJECT:
273  right_key = right_obj->name;
274  /* Fall through */
275  case OBJ_SEARCH_KEY:
276  if (strcmp(left_obj->name, right_key) == 0) {;
277  cmp = CMP_MATCH | CMP_STOP;
278  }
279  break;
281  if (strncmp(left_obj->name, right_key, strlen(right_key)) == 0) {
282  cmp = CMP_MATCH;
283  }
284  break;
285  default:
286  cmp = 0;
287  break;
288  }
289 
290  return cmp;
291 }
Definition: res_pjsip_cli.h:52
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition: astobj2.h:1120
The arg parameter is an object of the same type.
Definition: astobj2.h:1091
Search option field mask.
Definition: astobj2.h:1076
const char * name
Definition: res_pjsip_cli.h:58

◆ formatter_hash()

static int formatter_hash ( const void *  obj,
int  flags 
)
static

Definition at line 293 of file pjsip_cli.c.

References ast_str_hash(), ast_sip_cli_formatter_entry::name, OBJ_SEARCH_KEY, and OBJ_SEARCH_OBJECT.

Referenced by ast_sip_initialize_cli().

294 {
295  const struct ast_sip_cli_formatter_entry *left_obj = obj;
296  if (flags & OBJ_SEARCH_OBJECT) {
297  return ast_str_hash(left_obj->name);
298  } else if (flags & OBJ_SEARCH_KEY) {
299  return ast_str_hash(obj);
300  }
301 
302  return -1;
303 }
Definition: res_pjsip_cli.h:52
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
The arg parameter is an object of the same type.
Definition: astobj2.h:1091
const char * name
Definition: res_pjsip_cli.h:58
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
Definition: strings.h:1206

◆ formatter_sort()

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

Definition at line 239 of file pjsip_cli.c.

References ast_sip_cli_formatter_entry::name, OBJ_SEARCH_KEY, OBJ_SEARCH_MASK, OBJ_SEARCH_OBJECT, and OBJ_SEARCH_PARTIAL_KEY.

Referenced by ast_sip_initialize_cli().

240 {
241  const struct ast_sip_cli_formatter_entry *left_obj = obj;
242  const struct ast_sip_cli_formatter_entry *right_obj = arg;
243  const char *right_key = arg;
244  int cmp = 0;
245 
246  switch (flags & OBJ_SEARCH_MASK) {
247  case OBJ_SEARCH_OBJECT:
248  right_key = right_obj->name;
249  /* Fall through */
250  case OBJ_SEARCH_KEY:
251  cmp = strcmp(left_obj->name, right_key);
252  break;
254  cmp = strncmp(left_obj->name, right_key, strlen(right_key));
255  break;
256  default:
257  cmp = 0;
258  break;
259  }
260 
261  return cmp;
262 }
Definition: res_pjsip_cli.h:52
The arg parameter is a search key, but is not an object.
Definition: astobj2.h:1105
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Definition: astobj2.h:1120
The arg parameter is an object of the same type.
Definition: astobj2.h:1091
Search option field mask.
Definition: astobj2.h:1076
const char * name
Definition: res_pjsip_cli.h:58

◆ handle_pjsip_show_version()

static char* handle_pjsip_show_version ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 338 of file pjsip_cli.c.

References ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, NULL, and ast_cli_entry::usage.

339 {
340  switch(cmd) {
341  case CLI_INIT:
342  e->command = "pjsip show version";
343  e->usage =
344  "Usage: pjsip show version\n"
345  " Show the version of pjproject that res_pjsip is running against\n";
346  return NULL;
347  case CLI_GENERATE:
348  return NULL;
349  }
350 
351  ast_cli(a->fd, "PJPROJECT version currently running against: %s\n", pj_get_version());
352 
353  return CLI_SUCCESS;
354 }
Definition: cli.h:152
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
const int fd
Definition: cli.h:159
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44

Variable Documentation

◆ formatter_registry

struct ao2_container* formatter_registry
static

Definition at line 34 of file pjsip_cli.c.

◆ pjsip_cli

struct ast_cli_entry pjsip_cli[]
static
Initial value:
= {
{ .handler = handle_pjsip_show_version , .summary = "Show the version of pjproject in use" ,},
}
static char * handle_pjsip_show_version(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: pjsip_cli.c:338

Definition at line 356 of file pjsip_cli.c.