Asterisk - The Open Source Telephony Project GIT-master-4f2b068
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions
res_geolocation.h File Reference
#include "asterisk/channel.h"
#include "asterisk/config.h"
#include "asterisk/sorcery.h"
#include "asterisk/xml.h"
#include "asterisk/optional_api.h"
Include dependency graph for res_geolocation.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_geoloc_eprofile
 
struct  ast_geoloc_location
 
struct  ast_geoloc_profile
 

Macros

#define AST_GEOLOC_INVALID_VALUE   -1
 
#define CONFIG_STR_TO_ENUM_DECL(_stem)   int ast_geoloc_ ## _stem ## _str_to_enum(const char *str);
 
#define GEOLOC_ENUM_TO_NAME_DECL(_stem)   const char * ast_geoloc_ ## _stem ## _to_name(int ix);
 

Enumerations

enum  ast_geoloc_format {
  AST_GEOLOC_FORMAT_NONE = 0 , AST_GEOLOC_FORMAT_CIVIC_ADDRESS , AST_GEOLOC_FORMAT_GML , AST_GEOLOC_FORMAT_URI ,
  AST_GEOLOC_FORMAT_LAST
}
 
enum  ast_geoloc_pidf_element {
  AST_PIDF_ELEMENT_NONE = 0 , AST_PIDF_ELEMENT_DEVICE , AST_PIDF_ELEMENT_TUPLE , AST_PIDF_ELEMENT_PERSON ,
  AST_PIDF_ELEMENT_LAST
}
 
enum  ast_geoloc_precedence { AST_GEOLOC_PRECED_PREFER_INCOMING = 0 , AST_GEOLOC_PRECED_PREFER_CONFIG , AST_GEOLOC_PRECED_DISCARD_INCOMING , AST_GEOLOC_PRECED_DISCARD_CONFIG }
 
enum  ast_geoloc_validate_result {
  AST_GEOLOC_VALIDATE_SUCCESS = 0 , AST_GEOLOC_VALIDATE_MISSING_SHAPE , AST_GEOLOC_VALIDATE_INVALID_SHAPE , AST_GEOLOC_VALIDATE_INVALID_VARNAME ,
  AST_GEOLOC_VALIDATE_NOT_ENOUGH_VARNAMES , AST_GEOLOC_VALIDATE_TOO_MANY_VARNAMES , AST_GEOLOC_VALIDATE_INVALID_CRS , AST_GEOLOC_VALIDATE_INVALID_CRS_FOR_SHAPE ,
  AST_GEOLOC_VALIDATE_INVALID_VALUE
}
 

Functions

int ast_geoloc_civicaddr_is_code_valid (const char *code)
 Given a civicAddress code, check whether it's valid.
 
enum ast_geoloc_validate_result ast_geoloc_civicaddr_validate_varlist (const struct ast_variable *varlist, char **result)
 Validate that the names of the variables in the list are valid codes or synonyms.
 
struct ast_geoloc_location *AST_OPTIONAL_API_NAME() ast_geoloc_get_location (const char *id)
 Retrieve a geolocation location object by id.
 
struct ast_geoloc_profile *AST_OPTIONAL_API_NAME() ast_geoloc_get_profile (const char *id)
 Retrieve a geolocation profile by id.
 
enum ast_geoloc_validate_result ast_geoloc_gml_validate_varlist (struct ast_variable *varlist, char **result)
 Validate that the variables in the list represent a valid GML shape.
 
int AST_OPTIONAL_API_NAME() ast_geoloc_is_loaded (void)
 Check if res_geolocation is available.
 
const char * ast_geoloc_validate_result_to_str (enum ast_geoloc_validate_result result)
 
 CONFIG_STR_TO_ENUM_DECL (format)
 
 CONFIG_STR_TO_ENUM_DECL (precedence)
 
 GEOLOC_ENUM_TO_NAME_DECL (format)
 
 GEOLOC_ENUM_TO_NAME_DECL (precedence)
 
int ast_geoloc_datastore_add_eprofile (struct ast_datastore *ds, struct ast_geoloc_eprofile *eprofile)
 Add an eprofile to a datastore.
 
struct ast_datastoreast_geoloc_datastore_create (const char *id)
 Create an empty geoloc datastore.
 
struct ast_datastoreast_geoloc_datastore_create_from_eprofile (struct ast_geoloc_eprofile *eprofile)
 Create a geoloc datastore from an effective profile.
 
struct ast_datastoreast_geoloc_datastore_create_from_profile_name (const char *profile_name)
 Geolocation datastore Functions.
 
int ast_geoloc_datastore_delete_eprofile (struct ast_datastore *ds, int ix)
 Delete a specific eprofile from a datastore by index.
 
struct ast_datastoreast_geoloc_datastore_find (struct ast_channel *chan)
 Retrieves the geoloc datastore from a channel, if any.
 
struct ast_geoloc_eprofileast_geoloc_datastore_get_eprofile (struct ast_datastore *ds, int ix)
 Retrieve a specific eprofile from a datastore by index.
 
const char * ast_geoloc_datastore_get_id (struct ast_datastore *ds)
 Retrieve a geoloc datastore's id.
 
int ast_geoloc_datastore_insert_eprofile (struct ast_datastore *ds, struct ast_geoloc_eprofile *eprofile, int index)
 Insert an eprofile to a datastore at the specified position.
 
int ast_geoloc_datastore_set_inheritance (struct ast_datastore *ds, int inherit)
 Sets the inheritance flag on the datastore.
 
int ast_geoloc_datastore_size (struct ast_datastore *ds)
 Retrieves the number of eprofiles in the datastore.
 
struct ast_geoloc_eprofileast_geoloc_eprofile_alloc (const char *name)
 Geolocation Effective Profile Functions.
 
struct ast_geoloc_eprofileast_geoloc_eprofile_create_from_pidf (struct ast_xml_doc *pidf_xmldoc, const char *geoloc_uri, const char *reference_string)
 Allocate a new effective profile from an XML PIDF-LO document.
 
struct ast_geoloc_eprofileast_geoloc_eprofile_create_from_profile (struct ast_geoloc_profile *profile)
 Allocate a new effective profile from an existing profile.
 
struct ast_geoloc_eprofileast_geoloc_eprofile_create_from_uri (const char *uri, const char *reference_string)
 Allocate a new effective profile from a URI.
 
struct ast_geoloc_eprofileast_geoloc_eprofile_dup (struct ast_geoloc_eprofile *src)
 Duplicate an effective profile.
 
int ast_geoloc_eprofile_refresh_location (struct ast_geoloc_eprofile *eprofile)
 Refresh the effective profile with any changed info.
 
const char * ast_geoloc_eprofile_to_pidf (struct ast_geoloc_eprofile *eprofile, struct ast_channel *chan, struct ast_str **buf, const char *ref_string)
 Convert a single eprofile to a PIDF-LO document.
 
const char * ast_geoloc_eprofile_to_uri (struct ast_geoloc_eprofile *eprofile, struct ast_channel *chan, struct ast_str **buf, const char *ref_string)
 Convert a URI eprofile to a URI string.
 
const char * ast_geoloc_eprofiles_to_pidf (struct ast_datastore *ds, struct ast_channel *chan, struct ast_str **buf, const char *ref_string)
 Convert a datastore containing eprofiles to a PIDF-LO document.
 

Macro Definition Documentation

◆ AST_GEOLOC_INVALID_VALUE

#define AST_GEOLOC_INVALID_VALUE   -1

Definition at line 28 of file res_geolocation.h.

◆ CONFIG_STR_TO_ENUM_DECL

#define CONFIG_STR_TO_ENUM_DECL (   _stem)    int ast_geoloc_ ## _stem ## _str_to_enum(const char *str);

Definition at line 53 of file res_geolocation.h.

◆ GEOLOC_ENUM_TO_NAME_DECL

#define GEOLOC_ENUM_TO_NAME_DECL (   _stem)    const char * ast_geoloc_ ## _stem ## _to_name(int ix);

Definition at line 57 of file res_geolocation.h.

Enumeration Type Documentation

◆ ast_geoloc_format

