Asterisk - The Open Source Telephony Project  18.5.0
Macros | Functions | Variables
res_realtime.c File Reference

RealTime CLI. More...

#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/config.h"
#include "asterisk/module.h"
#include "asterisk/lock.h"
#include "asterisk/cli.h"
Include dependency graph for res_realtime.c:

Go to the source code of this file.

Macros

#define CRL_HEADER_FORMAT   "%30s %-30s\n"
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static char * cli_realtime_destroy (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * cli_realtime_load (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * cli_realtime_store (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * cli_realtime_update (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * cli_realtime_update2 (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Realtime Data Lookup/Rewrite" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_cli_entry cli_realtime []
 

Detailed Description

RealTime CLI.

Author
Anthony Minessale anthm.nosp@m.ct@y.nosp@m.ahoo..nosp@m.com
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file res_realtime.c.

Macro Definition Documentation

◆ CRL_HEADER_FORMAT

#define CRL_HEADER_FORMAT   "%30s %-30s\n"

Referenced by cli_realtime_load().

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 288 of file res_realtime.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 288 of file res_realtime.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 288 of file res_realtime.c.

◆ cli_realtime_destroy()

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

Definition at line 226 of file res_realtime.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_destroy_realtime(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ESS, ast_cli_args::fd, NULL, SENTINEL, and ast_cli_entry::usage.

227 {
228  int res = -1;
229 
230  switch (cmd) {
231  case CLI_INIT:
232  e->command = "realtime destroy";
233  e->usage =
234  "Usage: realtime destroy <family> <colmatch1> <valuematch1> [<colmatch2> <valuematch2> [... <colmatch5> <valuematch5>]]\n"
235  " Remove a stored row using the RealTime driver.\n"
236  " You must supply a family name and name/value pairs (up to 5).\n";
237  return NULL;
238  case CLI_GENERATE:
239  return NULL;
240  }
241 
242  if (a->argc < 5) {
243  return CLI_SHOWUSAGE;
244  } else if (a->argc == 5) {
245  res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], SENTINEL);
246  } else if (a->argc == 7) {
247  res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], SENTINEL);
248  } else if (a->argc == 9) {
249  res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], SENTINEL);
250  } else if (a->argc == 11) {
251  res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], SENTINEL);
252  } else if (a->argc == 13) {
253  res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], a->argv[11], a->argv[12], SENTINEL);
254  } else {
255  return CLI_SHOWUSAGE;
256  }
257 
258  if (res < 0) {
259  ast_cli(a->fd, "Failed to remove record. Check the debug log for possible SQL related entries.\n");
260  return CLI_FAILURE;
261  }
262 
263  ast_cli(a->fd, "Removed %d RealTime record%s.\n", res, ESS(res));
264 
265  return CLI_SUCCESS;
266 }
const int argc
Definition: cli.h:160
Definition: cli.h:152
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
#define SENTINEL
Definition: compiler.h:87
const int fd
Definition: cli.h:159
const char *const * argv
Definition: cli.h:161
#define CLI_SHOWUSAGE
Definition: cli.h:45
#define CLI_FAILURE
Definition: cli.h:46
#define ESS(x)
Definition: cli.h:59
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
int ast_destroy_realtime(const char *family, const char *keyfield, const char *lookup,...) attribute_sentinel
Destroy realtime configuration.
Definition: main/config.c:3606

◆ cli_realtime_load()

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

