#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sched.h>
#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/logger.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
#include "asterisk/localtime.h"
Include dependency graph for func_array.c:
Go to the source code of this file.
Functions | |
static void | array (struct ast_channel *chan, char *cmd, char *var, const char *value) |
AST_MUTEX_DEFINE_STATIC (local_lock) | |
char * | description (void) |
Provides a description of the module. | |
char * | key (void) |
Returns the ASTERISK_GPL_KEY. | |
int | load_module (void) |
Initialize the module. | |
static unsigned int | trunk_app_separate_args (char *buf, char delim, char **array, int arraylen) |
int | unload_module (void) |
Cleanup all module structures, sockets, etc. | |
int | usecount (void) |
Provides a usecount. | |
Variables | |
static struct ast_custom_function | array_function |
static char * | tdesc = "String handling dialplan functions" |
static int | use_count = 0 |
Definition in file func_array.c.
|
Definition at line 87 of file func_array.c. References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_strdupa, LOG_DEBUG, pbx_builtin_setvar_helper(), trunk_app_separate_args(), and use_count. 00088 { 00089 AST_DECLARE_APP_ARGS(arg1, 00090 AST_APP_ARG(var)[100]; 00091 ); 00092 AST_DECLARE_APP_ARGS(arg2, 00093 AST_APP_ARG(val)[100]; 00094 ); 00095 char *value2; 00096 int i; 00097 00098 value2 = ast_strdupa(value); 00099 if (!var || !value2) 00100 return; 00101 00102 ast_mutex_lock(&local_lock); 00103 use_count++; 00104 ast_mutex_unlock(&local_lock); 00105 00106 /* The functions this will generally be used with are SORT and ODBC_*, which 00107 * both return comma-delimited lists. However, if somebody uses literal lists, 00108 * their commas will be translated to vertical bars by the load, and I don't 00109 * want them to be surprised by the result. Hence, we prefer commas as the 00110 * delimiter, but we'll fall back to vertical bars if commas aren't found. 00111 */ 00112 ast_log(LOG_DEBUG, "array (%s=%s)\n", var, value2); 00113 if (strchr(var, ',')) 00114 arg1.argc = trunk_app_separate_args(var, ',', arg1.argv, (sizeof(arg1) - sizeof(arg1.argc)) / sizeof(arg1.argv[0])); 00115 else 00116 arg1.argc = trunk_app_separate_args(var, '|', arg1.argv, (sizeof(arg1) - sizeof(arg1.argc)) / sizeof(arg1.argv[0])); 00117 00118 if (strchr(value2, ',')) 00119 arg2.argc = trunk_app_separate_args(value2, ',', arg2.argv, (sizeof(arg2) - sizeof(arg2.argc)) / sizeof(arg2.argv[0])); 00120 else 00121 arg2.argc = trunk_app_separate_args(value2, '|', arg2.argv, (sizeof(arg2) - sizeof(arg2.argc)) / sizeof(arg2.argv[0])); 00122 00123 for (i = 0; i < arg1.argc; i++) { 00124 ast_log(LOG_DEBUG, "array set value (%s=%s)\n", arg1.var[i], 00125 arg2.val[i]); 00126 if (i < arg2.argc) { 00127 pbx_builtin_setvar_helper(chan, arg1.var[i], arg2.val[i]); 00128 } else { 00129 /* We could unset the variable, by passing a NULL, but due to 00130 * pushvar semantics, that could create some undesired behavior. */ 00131 pbx_builtin_setvar_helper(chan, arg1.var[i], ""); 00132 } 00133 } 00134 00135 ast_mutex_lock(&local_lock); 00136 use_count--; 00137 ast_mutex_unlock(&local_lock); 00138 00139 return; 00140 }
|
|
|
|
Provides a description of the module.
Definition at line 177 of file func_array.c. References tdesc. 00178 { 00179 return tdesc; 00180 }
|
|
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 187 of file func_array.c. References ASTERISK_GPL_KEY. 00188 { 00189 return ASTERISK_GPL_KEY; 00190 }
|
|
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 168 of file func_array.c. References ast_custom_function_register(). 00169 { 00170 int res = 0; 00171 00172 res |= ast_custom_function_register(&array_function); 00173 00174 return res; 00175 }
|
|
Definition at line 45 of file func_array.c. Referenced by array(). 00046 { 00047 int argc; 00048 char *scan; 00049 int paren = 0, quote = 0; 00050 00051 if (!buf || !array || !arraylen) 00052 return 0; 00053 00054 memset(array, 0, arraylen * sizeof(*array)); 00055 00056 scan = buf; 00057 00058 for (argc = 0; *scan && (argc < arraylen - 1); argc++) { 00059 array[argc] = scan; 00060 for (; *scan; scan++) { 00061 if (*scan == '(') 00062 paren++; 00063 else if (*scan == ')') { 00064 if (paren) 00065 paren--; 00066 } else if (*scan == '"') { 00067 quote = quote ? 0 : 1; 00068 /* Remove quote character from argument */ 00069 memmove(scan, scan + 1, strlen(scan)); 00070 scan--; 00071 } else if (*scan == '\\') { 00072 /* Literal character, don't parse */ 00073 memmove(scan, scan + 1, strlen(scan)); 00074 } else if ((*scan == delim) && !paren && !quote) { 00075 *scan++ = '\0'; 00076 break; 00077 } 00078 } 00079 } 00080 00081 if (*scan) 00082 array[argc++] = scan; 00083 00084 return argc; 00085 }
|
|
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 158 of file func_array.c. References ast_custom_function_unregister(). 00159 { 00160 int res = 0; 00161 00162 res |= ast_custom_function_unregister(&array_function); 00163 sched_yield(); /* Any remaining process gets time to clear out. Increases safety if a force unload is attempted. */ 00164 00165 return res; 00166 }
|
|
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 182 of file func_array.c. References use_count. 00183 { 00184 return use_count; 00185 }
|
|
Definition at line 142 of file func_array.c. |
|
Definition at line 156 of file func_array.c. |
|
Definition at line 43 of file func_array.c. Referenced by array(), and usecount(). |