Asterisk - The Open Source Telephony Project GIT-master-7e7a603
Functions
dns_recurring.h File Reference

DNS Recurring Resolution API. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

struct ast_dns_query_recurringast_dns_resolve_recurring (const char *name, int rr_type, int rr_class, ast_dns_resolve_callback callback, void *data)
 Asynchronously resolve a DNS query, and continue resolving it according to the lowest TTL available. More...
 
int ast_dns_resolve_recurring_cancel (struct ast_dns_query_recurring *recurring)
 Cancel an asynchronous recurring DNS resolution. More...
 

Detailed Description

DNS Recurring Resolution API.

Author
Joshua Colp jcolp.nosp@m.@dig.nosp@m.ium.c.nosp@m.om

Definition in file dns_recurring.h.

Function Documentation

◆ ast_dns_resolve_recurring()

struct ast_dns_query_recurring * ast_dns_resolve_recurring ( const char *  name,
int  rr_type,
int  rr_class,
ast_dns_resolve_callback  callback,
void *  data 
)

Asynchronously resolve a DNS query, and continue resolving it according to the lowest TTL available.

Parameters
nameThe name of what to resolve
rr_typeResource record type
rr_classResource record class
callbackThe callback to invoke upon completion
dataUser data to make available on the query
Return values
non-NULLsuccess - query has been sent for resolution
NULLfailure
Note
The user data passed in to this function must be ao2 allocated
This query will continue to happen according to the lowest TTL unless cancelled using ast_dns_resolve_recurring_cancel
It is NOT possible for the callback to be invoked concurrently for the query multiple times
The query will occur when the TTL expires, not before. This means that there is a period of time where the previous information can be considered stale.
If the TTL is determined to be 0 (the record specifies 0, or no records exist) this will cease doing a recurring query. It is the responsibility of the caller to resume querying at an interval they determine.

Definition at line 114 of file dns_recurring.c.

115{
116 struct ast_dns_query_recurring *recurring;
117
119 return NULL;
120 }
121
122 recurring = ao2_alloc(sizeof(*recurring) + strlen(name) + 1, dns_query_recurring_destroy);
123 if (!recurring) {
124 return NULL;
125 }
126
127 recurring->callback = callback;
128 recurring->user_data = ao2_bump(data);
129 recurring->timer = -1;
130 recurring->rr_type = rr_type;
131 recurring->rr_class = rr_class;
132 strcpy(recurring->name, name); /* SAFE */
133
135 if (!recurring->active) {
136 ao2_ref(recurring, -1);
137 return NULL;
138 }
139
140 return recurring;
141}
#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 ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
struct ast_dns_query_active * ast_dns_resolve_async(const char *name, int rr_type, int rr_class, ast_dns_resolve_callback callback, void *data)
Asynchronously resolve a DNS query.
Definition: dns_core.c:247
struct ast_sched_context * ast_dns_get_sched(void)
Retrieve the DNS scheduler context.
Definition: dns_core.c:52
static void dns_query_recurring_destroy(void *data)
Destructor for a DNS query.
Definition: dns_recurring.c:48
static void dns_query_recurring_resolution_callback(const struct ast_dns_query *query)
Query resolution callback.
Definition: dns_recurring.c:76
static const char name[]
Definition: format_mp3.c:68
#define NULL
Definition: resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
A recurring DNS query.
Definition: dns_internal.h:157
void * user_data
User-specific data.
Definition: dns_internal.h:161
ast_dns_resolve_callback callback
Callback to invoke upon completion.
Definition: dns_internal.h:159
struct ast_dns_query_active * active
Current active query.
Definition: dns_internal.h:163
int rr_class
Resource record class.
Definition: dns_internal.h:171
int rr_type
Resource record type.
Definition: dns_internal.h:169
int timer
Scheduled timer for next resolution.
Definition: dns_internal.h:167
char name[0]
The name of what is being resolved.
Definition: dns_internal.h:173

References ast_dns_query_recurring::active, ao2_alloc, ao2_bump, ao2_ref, ast_dns_get_sched(), ast_dns_resolve_async(), ast_strlen_zero(), ast_dns_query_recurring::callback, dns_query_recurring_destroy(), dns_query_recurring_resolution_callback(), ast_dns_query_recurring::name, name, NULL, ast_dns_query_recurring::rr_class, ast_dns_query_recurring::rr_type, ast_dns_query_recurring::timer, and ast_dns_query_recurring::user_data.

Referenced by AST_TEST_DEFINE(), and rtp_reload().

◆ ast_dns_resolve_recurring_cancel()

int ast_dns_resolve_recurring_cancel ( struct ast_dns_query_recurring recurring)

Cancel an asynchronous recurring DNS resolution.

Parameters
recurringThe DNS query returned from ast_dns_resolve_recurring
Return values
0success - any active query has been cancelled and the query will no longer occur
-1failure - an active query was in progress and could not be cancelled
Note
If successfully cancelled the callback will not be invoked
This function does NOT drop your reference to the recurring query, this should be dropped using ao2_ref

Definition at line 143 of file dns_recurring.c.

144{
145 int res = 0;
146
147 ao2_lock(recurring);
148
149 recurring->cancelled = 1;
150 AST_SCHED_DEL_UNREF(ast_dns_get_sched(), recurring->timer, ao2_ref(recurring, -1));
151
152 if (recurring->active) {
153 res = ast_dns_resolve_cancel(recurring->active);
154 ao2_replace(recurring->active, NULL);
155 }
156
157 ao2_unlock(recurring);
158
159 return res;
160}
#define ao2_unlock(a)
Definition: astobj2.h:729
#define ao2_replace(dst, src)
Replace one object reference with another cleaning up the original.
Definition: astobj2.h:501
#define ao2_lock(a)
Definition: astobj2.h:717
int ast_dns_resolve_cancel(struct ast_dns_query_active *active)
Cancel an asynchronous DNS resolution.
Definition: dns_core.c:272
#define AST_SCHED_DEL_UNREF(sched, id, refcall)
schedule task to get deleted and call unref function
Definition: sched.h:82
unsigned int cancelled
The recurring query has been cancelled.
Definition: dns_internal.h:165

References ast_dns_query_recurring::active, ao2_lock, ao2_ref, ao2_replace, ao2_unlock, ast_dns_get_sched(), ast_dns_resolve_cancel(), AST_SCHED_DEL_UNREF, ast_dns_query_recurring::cancelled, NULL, and ast_dns_query_recurring::timer.

Referenced by AST_TEST_DEFINE().