Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Functions | Variables
parking_ui.c File Reference

Call Parking CLI commands. More...

#include "asterisk.h"
#include "res_parking.h"
#include "asterisk/config.h"
#include "asterisk/config_options.h"
#include "asterisk/utils.h"
#include "asterisk/module.h"
#include "asterisk/cli.h"
#include "asterisk/astobj2.h"
#include "asterisk/features.h"
#include "asterisk/manager.h"
Include dependency graph for parking_ui.c:

Go to the source code of this file.

Data Structures

struct  parking_lot_complete
 

Functions

static void cli_display_parking_global (int fd)
 
static void cli_display_parking_lot (int fd, const char *name)
 
static void cli_display_parking_lot_list (int fd)
 
static char * complete_parking_lot (const char *word, int seeking)
 
static int complete_parking_lot_search (void *obj, void *arg, void *data, int flags)
 
static void display_parked_call (struct parked_user *user, int fd)
 
static int display_parked_users_cb (void *obj, void *arg, int flags)
 
static void display_parking_lot (struct parking_lot *lot, int fd)
 
static int display_parking_lot_cb (void *obj, void *arg, int flags)
 
static char * handle_show_parking_lot_cmd (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
int load_parking_ui (void)
 Register CLI commands. More...
 
void unload_parking_ui (void)
 Unregister CLI commands. More...
 

Variables

static struct ast_cli_entry cli_parking_lot []
 

Detailed Description

Call Parking CLI commands.

Author
Jonathan Rose jrose.nosp@m.@dig.nosp@m.ium.c.nosp@m.om

Definition in file parking_ui.c.

Function Documentation

◆ cli_display_parking_global()

static void cli_display_parking_global ( int  fd)
static

Definition at line 103 of file parking_ui.c.

References ast_cli(), and parking_dynamic_lots_enabled().

Referenced by handle_show_parking_lot_cmd().

104 {
105  ast_cli(fd, "Parking General Options\n"
106  "-----------------------\n");
107  ast_cli(fd, "Dynamic Parking : %s\n", parking_dynamic_lots_enabled() ? "yes" : "no");
108  ast_cli(fd, "\n");
109 }
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
int parking_dynamic_lots_enabled(void)
Check global configuration to see if dynamic parking is enabled.
Definition: res_parking.c:928

◆ cli_display_parking_lot()

static void cli_display_parking_lot ( int  fd,
const char *  name 
)
static

Definition at line 78 of file parking_ui.c.

References ao2_callback, ao2_cleanup, ao2_container_count(), ast_cli(), display_parked_users_cb(), display_parking_lot(), NULL, OBJ_MULTIPLE, OBJ_NODATA, parking_lot_find_by_name(), and RAII_VAR.

Referenced by handle_show_parking_lot_cmd().

79 {
80  RAII_VAR(struct parking_lot *, lot, NULL, ao2_cleanup);
82 
83  /* If the parking lot couldn't be found with the search, also abort. */
84  if (!lot) {
85  ast_cli(fd, "Could not find parking lot '%s'\n\n", name);
86  return;
87  }
88 
89  display_parking_lot(lot, fd);
90 
91  ast_cli(fd, "Parked Calls\n------------\n");
92 
93  if (!ao2_container_count(lot->parked_users)) {
94  ast_cli(fd, " (none)\n");
95  ast_cli(fd, "\n\n");
96  return;
97  }
98 
99  ao2_callback(lot->parked_users, OBJ_MULTIPLE | OBJ_NODATA, display_parked_users_cb, &fd);
100  ast_cli(fd, "\n");
101 }
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
#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
static const char name[]
Definition: cdr_mysql.c:74
static int display_parked_users_cb(void *obj, void *arg, int flags)
Definition: parking_ui.c:46
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct parking_lot * parking_lot_find_by_name(const char *lot_name)
Find a parking lot based on its name.
Definition: res_parking.c:601
static void display_parking_lot(struct parking_lot *lot, int fd)
Definition: parking_ui.c:54

◆ cli_display_parking_lot_list()

static void cli_display_parking_lot_list ( int  fd)
static

Definition at line 111 of file parking_ui.c.

References ao2_callback, ast_cli(), display_parking_lot_cb(), get_parking_lot_container(), OBJ_MULTIPLE, and OBJ_NODATA.

Referenced by handle_show_parking_lot_cmd().

112 {
113  struct ao2_container *lot_container;
114 
115  lot_container = get_parking_lot_container();
116 
117  if (!lot_container) {
118  ast_cli(fd, "Failed to obtain parking lot list.\n\n");
119  return;
120  }
121 
123  ast_cli(fd, "\n");
124 }
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
static int display_parking_lot_cb(void *obj, void *arg, int flags)
Definition: parking_ui.c:70
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
struct ao2_container * get_parking_lot_container(void)
Get a pointer to the parking lot container for purposes such as iteration.
Definition: res_parking.c:596
Generic container type.

◆ complete_parking_lot()

static char* complete_parking_lot ( const char *  word,
int  seeking 
)
static

Definition at line 140 of file parking_ui.c.

References ao2_callback_data, ao2_ref, ast_strdup, ast_strlen_zero, complete_parking_lot_search(), get_parking_lot_container(), parking_lot::name, NULL, OBJ_PARTIAL_KEY, and parking_lot_complete::seeking.

Referenced by handle_show_parking_lot_cmd().

141 {
142  char *ret = NULL;
143  struct parking_lot *lot;
144  struct ao2_container *global_lots = get_parking_lot_container();
145  struct parking_lot_complete search = {
146  .seeking = seeking,
147  };
148 
149  lot = ao2_callback_data(global_lots, ast_strlen_zero(word) ? 0 : OBJ_PARTIAL_KEY,
150  complete_parking_lot_search, (char *) word, &search);
151 
152  if (!lot) {
153  return NULL;
154  }
155 
156  ret = ast_strdup(lot->name);
157  ao2_ref(lot, -1);
158  return ret;
159 }
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
struct ao2_container * get_parking_lot_container(void)
Get a pointer to the parking lot container for purposes such as iteration.
Definition: res_parking.c:596
#define OBJ_PARTIAL_KEY
Definition: astobj2.h:1156
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ao2_callback_data(container, flags, cb_fn, arg, data)
Definition: astobj2.h:1743
const ast_string_field name
Definition: res_parking.h:100
static int complete_parking_lot_search(void *obj, void *arg, void *data, int flags)
Definition: parking_ui.c:131
Generic container type.
short word

◆ complete_parking_lot_search()

static int complete_parking_lot_search ( void *  obj,
void *  arg,
void *  data,
int  flags 
)
static

Definition at line 131 of file parking_ui.c.

References CMP_MATCH, parking_lot_complete::seeking, and parking_lot_complete::which.

Referenced by complete_parking_lot().

132 {
133  struct parking_lot_complete *search = data;
134  if (++search->which > search->seeking) {
135  return CMP_MATCH;
136  }
137  return 0;
138 }

◆ display_parked_call()

static void display_parked_call ( struct parked_user user,
int  fd 
)
static

Definition at line 38 of file parking_ui.c.

References ast_channel_name(), ast_cli(), parked_user::chan, parked_user::parker_dial_string, and parked_user::parking_space.

Referenced by display_parked_users_cb().

39 {
40  ast_cli(fd, " Space : %d\n", user->parking_space);
41  ast_cli(fd, " Channel : %s\n", ast_channel_name(user->chan));
42  ast_cli(fd, " Parker Dial String : %s\n", user->parker_dial_string);
43  ast_cli(fd, "\n");
44 }
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
char * parker_dial_string
Definition: res_parking.h:109
int parking_space
Definition: res_parking.h:107
const char * ast_channel_name(const struct ast_channel *chan)
struct ast_channel * chan
Definition: res_parking.h:104

◆ display_parked_users_cb()

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

Definition at line 46 of file parking_ui.c.

References display_parked_call().

Referenced by cli_display_parking_lot().

47 {
48  int *fd = arg;
49  struct parked_user *user = obj;
50  display_parked_call(user, *fd);
51  return 0;
52 }
static void display_parked_call(struct parked_user *user, int fd)
Definition: parking_ui.c:38
structure to hold users read from users.conf

◆ display_parking_lot()

static void display_parking_lot ( struct parking_lot lot,
int  fd 
)
static

Definition at line 54 of file parking_ui.c.

References ast_cli(), parking_lot::cfg, parking_lot_cfg::comebackcontext, parking_lot_cfg::comebackdialtime, parking_lot_cfg::comebacktoorigin, parking_lot::mode, parking_lot_cfg::mohclass, parking_lot::name, parking_lot_cfg::parkext, parking_lot_cfg::parking_con, parking_lot_cfg::parking_start, parking_lot_cfg::parking_stop, PARKINGLOT_DISABLED, PARKINGLOT_DYNAMIC, and parking_lot_cfg::parkingtime.

Referenced by cli_display_parking_lot(), and display_parking_lot_cb().

55 {
56  ast_cli(fd, "Parking Lot: %s\n--------------------------------------------------------------------------\n", lot->name);
57  ast_cli(fd, "Parking Extension : %s\n", lot->cfg->parkext);
58  ast_cli(fd, "Parking Context : %s\n", lot->cfg->parking_con);
59  ast_cli(fd, "Parking Spaces : %d-%d\n", lot->cfg->parking_start, lot->cfg->parking_stop);
60  ast_cli(fd, "Parking Time : %u sec\n", lot->cfg->parkingtime);
61  ast_cli(fd, "Comeback to Origin : %s\n", lot->cfg->comebacktoorigin ? "yes" : "no");
62  ast_cli(fd, "Comeback Context : %s%s\n", lot->cfg->comebackcontext, lot->cfg->comebacktoorigin ? " (comebacktoorigin=yes, not used)" : "");
63  ast_cli(fd, "Comeback Dial Time : %u sec\n", lot->cfg->comebackdialtime);
64  ast_cli(fd, "MusicOnHold Class : %s\n", lot->cfg->mohclass);
65  ast_cli(fd, "Enabled : %s\n", (lot->mode == PARKINGLOT_DISABLED) ? "no" : "yes");
66  ast_cli(fd, "Dynamic : %s\n", (lot->mode == PARKINGLOT_DYNAMIC) ? "yes" : "no");
67  ast_cli(fd, "\n");
68 }
unsigned int comebackdialtime
Definition: res_parking.h:70
unsigned int parkingtime
Definition: res_parking.h:69
const ast_string_field comebackcontext
Definition: res_parking.h:89
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
const ast_string_field parking_con
Definition: res_parking.h:89
unsigned int comebacktoorigin
Definition: res_parking.h:74
const ast_string_field name
Definition: res_parking.h:100
enum parking_lot_modes mode
Definition: res_parking.h:97
const ast_string_field parkext
Definition: res_parking.h:89
const ast_string_field mohclass
Definition: res_parking.h:89
struct parking_lot_cfg * cfg
Definition: res_parking.h:96

◆ display_parking_lot_cb()

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

Definition at line 70 of file parking_ui.c.

References display_parking_lot().

Referenced by cli_display_parking_lot_list().

71 {
72  int *fd = arg;
73  struct parking_lot *lot = obj;
74  display_parking_lot(lot, *fd);
75  return 0;
76 }
static void display_parking_lot(struct parking_lot *lot, int fd)
Definition: parking_ui.c:54

◆ handle_show_parking_lot_cmd()

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

Definition at line 162 of file parking_ui.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), cli_display_parking_global(), cli_display_parking_lot(), cli_display_parking_lot_list(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_parking_lot(), ast_cli_args::fd, ast_cli_args::n, NULL, ast_cli_args::pos, ast_cli_entry::usage, and ast_cli_args::word.

163 {
164  switch (cmd) {
165  case CLI_INIT:
166  e->command = "parking show";
167  e->usage =
168  "Usage: parking show [name]\n"
169  " Shows a list of parking lots or details of a specific parking lot.";
170  return NULL;
171  case CLI_GENERATE:
172  if (a->pos == 2) {
173  return complete_parking_lot(a->word, a->n);
174  }
175  return NULL;
176  }
177 
178  ast_cli(a->fd, "\n");
179 
180  if (a->argc == 2) {
183  return CLI_SUCCESS;
184  }
185 
186  if (a->argc == 3) {
187  cli_display_parking_lot(a->fd, a->argv[2]);
188  return CLI_SUCCESS;
189  }
190 
191  return CLI_SHOWUSAGE;
192 }
const int argc
Definition: cli.h:160
Definition: cli.h:152
static char * complete_parking_lot(const char *word, int seeking)
Definition: parking_ui.c:140
static void cli_display_parking_global(int fd)
Definition: parking_ui.c:103
#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
const int n
Definition: cli.h:165
static void cli_display_parking_lot(int fd, const char *name)
Definition: parking_ui.c:78
const char *const * argv
Definition: cli.h:161
#define CLI_SHOWUSAGE
Definition: cli.h:45
char * command
Definition: cli.h:186
const char * word
Definition: cli.h:163
static void cli_display_parking_lot_list(int fd)
Definition: parking_ui.c:111
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
const int pos
Definition: cli.h:164

◆ load_parking_ui()

int load_parking_ui ( void  )

Register CLI commands.

Since
12.0.0
Return values
0if successful
-1on failure

Definition at line 198 of file parking_ui.c.

References ARRAY_LEN, and ast_cli_register_multiple.

Referenced by load_module().

199 {
201 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
static struct ast_cli_entry cli_parking_lot[]
Definition: parking_ui.c:194

◆ unload_parking_ui()

void unload_parking_ui ( void  )

Unregister CLI commands.

Since
12.0.0

Definition at line 203 of file parking_ui.c.

References ARRAY_LEN, and ast_cli_unregister_multiple().

Referenced by unload_module().

204 {
206 }
#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 ast_cli_entry cli_parking_lot[]
Definition: parking_ui.c:194

Variable Documentation

◆ cli_parking_lot

struct ast_cli_entry cli_parking_lot[]
static
Initial value:
= {
{ .handler = handle_show_parking_lot_cmd , .summary = "Show a parking lot or a list of all parking lots." ,},
}
static char * handle_show_parking_lot_cmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: parking_ui.c:162

Definition at line 194 of file parking_ui.c.