Asterisk - The Open Source Telephony Project  18.5.0
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 109 of file dns_recurring.c.

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, 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().

110 {
111  struct ast_dns_query_recurring *recurring;
112 
114  return NULL;
115  }
116 
117  recurring = ao2_alloc(sizeof(*recurring) + strlen(name) + 1, dns_query_recurring_destroy);
118  if (!recurring) {
119  return NULL;
120  }
121 
122  recurring->callback = callback;
123  recurring->user_data = ao2_bump(data);
124  recurring->timer = -1;
125  recurring->rr_type = rr_type;
126  recurring->rr_class = rr_class;
127  strcpy(recurring->name, name); /* SAFE */
128 
130  if (!recurring->active) {
131  ao2_ref(recurring, -1);
132  return NULL;
133  }
134 
135  return recurring;
136 }
ast_dns_resolve_callback callback
Callback to invoke upon completion.
Definition: dns_internal.h:159
char name[0]
The name of what is being resolved.
Definition: dns_internal.h:173
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
int rr_class
Resource record class.
Definition: dns_internal.h:171
static void dns_query_recurring_destroy(void *data)
Destructor for a DNS query.
Definition: dns_recurring.c:43
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ao2_bump(obj)
Definition: astobj2.h:491
void * user_data
User-specific data.
Definition: dns_internal.h:161
struct ast_sched_context * ast_dns_get_sched(void)
Retrieve the DNS scheduler context.
Definition: dns_core.c:52
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ast_dns_query_active * active
Current active query.
Definition: dns_internal.h:163
static void dns_query_recurring_resolution_callback(const struct ast_dns_query *query)
Query resolution callback.
Definition: dns_recurring.c:71
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
static const char name[]
Definition: cdr_mysql.c:74
A recurring DNS query.
Definition: dns_internal.h:157
int rr_type
Resource record type.
Definition: dns_internal.h:169
int timer
Scheduled timer for next resolution.
Definition: dns_internal.h:167

◆ ast_dns_resolve_recurring_cancel()

int ast_dns_resolve_recurring_cancel ( struct ast_dns_query_recurring recurring)

Cancel an asynchronous recurring DNS resolution.

Parameters
queryThe 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 138 of file dns_recurring.c.

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().

139 {
140  int res = 0;
141 
142  ao2_lock(recurring);
143 
144  recurring->cancelled = 1;
145  AST_SCHED_DEL_UNREF(ast_dns_get_sched(), recurring->timer, ao2_ref(recurring, -1));
146 
147  if (recurring->active) {
148  res = ast_dns_resolve_cancel(recurring->active);
149  ao2_replace(recurring->active, NULL);
150  }
151 
152  ao2_unlock(recurring);
153 
154  return res;
155 }
#define AST_SCHED_DEL_UNREF(sched, id, refcall)
schedule task to get deleted and call unref function
Definition: sched.h:80
#define ao2_unlock(a)
Definition: astobj2.h:730
#define NULL
Definition: resample.c:96
struct ast_sched_context * ast_dns_get_sched(void)
Retrieve the DNS scheduler context.
Definition: dns_core.c:52
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ast_dns_query_active * active
Current active query.
Definition: dns_internal.h:163
#define ao2_lock(a)
Definition: astobj2.h:718
unsigned int cancelled
The recurring query has been cancelled.
Definition: dns_internal.h:165
#define ao2_replace(dst, src)
Definition: astobj2.h:517
int ast_dns_resolve_cancel(struct ast_dns_query_active *active)
Cancel an asynchronous DNS resolution.
Definition: dns_core.c:272
int timer
Scheduled timer for next resolution.
Definition: dns_internal.h:167