Enumerator
AST_GEOLOC_FORMAT_NONE 
AST_GEOLOC_FORMAT_CIVIC_ADDRESS 
AST_GEOLOC_FORMAT_GML 
AST_GEOLOC_FORMAT_URI 
AST_GEOLOC_FORMAT_LAST 

Definition at line 38 of file res_geolocation.h.

38 {
44};
@ AST_GEOLOC_FORMAT_GML
@ AST_GEOLOC_FORMAT_CIVIC_ADDRESS
@ AST_GEOLOC_FORMAT_LAST
@ AST_GEOLOC_FORMAT_URI
@ AST_GEOLOC_FORMAT_NONE

◆ ast_geoloc_pidf_element

Enumerator
AST_PIDF_ELEMENT_NONE 
AST_PIDF_ELEMENT_DEVICE 
AST_PIDF_ELEMENT_TUPLE 
AST_PIDF_ELEMENT_PERSON 
AST_PIDF_ELEMENT_LAST 

Definition at line 30 of file res_geolocation.h.

30 {
36};
@ AST_PIDF_ELEMENT_PERSON
@ AST_PIDF_ELEMENT_TUPLE
@ AST_PIDF_ELEMENT_DEVICE
@ AST_PIDF_ELEMENT_NONE
@ AST_PIDF_ELEMENT_LAST

◆ ast_geoloc_precedence

Enumerator
AST_GEOLOC_PRECED_PREFER_INCOMING 
AST_GEOLOC_PRECED_PREFER_CONFIG 
AST_GEOLOC_PRECED_DISCARD_INCOMING 
AST_GEOLOC_PRECED_DISCARD_CONFIG 

Definition at line 46 of file res_geolocation.h.

◆ ast_geoloc_validate_result

Enumerator
AST_GEOLOC_VALIDATE_SUCCESS 
AST_GEOLOC_VALIDATE_MISSING_SHAPE 
AST_GEOLOC_VALIDATE_INVALID_SHAPE 
AST_GEOLOC_VALIDATE_INVALID_VARNAME 
AST_GEOLOC_VALIDATE_NOT_ENOUGH_VARNAMES 
AST_GEOLOC_VALIDATE_TOO_MANY_VARNAMES 
AST_GEOLOC_VALIDATE_INVALID_CRS 
AST_GEOLOC_VALIDATE_INVALID_CRS_FOR_SHAPE 
AST_GEOLOC_VALIDATE_INVALID_VALUE 

Definition at line 156 of file res_geolocation.h.

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
#define ARRAY_LEN(a)
Definition utils.h:706

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,
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 = ast_strdup(var->name);
84 }
85 }
87}
#define var
Definition ast_expr2f.c:605
#define ast_strdup(str)
A wrapper for strdup()
Definition astmm.h:241
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.
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, ast_strdup, result, and var.

Referenced by validate_location_info().

◆ ast_geoloc_datastore_add_eprofile()

int ast_geoloc_datastore_add_eprofile ( struct ast_datastore ds,
struct ast_geoloc_eprofile eprofile 
)

Add an eprofile to a datastore.

Parameters
dsThe datastore
eprofileThe eprofile to add.
Returns
The new number of eprofiles or -1 to indicate a failure.

Definition at line 135 of file geoloc_datastore.c.

137{
138 struct eprofiles_datastore *eds = NULL;
139 int rc = 0;
140
141 if (!IS_GEOLOC_DS(ds) || !eprofile) {
142 return -1;
143 }
144
145 eds = ds->data;
146 rc = AST_VECTOR_APPEND(&eds->eprofiles, ao2_bump(eprofile));
147 if (rc != 0) {
148 ao2_ref(eprofile, -1);
149 ast_log(LOG_ERROR, "Couldn't add eprofile '%s' to geoloc datastore '%s'\n", eprofile->id, eds->id);
150 return -1;
151 }
152
153 return AST_VECTOR_SIZE(&eds->eprofiles);
154}
#define ast_log
Definition astobj2.c:42
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition astobj2.h:459
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition astobj2.h:480
#define IS_GEOLOC_DS(_ds)
#define LOG_ERROR
void * data
Definition datastore.h:66
const ast_string_field id
struct eprofiles_datastore::geoloc_eprofiles eprofiles
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition vector.h:620
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition vector.h:267

References ao2_bump, ao2_ref, ast_log, AST_VECTOR_APPEND, AST_VECTOR_SIZE, ast_datastore::data, eprofiles_datastore::eprofiles, ast_geoloc_eprofile::id, eprofiles_datastore::id, IS_GEOLOC_DS, LOG_ERROR, and NULL.

Referenced by add_eprofile_to_channel(), ast_geoloc_datastore_create_from_eprofile(), ast_geoloc_datastore_create_from_profile_name(), and geoloc_profile_write().

◆ ast_geoloc_datastore_create()

struct ast_datastore * ast_geoloc_datastore_create ( const char *  id)

Create an empty geoloc datastore.

Parameters
idAn id to use for the datastore.
Returns
The datastore.

Definition at line 99 of file geoloc_datastore.c.

100{
101 struct ast_datastore *ds = NULL;
102 struct eprofiles_datastore *eds = NULL;
103 int rc = 0;
104
105 if (ast_strlen_zero(id)) {
106 ast_log(LOG_ERROR, "A geoloc datastore can't be allocated with a NULL or empty id\n");
107 return NULL;
108 }
109
111 if (!ds) {
112 ast_log(LOG_ERROR, "Geoloc datastore '%s' couldn't be allocated\n", id);
113 return NULL;
114 }
115
116 eds = ast_calloc(1, sizeof(*eds));
117 if (!eds) {
119 ast_log(LOG_ERROR, "Private structure for geoloc datastore '%s' couldn't be allocated\n", id);
120 return NULL;
121 }
122 ds->data = eds;
123
124
125 rc = AST_VECTOR_INIT(&eds->eprofiles, 2);
126 if (rc != 0) {
128 ast_log(LOG_ERROR, "Vector for geoloc datastore '%s' couldn't be initialized\n", id);
129 return NULL;
130 }
131
132 return ds;
133}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition astmm.h:202
#define ast_datastore_alloc(info, uid)
Definition datastore.h:85
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
Definition datastore.c:68
static const struct ast_datastore_info geoloc_datastore_info
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
Structure for a data store object.
Definition datastore.h:64
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition vector.h:124

References ast_calloc, ast_datastore_alloc, ast_datastore_free(), ast_log, ast_strlen_zero(), AST_VECTOR_INIT, ast_datastore::data, eprofiles_datastore::eprofiles, geoloc_datastore_info, LOG_ERROR, and NULL.

Referenced by add_eprofile_to_channel(), ast_geoloc_datastore_create_from_eprofile(), ast_geoloc_datastore_create_from_profile_name(), and geoloc_profile_write().

◆ ast_geoloc_datastore_create_from_eprofile()

struct ast_datastore * ast_geoloc_datastore_create_from_eprofile ( struct ast_geoloc_eprofile eprofile)

Create a geoloc datastore from an effective profile.

Parameters
eprofileThe effective profile to use.
Returns
The datastore.

Definition at line 242 of file geoloc_datastore.c.

244{
245 struct ast_datastore *ds;
246 int rc = 0;
247
248 if (!eprofile) {
249 return NULL;
250 }
251
252 ds = ast_geoloc_datastore_create(eprofile->id);
253 if (!ds) {
254 return NULL;
255 }
256
257 rc = ast_geoloc_datastore_add_eprofile(ds, eprofile);
258 if (rc <= 0) {
260 ds = NULL;
261 }
262
263 return ds;
264}
struct ast_datastore * ast_geoloc_datastore_create(const char *id)
Create an empty geoloc datastore.
int ast_geoloc_datastore_add_eprofile(struct ast_datastore *ds, struct ast_geoloc_eprofile *eprofile)
Add an eprofile to a datastore.

References ast_datastore_free(), ast_geoloc_datastore_add_eprofile(), ast_geoloc_datastore_create(), ast_geoloc_eprofile::id, and NULL.

◆ ast_geoloc_datastore_create_from_profile_name()

struct ast_datastore * ast_geoloc_datastore_create_from_profile_name ( const char *  profile_name)

Geolocation datastore Functions.

Create a geoloc datastore from a profile name

