23 #include "asterisk/res_geolocation.h"
25 #include "geoloc_private.h"
27 #define GEOLOC_DS_TYPE "geoloc_eprofiles"
36 static
void geoloc_datastore_free(
void *obj)
45 static void *geoloc_datastore_duplicate(
void *obj)
51 int eprofile_count = 0;
65 for (i = 0; i < eprofile_count; i++) {
70 geoloc_datastore_free(out_eds);
79 .
type = GEOLOC_DS_TYPE,
80 .destroy = geoloc_datastore_free,
81 .duplicate = geoloc_datastore_duplicate,
84 #define IS_GEOLOC_DS(_ds) (_ds && _ds->data && ast_strings_equal(_ds->info->type, GEOLOC_DS_TYPE))
86 const char *ast_geoloc_datastore_get_id(
struct ast_datastore *ds)
90 if (!IS_GEOLOC_DS(ds)) {
99 struct ast_datastore *ast_geoloc_datastore_create(
const char *
id)
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");
110 ds = ast_datastore_alloc(&geoloc_datastore_info, NULL);
112 ast_log(LOG_ERROR,
"Geoloc datastore '%s' couldn't be allocated\n",
id);
119 ast_log(LOG_ERROR,
"Private structure for geoloc datastore '%s' couldn't be allocated\n",
id);
128 ast_log(LOG_ERROR,
"Vector for geoloc datastore '%s' couldn't be initialized\n",
id);
135 int ast_geoloc_datastore_add_eprofile(
struct ast_datastore *ds,
141 if (!IS_GEOLOC_DS(ds) || !eprofile) {
149 ast_log(LOG_ERROR,
"Couldn't add eprofile '%s' to geoloc datastore '%s'\n", eprofile->id, eds->id);
156 int ast_geoloc_datastore_insert_eprofile(
struct ast_datastore *ds,
162 if (!IS_GEOLOC_DS(ds) || !eprofile) {
170 ast_log(LOG_ERROR,
"Couldn't add eprofile '%s' to geoloc datastore '%s' in position '%d'\n",
171 eprofile->id, eds->id, index);
182 if (!IS_GEOLOC_DS(ds)) {
191 int ast_geoloc_datastore_set_inheritance(
struct ast_datastore *ds,
int inherit)
193 if (!IS_GEOLOC_DS(ds)) {
196 ds->
inheritance = inherit ? DATASTORE_INHERIT_FOREVER : 0;
205 if (!IS_GEOLOC_DS(ds)) {
224 int ast_geoloc_datastore_delete_eprofile(
struct ast_datastore *ds,
int ix)
228 if (!IS_GEOLOC_DS(ds)) {
242 struct ast_datastore *ast_geoloc_datastore_create_from_eprofile(
252 ds = ast_geoloc_datastore_create(eprofile->id);
257 rc = ast_geoloc_datastore_add_eprofile(ds, eprofile);
266 struct ast_datastore *ast_geoloc_datastore_create_from_profile_name(
const char *profile_name)
273 if (ast_strlen_zero(profile_name)) {
279 ast_log(LOG_ERROR,
"A profile with the name '%s' was not found\n", profile_name);
283 ds = ast_geoloc_datastore_create(profile_name);
285 ast_log(LOG_ERROR,
"A datastore couldn't be allocated for profile '%s'\n", profile_name);
290 eprofile = ast_geoloc_eprofile_create_from_profile(profile);
294 ast_log(LOG_ERROR,
"An effective profile with the name '%s' couldn't be allocated\n", profile_name);
298 rc = ast_geoloc_datastore_add_eprofile(ds, eprofile);
308 int geoloc_channel_unload(
void)
310 if (geoloc_sorcery) {
316 int geoloc_channel_load(
void)
318 geoloc_sorcery = geoloc_get_sorcery();
322 int geoloc_channel_reload(
void)
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Main Channel structure associated with a channel.
Asterisk main include file. File version handling, generic pbx functions.
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Full structure for sorcery.
Structure for a data store type.
Structure for a data store object.
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.
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
#define ast_sorcery_unref(sorcery)
Decrease the reference count of a sorcery structure.
Asterisk datastore objects.
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
General Asterisk PBX channel definitions.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define AST_VECTOR(name, type)
Define a vector structure.
#define ast_calloc(num, len)
A wrapper for calloc()
#define AST_VECTOR_RESET(vec, cleanup)
Reset vector.
Vector container support.
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
#define AST_VECTOR_INSERT_AT(vec, idx, elem)
Insert an element at a specific position in a vector, growing the vector if needed.
#define AST_VECTOR_REMOVE(vec, idx, preserve_ordered)
Remove an element from a vector by index.
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.