2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-24 19:18:50 +00:00
bind/lib/omapi/listener.c

495 lines
13 KiB
C
Raw Normal View History

checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
/*
2000-02-03 23:17:52 +00:00
* Copyright (C) 1996, 1997, 1998, 1999, 2000 Internet Software Consortium.
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
*
* Permission to use, copy, modify, and 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.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
1999-10-27 22:24:32 +00:00
/*
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
* Subroutines that support the generic listener object.
1999-10-27 22:24:32 +00:00
*/
#include <stdlib.h> /* NULL and abort() */
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
#include <string.h> /* memset */
1999-10-27 22:24:32 +00:00
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
#include <isc/assertions.h>
2000-01-04 20:04:42 +00:00
#include <isc/bufferlist.h>
2000-01-14 23:10:04 +00:00
#include <isc/error.h>
2000-01-04 20:04:42 +00:00
#include <isc/mem.h>
1999-10-27 22:24:32 +00:00
2000-01-04 20:04:42 +00:00
#include <omapi/private.h>
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
typedef struct omapi_listener_object {
OMAPI_OBJECT_PREAMBLE;
isc_mutex_t mutex;
2000-01-04 20:04:42 +00:00
isc_task_t *task;
isc_socket_t *socket; /* Listening socket. */
dns_acl_t *acl;
/*
* Locked by mutex.
*/
isc_boolean_t listening;
ISC_LIST(omapi_connection_t) connections;
2000-01-22 00:18:05 +00:00
} omapi_listener_t;
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
static void
free_listener(omapi_listener_t *listener) {
/*
* Break the link between the listener object and its parent
* (usually a generic object); this is done so the server's
* reference to its managing object does not prevent the
* listener object from being destroyed.
*/
OBJECT_DEREF(&listener->inner->outer);
OBJECT_DEREF(&listener->inner);
/*
* The listener object can now be freed.
*/
OBJECT_DEREF(&listener);
}
2000-01-04 20:04:42 +00:00
/*
* Reader callback for a listener object. Accept an incoming connection.
*/
static void
2000-01-17 18:02:11 +00:00
listener_accept(isc_task_t *task, isc_event_t *event) {
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
isc_result_t result;
2000-01-17 20:06:37 +00:00
isc_buffer_t *ibuffer = NULL;
isc_buffer_t *obuffer = NULL;
2000-01-06 03:36:32 +00:00
isc_task_t *connection_task = NULL;
2000-01-17 20:06:37 +00:00
isc_socket_t *socket;
isc_sockaddr_t sockaddr;
isc_netaddr_t netaddr;
2000-01-22 00:18:05 +00:00
omapi_connection_t *connection = NULL;
2000-01-17 20:06:37 +00:00
omapi_object_t *protocol = NULL;
omapi_listener_t *listener;
int match;
1999-10-27 22:24:32 +00:00
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
/*
* XXXDCL audit error handling
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
*/
2000-01-17 20:06:37 +00:00
result = ((isc_socket_newconnev_t *)event)->result;
socket = ((isc_socket_newconnev_t *)event)->newsocket;
listener = (omapi_listener_t *)event->arg;
2000-01-17 20:06:37 +00:00
/*
* No more need for the event, once all the desired data has been
* used from it.
*/
isc_event_free(&event);
1999-10-27 22:24:32 +00:00
if (result == ISC_R_CANCELED) {
/*
* omapi_listener_shutdown was called.
*/
LOCK(&listener->mutex);
listener->listening = ISC_FALSE;
if (ISC_LIST_HEAD(listener->connections) == NULL) {
UNLOCK(&listener->mutex);
free_listener(listener);
} else {
/*
* All connections this listener was responsible for
* must be removed.
*
* XXXDCL
* Since it is possible that this shutdown was
* triggered by one of the clients, it would be nice
* to give it a little time to exit, as well as allow
* any other connections to finish up cleanly.
* Unfortunately, since this could be called in the
* task/event thread of a program (as it is in named),
* no other events can be delivered while this routine
* blocks, so a loop to use isc_condition_waituntil
* until all of the connections are gone is pointless.
*/
for (connection = ISC_LIST_HEAD(listener->connections);
connection != NULL;
connection = ISC_LIST_NEXT(connection, link))
omapi_connection_disconnect((omapi_object_t *)
connection,
OMAPI_FORCE_DISCONNECT);
UNLOCK(&listener->mutex);
}
return;
}
/*
* Set up another accept task for the socket.
*/
isc_socket_accept(listener->socket, task, listener_accept, listener);
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
/*
2000-01-04 20:04:42 +00:00
* Check for the validity of new connection event.
* If the result is not ISC_R_SUCCESS, what can really
* be done about it other than just flunking out of here?
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
*/
2000-01-17 20:06:37 +00:00
if (result != ISC_R_SUCCESS)
return;
/*
* Is the connection from a valid host?
*/
result = isc_socket_getpeername(socket, &sockaddr);
if (result == ISC_R_SUCCESS) {
isc_netaddr_fromsockaddr(&netaddr, &sockaddr);
result = dns_acl_match(&netaddr, NULL, listener->acl,
NULL, &match, NULL);
}
if (result != ISC_R_SUCCESS || match <= 0) {
2000-01-04 20:04:42 +00:00
/*
* Permission denied. Close the connection.
* XXXDCL isc_log_write an error.
2000-01-04 20:04:42 +00:00
*/
isc_socket_detach(&socket);
2000-01-17 20:06:37 +00:00
return;
}
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
/*
2000-01-04 20:04:42 +00:00
* The new connection is good to go. Allocate the buffers for it and
2000-01-06 03:36:32 +00:00
* prepare its own task.
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
*/
2000-04-12 01:41:21 +00:00
if (isc_task_create(omapi_taskmgr, 0, &connection_task) !=
2000-01-04 20:04:42 +00:00
ISC_R_SUCCESS)
2000-01-14 23:10:04 +00:00
goto free_task;
2000-01-04 20:04:42 +00:00
ibuffer = NULL;
result = isc_buffer_allocate(omapi_mctx, &ibuffer, OMAPI_BUFFER_SIZE,
ISC_BUFFERTYPE_BINARY);
if (result != ISC_R_SUCCESS)
2000-01-14 23:10:04 +00:00
goto free_ibuffer;
2000-01-04 20:04:42 +00:00
obuffer = NULL;
result = isc_buffer_allocate(omapi_mctx, &obuffer, OMAPI_BUFFER_SIZE,
ISC_BUFFERTYPE_BINARY);
if (result != ISC_R_SUCCESS)
2000-01-14 23:10:04 +00:00
goto free_obuffer;
1999-10-27 22:24:32 +00:00
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
/*
2000-01-04 20:04:42 +00:00
* Create a new connection object.
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
*/
2000-01-17 18:02:11 +00:00
result = omapi_object_create((omapi_object_t **)&connection,
2000-01-06 03:36:32 +00:00
omapi_type_connection, sizeof(*connection));
2000-01-14 23:10:04 +00:00
if (result != ISC_R_SUCCESS)
goto free_obuffer;
1999-10-27 22:24:32 +00:00
2000-01-06 03:36:32 +00:00
connection->task = connection_task;
2000-01-04 20:04:42 +00:00
connection->state = omapi_connection_connected;
2000-01-17 20:06:37 +00:00
connection->socket = socket;
2000-01-13 06:13:26 +00:00
connection->is_client = ISC_FALSE;
1999-10-27 22:24:32 +00:00
2000-01-04 20:04:42 +00:00
ISC_LIST_INIT(connection->input_buffers);
ISC_LIST_APPEND(connection->input_buffers, ibuffer, link);
ISC_LIST_INIT(connection->output_buffers);
ISC_LIST_APPEND(connection->output_buffers, obuffer, link);
1999-10-27 22:24:32 +00:00
2000-01-04 20:04:42 +00:00
/*
2000-01-17 20:06:37 +00:00
* Create a new protocol object to oversee the handling of this
* connection.
2000-01-04 20:04:42 +00:00
*/
2000-01-17 20:06:37 +00:00
protocol = NULL;
result = omapi_object_create(&protocol, omapi_type_protocol,
2000-01-22 00:18:05 +00:00
sizeof(omapi_protocol_t));
2000-01-04 20:04:42 +00:00
if (result != ISC_R_SUCCESS)
2000-01-17 20:06:37 +00:00
goto free_connection_object;
/*
* Tie the protocol object bidirectionally to the connection
* object, with the connection as the outer object.
*/
OBJECT_REF(&protocol->outer, connection);
OBJECT_REF(&connection->inner, protocol);
/*
* Lose the external reference to the protocol object so both the
* connection object and protocol object will be freed when the
* connection ends.
2000-01-17 20:06:37 +00:00
*/
OBJECT_DEREF(&protocol);
2000-01-04 20:04:42 +00:00
/*
* Add the connection to the list of connections known by the
* listener. This is an added reference to the connection
* object, but since there's no easy way to use omapi_object_reference
* with the ISC_LIST macros, that reference is just not counted.
2000-01-04 20:04:42 +00:00
*/
LOCK(&listener->mutex);
ISC_LIST_APPEND(listener->connections, connection, link);
UNLOCK(&listener->mutex);
/*
* Remember the listener that accepted the connection, so it
* can be told when the connection goes away.
*/
OBJECT_REF(&connection->listener, listener);
2000-01-04 20:04:42 +00:00
2000-01-17 20:06:37 +00:00
/*
* Send the introductory message. The return value does not
* matter; if send_intro failed, it already destroyed the connection.
2000-01-17 20:06:37 +00:00
*/
(void)send_intro(connection->inner, OMAPI_PROTOCOL_VERSION);
return;
2000-01-17 20:06:37 +00:00
free_connection_object:
2000-01-14 23:10:04 +00:00
/*
* Destroy the connection. This will free everything created
2000-01-17 20:06:37 +00:00
* in this function but the event, which was already freed.
2000-01-14 23:10:04 +00:00
*/
2000-01-17 18:02:11 +00:00
OBJECT_DEREF(&connection);
2000-01-14 23:10:04 +00:00
return;
/*
* Free resources that were being created for the connection object.
*/
free_obuffer:
isc_buffer_free(&obuffer);
free_ibuffer:
isc_buffer_free(&ibuffer);
free_task:
isc_task_destroy(&connection_task);
1999-10-27 22:24:32 +00:00
}
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
isc_result_t
omapi_listener_listen(omapi_object_t *caller, isc_sockaddr_t *addr,
dns_acl_t *acl, int max,
isc_taskaction_t destroy_action, void *destroy_arg)
{
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
isc_result_t result;
2000-01-04 20:04:42 +00:00
isc_task_t *task;
2000-01-22 00:18:05 +00:00
omapi_listener_t *listener;
1999-10-27 22:24:32 +00:00
REQUIRE(caller != NULL);
REQUIRE(addr != NULL && isc_sockaddr_getport(addr) != 0);
2000-01-04 20:04:42 +00:00
task = NULL;
2000-04-12 01:41:21 +00:00
result = isc_task_create(omapi_taskmgr, 0, &task);
2000-01-04 20:04:42 +00:00
if (result != ISC_R_SUCCESS)
return (result);
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
/*
2000-01-17 20:06:37 +00:00
* Create the listener object.
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
*/
2000-01-17 20:06:37 +00:00
listener = NULL;
result = omapi_object_create((omapi_object_t **)&listener,
omapi_type_listener, sizeof(*listener));
if (result != ISC_R_SUCCESS) {
isc_task_destroy(&task);
return (result);
}
2000-01-04 20:04:42 +00:00
listener->task = task;
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
RUNTIME_CHECK(isc_mutex_init(&listener->mutex) == ISC_R_SUCCESS);
ISC_LIST_INIT(listener->connections);
2000-01-04 20:04:42 +00:00
/*
* Create a socket on which to listen.
*/
listener->socket = NULL;
result = isc_socket_create(omapi_socketmgr, PF_INET,
isc_sockettype_tcp, &listener->socket);
2000-01-17 20:06:37 +00:00
if (result == ISC_R_SUCCESS)
result = isc_socket_bind(listener->socket, addr);
1999-10-27 22:24:32 +00:00
2000-01-17 20:06:37 +00:00
if (result == ISC_R_SUCCESS)
/*
* Now tell the kernel to listen for connections.
*/
result = isc_socket_listen(listener->socket, max);
if (result == ISC_R_SUCCESS) {
2000-01-17 20:06:37 +00:00
/*
* Queue up the first accept event. The listener object
* will be passed to listener_accept() when it is called.
2000-01-17 20:06:37 +00:00
*/
dns_acl_attach(acl, &listener->acl);
listener->listening = ISC_TRUE;
2000-01-17 20:06:37 +00:00
result = isc_socket_accept(listener->socket, task,
listener_accept, listener);
}
1999-10-27 22:24:32 +00:00
if (result == ISC_R_SUCCESS) {
/*
* Tie the listener object to the calling object.
*/
OBJECT_REF(&caller->outer, listener);
OBJECT_REF(&listener->inner, caller);
/*
* The callback is not set until here because it should
* only be called if the listener was successfully set up.
*/
listener->destroy_action = destroy_action;
listener->destroy_arg = destroy_arg;
} else {
2000-01-17 20:06:37 +00:00
/*
* Failed to set up the listener.
2000-01-17 20:06:37 +00:00
*/
listener->listening = ISC_FALSE;
2000-01-17 18:02:11 +00:00
OBJECT_DEREF(&listener);
}
2000-01-04 20:04:42 +00:00
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
return (result);
1999-10-27 22:24:32 +00:00
}
void
omapi_listener_shutdown(omapi_object_t *listener) {
omapi_listener_t *l;
REQUIRE((listener != NULL && listener->type == omapi_type_listener) ||
(listener->outer != NULL &&
listener->outer->type == omapi_type_listener));
if (listener->type == omapi_type_listener)
l = (omapi_listener_t *)listener;
else
l = (omapi_listener_t *)listener->outer;
/*
* It is improper to call this function without having had a successful
* run of omapi_listener_listen.
*/
REQUIRE(l->socket != NULL && l->task != NULL);
/*
* Stop accepting connections.
*/
isc_socket_cancel(l->socket, NULL, ISC_SOCKCANCEL_ACCEPT);
}
2000-01-17 18:02:11 +00:00
static isc_result_t
2000-01-22 00:18:05 +00:00
listener_setvalue(omapi_object_t *listener, omapi_string_t *name,
omapi_data_t *value)
1999-10-27 22:24:32 +00:00
{
2000-01-04 20:04:42 +00:00
/*
* Nothing meaningful can be set in a listener object; just
* continue the call through the object chain.
*/
REQUIRE(listener != NULL && listener->type == omapi_type_listener);
2000-01-22 00:18:05 +00:00
return (omapi_object_passsetvalue(listener, name, value));
1999-10-27 22:24:32 +00:00
}
2000-01-17 18:02:11 +00:00
static isc_result_t
2000-01-22 00:18:05 +00:00
listener_getvalue(omapi_object_t *listener, omapi_string_t *name,
omapi_value_t **value)
1999-10-27 22:24:32 +00:00
{
2000-01-04 20:04:42 +00:00
/*
* Nothing meaningful can be fetched from a listener object; just
* continue the call through the object chain.
*/
REQUIRE(listener != NULL && listener->type == omapi_type_listener);
1999-10-27 22:24:32 +00:00
2000-01-22 00:18:05 +00:00
return (omapi_object_passgetvalue(listener, name, value));
1999-10-27 22:24:32 +00:00
}
2000-01-17 18:02:11 +00:00
static void
listener_destroy(omapi_object_t *listener) {
omapi_listener_t *l;
1999-10-27 22:24:32 +00:00
REQUIRE(listener != NULL && listener->type == omapi_type_listener);
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
l = (omapi_listener_t *)listener;
2000-01-04 20:04:42 +00:00
LOCK(&l->mutex);
INSIST(ISC_LIST_EMPTY(l->connections));
UNLOCK(&l->mutex);
RUNTIME_CHECK(isc_mutex_destroy(&l->mutex) == ISC_R_SUCCESS);
2000-01-17 20:06:37 +00:00
if (l->task != NULL)
isc_task_destroy(&l->task);
if (l->socket != NULL)
isc_socket_detach(&l->socket);
if (l->acl != NULL)
dns_acl_detach(&l->acl);
1999-10-27 22:24:32 +00:00
}
2000-01-17 18:02:11 +00:00
static isc_result_t
listener_signalhandler(omapi_object_t *listener, const char *name, va_list ap)
1999-10-27 22:24:32 +00:00
{
omapi_connection_t *c;
omapi_listener_t *l;
isc_result_t result;
2000-01-04 20:04:42 +00:00
REQUIRE(listener != NULL && listener->type == omapi_type_listener);
l = (omapi_listener_t *)listener;
2000-01-04 20:04:42 +00:00
/*
* free_connection() signals the listener when one of the connections
* it accepted has gone away.
2000-01-04 20:04:42 +00:00
*/
if (strcmp(name, "disconnect") == 0) {
c = va_arg(ap, omapi_connection_t *);
LOCK(&l->mutex);
ISC_LIST_UNLINK(l->connections, c, link);
if (! l->listening && ISC_LIST_HEAD(l->connections) == NULL) {
/*
* The listener has been shutdown and the last
* connection was received.
*/
UNLOCK(&l->mutex);
free_listener(l);
} else
UNLOCK(&l->mutex);
result = ISC_R_SUCCESS;
} else
result = omapi_object_passsignal(listener, name, ap);
return (result);
1999-10-27 22:24:32 +00:00
}
checkpoint conversion to ISC (doc/dev/coding.html) style. * no spaces around " -> " in indirect postfix expression. * no space between function name and open parenthesis. * no space between array name and open bracket. * use NULL not 0 for pointers. * explicitly compare pointers to NULL. * explicitly compare integers to 0. * Do not cast NULL. * return type of function declaration on line by itself. * open brace of function definition follows close parenthesis if parameters all fit on one line. * comment-only lines start with /* on line by itself, and end with */ on line by itself. * variable names in structures separated from their types in a column. * name the parameters in function prototypes. * ifndef multiple header file inclusion. and other BIND9 conventions not in coding.html: * private structures defined in relevant source module, not private header. * RCS /* $Id: $ */ comments. * Principal Author (Ted Lemon) comments. * Updated ISC copyrights. * Parenthesize value of return(). * Parenthesize argument of sizeof(). * "unsigned int foo" not "unsigned foo". * ISC_LANG_(BEGIN|END)DECLS in header files. * header files included directly by source/header file that needs them. * ... and others I am probably forgetting. and conversion to some libisc.a modules: * use isc/int.h for isc_uintXX_t types, not u_intXX_t. * use isc/assertions.h for REQUIRE() and INSIST(). * use isc/error.h for UNEXPECTED_ERROR. * use isc/boolean.h for isc_boolean_t flags instead of int flags. * use isc/net.h for networking types. * use isc/netdb.h for gethostby*. STILL TO COME ... * more isc_boolean_t. * isc/time.h to replace struct timeval. * isc/socket.h to replace socket/listen/select/etc. * isc/mem.h to replace malloc/free. * namespace overhaul & omapi/compatibility.h. Please collect all your belongings but stand clear of the doors until this train has come to a complete stop.
1999-11-02 04:01:34 +00:00
/*
* Write all the published values associated with the object through the
* specified connection.
*/
2000-01-17 18:02:11 +00:00
static isc_result_t
2000-01-22 00:18:05 +00:00
listener_stuffvalues(omapi_object_t *connection, omapi_object_t *listener)
1999-10-27 22:24:32 +00:00
{
2000-01-04 20:04:42 +00:00
REQUIRE(listener != NULL && listener->type == omapi_type_listener);
1999-10-27 22:24:32 +00:00
2000-01-22 00:18:05 +00:00
return (omapi_object_passstuffvalues(connection, listener));
1999-10-27 22:24:32 +00:00
}
2000-01-17 18:02:11 +00:00
isc_result_t
2000-01-22 00:18:05 +00:00
listener_init(void) {
2000-01-17 20:06:37 +00:00
return (omapi_object_register(&omapi_type_listener, "listener",
listener_setvalue,
listener_getvalue,
listener_destroy,
listener_signalhandler,
listener_stuffvalues,
NULL, NULL, NULL));
2000-01-17 18:02:11 +00:00
}