Parameters
profile_nameThe name of the profile to use.
Returns
The datastore.

Definition at line 266 of file geoloc_datastore.c.

267{
268 struct ast_datastore *ds = NULL;
269 struct ast_geoloc_eprofile *eprofile = NULL;
270 struct ast_geoloc_profile *profile = NULL;
271 int rc = 0;
272
273 if (ast_strlen_zero(profile_name)) {
274 return NULL;
275 }
276
277 profile = ast_sorcery_retrieve_by_id(geoloc_sorcery, "profile", profile_name);
278 if (!profile) {
279 ast_log(LOG_ERROR, "A profile with the name '%s' was not found\n", profile_name);
280 return NULL;
281 }
282
283 ds = ast_geoloc_datastore_create(profile_name);
284 if (!ds) {
285 ast_log(LOG_ERROR, "A datastore couldn't be allocated for profile '%s'\n", profile_name);
286 ao2_ref(profile, -1);
287 return NULL;
288 }
289
290 eprofile = ast_geoloc_eprofile_create_from_profile(profile);
291 ao2_ref(profile, -1);
292 if (!eprofile) {
294 ast_log(LOG_ERROR, "An effective profile with the name '%s' couldn't be allocated\n", profile_name);
295 return NULL;
296 }
297
298 rc = ast_geoloc_datastore_add_eprofile(ds, eprofile);
299 ao2_ref(eprofile, -1);
300 if (rc <= 0) {
302 ds = NULL;
303 }
304
305 return ds;
306}
struct ast_sorcery * geoloc_sorcery
struct ast_geoloc_eprofile * ast_geoloc_eprofile_create_from_profile(struct ast_geoloc_profile *profile)
Allocate a new effective profile from an existing profile.
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition sorcery.c:1917

References ao2_ref, ast_datastore_free(), ast_geoloc_datastore_add_eprofile(), ast_geoloc_datastore_create(), ast_geoloc_eprofile_create_from_profile(), ast_log, ast_sorcery_retrieve_by_id(), ast_strlen_zero(), geoloc_sorcery, LOG_ERROR, and NULL.

◆ ast_geoloc_datastore_delete_eprofile()

int ast_geoloc_datastore_delete_eprofile ( struct ast_datastore ds,
int  ix 
)

Delete a specific eprofile from a datastore by index.

Parameters
dsThe datastore
ixThe index
Returns
0 if succesful, -1 otherwise.

Definition at line 224 of file geoloc_datastore.c.

225{
226 struct eprofiles_datastore *eds = NULL;
227
228 if (!IS_GEOLOC_DS(ds)) {
229 return -1;
230 }
231
232 eds = ds->data;
233
234 if (ix >= AST_VECTOR_SIZE(&eds->eprofiles)) {
235 return -1;
236 }
237
238 ao2_ref(AST_VECTOR_REMOVE(&eds->eprofiles, ix, 1), -1);
239 return 0;
240}
#define AST_VECTOR_REMOVE(vec, idx, preserve_ordered)
Remove an element from a vector by index.
Definition vector.h:423

References ao2_ref, AST_VECTOR_REMOVE, AST_VECTOR_SIZE, ast_datastore::data, eprofiles_datastore::eprofiles, IS_GEOLOC_DS, and NULL.

◆ ast_geoloc_datastore_find()

struct ast_datastore * ast_geoloc_datastore_find ( struct ast_channel chan)

Retrieves the geoloc datastore from a channel, if any.

Parameters
chanChannel
Returns
datastore if found, NULL otherwise.

Definition at line 219 of file geoloc_datastore.c.

220{
222}
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Definition channel.c:2389

References ast_channel_datastore_find(), geoloc_datastore_info, and NULL.

Referenced by geoloc_profile_read(), geoloc_profile_write(), and handle_outgoing_request().

◆ ast_geoloc_datastore_get_eprofile()

struct ast_geoloc_eprofile * ast_geoloc_datastore_get_eprofile ( struct ast_datastore ds,
int  ix 
)

Retrieve a specific eprofile from a datastore by index.

Parameters
dsThe datastore
ixThe index
Returns
The effective profile ao2 object with its reference count bumped.

Definition at line 200 of file geoloc_datastore.c.

201{
202 struct eprofiles_datastore *eds = NULL;
203 struct ast_geoloc_eprofile *eprofile;
204
205 if (!IS_GEOLOC_DS(ds)) {
206 return NULL;
207 }
208
209 eds = ds->data;
210
211 if (ix >= AST_VECTOR_SIZE(&eds->eprofiles)) {
212 return NULL;
213 }
214
215 eprofile = AST_VECTOR_GET(&eds->eprofiles, ix);
216 return ao2_bump(eprofile);
217}
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition vector.h:691

References ao2_bump, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_datastore::data, eprofiles_datastore::eprofiles, IS_GEOLOC_DS, and NULL.

Referenced by ast_geoloc_eprofiles_to_pidf(), geoloc_profile_read(), geoloc_profile_write(), and handle_outgoing_request().

◆ ast_geoloc_datastore_get_id()

const char * ast_geoloc_datastore_get_id ( struct ast_datastore ds)

Retrieve a geoloc datastore's id.

Parameters
dsThe datastore
Returns
The datastore's id.

Definition at line 86 of file geoloc_datastore.c.

87{
88 struct eprofiles_datastore *eds = NULL;
89
90 if (!IS_GEOLOC_DS(ds)) {
91 return NULL;
92 }
93
94 eds = (struct eprofiles_datastore *)ds->data;
95
96 return eds->id;
97}

References ast_datastore::data, eprofiles_datastore::id, IS_GEOLOC_DS, and NULL.

◆ ast_geoloc_datastore_insert_eprofile()

int ast_geoloc_datastore_insert_eprofile ( struct ast_datastore ds,
struct ast_geoloc_eprofile eprofile,
int  index 
)

Insert an eprofile to a datastore at the specified position.

Parameters
dsThe datastore
eprofileThe eprofile to add.
indexThe position to insert at. Existing eprofiles will be moved up to make room.
Returns
The new number of eprofiles or -1 to indicate a failure.

Definition at line 156 of file geoloc_datastore.c.

158{
159 struct eprofiles_datastore *eds = NULL;
160 int rc = 0;
161
162 if (!IS_GEOLOC_DS(ds) || !eprofile) {
163 return -1;
164 }
165
166 eds = ds->data;
167 rc = AST_VECTOR_INSERT_AT(&eds->eprofiles, index, ao2_bump(eprofile));
168 if (rc != 0) {
169 ao2_ref(eprofile, -1);
170 ast_log(LOG_ERROR, "Couldn't add eprofile '%s' to geoloc datastore '%s' in position '%d'\n",
171 eprofile->id, eds->id, index);
172 return -1;
173 }
174
175 return AST_VECTOR_SIZE(&eds->eprofiles);
176}
#define AST_VECTOR_INSERT_AT(vec, idx, elem)
Insert an element at a specific position in a vector, growing the vector if needed.
Definition vector.h:349

References ao2_bump, ao2_ref, ast_log, AST_VECTOR_INSERT_AT, AST_VECTOR_SIZE, ast_datastore::data, eprofiles_datastore::eprofiles, ast_geoloc_eprofile::id, eprofiles_datastore::id, IS_GEOLOC_DS, LOG_ERROR, and NULL.

◆ ast_geoloc_datastore_set_inheritance()

int ast_geoloc_datastore_set_inheritance ( struct ast_datastore ds,
int  inherit 
)

Sets the inheritance flag on the datastore.

Parameters
dsThe datastore
inherit1 to allow the datastore to be inherited by other channels 0 to prevent the datastore to be inherited by other channels
Returns
0 if successful, -1 otherwise.

Definition at line 191 of file geoloc_datastore.c.

192{
193 if (!IS_GEOLOC_DS(ds)) {
194 return -1;
195 }
196 ds->inheritance = inherit ? DATASTORE_INHERIT_FOREVER : 0;
197 return 0;
198}
#define DATASTORE_INHERIT_FOREVER
Definition channel.h:194
unsigned int inheritance
Definition datastore.h:69

References DATASTORE_INHERIT_FOREVER, ast_datastore::inheritance, and IS_GEOLOC_DS.

