Allow the REALTIME() function to report errors back to the caller.

Also, do more error checking on the arguments specified to the REALTIME()
function and clarify the documentation.  While I was editing the file, a
few coding guidelines fixups, as well.

Review: https://reviewboard.asterisk.org/r/2031/
........

Merged revisions 369937 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........

Merged revisions 369938 from http://svn.asterisk.org/svn/asterisk/branches/10


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@369940 65c4cc65-6c06-0410-ace0-fbb531ad65f3
certified/11.2
Tilghman Lesher 13 years ago
parent 92a65de048
commit 6190ae4430

@ -2,10 +2,10 @@
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2005-2006, BJ Weschke. All rights reserved.
*
*
* BJ Weschke <bweschke@btwtech.com>
*
* This code is released by the author with no restrictions on usage.
*
* This code is released by the author with no restrictions on usage.
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
@ -18,9 +18,9 @@
/*! \file
*
* \brief REALTIME dialplan function
*
*
* \author BJ Weschke <bweschke@btwtech.com>
*
*
* \ingroup functions
*/
@ -49,7 +49,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
<syntax>
<parameter name="family" required="true" />
<parameter name="fieldmatch" required="true" />
<parameter name="value" />
<parameter name="matchvalue" />
<parameter name="delim1|field">
<para>Use <replaceable>delim1</replaceable> with <replaceable>delim2</replaceable> on
read and <replaceable>field</replaceable> without <replaceable>delim2</replaceable> on
@ -63,11 +63,11 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
</syntax>
<description>
<para>This function will read or write values from/to a RealTime repository.
REALTIME(....) will read names/values from the repository, and
REALTIME(....) will read names/values from the repository, and
REALTIME(....)= will write a new value/field to the repository. On a
read, this function returns a delimited text string. The name/value
pairs are delimited by <replaceable>delim1</replaceable>, and the name and value are delimited
between each other with delim2.
between each other with delim2.
If there is no match, NULL will be returned by the function.
On a write, this function will always return NULL.</para>
</description>
@ -108,7 +108,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
<syntax>
<parameter name="family" required="true" />
<parameter name="fieldmatch" required="true" />
<parameter name="value" />
<parameter name="matchvalue" />
<parameter name="delim1" />
<parameter name="delim2" />
</syntax>
@ -130,13 +130,13 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
<syntax>
<parameter name="family" required="true" />
<parameter name="fieldmatch" required="true" />
<parameter name="value" required="true" />
<parameter name="matchvalue" required="true" />
<parameter name="fieldname" required="true" />
</syntax>
<description>
<para>This function retrieves a single item, <replaceable>fieldname</replaceable>
from the RT engine, where <replaceable>fieldmatch</replaceable> contains the value
<replaceable>value</replaceable>. When written to, the REALTIME_FIELD() function
<replaceable>matchvalue</replaceable>. When written to, the REALTIME_FIELD() function
performs identically to the REALTIME() function.</para>
</description>
<see-also>
@ -153,12 +153,12 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
<syntax>
<parameter name="family" required="true" />
<parameter name="fieldmatch" required="true" />
<parameter name="value" required="true" />
<parameter name="matchvalue" required="true" />
</syntax>
<description>
<para>This function retrieves a single record from the RT engine, where
<replaceable>fieldmatch</replaceable> contains the value
<replaceable>value</replaceable> and formats the output suitably, such that
<replaceable>matchvalue</replaceable> and formats the output suitably, such that
it can be assigned to the HASH() function. The HASH() function then provides
a suitable method for retrieving each field value of the record.</para>
</description>
@ -175,7 +175,7 @@ AST_THREADSTORAGE(buf1);
AST_THREADSTORAGE(buf2);
AST_THREADSTORAGE(buf3);
static int function_realtime_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static int function_realtime_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
{
struct ast_variable *var, *head;
struct ast_str *out;
@ -190,7 +190,7 @@ static int function_realtime_read(struct ast_channel *chan, const char *cmd, cha
);
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "Syntax: REALTIME(family,fieldmatch[,value[,delim1[,delim2]]]) - missing argument!\n");
ast_log(LOG_WARNING, "Syntax: REALTIME(family,fieldmatch[,matchvalue[,delim1[,delim2]]]) - missing argument!\n");
return -1;
}
@ -243,28 +243,35 @@ static int function_realtime_write(struct ast_channel *chan, const char *cmd, ch
);
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "Syntax: %s(family,fieldmatch,value,newcol) - missing argument!\n", cmd);
ast_log(LOG_WARNING, "Syntax: %s(family,fieldmatch,matchvalue,updatecol) - missing argument!\n", cmd);
return -1;
}
if (chan)
ast_autoservice_start(chan);
AST_STANDARD_APP_ARGS(args, data);
if (ast_strlen_zero(args.fieldmatch) || ast_strlen_zero(args.field)) {
ast_log(LOG_WARNING, "Syntax: %s(family,fieldmatch,matchvalue,updatecol) - missing argument!\n", cmd);
return -1;
}
if (chan) {
ast_autoservice_start(chan);
}
res = ast_update_realtime(args.family, args.fieldmatch, args.value, args.field, (char *)value, SENTINEL);
if (res < 0) {
ast_log(LOG_WARNING, "Failed to update. Check the debug log for possible data repository related entries.\n");
}
if (chan)
if (chan) {
ast_autoservice_stop(chan);
}
return 0;
return res;
}
static int realtimefield_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static int realtimefield_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
{
struct ast_variable *var, *head;
struct ast_str *escapebuf = ast_str_thread_get(&buf1, 16);
@ -286,14 +293,14 @@ static int realtimefield_read(struct ast_channel *chan, const char *cmd, char *d
}
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "Syntax: %s(family,fieldmatch,value%s) - missing argument!\n", cmd, which == rtfield ? ",fieldname" : "");
ast_log(LOG_WARNING, "Syntax: %s(family,fieldmatch,matchvalue%s) - missing argument!\n", cmd, which == rtfield ? ",fieldname" : "");
return -1;
}
AST_STANDARD_APP_ARGS(args, data);
if ((which == rtfield && args.argc != 4) || (which == rthash && args.argc != 3)) {
ast_log(LOG_WARNING, "Syntax: %s(family,fieldmatch,value%s) - missing argument!\n", cmd, which == rtfield ? ",fieldname" : "");
ast_log(LOG_WARNING, "Syntax: %s(family,fieldmatch,matchvalue%s) - missing argument!\n", cmd, which == rtfield ? ",fieldname" : "");
return -1;
}
@ -366,7 +373,7 @@ static int function_realtime_store(struct ast_channel *chan, const char *cmd, ch
AST_STANDARD_APP_ARGS(a, data);
AST_STANDARD_APP_ARGS(v, valcopy);
res = ast_store_realtime(a.family,
res = ast_store_realtime(a.family,
a.f[0], v.v[0], a.f[1], v.v[1], a.f[2], v.v[2], a.f[3], v.v[3], a.f[4], v.v[4],
a.f[5], v.v[5], a.f[6], v.v[6], a.f[7], v.v[7], a.f[8], v.v[8], a.f[9], v.v[9],
a.f[10], v.v[10], a.f[11], v.v[11], a.f[12], v.v[12], a.f[13], v.v[13], a.f[14], v.v[14],
@ -388,7 +395,7 @@ static int function_realtime_store(struct ast_channel *chan, const char *cmd, ch
return 0;
}
static int function_realtime_readdestroy(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static int function_realtime_readdestroy(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
{
struct ast_variable *var, *head;
struct ast_str *out;
@ -403,7 +410,7 @@ static int function_realtime_readdestroy(struct ast_channel *chan, const char *c
);
if (ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "Syntax: REALTIME_DESTROY(family,fieldmatch[,value[,delim1[,delim2]]]) - missing argument!\n");
ast_log(LOG_WARNING, "Syntax: REALTIME_DESTROY(family,fieldmatch[,matchvalue[,delim1[,delim2]]]) - missing argument!\n");
return -1;
}

File diff suppressed because it is too large Load Diff

@ -1,8 +1,10 @@
/* A Bison parser, made by GNU Bison 2.5. */
/* Bison interface for Yacc-like parsers in C
/* A Bison parser, made by GNU Bison 2.4.1. */
/* Skeleton interface for Bison's Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc.
Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -69,7 +71,7 @@
typedef union YYSTYPE
{
/* Line 2068 of yacc.c */
/* Line 1676 of yacc.c */
#line 345 "ast_expr2.y"
struct val *val;
@ -77,8 +79,8 @@ typedef union YYSTYPE
/* Line 2068 of yacc.c */
#line 82 "ast_expr2.h"
/* Line 1676 of yacc.c */
#line 84 "ast_expr2.h"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */

@ -56,7 +56,6 @@ typedef int flex_int32_t;
typedef unsigned char flex_uint8_t;
typedef unsigned short int flex_uint16_t;
typedef unsigned int flex_uint32_t;
#endif /* ! C99 */
/* Limits of integral types. */
#ifndef INT8_MIN
@ -87,6 +86,8 @@ typedef unsigned int flex_uint32_t;
#define UINT32_MAX (4294967295U)
#endif
#endif /* ! C99 */
#endif /* ! FLEXINT_H */
#ifdef __cplusplus
@ -160,7 +161,15 @@ typedef void* yyscan_t;
/* Size of default input buffer. */
#ifndef YY_BUF_SIZE
#ifdef __ia64__
/* On IA-64, the buffer size is 16k, not 8k.
* Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
* Ditto for the __ia64__ case accordingly.
*/
#define YY_BUF_SIZE 32768
#else
#define YY_BUF_SIZE 16384
#endif /* __ia64__ */
#endif
/* The state buf must be large enough to hold one state per character in the main buffer.
@ -600,7 +609,7 @@ int ast_yyget_column(yyscan_t yyscanner);
static int curlycount = 0;
static char *expr2_token_subst(const char *mess);
#line 602 "ast_expr2f.c"
#line 611 "ast_expr2f.c"
#define INITIAL 0
#define var 1
@ -697,10 +706,6 @@ int ast_yyget_lineno (yyscan_t yyscanner );
void ast_yyset_lineno (int line_number ,yyscan_t yyscanner );
int ast_yyget_column (yyscan_t yyscanner );
void ast_yyset_column (int column_no ,yyscan_t yyscanner );
YYSTYPE * ast_yyget_lval (yyscan_t yyscanner );
void ast_yyset_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner );
@ -743,7 +748,12 @@ static int input (yyscan_t yyscanner );
/* Amount of stuff to slurp up with each read. */
#ifndef YY_READ_BUF_SIZE
#ifdef __ia64__
/* On IA-64, the buffer size is 16k, not 8k */
#define YY_READ_BUF_SIZE 16384
#else
#define YY_READ_BUF_SIZE 8192
#endif /* __ia64__ */
#endif
/* Copy whatever the last rule matched to the standard output. */
@ -762,7 +772,7 @@ static int input (yyscan_t yyscanner );
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
{ \
int c = '*'; \
unsigned n; \
size_t n; \
for ( n = 0; n < max_size && \
(c = getc( yyin )) != EOF && c != '\n'; ++n ) \
buf[n] = (char) c; \
@ -850,7 +860,7 @@ YY_DECL
#line 130 "ast_expr2.fl"
#line 852 "ast_expr2f.c"
#line 862 "ast_expr2f.c"
yylval = yylval_param;
@ -1196,7 +1206,7 @@ YY_RULE_SETUP
#line 238 "ast_expr2.fl"
ECHO;
YY_BREAK
#line 1198 "ast_expr2f.c"
#line 1208 "ast_expr2f.c"
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(var):
yyterminate();
@ -1970,8 +1980,8 @@ YY_BUFFER_STATE ast_yy_scan_string (yyconst char * yystr , yyscan_t yyscanner)
/** Setup the input buffer state to scan the given bytes. The next call to ast_yylex() will
* scan from a @e copy of @a bytes.
* @param bytes the byte buffer to scan
* @param len the number of bytes in the buffer pointed to by @a bytes.
* @param yybytes the byte buffer to scan
* @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
* @param yyscanner The scanner object.
* @return the newly allocated buffer state object.
*/

@ -56,7 +56,6 @@ typedef int flex_int32_t;
typedef unsigned char flex_uint8_t;
typedef unsigned short int flex_uint16_t;
typedef unsigned int flex_uint32_t;
#endif /* ! C99 */
/* Limits of integral types. */
#ifndef INT8_MIN
@ -87,6 +86,8 @@ typedef unsigned int flex_uint32_t;
#define UINT32_MAX (4294967295U)
#endif
#endif /* ! C99 */
#endif /* ! FLEXINT_H */
#ifdef __cplusplus
@ -160,7 +161,15 @@ typedef void* yyscan_t;
/* Size of default input buffer. */
#ifndef YY_BUF_SIZE
#ifdef __ia64__
/* On IA-64, the buffer size is 16k, not 8k.
* Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
* Ditto for the __ia64__ case accordingly.
*/
#define YY_BUF_SIZE 32768
#else
#define YY_BUF_SIZE 16384
#endif /* __ia64__ */
#endif
/* The state buf must be large enough to hold one state per character in the main buffer.
@ -952,7 +961,7 @@ static void pbcwhere(const char *text, int *line, int *col )
#define STORE_POS
#define STORE_LOC
#endif
#line 954 "ael_lex.c"
#line 963 "ael_lex.c"
#define INITIAL 0
#define paren 1
@ -1054,10 +1063,6 @@ int ael_yyget_lineno (yyscan_t yyscanner );
void ael_yyset_lineno (int line_number ,yyscan_t yyscanner );
int ael_yyget_column (yyscan_t yyscanner );
void ael_yyset_column (int column_no ,yyscan_t yyscanner );
YYSTYPE * ael_yyget_lval (yyscan_t yyscanner );
void ael_yyset_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner );
@ -1100,7 +1105,12 @@ static int input (yyscan_t yyscanner );
/* Amount of stuff to slurp up with each read. */
#ifndef YY_READ_BUF_SIZE
#ifdef __ia64__
/* On IA-64, the buffer size is 16k, not 8k */
#define YY_READ_BUF_SIZE 16384
#else
#define YY_READ_BUF_SIZE 8192
#endif /* __ia64__ */
#endif
/* Copy whatever the last rule matched to the standard output. */
@ -1119,7 +1129,7 @@ static int input (yyscan_t yyscanner );
if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
{ \
int c = '*'; \
unsigned n; \
size_t n; \
for ( n = 0; n < max_size && \
(c = getc( yyin )) != EOF && c != '\n'; ++n ) \
buf[n] = (char) c; \
@ -1207,7 +1217,7 @@ YY_DECL
#line 217 "ael.flex"
#line 1209 "ael_lex.c"
#line 1219 "ael_lex.c"
yylval = yylval_param;
@ -2041,7 +2051,7 @@ YY_RULE_SETUP
#line 656 "ael.flex"
YY_FATAL_ERROR( "flex scanner jammed" );
YY_BREAK
#line 2043 "ael_lex.c"
#line 2053 "ael_lex.c"
case YY_END_OF_BUFFER:
{
@ -2812,8 +2822,8 @@ YY_BUFFER_STATE ael_yy_scan_string (yyconst char * yystr , yyscan_t yyscanner)
/** Setup the input buffer state to scan the given bytes. The next call to ael_yylex() will
* scan from a @e copy of @a bytes.
* @param bytes the byte buffer to scan
* @param len the number of bytes in the buffer pointed to by @a bytes.
* @param yybytes the byte buffer to scan
* @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
* @param yyscanner The scanner object.
* @return the newly allocated buffer state object.
*/
@ -3368,7 +3378,9 @@ struct pval *ael2_parse(char *filename, int *errors)
if (my_file)
free(my_file);
my_file = strdup(filename);
stat(filename, &stats);
if (stat(filename, &stats)) {
ast_log(LOG_WARNING, "failed to populate stats from file '%s'\n", filename);
}
buffer = (char*)malloc(stats.st_size+2);
if (fread(buffer, 1, stats.st_size, fin) != stats.st_size) {
ast_log(LOG_ERROR, "fread() failed: %s\n", strerror(errno));
@ -3438,7 +3450,9 @@ static void setup_filestack(char *fnamebuf2, int fnamebuf_siz, glob_t *globbuf,
} else {
char *buffer;
struct stat stats;
stat(fnamebuf2, &stats);
if (stat(fnamebuf2, &stats)) {
ast_log(LOG_WARNING, "Failed to populate stats from file '%s'\n", fnamebuf2);
}
buffer = (char*)malloc(stats.st_size+1);
if (fread(buffer, 1, stats.st_size, in1) != stats.st_size) {
ast_log(LOG_ERROR, "fread() failed: %s\n", strerror(errno));

Loading…
Cancel
Save