[svn-commits] jrose: branch 12 r401973 - in /branches/12: res/ res/ari/ rest-api/api-docs/
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Fri Oct 25 16:20:47 CDT 2013
Author: jrose
Date: Fri Oct 25 16:20:42 2013
New Revision: 401973
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=401973
Log:
ARI recordings: Issue HTTP failures for recording requests with file conflicts
If a file already exists in the recordings directory with the same name as what
we would record, issue a 422 instead of relying on the internal failure and
issuing success.
(closes issue ASTERISK-22623)
Reported by: Joshua Colp
Review: https://reviewboard.asterisk.org/r/2922/
Modified:
branches/12/res/ari/ari_model_validators.c
branches/12/res/ari/ari_model_validators.h
branches/12/res/ari/resource_bridges.c
branches/12/res/ari/resource_channels.c
branches/12/res/res_ari_bridges.c
branches/12/res/res_ari_channels.c
branches/12/res/res_stasis_recording.c
branches/12/rest-api/api-docs/bridges.json
branches/12/rest-api/api-docs/channels.json
branches/12/rest-api/api-docs/events.json
branches/12/rest-api/api-docs/recordings.json
Modified: branches/12/res/ari/ari_model_validators.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/ari/ari_model_validators.c?view=diff&rev=401973&r1=401972&r2=401973
==============================================================================
--- branches/12/res/ari/ari_model_validators.c (original)
+++ branches/12/res/ari/ari_model_validators.c Fri Oct 25 16:20:42 2013
@@ -3288,6 +3288,136 @@
return ast_ari_validate_playback_started;
}
+int ast_ari_validate_recording_failed(struct ast_json *json)
+{
+ int res = 1;
+ struct ast_json_iter *iter;
+ int has_cause = 0;
+ int has_recording = 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_is_valid;
+ has_cause = 1;
+ prop_is_valid = ast_ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI RecordingFailed field cause failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("recording", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_recording = 1;
+ prop_is_valid = ast_ari_validate_live_recording(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI RecordingFailed field recording failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI RecordingFailed has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_cause) {
+ ast_log(LOG_ERROR, "ARI RecordingFailed missing required field cause\n");
+ res = 0;
+ }
+
+ if (!has_recording) {
+ ast_log(LOG_ERROR, "ARI RecordingFailed missing required field recording\n");
+ res = 0;
+ }
+
+ return res;
+}
+
+ari_validator ast_ari_validate_recording_failed_fn(void)
+{
+ return ast_ari_validate_recording_failed;
+}
+
+int ast_ari_validate_recording_finished(struct ast_json *json)
+{
+ int res = 1;
+ struct ast_json_iter *iter;
+ int has_recording = 0;
+
+ for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+ if (strcmp("recording", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_recording = 1;
+ prop_is_valid = ast_ari_validate_live_recording(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI RecordingFinished field recording failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI RecordingFinished has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_recording) {
+ ast_log(LOG_ERROR, "ARI RecordingFinished missing required field recording\n");
+ res = 0;
+ }
+
+ return res;
+}
+
+ari_validator ast_ari_validate_recording_finished_fn(void)
+{
+ return ast_ari_validate_recording_finished;
+}
+
+int ast_ari_validate_recording_started(struct ast_json *json)
+{
+ int res = 1;
+ struct ast_json_iter *iter;
+ int has_recording = 0;
+
+ for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+ if (strcmp("recording", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_recording = 1;
+ prop_is_valid = ast_ari_validate_live_recording(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI RecordingStarted field recording failed validation\n");
+ res = 0;
+ }
+ } else
+ {
+ ast_log(LOG_ERROR,
+ "ARI RecordingStarted has undocumented field %s\n",
+ ast_json_object_iter_key(iter));
+ res = 0;
+ }
+ }
+
+ if (!has_recording) {
+ ast_log(LOG_ERROR, "ARI RecordingStarted missing required field recording\n");
+ res = 0;
+ }
+
+ return res;
+}
+
+ari_validator ast_ari_validate_recording_started_fn(void)
+{
+ return ast_ari_validate_recording_started;
+}
+
int ast_ari_validate_stasis_end(struct ast_json *json)
{
int res = 1;
Modified: branches/12/res/ari/ari_model_validators.h
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/ari/ari_model_validators.h?view=diff&rev=401973&r1=401972&r2=401973
==============================================================================
--- branches/12/res/ari/ari_model_validators.h (original)
+++ branches/12/res/ari/ari_model_validators.h Fri Oct 25 16:20:42 2013
@@ -861,6 +861,60 @@
* See \ref ast_ari_model_validators.h for more details.
*/
ari_validator ast_ari_validate_playback_started_fn(void);
+
+/*!
+ * \brief Validator for RecordingFailed.
+ *
+ * Event showing failure of a recording operation.
+ *
+ * \param json JSON object to validate.
+ * \returns True (non-zero) if valid.
+ * \returns False (zero) if invalid.
+ */
+int ast_ari_validate_recording_failed(struct ast_json *json);
+
+/*!
+ * \brief Function pointer to ast_ari_validate_recording_failed().
+ *
+ * See \ref ast_ari_model_validators.h for more details.
+ */
+ari_validator ast_ari_validate_recording_failed_fn(void);
+
+/*!
+ * \brief Validator for RecordingFinished.
+ *
+ * Event showing the completion of a recording operation.
+ *
+ * \param json JSON object to validate.
+ * \returns True (non-zero) if valid.
+ * \returns False (zero) if invalid.
+ */
+int ast_ari_validate_recording_finished(struct ast_json *json);
+
+/*!
+ * \brief Function pointer to ast_ari_validate_recording_finished().
+ *
+ * See \ref ast_ari_model_validators.h for more details.
+ */
+ari_validator ast_ari_validate_recording_finished_fn(void);
+
+/*!
+ * \brief Validator for RecordingStarted.
+ *
+ * Event showing the start of a recording operation.
+ *
+ * \param json JSON object to validate.
+ * \returns True (non-zero) if valid.
+ * \returns False (zero) if invalid.
+ */
+int ast_ari_validate_recording_started(struct ast_json *json);
+
+/*!
+ * \brief Function pointer to ast_ari_validate_recording_started().
+ *
+ * See \ref ast_ari_model_validators.h for more details.
+ */
+ari_validator ast_ari_validate_recording_started_fn(void);
/*!
* \brief Validator for StasisEnd.
@@ -1112,6 +1166,13 @@
* - application: string (required)
* - timestamp: Date
* - playback: Playback (required)
+ * RecordingFailed
+ * - cause: string (required)
+ * - recording: LiveRecording (required)
+ * RecordingFinished
+ * - recording: LiveRecording (required)
+ * RecordingStarted
+ * - recording: LiveRecording (required)
* StasisEnd
* - type: string (required)
* - application: string (required)
Modified: branches/12/res/ari/resource_bridges.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/ari/resource_bridges.c?view=diff&rev=401973&r1=401972&r2=401973
==============================================================================
--- branches/12/res/ari/resource_bridges.c (original)
+++ branches/12/res/ari/resource_bridges.c Fri Oct 25 16:20:42 2013
@@ -452,7 +452,7 @@
break;
case EEXIST:
ast_ari_response_error(response, 409, "Conflict",
- "Recording '%s' already in progress",
+ "Recording '%s' already exists and can not be overwritten",
args->name);
break;
case ENOMEM:
Modified: branches/12/res/ari/resource_channels.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/ari/resource_channels.c?view=diff&rev=401973&r1=401972&r2=401973
==============================================================================
--- branches/12/res/ari/resource_channels.c (original)
+++ branches/12/res/ari/resource_channels.c Fri Oct 25 16:20:42 2013
@@ -420,7 +420,7 @@
break;
case EEXIST:
ast_ari_response_error(response, 409, "Conflict",
- "Recording '%s' already in progress",
+ "Recording '%s' already exists and can not be overwritten",
args->name);
break;
case ENOMEM:
Modified: branches/12/res/res_ari_bridges.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_ari_bridges.c?view=diff&rev=401973&r1=401972&r2=401973
==============================================================================
--- branches/12/res/res_ari_bridges.c (original)
+++ branches/12/res/res_ari_bridges.c Fri Oct 25 16:20:42 2013
@@ -742,9 +742,9 @@
break;
case 500: /* Internal Server Error */
case 501: /* Not Implemented */
- case 400: /* Recording name invalid */
+ case 400: /* Invalid parameters */
case 404: /* Bridge not found */
- case 409: /* Bridge not in Stasis application; Recording already in progress */
+ case 409: /* Bridge is not in a Stasis application; A recording with the same name already exists on the system and can not be overwritten because it is in progress or ifExists=fail */
is_valid = 1;
break;
default:
Modified: branches/12/res/res_ari_channels.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_ari_channels.c?view=diff&rev=401973&r1=401972&r2=401973
==============================================================================
--- branches/12/res/res_ari_channels.c (original)
+++ branches/12/res/res_ari_channels.c Fri Oct 25 16:20:42 2013
@@ -992,7 +992,7 @@
case 501: /* Not Implemented */
case 400: /* Invalid parameters */
case 404: /* Channel not found */
- case 409: /* Channel is not in a Stasis application; the channel is currently bridged with other channels; A recording with the same name is currently in progress. */
+ case 409: /* Channel is not in a Stasis application; the channel is currently bridged with other hcannels; A recording with the same name already exists on the system and can not be overwritten because it is in progress or ifExists=fail */
is_valid = 1;
break;
default:
Modified: branches/12/res/res_stasis_recording.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_stasis_recording.c?view=diff&rev=401973&r1=401972&r2=401973
==============================================================================
--- branches/12/res/res_stasis_recording.c (original)
+++ branches/12/res/res_stasis_recording.c Fri Oct 25 16:20:42 2013
@@ -348,6 +348,14 @@
recording->control = control;
recording->state = STASIS_APP_RECORDING_STATE_QUEUED;
+ if ((recording->options->if_exists == AST_RECORD_IF_EXISTS_FAIL) &&
+ (ast_fileexists(recording->absolute_name, NULL, NULL))) {
+ ast_log(LOG_WARNING, "Recording file '%s' already exists and ifExists option is failure.\n",
+ recording->absolute_name);
+ errno = EEXIST;
+ return NULL;
+ }
+
{
RAII_VAR(struct stasis_app_recording *, old_recording, NULL,
ao2_cleanup);
Modified: branches/12/rest-api/api-docs/bridges.json
URL: http://svnview.digium.com/svn/asterisk/branches/12/rest-api/api-docs/bridges.json?view=diff&rev=401973&r1=401972&r2=401973
==============================================================================
--- branches/12/rest-api/api-docs/bridges.json (original)
+++ branches/12/rest-api/api-docs/bridges.json Fri Oct 25 16:20:42 2013
@@ -454,20 +454,20 @@
}
}
],
- "errorResponses": [
- {
- "code": 400,
- "reason": "Recording name invalid"
- },
- {
- "code": 404,
- "reason": "Bridge not found"
- },
- {
- "code": 409,
- "reason": "Bridge not in Stasis application; Recording already in progress"
- }
- ]
+ "errorResponses": [
+ {
+ "code": 400,
+ "reason": "Invalid parameters"
+ },
+ {
+ "code": 404,
+ "reason": "Bridge not found"
+ },
+ {
+ "code": 409,
+ "reason": "Bridge is not in a Stasis application; A recording with the same name already exists on the system and can not be overwritten because it is in progress or ifExists=fail"
+ }
+ ]
}
]
}
Modified: branches/12/rest-api/api-docs/channels.json
URL: http://svnview.digium.com/svn/asterisk/branches/12/rest-api/api-docs/channels.json?view=diff&rev=401973&r1=401972&r2=401973
==============================================================================
--- branches/12/rest-api/api-docs/channels.json (original)
+++ branches/12/rest-api/api-docs/channels.json Fri Oct 25 16:20:42 2013
@@ -720,7 +720,7 @@
},
{
"code": 409,
- "reason": "Channel is not in a Stasis application; the channel is currently bridged with other channels; A recording with the same name is currently in progress."
+ "reason": "Channel is not in a Stasis application; the channel is currently bridged with other hcannels; A recording with the same name already exists on the system and can not be overwritten because it is in progress or ifExists=fail"
}
]
}
Modified: branches/12/rest-api/api-docs/events.json
URL: http://svnview.digium.com/svn/asterisk/branches/12/rest-api/api-docs/events.json?view=diff&rev=401973&r1=401972&r2=401973
==============================================================================
--- branches/12/rest-api/api-docs/events.json (original)
+++ branches/12/rest-api/api-docs/events.json Fri Oct 25 16:20:42 2013
@@ -120,6 +120,47 @@
}
}
},
+ "RecordingStarted": {
+ "id": "RecordingStarted",
+ "extends": "Event",
+ "description": "Event showing the start of a recording operation.",
+ "properties": {
+ "recording": {
+ "type": "LiveRecording",
+ "description": "Recording control object",
+ "required": true
+ }
+ }
+ },
+ "RecordingFinished": {
+ "id": "RecordingFinished",
+ "extends": "Event",
+ "description": "Event showing the completion of a recording operation.",
+ "properties": {
+ "recording": {
+ "type": "LiveRecording",
+ "description": "Recording control object",
+ "required": true
+ }
+ }
+ },
+ "RecordingFailed": {
+ "id": "RecordingFailed",
+ "extends": "Event",
+ "description": "Event showing failure of a recording operation.",
+ "properties": {
+ "recording": {
+ "type": "LiveRecording",
+ "description": "Recording control object",
+ "required": true
+ },
+ "cause": {
+ "type": "string",
+ "description": "Cause for the recording failure",
+ "required": true
+ }
+ }
+ },
"ApplicationReplaced": {
"id": "ApplicationReplaced",
"description": "Notification that another WebSocket has taken over for an application.\n\nAn application may only be subscribed to by a single WebSocket at a time. If multiple WebSockets attempt to subscribe to the same application, the newer WebSocket wins, and the older one receives this event.",
Modified: branches/12/rest-api/api-docs/recordings.json
URL: http://svnview.digium.com/svn/asterisk/branches/12/rest-api/api-docs/recordings.json?view=diff&rev=401973&r1=401972&r2=401973
==============================================================================
--- branches/12/rest-api/api-docs/recordings.json (original)
+++ branches/12/rest-api/api-docs/recordings.json Fri Oct 25 16:20:42 2013
@@ -309,9 +309,11 @@
"valueType": "LIST",
"values": [
"queued",
- "playing",
+ "recording",
"paused",
- "done"
+ "done",
+ "failed",
+ "canceled"
]
}
},
More information about the svn-commits
mailing list