Referenced by add_eprofile_to_channel(), and geoloc_profile_write().

◆ ast_geoloc_datastore_size()

int ast_geoloc_datastore_size ( struct ast_datastore ds)

Retrieves the number of eprofiles in the datastore.

Parameters
dsThe datastore
Returns
The number of eprofiles.

Definition at line 178 of file geoloc_datastore.c.

179{
180 struct eprofiles_datastore *eds = NULL;
181
182 if (!IS_GEOLOC_DS(ds)) {
183 return -1;
184 }
185
186 eds = ds->data;
187
188 return AST_VECTOR_SIZE(&eds->eprofiles);
189}

References AST_VECTOR_SIZE, ast_datastore::data, eprofiles_datastore::eprofiles, IS_GEOLOC_DS, and NULL.

Referenced by ast_geoloc_eprofiles_to_pidf(), and handle_outgoing_request().

◆ ast_geoloc_eprofile_alloc()

struct ast_geoloc_eprofile * ast_geoloc_eprofile_alloc ( const char *  name)

Geolocation Effective Profile Functions.

Allocate a new, empty effective profile.

Parameters
nameThe profile's name
Returns
The effective profile ao2 object.

Definition at line 69 of file geoloc_eprofile.c.

70{
71 struct ast_geoloc_eprofile *eprofile = ao2_alloc_options(sizeof(*eprofile),
73
74 ast_string_field_init(eprofile, 256);
75 ast_string_field_set(eprofile, id, name); /* SAFE string fields handle NULL */
76
77 return eprofile;
78}
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition astobj2.h:367
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition astobj2.h:404
static const char name[]
Definition format_mp3.c:68
static void geoloc_eprofile_destructor(void *obj)
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ast_string_field_init, ast_string_field_set, geoloc_eprofile_destructor(), and name.

Referenced by ast_geoloc_eprofile_create_from_profile(), ast_geoloc_eprofile_create_from_uri(), ast_geoloc_eprofile_dup(), geoloc_eprofile_create_from_xslt_result(), and geoloc_profile_write().

◆ ast_geoloc_eprofile_create_from_pidf()

struct ast_geoloc_eprofile * ast_geoloc_eprofile_create_from_pidf ( struct ast_xml_doc *  pidf_xmldoc,
const char *  geoloc_uri,
const char *  reference_string 
)

Allocate a new effective profile from an XML PIDF-LO document.

Parameters
pidf_xmldocThe ast_xml_doc to use.
geoloc_uriThe URI that referenced this document.
reference_stringAn identifying string to use in error messages.
Returns
The effective profile ao2 object.

Definition at line 805 of file geoloc_eprofile.c.

807{
808 struct ast_xml_doc *result_doc = NULL;
809 struct ast_geoloc_eprofile *eprofile = NULL;
810
811 SCOPE_ENTER(3, "%s\n", ref_str);
812
813 result_doc = ast_xslt_apply(pidf_to_eprofile_xslt, pidf_xmldoc, NULL);
814 if (!is_pidf_lo(result_doc)) {
815 SCOPE_EXIT_RTN_VALUE(NULL, "%s: Not a PIDF-LO. Skipping.\n", ref_str);
816 }
817
818 /*
819 * The document returned from the stylesheet application looks like this...
820 * <presence id="presence-entity">
821 * <tuple id="element-id">
822 * <location-info format="gml">shape="Ellipsoid", crs="3d", ...</location-info>
823 * <usage-rules>retransmission-allowed="no", retention-expiry="2010-11-14T20:00:00Z"</usage-rules>
824 * <method>Hybrid_A-GPS</method>
825 * </tuple>
826 * </presence>
827 *
828 * Regardless of whether the pidf-element was tuple, device or person and whether
829 * the format is gml or civicAddress, the presence, pidf-element and location-info
830 * elements should be there.
831 *
832 * The confidence, usage-rules and note-well elements are optional.
833 */
834
835 if (TRACE_ATLEAST(5)) {
836 char *doc_str = NULL;
837 int doc_len = 0;
838
839 ast_xml_doc_dump_memory(result_doc, &doc_str, &doc_len);
840 ast_trace(5, "Intermediate doc len: %d\n%s\n", doc_len, doc_len ? doc_str : "<empty>");
841 ast_xml_free_text(doc_str);
842 doc_str = NULL;
843 doc_len = 0;
844 }
845
846 eprofile = geoloc_eprofile_create_from_xslt_result(result_doc, ref_str);
847 ast_xml_close(result_doc);
848
849 if (eprofile && geoloc_uri) {
850 set_loc_src(eprofile, geoloc_uri, ref_str);
851 }
852
853 SCOPE_EXIT_RTN_VALUE(eprofile, "%s: Done.\n", ref_str);
854}
static struct ast_xslt_doc * pidf_to_eprofile_xslt
static int set_loc_src(struct ast_geoloc_eprofile *eprofile, const char *uri, const char *ref_str)
static int is_pidf_lo(struct ast_xml_doc *result_doc)
static struct ast_geoloc_eprofile * geoloc_eprofile_create_from_xslt_result(struct ast_xml_doc *result_doc, const char *ref_str)
#define TRACE_ATLEAST(level)
#define SCOPE_EXIT_RTN_VALUE(__return_value,...)
#define SCOPE_ENTER(level,...)
#define ast_trace(level,...)
void ast_xml_close(struct ast_xml_doc *doc)
Close an already open document and free the used structure.
Definition xml.c:211
void ast_xml_doc_dump_memory(struct ast_xml_doc *doc, char **buffer, int *length)
Dump the specified document to a buffer.
Definition xml.c:385
void ast_xml_free_text(const char *text)
Free a content element that was returned by ast_xml_get_text()
Definition xml.c:260

References ast_trace, ast_xml_close(), ast_xml_doc_dump_memory(), ast_xml_free_text(), geoloc_eprofile_create_from_xslt_result(), is_pidf_lo(), NULL, pidf_to_eprofile_xslt, SCOPE_ENTER, SCOPE_EXIT_RTN_VALUE, set_loc_src(), and TRACE_ATLEAST.

Referenced by handle_incoming_request().

◆ ast_geoloc_eprofile_create_from_profile()

struct ast_geoloc_eprofile * ast_geoloc_eprofile_create_from_profile ( struct ast_geoloc_profile profile)

Allocate a new effective profile from an existing profile.

Parameters
profileThe profile to use.
Returns
The effective profile ao2 object.

Definition at line 226 of file geoloc_eprofile.c.

227{
228 struct ast_geoloc_eprofile *eprofile;
229 const char *profile_id;
230 int rc = 0;
231
232 if (!profile) {
233 return NULL;
234 }
235
236 profile_id = ast_sorcery_object_get_id(profile);
237
238 eprofile = ast_geoloc_eprofile_alloc(profile_id);
239 if (!eprofile) {
240 return NULL;
241 }
242
243 ao2_lock(profile);
244 eprofile->allow_routing_use = profile->allow_routing_use;
245 eprofile->pidf_element = profile->pidf_element;
247 eprofile->format = profile->format;
248
250 if (rc == 0) {
251 rc = ast_string_field_set(eprofile, pidf_element_id, profile->pidf_element_id);
252 }
253 if (rc == 0) {
254 ast_string_field_set(eprofile, notes, profile->notes);
255 }
256 if (rc == 0) {
257 ast_string_field_set(eprofile, method, profile->method);
258 }
259 if (rc == 0) {
261 }
262 if (rc == 0) {
263 rc = DUP_VARS(eprofile->location_info, profile->location_info);
264 }
265 if (rc == 0) {
266 rc = DUP_VARS(eprofile->location_refinement, profile->location_refinement);
267 }
268 if (rc == 0) {
269 rc = DUP_VARS(eprofile->location_variables, profile->location_variables);
270 }
271 if (rc == 0) {
272 rc = DUP_VARS(eprofile->usage_rules, profile->usage_rules);
273 }
274 if (rc == 0) {
275 rc = DUP_VARS(eprofile->confidence, profile->confidence);
276 }
277 if (rc == 0) {
278 rc = ast_string_field_set(eprofile, device_id, profile->device_id);
279 }
280 if (rc != 0) {
281 ao2_unlock(profile);
282 ao2_ref(eprofile, -1);
283 return NULL;
284 }
285
286 eprofile->precedence = profile->precedence;
287 ao2_unlock(profile);
288
289 if (ast_geoloc_eprofile_refresh_location(eprofile) != 0) {
290 ao2_ref(eprofile, -1);
291 return NULL;
292 }
293
294 return eprofile;
295}
#define ao2_unlock(a)
Definition astobj2.h:729
#define ao2_lock(a)
Definition astobj2.h:717
int ast_geoloc_eprofile_refresh_location(struct ast_geoloc_eprofile *eprofile)
Refresh the effective profile with any changed info.
struct ast_geoloc_eprofile * ast_geoloc_eprofile_alloc(const char *name)
Geolocation Effective Profile Functions.
#define DUP_VARS(_dest, _source)
static int notes
Definition pval.c:66
const char * method
Definition res_pjsip.c:1273
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
Definition sorcery.c:2381
const ast_string_field location_reference
enum ast_geoloc_format format
enum ast_geoloc_pidf_element pidf_element
struct ast_variable * location_refinement
const ast_string_field device_id
enum ast_geoloc_precedence precedence
struct ast_variable * location_variables
struct ast_variable * confidence
struct ast_variable * usage_rules
const ast_string_field location_source
const ast_string_field pidf_element_id
struct ast_variable * location_info
const ast_string_field location_reference
enum ast_geoloc_format format
enum ast_geoloc_pidf_element pidf_element
const ast_string_field method
struct ast_variable * location_refinement
const ast_string_field device_id
enum ast_geoloc_precedence precedence
const ast_string_field notes
struct ast_variable * location_variables
struct ast_variable * confidence
struct ast_variable * usage_rules
const ast_string_field location_source
const ast_string_field pidf_element_id
struct ast_variable * location_info

References ast_geoloc_profile::allow_routing_use, ast_geoloc_eprofile::allow_routing_use, ao2_lock, ao2_ref, ao2_unlock, ast_geoloc_eprofile_alloc(), ast_geoloc_eprofile_refresh_location(), ast_sorcery_object_get_id(), ast_string_field_set, ast_geoloc_profile::confidence, ast_geoloc_eprofile::confidence, ast_geoloc_profile::device_id, ast_geoloc_eprofile::device_id, DUP_VARS, ast_geoloc_profile::format, ast_geoloc_eprofile::format, ast_geoloc_profile::location_info, ast_geoloc_eprofile::location_info, ast_geoloc_profile::location_reference, ast_geoloc_eprofile::location_reference, ast_geoloc_profile::location_refinement, ast_geoloc_eprofile::location_refinement, ast_geoloc_profile::location_source, ast_geoloc_eprofile::location_source, ast_geoloc_profile::location_variables, ast_geoloc_eprofile::location_variables, ast_geoloc_profile::method, method, ast_geoloc_profile::notes, notes, NULL, ast_geoloc_profile::pidf_element, ast_geoloc_eprofile::pidf_element, ast_geoloc_profile::pidf_element_id, ast_geoloc_eprofile::pidf_element_id, ast_geoloc_profile::precedence, ast_geoloc_eprofile::precedence, ast_geoloc_profile::suppress_empty_ca_elements, ast_geoloc_eprofile::suppress_empty_ca_elements, ast_geoloc_profile::usage_rules, and ast_geoloc_eprofile::usage_rules.

Referenced by ast_geoloc_datastore_create_from_profile_name(), geoloc_config_show_profiles(), handle_incoming_request(), and handle_outgoing_request().

◆ ast_geoloc_eprofile_create_from_uri()

struct ast_geoloc_eprofile * ast_geoloc_eprofile_create_from_uri ( const char *  uri,
const char *  reference_string 
)

Allocate a new effective profile from a URI.

Parameters
uriThe URI to use.
reference_stringAn identifying string to use in error messages.
Returns
The effective profile ao2 object.

Definition at line 327 of file geoloc_eprofile.c.

329{
330 struct ast_geoloc_eprofile *eprofile = NULL;
331 char *ra = NULL;
332 char *local_uri;
333
334 if (ast_strlen_zero(uri)) {
335 return NULL;
336 }
337 local_uri = ast_strdupa(uri);
338
339 if (local_uri[0] == '<') {
340 local_uri++;
341 }
342 ra = strchr(local_uri, '>');
343 if (ra) {
344 *ra = '\0';
345 }
346
347 ast_strip(local_uri);
348
349 eprofile = ast_geoloc_eprofile_alloc(local_uri);
350 if (!eprofile) {
351 return NULL;
352 }
353
354 set_loc_src(eprofile, uri, ref_str);
355
356 eprofile->format = AST_GEOLOC_FORMAT_URI;
357 eprofile->location_info = ast_variable_new("URI", local_uri, "");
358
359 return eprofile;
360}
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition astmm.h:298
#define ast_variable_new(name, value, filename)
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition strings.h:223

References ast_geoloc_eprofile_alloc(), AST_GEOLOC_FORMAT_URI, ast_strdupa, ast_strip(), ast_strlen_zero(), ast_variable_new, ast_geoloc_eprofile::format, ast_geoloc_eprofile::location_info, NULL, and set_loc_src().

Referenced by handle_incoming_request().

◆ ast_geoloc_eprofile_dup()

struct ast_geoloc_eprofile * ast_geoloc_eprofile_dup ( struct ast_geoloc_eprofile src)

Duplicate an effective profile.

Parameters
srcThe eprofile to duplicate.
Returns
The duplicated effective profile ao2 object.

Definition at line 159 of file geoloc_eprofile.c.

160{
161 struct ast_geoloc_eprofile *eprofile;
162 const char *profile_id;
163 int rc = 0;
164
165 if (!src) {
166 return NULL;
167 }
168
169 profile_id = ast_strdupa(src->id);
170
171 eprofile = ast_geoloc_eprofile_alloc(profile_id);
172 if (!eprofile) {
173 return NULL;
174 }
175
176 eprofile->allow_routing_use = src->allow_routing_use;
177 eprofile->pidf_element = src->pidf_element;
179 eprofile->format = src->format;
180 eprofile->precedence = src->precedence;
181
182
184 if (rc == 0) {
186 }
187 if (rc == 0) {
188 ast_string_field_set(eprofile, notes, src->notes);
189 }
190 if (rc == 0) {
191 ast_string_field_set(eprofile, method, src->method);
192 }
193 if (rc == 0) {
195 }
196 if (rc == 0) {
197 rc = DUP_VARS(eprofile->location_info, src->location_info);
198 }
199 if (rc == 0) {
200 rc = DUP_VARS(eprofile->effective_location, src->effective_location);
201 }
202 if (rc == 0) {
204 }
205 if (rc == 0) {
206 rc = DUP_VARS(eprofile->location_variables, src->location_variables);
207 }
208 if (rc == 0) {
209 rc = DUP_VARS(eprofile->usage_rules, src->usage_rules);
210 }
211 if (rc == 0) {
212 rc = DUP_VARS(eprofile->confidence, src->confidence);
213 }
214 if (rc == 0) {
215 rc = ast_string_field_set(eprofile, device_id, src->device_id);
216 }
217 if (rc != 0) {
218 ao2_ref(eprofile, -1);
219 return NULL;
220 }
221
222
223 return eprofile;
224}
struct ast_variable * effective_location
const ast_string_field method
const ast_string_field notes

References ast_geoloc_eprofile::allow_routing_use, ao2_ref, ast_geoloc_eprofile_alloc(), ast_strdupa, ast_string_field_set, ast_geoloc_eprofile::confidence, ast_geoloc_eprofile::device_id, DUP_VARS, ast_geoloc_eprofile::effective_location, ast_geoloc_eprofile::format, ast_geoloc_eprofile::id, ast_geoloc_eprofile::location_info, ast_geoloc_eprofile::location_reference, ast_geoloc_eprofile::location_refinement, ast_geoloc_eprofile::location_source, ast_geoloc_eprofile::location_variables, ast_geoloc_eprofile::method, method, ast_geoloc_eprofile::notes, notes, NULL, ast_geoloc_eprofile::pidf_element, ast_geoloc_eprofile::pidf_element_id, ast_geoloc_eprofile::precedence, ast_geoloc_eprofile::suppress_empty_ca_elements, and ast_geoloc_eprofile::usage_rules.

Referenced by geoloc_profile_read().

◆ ast_geoloc_eprofile_refresh_location()

int ast_geoloc_eprofile_refresh_location ( struct ast_geoloc_eprofile eprofile)

Refresh the effective profile with any changed info.

Parameters
eprofileThe eprofile to refresh.
Returns
0 on success, any other value on error.

Definition at line 80 of file geoloc_eprofile.c.

81{
82 struct ast_geoloc_location *loc = NULL;
83 RAII_VAR(struct ast_variable *, temp_locinfo, NULL, ast_variables_destroy);
84 RAII_VAR(struct ast_variable *, temp_effloc, NULL, ast_variables_destroy);
85 RAII_VAR(struct ast_variable *, temp_confidence, NULL, ast_variables_destroy);
86 const char *method = NULL;
87 const char *location_source = NULL;
89 struct ast_variable *var;
90 int rc = 0;
91
92 if (!eprofile) {
93 return -1;
94 }
95
96 if (!ast_strlen_zero(eprofile->location_reference)) {
98 if (!loc) {
99 ast_log(LOG_ERROR, "Profile '%s' referenced location '%s' does not exist!", eprofile->id,
100 eprofile->location_reference);
101 return -1;
102 }
103
104 format = loc->format;
105 method = loc->method;
106 location_source = loc->location_source;
107 rc = DUP_VARS(temp_locinfo, loc->location_info);
108 if (rc == 0) {
109 rc = DUP_VARS(temp_confidence, loc->confidence);
110 }
111 ao2_ref(loc, -1);
112 if (rc != 0) {
113 return -1;
114 }
115 } else {
116 format = eprofile->format;
117 method = eprofile->method;
118 location_source = eprofile->location_source;
119 rc = DUP_VARS(temp_locinfo, eprofile->location_info);
120 if (rc == 0) {
121 rc = DUP_VARS(temp_confidence, eprofile->confidence);
122 }
123 if (rc != 0) {
124 return -1;
125 }
126 }
127
128 rc = DUP_VARS(temp_effloc, temp_locinfo);
129 if (rc != 0) {
130 return -1;
131 }
132
133 if (eprofile->location_refinement) {
134 for (var = eprofile->location_refinement; var; var = var->next) {
135 struct ast_variable *newvar = ast_variable_new(var->name, var->value, "");
136 if (!newvar) {
137 return -1;
138 }
139 if (ast_variable_list_replace(&temp_effloc, newvar)) {
140 ast_variable_list_append(&temp_effloc, newvar);
141 }
142 }
143 }
144
145 eprofile->format = format;
147 ast_string_field_set(eprofile, location_source, location_source);
148
150 eprofile->location_info = temp_locinfo;
151 temp_locinfo = NULL;
153 eprofile->effective_location = temp_effloc;
154 temp_effloc = NULL;
155
156 return 0;
157}
static struct ast_sorcery * geoloc_sorcery
#define ast_variable_list_append(head, new_var)
int ast_variable_list_replace(struct ast_variable **head, struct ast_variable *replacement)
Replace a variable in the given list with a new value.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition extconf.c:1260
ast_geoloc_format
enum ast_geoloc_format format
const ast_string_field method
struct ast_variable * confidence
const ast_string_field location_source
struct ast_variable * location_info
#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:981

References ao2_ref, ast_log, ast_sorcery_retrieve_by_id(), ast_string_field_set, ast_strlen_zero(), ast_variable_list_append, ast_variable_list_replace(), ast_variable_new, ast_variables_destroy(), ast_geoloc_location::confidence, ast_geoloc_eprofile::confidence, DUP_VARS, ast_geoloc_eprofile::effective_location, ast_geoloc_location::format, ast_geoloc_eprofile::format, geoloc_sorcery, ast_geoloc_eprofile::id, ast_geoloc_location::location_info, ast_geoloc_eprofile::location_info, ast_geoloc_eprofile::location_reference, ast_geoloc_eprofile::location_refinement, ast_geoloc_location::location_source, ast_geoloc_eprofile::location_source, LOG_ERROR, ast_geoloc_location::method, ast_geoloc_eprofile::method, method, NULL, RAII_VAR, and var.

Referenced by ast_geoloc_eprofile_create_from_profile(), geoloc_profile_read(), geoloc_profile_write(), and handle_outgoing_request().

◆ ast_geoloc_eprofile_to_pidf()

const char * ast_geoloc_eprofile_to_pidf ( struct ast_geoloc_eprofile eprofile,
struct ast_channel chan,
struct ast_str **  buf,
const char *  ref_string 
)

Convert a single eprofile to a PIDF-LO document.

Parameters
eprofileEffective profile to convert
chanChannel to use to resolve variables
bufPointer to ast_str pointer to use for work
ref_stringAn identifying string to use in error messages.
Returns
String representation PIDF-LO allocated from buf or NULL on failure.

Definition at line 1215 of file geoloc_eprofile.c.

1217{
1218
1219 RAII_VAR(struct ast_xml_doc *, pidf_doc, NULL, ast_xml_close);
1220 char *doc_str = NULL;
1221 int doc_len = 0;
1222 int rc = 0;
1223 SCOPE_ENTER(3, "%s\n", ref_string);
1224
1225 pidf_doc = geoloc_eprofile_to_xmldoc(eprofile, chan, buf, ref_string);
1226 if (!pidf_doc) {
1227 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: Unable to create final PIDF-LO doc from intermediate doc\n",
1228 ref_string);
1229 }
1230
1231 ast_xml_doc_dump_memory(pidf_doc, &doc_str, &doc_len);
1232 if (doc_len == 0 || !doc_str) {
1233 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: Unable to dump final PIDF-LO doc to string\n",
1234 ref_string);
1235 }
1236
1237 rc = ast_str_set(buf, 0, "%s", doc_str);
1238 ast_xml_free_text(doc_str);
1239 if (rc <= 0) {
1240 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: Unable to extend buffer (%d)\n",
1241 ref_string, rc);
1242 }
1243
1244 ast_trace(5, "Final doc:\n%s\n", ast_str_buffer(*buf));
1245
1246 SCOPE_EXIT_RTN_VALUE(ast_str_buffer(*buf), "%s: Done\n", ref_string);
1247
1248}
char buf[BUFSIZE]
Definition eagi_proxy.c:66
static struct ast_xml_doc * geoloc_eprofile_to_xmldoc(struct ast_geoloc_eprofile *eprofile, struct ast_channel *chan, struct ast_str **buf, const char *ref_string)
#define SCOPE_EXIT_LOG_RTN_VALUE(__value, __log_level,...)
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition strings.h:1113
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition strings.h:761

