[asterisk-commits] file: branch file/sorceryx4 r389328 - in /team/file/sorceryx4: include/asteri...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon May 20 16:00:45 CDT 2013


Author: file
Date: Mon May 20 16:00:42 2013
New Revision: 389328

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389328
Log:
Expose setting extended fields on an object and make the extended fields present in object sets.

Modified:
    team/file/sorceryx4/include/asterisk/sorcery.h
    team/file/sorceryx4/main/sorcery.c

Modified: team/file/sorceryx4/include/asterisk/sorcery.h
URL: http://svnview.digium.com/svn/asterisk/team/file/sorceryx4/include/asterisk/sorcery.h?view=diff&rev=389328&r1=389327&r2=389328
==============================================================================
--- team/file/sorceryx4/include/asterisk/sorcery.h (original)
+++ team/file/sorceryx4/include/asterisk/sorcery.h Mon May 20 16:00:42 2013
@@ -719,6 +719,18 @@
  */
 const char *ast_sorcery_object_get_extended(const void *object, const char *name);
 
+/*!
+ * \brief Set an extended field value on a sorcery object
+ *
+ * \param object Pointer to a sorcery object
+ * \param name Name of the extended field
+ * \param value Value of the extended field
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ */
+int ast_sorcery_object_set_extended(const void *object, const char *name, const char *value);
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif

Modified: team/file/sorceryx4/main/sorcery.c
URL: http://svnview.digium.com/svn/asterisk/team/file/sorceryx4/main/sorcery.c?view=diff&rev=389328&r1=389327&r2=389328
==============================================================================
--- team/file/sorceryx4/main/sorcery.c (original)
+++ team/file/sorceryx4/main/sorcery.c Mon May 20 16:00:42 2013
@@ -542,16 +542,18 @@
 
 static int sorcery_extended_config_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
 {
-	/* The + 1 below is to strip the @ from the beginning of the name */
-	struct ast_variable *extended = ast_variable_new(var->name + 1, var->value, "");
+	return ast_sorcery_object_set_extended(obj, var->name, var->value);
+}
+
+static int sorcery_extended_fields_handler(const void *obj, struct ast_variable **fields)
+{
 	const struct ast_sorcery_object_details *details = obj;
 
-	if (!extended) {
-		return -1;
-	}
-
-	extended->next = details->object->extended;
-	details->object->extended = extended;
+	if (details->object->extended) {
+		*fields = ast_variables_dup(details->object->extended);
+	} else {
+		*fields = NULL;
+	}
 
 	return 0;
 }
@@ -578,7 +580,7 @@
 		return -1;
 	}
 
-	if (ast_sorcery_object_fields_register(sorcery, type, "^@", sorcery_extended_config_handler, NULL)) {
+	if (ast_sorcery_object_fields_register(sorcery, type, "^@", sorcery_extended_config_handler, sorcery_extended_fields_handler)) {
 		return -1;
 	}
 
@@ -851,7 +853,7 @@
 			continue;
 		}
 
-		if (!res) {
+		if (!res && tmp) {
 			tmp->next = fields;
 			fields = tmp;
 		}
@@ -1446,12 +1448,28 @@
 	struct ast_variable *field;
 
 	for (field = details->object->extended; field; field = field->next) {
-		if (!strcmp(field->name, name)) {
+		if (!strcmp(field->name + 1, name)) {
 			return field->value;
 		}
 	}
 
 	return NULL;
+}
+
+int ast_sorcery_object_set_extended(const void *object, const char *name, const char *value)
+{
+	struct ast_variable *extended;
+	const struct ast_sorcery_object_details *details = object;
+
+	if (ast_sorcery_object_get_extended(object, name) || 
+		!(extended = ast_variable_new(name, value, ""))) {
+		return -1;
+	}
+
+	extended->next = details->object->extended;
+	details->object->extended = extended;
+
+	return 0;
 }
 
 int ast_sorcery_observer_add(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks)




More information about the asterisk-commits mailing list