Asterisk - The Open Source Telephony Project GIT-master-4f2b068
Loading...
Searching...
No Matches
res_geolocation.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 INCLUDE_ASTERISK_RES_GEOLOCATION_H_
20#define INCLUDE_ASTERISK_RES_GEOLOCATION_H_
21
22#include "asterisk/channel.h"
23#include "asterisk/config.h"
24#include "asterisk/sorcery.h"
25#include "asterisk/xml.h"
27
28#define AST_GEOLOC_INVALID_VALUE -1
29
37
45
52
53#define CONFIG_STR_TO_ENUM_DECL(_stem) int ast_geoloc_ ## _stem ## _str_to_enum(const char *str);
54CONFIG_STR_TO_ENUM_DECL(pidf_element)
57#define GEOLOC_ENUM_TO_NAME_DECL(_stem) const char * ast_geoloc_ ## _stem ## _to_name(int ix);
58GEOLOC_ENUM_TO_NAME_DECL(pidf_element)
61
72
94
117
118/*!
119 * \brief Check if res_geolocation is available
120 *
121 * \return 1 if available, 0 otherwise.
122 */
123AST_OPTIONAL_API(int, ast_geoloc_is_loaded, (void), { return 0; });
124
125/*!
126 * \brief Retrieve a geolocation location object by id.
127 *
128 * \param id Location object id.
129 *
130 * \return Location object or NULL if not found.
131 */
133 (const char *id),
134 { return NULL; });
135
136/*!
137 * \brief Retrieve a geolocation profile by id.
138 *
139 * \param id profile id.
140 *
141 * \return Profile or NULL if not found.
142 */
144 (const char *id),
145 { return NULL; });
146
147/*!
148 * \brief Given a civicAddress code, check whether it's valid.
149 *
150 * \param code Pointer to the code to check
151 *
152 * \return 1 if valid, 0 otherwise.
153 */
154int ast_geoloc_civicaddr_is_code_valid(const char *code);
155
167
169
170/*!
171 * \brief Validate that the names of the variables in the list are valid codes or synonyms
172 *
173 * \param varlist Variable list to check.
174 * \param[out] result Pointer to char * to receive failing item.
175 *
176 * \return result code.
177 */
179 const struct ast_variable *varlist, char **result);
180
181/*!
182 * \brief Validate that the variables in the list represent a valid GML shape
183 *
184 * \param varlist Variable list to check.
185 * \param[out] result Pointer to char * to receive failing item.
186 *
187 * \return result code.
188 */
190 char **result);
191
192
193/*!
194 * \brief Geolocation datastore Functions
195 * @{
196 */
197
198/*!
199 * \brief Create a geoloc datastore from a profile name
200 *
201 * \param profile_name The name of the profile to use.
202 *
203 * \return The datastore.
204 */
205struct ast_datastore *ast_geoloc_datastore_create_from_profile_name(const char *profile_name);
206
207/*!
208 * \brief Create a geoloc datastore from an effective profile.
209 *
210 * \param eprofile The effective profile to use.
211 *
212 * \return The datastore.
213 */
215 struct ast_geoloc_eprofile *eprofile);
216
217/*!
218 * \brief Create an empty geoloc datastore.
219 *
220 * \param id An id to use for the datastore.
221 *
222 * \return The datastore.
223 */
224struct ast_datastore *ast_geoloc_datastore_create(const char *id);
225
226/*!
227 * \brief Retrieve a geoloc datastore's id.
228 *
229 * \param ds The datastore
230 *
231 * \return The datastore's id.
232 */
233const char *ast_geoloc_datastore_get_id(struct ast_datastore *ds);
234
235/*!
236 * \brief Add an eprofile to a datastore
237 *
238 * \param ds The datastore
239 * \param eprofile The eprofile to add.
240 *
241 * \return The new number of eprofiles or -1 to indicate a failure.
242 */
244 struct ast_geoloc_eprofile *eprofile);
245
246/*!
247 * \brief Insert an eprofile to a datastore at the specified position
248 *
249 * \param ds The datastore
250 * \param eprofile The eprofile to add.
251 * \param index The position to insert at. Existing eprofiles will
252 * be moved up to make room.
253 *
254 * \return The new number of eprofiles or -1 to indicate a failure.
255 */
257 struct ast_geoloc_eprofile *eprofile, int index);
258
259/*!
260 * \brief Retrieves the number of eprofiles in the datastore
261 *
262 * \param ds The datastore
263 *
264 * \return The number of eprofiles.
265 */
267
268/*!
269 * \brief Sets the inheritance flag on the datastore
270 *
271 * \param ds The datastore
272 * \param inherit 1 to allow the datastore to be inherited by other channels
273 * 0 to prevent the datastore to be inherited by other channels
274 *
275 * \return 0 if successful, -1 otherwise.
276 */
277int ast_geoloc_datastore_set_inheritance(struct ast_datastore *ds, int inherit);
278
279/*!
280 * \brief Retrieve a specific eprofile from a datastore by index
281 *
282 * \param ds The datastore
283 * \param ix The index
284 *
285 * \return The effective profile ao2 object with its reference count bumped.
286 */
288
289/*!
290 * \brief Delete a specific eprofile from a datastore by index
291 *
292 * \param ds The datastore
293 * \param ix The index
294 *
295 * \return 0 if succesful, -1 otherwise.
296 */
298
299/*!
300 * \brief Retrieves the geoloc datastore from a channel, if any
301 *
302 * \param chan Channel
303 *
304 * \return datastore if found, NULL otherwise.
305 */
307
308/*!
309 * @}
310 */
311
312/*!
313 * \brief Geolocation Effective Profile Functions
314 * @{
315 */
316
317/*!
318 * \brief Allocate a new, empty effective profile.
319 *
320 * \param name The profile's name
321 *
322 * \return The effective profile ao2 object.
323 */
325
326/*!
327 * \brief Duplicate an effective profile.
328 *
329 * \param src The eprofile to duplicate.
330 *
331 * \return The duplicated effective profile ao2 object.
332 */
334
335/*!
336 * \brief Allocate a new effective profile from an existing profile.
337 *
338 * \param profile The profile to use.
339 *
340 * \return The effective profile ao2 object.
341 */
343
344/*!
345 * \brief Allocate a new effective profile from an XML PIDF-LO document
346 *
347 * \param pidf_xmldoc The ast_xml_doc to use.
348 * \param geoloc_uri The URI that referenced this document.
349 * \param reference_string An identifying string to use in error messages.
350 *
351 * \return The effective profile ao2 object.
352 */
354 struct ast_xml_doc *pidf_xmldoc, const char *geoloc_uri, const char *reference_string);
355
356/*!
357 * \brief Allocate a new effective profile from a URI.
358 *
359 * \param uri The URI to use.
360 * \param reference_string An identifying string to use in error messages.
361 *
362 * \return The effective profile ao2 object.
363 */
365 const char *reference_string);
366
367/*!
368 * \brief Convert a URI eprofile to a URI string
369 *
370 * \param eprofile Effective profile to convert
371 * \param chan Channel to use to resolve variables
372 * \param buf Pointer to ast_str pointer to use for work
373 * \param ref_string An identifying string to use in error messages.
374 *
375 * \return String representation of URI allocated from buf or NULL on failure
376 */
377const char *ast_geoloc_eprofile_to_uri(struct ast_geoloc_eprofile *eprofile,
378 struct ast_channel *chan, struct ast_str **buf, const char *ref_string);
379
380/*!
381 * \brief Convert a datastore containing eprofiles to a PIDF-LO document
382 *
383 * \param ds Datastore containing effective profiles to convert
384 * \param chan Channel to use to resolve variables
385 * \param buf Pointer to ast_str pointer to use for work
386 * \param ref_string An identifying string to use in error messages.
387 *
388 * \return String representation PIDF-LO allocated from buf or NULL on failure.
389 */
390const char *ast_geoloc_eprofiles_to_pidf(struct ast_datastore *ds,
391 struct ast_channel *chan, struct ast_str **buf, const char * ref_string);
392
393/*!
394 * \brief Convert a single eprofile to a PIDF-LO document
395 *
396 * \param eprofile Effective profile to convert
397 * \param chan Channel to use to resolve variables
398 * \param buf Pointer to ast_str pointer to use for work
399 * \param ref_string An identifying string to use in error messages.
400 *
401 * \return String representation PIDF-LO allocated from buf or NULL on failure.
402 */
403const char *ast_geoloc_eprofile_to_pidf(struct ast_geoloc_eprofile *eprofile,
404 struct ast_channel *chan, struct ast_str **buf, const char * ref_string);
405
406/*!
407 * \brief Refresh the effective profile with any changed info.
408 *
409 * \param eprofile The eprofile to refresh.
410 *
411 * \return 0 on success, any other value on error.
412 */
414
415/*!
416 * @}
417 */
418
419#endif /* INCLUDE_ASTERISK_RES_GEOLOCATION_H_ */
static PGresult * result
Definition cel_pgsql.c:84
General Asterisk PBX channel definitions.
char buf[BUFSIZE]
Definition eagi_proxy.c:66
static const char name[]
Definition format_mp3.c:68
Configuration File Parser.
Optional API function macros.
#define AST_OPTIONAL_API(result, name, proto, stub)
Declare an optional API function.
ast_geoloc_precedence
@ AST_GEOLOC_PRECED_DISCARD_CONFIG
@ AST_GEOLOC_PRECED_PREFER_CONFIG
@ AST_GEOLOC_PRECED_DISCARD_INCOMING
@ AST_GEOLOC_PRECED_PREFER_INCOMING
struct ast_datastore * ast_geoloc_datastore_create_from_profile_name(const char *profile_name)
Geolocation datastore Functions.
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.
Definition geoloc_gml.c:260
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_dup(struct ast_geoloc_eprofile *src)
Duplicate an effective profile.
const char * ast_geoloc_validate_result_to_str(enum ast_geoloc_validate_result result)
struct ast_geoloc_eprofile * ast_geoloc_datastore_get_eprofile(struct ast_datastore *ds, int ix)
Retrieve a specific eprofile from a datastore by index.
struct ast_geoloc_location *AST_OPTIONAL_API_NAME() ast_geoloc_get_location(const char *id)
Retrieve a geolocation location object by id.
struct ast_datastore * ast_geoloc_datastore_create_from_eprofile(struct ast_geoloc_eprofile *eprofile)
Create a geoloc datastore from an effective profile.
#define CONFIG_STR_TO_ENUM_DECL(_stem)
ast_geoloc_validate_result
@ AST_GEOLOC_VALIDATE_INVALID_CRS
@ 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_CRS_FOR_SHAPE
@ AST_GEOLOC_VALIDATE_INVALID_SHAPE
@ AST_GEOLOC_VALIDATE_INVALID_VARNAME
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.
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_OPTIONAL_API_NAME() ast_geoloc_is_loaded(void)
Check if res_geolocation is available.
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.
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.
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.
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.
const char * ast_geoloc_datastore_get_id(struct ast_datastore *ds)
Retrieve a geoloc datastore's id.
struct ast_datastore * ast_geoloc_datastore_create(const char *id)
Create an empty geoloc datastore.
ast_geoloc_pidf_element
@ AST_PIDF_ELEMENT_PERSON
@ AST_PIDF_ELEMENT_TUPLE
@ AST_PIDF_ELEMENT_DEVICE
@ AST_PIDF_ELEMENT_NONE
@ AST_PIDF_ELEMENT_LAST
ast_geoloc_format
@ AST_GEOLOC_FORMAT_GML
@ AST_GEOLOC_FORMAT_CIVIC_ADDRESS
@ AST_GEOLOC_FORMAT_LAST
@ AST_GEOLOC_FORMAT_URI
@ AST_GEOLOC_FORMAT_NONE
struct ast_geoloc_eprofile * ast_geoloc_eprofile_alloc(const char *name)
Geolocation Effective Profile Functions.
int ast_geoloc_datastore_set_inheritance(struct ast_datastore *ds, int inherit)
Sets the inheritance flag on the datastore.
int ast_geoloc_datastore_add_eprofile(struct ast_datastore *ds, struct ast_geoloc_eprofile *eprofile)
Add an eprofile to a datastore.
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.
int ast_geoloc_datastore_size(struct ast_datastore *ds)
Retrieves the number of eprofiles in the datastore.
struct ast_datastore * ast_geoloc_datastore_find(struct ast_channel *chan)
Retrieves the geoloc datastore from a channel, if any.
struct ast_geoloc_eprofile * ast_geoloc_eprofile_create_from_profile(struct ast_geoloc_profile *profile)
Allocate a new effective profile from an existing profile.
int ast_geoloc_civicaddr_is_code_valid(const char *code)
Given a civicAddress code, check whether it's valid.
struct ast_geoloc_profile *AST_OPTIONAL_API_NAME() ast_geoloc_get_profile(const char *id)
Retrieve a geolocation profile by id.
int ast_geoloc_datastore_delete_eprofile(struct ast_datastore *ds, int ix)
Delete a specific eprofile from a datastore by index.
#define GEOLOC_ENUM_TO_NAME_DECL(_stem)
const char * method
Definition res_pjsip.c:1273
#define NULL
Definition resample.c:96
Sorcery Data Access Layer API.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define AST_STRING_FIELD(name)
Declare a string field.
Main Channel structure associated with a channel.
Structure for a data store object.
Definition datastore.h:64
struct ast_variable * effective_location
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
enum ast_geoloc_format format
struct ast_variable * confidence
struct ast_variable * location_info
SORCERY_OBJECT(details)
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
Support for dynamic strings.
Definition strings.h:623
Structure for variables, used for configurations and for channel variables.
Asterisk XML abstraction layer.