References ast_str_buffer(), ast_str_set(), ast_trace, ast_xml_close(), ast_xml_doc_dump_memory(), ast_xml_free_text(), buf, geoloc_eprofile_to_xmldoc(), LOG_ERROR, NULL, RAII_VAR, SCOPE_ENTER, SCOPE_EXIT_LOG_RTN_VALUE, and SCOPE_EXIT_RTN_VALUE.

Referenced by add_eprofile_to_tdata().

◆ ast_geoloc_eprofile_to_uri()

const char * ast_geoloc_eprofile_to_uri ( struct ast_geoloc_eprofile eprofile,
struct ast_channel chan,
struct ast_str **  buf,
const char *  ref_string 
)

Convert a URI eprofile to a URI string.

Parameters
eprofileEffective profile to convert
chanChannel to use to resolve variables
bufPointer to ast_str pointer to use for work
ref_stringAn identifying string to use in error messages.
Returns
String representation of URI allocated from buf or NULL on failure

Definition at line 444 of file geoloc_eprofile.c.

446{
447 const char *uri = NULL;
448 struct ast_variable *resolved = NULL;
449 char *result;
450 int we_created_buf = 0;
451
452 if (!eprofile || !buf || !chan) {
453 return NULL;
454 }
455
456 if (eprofile->format != AST_GEOLOC_FORMAT_URI) {
457 ast_log(LOG_ERROR, "%s: '%s' is not a URI profile. It's '%s'\n",
458 ref_str, eprofile->id, ast_geoloc_format_to_name(eprofile->format));
459 return NULL;
460 }
461
463 eprofile->location_variables, chan);
464 if (!resolved) {
465 return NULL;
466 }
467
468 uri = ast_variable_find_in_list(resolved, "URI");
469 result = uri ? ast_strdupa(uri) : NULL;
470 ast_variables_destroy(resolved);
471
472 if (ast_strlen_zero(result)) {
473 ast_log(LOG_ERROR, "%s: '%s' is a URI profile but had no, or an empty, 'URI' entry in location_info\n",
474 ref_str, eprofile->id);
475 return NULL;
476 }
477
478 if (!*buf) {
479 *buf = ast_str_create(256);
480 if (!*buf) {
481 return NULL;
482 }
483 we_created_buf = 1;
484 }
485
486 if (ast_str_append(buf, 0, "%s", result) <= 0) {
487 if (we_created_buf) {
488 ast_free(*buf);
489 *buf = NULL;
490 return NULL;
491 }
492 }
493
494 return ast_str_buffer(*buf);
495}
#define ast_free(a)
Definition astmm.h:180
struct ast_variable * geoloc_eprofile_resolve_varlist(struct ast_variable *source, struct ast_variable *variables, struct ast_channel *chan)
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.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition strings.h:1139
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition strings.h:659

