[asterisk-commits] russell: branch russell/dtls r206090 - /team/russell/dtls/main/dtls.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Jul 12 21:03:25 CDT 2009


Author: russell
Date: Sun Jul 12 21:03:21 2009
New Revision: 206090

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=206090
Log:
Convert ast_dtls_config to stringfields.

Modified:
    team/russell/dtls/main/dtls.c

Modified: team/russell/dtls/main/dtls.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/russell/dtls/main/dtls.c?view=diff&rev=206090&r1=206089&r2=206090
==============================================================================
--- team/russell/dtls/main/dtls.c (original)
+++ team/russell/dtls/main/dtls.c Sun Jul 12 21:03:21 2009
@@ -139,24 +139,22 @@
 #include "asterisk/io.h"
 #include "asterisk/netsock.h"
 #include "asterisk/linkedlists.h"
+#include "asterisk/stringfields.h"
 #include "asterisk/dtls.h"
 
 /*!
  * \brief DTLS service configuration
- *
- * \note I suppose this could use stringfields.  I haven't done it yet since the
- *       benefits will be minor since there will be very few instances of this
- *       object.  It's not like "sip_peer" or something where there may be
- *       thousands.
  */
 struct ast_dtls_config {
-	char bind_addr[32];
+	AST_DECLARE_STRING_FIELDS(
+		AST_STRING_FIELD(bind_addr);
+		AST_STRING_FIELD(ca_cert);
+		AST_STRING_FIELD(ca_path);
+		AST_STRING_FIELD(private_key);
+		AST_STRING_FIELD(server_cert);
+		AST_STRING_FIELD(dh_params);
+	);
 	uint16_t bind_port;
-	char ca_cert[PATH_MAX];
-	char ca_path[PATH_MAX];
-	char private_key[PATH_MAX];
-	char server_cert[PATH_MAX];
-	char dh_params[PATH_MAX];
 	unsigned char enabled;
 };
 
@@ -959,12 +957,25 @@
 
 static void config_destructor(void *obj)
 {
-	/* Well, that was easy. */
+	struct ast_dtls_config *config = obj;
+
+	ast_string_field_free_memory(config);
 }
 
 struct ast_dtls_config *ast_dtls_config_alloc(void)
 {
-	return ao2_alloc(sizeof(struct ast_dtls_config), config_destructor);
+	struct ast_dtls_config *config;
+
+	if (!(config = ao2_alloc(sizeof(struct ast_dtls_config), config_destructor))) {
+		return NULL;
+	}
+
+	if (ast_string_field_init(config, 128)) {
+		config = ast_dtls_config_unref(config);
+		return NULL;
+	}
+
+	return config;
 }
 
 unsigned int ast_dtls_config_get_enabled(const struct ast_dtls_config *config)
@@ -979,14 +990,14 @@
 
 	CV_START(var, val);
 
-	CV_STR("dtlsbindaddr", config->bind_addr);
+	CV_STRFIELD("dtlsbindaddr", config, bind_addr);
 	CV_UINT("dtlsbindport", config->bind_port);
 	CV_BOOL("dtlsenable", config->enabled);
-	CV_STR("dtlscafile", config->ca_cert);
-	CV_STR("dtlscapath", config->ca_path);
-	CV_STR("dtlscertfile", config->server_cert);
-	CV_STR("dtlsprivatekey", config->private_key);
-	CV_STR("dtlsdhfile", config->dh_params);
+	CV_STRFIELD("dtlscafile", config, ca_cert);
+	CV_STRFIELD("dtlscapath", config, ca_path);
+	CV_STRFIELD("dtlscertfile", config, server_cert);
+	CV_STRFIELD("dtlsprivatekey", config, private_key);
+	CV_STRFIELD("dtlsdhfile", config, dh_params);
 
 	res = -1;
 




More information about the asterisk-commits mailing list