#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/utils.h"
#include "asterisk/options.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/lock.h"
#include "asterisk/app.h"
Include dependency graph for app_md5.c:
Go to the source code of this file.
Functions | |
char * | description (void) |
Provides a description of the module. | |
char * | key () |
Returns the ASTERISK_GPL_KEY. | |
int | load_module (void) |
Initialize the module. | |
static int | md5_exec (struct ast_channel *chan, void *data) |
static int | md5check_exec (struct ast_channel *chan, void *data) |
int | unload_module (void) |
Cleanup all module structures, sockets, etc. | |
int | usecount (void) |
Provides a usecount. | |
Variables | |
static char * | app_md5 = "MD5" |
static char * | app_md5check = "MD5Check" |
static char * | desc_md5 = "Calculate MD5 checksum" |
static char * | desc_md5check = "Check MD5 checksum" |
LOCAL_USER_DECL | |
STANDARD_LOCAL_USER | |
static char * | synopsis_md5 |
static char * | synopsis_md5check |
static char * | tdesc_md5 = "MD5 checksum applications" |
Definition in file app_md5.c.
|
Provides a description of the module.
Definition at line 190 of file app_md5.c. 00191 { 00192 return tdesc_md5; 00193 }
|
|
Returns the ASTERISK_GPL_KEY. This returns the ASTERISK_GPL_KEY, signifiying that you agree to the terms of the GPL stated in the ASTERISK_GPL_KEY. Your module will not load if it does not return the EXACT message:
char *key(void) { return ASTERISK_GPL_KEY; }
Definition at line 202 of file app_md5.c. References ASTERISK_GPL_KEY. 00203 { 00204 return ASTERISK_GPL_KEY; 00205 }
|
|
Initialize the module. Initialize the Agents module. This function is being called by Asterisk when loading the module. Among other thing it registers applications, cli commands and reads the cofiguration file.
Definition at line 180 of file app_md5.c. References ast_register_application(), md5_exec(), and md5check_exec(). 00181 { 00182 int res; 00183 00184 res = ast_register_application(app_md5check, md5check_exec, desc_md5check, synopsis_md5check); 00185 res |= ast_register_application(app_md5, md5_exec, desc_md5, synopsis_md5); 00186 00187 return res; 00188 }
|
|
Definition at line 69 of file app_md5.c. References ast_log(), ast_md5_hash(), ast_strdupa, ast_strlen_zero(), localuser::chan, dep_warning, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_WARNING, pbx_builtin_setvar_helper(), and strsep(). Referenced by load_module(). 00070 { 00071 int res=0; 00072 struct localuser *u; 00073 char *varname= NULL; /* Variable to set */ 00074 char *string = NULL; /* String to calculate on */ 00075 char retvar[50]; /* Return value */ 00076 static int dep_warning = 0; 00077 00078 if (!dep_warning) { 00079 ast_log(LOG_WARNING, "This application has been deprecated, please use the MD5 function instead.\n"); 00080 dep_warning = 1; 00081 } 00082 00083 if (ast_strlen_zero(data)) { 00084 ast_log(LOG_WARNING, "Syntax: md5(<varname>=<string>) - missing argument!\n"); 00085 return -1; 00086 } 00087 00088 LOCAL_USER_ADD(u); 00089 00090 memset(retvar,0, sizeof(retvar)); 00091 string = ast_strdupa(data); 00092 varname = strsep(&string,"="); 00093 if (ast_strlen_zero(varname)) { 00094 ast_log(LOG_WARNING, "Syntax: md5(<varname>=<string>) - missing argument!\n"); 00095 LOCAL_USER_REMOVE(u); 00096 return -1; 00097 } 00098 ast_md5_hash(retvar, string); 00099 pbx_builtin_setvar_helper(chan, varname, retvar); 00100 LOCAL_USER_REMOVE(u); 00101 return res; 00102 }
|
|
Definition at line 106 of file app_md5.c. References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_goto_if_exists(), ast_log(), ast_md5_hash(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), localuser::chan, ast_channel::context, dep_warning, LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_DEBUG, LOG_WARNING, option_debug, option_priority_jumping, and pbx_builtin_setvar_helper(). Referenced by load_module(). 00107 { 00108 int res=0; 00109 struct localuser *u; 00110 char *string = NULL; /* String to calculate on */ 00111 char newhash[50]; /* Return value */ 00112 static int dep_warning = 0; 00113 int priority_jump = 0; 00114 AST_DECLARE_APP_ARGS(args, 00115 AST_APP_ARG(md5hash); 00116 AST_APP_ARG(string); 00117 AST_APP_ARG(options); 00118 ); 00119 00120 if (!dep_warning) { 00121 ast_log(LOG_WARNING, "This application has been deprecated, please use the CHECK_MD5 function instead.\n"); 00122 dep_warning = 1; 00123 } 00124 00125 LOCAL_USER_ADD(u); 00126 00127 if (!(string = ast_strdupa(data))) { 00128 ast_log(LOG_WARNING, "Memory Error!\n"); 00129 LOCAL_USER_REMOVE(u); 00130 return -1; 00131 } 00132 00133 AST_STANDARD_APP_ARGS(args, string); 00134 00135 if (args.options) { 00136 if (strchr(args.options, 'j')) 00137 priority_jump = 1; 00138 } 00139 00140 if (ast_strlen_zero(args.md5hash) || ast_strlen_zero(args.string)) { 00141 ast_log(LOG_WARNING, "Syntax: MD5Check(<md5hash>|<string>[|options]) - missing argument!\n"); 00142 LOCAL_USER_REMOVE(u); 00143 return -1; 00144 } 00145 00146 memset(newhash,0, sizeof(newhash)); 00147 00148 ast_md5_hash(newhash, args.string); 00149 if (!strcmp(newhash, args.md5hash)) { /* Verification ok */ 00150 if (option_debug > 2) 00151 ast_log(LOG_DEBUG, "MD5 verified ok: %s -- %s\n", args.md5hash, args.string); 00152 pbx_builtin_setvar_helper(chan, "CHECKMD5STATUS", "MATCH"); 00153 LOCAL_USER_REMOVE(u); 00154 return 0; 00155 } 00156 if (option_debug > 2) 00157 ast_log(LOG_DEBUG, "ERROR: MD5 not verified: %s -- %s\n", args.md5hash, args.string); 00158 pbx_builtin_setvar_helper(chan, "CHECKMD5STATUS", "NOMATCH"); 00159 if (priority_jump || option_priority_jumping) { 00160 if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) 00161 if (option_debug > 2) 00162 ast_log(LOG_DEBUG, "Can't jump to exten+101 (e%s,p%d), sorry\n", chan->exten,chan->priority+101); 00163 } 00164 LOCAL_USER_REMOVE(u); 00165 return res; 00166 }
|
|
Cleanup all module structures, sockets, etc. This is called at exit. Any registrations and memory allocations need to be unregistered and free'd here. Nothing else will do these for you (until exit).
Definition at line 168 of file app_md5.c. References ast_unregister_application(), and STANDARD_HANGUP_LOCALUSERS. 00169 { 00170 int res; 00171 00172 res = ast_unregister_application(app_md5); 00173 res |= ast_unregister_application(app_md5check); 00174 00175 STANDARD_HANGUP_LOCALUSERS; 00176 00177 return res; 00178 }
|
|
Provides a usecount. This function will be called by various parts of asterisk. Basically, all it has to do is to return a usecount when called. You will need to maintain your usecount within the module somewhere. The usecount should be how many channels provided by this module are in use.
Definition at line 195 of file app_md5.c. References STANDARD_USECOUNT. 00196 { 00197 int res; 00198 STANDARD_USECOUNT(res); 00199 return res; 00200 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Initial value: " MD5(<var>=<string>): Calculates a MD5 checksum on <string>.\n" "Returns hash value in a channel variable. \n" |
|
|
|
|