Asterisk - The Open Source Telephony Project GIT-master-f36a736
Data Structures | Enumerations | Functions | Variables
geoloc_gml.c File Reference
#include "asterisk.h"
#include "asterisk/config.h"
#include "asterisk/cli.h"
#include "asterisk/res_geolocation.h"
#include "geoloc_private.h"
Include dependency graph for geoloc_gml.c:

Go to the source code of this file.

Data Structures

struct  geoloc_gml_attr
 
struct  geoloc_gml_attr_def
 
struct  geoloc_gml_shape_def
 

Enumerations

enum  geoloc_shape_attrs {
  GEOLOC_SHAPE_ATTR_POS = 0 , GEOLOC_SHAPE_ATTR_POS3D , GEOLOC_SHAPE_ATTR_RADIUS , GEOLOC_SHAPE_ATTR_SEMI_MAJOR_AXIS ,
  GEOLOC_SHAPE_ATTR_SEMI_MINOR_AXIS , GEOLOC_SHAPE_ATTR_VERTICAL_AXIS , GEOLOC_SHAPE_ATTR_HEIGHT , GEOLOC_SHAPE_ATTR_ORIENTATION ,
  GEOLOC_SHAPE_ATTR_ORIENTATION_UOM , GEOLOC_SHAPE_ATTR_INNER_RADIUS , GEOLOC_SHAPE_ATTR_OUTER_RADIUS , GEOLOC_SHAPE_ATTR_STARTING_ANGLE ,
  GEOLOC_SHAPE_ATTR_OPENING_ANGLE , GEOLOC_SHAPE_ATTR_ANGLE_UOM
}
 

Functions

enum ast_geoloc_validate_result ast_geoloc_gml_validate_varlist (const struct ast_variable *varlist, const char **result)
 Validate that the variables in the list represent a valid GML shape. More...
 
static int float_validator (const char *value)
 
struct ast_xml_node * geoloc_gml_list_to_xml (const struct ast_variable *resolved_location, const char *ref_string)
 
int geoloc_gml_load (void)
 
int geoloc_gml_reload (void)
 
int geoloc_gml_unload (void)
 
