[svn-commits] dlee: branch dlee/record r395134 - in /team/dlee/record: include/asterisk/ re...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jul 23 09:44:57 CDT 2013


Author: dlee
Date: Tue Jul 23 09:44:55 2013
New Revision: 395134

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=395134
Log:
More review fixups; make playback use the recording object

Modified:
    team/dlee/record/include/asterisk/stasis_app_recording.h
    team/dlee/record/res/res_stasis_http_channels.c
    team/dlee/record/res/res_stasis_playback.c
    team/dlee/record/res/res_stasis_recording.c
    team/dlee/record/res/stasis_http/ari_model_validators.c
    team/dlee/record/res/stasis_http/ari_model_validators.h
    team/dlee/record/res/stasis_http/resource_recordings.c
    team/dlee/record/res/stasis_recording/stored.c
    team/dlee/record/rest-api/api-docs/channels.json
    team/dlee/record/rest-api/api-docs/recordings.json

Modified: team/dlee/record/include/asterisk/stasis_app_recording.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/include/asterisk/stasis_app_recording.h?view=diff&rev=395134&r1=395133&r2=395134
==============================================================================
--- team/dlee/record/include/asterisk/stasis_app_recording.h (original)
+++ team/dlee/record/include/asterisk/stasis_app_recording.h Tue Jul 23 09:44:55 2013
@@ -33,11 +33,37 @@
 
 /*! @{ */
 
+/*! \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);
 
 /*!
@@ -53,6 +79,13 @@
 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);
 

Modified: team/dlee/record/res/res_stasis_http_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/res/res_stasis_http_channels.c?view=diff&rev=395134&r1=395133&r2=395134
==============================================================================
--- team/dlee/record/res/res_stasis_http_channels.c (original)
+++ team/dlee/record/res/res_stasis_http_channels.c Tue Jul 23 09:44:55 2013
@@ -848,7 +848,7 @@
 		break;
 	default:
 		if (200 <= code && code <= 299) {
-			is_valid = ari_validate_void(
+			is_valid = ari_validate_live_recording(
 				response->message);
 		} else {
 			ast_log(LOG_ERROR, "Invalid error response %d for /channels/{channelId}/record\n", code);

Modified: team/dlee/record/res/res_stasis_playback.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/res/res_stasis_playback.c?view=diff&rev=395134&r1=395133&r2=395134
==============================================================================
--- team/dlee/record/res/res_stasis_playback.c (original)
+++ team/dlee/record/res/res_stasis_playback.c Tue Jul 23 09:44:55 2013
@@ -25,6 +25,7 @@
 
 /*** MODULEINFO
 	<depend type="module">res_stasis</depend>
+	<depend type="module">res_stasis_recording</depend>
 	<support_level>core</support_level>
  ***/
 
@@ -40,6 +41,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"
@@ -229,13 +231,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 */
@@ -495,4 +498,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: team/dlee/record/res/res_stasis_recording.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/res/res_stasis_recording.c?view=diff&rev=395134&r1=395133&r2=395134
==============================================================================
--- team/dlee/record/res/res_stasis_recording.c (original)
+++ team/dlee/record/res/res_stasis_recording.c Tue Jul 23 09:44:55 2013
@@ -436,7 +436,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: team/dlee/record/res/stasis_http/ari_model_validators.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/res/stasis_http/ari_model_validators.c?view=diff&rev=395134&r1=395133&r2=395134
==============================================================================
--- team/dlee/record/res/stasis_http/ari_model_validators.c (original)
+++ team/dlee/record/res/stasis_http/ari_model_validators.c Tue Jul 23 09:44:55 2013
@@ -578,16 +578,36 @@
 {
 	int res = 1;
 	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_is_valid;
-			has_id = 1;
-			prop_is_valid = ari_validate_string(
-				ast_json_object_iter_value(iter));
-			if (!prop_is_valid) {
-				ast_log(LOG_ERROR, "ARI LiveRecording field id 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 = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_is_valid) {
+				ast_log(LOG_ERROR, "ARI LiveRecording 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 = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_is_valid) {
+				ast_log(LOG_ERROR, "ARI LiveRecording field name failed validation\n");
+				res = 0;
+			}
+		} else
+		if (strcmp("state", ast_json_object_iter_key(iter)) == 0) {
+			int prop_is_valid;
+			prop_is_valid = ari_validate_string(
+				ast_json_object_iter_value(iter));
+			if (!prop_is_valid) {
+				ast_log(LOG_ERROR, "ARI LiveRecording field state failed validation\n");
 				res = 0;
 			}
 		} else
@@ -599,8 +619,13 @@
 		}
 	}
 
