[svn-commits] dlee: trunk r397988 - in /trunk: ./ include/asterisk/ res/ res/ari/ res/stasi...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Fri Aug 30 08:28:53 CDT 2013
Author: dlee
Date: Fri Aug 30 08:28:50 2013
New Revision: 397988
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=397988
Log:
ARI: Implement /recordings/stored API's
his patch implements the ARI API's for stored recordings. While the
original task only specified deleting a recording, it was simple
enough to implement the GET for all recordings, and for an individual
recording.
The recording playback operation was modified to use the same code for
accessing the recording as the REST API, so that they will behave
consistently.
There were several problems with the api-docs that were also fixed,
bringing the ARI spec in line with the implementation. There were some
'wishful thinking' fields on the stored recording model (duration and
timestamp) that were removed, because I ended up not implementing a
metadata file to go along with the recording to store such information.
The GET /recordings/live operation was removed, since it's not really
that useful to get a list of all recordings that are currently going
on in the system. (At least, if we did that, we'd probably want to
also list all of the current playbacks. Which seems weird.)
(closes issue ASTERISK-21582)
Review: https://reviewboard.asterisk.org/r/2693/
........
Merged revisions 397985 from http://svn.asterisk.org/svn/asterisk/branches/12
Added:
trunk/res/stasis_recording/
- copied from r397985, branches/12/res/stasis_recording/
Modified:
trunk/ (props changed)
trunk/include/asterisk/stasis_app_recording.h
trunk/res/Makefile
trunk/res/ari/ari_model_validators.c
trunk/res/ari/ari_model_validators.h
trunk/res/ari/resource_recordings.c
trunk/res/ari/resource_recordings.h
trunk/res/res_ari_recordings.c
trunk/res/res_stasis_playback.c
trunk/res/res_stasis_recording.c
trunk/rest-api/api-docs/recordings.json
Propchange: trunk/
------------------------------------------------------------------------------
--- branch-12-merged (original)
+++ branch-12-merged Fri Aug 30 08:28:50 2013
@@ -1,1 +1,1 @@
-/branches/12:1-397977
+/branches/12:1-397985
Modified: trunk/include/asterisk/stasis_app_recording.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/stasis_app_recording.h?view=diff&rev=397988&r1=397987&r2=397988
==============================================================================
--- trunk/include/asterisk/stasis_app_recording.h (original)
+++ trunk/include/asterisk/stasis_app_recording.h Fri Aug 30 08:28:50 2013
@@ -30,6 +30,68 @@
#include "asterisk/app.h"
#include "asterisk/stasis_app.h"
+
+/*! @{ */
+
+/*! \brief Structure representing a recording stored on disk */
+struct stasis_app_stored_recording;
+
+/*!
+ * \brief Returns the filename for this recording, for use with streamfile.
+ *
+ * The returned string will be valid until the \a recording object is freed.
+ *
+ * \param recording Recording to query.
+ * \return Absolute path to the recording file, without the extension.
+ * \return \c NULL on error.
+ */
+const char *stasis_app_stored_recording_get_file(
+ struct stasis_app_stored_recording *recording);
+
+/*!
+ * \brief Convert stored recording info to JSON.
+ *
+ * \param recording Recording to convert.
+ * \return JSON representation.
+ * \return \c NULL on error.
+ */
+struct ast_json *stasis_app_stored_recording_to_json(
+ struct stasis_app_stored_recording *recording);
+
+/*!
+ * \brief Find all stored recordings on disk.
+ *
+ * \return Container of \ref stasis_app_stored_recording objects.
+ * \return \c NULL on error.
+ */
+struct ao2_container *stasis_app_stored_recording_find_all(void);
+
+/*!
+ * \brief Creates a stored recording object, with the given name.
+ *
+ * \param name Name of the recording.
+ * \return New recording object.
+ * \return \c NULL if recording is not found. \c errno is set to indicate why
+ * - \c ENOMEM - out of memeory
+ * - \c EACCES - file permissions (or recording is outside the config dir)
+ * - Any of the error codes for stat(), opendir(), readdir()
+ */
+struct stasis_app_stored_recording *stasis_app_stored_recording_find_by_name(
+ const char *name);
+
+/*!
+ * \brief Delete a recording from disk.
+ *
+ * \param recording Recording to delete.
+ * \return 0 on success.
+ * \return Non-zero on error.
+ */
+int stasis_app_stored_recording_delete(
+ struct stasis_app_stored_recording *recording);
+
+/*! @} */
+
+/*! @{ */
/*! Opaque struct for handling the recording of media to a file. */
struct stasis_app_recording;
@@ -216,4 +278,6 @@
*/
struct stasis_message_type *stasis_app_recording_snapshot_type(void);
+/*! @} */
+
#endif /* _ASTERISK_STASIS_APP_RECORDING_H */
Modified: trunk/res/Makefile
URL: http://svnview.digium.com/svn/asterisk/trunk/res/Makefile?view=diff&rev=397988&r1=397987&r2=397988
==============================================================================
--- trunk/res/Makefile (original)
+++ trunk/res/Makefile Fri Aug 30 08:28:50 2013
@@ -75,7 +75,7 @@
clean::
rm -f snmp/*.[oi] ael/*.[oi] ais/*.[oi] ari/*.[oi]
rm -f res_pjsip/*.[oi] stasis/*.[oi]
- rm -f parking/*.o parking/*.i
+ rm -f parking/*.o parking/*.i stasis_recording/*.[oi]
$(if $(filter res_parking,$(EMBEDDED_MODS)),modules.link,res_parking.so): $(subst .c,.o,$(wildcard parking/*.c))
$(subst .c,.o,$(wildcard parking/*.c)): _ASTCFLAGS+=$(call MOD_ASTCFLAGS,res_parking)
@@ -86,5 +86,8 @@
res_ari_model.so: ari/ari_model_validators.o
ari/ari_model_validators.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,res_ari_model)
+res_stasis_recording.so: stasis_recording/stored.o
+stasis_recording/stored.o: _ASTCFLAGS+=$(call MOD_ASTCFLAGS,res_stasis_recording)
+
# Dependencies for res_ari_*.so are generated, so they're in this file
include ari.make
Modified: trunk/res/ari/ari_model_validators.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/ari/ari_model_validators.c?view=diff&rev=397988&r1=397987&r2=397988
==============================================================================
--- trunk/res/ari/ari_model_validators.c (original)
+++ trunk/res/ari/ari_model_validators.c Fri Aug 30 08:28:50 2013
@@ -1061,46 +1061,27 @@
{
int res = 1;
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_is_valid;
- prop_is_valid = ast_ari_validate_int(
- ast_json_object_iter_value(iter));
- if (!prop_is_valid) {
- 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_is_valid;
- has_formats = 1;
- prop_is_valid = ast_ari_validate_list(
- ast_json_object_iter_value(iter),
- ast_ari_validate_string);
- if (!prop_is_valid) {
- 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_is_valid;
- has_id = 1;
- prop_is_valid = ast_ari_validate_string(
- ast_json_object_iter_value(iter));
- if (!prop_is_valid) {
- 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_is_valid;
- prop_is_valid = ast_ari_validate_date(
- ast_json_object_iter_value(iter));
- if (!prop_is_valid) {
- ast_log(LOG_ERROR, "ARI StoredRecording field time failed validation\n");
+ int has_format = 0;
+ int has_name = 0;
+
+ for (iter = ast_json_object_iter(json); iter; iter = ast_json_object_iter_next(json, iter)) {
+ if (strcmp("format", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_format = 1;
+ prop_is_valid = ast_ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI StoredRecording field format failed validation\n");
+ res = 0;
+ }
+ } else
+ if (strcmp("name", ast_json_object_iter_key(iter)) == 0) {
+ int prop_is_valid;
+ has_name = 1;
+ prop_is_valid = ast_ari_validate_string(
+ ast_json_object_iter_value(iter));
+ if (!prop_is_valid) {
+ ast_log(LOG_ERROR, "ARI StoredRecording field name failed validation\n");
res = 0;
}
} else
@@ -1112,13 +1093,13 @@
}
}
- if (!has_formats) {
- ast_log(LOG_ERROR, "ARI StoredRecording missing required field formats\n");
- res = 0;
- }
-
- if (!has_id) {
- ast_log(LOG_ERROR, "ARI StoredRecording missing required field id\n");
+ if (!has_format) {
+ ast_log(LOG_ERROR, "ARI StoredRecording missing required field format\n");
+ res = 0;
+ }
+
+ if (!has_name) {
+ ast_log(LOG_ERROR, "ARI StoredRecording missing required field name\n");
res = 0;
}
Modified: trunk/res/ari/ari_model_validators.h
URL: http://svnview.digium.com/svn/asterisk/trunk/res/ari/ari_model_validators.h?view=diff&rev=397988&r1=397987&r2=397988
==============================================================================
--- trunk/res/ari/ari_model_validators.h (original)
+++ trunk/res/ari/ari_model_validators.h Fri Aug 30 08:28:50 2013
@@ -937,10 +937,8 @@
* - name: string (required)
* - state: string (required)
* StoredRecording
- * - duration_seconds: int
- * - formats: List[string] (required)
- * - id: string (required)
- * - time: Date
+ * - format: string (required)
+ * - name: string (required)
* FormatLangPair
* - format: string (required)
* - language: string (required)
Modified: trunk/res/ari/resource_recordings.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/ari/resource_recordings.c?view=diff&rev=397988&r1=397987&r2=397988
==============================================================================
--- trunk/res/ari/resource_recordings.c (original)
+++ trunk/res/ari/resource_recordings.c Fri Aug 30 08:28:50 2013
@@ -30,21 +30,111 @@
#include "asterisk/stasis_app_recording.h"
#include "resource_recordings.h"
-void ast_ari_get_stored_recordings(struct ast_variable *headers, struct ast_get_stored_recordings_args *args, struct ast_ari_response *response)
-{
- ast_log(LOG_ERROR, "TODO: ast_ari_get_stored_recordings\n");
-}
-void ast_ari_get_stored_recording(struct ast_variable *headers, struct ast_get_stored_recording_args *args, struct ast_ari_response *response)
-{
- ast_log(LOG_ERROR, "TODO: ast_ari_get_stored_recording\n");
-}
-void ast_ari_delete_stored_recording(struct ast_variable *headers, struct ast_delete_stored_recording_args *args, struct ast_ari_response *response)
-{
- ast_log(LOG_ERROR, "TODO: ast_ari_delete_stored_recording\n");
-}
-void ast_ari_get_live_recordings(struct ast_variable *headers, struct ast_get_live_recordings_args *args, struct ast_ari_response *response)
-{
- ast_log(LOG_ERROR, "TODO: ast_ari_get_live_recordings\n");
+void ast_ari_get_stored_recordings(struct ast_variable *headers,
+ struct ast_get_stored_recordings_args *args,
+ struct ast_ari_response *response)
+{
+ RAII_VAR(struct ao2_container *, recordings, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
+ struct ao2_iterator i;
+ void *obj;
+
+ recordings = stasis_app_stored_recording_find_all();
+
+ if (!recordings) {
+ ast_ari_response_alloc_failed(response);
+ return;
+ }
+
+ json = ast_json_array_create();
+ if (!json) {
+ ast_ari_response_alloc_failed(response);
+ return;
+ }
+
+ i = ao2_iterator_init(recordings, 0);
+ while ((obj = ao2_iterator_next(&i))) {
+ RAII_VAR(struct stasis_app_stored_recording *, recording, obj,
+ ao2_cleanup);
+
+ int r = ast_json_array_append(
+ json, stasis_app_stored_recording_to_json(recording));
+ if (r != 0) {
+ ast_ari_response_alloc_failed(response);
+ ao2_iterator_destroy(&i);
+ return;
+ }
+ }
+ ao2_iterator_destroy(&i);
+
+ ast_ari_response_ok(response, ast_json_ref(json));
+}
+
+void ast_ari_get_stored_recording(struct ast_variable *headers,
+ struct ast_get_stored_recording_args *args,
+ struct ast_ari_response *response)
+{
+ RAII_VAR(struct stasis_app_stored_recording *, recording, NULL,
+ ao2_cleanup);
+ RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
+
+ recording = stasis_app_stored_recording_find_by_name(
+ args->recording_name);
+ if (recording == NULL) {
+ ast_ari_response_error(response, 404, "Not Found",
+ "Recording not found");
+ return;
+ }
+
+ json = stasis_app_stored_recording_to_json(recording);
+ if (json == NULL) {
+ ast_ari_response_error(response, 500,
+ "Internal Server Error", "Error building response");
+ return;
+ }
+
+ ast_ari_response_ok(response, ast_json_ref(json));
+}
+
+void ast_ari_delete_stored_recording(struct ast_variable *headers,
+ struct ast_delete_stored_recording_args *args,
+ struct ast_ari_response *response)
+{
+ RAII_VAR(struct stasis_app_stored_recording *, recording, NULL,
+ ao2_cleanup);
+ int res;
+
+ recording = stasis_app_stored_recording_find_by_name(
+ args->recording_name);
+ if (recording == NULL) {
+ ast_ari_response_error(response, 404, "Not Found",
+ "Recording not found");
+ return;
+ }
+
+ res = stasis_app_stored_recording_delete(recording);
+
+ if (res != 0) {
+ switch (errno) {
+ case EACCES:
+ case EPERM:
+ ast_ari_response_error(response, 500,
+ "Internal Server Error",
+ "Delete failed");
+ break;
+ default:
+ ast_log(LOG_WARNING,
+ "Unexpected error deleting recording %s: %s\n",
+ args->recording_name, strerror(errno));
+ ast_ari_response_error(response, 500,
+ "Internal Server Error",
+ "Delete failed");
+ break;
+ }
+ return;
+ }
+
+ ast_ari_response_no_content(response);
}
void ast_ari_get_live_recording(struct ast_variable *headers,
Modified: trunk/res/ari/resource_recordings.h
URL: http://svnview.digium.com/svn/asterisk/trunk/res/ari/resource_recordings.h?view=diff&rev=397988&r1=397987&r2=397988
==============================================================================
--- trunk/res/ari/resource_recordings.h (original)
+++ trunk/res/ari/resource_recordings.h Fri Aug 30 08:28:50 2013
@@ -76,17 +76,6 @@
* \param[out] response HTTP response
*/
void ast_ari_delete_stored_recording(struct ast_variable *headers, struct ast_delete_stored_recording_args *args, struct ast_ari_response *response);
-/*! \brief Argument struct for ast_ari_get_live_recordings() */
-struct ast_get_live_recordings_args {
-};
-/*!
- * \brief List libe recordings.
- *
- * \param headers HTTP headers
- * \param args Swagger parameters
- * \param[out] response HTTP response
- */
-void ast_ari_get_live_recordings(struct ast_variable *headers, struct ast_get_live_recordings_args *args, struct ast_ari_response *response);
/*! \brief Argument struct for ast_ari_get_live_recording() */
struct ast_get_live_recording_args {
/*! \brief The name of the recording */
Modified: trunk/res/res_ari_recordings.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_ari_recordings.c?view=diff&rev=397988&r1=397987&r2=397988
==============================================================================
--- trunk/res/res_ari_recordings.c (original)
+++ trunk/res/res_ari_recordings.c Fri Aug 30 08:28:50 2013
@@ -134,6 +134,7 @@
break;
case 500: /* Internal Server Error */
case 501: /* Not Implemented */
+ case 404: /* Recording not found */
is_valid = 1;
break;
default:
@@ -190,6 +191,7 @@
break;
case 500: /* Internal Server Error */
case 501: /* Not Implemented */
+ case 404: /* Recording not found */
is_valid = 1;
break;
default:
@@ -204,55 +206,6 @@
if (!is_valid) {
ast_log(LOG_ERROR, "Response validation failed for /recordings/stored/{recordingName}\n");
- ast_ari_response_error(response, 500,
- "Internal Server Error", "Response validation failed");
- }
-#endif /* AST_DEVMODE */
-
-fin: __attribute__((unused))
- return;
-}
-/*!
- * \brief Parameter parsing callback for /recordings/live.
- * \param get_params GET parameters in the HTTP request.
- * \param path_vars Path variables extracted from the request.
- * \param headers HTTP headers.
- * \param[out] response Response to the HTTP request.
- */
-static void ast_ari_get_live_recordings_cb(
- struct ast_variable *get_params, struct ast_variable *path_vars,
- struct ast_variable *headers, struct ast_ari_response *response)
-{
- struct ast_get_live_recordings_args args = {};
-#if defined(AST_DEVMODE)
- int is_valid;
- int code;
-#endif /* AST_DEVMODE */
-
- ast_ari_get_live_recordings(headers, &args, response);
-#if defined(AST_DEVMODE)
- code = response->response_code;
-
- switch (code) {
- case 0: /* Implementation is still a stub, or the code wasn't set */
- is_valid = response->message == NULL;
- break;
- case 500: /* Internal Server Error */
- case 501: /* Not Implemented */
- is_valid = 1;
- break;
- default:
- if (200 <= code && code <= 299) {
- is_valid = ast_ari_validate_list(response->message,
- ast_ari_validate_live_recording_fn());
- } else {
- ast_log(LOG_ERROR, "Invalid error response %d for /recordings/live\n", code);
- is_valid = 0;
- }
- }
-
- if (!is_valid) {
- ast_log(LOG_ERROR, "Response validation failed for /recordings/live\n");
ast_ari_response_error(response, 500,
"Internal Server Error", "Response validation failed");
}
@@ -745,7 +698,6 @@
static struct stasis_rest_handlers recordings_live = {
.path_segment = "live",
.callbacks = {
- [AST_HTTP_GET] = ast_ari_get_live_recordings_cb,
},
.num_children = 1,
.children = { &recordings_live_recordingName, }
Modified: trunk/res/res_stasis_playback.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_stasis_playback.c?view=diff&rev=397988&r1=397987&r2=397988
==============================================================================
--- trunk/res/res_stasis_playback.c (original)
+++ trunk/res/res_stasis_playback.c Fri Aug 30 08:28:50 2013
@@ -25,6 +25,7 @@
/*** MODULEINFO
<depend type="module">res_stasis</depend>
+ <depend type="module">res_stasis_recording</depend>
<support_level>core</support_level>
***/
@@ -42,6 +43,7 @@
#include "asterisk/paths.h"
#include "asterisk/stasis_app_impl.h"
#include "asterisk/stasis_app_playback.h"
+#include "asterisk/stasis_app_recording.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/stringfields.h"
#include "asterisk/uuid.h"
@@ -279,13 +281,14 @@
file = ast_strdup(playback->media + strlen(SOUND_URI_SCHEME));
} else if (ast_begins_with(playback->media, RECORDING_URI_SCHEME)) {
/* Play recording */
+ RAII_VAR(struct stasis_app_stored_recording *, recording, NULL,
+ ao2_cleanup);
const char *relname =
playback->media + strlen(RECORDING_URI_SCHEME);
- if (relname[0] == '/') {
- file = ast_strdup(relname);
- } else {
- ast_asprintf(&file, "%s/%s",
- ast_config_AST_RECORDING_DIR, relname);
+ recording = stasis_app_stored_recording_find_by_name(relname);
+ if (recording) {
+ file = ast_strdup(stasis_app_stored_recording_get_file(
+ recording));
}
} else {
/* Play URL */
@@ -627,4 +630,4 @@
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "Stasis application playback support",
.load = load_module,
.unload = unload_module,
- .nonoptreq = "res_stasis");
+ .nonoptreq = "res_stasis,res_stasis_recording");
Modified: trunk/res/res_stasis_recording.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_stasis_recording.c?view=diff&rev=397988&r1=397987&r2=397988
==============================================================================
--- trunk/res/res_stasis_recording.c (original)
+++ trunk/res/res_stasis_recording.c Fri Aug 30 08:28:50 2013
@@ -564,7 +564,8 @@
return 0;
}
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "Stasis application recording support",
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, "Stasis application recording support",
.load = load_module,
.unload = unload_module,
- .nonoptreq = "res_stasis");
+ .nonoptreq = "res_stasis",
+ .load_pri = AST_MODPRI_APP_DEPEND);
Modified: trunk/rest-api/api-docs/recordings.json
URL: http://svnview.digium.com/svn/asterisk/trunk/rest-api/api-docs/recordings.json?view=diff&rev=397988&r1=397987&r2=397988
==============================================================================
--- trunk/rest-api/api-docs/recordings.json (original)
+++ trunk/rest-api/api-docs/recordings.json Fri Aug 30 08:28:50 2013
@@ -37,6 +37,12 @@
"allowMultiple": false,
"dataType": "string"
}
+ ],
+ "errorResponses": [
+ {
+ "code": 404,
+ "reason": "Recording not found"
+ }
]
},
{
@@ -53,19 +59,13 @@
"allowMultiple": false,
"dataType": "string"
}
- ]
- }
- ]
- },
- {
- "path": "/recordings/live",
- "description": "Recordings that are in progress",
- "operations": [
- {
- "httpMethod": "GET",
- "summary": "List libe recordings.",
- "nickname": "getLiveRecordings",
- "responseClass": "List[LiveRecording]"
+ ],
+ "errorResponses": [
+ {
+ "code": 404,
+ "reason": "Recording not found"
+ }
+ ]
}
]
},
@@ -278,22 +278,13 @@
"id": "StoredRecording",
"description": "A past recording that may be played back.",
"properties": {
- "id": {
+ "name": {
"required": true,
"type": "string"
},
- "formats": {
- "required": true,
- "type": "List[string]"
- },
- "duration_seconds": {
- "required": false,
- "type": "int"
- },
- "time": {
- "description": "Time recording was started",
- "required": false,
- "type": "Date"
+ "format": {
+ "required": true,
+ "type": "string"
}
}
},
@@ -303,7 +294,26 @@
"properties": {
"name": {
"required": true,
- "type": "string"
+ "type": "string",
+ "description": "Base name for the recording"
+ },
+ "format": {
+ "required": true,
+ "type": "string",
+ "description": "Recording format (wav, gsm, etc.)"
+ },
+ "state": {
+ "required": false,
+ "type": "string",
+ "allowableValues": {
+ "valueType": "LIST",
+ "values": [
+ "queued",
+ "playing",
+ "paused",
+ "done"
+ ]
+ }
},
"state": {
"required": true,
More information about the svn-commits
mailing list