[Asterisk-cvs] asterisk pbx.c,1.235,1.236 utils.c,1.41,1.42

kpfleming at lists.digium.com kpfleming at lists.digium.com
Tue May 3 23:58:30 CDT 2005


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv11476

Modified Files:
	pbx.c utils.c 
Log Message:
add MD5 and CHECK_MD5 functions, deprecate MD5 and MD5Check apps (bug #4123)


Index: pbx.c
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx.c,v
retrieving revision 1.235
retrieving revision 1.236
diff -u -d -r1.235 -r1.236
--- pbx.c	1 May 2005 23:09:28 -0000	1.235
+++ pbx.c	4 May 2005 04:05:34 -0000	1.236
@@ -1370,6 +1370,51 @@
 	return ret;
 }
 
+static char *builtin_function_md5(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) 
+{
+	char md5[33];
+
+	if (!data || ast_strlen_zero(data)) {
+		ast_log(LOG_WARNING, "Syntax: MD5(<data>) - missing argument!\n");
+		return NULL;
+	}
+
+	ast_md5_hash(md5, data);
+	ast_copy_string(buf, md5, len);
+	
+	return buf;
+}
+
+static char *builtin_function_checkmd5(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) 
+{
+	int argc;
+	char *argv[2];
+	char *args;
+	char newmd5[33];
+
+	if (!data || ast_strlen_zero(data)) {
+		ast_log(LOG_WARNING, "Syntax: CHECK_MD5(<digest>,<data>) - missing argument!\n");
+		return NULL;
+	}
+
+	args = ast_strdupa(data);	
+	argc = ast_separate_app_args(args, '|', argv, sizeof(argv) / sizeof(argv[0]));
+
+	if (argc < 2) {
+		ast_log(LOG_WARNING, "Syntax: CHECK_MD5(<digest>,<data>) - missing argument!\n");
+		return NULL;
+	}
+
+	ast_md5_hash(newmd5, argv[1]);
+
+	if (!strcasecmp(newmd5, argv[0]))	/* they match */
+		ast_copy_string(buf, "1", len);
+	else
+		ast_copy_string(buf, "0", len);
+	
+	return buf;
+}
+
 static void pbx_substitute_variables_helper_full(struct ast_channel *c, const char *cp1, char *cp2, int count, struct varshead *headp)
 {
 	char *cp4;
@@ -3554,6 +3599,21 @@
 	.write = builtin_function_cdr_write,
 };
 
+static struct ast_custom_function_obj md5_function = {
+	.name = "MD5",
+	.desc = "Computes an MD5 digest",
+	.syntax = "MD5(<data>)",
+	.read = builtin_function_md5,
+	.write = NULL,
+};
+
+static struct ast_custom_function_obj checkmd5_function = {
+	.name = "CHECK_MD5",
+	.desc = "Checks an MD5 digest. Returns 1 on a match, 0 otherwise",
+	.syntax = "CHECK_MD5(<digest>,<data>)",
+	.read = builtin_function_checkmd5,
+	.write = NULL,
+};
 
 /*
  * CLI entries for upper commands ...
@@ -6000,6 +6060,8 @@
 	ast_custom_function_register(&env_function);
 	ast_custom_function_register(&len_function);
 	ast_custom_function_register(&cdr_function);
+	ast_custom_function_register(&md5_function);
+	ast_custom_function_register(&checkmd5_function);
 
 	/* Register builtin applications */
 	for (x=0; x<sizeof(builtins) / sizeof(struct pbx_builtin); x++) {

Index: utils.c
===================================================================
RCS file: /usr/cvsroot/asterisk/utils.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- utils.c	3 May 2005 23:51:20 -0000	1.41
+++ utils.c	4 May 2005 04:05:34 -0000	1.42
@@ -252,16 +252,17 @@
 /*--- ast_md5_hash: Produce 16 char MD5 hash of value. ---*/
 void ast_md5_hash(char *output, char *input)
 {
-		struct MD5Context md5;
-		unsigned char digest[16];
-		char *ptr;
-		int x;
-		MD5Init(&md5);
-		MD5Update(&md5, input, strlen(input));
-		MD5Final(digest, &md5);
-		ptr = output;
-		for (x=0;x<16;x++)
-			ptr += sprintf(ptr, "%2.2x", digest[x]);
+	struct MD5Context md5;
+	unsigned char digest[16];
+	char *ptr;
+	int x;
+
+	MD5Init(&md5);
+	MD5Update(&md5, input, strlen(input));
+	MD5Final(digest, &md5);
+	ptr = output;
+	for (x=0; x<16; x++)
+		ptr += sprintf(ptr, "%2.2x", digest[x]);
 }
 
 int ast_base64decode(unsigned char *dst, char *src, int max)




More information about the svn-commits mailing list