24 #include "asterisk/res_pjsip.h"
25 #include "include/res_pjsip_private.h"
26 #include "asterisk/res_pjsip_cli.h"
36 int ast_sip_cli_print_sorcery_objectset(
void *obj,
void *arg,
int flags)
40 int max_name_width = 13;
41 int max_value_width = 14;
55 for (i = objset; i; i = i->
next) {
57 width = strlen(i->
name);
58 max_name_width = width > max_name_width ? width : max_name_width;
61 width = strlen(i->
value);
62 max_value_width = width > max_value_width ? width : max_value_width;
66 separator =
ast_alloca(max_name_width + max_value_width + 8);
68 memset(separator,
'=', max_name_width + max_value_width + 3);
69 separator[max_name_width + max_value_width + 3] = 0;
76 for (i = objset; i; i = i->
next) {
89 size_t wordlen = strlen(word);
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)) {
98 ao2_t_ref(
object, -1,
"toss iterator endpoint ptr before break");
103 static void dump_str_and_free(
int fd,
struct ast_str *buf)
113 RAII_VAR(
void *,
object, NULL, ao2_cleanup);
114 int is_container = 0;
117 const char *object_id;
118 char formatter_type[64];
124 .show_details_only_level_0 = 0,
128 if (cmd == CLI_INIT) {
134 object_id = a->argv[3];
141 int l = strlen(cmd2);
142 snprintf(formatter_type, 64,
"%*.*sy", l - 3, l - 3, cmd2);
150 if (!strcmp(cmd1,
"show")) {
157 if (cmd != CLI_GENERATE
160 && strcmp(object_id,
"like") == 0) {
161 if (ast_strlen_zero(a->argv[4])) {
162 return CLI_SHOWUSAGE;
169 if (cmd == CLI_GENERATE
172 || (a->argc == 4 && ast_strlen_zero(a->word)))) {
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",
191 "==========================================================================================\n\n");
193 if (is_container || cmd == CLI_GENERATE) {
196 ast_cli(a->fd,
"No container returned for object type %s.\n",
203 if (cmd == CLI_GENERATE) {
205 complete_show_sorcery_object(container, formatter_entry, a->word);
212 ast_cli(a->fd,
"No objects found.\n\n");
219 if (ast_strlen_zero(object_id)) {
221 ast_cli(a->fd,
"No object specified.\n");
228 ast_cli(a->fd,
"Unable to find object %s.\n\n", object_id);
231 formatter_entry->
print_body(
object, &context, 0);
239 static int formatter_sort(
const void *obj,
const void *arg,
int flags)
243 const char *right_key = arg;
248 right_key = right_obj->
name;
251 cmp = strcmp(left_obj->
name, right_key);
254 cmp = strncmp(left_obj->
name, right_key, strlen(right_key));
264 static int formatter_compare(
void *obj,
void *arg,
int flags)
268 const char *right_key = arg;
271 switch (flags & OBJ_SEARCH_MASK) {
273 right_key = right_obj->
name;
276 if (strcmp(left_obj->
name, right_key) == 0) {;
281 if (strncmp(left_obj->
name, right_key, strlen(right_key)) == 0) {
293 static int formatter_hash(
const void *obj,
int flags)
312 ast_assert(formatter != NULL);
313 ast_assert(formatter->
name != NULL);
317 ast_assert(formatter->
iterate != NULL);
318 ast_assert(formatter->
get_id != NULL);
321 ao2_link(formatter_registry, formatter);
329 ao2_wrlock(formatter_registry);
330 if (
ao2_ref(formatter, -1) == 2) {
333 ao2_unlock(formatter_registry);
342 e->
command =
"pjsip show version";
344 "Usage: pjsip show version\n"
345 " Show the version of pjproject that res_pjsip is running against\n";
351 ast_cli(a->fd,
"PJPROJECT version currently running against: %s\n", pj_get_version());
357 AST_CLI_DEFINE(handle_pjsip_show_version,
"Show the version of pjproject in use"),
360 int ast_sip_initialize_cli(
void)
363 formatter_hash, formatter_sort, formatter_compare);
365 if (!formatter_registry) {
366 ast_log(LOG_ERROR,
"Unable to create formatter_registry.\n");
375 void ast_sip_destroy_cli(
void)
378 ao2_ref(formatter_registry, -1);
struct ast_str * output_buffer
struct ast_variable * next
struct ao2_container *(* get_container)(const char *regex)
struct ast_variable * ast_variable_list_sort(struct ast_variable *head)
Performs an in-place sort on the variable list by ascending name.
Asterisk main include file. File version handling, generic pbx functions.
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
CLI Formatter Registry Entry.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
The arg parameter is a search key, but is not an object.
static int force_inline attribute_pure ast_ends_with(const char *str, const char *suffix)
Checks whether a string ends with another.
descriptor for a cli entry.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container, as described below.
Generic (perhaps overly so) hashtable implementation Hash Table support in Asterisk.
Structure for variables, used for configurations and for channel variables.
Assume that the ao2_container is already locked.
int(* iterate)(void *container, ao2_callback_fn callback, void *args)
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#define ast_strdup(str)
A wrapper for strdup()
CLI Formatter Context passed to all formatters.
The arg parameter is a partial search key similar to OBJ_SEARCH_KEY.
Access Control of various sorts.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
void *(* retrieve_by_id)(const char *id)
struct ao2_container * container
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Allocate and initialize a hash container with the desired number of buckets.
Support for dynamic strings.
#define ast_sorcery_objectset_create(sorcery, object)
Create an object set (KVP list) for an object.
const char *(* get_id)(const void *obj)
The arg parameter is an object of the same type.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Standard Command Line Interface.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
#define ao2_unlink_flags(container, obj, flags)
Remove an object from a container.
ao2_callback_fn * print_header
Search option field mask.
int ast_cli_completion_add(char *value)
Add a result to a request for completion options.
ao2_callback_fn * print_body
const char *const cmda[AST_MAX_CMD_LEN]
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
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.
Sorcery Data Access Layer API.
static force_inline int attribute_pure ast_str_hash(const char *str)
Compute a hash value on a string.
unsigned show_details_only_level_0
#define ao2_link(container, obj)
Add an object to a container.