[asterisk-commits] qwell: branch qwell/ari_channel_variables r392726 - in /team/qwell/ari_channe...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jun 24 11:53:43 CDT 2013


Author: qwell
Date: Mon Jun 24 11:53:41 2013
New Revision: 392726

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392726
Log:
Implement global variables.  No functions on get, because, wat?

Modified:
    team/qwell/ari_channel_variables/res/res_stasis_http_asterisk.c
    team/qwell/ari_channel_variables/res/stasis_http/resource_asterisk.c
    team/qwell/ari_channel_variables/res/stasis_http/resource_asterisk.h
    team/qwell/ari_channel_variables/res/stasis_json/resource_asterisk.h
    team/qwell/ari_channel_variables/rest-api/api-docs/asterisk.json
    team/qwell/ari_channel_variables/rest-api/api-docs/channels.json

Modified: team/qwell/ari_channel_variables/res/res_stasis_http_asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_variables/res/res_stasis_http_asterisk.c?view=diff&rev=392726&r1=392725&r2=392726
==============================================================================
--- team/qwell/ari_channel_variables/res/res_stasis_http_asterisk.c (original)
+++ team/qwell/ari_channel_variables/res/res_stasis_http_asterisk.c Mon Jun 24 11:53:41 2013
@@ -67,6 +67,53 @@
 	}
 	stasis_http_get_asterisk_info(headers, &args, response);
 }
+/*!
+ * \brief Parameter parsing callback for /asterisk/variable.
+ * \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 stasis_http_get_global_var_cb(
+    struct ast_variable *get_params, struct ast_variable *path_vars,
+    struct ast_variable *headers, struct stasis_http_response *response)
+{
+	struct ast_get_global_var_args args = {};
+	struct ast_variable *i;
+
+	for (i = get_params; i; i = i->next) {
+		if (strcmp(i->name, "variable") == 0) {
+			args.variable = (i->value);
+		} else
+		{}
+	}
+	stasis_http_get_global_var(headers, &args, response);
+}
+/*!
+ * \brief Parameter parsing callback for /asterisk/variable.
+ * \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 stasis_http_set_global_var_cb(
+    struct ast_variable *get_params, struct ast_variable *path_vars,
+    struct ast_variable *headers, struct stasis_http_response *response)
+{
+	struct ast_set_global_var_args args = {};
+	struct ast_variable *i;
+
+	for (i = get_params; i; i = i->next) {
+		if (strcmp(i->name, "variable") == 0) {
+			args.variable = (i->value);
+		} else
+		if (strcmp(i->name, "value") == 0) {
+			args.value = (i->value);
+		} else
+		{}
+	}
+	stasis_http_set_global_var(headers, &args, response);
+}
 
 /*! \brief REST handler for /api-docs/asterisk.{format} */
 static struct stasis_rest_handlers asterisk_info = {
@@ -78,12 +125,22 @@
 	.children = {  }
 };
 /*! \brief REST handler for /api-docs/asterisk.{format} */
+static struct stasis_rest_handlers asterisk_variable = {
+	.path_segment = "variable",
+	.callbacks = {
+		[AST_HTTP_GET] = stasis_http_get_global_var_cb,
+		[AST_HTTP_POST] = stasis_http_set_global_var_cb,
+	},
+	.num_children = 0,
+	.children = {  }
+};
+/*! \brief REST handler for /api-docs/asterisk.{format} */
 static struct stasis_rest_handlers asterisk = {
 	.path_segment = "asterisk",
 	.callbacks = {
 	},
-	.num_children = 1,
-	.children = { &asterisk_info, }
+	.num_children = 2,
+	.children = { &asterisk_info,&asterisk_variable, }
 };
 
 static int load_module(void)

Modified: team/qwell/ari_channel_variables/res/stasis_http/resource_asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_variables/res/stasis_http/resource_asterisk.c?view=diff&rev=392726&r1=392725&r2=392726
==============================================================================
--- team/qwell/ari_channel_variables/res/stasis_http/resource_asterisk.c (original)
+++ team/qwell/ari_channel_variables/res/stasis_http/resource_asterisk.c Mon Jun 24 11:53:41 2013
@@ -32,8 +32,40 @@
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "resource_asterisk.h"
+#include "asterisk/pbx.h"
 
 void stasis_http_get_asterisk_info(struct ast_variable *headers, struct ast_get_asterisk_info_args *args, struct stasis_http_response *response)
 {
 	ast_log(LOG_ERROR, "TODO: stasis_http_get_asterisk_info\n");
 }
+
+void stasis_http_get_global_var(struct ast_variable *headers, struct ast_get_global_var_args *args, struct stasis_http_response *response)
+{
+	RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
+	const char *value;
+
+	ast_assert(response != NULL);
+
+	value = pbx_builtin_getvar_helper(NULL, args->variable);
+
+	if (!(json = ast_json_pack("{s: s}", "value", S_OR(value, "")))) {
+		stasis_http_response_alloc_failed(response);
+		return;
+	}
+
+	stasis_http_response_ok(response, ast_json_ref(json));
+}
+
+void stasis_http_set_global_var(struct ast_variable *headers, struct ast_set_global_var_args *args, struct stasis_http_response *response)
+{
+	ast_assert(response != NULL);
+
+	if (pbx_builtin_setvar_helper(NULL, args->variable, args->value)) {
+		stasis_http_response_error(
+			response, 500, "Internal server error",
+			"Failed to set variable");
+		return;
+	}
+
+	stasis_http_response_no_content(response);
+}

