00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "asterisk.h"
00030
00031 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
00032
00033 #include <stdio.h>
00034 #include <stdlib.h>
00035 #include <string.h>
00036 #include <sys/types.h>
00037
00038 #include "asterisk/module.h"
00039 #include "asterisk/channel.h"
00040 #include "asterisk/pbx.h"
00041 #include "asterisk/logger.h"
00042 #include "asterisk/utils.h"
00043 #include "asterisk/app.h"
00044
00045 static int md5(struct ast_channel *chan, char *cmd, char *data,
00046 char *buf, size_t len)
00047 {
00048 if (ast_strlen_zero(data)) {
00049 ast_log(LOG_WARNING, "Syntax: MD5(<data>) - missing argument!\n");
00050 return -1;
00051 }
00052
00053 ast_md5_hash(buf, data);
00054 buf[32] = '\0';
00055
00056 return 0;
00057 }
00058
00059 static int checkmd5(struct ast_channel *chan, char *cmd, char *parse,
00060 char *buf, size_t len)
00061 {
00062 char newmd5[33];
00063 static int deprecated = 0;
00064 AST_DECLARE_APP_ARGS(args, AST_APP_ARG(digest); AST_APP_ARG(data););
00065
00066 if (ast_strlen_zero(parse)) {
00067 ast_log(LOG_WARNING,
00068 "Syntax: CHECK_MD5(<digest>,<data>) - missing argument!\n");
00069 return -1;
00070 }
00071
00072 AST_STANDARD_APP_ARGS(args, parse);
00073
00074 if (args.argc < 2) {
00075 ast_log(LOG_WARNING,
00076 "Syntax: CHECK_MD5(<digest>,<data>) - missing argument!\n");
00077 return -1;
00078 }
00079
00080 if (!deprecated) {
00081 deprecated = 1;
00082 ast_log(LOG_WARNING, "CHECK_MD5() is deprecated in Asterisk 1.4 and later.\n");
00083 }
00084
00085 ast_md5_hash(newmd5, args.data);
00086
00087 if (!strcasecmp(newmd5, args.digest))
00088 ast_copy_string(buf, "1", len);
00089 else
00090 ast_copy_string(buf, "0", len);
00091
00092 return 0;
00093 }
00094
00095 static struct ast_custom_function md5_function = {
00096 .name = "MD5",
00097 .synopsis = "Computes an MD5 digest",
00098 .syntax = "MD5(<data>)",
00099 .read = md5,
00100 };
00101
00102 static struct ast_custom_function checkmd5_function = {
00103 .name = "CHECK_MD5",
00104 .synopsis = "Checks an MD5 digest",
00105 .desc = "Returns 1 on a match, 0 otherwise\n",
00106 .syntax = "CHECK_MD5(<digest>,<data>)",
00107 .read = checkmd5,
00108 };
00109
00110 static int unload_module(void)
00111 {
00112 return ast_custom_function_unregister(&md5_function) |
00113 ast_custom_function_unregister(&checkmd5_function);
00114 }
00115
00116 static int load_module(void)
00117 {
00118 return ast_custom_function_register(&md5_function) |
00119 ast_custom_function_register(&checkmd5_function);
00120 }
00121
00122 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "MD5 digest dialplan functions");