static char * handle_gml_show (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static int pos3d_validator (const char *value)
 
static int pos_validator (const char *value)
 
static int uom_validator (const char *value)
 

Variables

static struct ast_cli_entry geoloc_gml_cli []
 
struct geoloc_gml_attr_def gml_attr_defs []
 
static struct geoloc_gml_shape_def gml_shape_defs [8]
 

Enumeration Type Documentation

◆ geoloc_shape_attrs

Enumerator
GEOLOC_SHAPE_ATTR_POS 
GEOLOC_SHAPE_ATTR_POS3D 
GEOLOC_SHAPE_ATTR_RADIUS 
GEOLOC_SHAPE_ATTR_SEMI_MAJOR_AXIS 
GEOLOC_SHAPE_ATTR_SEMI_MINOR_AXIS 
GEOLOC_SHAPE_ATTR_VERTICAL_AXIS 
GEOLOC_SHAPE_ATTR_HEIGHT 
GEOLOC_SHAPE_ATTR_ORIENTATION 
GEOLOC_SHAPE_ATTR_ORIENTATION_UOM 
GEOLOC_SHAPE_ATTR_INNER_RADIUS 
GEOLOC_SHAPE_ATTR_OUTER_RADIUS 
GEOLOC_SHAPE_ATTR_STARTING_ANGLE 
GEOLOC_SHAPE_ATTR_OPENING_ANGLE 
GEOLOC_SHAPE_ATTR_ANGLE_UOM 

Definition at line 25 of file geoloc_gml.c.

25 {
40};
@ GEOLOC_SHAPE_ATTR_INNER_RADIUS
Definition: geoloc_gml.c:35
@ GEOLOC_SHAPE_ATTR_ANGLE_UOM
Definition: geoloc_gml.c:39
@ GEOLOC_SHAPE_ATTR_RADIUS
Definition: geoloc_gml.c:28
@ GEOLOC_SHAPE_ATTR_OPENING_ANGLE
Definition: geoloc_gml.c:38
@ GEOLOC_SHAPE_ATTR_POS
Definition: geoloc_gml.c:26
@ GEOLOC_SHAPE_ATTR_STARTING_ANGLE
Definition: geoloc_gml.c:37
@ GEOLOC_SHAPE_ATTR_OUTER_RADIUS
Definition: geoloc_gml.c:36
@ GEOLOC_SHAPE_ATTR_ORIENTATION
Definition: geoloc_gml.c:33
@ GEOLOC_SHAPE_ATTR_ORIENTATION_UOM
Definition: geoloc_gml.c:34
@ GEOLOC_SHAPE_ATTR_HEIGHT
Definition: geoloc_gml.c:32
@ GEOLOC_SHAPE_ATTR_SEMI_MINOR_AXIS
Definition: geoloc_gml.c:30
@ GEOLOC_SHAPE_ATTR_SEMI_MAJOR_AXIS
Definition: geoloc_gml.c:29
@ GEOLOC_SHAPE_ATTR_VERTICAL_AXIS
Definition: geoloc_gml.c:31
@ GEOLOC_SHAPE_ATTR_POS3D
Definition: geoloc_gml.c:27

Function Documentation

◆ ast_geoloc_gml_validate_varlist()

enum ast_geoloc_validate_result ast_geoloc_gml_validate_varlist ( const struct ast_variable varlist,
const char **  result 
)

Validate that the variables in the list represent a valid GML shape.

Parameters
varlistVariable list to check.
[out]resultPointer to char * to receive failing item.
Returns
result code.

Definition at line 124 of file geoloc_gml.c.

126{
127 int def_index = -1;
128 const struct ast_variable *var;
129 int i;
130 const char *shape_type = ast_variable_find_in_list(varlist, "shape");
131
132 if (!shape_type) {
134 }
135
136 for (i = 0; i < ARRAY_LEN(gml_shape_defs); i++) {
137 if (ast_strings_equal(gml_shape_defs[i].shape_type, shape_type)) {
138 def_index = i;
139 }
140 }
141 if (def_index < 0) {
143 }
144
145 for (var = varlist; var; var = var->next) {
146 int vname_index = -1;
147 if (ast_strings_equal("shape", var->name)) {
148 continue;
149 }
150 for (i = 0; i < ARRAY_LEN(gml_shape_defs[def_index].required_attributes); i++) {
151 if (gml_shape_defs[def_index].required_attributes[i].attribute == NULL) {
152 break;
153 }
154 if (ast_strings_equal(gml_shape_defs[def_index].required_attributes[i].attribute, var->name)) {
155 vname_index = i;
156 break;
157 }
158 }
159 if (vname_index < 0) {
160 *result = var->name;
162 }
163 if (!gml_shape_defs[def_index].required_attributes[vname_index].validator(var->value)) {
164 *result = var->name;
166 }
167 }
168
169 for (i = 0; i < ARRAY_LEN(gml_shape_defs[def_index].required_attributes); i++) {
170 int count = 0;
171 if (gml_shape_defs[def_index].required_attributes[i].attribute == NULL) {
172 break;
173 }
174
175 for (var = varlist; var; var = var->next) {
176 if (ast_strings_equal(gml_shape_defs[def_index].required_attributes[i].attribute, var->name)) {
177 count++;
178 }
179 }
180 if (count < gml_shape_defs[def_index].required_attributes[i].min_required) {
183 }
184 if (gml_shape_defs[def_index].required_attributes[i].max_allowed > 0 &&
185 count > gml_shape_defs[def_index].required_attributes[i].max_allowed) {
188 }
189 }
191}
#define var
Definition: ast_expr2f.c:605
static PGresult * result
Definition: cel_pgsql.c:84
static struct geoloc_gml_shape_def gml_shape_defs[8]
Definition: geoloc_gml.c:106
const char * ast_variable_find_in_list(const struct ast_variable *list, const char *variable)
Gets the value of a variable from a variable list by name.
Definition: main/config.c:928
@ AST_GEOLOC_VALIDATE_TOO_MANY_VARNAMES
@ AST_GEOLOC_VALIDATE_MISSING_SHAPE
@ AST_GEOLOC_VALIDATE_INVALID_VALUE
@ AST_GEOLOC_VALIDATE_SUCCESS
@ AST_GEOLOC_VALIDATE_NOT_ENOUGH_VARNAMES
@ AST_GEOLOC_VALIDATE_INVALID_SHAPE
@ AST_GEOLOC_VALIDATE_INVALID_VARNAME
#define NULL
Definition: resample.c:96
int ast_strings_equal(const char *str1, const char *str2)
Compare strings for equality checking for NULL.
Definition: strings.c:238
Structure for variables, used for configurations and for channel variables.
const char * attribute
Definition: geoloc_gml.c:68
struct geoloc_gml_attr required_attributes[8]
Definition: geoloc_gml.c:76
#define ARRAY_LEN(a)
Definition: utils.h:666

References ARRAY_LEN, AST_GEOLOC_VALIDATE_INVALID_SHAPE, AST_GEOLOC_VALIDATE_INVALID_VALUE, AST_GEOLOC_VALIDATE_INVALID_VARNAME, AST_GEOLOC_VALIDATE_MISSING_SHAPE, AST_GEOLOC_VALIDATE_NOT_ENOUGH_VARNAMES, AST_GEOLOC_VALIDATE_SUCCESS, AST_GEOLOC_VALIDATE_TOO_MANY_VARNAMES, ast_strings_equal(), ast_variable_find_in_list(), geoloc_gml_attr::attribute, gml_shape_defs, NULL, geoloc_gml_shape_def::required_attributes, result, and var.

Referenced by validate_location_info().

◆ float_validator()

static int float_validator ( const char *  value)
static

Definition at line 94 of file geoloc_gml.c.

95{
96 float val;
97 return (sscanf(value, "%f", &val) == 1);
98}
Definition: ast_expr2.c:325
int value
Definition: syslog.c:37

References value.

◆ geoloc_gml_list_to_xml()

struct ast_xml_node * geoloc_gml_list_to_xml ( const struct ast_variable resolved_location,
const char *  ref_string 
)

Definition at line 238 of file geoloc_gml.c.

240{
241 const char *shape;
242 char *crs;
243 struct ast_variable *var;
244 struct ast_xml_node *gml_node;
245 struct ast_xml_node *child_node;
246 int rc = 0;
247
248 SCOPE_ENTER(3, "%s", ref_string);
249
250 if (!resolved_location) {
251 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: resolved_location was NULL\n",
252 ref_string);
253 }
254
255 shape = ast_variable_find_in_list(resolved_location, "shape");
256 if (ast_strlen_zero(shape)) {
257 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: There's no 'shape' parameter\n",
258 ref_string);
259 }
260 crs = (char *)ast_variable_find_in_list(resolved_location, "crs");
261 if (ast_strlen_zero(crs)) {
262 crs = "2d";
263 }
264
265 gml_node = ast_xml_new_node(shape);
266 if (!gml_node) {
267 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: Unable to create '%s' XML node\n", shape, ref_string);
268 }
269 rc = ast_xml_set_attribute(gml_node, "crs", crs);
270 if (rc != 0) {
271 ast_xml_free_node(gml_node);
272 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: Unable to create 'crs' XML attribute\n", ref_string);
273 }
274
275 for (var = (struct ast_variable *)resolved_location; var; var = var->next) {
276 RAII_VAR(char *, value, NULL, ast_free);
277 char *uom = NULL;
278
279 if (ast_strings_equal(var->name, "shape") || ast_strings_equal(var->name, "crs")) {
280 continue;
281 }
282 value = ast_strdup(var->value);
283
284 if (ast_strings_equal(var->name, "orientation") || ast_strings_equal(var->name, "startAngle")
285 || ast_strings_equal(var->name, "openingAngle")) {
286 char *a = NULL;
287 char *junk = NULL;
288 float angle;
289 uom = value;
290
291 /* 'a' should now be the angle and 'uom' should be the uom */
292 a = strsep(&uom, " ");
293 angle = strtof(a, &junk);
294 /*
295 * strtof sets junk to the first non-valid character so if it's
296 * not empty after the conversion, there were unrecognized
297 * characters in the angle. It'll point to the NULL terminator
298 * if angle was completely converted.
299 */
300 if (!ast_strlen_zero(junk)) {
301 ast_xml_free_node(gml_node);
302 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: The angle portion of parameter '%s' ('%s') is malformed\n",
303 ref_string, var->name, var->value);
304 }
305
306 if (ast_strlen_zero(uom)) {
307 uom = "degrees";
308 }
309
310 if (ast_begins_with(uom, "deg")) {
311 if (angle > 360.0) {
312 ast_xml_free_node(gml_node);
313 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: Parameter '%s': '%s' is malformed. "
314 "Degrees can't be > 360.0\n",
315 ref_string, var->name, var->value);
316 }
317 } else if (ast_begins_with(uom, "rad")) {
318 if(angle > 100.0) {
319 ast_xml_free_node(gml_node);
320 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: Parameter '%s': '%s' is malformed. "
321 "Radians can't be > 100.0\n",
322 ref_string, var->name, var->value);
323 }
324 } else {
325 ast_xml_free_node(gml_node);
326 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: Parameter '%s': '%s' is malformed. "
327 "The unit of measure must be 'deg[rees]' or 'rad[ians]'\n",
328 ref_string, var->name, var->value);
329 }
330 }
331
332 child_node = ast_xml_new_child(gml_node, var->name);
333 if (!child_node) {
334 ast_xml_free_node(gml_node);
335 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: Unable to create '%s' XML node\n", var->name, ref_string);
336 }
337 if (!ast_strlen_zero(uom)) {
338 rc = ast_xml_set_attribute(child_node, "uom", uom);
339 if (rc != 0) {
340 ast_xml_free_node(gml_node);
341 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: Unable to create 'uom' XML attribute\n", ref_string);
342 }
343 }
344 ast_xml_set_text(child_node, value);
345 }
346
347 SCOPE_EXIT_RTN_VALUE(gml_node, "%s: Done\n", ref_string);
348}
#define ast_free(a)
Definition: astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define SCOPE_EXIT_RTN_VALUE(__return_value,...)
#define SCOPE_EXIT_LOG_RTN_VALUE(__value, __log_level,...)
#define SCOPE_ENTER(level,...)
char * strsep(char **str, const char *delims)
#define LOG_ERROR
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
static int force_inline attribute_pure ast_begins_with(const char *str, const char *prefix)
Checks whether a string begins with another.
Definition: strings.h:97
static struct test_val a
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941
struct ast_xml_node * ast_xml_new_child(struct ast_xml_node *parent, const char *child_name)
Add a child node inside a passed parent node.
Definition: xml.c:156
struct ast_xml_node * ast_xml_new_node(const char *name)
Create a XML node.
Definition: xml.c:144
int ast_xml_set_attribute(struct ast_xml_node *node, const char *name, const char *value)
Set an attribute to a node.
Definition: xml.c:284
void ast_xml_set_text(struct ast_xml_node *node, const char *content)
Set an element content string.
Definition: xml.c:362
void ast_xml_free_node(struct ast_xml_node *node)
Free node.
Definition: xml.c:243

