forked from atheme/libmowgli-2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DNS stuff, round deux. This is preliminary stuff, I am not done.
- Loading branch information
Elizabeth J. Myers
committed
Mar 29, 2012
1 parent
e254de4
commit 88cc2ed
Showing
10 changed files
with
2,416 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
include ../../../extra.mk | ||
|
||
STATIC_PIC_LIB_NOINST = ${LIBMOWGLI_SHARED_DNS} | ||
STATIC_LIB_NOINST = ${LIBMOWGLI_STATIC_DNS} | ||
|
||
SRCS = dns.c \ | ||
res.c \ | ||
reslib.c | ||
|
||
INCLUDES = dns.h \ | ||
res.h \ | ||
reslib.h | ||
|
||
include ../../../buildsys.mk | ||
|
||
includesubdir = $(PACKAGE_NAME)/dns | ||
|
||
CPPFLAGS += -I. -I.. -I../../.. -DMOWGLI_CORE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* Copyright (c) 2012 Elizabeth J. Myers. All rights reserved. | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | ||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "dns.h" | ||
|
||
mowgli_dns_t * mowgli_dns_create(mowgli_eventloop_t *eventloop, int implementation) | ||
{ | ||
mowgli_dns_t *dns = mowgli_alloc(sizeof(mowgli_dns_ops_t)); | ||
mowgli_dns_ops_t *ops; | ||
|
||
switch (implementation) | ||
{ | ||
case MOWGLI_DNS_TYPE_CUSTOM: | ||
return dns; | ||
case MOWGLI_DNS_TYPE_ASYNC: | ||
default: | ||
ops = &mowgli_dns_evloop_resolver; | ||
break; | ||
} | ||
|
||
dns->dns_ops = ops; | ||
|
||
if (mowgli_dns_init(dns, eventloop) != 0) | ||
{ | ||
mowgli_free(dns); | ||
return NULL; | ||
} | ||
|
||
return dns; | ||
} | ||
|
||
int mowgli_dns_init(mowgli_dns_t *dns, mowgli_eventloop_t *eventloop) | ||
{ | ||
return_val_if_fail(dns != NULL, -1); | ||
return_val_if_fail(dns->dns_ops != NULL, -1); | ||
|
||
return dns->dns_ops->mowgli_dns_init_func_t(dns, eventloop); | ||
} | ||
|
||
void mowgli_dns_destroy(mowgli_dns_t *dns) | ||
{ | ||
dns->dns_ops->mowgli_dns_fini_func_t(dns); | ||
|
||
mowgli_free(dns); | ||
} | ||
|
||
int mowgli_dns_restart(mowgli_dns_t *dns) | ||
{ | ||
return dns->dns_ops->mowgli_dns_restart_func_t(dns); | ||
} | ||
|
||
void mowgli_dns_delete_query(mowgli_dns_t *dns, const mowgli_dns_query_t *query) | ||
{ | ||
dns->dns_ops->mowgli_dns_delete_query_func_t(dns, query); | ||
} | ||
|
||
void mowgli_dns_gethost_byname(mowgli_dns_t *dns, const char *name, mowgli_dns_query_t *query, int type) | ||
{ | ||
dns->dns_ops->mowgli_dns_gethost_byname_func_t(dns, name, query, type); | ||
} | ||
|
||
void mowgli_dns_gethost_byaddr(mowgli_dns_t *dns, const struct sockaddr_storage *addr, mowgli_dns_query_t *query) | ||
{ | ||
dns->dns_ops->mowgli_dns_gethost_byaddr_func_t(dns, addr, query); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright (c) 2012 Elizabeth J. Myers. All rights reserved. | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | ||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#ifndef __MOWGLI_DNS_DNS_H__ | ||
#define __MOWGLI_DNS_DNS_H__ | ||
|
||
#include "mowgli.h" | ||
|
||
#define MOWGLI_DNS_TYPE_CUSTOM 0 | ||
#define MOWGLI_DNS_TYPE_ASYNC 1 | ||
#define MOWGLI_DNS_TYPE_HELPER 2 | ||
|
||
#define MOWGLI_DNS_T_A 1 | ||
#define MOWGLI_DNS_T_AAAA 28 | ||
#define MOWGLI_DNS_T_PTR 12 | ||
#define MOWGLI_DNS_T_CNAME 5 | ||
#define MOWGLI_DNS_T_MX 15 | ||
#define MOWGLI_DNS_T_TXT 16 | ||
#define MOWGLI_DNS_T_SSHFP 44 | ||
#define MOWGLI_DNS_T_NULL 10 | ||
|
||
typedef struct _mowgli_dns_t mowgli_dns_t; | ||
typedef struct _mowgli_dns_query_t mowgli_dns_query_t; | ||
typedef struct _mowgli_dns_reply_t mowgli_dns_reply_t; | ||
|
||
typedef struct | ||
{ | ||
int (*mowgli_dns_init_func_t)(mowgli_dns_t *, mowgli_eventloop_t *); | ||
void (*mowgli_dns_fini_func_t)(mowgli_dns_t *); | ||
int (*mowgli_dns_restart_func_t)(mowgli_dns_t *); | ||
void (*mowgli_dns_delete_query_func_t)(mowgli_dns_t *, const mowgli_dns_query_t *); | ||
void (*mowgli_dns_gethost_byname_func_t)(mowgli_dns_t *, const char *, mowgli_dns_query_t *, int); | ||
void (*mowgli_dns_gethost_byaddr_func_t)(mowgli_dns_t *, const struct sockaddr_storage *, mowgli_dns_query_t *); | ||
} mowgli_dns_ops_t; | ||
|
||
struct _mowgli_dns_reply_t | ||
{ | ||
char *h_name; | ||
mowgli_vio_sockaddr_t addr; | ||
}; | ||
|
||
struct _mowgli_dns_t | ||
{ | ||
int dns_type; | ||
mowgli_dns_ops_t *dns_ops; | ||
void *dns_state; | ||
}; | ||
|
||
struct _mowgli_dns_query_t | ||
{ | ||
void *ptr; /* pointer used by callback to identify request */ | ||
void (*callback) (void *vptr, mowgli_dns_reply_t * reply); /* callback to call */ | ||
}; | ||
|
||
extern mowgli_dns_t * mowgli_dns_create(mowgli_eventloop_t *eventloop, int implementation); | ||
extern int mowgli_dns_init(mowgli_dns_t *dns, mowgli_eventloop_t *eventloop); | ||
extern void mowgli_dns_destroy(mowgli_dns_t *dns); | ||
extern int mowgli_dns_restart(mowgli_dns_t *dns); | ||
extern void mowgli_dns_delete_query(mowgli_dns_t *dns, const mowgli_dns_query_t *query); | ||
extern void mowgli_dns_gethost_byname(mowgli_dns_t *dns, const char *name, mowgli_dns_query_t *query, int type); | ||
extern void mowgli_dns_gethost_byaddr(mowgli_dns_t *dns, const struct sockaddr_storage *addr, mowgli_dns_query_t *query); | ||
|
||
/* Pull in headers that depend on these types */ | ||
#include "res.h" | ||
#include "reslib.h" | ||
|
||
#endif | ||
|
Oops, something went wrong.