[asterisk-commits] dlee: branch dlee/ari-event-remodel2 r392164 - in /team/dlee/ari-event-remode...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jun 18 12:12:41 CDT 2013
Author: dlee
Date: Tue Jun 18 12:12:39 2013
New Revision: 392164
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392164
Log:
Validate extra fields
Modified:
team/dlee/ari-event-remodel2/res/stasis_http/ari_model.c
team/dlee/ari-event-remodel2/rest-api-templates/ari_model.c.mustache
Modified: team/dlee/ari-event-remodel2/res/stasis_http/ari_model.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ari-event-remodel2/res/stasis_http/ari_model.c?view=diff&rev=392164&r1=392163&r2=392164
==============================================================================
--- team/dlee/ari-event-remodel2/res/stasis_http/ari_model.c (original)
+++ team/dlee/ari-event-remodel2/res/stasis_http/ari_model.c Tue Jun 18 12:12:39 2013
@@ -44,268 +44,339 @@
int ari_validate_endpoint(struct ast_json *json)
{
int res = 1;
- struct ast_json *prop;
- prop = ast_json_object_get(json, "resource");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Endpoint field resource failed validation\n");
- res = 0;
- }
- }
- else {
+ struct ast_json_iter *iter;
+ int has_resource = 0;
+ int has_technology = 0;
+
+ for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+ if (strcmp("resource", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_resource = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Endpoint field resource failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("technology", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_technology = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Endpoint field technology failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI Endpoint has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_resource) {
ast_log(LOG_ERROR, "ARI Endpoint missing required field resource\n");
res = 0;
}
- prop = ast_json_object_get(json, "technology");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Endpoint field technology failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_technology) {
ast_log(LOG_ERROR, "ARI Endpoint missing required field technology\n");
res = 0;
}
+
return res;
}
int ari_validate_caller_id(struct ast_json *json)
{
int res = 1;
- struct ast_json *prop;
- prop = ast_json_object_get(json, "name");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI CallerID field name failed validation\n");
- res = 0;
- }
- }
- else {
+ struct ast_json_iter *iter;
+ int has_name = 0;
+ int has_number = 0;
+
+ for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+ if (strcmp("name", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_name = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI CallerID field name failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("number", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_number = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI CallerID field number failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI CallerID has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_name) {
ast_log(LOG_ERROR, "ARI CallerID missing required field name\n");
res = 0;
}
- prop = ast_json_object_get(json, "number");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI CallerID field number failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_number) {
ast_log(LOG_ERROR, "ARI CallerID missing required field number\n");
res = 0;
}
+
return res;
}
int ari_validate_channel(struct ast_json *json)
{
int res = 1;
- struct ast_json *prop;
- prop = ast_json_object_get(json, "accountcode");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Channel field accountcode failed validation\n");
- res = 0;
- }
- }
- else {
+ struct ast_json_iter *iter;
+ int has_accountcode = 0;
+ int has_appl = 0;
+ int has_caller = 0;
+ int has_connected = 0;
+ int has_creationtime = 0;
+ int has_data = 0;
+ int has_dialplan = 0;
+ int has_hangupsource = 0;
+ int has_linkedid = 0;
+ int has_name = 0;
+ int has_parkinglot = 0;
+ int has_peeraccount = 0;
+ int has_state = 0;
+ int has_uniqueid = 0;
+ int has_userfield = 0;
+
+ for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+ if (strcmp("accountcode", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_accountcode = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Channel field accountcode failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("appl", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_appl = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Channel field appl failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("caller", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_caller = 1;
+ prop_res = ari_validate_caller_id(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Channel field caller failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("connected", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_connected = 1;
+ prop_res = ari_validate_caller_id(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Channel field connected failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("creationtime", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_creationtime = 1;
+ prop_res = ari_validate_date(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Channel field creationtime failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("data", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_data = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Channel field data failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("dialplan", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_dialplan = 1;
+ prop_res = ari_validate_dialplan_cep(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Channel field dialplan failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("hangupsource", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_hangupsource = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Channel field hangupsource failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("linkedid", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_linkedid = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Channel field linkedid failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("name", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_name = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Channel field name failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("parkinglot", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_parkinglot = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Channel field parkinglot failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("peeraccount", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_peeraccount = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Channel field peeraccount failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("state", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_state = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Channel field state failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("uniqueid", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_uniqueid = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Channel field uniqueid failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("userfield", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_userfield = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Channel field userfield failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI Channel has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_accountcode) {
ast_log(LOG_ERROR, "ARI Channel missing required field accountcode\n");
res = 0;
}
- prop = ast_json_object_get(json, "appl");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Channel field appl failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_appl) {
ast_log(LOG_ERROR, "ARI Channel missing required field appl\n");
res = 0;
}
- prop = ast_json_object_get(json, "caller");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_caller_id(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Channel field caller failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_caller) {
ast_log(LOG_ERROR, "ARI Channel missing required field caller\n");
res = 0;
}
- prop = ast_json_object_get(json, "connected");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_caller_id(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Channel field connected failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_connected) {
ast_log(LOG_ERROR, "ARI Channel missing required field connected\n");
res = 0;
}
- prop = ast_json_object_get(json, "creationtime");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_date(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Channel field creationtime failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_creationtime) {
ast_log(LOG_ERROR, "ARI Channel missing required field creationtime\n");
res = 0;
}
- prop = ast_json_object_get(json, "data");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Channel field data failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_data) {
ast_log(LOG_ERROR, "ARI Channel missing required field data\n");
res = 0;
}
- prop = ast_json_object_get(json, "dialplan");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_dialplan_cep(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Channel field dialplan failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_dialplan) {
ast_log(LOG_ERROR, "ARI Channel missing required field dialplan\n");
res = 0;
}
- prop = ast_json_object_get(json, "hangupsource");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Channel field hangupsource failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_hangupsource) {
ast_log(LOG_ERROR, "ARI Channel missing required field hangupsource\n");
res = 0;
}
- prop = ast_json_object_get(json, "linkedid");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Channel field linkedid failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_linkedid) {
ast_log(LOG_ERROR, "ARI Channel missing required field linkedid\n");
res = 0;
}
- prop = ast_json_object_get(json, "name");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Channel field name failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_name) {
ast_log(LOG_ERROR, "ARI Channel missing required field name\n");
res = 0;
}
- prop = ast_json_object_get(json, "parkinglot");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Channel field parkinglot failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_parkinglot) {
ast_log(LOG_ERROR, "ARI Channel missing required field parkinglot\n");
res = 0;
}
- prop = ast_json_object_get(json, "peeraccount");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Channel field peeraccount failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_peeraccount) {
ast_log(LOG_ERROR, "ARI Channel missing required field peeraccount\n");
res = 0;
}
- prop = ast_json_object_get(json, "state");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Channel field state failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_state) {
ast_log(LOG_ERROR, "ARI Channel missing required field state\n");
res = 0;
}
- prop = ast_json_object_get(json, "uniqueid");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Channel field uniqueid failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_uniqueid) {
ast_log(LOG_ERROR, "ARI Channel missing required field uniqueid\n");
res = 0;
}
- prop = ast_json_object_get(json, "userfield");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Channel field userfield failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_userfield) {
ast_log(LOG_ERROR, "ARI Channel missing required field userfield\n");
res = 0;
}
+
return res;
}
@@ -318,906 +389,1305 @@
int ari_validate_dialplan_cep(struct ast_json *json)
{
int res = 1;
- struct ast_json *prop;
- prop = ast_json_object_get(json, "context");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI DialplanCEP field context failed validation\n");
- res = 0;
- }
- }
- else {
+ struct ast_json_iter *iter;
+ int has_context = 0;
+ int has_exten = 0;
+ int has_priority = 0;
+
+ for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+ if (strcmp("context", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_context = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI DialplanCEP field context failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("exten", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_exten = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI DialplanCEP field exten failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("priority", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_priority = 1;
+ prop_res = ari_validate_long(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI DialplanCEP field priority failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI DialplanCEP has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_context) {
ast_log(LOG_ERROR, "ARI DialplanCEP missing required field context\n");
res = 0;
}
- prop = ast_json_object_get(json, "exten");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI DialplanCEP field exten failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_exten) {
ast_log(LOG_ERROR, "ARI DialplanCEP missing required field exten\n");
res = 0;
}
- prop = ast_json_object_get(json, "priority");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_long(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI DialplanCEP field priority failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_priority) {
ast_log(LOG_ERROR, "ARI DialplanCEP missing required field priority\n");
res = 0;
}
+
return res;
}
int ari_validate_bridge(struct ast_json *json)
{
int res = 1;
- struct ast_json *prop;
- prop = ast_json_object_get(json, "bridge_type");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Bridge field bridge_type failed validation\n");
- res = 0;
- }
- }
- else {
+ struct ast_json_iter *iter;
+ int has_bridge_type = 0;
+ int has_channels = 0;
+
+ for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+ if (strcmp("bridge_type", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_bridge_type = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Bridge field bridge_type failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("channels", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_channels = 1;
+ prop_res = ari_validate_list(
+ ast_json_object_iter_value(iter),
+ ari_validate_string);
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Bridge field channels failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI Bridge has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_bridge_type) {
ast_log(LOG_ERROR, "ARI Bridge missing required field bridge_type\n");
res = 0;
}
- prop = ast_json_object_get(json, "channels");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_list(prop, ari_validate_string);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Bridge field channels failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_channels) {
ast_log(LOG_ERROR, "ARI Bridge missing required field channels\n");
res = 0;
}
+
return res;
}
int ari_validate_live_recording(struct ast_json *json)
{
int res = 1;
- struct ast_json *prop;
- prop = ast_json_object_get(json, "id");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI LiveRecording field id failed validation\n");
- res = 0;
- }
- }
- else {
+ struct ast_json_iter *iter;
+ int has_id = 0;
+
+ for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+ if (strcmp("id", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_id = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI LiveRecording field id failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI LiveRecording has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_id) {
ast_log(LOG_ERROR, "ARI LiveRecording missing required field id\n");
res = 0;
}
+
return res;
}
int ari_validate_stored_recording(struct ast_json *json)
{
int res = 1;
- struct ast_json *prop;
- prop = ast_json_object_get(json, "duration_seconds");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_int(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI StoredRecording field duration_seconds failed validation\n");
- res = 0;
- }
- }
- prop = ast_json_object_get(json, "formats");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_list(prop, ari_validate_string);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI StoredRecording field formats failed validation\n");
- res = 0;
- }
- }
- else {
+ struct ast_json_iter *iter;
+ int has_formats = 0;
+ int has_id = 0;
+
+ for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+ if (strcmp("duration_seconds", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ prop_res = ari_validate_int(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI StoredRecording field duration_seconds failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("formats", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_formats = 1;
+ prop_res = ari_validate_list(
+ ast_json_object_iter_value(iter),
+ ari_validate_string);
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI StoredRecording field formats failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("id", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_id = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI StoredRecording field id failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("time", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ prop_res = ari_validate_date(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI StoredRecording field time failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI StoredRecording has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_formats) {
ast_log(LOG_ERROR, "ARI StoredRecording missing required field formats\n");
res = 0;
}
- prop = ast_json_object_get(json, "id");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI StoredRecording field id failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_id) {
ast_log(LOG_ERROR, "ARI StoredRecording missing required field id\n");
res = 0;
}
- prop = ast_json_object_get(json, "time");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_date(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI StoredRecording field time failed validation\n");
- res = 0;
- }
- }
+
return res;
}
int ari_validate_sound(struct ast_json *json)
{
int res = 1;
- struct ast_json *prop;
- prop = ast_json_object_get(json, "formats");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_list(prop, ari_validate_string);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Sound field formats failed validation\n");
- res = 0;
- }
- }
- else {
+ struct ast_json_iter *iter;
+ int has_formats = 0;
+ int has_id = 0;
+ int has_lang = 0;
+
+ for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+ if (strcmp("formats", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_formats = 1;
+ prop_res = ari_validate_list(
+ ast_json_object_iter_value(iter),
+ ari_validate_string);
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Sound field formats failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("id", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_id = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Sound field id failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("lang", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_lang = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Sound field lang failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("text", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Sound field text failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI Sound has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_formats) {
ast_log(LOG_ERROR, "ARI Sound missing required field formats\n");
res = 0;
}
- prop = ast_json_object_get(json, "id");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Sound field id failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_id) {
ast_log(LOG_ERROR, "ARI Sound missing required field id\n");
res = 0;
}
- prop = ast_json_object_get(json, "lang");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Sound field lang failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_lang) {
ast_log(LOG_ERROR, "ARI Sound missing required field lang\n");
res = 0;
}
- prop = ast_json_object_get(json, "text");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Sound field text failed validation\n");
- res = 0;
- }
- }
+
return res;
}
int ari_validate_playback(struct ast_json *json)
{
int res = 1;
- struct ast_json *prop;
- prop = ast_json_object_get(json, "id");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Playback field id failed validation\n");
- res = 0;
- }
- }
- else {
+ struct ast_json_iter *iter;
+ int has_id = 0;
+ int has_media_uri = 0;
+ int has_state = 0;
+ int has_target_uri = 0;
+
+ for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+ if (strcmp("id", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_id = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Playback field id failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("language", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Playback field language failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("media_uri", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_media_uri = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Playback field media_uri failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("state", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_state = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Playback field state failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("target_uri", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_target_uri = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI Playback field target_uri failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI Playback has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_id) {
ast_log(LOG_ERROR, "ARI Playback missing required field id\n");
res = 0;
}
- prop = ast_json_object_get(json, "language");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Playback field language failed validation\n");
- res = 0;
- }
- }
- prop = ast_json_object_get(json, "media_uri");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Playback field media_uri failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_media_uri) {
ast_log(LOG_ERROR, "ARI Playback missing required field media_uri\n");
res = 0;
}
- prop = ast_json_object_get(json, "state");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Playback field state failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_state) {
ast_log(LOG_ERROR, "ARI Playback missing required field state\n");
res = 0;
}
- prop = ast_json_object_get(json, "target_uri");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI Playback field target_uri failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_target_uri) {
ast_log(LOG_ERROR, "ARI Playback missing required field target_uri\n");
res = 0;
}
+
return res;
}
int ari_validate_application_replaced(struct ast_json *json)
{
int res = 1;
- struct ast_json *prop;
- prop = ast_json_object_get(json, "application");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI ApplicationReplaced field application failed validation\n");
- res = 0;
- }
- }
- else {
+ struct ast_json_iter *iter;
+ int has_application = 0;
+
+ for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+ if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_application = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI ApplicationReplaced field application failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI ApplicationReplaced has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_application) {
ast_log(LOG_ERROR, "ARI ApplicationReplaced missing required field application\n");
res = 0;
}
+
return res;
}
int ari_validate_bridge_created(struct ast_json *json)
{
int res = 1;
- struct ast_json *prop;
- prop = ast_json_object_get(json, "bridge");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_bridge(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI BridgeCreated field bridge failed validation\n");
- res = 0;
- }
- }
- else {
+ struct ast_json_iter *iter;
+ int has_bridge = 0;
+
+ for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+ if (strcmp("bridge", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_bridge = 1;
+ prop_res = ari_validate_bridge(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI BridgeCreated field bridge failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI BridgeCreated has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_bridge) {
ast_log(LOG_ERROR, "ARI BridgeCreated missing required field bridge\n");
res = 0;
}
+
return res;
}
int ari_validate_bridge_destroyed(struct ast_json *json)
{
int res = 1;
- struct ast_json *prop;
- prop = ast_json_object_get(json, "bridge");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_bridge(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI BridgeDestroyed field bridge failed validation\n");
- res = 0;
- }
- }
- else {
+ struct ast_json_iter *iter;
+ int has_bridge = 0;
+
+ for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+ if (strcmp("bridge", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_bridge = 1;
+ prop_res = ari_validate_bridge(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI BridgeDestroyed field bridge failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI BridgeDestroyed has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_bridge) {
ast_log(LOG_ERROR, "ARI BridgeDestroyed missing required field bridge\n");
res = 0;
}
+
return res;
}
int ari_validate_bridge_merged(struct ast_json *json)
{
int res = 1;
- struct ast_json *prop;
- prop = ast_json_object_get(json, "bridge");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_bridge(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI BridgeMerged field bridge failed validation\n");
- res = 0;
- }
- }
- else {
+ struct ast_json_iter *iter;
+ int has_bridge = 0;
+ int has_bridge_from = 0;
+
+ for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+ if (strcmp("bridge", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_bridge = 1;
+ prop_res = ari_validate_bridge(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI BridgeMerged field bridge failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("bridge_from", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_bridge_from = 1;
+ prop_res = ari_validate_bridge(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI BridgeMerged field bridge_from failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI BridgeMerged has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_bridge) {
ast_log(LOG_ERROR, "ARI BridgeMerged missing required field bridge\n");
res = 0;
}
- prop = ast_json_object_get(json, "bridge_from");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_bridge(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI BridgeMerged field bridge_from failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_bridge_from) {
ast_log(LOG_ERROR, "ARI BridgeMerged missing required field bridge_from\n");
res = 0;
}
+
return res;
}
int ari_validate_channel_caller_id(struct ast_json *json)
{
int res = 1;
- struct ast_json *prop;
- prop = ast_json_object_get(json, "caller_presentation");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_int(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI ChannelCallerId field caller_presentation failed validation\n");
- res = 0;
- }
- }
- else {
+ struct ast_json_iter *iter;
+ int has_caller_presentation = 0;
+ int has_caller_presentation_txt = 0;
+ int has_channel = 0;
+
+ for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+ if (strcmp("caller_presentation", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_caller_presentation = 1;
+ prop_res = ari_validate_int(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI ChannelCallerId field caller_presentation failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("caller_presentation_txt", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_caller_presentation_txt = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI ChannelCallerId field caller_presentation_txt failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("channel", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_channel = 1;
+ prop_res = ari_validate_channel(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI ChannelCallerId field channel failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI ChannelCallerId has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_caller_presentation) {
ast_log(LOG_ERROR, "ARI ChannelCallerId missing required field caller_presentation\n");
res = 0;
}
- prop = ast_json_object_get(json, "caller_presentation_txt");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_string(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI ChannelCallerId field caller_presentation_txt failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_caller_presentation_txt) {
ast_log(LOG_ERROR, "ARI ChannelCallerId missing required field caller_presentation_txt\n");
res = 0;
}
- prop = ast_json_object_get(json, "channel");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_channel(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI ChannelCallerId field channel failed validation\n");
- res = 0;
- }
- }
- else {
+ if (!has_channel) {
ast_log(LOG_ERROR, "ARI ChannelCallerId missing required field channel\n");
res = 0;
}
+
return res;
}
int ari_validate_channel_created(struct ast_json *json)
{
int res = 1;
- struct ast_json *prop;
- prop = ast_json_object_get(json, "channel");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_channel(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI ChannelCreated field channel failed validation\n");
- res = 0;
- }
- }
- else {
+ struct ast_json_iter *iter;
+ int has_channel = 0;
+
+ for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+ if (strcmp("channel", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_channel = 1;
+ prop_res = ari_validate_channel(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI ChannelCreated field channel failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI ChannelCreated has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_channel) {
ast_log(LOG_ERROR, "ARI ChannelCreated missing required field channel\n");
res = 0;
}
+
return res;
}
int ari_validate_channel_destroyed(struct ast_json *json)
{
int res = 1;
- struct ast_json *prop;
- prop = ast_json_object_get(json, "cause");
- if (prop) {
- int prop_res;
- prop_res = ari_validate_int(prop);
- if (!prop_res) {
- ast_log(LOG_ERROR, "ARI ChannelDestroyed field cause failed validation\n");
- res = 0;
- }
- }
- else {
+ struct ast_json_iter *iter;
+ int has_cause = 0;
+ int has_cause_txt = 0;
+ int has_channel = 0;
+
+ for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+ if (strcmp("cause", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_cause = 1;
+ prop_res = ari_validate_int(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI ChannelDestroyed field cause failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("cause_txt", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_cause_txt = 1;
+ prop_res = ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_res) {
+ ast_log(LOG_ERROR, "ARI ChannelDestroyed field cause_txt failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("channel", ast_json_object_iter_key(iter)) == 0) {
+ int prop_res;
+ has_channel = 1;
+ prop_res = ari_validate_channel(
[... 1027 lines stripped ...]
More information about the asterisk-commits
mailing list