Fri Sep 29 11:12:30 2006

Asterisk developer's documentation


func_md5.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2005, Digium, Inc.
00005  * Copyright (C) 2005, Olle E. Johansson, Edvina.net
00006  * Copyright (C) 2005, Russell Bryant <russelb@clemson.edu> 
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief MD5 digest related dialplan functions
00022  * 
00023  */
00024 
00025 #include <stdlib.h>
00026 #include <string.h>
00027 #include <sys/types.h>
00028 
00029 #include "asterisk.h"
00030 
00031 /* ASTERISK_FILE_VERSION(__FILE__, "$Revision: 7221 $") */
00032 
00033 #include "asterisk/channel.h"
00034 #include "asterisk/pbx.h"
00035 #include "asterisk/logger.h"
00036 #include "asterisk/utils.h"
00037 #include "asterisk/app.h"
00038 
00039 static char *builtin_function_md5(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) 
00040 {
00041    char md5[33];
00042 
00043    if (ast_strlen_zero(data)) {
00044       ast_log(LOG_WARNING, "Syntax: MD5(<data>) - missing argument!\n");
00045       return NULL;
00046    }
00047 
00048    ast_md5_hash(md5, data);
00049    ast_copy_string(buf, md5, len);
00050    
00051    return buf;
00052 }
00053 
00054 static char *builtin_function_checkmd5(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) 
00055 {
00056    int argc;
00057    char *argv[2];
00058    char *args;
00059    char newmd5[33];
00060 
00061    if (!data || ast_strlen_zero(data)) {
00062       ast_log(LOG_WARNING, "Syntax: CHECK_MD5(<digest>,<data>) - missing argument!\n");
00063       return NULL;
00064    }
00065 
00066    args = ast_strdupa(data);  
00067    argc = ast_app_separate_args(args, '|', argv, sizeof(argv) / sizeof(argv[0]));
00068 
00069    if (argc < 2) {
00070       ast_log(LOG_WARNING, "Syntax: CHECK_MD5(<digest>,<data>) - missing argument!\n");
00071       return NULL;
00072    }
00073 
00074    ast_md5_hash(newmd5, argv[1]);
00075 
00076    if (!strcasecmp(newmd5, argv[0]))   /* they match */
00077       ast_copy_string(buf, "1", len);
00078    else
00079       ast_copy_string(buf, "0", len);
00080    
00081    return buf;
00082 }
00083 
00084 #ifndef BUILTIN_FUNC
00085 static
00086 #endif
00087 struct ast_custom_function md5_function = {
00088    .name = "MD5",
00089    .synopsis = "Computes an MD5 digest",
00090    .syntax = "MD5(<data>)",
00091    .read = builtin_function_md5,
00092 };
00093 
00094 #ifndef BUILTIN_FUNC
00095 static
00096 #endif
00097 struct ast_custom_function checkmd5_function = {
00098    .name = "CHECK_MD5",
00099    .synopsis = "Checks an MD5 digest",
00100    .desc = "Returns 1 on a match, 0 otherwise\n",
00101    .syntax = "CHECK_MD5(<digest>,<data>)",
00102    .read = builtin_function_checkmd5,
00103 };

Generated on Fri Sep 29 11:12:30 2006 for Asterisk - the Open Source PBX by  doxygen 1.4.7