References ast_free, AST_GEOLOC_FORMAT_URI, ast_log, ast_str_append(), ast_str_buffer(), ast_str_create, ast_strdupa, ast_strlen_zero(), ast_variable_find_in_list(), ast_variables_destroy(), buf, ast_geoloc_eprofile::effective_location, ast_geoloc_eprofile::format, geoloc_eprofile_resolve_varlist(), ast_geoloc_eprofile::id, ast_geoloc_eprofile::location_variables, LOG_ERROR, NULL, and result.

Referenced by handle_outgoing_request().

◆ ast_geoloc_eprofiles_to_pidf()

const char * ast_geoloc_eprofiles_to_pidf ( struct ast_datastore ds,
struct ast_channel chan,
struct ast_str **  buf,
const char *  ref_string 
)

Convert a datastore containing eprofiles to a PIDF-LO document.

Parameters
dsDatastore containing effective profiles to convert
chanChannel to use to resolve variables
bufPointer to ast_str pointer to use for work
ref_stringAn identifying string to use in error messages.
Returns
String representation PIDF-LO allocated from buf or NULL on failure.

Definition at line 1033 of file geoloc_eprofile.c.

1035{
1036 RAII_VAR(struct ast_xml_doc *, intermediate, NULL, ast_xml_close);
1037 RAII_VAR(struct ast_xml_doc *, pidf_doc, NULL, ast_xml_close);
1038 struct ast_xml_node *root_node;
1039 struct ast_xml_node *pidfs[AST_PIDF_ELEMENT_LAST] = {NULL, };
1040 struct ast_geoloc_eprofile *eprofile;
1041 int eprofile_count = 0;
1042 int i;
1043 char *doc_str = NULL;
1044 int doc_len = 0;
1045 int rc = 0;
1046 SCOPE_ENTER(3, "%s\n", ref_string);
1047
1048 if (!ds || !chan || !buf || !*buf || ast_strlen_zero(ref_string)) {
1049 SCOPE_EXIT_RTN_VALUE(NULL, "%s: Either or both datastore or chan were NULL\n",
1050 ref_string);
1051 }
1052
1053 intermediate = ast_xml_new();
1054 if (!intermediate) {
1055 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: Unable to create XML document\n", ref_string);
1056 }
1057 root_node = ast_xml_new_node("presence");
1058 if (!root_node) {
1059 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: Unable to create root XML node\n", ref_string);
1060 }
1061 ast_xml_set_root(intermediate, root_node);
1062
1063 eprofile_count = ast_geoloc_datastore_size(ds);
1064 for (i = 0; i < eprofile_count; i++) {
1065 struct ast_xml_node *temp_node = NULL;
1066 struct ast_xml_node *curr_loc = NULL;
1067 struct ast_xml_node *new_loc = NULL;
1068 struct ast_xml_node *new_loc_child = NULL;
1069 struct ast_xml_node *new_loc_child_dup = NULL;
1070 const char *entity = NULL;
1071 int has_no_entity = 0;
1072 eprofile = ast_geoloc_datastore_get_eprofile(ds, i);
1073 if (eprofile->format == AST_GEOLOC_FORMAT_URI) {
1074 continue;
1075 }
1076
1077 entity = ast_xml_get_attribute(root_node, "entity");
1078 has_no_entity = ast_strlen_zero(entity);
1079 ast_xml_free_attr(entity);
1080 if (has_no_entity) {
1081 rc = ast_xml_set_attribute(root_node, "entity", eprofile->id);
1082 if (rc != 0) {
1083 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: Unable to set 'entity' XML attribute\n", ref_string);
1084 }
1085 }
1086
1087 temp_node = geoloc_eprofile_to_intermediate(ast_geoloc_pidf_element_to_name(eprofile->pidf_element),
1088 eprofile, chan, ref_string);
1089 if (!temp_node) {
1090 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: Unable to create temp_node\n", ref_string);
1091 }
1092
1093 if (!pidfs[eprofile->pidf_element]) {
1094 pidfs[eprofile->pidf_element] = temp_node;
1095 ast_xml_add_child(root_node, temp_node);
1096 continue;
1097 }
1098
1099 curr_loc = ast_xml_find_child_element(pidfs[eprofile->pidf_element], "location-info", NULL, NULL);
1100 new_loc = ast_xml_find_child_element(temp_node, "location-info", NULL, NULL);
1101 new_loc_child = ast_xml_node_get_children(new_loc);
1102 new_loc_child_dup = ast_xml_copy_node_list(new_loc_child);
1103 ast_xml_add_child_list(curr_loc, new_loc_child_dup);
1104
1105 ast_xml_free_node(temp_node);
1106 }
1107
1108 if (TRACE_ATLEAST(5)) {
1109 ast_xml_doc_dump_memory(intermediate, &doc_str, &doc_len);
1110 ast_trace(5, "Intermediate doc len: %d\n%s\n", doc_len, doc_len ? doc_str : "<empty>");
1111 ast_xml_free_text(doc_str);
1112 doc_str = NULL;
1113 doc_len = 0;
1114 }
1115
1116 pidf_doc = ast_xslt_apply(eprofile_to_pidf_xslt, intermediate, NULL);
1117 if (!pidf_doc) {
1118 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: Unable to create final PIDF-LO doc from intermediate docs\n",
1119 ref_string);
1120 }
1121
1122 ast_xml_doc_dump_memory(pidf_doc, &doc_str, &doc_len);
1123 if (doc_len == 0 || !doc_str) {
1124 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: Unable to dump final PIDF-LO doc to string\n",
1125 ref_string);
1126 }
1127
1128 rc = ast_str_set(buf, 0, "%s", doc_str);
1129 ast_xml_free_text(doc_str);
1130 if (rc <= 0) {
1131 SCOPE_EXIT_LOG_RTN_VALUE(NULL, LOG_ERROR, "%s: Unable to extend buffer (%d)\n",
1132 ref_string, rc);
1133 }
1134
1135 ast_trace(5, "Final doc:\n%s\n", ast_str_buffer(*buf));
1136
1137 SCOPE_EXIT_RTN_VALUE(ast_str_buffer(*buf), "%s: Done\n", ref_string);
1138}
static struct ast_xslt_doc * eprofile_to_pidf_xslt
static struct ast_xml_node * geoloc_eprofile_to_intermediate(const char *element_name, struct ast_geoloc_eprofile *eprofile, struct ast_channel *chan, const char *ref_string)
struct ast_geoloc_eprofile * ast_geoloc_datastore_get_eprofile(struct ast_datastore *ds, int ix)
Retrieve a specific eprofile from a datastore by index.
int ast_geoloc_datastore_size(struct ast_datastore *ds)
Retrieves the number of eprofiles in the datastore.
#define ast_xml_find_child_element(_parent_node, _name, _attrname, _attrvalue)
Find a direct child element by name.
Definition xml.h:201
struct ast_xml_node * ast_xml_copy_node_list(struct ast_xml_node *list)
Create a copy of a n ode list.
Definition xml.c:184
struct ast_xml_node * ast_xml_add_child(struct ast_xml_node *parent, struct ast_xml_node *child)
Add a child node, to a specified parent node.
Definition xml.c:168
struct ast_xml_node * ast_xml_node_get_children(struct ast_xml_node *node)
Get the node's children.
Definition xml.c:395
const char * ast_xml_get_attribute(struct ast_xml_node *node, const char *attrname)
Get a node attribute by name.
Definition xml.c:267
struct ast_xml_node * ast_xml_new_node(const char *name)
Create a XML node.
Definition xml.c:144
void ast_xml_free_attr(const char *attribute)
Free an attribute returned by ast_xml_get_attribute()
Definition xml.c:253
struct ast_xml_doc * ast_xml_new(void)
Create a XML document.
Definition xml.c:136
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
struct ast_xml_node * ast_xml_add_child_list(struct ast_xml_node *parent, struct ast_xml_node *child)
Add a list of child nodes, to a specified parent node.
Definition xml.c:176
void ast_xml_set_root(struct ast_xml_doc *doc, struct ast_xml_node *node)
Specify the root node of a XML document.
Definition xml.c:221
void ast_xml_free_node(struct ast_xml_node *node)
Free node.
Definition xml.c:243

