Wed Apr 6 11:29:45 2011

Asterisk developer's documentation


func_sha1.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2006, Digium, Inc.
00005  * Copyright (C) 2006, Claude Patry
00006  *
00007  * See http://www.asterisk.org for more information about
00008  * the Asterisk project. Please do not directly contact
00009  * any of the maintainers of this project for assistance;
00010  * the project provides a web site, mailing lists and IRC
00011  * channels for your use.
00012  *
00013  * This program is free software, distributed under the terms of
00014  * the GNU General Public License Version 2. See the LICENSE file
00015  * at the top of the source tree.
00016  */
00017 
00018 /*! \file
00019  *
00020  * \brief SHA1 digest related dialplan functions
00021  * 
00022  * \author Claude Patry <cpatry@gmail.com>
00023  *
00024  * \ingroup functions
00025  */
00026 
00027 #include "asterisk.h"
00028 
00029 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 191140 $")
00030 
00031 #include "asterisk/module.h"
00032 #include "asterisk/pbx.h"
00033 
00034 /*** DOCUMENTATION
00035    <function name="SHA1" language="en_US">
00036       <synopsis>
00037          Computes a SHA1 digest.
00038       </synopsis>
00039       <syntax>
00040          <parameter name="data" required="true">
00041             <para>Input string</para>
00042          </parameter>
00043       </syntax>
00044       <description>
00045          <para>Generate a SHA1 digest via the SHA1 algorythm.</para>
00046          <para>Example:  Set(sha1hash=${SHA1(junky)})</para>
00047          <para>Sets the asterisk variable sha1hash to the string <literal>60fa5675b9303eb62f99a9cd47f9f5837d18f9a0</literal>
00048          which is known as his hash</para>   
00049       </description>
00050    </function>
00051  ***/
00052 
00053 static int sha1(struct ast_channel *chan, const char *cmd, char *data,
00054       char *buf, size_t len)
00055 {
00056    *buf = '\0';
00057 
00058    if (ast_strlen_zero(data)) {
00059       ast_log(LOG_WARNING, "Syntax: SHA1(<data>) - missing argument!\n");
00060       return -1;
00061    }
00062 
00063    if (len >= 41)
00064       ast_sha1_hash(buf, data);
00065    else {
00066       ast_log(LOG_ERROR,
00067             "Insufficient space to produce SHA1 hash result (%d < 41)\n",
00068             (int) len);
00069    }
00070 
00071    return 0;
00072 }
00073 
00074 static struct ast_custom_function sha1_function = {
00075    .name = "SHA1",
00076    .read = sha1,
00077    .read_max = 42,
00078 };
00079 
00080 static int unload_module(void)
00081 {
00082    return ast_custom_function_unregister(&sha1_function);
00083 }
00084 
00085 static int load_module(void)
00086 {
00087    return ast_custom_function_register(&sha1_function);
00088 }
00089 
00090 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "SHA-1 computation dialplan function");

Generated on Wed Apr 6 11:29:45 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7