References a, ast_begins_with(), ast_free, ast_strdup, ast_strings_equal(), ast_strlen_zero(), ast_variable_find_in_list(), ast_xml_free_node(), ast_xml_new_child(), ast_xml_new_node(), ast_xml_set_attribute(), ast_xml_set_text(), LOG_ERROR, NULL, RAII_VAR, SCOPE_ENTER, SCOPE_EXIT_LOG_RTN_VALUE, SCOPE_EXIT_RTN_VALUE, strsep(), value, and var.

Referenced by geoloc_eprofile_to_intermediate().

◆ geoloc_gml_load()

int geoloc_gml_load ( void  )

Definition at line 357 of file geoloc_gml.c.

358{
360
362}
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
static struct ast_cli_entry geoloc_gml_cli[]
Definition: geoloc_gml.c:234
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70

References ARRAY_LEN, ast_cli_register_multiple, AST_MODULE_LOAD_SUCCESS, and geoloc_gml_cli.

Referenced by load_module().

◆ geoloc_gml_reload()

int geoloc_gml_reload ( void  )

Definition at line 364 of file geoloc_gml.c.

365{
367}

References AST_MODULE_LOAD_SUCCESS.

Referenced by reload_module().

◆ geoloc_gml_unload()

int geoloc_gml_unload ( void  )