References ast_geoloc_datastore_get_eprofile(), ast_geoloc_datastore_size(), AST_GEOLOC_FORMAT_URI, AST_PIDF_ELEMENT_LAST, ast_str_buffer(), ast_str_set(), ast_strlen_zero(), ast_trace, ast_xml_add_child(), ast_xml_add_child_list(), ast_xml_close(), ast_xml_copy_node_list(), ast_xml_doc_dump_memory(), ast_xml_find_child_element, ast_xml_free_attr(), ast_xml_free_node(), ast_xml_free_text(), ast_xml_get_attribute(), ast_xml_new(), ast_xml_new_node(), ast_xml_node_get_children(), ast_xml_set_attribute(), ast_xml_set_root(), buf, eprofile_to_pidf_xslt, ast_geoloc_eprofile::format, geoloc_eprofile_to_intermediate(), ast_geoloc_eprofile::id, LOG_ERROR, NULL, ast_geoloc_eprofile::pidf_element, RAII_VAR, SCOPE_ENTER, SCOPE_EXIT_LOG_RTN_VALUE, SCOPE_EXIT_RTN_VALUE, and TRACE_ATLEAST.

◆ ast_geoloc_get_location()

struct ast_geoloc_location *AST_OPTIONAL_API_NAME() ast_geoloc_get_location ( const char *  id)

