[svn-commits] dlee: branch dlee/ari-event-remodel r392099 - in /team/dlee/ari-event-remodel...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Mon Jun 17 15:08:48 CDT 2013
Author: dlee
Date: Mon Jun 17 15:08:46 2013
New Revision: 392099
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392099
Log:
Test validators for byte, int, and boolean
Added:
team/dlee/ari-event-remodel/res/res_ari_model.exports.in (with props)
Removed:
team/dlee/ari-event-remodel/include/asterisk/ari_model.h
Modified:
team/dlee/ari-event-remodel/res/res_ari_model.c
team/dlee/ari-event-remodel/res/stasis_http/ari_model.c
team/dlee/ari-event-remodel/rest-api-templates/ari_model.c.mustache
Modified: team/dlee/ari-event-remodel/res/res_ari_model.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel/res/res_ari_model.c?view=diff&rev=392099&r1=392098&r2=392099
==============================================================================
--- team/dlee/ari-event-remodel/res/res_ari_model.c (original)
+++ team/dlee/ari-event-remodel/res/res_ari_model.c Mon Jun 17 15:08:46 2013
@@ -31,7 +31,7 @@
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-#include "asterisk/ari_model.h"
+#include "stasis_http/ari_model.h"
#include "asterisk/logger.h"
#include "asterisk/module.h"
#include "asterisk/utils.h"
@@ -41,7 +41,18 @@
/* Regex to match date strings */
static regex_t date_regex;
-#define DATE_PATTERN "^$"
+/* Regex for YYYY-MM-DD */
+#define REGEX_YMD "[0-9]{4}-[0-9]{2}-[0-9]{2}"
+
+/* Regex for hh:mm(:ss(.s)); seconds and subseconds optional
+ * Handles the probably impossible case of a leap second, too */
+#define REGEX_HMS "[0-2][0-9]:[0-5][0-9](:[0-6][0-9](.[0-9]+)?)?"
+
+/* Regex for timezone */
+#define REGEX_TZ "(Z|[-+][0-2]:[0-59])"
+
+/* REGEX for ISO 8601, the time specifier optional */
+#define ISO8601_PATTERN "^" REGEX_YMD "(T" REGEX_HMS REGEX_TZ ")?$"
static int check_type(struct ast_json *json, enum ast_json_type expected)
{
@@ -54,32 +65,52 @@
return 1;
}
-int ari_validate_byte(struct ast_json *json)
+static int check_range(intmax_t minval, intmax_t maxval, struct ast_json *json)
{
- int v;
+ intmax_t v;
if (!check_type(json, AST_JSON_INTEGER)) {
return 0;
}
v = ast_json_integer_get(json);
+
+ if (v < minval || maxval < v) {
+ ast_log(LOG_ERROR, "Value out of range. Expected %jd <= %jd <= %jd\n", minval, v, maxval);
+ return 0;
+ }
+ return 1;
+}
+
+int ari_validate_byte(struct ast_json *json)
+{
/* Java bytes are signed, which accounts for great fun for all */
- return -128 <= v && v <= 255;
+ return check_range(-128, 255, json);
}
int ari_validate_boolean(struct ast_json *json)
{
- return check_type(json, AST_JSON_TRUE) ||
- check_type(json, AST_JSON_FALSE);
+ enum ast_json_type actual = ast_json_typeof(json);
+ switch (actual) {
+ case AST_JSON_TRUE:
+ case AST_JSON_FALSE:
+ return 1;
+ default:
+ ast_log(LOG_ERROR, "Expected type boolean, was %s\n",
+ ast_json_typename(actual));
+ return 0;
+ }
}
int ari_validate_int(struct ast_json *json)
{
- return check_type(json, AST_JSON_INTEGER);
+ /* Swagger int's are 32-bit */
+ return check_range(-2147483648, 2147483647, json);
}
int ari_validate_long(struct ast_json *json)
{
+ /* All integral values are valid longs. No need for range check. */
return check_type(json, AST_JSON_INTEGER);
}
@@ -139,7 +170,7 @@
static int load_module(void)
{
int res;
- res = regcomp(&date_regex, DATE_PATTERN,
+ res = regcomp(&date_regex, ISO8601_PATTERN,
REG_EXTENDED | REG_ICASE | REG_NOSUB);
if (res != 0) {
@@ -154,7 +185,8 @@
return 0;
}
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER,
+AST_MODULE_INFO(ASTERISK_GPL_KEY,
+ AST_MODFLAG_LOAD_ORDER | AST_MODFLAG_GLOBAL_SYMBOLS,
"ARI Model validators",
.load = load_module,
.unload = unload_module,
Added: team/dlee/ari-event-remodel/res/res_ari_model.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel/res/res_ari_model.exports.in?view=auto&rev=392099
==============================================================================
--- team/dlee/ari-event-remodel/res/res_ari_model.exports.in (added)
+++ team/dlee/ari-event-remodel/res/res_ari_model.exports.in Mon Jun 17 15:08:46 2013
@@ -1,0 +1,6 @@
+{
+ global:
+ LINKER_SYMBOL_PREFIXari_*;
+ local:
+ *;
+};
Propchange: team/dlee/ari-event-remodel/res/res_ari_model.exports.in
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/dlee/ari-event-remodel/res/res_ari_model.exports.in
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/dlee/ari-event-remodel/res/res_ari_model.exports.in
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: team/dlee/ari-event-remodel/res/stasis_http/ari_model.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel/res/stasis_http/ari_model.c?view=diff&rev=392099&r1=392098&r2=392099
==============================================================================
--- team/dlee/ari-event-remodel/res/stasis_http/ari_model.c (original)
+++ team/dlee/ari-event-remodel/res/stasis_http/ari_model.c Mon Jun 17 15:08:46 2013
@@ -33,7 +33,7 @@
#include "asterisk/logger.h"
#include "asterisk/module.h"
-#include "asterisk/ari_model.h"
+#include "ari_model.h"
int ari_validate_asterisk_info(struct ast_json *json)
{
Modified: team/dlee/ari-event-remodel/rest-api-templates/ari_model.c.mustache
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel/rest-api-templates/ari_model.c.mustache?view=diff&rev=392099&r1=392098&r2=392099
==============================================================================
--- team/dlee/ari-event-remodel/rest-api-templates/ari_model.c.mustache (original)
+++ team/dlee/ari-event-remodel/rest-api-templates/ari_model.c.mustache Mon Jun 17 15:08:46 2013
@@ -31,7 +31,7 @@
#include "asterisk/logger.h"
#include "asterisk/module.h"
-#include "asterisk/ari_model.h"
+#include "ari_model.h"
{{#apis}}
{{#api_declaration}}
{{#models}}
More information about the svn-commits
mailing list