| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#ifndef GEOLOC_PRIVATE_H_ |
| 20 |
#define GEOLOC_PRIVATE_H_ |
| 21 |
|
| 22 |
#include "asterisk/module.h" |
| 23 |
#include "asterisk/config.h" |
| 24 |
#include "asterisk/sorcery.h" |
| 25 |
#include "asterisk/lock.h" |
| 26 |
#include "asterisk/res_geolocation.h" |
| 27 |
|
| 28 |
#define CONFIG_STR_TO_ENUM(_stem) \ |
| 29 |
int ast_geoloc_ ## _stem ## _str_to_enum(const char *str) \ |
| 30 |
{ \ |
| 31 |
int i; \ |
| 32 |
for (i = 0; i < ARRAY_LEN(_stem ## _names); i++) { \ |
| 33 |
if (ast_strings_equal(str, _stem ## _names[i])) { \ |
| 34 |
return i; \ |
| 35 |
} \ |
| 36 |
} \ |
| 37 |
return -1; \ |
| 38 |
} |
| 39 |
|
| 40 |
#define CONFIG_ENUM_HANDLER(_object, _stem) \ |
| 41 |
static int _object ## _ ## _stem ## _handler(const struct aco_option *opt, struct ast_variable *var, void *obj) \ |
| 42 |
{ \ |
| 43 |
struct ast_geoloc_ ## _object *_thisobject = obj; \ |
| 44 |
int enumval = ast_geoloc_ ## _stem ## _str_to_enum(var->value); \ |
| 45 |
if (enumval == -1) { \ |
| 46 |
return -1; \ |
| 47 |
} \ |
| 48 |
_thisobject->_stem = enumval; \ |
| 49 |
return 0; \ |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
#define GEOLOC_ENUM_TO_NAME(_stem) \ |
| 54 |
const char * ast_geoloc_ ## _stem ## _to_name(int ix) \ |
| 55 |
{ \ |
| 56 |
if (!ARRAY_IN_BOUNDS(ix, _stem ## _names)) { \ |
| 57 |
return "none"; \ |
| 58 |
} else { \ |
| 59 |
return _stem ## _names[ix]; \ |
| 60 |
} \ |
| 61 |
} |
| 62 |
|
| 63 |
#define CONFIG_ENUM_TO_STR(_object, _stem) \ |
| 64 |
static int _object ## _ ## _stem ## _to_str(const void *obj, const intptr_t *args, char **buf) \ |
| 65 |
{ \ |
| 66 |
const struct ast_geoloc_ ## _object *_thisobject = obj; \ |
| 67 |
if (!ARRAY_IN_BOUNDS(_thisobject->_stem, _stem ## _names)) { \ |
| 68 |
*buf = ast_strdup("none"); \ |
| 69 |
} else { \ |
| 70 |
*buf = ast_strdup(_stem ## _names[_thisobject->_stem]); \ |
| 71 |
} \ |
| 72 |
return 0; \ |
| 73 |
} |
| 74 |
|
| 75 |
#define CONFIG_ENUM(_object, _stem) \ |
| 76 |
CONFIG_STR_TO_ENUM(_stem) \ |
| 77 |
GEOLOC_ENUM_TO_NAME(_stem) \ |
| 78 |
CONFIG_ENUM_HANDLER(_object, _stem) \ |
| 79 |
CONFIG_ENUM_TO_STR(_object, _stem) |
| 80 |
|
| 81 |
#define CONFIG_VAR_LIST_HANDLER(_object, _stem) \ |
| 82 |
static int _object ## _ ## _stem ## _handler(const struct aco_option *opt, struct ast_variable *var, void *obj) \ |
| 83 |
{ \ |
| 84 |
struct ast_geoloc_ ## _object *_thisobject = obj; \ |
| 85 |
struct ast_variable *new_var; \ |
| 86 |
char *item_string, *item, *item_name, *item_value; \ |
| 87 |
int rc = 0;\ |
| 88 |
if (ast_strlen_zero(var->value)) { return 0; } \ |
| 89 |
item_string = ast_strdupa(var->value); \ |
| 90 |
while ((item = ast_strsep(&item_string, ',', AST_STRSEP_ALL))) { \ |
| 91 |
item_name = ast_strsep(&item, '=', AST_STRSEP_ALL); \ |
| 92 |
item_value = ast_strsep(&item, '=', AST_STRSEP_ALL); \ |
| 93 |
new_var = ast_variable_new(item_name, S_OR(item_value, ""), ""); \ |
| 94 |
if (!new_var) { \ |
| 95 |
rc = -1; \ |
| 96 |
break; \ |
| 97 |
} \ |
| 98 |
ast_variable_list_append(&_thisobject->_stem, new_var); \ |
| 99 |
} \ |
| 100 |
return rc; \ |
| 101 |
} |
| 102 |
|
| 103 |
#define CONFIG_VAR_LIST_DUP(_object, _stem) \ |
| 104 |
static int _object ## _ ## _stem ## _dup(const void *obj, struct ast_variable **fields) \ |
| 105 |
{ \ |
| 106 |
const struct ast_geoloc_ ## _object *_thisobject = obj; \ |
| 107 |
if (_thisobject->_stem) { \ |
| 108 |
*fields = ast_variables_dup(_thisobject->_stem); \ |
| 109 |
} \ |
| 110 |
return 0; \ |
| 111 |
} |
| 112 |
|
| 113 |
#define CONFIG_VAR_LIST_TO_STR(_object, _stem) \ |
| 114 |
static int _object ## _ ## _stem ## _to_str(const void *obj, const intptr_t *args, char **buf) \ |
| 115 |
{ \ |
| 116 |
const struct ast_geoloc_ ## _object *_thisobject = obj; \ |
| 117 |
struct ast_str *str = ast_variable_list_join(_thisobject->_stem, ",", "=", "\"", NULL); \ |
| 118 |
*buf = ast_strdup(ast_str_buffer(str)); \ |
| 119 |
ast_free(str); \ |
| 120 |
return 0; \ |
| 121 |
} |
| 122 |
|
| 123 |
#define CONFIG_VAR_LIST(_object, _stem) \ |
| 124 |
CONFIG_VAR_LIST_HANDLER(_object, _stem) \ |
| 125 |
CONFIG_VAR_LIST_DUP(_object, _stem) \ |
| 126 |
CONFIG_VAR_LIST_TO_STR(_object, _stem) |
| 127 |
|
| 128 |
int geoloc_config_load(void); |
| 129 |
int geoloc_config_reload(void); |
| 130 |
int geoloc_config_unload(void); |
| 131 |
|
| 132 |
struct ast_xml_node *geoloc_civicaddr_list_to_xml(const struct ast_variable *resolved_location, |
| 133 |
const char *ref_string); |
| 134 |
int geoloc_civicaddr_load(void); |
| 135 |
int geoloc_civicaddr_unload(void); |
| 136 |
int geoloc_civicaddr_reload(void); |
| 137 |
|
| 138 |
struct ast_xml_node *geoloc_gml_list_to_xml(struct ast_variable *resolved_location, |
| 139 |
const char *ref_string); |
| 140 |
int geoloc_gml_unload(void); |
| 141 |
int geoloc_gml_load(void); |
| 142 |
int geoloc_gml_reload(void); |
| 143 |
|
| 144 |
int geoloc_dialplan_unload(void); |
| 145 |
int geoloc_dialplan_load(void); |
| 146 |
int geoloc_dialplan_reload(void); |
| 147 |
|
| 148 |
int geoloc_channel_unload(void); |
| 149 |
int geoloc_channel_load(void); |
| 150 |
int geoloc_channel_reload(void); |
| 151 |
|
| 152 |
int geoloc_eprofile_unload(void); |
| 153 |
int geoloc_eprofile_load(void); |
| 154 |
int geoloc_eprofile_reload(void); |
| 155 |
|
| 156 |
struct ast_sorcery *geoloc_get_sorcery(void); |
| 157 |
|
| 158 |
struct ast_variable *geoloc_eprofile_resolve_varlist(struct ast_variable *source, |
| 159 |
struct ast_variable *variables, struct ast_channel *chan); |
| 160 |
|
| 161 |
char *geoloc_eprofile_resolve_string(const char *source, |
| 162 |
struct ast_variable *variables, struct ast_channel *chan); |
| 163 |
|
| 164 |
#endif |