Retrieve a geolocation location object by id.

Parameters
idLocation object id.
Returns
Location object or NULL if not found.

Definition at line 584 of file geoloc_config.c.

585{
586 if (ast_strlen_zero(id)) {
587 return NULL;
588 }
589
590 return ast_sorcery_retrieve_by_id(geoloc_sorcery, "location", id);
591}
static struct ast_sorcery * geoloc_sorcery

References ast_sorcery_retrieve_by_id(), ast_strlen_zero(), geoloc_sorcery, and NULL.

Referenced by geoloc_profile_write().

◆ ast_geoloc_get_profile()

struct ast_geoloc_profile *AST_OPTIONAL_API_NAME() ast_geoloc_get_profile ( const char *  id)

Retrieve a geolocation profile by id.

Parameters
idprofile id.
Returns
Profile or NULL if not found.

Definition at line 593 of file geoloc_config.c.

594{
595 if (ast_strlen_zero(id)) {
596 return NULL;
597 }
598
599 return ast_sorcery_retrieve_by_id(geoloc_sorcery, "profile", id);
600}

References ast_sorcery_retrieve_by_id(), ast_strlen_zero(), geoloc_sorcery, and NULL.

Referenced by handle_incoming_request(), handle_outgoing_request(), and sip_endpoint_apply_handler().

◆ ast_geoloc_gml_validate_varlist()

enum ast_geoloc_validate_result ast_geoloc_gml_validate_varlist ( struct ast_variable varlist,
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 260 of file geoloc_gml.c.

262{
263 const char *shape_type = ast_variable_find_in_list(varlist, "shape");
264 int shape_index = -1;
265 const char *crs = ast_variable_find_in_list(varlist, "crs");
266
267 if (!shape_type) {
268 SET_RESULT(result, "Missing 'shape'");
270 }
271
272 shape_index = find_shape_index(shape_type);
273 if (shape_index < 0) {
274 SET_RESULT(result, "Invalid shape '%s'", shape_type);
276 }
277
278 if (ast_strlen_zero(crs)) {
279 struct ast_variable *vcrs = NULL;
280 if (ast_strings_equal("any", gml_shape_defs[shape_index].crs)) {
281 crs = "2d";
282 } else {
283 crs = gml_shape_defs[shape_index].crs;
284 }
285
286 vcrs = ast_variable_new("crs", "2d", "");
287 if (vcrs) {
288 ast_variable_list_append(&varlist, vcrs);
289 }
290 }
291 if (!crs_validator("crs", crs, varlist, result)) {
293 }
294
295 if (!ast_strings_equal("any", gml_shape_defs[shape_index].crs)
296 && !ast_strings_equal(crs, gml_shape_defs[shape_index].crs)) {
297 SET_RESULT(result, "Invalid crs '%s' for shape '%s'", crs, shape_type);
299 }
300
301 return validate_def_varlist(shape_index, varlist, result);
302}
static enum ast_geoloc_validate_result validate_def_varlist(int shape_index, const struct ast_variable *varlist, char **result)
Definition geoloc_gml.c:206
static int crs_validator(const char *name, const char *value, const struct ast_variable *varlist, char **result)
Definition geoloc_gml.c:45
#define SET_RESULT(__result,...)
Definition geoloc_gml.c:38
static int find_shape_index(const char *shape)
Definition geoloc_gml.c:178
static struct geoloc_gml_shape_def gml_shape_defs[]
Definition geoloc_gml.c:161
int ast_strings_equal(const char *str1, const char *str2)
Compare strings for equality checking for NULL.
Definition strings.c:238
const char * crs
Definition geoloc_gml.c:34

References AST_GEOLOC_VALIDATE_INVALID_CRS, AST_GEOLOC_VALIDATE_INVALID_CRS_FOR_SHAPE, AST_GEOLOC_VALIDATE_INVALID_SHAPE, AST_GEOLOC_VALIDATE_MISSING_SHAPE, ast_strings_equal(), ast_strlen_zero(), ast_variable_find_in_list(), ast_variable_list_append, ast_variable_new, geoloc_gml_shape_def::crs, crs_validator(), find_shape_index(), gml_shape_defs, NULL, result, SET_RESULT, and validate_def_varlist().

Referenced by geoloc_gml_list_to_xml(), and validate_location_info().

◆ ast_geoloc_is_loaded()

int AST_OPTIONAL_API_NAME() ast_geoloc_is_loaded ( void  )

Check if res_geolocation is available.

Returns
1 if available, 0 otherwise.

Definition at line 770 of file geoloc_config.c.

771{
772 return 1;
773}

Referenced by sip_endpoint_apply_handler().

◆ ast_geoloc_validate_result_to_str()

const char * ast_geoloc_validate_result_to_str ( enum ast_geoloc_validate_result  result)

Definition at line 34 of file geoloc_common.c.

35{
36 return result_names[result];
37}
static const char * result_names[]

References result, and result_names.

◆ CONFIG_STR_TO_ENUM_DECL() [1/2]

CONFIG_STR_TO_ENUM_DECL ( format  )

◆ CONFIG_STR_TO_ENUM_DECL() [2/2]

CONFIG_STR_TO_ENUM_DECL ( precedence  )

◆ GEOLOC_ENUM_TO_NAME_DECL() [1/2]

GEOLOC_ENUM_TO_NAME_DECL ( format  )

◆ GEOLOC_ENUM_TO_NAME_DECL() [2/2]

GEOLOC_ENUM_TO_NAME_DECL ( precedence  )