Wed Jan 8 2020 09:50:19

Asterisk developer's documentation


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"

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)
 
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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
 
static 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

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

Referenced by cli_realtime_load().

Function Documentation

static void __reg_module ( void  )
static

Definition at line 272 of file res_realtime.c.

static void __unreg_module ( void  )
static

Definition at line 272 of file res_realtime.c.

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

Definition at line 210 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, SENTINEL, and ast_cli_entry::usage.

211 {
212  int res = -1;
213 
214  switch (cmd) {
215  case CLI_INIT:
216  e->command = "realtime destroy";
217  e->usage =
218  "Usage: realtime destroy <family> <colmatch1> <valuematch1> [<colmatch2> <valuematch2> [... <colmatch5> <valuematch5>]]\n"
219  " Remove a stored row using the RealTime driver.\n"
220  " You must supply a family name and name/value pairs (up to 5).\n";
221  return NULL;
222  case CLI_GENERATE:
223  return NULL;
224  }
225 
226  if (a->argc < 5) {
227  return CLI_SHOWUSAGE;
228  } else if (a->argc == 5) {
229  res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], SENTINEL);
230  } else if (a->argc == 7) {
231  res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], SENTINEL);
232  } else if (a->argc == 9) {
233  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);
234  } else if (a->argc == 11) {
235  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);
236  } else if (a->argc == 13) {
237  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);
238  } else {
239  return CLI_SHOWUSAGE;
240  }
241 
242  if (res < 0) {
243  ast_cli(a->fd, "Failed to remove record. Check the debug log for possible SQL related entries.\n");
244  return CLI_FAILURE;
245  }
246 
247  ast_cli(a->fd, "Removed %d RealTime record%s.\n", res, ESS(res));
248 
249  return CLI_SUCCESS;
250 }
const int argc
Definition: cli.h:154
Definition: cli.h:146
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
#define SENTINEL
Definition: compiler.h:75
int ast_destroy_realtime(const char *family, const char *keyfield, const char *lookup,...) attribute_sentinel
Destroy realtime configuration.
Definition: config.c:2750
const int fd
Definition: cli.h:153
const char *const * argv
Definition: cli.h:155
#define CLI_SHOWUSAGE
Definition: cli.h:44
#define CLI_FAILURE
Definition: cli.h:45
#define ESS(x)
Definition: cli.h:58
char * command
Definition: cli.h:180
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
static char* cli_realtime_load ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 47 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, SENTINEL, ast_cli_entry::usage, ast_variable::value, and var.

48 {
49 #define CRL_HEADER_FORMAT "%30s %-30s\n"
50  struct ast_variable *var = NULL, *orig_var = NULL;
51 
52  switch (cmd) {
53  case CLI_INIT:
54  e->command = "realtime load";
55  e->usage =
56  "Usage: realtime load <family> <colmatch> <value>\n"
57  " Prints out a list of variables using the RealTime driver.\n"
58  " You must supply a family name, a column to match on, and a value to match to.\n";
59  return NULL;
60  case CLI_GENERATE:
61  return NULL;
62  }
63 
64 
65  if (a->argc < 5)
66  return CLI_SHOWUSAGE;
67 
68  var = ast_load_realtime_all(a->argv[2], a->argv[3], a->argv[4], SENTINEL);
69 
70  if (var) {
71  ast_cli(a->fd, CRL_HEADER_FORMAT, "Column Name", "Column Value");
72  ast_cli(a->fd, CRL_HEADER_FORMAT, "--------------------", "--------------------");
73  orig_var = var;
74  while (var) {
75  ast_cli(a->fd, CRL_HEADER_FORMAT, var->name, var->value);
76  var = var->next;
77  }
78  } else {
79  ast_cli(a->fd, "No rows found matching search criteria.\n");
80  }
81  ast_variables_destroy(orig_var);
82  return CLI_SUCCESS;
83 }
const int argc
Definition: cli.h:154
struct ast_variable * ast_load_realtime_all(const char *family,...) attribute_sentinel
Definition: config.c:2536
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
#define var
Definition: ast_expr2f.c:606
Definition: cli.h:146
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: config.c:586
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
#define SENTINEL
Definition: compiler.h:75
const char * value
Definition: config.h:79
const int fd
Definition: cli.h:153
const char * name
Definition: config.h:77
const char *const * argv
Definition: cli.h:155
#define CLI_SHOWUSAGE
Definition: cli.h:44
char * command
Definition: cli.h:180
#define CRL_HEADER_FORMAT
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
struct ast_variable * next
Definition: config.h:82
static char* cli_realtime_store ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 165 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, SENTINEL, and ast_cli_entry::usage.