Modified: team/qwell/ari_channel_variables/res/stasis_http/resource_asterisk.h
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_variables/res/stasis_http/resource_asterisk.h?view=diff&rev=392726&r1=392725&r2=392726
==============================================================================
--- team/qwell/ari_channel_variables/res/stasis_http/resource_asterisk.h (original)
+++ team/qwell/ari_channel_variables/res/stasis_http/resource_asterisk.h Mon Jun 24 11:53:41 2013
@@ -52,5 +52,33 @@
  * \param[out] response HTTP response
  */
 void stasis_http_get_asterisk_info(struct ast_variable *headers, struct ast_get_asterisk_info_args *args, struct stasis_http_response *response);
+/*! \brief Argument struct for stasis_http_get_global_var() */
+struct ast_get_global_var_args {
+	/*! \brief The variable to get */
+	const char *variable;
+};
+/*!
+ * \brief Get the value of a global variable.
+ *
+ * \param headers HTTP headers
+ * \param args Swagger parameters
+ * \param[out] response HTTP response
+ */
+void stasis_http_get_global_var(struct ast_variable *headers, struct ast_get_global_var_args *args, struct stasis_http_response *response);
+/*! \brief Argument struct for stasis_http_set_global_var() */
+struct ast_set_global_var_args {
+	/*! \brief The variable to set */
+	const char *variable;
+	/*! \brief The value to set the variable to */
+	const char *value;
+};
+/*!
+ * \brief Set the value of a global variable.
+ *
+ * \param headers HTTP headers
+ * \param args Swagger parameters
+ * \param[out] response HTTP response
+ */
+void stasis_http_set_global_var(struct ast_variable *headers, struct ast_set_global_var_args *args, struct stasis_http_response *response);
 
 #endif /* _ASTERISK_RESOURCE_ASTERISK_H */

Modified: team/qwell/ari_channel_variables/res/stasis_json/resource_asterisk.h
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_variables/res/stasis_json/resource_asterisk.h?view=diff&rev=392726&r1=392725&r2=392726
==============================================================================
--- team/qwell/ari_channel_variables/res/stasis_json/resource_asterisk.h (original)
+++ team/qwell/ari_channel_variables/res/stasis_json/resource_asterisk.h Mon Jun 24 11:53:41 2013
@@ -40,6 +40,8 @@
 /*
  * JSON models
  *
+ * Variable
+ * - variable: string (required)
  * AsteriskInfo
  */
 

Modified: team/qwell/ari_channel_variables/rest-api/api-docs/asterisk.json
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_variables/rest-api/api-docs/asterisk.json?view=diff&rev=392726&r1=392725&r2=392726
==============================================================================
--- team/qwell/ari_channel_variables/rest-api/api-docs/asterisk.json (original)
+++ team/qwell/ari_channel_variables/rest-api/api-docs/asterisk.json Mon Jun 24 11:53:41 2013
@@ -36,12 +36,68 @@
 					]
 				}
 			]
+		},
+		{
+			"path": "/asterisk/variable",
+			"description": "Global variables",
+			"operations": [
+				{
+					"httpMethod": "GET",
+					"summary": "Get the value of a global variable.",
+					"nickname": "getGlobalVar",
+					"responseClass": "Variable",
+					"parameters": [
+						{
+							"name": "variable",
+							"description": "The variable to get",
+							"paramType": "query",
+							"required": true,
+							"allowMultiple": false,
+							"dataType": "string"
+						}
+					]
+				},
+				{
+					"httpMethod": "POST",
+					"summary": "Set the value of a global variable.",
+					"nickname": "setGlobalVar",
+					"responseClass": "void",
+					"parameters": [
+						{
+							"name": "variable",
+							"description": "The variable to set",
+							"paramType": "query",
+							"required": true,
+							"allowMultiple": false,
+							"dataType": "string"
+						},
+						{
+							"name": "value",
+							"description": "The value to set the variable to",
+							"paramType": "query",
+							"required": false,
+							"allowMultiple": false,
+							"dataType": "string"
+						}
+					]
+				}
+			]
 		}
 	],
 	"models": {
 		"AsteriskInfo": {
 			"id": "AsteriskInfo",
 			"properties": {}
+		},
+		"Variable": {
+			"id": "Variable",
+			"properties": {
+				"variable": {
+					"required": true,
+					"type": "string",
+					"description": "The value of the variable requested"
+				}
+			}
 		}
 	}
 }

Modified: team/qwell/ari_channel_variables/rest-api/api-docs/channels.json
URL: http://svnview.digium.com/svn/asterisk/team/qwell/ari_channel_variables/rest-api/api-docs/channels.json?view=diff&rev=392726&r1=392725&r2=392726
==============================================================================
--- team/qwell/ari_channel_variables/rest-api/api-docs/channels.json (original)
+++ team/qwell/ari_channel_variables/rest-api/api-docs/channels.json Mon Jun 24 11:53:41 2013
@@ -593,7 +593,7 @@
 					"httpMethod": "GET",
 					"summary": "Get the value of a channel variable.",
 					"nickname": "getChannelVar",
-					"responseClass": "Variable",
+					"responseClass": "ChannelVariable",
 					"parameters": [
 						{
 							"name": "channelId",




More information about the asterisk-commits mailing list