Definition at line 45 of file res_realtime.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_load_realtime_all(), ast_variables_destroy(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, CRL_HEADER_FORMAT, ast_cli_args::fd, ast_variable::name, ast_variable::next, NULL, SENTINEL, ast_cli_entry::usage, ast_variable::value, and var.

46 {
47 #define CRL_HEADER_FORMAT "%30s %-30s\n"
48  struct ast_variable *var = NULL, *orig_var = NULL;
49 
50  switch (cmd) {
51  case CLI_INIT:
52  e->command = "realtime load";
53  e->usage =
54  "Usage: realtime load <family> <colmatch> <value>\n"
55  " Prints out a list of variables using the RealTime driver.\n"
56  " You must supply a family name, a column to match on, and a value to match to.\n";
57  return NULL;
58  case CLI_GENERATE:
59  return NULL;
60  }
61 
62 
63  if (a->argc < 5)
64  return CLI_SHOWUSAGE;
65 
66  var = ast_load_realtime_all(a->argv[2], a->argv[3], a->argv[4], SENTINEL);
67 
68  if (var) {
69  ast_cli(a->fd, CRL_HEADER_FORMAT, "Column Name", "Column Value");
70  ast_cli(a->fd, CRL_HEADER_FORMAT, "--------------------", "--------------------");
71  orig_var = var;
72  while (var) {
73  ast_cli(a->fd, CRL_HEADER_FORMAT, var->name, var->value);
74  var = var->next;
75  }
76  } else {
77  ast_cli(a->fd, "No rows found matching search criteria.\n");
78  }
79  ast_variables_destroy(orig_var);
80  return CLI_SUCCESS;
81 }
struct ast_variable * next
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1263
const int argc
Definition: cli.h:160
Structure for variables, used for configurations and for channel variables.
#define var
Definition: ast_expr2f.c:614
Definition: cli.h:152
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
#define SENTINEL
Definition: compiler.h:87
const int fd
Definition: cli.h:159
const char *const * argv
Definition: cli.h:161
#define CLI_SHOWUSAGE
Definition: cli.h:45
char * command
Definition: cli.h:186
#define CRL_HEADER_FORMAT
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44
struct ast_variable * ast_load_realtime_all(const char *family,...) attribute_sentinel
Definition: main/config.c:3287

◆ cli_realtime_store()

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

Definition at line 181 of file res_realtime.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_store_realtime(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, NULL, SENTINEL, and ast_cli_entry::usage.

182 {
183  int res = -1;
184 
185  switch (cmd) {
186  case CLI_INIT:
187  e->command = "realtime store";
188  e->usage =
189  "Usage: realtime store <family> <colname1> <value1> [<colname2> <value2> [... <colname5> <value5>]]\n"
190  " Create a stored row using the RealTime driver.\n"
191  " You must supply a family name and name/value pairs (up to 5). If\n"
192  " you need to store more than 5 key/value pairs, start with the first\n"
193  " five, then use 'realtime update' or 'realtime update2' to add\n"
194  " additional columns.\n";
195  return NULL;
196  case CLI_GENERATE:
197  return NULL;
198  }
199 
200  if (a->argc < 5) {
201  return CLI_SHOWUSAGE;
202  } else if (a->argc == 5) {
203  res = ast_store_realtime(a->argv[2], a->argv[3], a->argv[4], SENTINEL);
204  } else if (a->argc == 7) {
205  res = ast_store_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], SENTINEL);
206  } else if (a->argc == 9) {
207  res = ast_store_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], SENTINEL);
208  } else if (a->argc == 11) {
209  res = ast_store_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], SENTINEL);
210  } else if (a->argc == 13) {
211  res = ast_store_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], a->argv[11], a->argv[12], SENTINEL);
212  } else {
213  return CLI_SHOWUSAGE;
214  }
215 
216  if (res < 0) {
217  ast_cli(a->fd, "Failed to store record. Check the debug log for possible SQL related entries.\n");
218  return CLI_FAILURE;
219  }
220 
221  ast_cli(a->fd, "Stored RealTime record.\n");
222 
223  return CLI_SUCCESS;
224 }
const int argc
Definition: cli.h:160
Definition: cli.h:152
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
#define SENTINEL
Definition: compiler.h:87
int ast_store_realtime(const char *family,...) attribute_sentinel
Create realtime configuration.
Definition: main/config.c:3570
const int fd
Definition: cli.h:159
const char *const * argv
Definition: cli.h:161
#define CLI_SHOWUSAGE
Definition: cli.h:45
#define CLI_FAILURE
Definition: cli.h:46
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44

◆ cli_realtime_update()

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

Definition at line 83 of file res_realtime.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_update_realtime(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ESS, ast_cli_args::fd, NULL, SENTINEL, and ast_cli_entry::usage.

84 {
85  int res = 0;
86 
87  switch (cmd) {
88  case CLI_INIT:
89  e->command = "realtime update";
90  e->usage =
91  "Usage: realtime update <family> <colmatch> <valuematch> <colupdate> <newvalue>\n"
92  " Update a single variable using the RealTime driver.\n"
93  " You must supply a family name, a column to update on, a new value, column to match, and value to match.\n"
94  " Ex: realtime update sippeers name bobsphone port 4343\n"
95  " will execute SQL as UPDATE sippeers SET port = 4343 WHERE name = bobsphone\n";
96  return NULL;
97  case CLI_GENERATE:
98  return NULL;
99  }
100 
101  if (a->argc < 7)
102  return CLI_SHOWUSAGE;
103 
104  res = ast_update_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], SENTINEL);
105 
106  if (res < 0) {
107  ast_cli(a->fd, "Failed to update. Check the debug log for possible SQL related entries.\n");
108  return CLI_FAILURE;
109  }
110 
111  ast_cli(a->fd, "Updated %d RealTime record%s.\n", res, ESS(res));
112 
113  return CLI_SUCCESS;
114 }
const int argc
Definition: cli.h:160
Definition: cli.h:152
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
int ast_update_realtime(const char *family, const char *keyfield, const char *lookup,...) attribute_sentinel
Update realtime configuration.
Definition: main/config.c:3489
#define SENTINEL
Definition: compiler.h:87
const int fd
Definition: cli.h:159
const char *const * argv
Definition: cli.h:161
#define CLI_SHOWUSAGE
Definition: cli.h:45
#define CLI_FAILURE
Definition: cli.h:46
#define ESS(x)
Definition: cli.h:59
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44

