ARI: Add the ability to intercept hold and raise an event
[asterisk/asterisk.git] / res / ari / ari_model_validators.c
index 491a4cc..007d765 100644 (file)
@@ -3197,6 +3197,85 @@ ari_validator ast_ari_validate_channel_hangup_request_fn(void)
        return ast_ari_validate_channel_hangup_request;
 }
 
+int ast_ari_validate_channel_hold(struct ast_json *json)
+{
+       int res = 1;
+       struct ast_json_iter *iter;
+       int has_type = 0;
+       int has_application = 0;
+       int has_channel = 0;
+
+       for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       has_type = 1;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelHold field type failed validation\n");
+                               res = 0;
+                       }
+               } else
+               if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       has_application = 1;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelHold field application failed validation\n");
+                               res = 0;
+                       }
+               } else
+               if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_date(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelHold field timestamp failed validation\n");
+                               res = 0;
+                       }
+               } else
+               if (strcmp("channel", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       has_channel = 1;
+                       prop_is_valid = ast_ari_validate_channel(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelHold field channel failed validation\n");
+                               res = 0;
+                       }
+               } else
+               {
+                       ast_log(LOG_ERROR,
+                               "ARI ChannelHold has undocumented field %s\n",
+                               ast_json_object_iter_key(iter));
+                       res = 0;
+               }
+       }
+
+       if (!has_type) {
+               ast_log(LOG_ERROR, "ARI ChannelHold missing required field type\n");
+               res = 0;
+       }
+
+       if (!has_application) {
+               ast_log(LOG_ERROR, "ARI ChannelHold missing required field application\n");
+               res = 0;
+       }
+
+       if (!has_channel) {
+               ast_log(LOG_ERROR, "ARI ChannelHold missing required field channel\n");
+               res = 0;
+       }
+
+       return res;
+}
+
+ari_validator ast_ari_validate_channel_hold_fn(void)
+{
+       return ast_ari_validate_channel_hold;
+}
+
 int ast_ari_validate_channel_left_bridge(struct ast_json *json)
 {
        int res = 1;
@@ -3545,6 +3624,85 @@ ari_validator ast_ari_validate_channel_talking_started_fn(void)
        return ast_ari_validate_channel_talking_started;
 }
 
+int ast_ari_validate_channel_unhold(struct ast_json *json)
+{
+       int res = 1;
+       struct ast_json_iter *iter;
+       int has_type = 0;
+       int has_application = 0;
+       int has_channel = 0;
+
+       for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+               if (strcmp("type", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       has_type = 1;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelUnhold field type failed validation\n");
+                               res = 0;
+                       }
+               } else
+               if (strcmp("application", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       has_application = 1;
+                       prop_is_valid = ast_ari_validate_string(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelUnhold field application failed validation\n");
+                               res = 0;
+                       }
+               } else
+               if (strcmp("timestamp", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       prop_is_valid = ast_ari_validate_date(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelUnhold field timestamp failed validation\n");
+                               res = 0;
+                       }
+               } else
+               if (strcmp("channel", ast_json_object_iter_key(iter)) == 0) {
+                       int prop_is_valid;
+                       has_channel = 1;
+                       prop_is_valid = ast_ari_validate_channel(
+                               ast_json_object_iter_value(iter));
+                       if (!prop_is_valid) {
+                               ast_log(LOG_ERROR, "ARI ChannelUnhold field channel failed validation\n");
+                               res = 0;
+                       }
+               } else
+               {
+                       ast_log(LOG_ERROR,
+                               "ARI ChannelUnhold has undocumented field %s\n",
+                               ast_json_object_iter_key(iter));
+                       res = 0;
+               }
+       }
+
+       if (!has_type) {
+               ast_log(LOG_ERROR, "ARI ChannelUnhold missing required field type\n");
+               res = 0;
+       }
+
+       if (!has_application) {
+               ast_log(LOG_ERROR, "ARI ChannelUnhold missing required field application\n");
+               res = 0;
+       }
+
+       if (!has_channel) {
+               ast_log(LOG_ERROR, "ARI ChannelUnhold missing required field channel\n");
+               res = 0;
+       }
+
+       return res;
+}
+
+ari_validator ast_ari_validate_channel_unhold_fn(void)
+{
+       return ast_ari_validate_channel_unhold;
+}
+
 int ast_ari_validate_channel_userevent(struct ast_json *json)
 {
        int res = 1;
@@ -4119,6 +4277,9 @@ int ast_ari_validate_event(struct ast_json *json)
        if (strcmp("ChannelHangupRequest", discriminator) == 0) {
                return ast_ari_validate_channel_hangup_request(json);
        } else
+       if (strcmp("ChannelHold", discriminator) == 0) {
+               return ast_ari_validate_channel_hold(json);
+       } else
        if (strcmp("ChannelLeftBridge", discriminator) == 0) {
                return ast_ari_validate_channel_left_bridge(json);
        } else
@@ -4131,6 +4292,9 @@ int ast_ari_validate_event(struct ast_json *json)
        if (strcmp("ChannelTalkingStarted", discriminator) == 0) {
                return ast_ari_validate_channel_talking_started(json);
        } else
+       if (strcmp("ChannelUnhold", discriminator) == 0) {
+               return ast_ari_validate_channel_unhold(json);
+       } else
        if (strcmp("ChannelUserevent", discriminator) == 0) {
                return ast_ari_validate_channel_userevent(json);
        } else
@@ -4290,6 +4454,9 @@ int ast_ari_validate_message(struct ast_json *json)
        if (strcmp("ChannelHangupRequest", discriminator) == 0) {
                return ast_ari_validate_channel_hangup_request(json);
        } else
+       if (strcmp("ChannelHold", discriminator) == 0) {
+               return ast_ari_validate_channel_hold(json);
+       } else
        if (strcmp("ChannelLeftBridge", discriminator) == 0) {
                return ast_ari_validate_channel_left_bridge(json);
        } else
@@ -4302,6 +4469,9 @@ int ast_ari_validate_message(struct ast_json *json)
        if (strcmp("ChannelTalkingStarted", discriminator) == 0) {
                return ast_ari_validate_channel_talking_started(json);
        } else
+       if (strcmp("ChannelUnhold", discriminator) == 0) {
+               return ast_ari_validate_channel_unhold(json);
+       } else
        if (strcmp("ChannelUserevent", discriminator) == 0) {
                return ast_ari_validate_channel_userevent(json);
        } else