summaryrefslogtreecommitdiff
path: root/pjlib-util/include
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2008-06-06 14:18:28 +0000
committerBenny Prijono <bennylp@teluu.com>2008-06-06 14:18:28 +0000
commit77825e4c00356383e69f3fc4c63eccd0a3aa103f (patch)
tree62f0bfb5fad28674d04ceae3349b855ca24e5931 /pjlib-util/include
parentd37adaba9d2fe38fe3f06759c6ba47e37aa562c5 (diff)
Ticket #537: implemented Simple DNS Server class (for testing) in pjlib-util
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1987 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib-util/include')
-rw-r--r--pjlib-util/include/pjlib-util.h3
-rw-r--r--pjlib-util/include/pjlib-util/dns.h54
-rw-r--r--pjlib-util/include/pjlib-util/dns_server.h116
3 files changed, 173 insertions, 0 deletions
diff --git a/pjlib-util/include/pjlib-util.h b/pjlib-util/include/pjlib-util.h
index 728d8fee..567144a5 100644
--- a/pjlib-util/include/pjlib-util.h
+++ b/pjlib-util/include/pjlib-util.h
@@ -44,6 +44,9 @@
#include <pjlib-util/resolver.h>
#include <pjlib-util/srv_resolver.h>
+/* Simple DNS server */
+#include <pjlib-util/dns_server.h>
+
/* Text scanner */
#include <pjlib-util/scanner.h>
diff --git a/pjlib-util/include/pjlib-util/dns.h b/pjlib-util/include/pjlib-util/dns.h
index 10ba1166..a537169a 100644
--- a/pjlib-util/include/pjlib-util/dns.h
+++ b/pjlib-util/include/pjlib-util/dns.h
@@ -372,6 +372,60 @@ PJ_DECL(const char *) pj_dns_get_type_name(int type);
/**
+ * Initialize DNS record as DNS SRV record.
+ *
+ * @param rec The DNS resource record to be initialized as DNS
+ * SRV record.
+ * @param res_name Resource name.
+ * @param dnsclass DNS class.
+ * @param ttl Resource TTL value.
+ * @param prio DNS SRV priority.
+ * @param weight DNS SRV weight.
+ * @param port Target port.
+ * @param target Target name.
+ */
+PJ_DECL(void) pj_dns_init_srv_rr(pj_dns_parsed_rr *rec,
+ const pj_str_t *res_name,
+ unsigned dnsclass,
+ unsigned ttl,
+ unsigned prio,
+ unsigned weight,
+ unsigned port,
+ const pj_str_t *target);
+
+/**
+ * Initialize DNS record as DNS CNAME record.
+ *
+ * @param rec The DNS resource record to be initialized as DNS
+ * CNAME record.
+ * @param res_name Resource name.
+ * @param dnsclass DNS class.
+ * @param ttl Resource TTL value.
+ * @param name Host name.
+ */
+PJ_DECL(void) pj_dns_init_cname_rr(pj_dns_parsed_rr *rec,
+ const pj_str_t *res_name,
+ unsigned dnsclass,
+ unsigned ttl,
+ const pj_str_t *name);
+
+/**
+ * Initialize DNS record as DNS A record.
+ *
+ * @param rec The DNS resource record to be initialized as DNS
+ * A record.
+ * @param res_name Resource name.
+ * @param dnsclass DNS class.
+ * @param ttl Resource TTL value.
+ * @param ip_addr Host address.
+ */
+PJ_DECL(void) pj_dns_init_a_rr(pj_dns_parsed_rr *rec,
+ const pj_str_t *res_name,
+ unsigned dnsclass,
+ unsigned ttl,
+ const pj_in_addr *ip_addr);
+
+/**
* Dump DNS packet to standard log.
*
* @param res The DNS packet.
diff --git a/pjlib-util/include/pjlib-util/dns_server.h b/pjlib-util/include/pjlib-util/dns_server.h
new file mode 100644
index 00000000..742b3c8e
--- /dev/null
+++ b/pjlib-util/include/pjlib-util/dns_server.h
@@ -0,0 +1,116 @@
+/* $Id$ */
+/*
+ * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef __PJLIB_UTIL_DNS_SERVER_H__
+#define __PJLIB_UTIL_DNS_SERVER_H__
+
+/**
+ * @file dns_server.h
+ * @brief Simple DNS server
+ */
+#include <pjlib-util/types.h>
+#include <pjlib-util/dns.h>
+
+PJ_BEGIN_DECL
+
+/**
+ * @defgroup PJ_DNS_SERVER Simple DNS Server
+ * @ingroup PJLIB_UTIL
+ * @{
+ * This contains a simple but fully working DNS server implementation,
+ * mostly for testing purposes. It supports serving various DNS resource
+ * records such as SRV, CNAME, A, and AAAA.
+ */
+
+/**
+ * Opaque structure to hold DNS server instance.
+ */
+typedef struct pj_dns_server pj_dns_server;
+
+/**
+ * Create the DNS server instance. The instance will run immediately.
+ *
+ * @param pf The pool factory to create memory pools.
+ * @param ioqueue Ioqueue instance where the server socket will be
+ * registered to.
+ * @param af Address family of the server socket (valid values
+ * are pj_AF_INET() for IPv4 and pj_AF_INET6() for IPv6).
+ * @param port The UDP port to listen.
+ * @param flags Flags, currently must be zero.
+ * @param p_srv Pointer to receive the DNS server instance.
+ *
+ * @return PJ_SUCCESS if server has been created successfully,
+ * otherwise the function will return the appropriate
+ * error code.
+ */
+PJ_DECL(pj_status_t) pj_dns_server_create(pj_pool_factory *pf,
+ pj_ioqueue_t *ioqueue,
+ int af,
+ unsigned port,
+ unsigned flags,
+ pj_dns_server **p_srv);
+
+/**
+ * Destroy DNS server instance.
+ *
+ * @param srv The DNS server instance.
+ *
+ * @return PJ_SUCCESS on success or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pj_dns_server_destroy(pj_dns_server *srv);
+
+
+/**
+ * Add generic resource record entries to the server.
+ *
+ * @param srv The DNS server instance.
+ * @param count Number of records to be added.
+ * @param rr Array of records to be added.
+ *
+ * @return PJ_SUCCESS on success or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pj_dns_server_add_rec(pj_dns_server *srv,
+ unsigned count,
+ const pj_dns_parsed_rr rr[]);
+
+/**
+ * Remove the specified record from the server.
+ *
+ * @param srv The DNS server instance.
+ * @param dns_class The resource's DNS class. Valid value is PJ_DNS_CLASS_IN.
+ * @param type The resource type.
+ * @param name The resource name to be removed.
+ *
+ * @return PJ_SUCCESS on success or the appropriate error code.
+ */
+PJ_DECL(pj_status_t) pj_dns_server_del_rec(pj_dns_server *srv,
+ int dns_class,
+ pj_dns_type type,
+ const pj_str_t *name);
+
+
+
+/**
+ * @}
+ */
+
+PJ_END_DECL
+
+
+#endif /* __PJLIB_UTIL_DNS_SERVER_H__ */
+