166 {
167  int res = -1;
168 
169  switch (cmd) {
170  case CLI_INIT:
171  e->command = "realtime store";
172  e->usage =
173  "Usage: realtime store <family> <colname1> <value1> [<colname2> <value2> [... <colname5> <value5>]]\n"
174  " Create a stored row using the RealTime driver.\n"
175  " You must supply a family name and name/value pairs (up to 5). If\n"
176  " you need to store more than 5 key/value pairs, start with the first\n"
177  " five, then use 'realtime update' or 'realtime update2' to add\n"
178  " additional columns.\n";
179  return NULL;
180  case CLI_GENERATE:
181  return NULL;
182  }
183 
184  if (a->argc < 5) {
185  return CLI_SHOWUSAGE;
186  } else if (a->argc == 5) {
187  res = ast_store_realtime(a->argv[2], a->argv[3], a->argv[4], SENTINEL);
188  } else if (a->argc == 7) {
189  res = ast_store_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], SENTINEL);
190  } else if (a->argc == 9) {
191  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);
192  } else if (a->argc == 11) {
193  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);
194  } else if (a->argc == 13) {
195  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);
196  } else {
197  return CLI_SHOWUSAGE;
198  }
199 
200  if (res < 0) {
201  ast_cli(a->fd, "Failed to store record. Check the debug log for possible SQL related entries.\n");
202  return CLI_FAILURE;
203  }
204 
205  ast_cli(a->fd, "Stored RealTime record.\n");
206 
207  return CLI_SUCCESS;
208 }
int ast_store_realtime(const char *family,...) attribute_sentinel
Create realtime configuration.
Definition: config.c:2726
const int argc
Definition: cli.h:154
Definition: cli.h:146
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
#define SENTINEL
Definition: compiler.h:75
const int fd
Definition: cli.h:153
const char *const * argv
Definition: cli.h:155
#define CLI_SHOWUSAGE
Definition: cli.h:44
#define CLI_FAILURE
Definition: cli.h:45
char * command
Definition: cli.h:180
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
static char* cli_realtime_update ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 85 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, SENTINEL, and ast_cli_entry::usage.

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

Definition at line 118 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, SENTINEL, and ast_cli_entry::usage.

119 {
120  int res = -1;
121 
122  switch (cmd) {
123  case CLI_INIT:
124  e->command = "realtime update2";
125  e->usage =
126  "Usage: realtime update2 <family> <colmatch> <valuematch> [... <colmatch5> <valuematch5>] NULL <colupdate> <newvalue>\n"
127  " Update a single variable, requiring one or more fields to match using the\n"
128  " RealTime driver. You must supply a family name, a column to update, a new\n"
129  " value, and at least one column and value to match.\n"
130  " Ex: realtime update sippeers name bobsphone ipaddr 127.0.0.1 NULL port 4343\n"
131  " will execute SQL as\n"
132  " UPDATE sippeers SET port='4343' WHERE name='bobsphone' and ipaddr='127.0.0.1'\n";
133  return NULL;
134  case CLI_GENERATE:
135  return NULL;
136  }
137 
138  if (a->argc < 7)
139  return CLI_SHOWUSAGE;
140 
141  if (a->argc == 7) {
142  res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], SENTINEL, a->argv[5], a->argv[6], SENTINEL);
143  } else if (a->argc == 9) {
144  res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], SENTINEL, a->argv[7], a->argv[8], SENTINEL);
145  } else if (a->argc == 11) {
146  res = ast_update2_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], SENTINEL, a->argv[9], a->argv[10], SENTINEL);
147  } else if (a->argc == 13) {
148  res = ast_update2_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, a->argv[11], a->argv[12], SENTINEL);
149  } else if (a->argc == 15) {
150  res = ast_update2_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, a->argv[13], a->argv[14], SENTINEL);
151  } else {
152  return CLI_SHOWUSAGE;
153  }
154 
155  if (res < 0) {
156  ast_cli(a->fd, "Failed to update. Check the debug log for possible SQL related entries.\n");
157  return CLI_FAILURE;
158  }
159 
160  ast_cli(a->fd, "Updated %d RealTime record%s.\n", res, ESS(res));
161 
162  return CLI_SUCCESS;
163 }
const int argc
Definition: cli.h:154
int ast_update2_realtime(const char *family,...) attribute_sentinel
Update realtime configuration.
Definition: config.c:2703
Definition: cli.h:146
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
#define SENTINEL
Definition: compiler.h:75
const int fd
Definition: cli.h:153
const char *const * argv
Definition: cli.h:155
#define CLI_SHOWUSAGE
Definition: cli.h:44
#define CLI_FAILURE
Definition: cli.h:45
#define ESS(x)
Definition: cli.h:58
char * command
Definition: cli.h:180
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
static int load_module ( void  )
static

Definition at line 266 of file res_realtime.c.

References ARRAY_LEN, ast_cli_register_multiple(), and AST_MODULE_LOAD_SUCCESS.

267 {
270 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static struct ast_cli_entry cli_realtime[]
Definition: res_realtime.c:252
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
Definition: cli.c:2167
static int unload_module ( void  )
static

Definition at line 260 of file res_realtime.c.

References ARRAY_LEN, and ast_cli_unregister_multiple().

261 {
263  return 0;
264 }
#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: cli.c:2177
static struct ast_cli_entry cli_realtime[]
Definition: res_realtime.c:252

Variable Documentation

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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
static

Definition at line 272 of file res_realtime.c.

Definition at line 272 of file res_realtime.c.

struct ast_cli_entry cli_realtime[]
static

Definition at line 252 of file res_realtime.c.