[asterisk-commits] dlee: branch dlee/record r394812 - in /team/dlee/record: res/ res/stasis_http...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jul 19 15:15:03 CDT 2013


Author: dlee
Date: Fri Jul 19 15:15:01 2013
New Revision: 394812

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=394812
Log:
GET and DELETE work for stored recordings

Modified:
    team/dlee/record/res/res_stasis_http_recordings.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_recording/stored.c
    team/dlee/record/rest-api/api-docs/recordings.json

Modified: team/dlee/record/res/res_stasis_http_recordings.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/record/res/res_stasis_http_recordings.c?view=diff&rev=394812&r1=394811&r2=394812
==============================================================================
--- team/dlee/record/res/res_stasis_http_recordings.c (original)
+++ team/dlee/record/res/res_stasis_http_recordings.c Fri Jul 19 15:15:01 2013
@@ -129,6 +129,7 @@
 		break;
 	case 500: /* Internal Server Error */
 	case 501: /* Not Implemented */
+	case 404: /* Recording not found */
 		is_valid = 1;
 		break;
 	default:
@@ -183,6 +184,7 @@
 		break;
 	case 500: /* Internal Server Error */
 	case 501: /* Not Implemented */
+	case 404: /* Recording not found */
 		is_valid = 1;
 		break;
 	default:
@@ -237,6 +239,7 @@
 		break;
 	case 500: /* Internal Server Error */
 	case 501: /* Not Implemented */
+	case 404: /* Recording not found */
 		is_valid = 1;
 		break;
 	default:
@@ -291,6 +294,7 @@
 		break;
 	case 500: /* Internal Server Error */
 	case 501: /* Not Implemented */
+	case 404: /* Recording not found */
 		is_valid = 1;
 		break;
 	default:
@@ -345,6 +349,7 @@
 		break;
 	case 500: /* Internal Server Error */
 	case 501: /* Not Implemented */
+	case 404: /* Recording not found */
 		is_valid = 1;
 		break;
 	default:
@@ -399,6 +404,7 @@
 		break;
 	case 500: /* Internal Server Error */
 	case 501: /* Not Implemented */
+	case 404: /* Recording not found */
 		is_valid = 1;
 		break;
 	default:
@@ -453,6 +459,7 @@
 		break;
 	case 500: /* Internal Server Error */
 	case 501: /* Not Implemented */
+	case 404: /* Recording not found */
 		is_valid = 1;
 		break;
 	default:
@@ -507,6 +514,7 @@
 		break;
 	case 500: /* Internal Server Error */
 	case 501: /* Not Implemented */
+	case 404: /* Recording not found */
 		is_valid = 1;
 		break;
 	default:
@@ -561,6 +569,7 @@
 		break;
 	case 500: /* Internal Server Error */
 	case 501: /* Not Implemented */
+	case 404: /* Recording not found */
 		is_valid = 1;
 		break;
 	default:

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=394812&r1=394811&r2=394812
==============================================================================
--- team/dlee/record/res/stasis_http/ari_model_validators.c (original)
+++ team/dlee/record/res/stasis_http/ari_model_validators.c Fri Jul 19 15:15:01 2013
@@ -616,46 +616,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 = 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 = ari_validate_list(
-				ast_json_object_iter_value(iter),
-				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 = 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 = 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 = 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 = 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
@@ -667,13 +648,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: 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=394812&r1=394811&r2=394812
==============================================================================
--- team/dlee/record/res/stasis_http/ari_model_validators.h (original)
+++ team/dlee/record/res/stasis_http/ari_model_validators.h Fri Jul 19 15:15:01 2013
@@ -818,10 +818,8 @@
  * LiveRecording
  * - id: 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: 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=394812&r1=394811&r2=394812
==============================================================================
--- team/dlee/record/res/stasis_recording/stored.c (original)
+++ team/dlee/record/res/stasis_recording/stored.c Fri Jul 19 15:15:01 2013
@@ -42,6 +42,8 @@
 		AST_STRING_FIELD(file);	/*!< Absolute filename, without extension; for use with streamfile */
 		AST_STRING_FIELD(file_with_ext);	/*!< Absolute filename, with extension; for use with everything  */
 		);
+
+	const char *format;	/*!< Format name (i.e. filename extension) */
 };
 
 static void stored_recording_dtor(void *obj)
@@ -68,21 +70,24 @@
 	RAII_VAR(char *, relative_dir, NULL, ast_free);
 	RAII_VAR(char *, absolute_dir, NULL, ast_free);
 	RAII_VAR(char *, real_dir, NULL, free);
-	char *file_portion;
+	char *last_slash;
+	const char *file_portion;
 
 	relative_dir = ast_strdup(path);
 	if (!relative_dir) {
 		return -1;
 	}
 
