Asterisk - The Open Source Telephony Project GIT-master-abe0018
geoloc_private.h
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2022, Sangoma Technologies Corporation
5 *
6 * George Joseph <gjoseph@sangoma.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
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"
27
28#define CONFIG_STR_TO_ENUM(_stem) \
29int 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) \
41static 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) \
54const 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) \
64static 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) \
76CONFIG_STR_TO_ENUM(_stem) \
77GEOLOC_ENUM_TO_NAME(_stem) \
78CONFIG_ENUM_HANDLER(_object, _stem) \
79CONFIG_ENUM_TO_STR(_object, _stem)
80
81#define CONFIG_VAR_LIST_HANDLER(_object, _stem) \
82static 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) \
104static 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) \
114static 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) \
124CONFIG_VAR_LIST_HANDLER(_object, _stem) \
125CONFIG_VAR_LIST_DUP(_object, _stem) \
126CONFIG_VAR_LIST_TO_STR(_object, _stem)
127
128int geoloc_config_load(void);
129int geoloc_config_reload(void);
130int geoloc_config_unload(void);
131
132struct ast_xml_node *geoloc_civicaddr_list_to_xml(const struct ast_variable *resolved_location,
133 const char *ref_string);
134int geoloc_civicaddr_load(void);
137
138struct ast_xml_node *geoloc_gml_list_to_xml(const struct ast_variable *resolved_location,
139 const char *ref_string);
140int geoloc_gml_unload(void);
141int geoloc_gml_load(void);
142int geoloc_gml_reload(void);
143
144int geoloc_dialplan_unload(void);
145int geoloc_dialplan_load(void);
146int geoloc_dialplan_reload(void);
147
148int geoloc_channel_unload(void);
149int geoloc_channel_load(void);
150int geoloc_channel_reload(void);
151
152int geoloc_eprofile_unload(void);
153int geoloc_eprofile_load(void);
154int geoloc_eprofile_reload(void);
155
156struct ast_sorcery *geoloc_get_sorcery(void);
157
159 struct ast_variable *variables, struct ast_channel *chan);
160
161
162#endif /* GEOLOC_PRIVATE_H_ */
int geoloc_channel_reload(void)
struct ast_variable * geoloc_eprofile_resolve_varlist(struct ast_variable *source, struct ast_variable *variables, struct ast_channel *chan)
int geoloc_eprofile_reload(void)
struct ast_xml_node * geoloc_civicaddr_list_to_xml(const struct ast_variable *resolved_location, const char *ref_string)
int geoloc_eprofile_unload(void)
int geoloc_dialplan_reload(void)
int geoloc_dialplan_unload(void)
int geoloc_config_reload(void)
int geoloc_channel_load(void)
int geoloc_config_unload(void)
int geoloc_dialplan_load(void)
int geoloc_config_load(void)
int geoloc_civicaddr_reload(void)
int geoloc_eprofile_load(void)
int geoloc_gml_reload(void)
Definition: geoloc_gml.c:364
int geoloc_civicaddr_load(void)
struct ast_sorcery * geoloc_get_sorcery(void)
int geoloc_channel_unload(void)
int geoloc_gml_unload(void)
Definition: geoloc_gml.c:350
struct ast_xml_node * geoloc_gml_list_to_xml(const struct ast_variable *resolved_location, const char *ref_string)
Definition: geoloc_gml.c:238
int geoloc_gml_load(void)
Definition: geoloc_gml.c:357
int geoloc_civicaddr_unload(void)
Configuration File Parser.
Asterisk locking-related definitions:
Asterisk module definitions.
Sorcery Data Access Layer API.
Main Channel structure associated with a channel.
Full structure for sorcery.
Definition: sorcery.c:230
Structure for variables, used for configurations and for channel variables.