◆ cli_realtime_update2()

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

Definition at line 116 of file res_realtime.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_update2_realtime(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ESS, ast_cli_args::fd, NULL, SENTINEL, and ast_cli_entry::usage.

117 {
118  int res = -1;
119 
120  switch (cmd) {
121  case CLI_INIT:
122  e->command = "realtime update2";
123  e->usage =
124  "Usage: realtime update2 <family> <colmatch> <valuematch> [... <colmatch5> <valuematch5>] NULL <colupdate> <newvalue>\n"
125  " Update a single variable, requiring one or more fields to match using the\n"
126  " RealTime driver. You must supply a family name, a column to update, a new\n"
127  " value, and at least one column and value to match.\n"
128  " Ex: realtime update2 sippeers name bobsphone ipaddr 127.0.0.1 NULL port 4343\n"
129  " will execute SQL as\n"
130  " UPDATE sippeers SET port='4343' WHERE name='bobsphone' and ipaddr='127.0.0.1'\n";
131  return NULL;
132  case CLI_GENERATE:
133  return NULL;
134  }
135 
136  /* Make sure we have the right number of arguments and that the required literal NULL
137  is present */
138  if (a->argc < 8 || a->argc > 16 || a->argc % 2
139  || strcmp(a->argv[a->argc - 3], "NULL")) {
140  return CLI_SHOWUSAGE;
141  }
142 
143  if (a->argc == 8) {
144  res = ast_update2_realtime(
145  a->argv[2], a->argv[3], a->argv[4], SENTINEL,
146  a->argv[6], a->argv[7], SENTINEL);
147  } else if (a->argc == 10) {
148  res = ast_update2_realtime(
149  a->argv[2], a->argv[3], a->argv[4], a->argv[5],
150  a->argv[6], SENTINEL,
151  a->argv[8], a->argv[9], SENTINEL);
152  } else if (a->argc == 12) {
153  res = ast_update2_realtime(
154  a->argv[2], a->argv[3], a->argv[4], a->argv[5],
155  a->argv[6], a->argv[7], a->argv[8], SENTINEL,
156  a->argv[10], a->argv[11], SENTINEL);
157  } else if (a->argc == 14) {
158  res = ast_update2_realtime(
159  a->argv[2], a->argv[3], a->argv[4], a->argv[5],
160  a->argv[6], a->argv[7], a->argv[8], a->argv[9],
161  a->argv[10], SENTINEL,
162  a->argv[12], a->argv[13], SENTINEL);
163  } else if (a->argc == 16) {
164  res = ast_update2_realtime(
165  a->argv[2], a->argv[3], a->argv[4], a->argv[5],
166  a->argv[6], a->argv[7], a->argv[8], a->argv[9],
167  a->argv[10], a->argv[11], a->argv[12], SENTINEL,
168  a->argv[14], a->argv[15], SENTINEL);
169  }
170 
171  if (res < 0) {
172  ast_cli(a->fd, "Failed to update. Check the debug log for possible SQL related entries.\n");
173  return CLI_FAILURE;
174  }
175 
176  ast_cli(a->fd, "Updated %d RealTime record%s.\n", res, ESS(res));
177 
178  return CLI_SUCCESS;
179 }
const int argc
Definition: cli.h:160
Definition: cli.h:152
#define NULL
Definition: resample.c:96
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
int ast_update2_realtime(const char *family,...) attribute_sentinel
Update realtime configuration.
Definition: main/config.c:3525
#define SENTINEL
Definition: compiler.h:87
const int fd
Definition: cli.h:159
const char *const * argv
Definition: cli.h:161
#define CLI_SHOWUSAGE
Definition: cli.h:45
#define CLI_FAILURE
Definition: cli.h:46
#define ESS(x)
Definition: cli.h:59
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
#define CLI_SUCCESS
Definition: cli.h:44

◆ load_module()

static int load_module ( void  )
static

Definition at line 282 of file res_realtime.c.

References ARRAY_LEN, ast_cli_register_multiple, and AST_MODULE_LOAD_SUCCESS.

283 {
286 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static struct ast_cli_entry cli_realtime[]
Definition: res_realtime.c:268
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 276 of file res_realtime.c.

References ARRAY_LEN, and ast_cli_unregister_multiple().

277 {
279  return 0;
280 }
#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_realtime[]
Definition: res_realtime.c:268

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Realtime Data Lookup/Rewrite" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 288 of file res_realtime.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 288 of file res_realtime.c.

◆ cli_realtime

struct ast_cli_entry cli_realtime[]
static

Definition at line 268 of file res_realtime.c.