Asterisk - The Open Source Telephony Project GIT-master-f3e88d3
Functions | Variables
geoloc_civicaddr.c File Reference
#include "asterisk.h"
#include "asterisk/config.h"
#include "asterisk/cli.h"
#include "asterisk/res_geolocation.h"
#include "asterisk/xml.h"
#include "geoloc_private.h"
Include dependency graph for geoloc_civicaddr.c:

Go to the source code of this file.

Functions

int ast_geoloc_civicaddr_is_code_valid (const char *code)
 Given a civicAddress code, check whether it's valid. More...
 
enum ast_geoloc_validate_result ast_geoloc_civicaddr_validate_varlist (const struct ast_variable *varlist, const char **result)
 Validate that the names of the variables in the list are valid codes or synonyms. More...
 
static int compare_civicaddr_codes (const void *_a, const void *_b)
 
struct ast_xml_node * geoloc_civicaddr_list_to_xml (const struct ast_variable *resolved_location, const char *ref_string)
 
int geoloc_civicaddr_load (void)
 
int geoloc_civicaddr_reload (void)
 
int geoloc_civicaddr_unload (void)
 

Variables

static const char * addr_code_name_entries []
 

Function Documentation

◆ ast_geoloc_civicaddr_is_code_valid()

int ast_geoloc_civicaddr_is_code_valid ( const char *  code)

Given a civicAddress code, check whether it's valid.

Parameters
codePointer to the code to check
Returns
1 if valid, 0 otherwise.

Definition at line 68 of file geoloc_civicaddr.c.

69{
70 const char **entry = bsearch(&code, addr_code_name_entries, ARRAY_LEN(addr_code_name_entries),
71 sizeof(const char *), compare_civicaddr_codes);
72 return (entry != NULL);
73}
static int compare_civicaddr_codes(const void *_a, const void *_b)
static const char * addr_code_name_entries[]
#define NULL
Definition: resample.c:96
Definition: search.h:40
#define ARRAY_LEN(a)
Definition: utils.h:666

References addr_code_name_entries, ARRAY_LEN, compare_civicaddr_codes(), and NULL.

Referenced by ast_geoloc_civicaddr_validate_varlist().

◆ ast_geoloc_civicaddr_validate_varlist()

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

Validate that the names of the variables in the list are valid codes or synonyms.

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

Definition at line 75 of file geoloc_civicaddr.c.

77{
78 const struct ast_variable *var = varlist;
79 for (; var; var = var->next) {
80 int valid = ast_geoloc_civicaddr_is_code_valid(var->name);
81 if (!valid) {
82 *result = var->name;
84 }
85 }
87}
#define var
Definition: ast_expr2f.c:605
static PGresult * result
Definition: cel_pgsql.c:84
int ast_geoloc_civicaddr_is_code_valid(const char *code)
Given a civicAddress code, check whether it's valid.
@ AST_GEOLOC_VALIDATE_SUCCESS
@ AST_GEOLOC_VALIDATE_INVALID_VARNAME
Structure for variables, used for configurations and for channel variables.

References ast_geoloc_civicaddr_is_code_valid(), AST_GEOLOC_VALIDATE_INVALID_VARNAME, AST_GEOLOC_VALIDATE_SUCCESS, result, and var.

Referenced by validate_location_info().

◆ compare_civicaddr_codes()

static int compare_civicaddr_codes ( const void *  _a,
const void *  _b 
)
static

Definition at line 61 of file geoloc_civicaddr.c.

62{
63 /* See the man page for qsort(3) for an explanation of the casts */
64 int rc = strcmp(*(const char **)_a, *(const char **)_b);
65 return rc;
66}

Referenced by ast_geoloc_civicaddr_is_code_valid(), and geoloc_civicaddr_load().

◆ geoloc_civicaddr_list_to_xml()

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

Definition at line 89 of file geoloc_civicaddr.c.

91{
92 char *lang = NULL;
93 char *s = NULL;
94 struct ast_variable *var;
95 struct ast_xml_node *ca_node;
96 struct ast_xml_node *child_node;
97 int rc = 0;
98 SCOPE_ENTER(3, "%s", ref_string);
99
100 lang = (char *)ast_variable_find_in_list(resolved_location, "lang");
101 if (ast_strlen_zero(lang)) {
103 for (s = lang; *s; s++) {
104 if (*s == '_') {
105 *s = '-';
106 }
107 }
108 }
109
110 ca_node = ast_xml_new_node("civicAddress");
111 if (!ca_node) {
112 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: Unable to create 'civicAddress' XML node\n", ref_string);
113 }
114 rc = ast_xml_set_attribute(ca_node, "lang", lang);
115 if (rc != 0) {
116 ast_xml_free_node(ca_node);
117 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: Unable to create 'lang' XML attribute\n", ref_string);
118 }
119
120 for (var = (struct ast_variable *)resolved_location; var; var = var->next) {
121 if (ast_strings_equal(var->name, "lang")) {
122 continue;
123 }
124 child_node = ast_xml_new_child(ca_node, var->name);
125 if (!child_node) {
126 ast_xml_free_node(ca_node);
127 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: Unable to create '%s' XML node\n", var->name, ref_string);
128 }
129 ast_xml_set_text(child_node, var->value);
130 }
131
132 SCOPE_EXIT_RTN_VALUE(ca_node, "%s: Done\n", ref_string);
133}
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define SCOPE_EXIT_RTN_VALUE(__return_value,...)
#define SCOPE_EXIT_LOG_RTN_VALUE(__value, __log_level,...)
#define SCOPE_ENTER(level,...)
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:919
#define LOG_ERROR
char ast_defaultlanguage[]
Definition: options.c:98
int ast_strings_equal(const char *str1, const char *str2)
Compare strings for equality checking for NULL.
Definition: strings.c:238
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
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 ast_defaultlanguage, ast_strdupa, 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, SCOPE_ENTER, SCOPE_EXIT_LOG_RTN_VALUE, SCOPE_EXIT_RTN_VALUE, and var.

Referenced by geoloc_eprofile_to_intermediate().

◆ geoloc_civicaddr_load()

int geoloc_civicaddr_load ( void  )

Definition at line 140 of file geoloc_civicaddr.c.

141{
142 qsort(addr_code_name_entries, ARRAY_LEN(addr_code_name_entries), sizeof(const char *),
144
146}
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70

References addr_code_name_entries, ARRAY_LEN, AST_MODULE_LOAD_SUCCESS, and compare_civicaddr_codes().

Referenced by load_module().

◆ geoloc_civicaddr_reload()

int geoloc_civicaddr_reload ( void  )

Definition at line 148 of file geoloc_civicaddr.c.

149{
151}

References AST_MODULE_LOAD_SUCCESS.

Referenced by reload_module().

◆ geoloc_civicaddr_unload()

int geoloc_civicaddr_unload ( void  )

Definition at line 135 of file geoloc_civicaddr.c.

136{
138}

References AST_MODULE_LOAD_SUCCESS.

Referenced by unload_module().

Variable Documentation

◆ addr_code_name_entries

const char* addr_code_name_entries[]
static

Definition at line 26 of file geoloc_civicaddr.c.

Referenced by ast_geoloc_civicaddr_is_code_valid(), and geoloc_civicaddr_load().