-	if (!has_id) {
-		ast_log(LOG_ERROR, "ARI LiveRecording missing required field id\n");
+	if (!has_format) {
+		ast_log(LOG_ERROR, "ARI LiveRecording missing required field format\n");
+		res = 0;
+	}
+
+	if (!has_name) {
+		ast_log(LOG_ERROR, "ARI LiveRecording missing required field name\n");
 		res = 0;
 	}
 

Modified: team/dlee/record/res/stasis_http/ari_model_validators.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/res/stasis_http/ari_model_validators.h?view=diff&rev=395134&r1=395133&r2=395134
==============================================================================
--- team/dlee/record/res/stasis_http/ari_model_validators.h (original)
+++ team/dlee/record/res/stasis_http/ari_model_validators.h Tue Jul 23 09:44:55 2013
@@ -816,7 +816,9 @@
  * - id: string (required)
  * - technology: string (required)
  * LiveRecording
- * - id: string (required)
+ * - format: string (required)
+ * - name: string (required)
+ * - state: string
  * StoredRecording
  * - format: string (required)
  * - name: string (required)

Modified: team/dlee/record/res/stasis_http/resource_recordings.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/res/stasis_http/resource_recordings.c?view=diff&rev=395134&r1=395133&r2=395134
==============================================================================
--- team/dlee/record/res/stasis_http/resource_recordings.c (original)
+++ team/dlee/record/res/stasis_http/resource_recordings.c Tue Jul 23 09:44:55 2013
@@ -61,6 +61,7 @@
 			json, stasis_app_stored_recording_to_json(recording));
 		if (r != 0) {
 			stasis_http_response_alloc_failed(response);
+			ao2_iterator_destroy(&i);
 			return;
 		}
 	}
@@ -86,7 +87,6 @@
 	}
 
 	json = stasis_app_stored_recording_to_json(recording);
-
 	if (json == NULL) {
 		stasis_http_response_error(response, 500,
 			"Internal Server Error", "Error building response");
@@ -122,14 +122,14 @@
 				"Internal Server Error",
 				"Delete failed");
 			break;
-		case ENOENT:
-			/* Treat does not exist errors as success */
-			stasis_http_response_no_content(response);
-			break;
 		default:
 			ast_log(LOG_WARNING,
 				"Unexpected error deleting recording %s: %s\n",
 				args->recording_name, strerror(errno));
+			stasis_http_response_error(response, 500,
+				"Internal Server Error",
+				"Delete failed");
+			break;
 		}
 		return;
 	}

Modified: team/dlee/record/res/stasis_recording/stored.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/res/stasis_recording/stored.c?view=diff&rev=395134&r1=395133&r2=395134
==============================================================================
--- team/dlee/record/res/stasis_recording/stored.c (original)
+++ team/dlee/record/res/stasis_recording/stored.c Tue Jul 23 09:44:55 2013
@@ -51,6 +51,15 @@
 	struct stasis_app_stored_recording *recording = obj;
 
 	ast_string_field_free_memory(recording);
+}
+
+const char *stasis_app_stored_recording_get_file(
+	struct stasis_app_stored_recording *recording)
+{
+	if (!recording) {
+		return NULL;
+	}
+	return recording->file;
 }
 
 /*!
@@ -260,16 +269,9 @@
 	recording->format = strrchr(recording->file, '.');
 	*(recording->format++) = '\0';
 
-	/* Build recording name */
-	name = ast_str_create(255);
-	if (!name) {
-		return -1;
-	}
-	if (!ast_strlen_zero(subdir)) {
-		ast_str_append(&name, 0, "/%s", subdir);
-	}
-	ast_str_append(&name, 0, "/%s", filename);
-	ast_string_field_set(recording, name, ast_str_buffer(name));
+	/* Removed the recording dir from the file for the name. */
+	ast_string_field_set(recording, name,
+		recording->file + strlen(ast_config_AST_RECORDING_DIR) + 1);
 
 	/* Add it to the recordings container */
 	ao2_link(recordings, recording);

Modified: team/dlee/record/rest-api/api-docs/channels.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/rest-api/api-docs/channels.json?view=diff&rev=395134&r1=395133&r2=395134
==============================================================================
--- team/dlee/record/rest-api/api-docs/channels.json (original)
+++ team/dlee/record/rest-api/api-docs/channels.json Tue Jul 23 09:44:55 2013
@@ -538,7 +538,7 @@
 					"summary": "Start a recording.",
 					"notes": "Record audio from a channel. Note that this will not capture audio sent to the channel. The bridge itself has a record feature if that's what you want.",
 					"nickname": "recordChannel",
-					"responseClass": "void",
+					"responseClass": "LiveRecording",
 					"parameters": [
 						{
 							"name": "channelId",

Modified: team/dlee/record/rest-api/api-docs/recordings.json
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/rest-api/api-docs/recordings.json?view=diff&rev=395134&r1=395133&r2=395134
==============================================================================
--- team/dlee/record/rest-api/api-docs/recordings.json (original)
+++ team/dlee/record/rest-api/api-docs/recordings.json Tue Jul 23 09:44:55 2013
@@ -276,9 +276,28 @@
 			"id": "LiveRecording",
 			"description": "A recording that is in progress",
 			"properties": {
-				"id": {
+				"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"
+						]
+					}
 				}
 			}
 		}




More information about the svn-commits mailing list