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.


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.
int ast_dns_resolve_recurring_cancel (struct ast_dns_query_recurring *recurring)
 Cancel an asynchronous recurring DNS resolution.

Detailed Description

DNS Recurring Resolution API.

Joshua Colp <jcolp@digium.com>

Definition in file dns_recurring.h.

Function Documentation

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 
) [read]

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

name The name of what to resolve
rr_type Resource record type
rr_class Resource record class
callback The callback to invoke upon completion
data User data to make available on the query
Return values:
non-NULL success - query has been sent for resolution
NULL failure
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 103 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().

00104 {
00105    struct ast_dns_query_recurring *recurring;
00107    if (ast_strlen_zero(name) || !callback || !ast_dns_get_sched()) {
00108       return NULL;
00109    }
00111    recurring = ao2_alloc(sizeof(*recurring) + strlen(name) + 1, dns_query_recurring_destroy);
00112    if (!recurring) {
00113       return NULL;
00114    }
00116    recurring->callback = callback;
00117    recurring->user_data = ao2_bump(data);
00118    recurring->timer = -1;
00119    recurring->rr_type = rr_type;
00120    recurring->rr_class = rr_class;
00121    strcpy(recurring->name, name); /* SAFE */
00123    recurring->active = ast_dns_resolve_async(name, rr_type, rr_class, dns_query_recurring_resolution_callback, recurring);
00124    if (!recurring->active) {
00125       ao2_ref(recurring, -1);
00126       return NULL;
00127    }
00129    return recurring;
00130 }

int ast_dns_resolve_recurring_cancel ( struct ast_dns_query_recurring recurring  ) 

Cancel an asynchronous recurring DNS resolution.

query The DNS query returned from ast_dns_resolve_recurring
Return values:
0 success - any active query has been cancelled and the query will no longer occur
-1 failure - an active query was in progress and could not be cancelled
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 132 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().

00133 {
00134    int res = 0;
00136    ao2_lock(recurring);
00138    recurring->cancelled = 1;
00139    AST_SCHED_DEL_UNREF(ast_dns_get_sched(), recurring->timer, ao2_ref(recurring, -1));
00141    if (recurring->active) {
00142       res = ast_dns_resolve_cancel(recurring->active);
00143       ao2_replace(recurring->active, NULL);
00144    }
00146    ao2_unlock(recurring);
00148    return res;
00149 }

Generated on Thu Apr 16 06:30:43 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6