Skip to content

Commit

Permalink
DNS stuff, round deux. This is preliminary stuff, I am not done.
Browse files Browse the repository at this point in the history
  • Loading branch information
Elizabeth J. Myers committed Mar 29, 2012
1 parent e254de4 commit 88cc2ed
Show file tree
Hide file tree
Showing 10 changed files with 2,416 additions and 2 deletions.
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -4038,7 +4038,7 @@ fi
LIBMOWGLI_MODULES="core base container concurrent eventloop ext module object thread vio linebuf"
LIBMOWGLI_MODULES="core base container concurrent dns eventloop ext linebuf module object thread vio"
LIBMOWGLI_MODULE_BUILD="$(echo && echo x)"
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ AC_CHECK_FUNCS([fcntl kqueue mmap select dispatch_block port_create])
AC_PATH_PROG(AR, ar)
AC_PATH_PROG(RANLIB, ranlib)

LIBMOWGLI_MODULES="core base container concurrent eventloop ext module object thread vio linebuf"
LIBMOWGLI_MODULES="core base container concurrent dns eventloop ext linebuf module object thread vio"
AC_SUBST(LIBMOWGLI_MODULES)

LIBMOWGLI_MODULE_BUILD="$(echo && echo x)"
Expand Down
19 changes: 19 additions & 0 deletions src/libmowgli/dns/Makefile
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

83 changes: 83 additions & 0 deletions src/libmowgli/dns/dns.c
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);
}

85 changes: 85 additions & 0 deletions src/libmowgli/dns/dns.h
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

Loading

0 comments on commit 88cc2ed

Please sign in to comment.