Definition at line 350 of file geoloc_gml.c.

351{
353
355}
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30

References ARRAY_LEN, ast_cli_unregister_multiple(), AST_MODULE_LOAD_SUCCESS, and geoloc_gml_cli.

Referenced by unload_module().

◆ handle_gml_show()

static char * handle_gml_show ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 193 of file geoloc_gml.c.

194{
195 int i;
196
197 switch (cmd) {
198 case CLI_INIT:
199 e->command = "geoloc show gml_shape_defs";
200 e->usage =
201 "Usage: geoloc show gml_shape_defs\n"
202 " Show the GML Shape definitions.\n";
203 return NULL;
204 case CLI_GENERATE:
205 return NULL;
206 }
207
208 ast_cli(a->fd, "%-16s %-32s\n", "Shape", "Attributes name(min,max)");
209 ast_cli(a->fd, "================ ===============================\n");
210
211 for (i = 0; i < ARRAY_LEN(gml_shape_defs); i++) {
212 int j;
213 ast_cli(a->fd, "%-16s", gml_shape_defs[i].shape_type);
214 for (j = 0; j < ARRAY_LEN(gml_shape_defs[i].required_attributes); j++) {
215 if (gml_shape_defs[i].required_attributes[j].attribute == NULL) {
216 break;
217 }
218 if (gml_shape_defs[i].required_attributes[j].max_allowed >= 0) {
219 ast_cli(a->fd, " %s(%d,%d)", gml_shape_defs[i].required_attributes[j].attribute,
222 } else {
223 ast_cli(a->fd, " %s(%d,unl)", gml_shape_defs[i].required_attributes[j].attribute,
225 }
226 }
227 ast_cli(a->fd, "\n");
228 }
229 ast_cli(a->fd, "\n");
230
231 return CLI_SUCCESS;
232}
#define CLI_SUCCESS
Definition: cli.h:44
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
@ CLI_INIT
Definition: cli.h:152
@ CLI_GENERATE
Definition: cli.h:153
char * command
Definition: cli.h:186
const char * usage
Definition: cli.h:177
const char * shape_type
Definition: geoloc_gml.c:75

References a, ARRAY_LEN, ast_cli(), geoloc_gml_attr::attribute, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, gml_shape_defs, geoloc_gml_attr::max_allowed, geoloc_gml_attr::min_required, NULL, geoloc_gml_shape_def::required_attributes, geoloc_gml_shape_def::shape_type, and ast_cli_entry::usage.

◆ pos3d_validator()

static int pos3d_validator ( const char *  value)
static

Definition at line 86 of file geoloc_gml.c.

87{
88 float lat;
89 float lon;
90 float alt;
91 return (sscanf(value, "%f %f %f", &lat, &lon, &alt) == 3);
92}

References value.

◆ pos_validator()

static int pos_validator ( const char *  value)
static

Definition at line 79 of file geoloc_gml.c.

80{
81 float lat;
82 float lon;
83 return (sscanf(value, "%f %f", &lat, &lon) == 2);
84}

References value.

◆ uom_validator()

static int uom_validator ( const char *  value)
static

Definition at line 100 of file geoloc_gml.c.

101{
102 return (ast_strings_equal(value, "degrees") || ast_strings_equal(value, "radians"));
103}

References ast_strings_equal(), and value.

Variable Documentation

◆ geoloc_gml_cli

struct ast_cli_entry geoloc_gml_cli[]
static
Initial value:
= {
{ .handler = handle_gml_show , .summary = "Show the GML Shape definitions" ,},
}
static char * handle_gml_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: geoloc_gml.c:193

Definition at line 234 of file geoloc_gml.c.

Referenced by geoloc_gml_load(), and geoloc_gml_unload().

◆ gml_attr_defs

struct geoloc_gml_attr_def gml_attr_defs[]

Definition at line 49 of file geoloc_gml.c.

◆ gml_shape_defs

struct geoloc_gml_shape_def gml_shape_defs[8]
static

Definition at line 106 of file geoloc_gml.c.

Referenced by ast_geoloc_gml_validate_varlist(), and handle_gml_show().