Newer
Older
ao2_t_find(reg_containers, name, OBJ_UNLINK | OBJ_NODATA | OBJ_SEARCH_KEY,
"Unregister container");
George Joseph
committed
#endif /* defined(AO2_DEBUG) */
George Joseph
committed
#if defined(AO2_DEBUG)
static int ao2_complete_reg_cb(void *obj, void *arg, void *data, int flags)
{
struct ao2_reg_match *which = data;
/* ao2_reg_sort_cb() has already filtered the search to matching keys */
return (which->find_nth < ++which->count) ? (CMP_MATCH | CMP_STOP) : 0;
}
George Joseph
committed
#endif /* defined(AO2_DEBUG) */
George Joseph
committed
#if defined(AO2_DEBUG)
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
static char *complete_container_names(struct ast_cli_args *a)
{
struct ao2_reg_partial_key partial_key;
struct ao2_reg_match which;
struct ao2_reg_container *reg;
char *name;
if (a->pos != 3) {
return NULL;
}
partial_key.len = strlen(a->word);
partial_key.name = a->word;
which.find_nth = a->n;
which.count = 0;
reg = ao2_t_callback_data(reg_containers, partial_key.len ? OBJ_SEARCH_PARTIAL_KEY : 0,
ao2_complete_reg_cb, &partial_key, &which, "Find partial registered container");
if (reg) {
name = ast_strdup(reg->name);
ao2_t_ref(reg, -1, "Done with registered container object.");
} else {
name = NULL;
}
return name;
}
George Joseph
committed
#endif /* defined(AO2_DEBUG) */
George Joseph
committed
#if defined(AO2_DEBUG)
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
AST_THREADSTORAGE(ao2_out_buf);
/*!
* \brief Print CLI output.
* \since 12.0.0
*
* \param where User data pointer needed to determine where to put output.
* \param fmt printf type format string.
*
* \return Nothing
*/
static void cli_output(void *where, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
static void cli_output(void *where, const char *fmt, ...)
{
int res;
struct ast_str *buf;
va_list ap;
buf = ast_str_thread_get(&ao2_out_buf, 256);
if (!buf) {
return;
}
va_start(ap, fmt);
res = ast_str_set_va(&buf, 0, fmt, ap);
va_end(ap);
if (res != AST_DYNSTR_BUILD_FAILED) {
ast_cli(*(int *) where, "%s", ast_str_buffer(buf));
}
}
George Joseph
committed
#endif /* defined(AO2_DEBUG) */
George Joseph
committed
#if defined(AO2_DEBUG)
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
/*! \brief Show container contents - CLI command */
static char *handle_cli_astobj2_container_dump(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
const char *name;
struct ao2_reg_container *reg;
switch (cmd) {
case CLI_INIT:
e->command = "astobj2 container dump";
e->usage =
"Usage: astobj2 container dump <name>\n"
" Show contents of the container <name>.\n";
return NULL;
case CLI_GENERATE:
return complete_container_names(a);
}
if (a->argc != 4) {
return CLI_SHOWUSAGE;
}
name = a->argv[3];
reg = ao2_t_find(reg_containers, name, OBJ_SEARCH_KEY, "Find registered container");
if (reg) {
ao2_container_dump(reg->registered, 0, name, (void *) &a->fd, cli_output,
reg->prnt_obj);
ao2_t_ref(reg, -1, "Done with registered container object.");
} else {
ast_cli(a->fd, "Container '%s' not found.\n", name);
}
return CLI_SUCCESS;
}
George Joseph
committed
#endif /* defined(AO2_DEBUG) */
George Joseph
committed
#if defined(AO2_DEBUG)
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
/*! \brief Show container statistics - CLI command */
static char *handle_cli_astobj2_container_stats(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
const char *name;
struct ao2_reg_container *reg;
switch (cmd) {
case CLI_INIT:
e->command = "astobj2 container stats";
e->usage =
"Usage: astobj2 container stats <name>\n"
" Show statistics about the specified container <name>.\n";
return NULL;
case CLI_GENERATE:
return complete_container_names(a);
}
if (a->argc != 4) {
return CLI_SHOWUSAGE;
}
name = a->argv[3];
reg = ao2_t_find(reg_containers, name, OBJ_SEARCH_KEY, "Find registered container");
if (reg) {
ao2_container_stats(reg->registered, 0, name, (void *) &a->fd, cli_output);
ao2_t_ref(reg, -1, "Done with registered container object.");
} else {
ast_cli(a->fd, "Container '%s' not found.\n", name);
}
return CLI_SUCCESS;
}
George Joseph
committed
#endif /* defined(AO2_DEBUG) */
George Joseph
committed
#if defined(AO2_DEBUG)
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
/*! \brief Show container check results - CLI command */
static char *handle_cli_astobj2_container_check(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
const char *name;
struct ao2_reg_container *reg;
switch (cmd) {
case CLI_INIT:
e->command = "astobj2 container check";
e->usage =
"Usage: astobj2 container check <name>\n"
" Perform a container integrity check on <name>.\n";
return NULL;
case CLI_GENERATE:
return complete_container_names(a);
}
if (a->argc != 4) {
return CLI_SHOWUSAGE;
}
name = a->argv[3];
reg = ao2_t_find(reg_containers, name, OBJ_SEARCH_KEY, "Find registered container");
if (reg) {
ast_cli(a->fd, "Container check of '%s': %s.\n", name,
ao2_container_check(reg->registered, 0) ? "failed" : "OK");
ao2_t_ref(reg, -1, "Done with registered container object.");
} else {
ast_cli(a->fd, "Container '%s' not found.\n", name);
}
return CLI_SUCCESS;
}
George Joseph
committed
#endif /* defined(AO2_DEBUG) */
George Joseph
committed
#if defined(AO2_DEBUG)
static struct ast_cli_entry cli_astobj2[] = {
AST_CLI_DEFINE(handle_cli_astobj2_container_dump, "Show container contents"),
AST_CLI_DEFINE(handle_cli_astobj2_container_stats, "Show container statistics"),
AST_CLI_DEFINE(handle_cli_astobj2_container_check, "Perform a container integrity check"),
};
George Joseph
committed
#endif /* defined(AO2_DEBUG) */
George Joseph
committed
#if defined(AO2_DEBUG)
static void container_cleanup(void)
{
ao2_t_ref(reg_containers, -1, "Releasing container registration container");
reg_containers = NULL;
ast_cli_unregister_multiple(cli_astobj2, ARRAY_LEN(cli_astobj2));
}
George Joseph
committed
#endif /* defined(AO2_DEBUG) */
int container_init(void)
{
George Joseph
committed
#if defined(AO2_DEBUG)
reg_containers = ao2_t_container_alloc_list(AO2_ALLOC_OPT_LOCK_RWLOCK,
AO2_CONTAINER_ALLOC_OPT_DUPS_REPLACE, ao2_reg_sort_cb, NULL,
"Container registration container.");
if (!reg_containers) {
return -1;
}
ast_cli_register_multiple(cli_astobj2, ARRAY_LEN(cli_astobj2));
ast_register_atexit(container_cleanup);
George Joseph
committed
#endif /* defined(AO2_DEBUG) */
return 0;
}