mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 04:11:08 +00:00
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/ ........ Merged revisions 401973 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@401999 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -3288,6 +3288,136 @@ ari_validator ast_ari_validate_playback_started_fn(void)
|
||||
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;
|
||||
|
@@ -862,6 +862,60 @@ int ast_ari_validate_playback_started(struct ast_json *json);
|
||||
*/
|
||||
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 @@ ari_validator ast_ari_validate_application_fn(void);
|
||||
* - 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)
|
||||
|
@@ -452,7 +452,7 @@ void ast_ari_record_bridge(struct ast_variable *headers, struct ast_record_bridg
|
||||
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:
|
||||
|
@@ -420,7 +420,7 @@ void ast_ari_record_channel(struct ast_variable *headers,
|
||||
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:
|
||||
|
@@ -742,9 +742,9 @@ static void ast_ari_record_bridge_cb(
|
||||
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:
|
||||
|
@@ -992,7 +992,7 @@ static void ast_ari_record_channel_cb(
|
||||
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:
|
||||
|
@@ -348,6 +348,14 @@ struct stasis_app_recording *stasis_app_control_record(
|
||||
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);
|
||||
|
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@@ -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.",
|
||||
|
@@ -309,9 +309,11 @@
|
||||
"valueType": "LIST",
|
||||
"values": [
|
||||
"queued",
|
||||
"playing",
|
||||
"recording",
|
||||
"paused",
|
||||
"done"
|
||||
"done",
|
||||
"failed",
|
||||
"canceled"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
Reference in New Issue
Block a user