-	file_portion = strrchr(relative_dir, '/');
-	if (file_portion) {
-		*file_portion++ = '\0';
+	last_slash = strrchr(relative_dir, '/');
+	if (last_slash) {
+		*last_slash = '\0';
+		file_portion = last_slash + 1;
 		ast_asprintf(&absolute_dir, "%s/%s",
 			ast_config_AST_RECORDING_DIR, relative_dir);
 	} else {
-		file_portion = relative_dir;
-		relative_dir = "";
+		/* There is no directory portion */
+		file_portion = path;
+		*relative_dir = '\0';
 		absolute_dir = ast_strdup(ast_config_AST_RECORDING_DIR);
 	}
 	if (!absolute_dir) {
@@ -152,7 +157,7 @@
 	int res;
 	struct stat file_stat;
 
-	ast_string_field_set(recording, name, name);
+	ast_string_field_init(recording, 255);
 
 	res = split_path(name, &dir, &file);
 	if (res != 0) {
@@ -168,11 +173,22 @@
 		return -1;
 	}
 
+	/* The actual name of the recording is file with the config dir
+	 * prefix removed.
+	 */
+	ast_string_field_set(recording, name,
+		recording->file + strlen(ast_config_AST_RECORDING_DIR) + 1);
+
 	file_with_ext = find_recording(dir, file);
 	if (!file_with_ext) {
 		return -1;
 	}
 	ast_string_field_set(recording, file_with_ext, file_with_ext);
+	recording->format = strrchr(recording->file_with_ext, '.');
+	if (!recording->format) {
+		return -1;
+	}
+	++(recording->format);
 
 	res = stat(file_with_ext, &file_stat);
 	if (res != 0) {
@@ -195,7 +211,9 @@
 		return NULL;
 	}
 
-	return ast_json_pack("{ s: s }", "name", recording->name);
+	return ast_json_pack("{ s: s, s: s }",
+		"name", recording->name,
+		"format", recording->format);
 }
 
 struct ao2_container *stasis_app_stored_recording_find_all(void)

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=394812&r1=394811&r2=394812
==============================================================================
--- team/dlee/record/rest-api/api-docs/recordings.json (original)
+++ team/dlee/record/rest-api/api-docs/recordings.json Fri Jul 19 15:15:01 2013
@@ -37,6 +37,12 @@
 							"allowMultiple": false,
 							"dataType": "string"
 						}
+					],
+					"errorResponses": [
+						{
+							"code": 404,
+							"reason": "Recording not found"
+						}
 					]
 				},
 				{
@@ -52,6 +58,12 @@
 							"required": true,
 							"allowMultiple": false,
 							"dataType": "string"
+						}
+					],
+					"errorResponses": [
+						{
+							"code": 404,
+							"reason": "Recording not found"
 						}
 					]
 				}
@@ -75,6 +87,12 @@
 							"allowMultiple": false,
 							"dataType": "string"
 						}
+					],
+					"errorResponses": [
+						{
+							"code": 404,
+							"reason": "Recording not found"
+						}
 					]
 				},
 				{
@@ -91,6 +109,12 @@
 							"allowMultiple": false,
 							"dataType": "string"
 						}
+					],
+					"errorResponses": [
+						{
+							"code": 404,
+							"reason": "Recording not found"
+						}
 					]
 				}
 			]
@@ -111,6 +135,12 @@
 							"required": true,
 							"allowMultiple": false,
 							"dataType": "string"
+						}
+					],
+					"errorResponses": [
+						{
+							"code": 404,
+							"reason": "Recording not found"
 						}
 					]
 				}
@@ -134,6 +164,12 @@
 							"allowMultiple": false,
 							"dataType": "string"
 						}
+					],
+					"errorResponses": [
+						{
+							"code": 404,
+							"reason": "Recording not found"
+						}
 					]
 				}
 			]
@@ -154,6 +190,12 @@
 							"required": true,
 							"allowMultiple": false,
 							"dataType": "string"
+						}
+					],
+					"errorResponses": [
+						{
+							"code": 404,
+							"reason": "Recording not found"
 						}
 					]
 				}
@@ -177,6 +219,12 @@
 							"allowMultiple": false,
 							"dataType": "string"
 						}
+					],
+					"errorResponses": [
+						{
+							"code": 404,
+							"reason": "Recording not found"
+						}
 					]
 				}
 			]
@@ -197,6 +245,12 @@
 							"required": true,
 							"allowMultiple": false,
 							"dataType": "string"
+						}
+					],
+					"errorResponses": [
+						{
+							"code": 404,
+							"reason": "Recording not found"
 						}
 					]
 				}
@@ -208,22 +262,13 @@
 			"id": "StoredRecording",
 			"description": "A past recording that may be played back.",
 			"properties": {
-				"id": {
+				"name": {
 					"required": true,
 					"type": "string"
 				},
-				"formats": {
+				"format": {
 					"required": true,
-					"type": "List[string]"
-				},
-				"duration_seconds": {
-					"required": false,
-					"type": "int"
-				},
-				"time": {
-					"description": "Time recording was started",
-					"required": false,
-					"type": "Date"
+					"type": "string"
 				}
 			}
 		},




More information about the asterisk-commits mailing list