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/


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@369937 65c4cc65-6c06-0410-ace0-fbb531ad65f3
changes/98/198/1
Tilghman Lesher 13 years ago
parent 913225a79a
commit be2a4c0d0d

@ -49,7 +49,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
<syntax> <syntax>
<parameter name="family" required="true" /> <parameter name="family" required="true" />
<parameter name="fieldmatch" required="true" /> <parameter name="fieldmatch" required="true" />
<parameter name="value" /> <parameter name="matchvalue" />
<parameter name="delim1|field"> <parameter name="delim1|field">
<para>Use <replaceable>delim1</replaceable> with <replaceable>delim2</replaceable> on <para>Use <replaceable>delim1</replaceable> with <replaceable>delim2</replaceable> on
read and <replaceable>field</replaceable> without <replaceable>delim2</replaceable> on read and <replaceable>field</replaceable> without <replaceable>delim2</replaceable> on
@ -108,7 +108,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
<syntax> <syntax>
<parameter name="family" required="true" /> <parameter name="family" required="true" />
<parameter name="fieldmatch" required="true" /> <parameter name="fieldmatch" required="true" />
<parameter name="value" /> <parameter name="matchvalue" />
<parameter name="delim1" /> <parameter name="delim1" />
<parameter name="delim2" /> <parameter name="delim2" />
</syntax> </syntax>
@ -130,13 +130,13 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
<syntax> <syntax>
<parameter name="family" required="true" /> <parameter name="family" required="true" />
<parameter name="fieldmatch" required="true" /> <parameter name="fieldmatch" required="true" />
<parameter name="value" required="true" /> <parameter name="matchvalue" required="true" />
<parameter name="fieldname" required="true" /> <parameter name="fieldname" required="true" />
</syntax> </syntax>
<description> <description>
<para>This function retrieves a single item, <replaceable>fieldname</replaceable> <para>This function retrieves a single item, <replaceable>fieldname</replaceable>
from the RT engine, where <replaceable>fieldmatch</replaceable> contains the value 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> performs identically to the REALTIME() function.</para>
</description> </description>
<see-also> <see-also>
@ -153,12 +153,12 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
<syntax> <syntax>
<parameter name="family" required="true" /> <parameter name="family" required="true" />
<parameter name="fieldmatch" required="true" /> <parameter name="fieldmatch" required="true" />
<parameter name="value" required="true" /> <parameter name="matchvalue" required="true" />
</syntax> </syntax>
<description> <description>
<para>This function retrieves a single record from the RT engine, where <para>This function retrieves a single record from the RT engine, where
<replaceable>fieldmatch</replaceable> contains the value <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 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> a suitable method for retrieving each field value of the record.</para>
</description> </description>
@ -190,7 +190,7 @@ static int function_realtime_read(struct ast_channel *chan, const char *cmd, cha
); );
if (ast_strlen_zero(data)) { 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; return -1;
} }
@ -243,25 +243,32 @@ static int function_realtime_write(struct ast_channel *chan, const char *cmd, ch
); );
if (ast_strlen_zero(data)) { 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; return -1;
} }
if (chan)
ast_autoservice_start(chan);
AST_STANDARD_APP_ARGS(args, data); 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); res = ast_update_realtime(args.family, args.fieldmatch, args.value, args.field, (char *)value, SENTINEL);
if (res < 0) { if (res < 0) {
ast_log(LOG_WARNING, "Failed to update. Check the debug log for possible data repository related entries.\n"); 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); 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)
@ -286,14 +293,14 @@ static int realtimefield_read(struct ast_channel *chan, const char *cmd, char *d
} }
if (ast_strlen_zero(data)) { 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; return -1;
} }
AST_STANDARD_APP_ARGS(args, data); AST_STANDARD_APP_ARGS(args, data);
if ((which == rtfield && args.argc != 4) || (which == rthash && args.argc != 3)) { 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; return -1;
} }
@ -403,7 +410,7 @@ static int function_realtime_readdestroy(struct ast_channel *chan, const char *c
); );
if (ast_strlen_zero(data)) { 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; return -1;
} }

Loading…
Cancel
Save