2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-23 10:39:16 +00:00
bind/lib/omapi/lib.c

139 lines
3.2 KiB
C
Raw Normal View History

1999-10-27 23:55:07 +00:00
/*
2000-02-03 23:17:52 +00:00
* Copyright (C) 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 23:55:07 +00:00
*/
/* $ID: $ */
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-06 03:36:32 +00:00
#include <stddef.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
#include <isc/assertions.h>
2000-01-06 03:36:32 +00:00
#include <isc/once.h>
#include <isc/error.h>
#include <isc/msgcat.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
2000-01-06 03:36:32 +00:00
#include <omapi/lib.h>
2000-01-22 00:18:05 +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
2000-01-06 03:36:32 +00:00
/***
2000-01-22 00:18:05 +00:00
*** Library Globals.
2000-01-06 03:36: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-22 00:18:05 +00:00
isc_msgcat_t *omapi_msgcat = NULL;
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-22 00:18:05 +00:00
omapi_objecttype_t *omapi_type_connection;
omapi_objecttype_t *omapi_type_listener;
omapi_objecttype_t *omapi_type_generic;
omapi_objecttype_t *omapi_type_protocol;
omapi_objecttype_t *omapi_type_message;
omapi_objecttype_t *omapi_object_types;
isc_mem_t *omapi_mctx;
isc_task_t *omapi_task;
2000-01-22 00:18:05 +00:00
isc_taskmgr_t *omapi_taskmgr;
isc_socketmgr_t *omapi_socketmgr;
2000-01-06 03:36:32 +00:00
/***
2000-01-22 00:18:05 +00:00
*** Private to lib.c.
2000-01-06 03:36:32 +00:00
***/
2000-01-22 00:18:05 +00:00
static isc_once_t msgcat_once = ISC_ONCE_INIT;
2000-01-06 03:36:32 +00:00
/***
2000-01-22 00:18:05 +00:00
*** Functions.
2000-01-06 03:36:32 +00:00
***/
static void
open_msgcat(void) {
isc_msgcat_open("libomapi.cat", &omapi_msgcat);
}
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
void
2000-01-06 03:36:32 +00:00
omapi_lib_initmsgcat(void) {
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-06 03:36:32 +00:00
/*
* Initialize the OMAPI library's message catalog, omapi_msgcat, if it
* has not already been initialized.
*/
RUNTIME_CHECK(isc_once_do(&msgcat_once, open_msgcat) == ISC_R_SUCCESS);
}
2000-01-22 00:18:05 +00:00
isc_result_t
omapi_lib_init(isc_mem_t *mctx, isc_taskmgr_t *taskmgr,
isc_socketmgr_t *socketmgr)
{
2000-01-22 00:18:05 +00:00
isc_result_t result;
/*
* Can only be called once without an intervening omapi_lib_destroy.
*/
REQUIRE(omapi_mctx == NULL &&
omapi_socketmgr == NULL &&
omapi_taskmgr == NULL &&
omapi_task == NULL &&
omapi_object_types == NULL);
REQUIRE(mctx != NULL && taskmgr != NULL && socketmgr != NULL);
2000-01-22 00:18:05 +00:00
omapi_mctx = mctx;
omapi_taskmgr = taskmgr;
omapi_socketmgr = socketmgr;
2000-01-22 00:18:05 +00:00
result = isc_task_create(omapi_taskmgr, omapi_mctx, 0, &omapi_task);
if (result == ISC_R_SUCCESS)
isc_task_setname(omapi_task, "omapi", NULL);
2000-01-22 00:18:05 +00:00
/*
* Initialize the standard object types.
*/
if (result == ISC_R_SUCCESS)
result = generic_init();
2000-01-22 00:18:05 +00:00
if (result == ISC_R_SUCCESS)
result = listener_init();
if (result == ISC_R_SUCCESS)
result = connection_init();
if (result == ISC_R_SUCCESS)
result = protocol_init();
if (result == ISC_R_SUCCESS)
result = message_init();
return (result);
}
/*
* This does not free connections and other in-use objects, only the
* things created by omapi_lib_init(). It is the callers responsibility to
* free the other things (as via omapi_connection_disconnect or
* omapi_object_dereference).
*/
void
omapi_lib_destroy() {
object_destroytypes();
handle_destroy();
2000-03-14 03:39:40 +00:00
auth_destroy();
isc_task_destroy(&omapi_task);
omapi_mctx = NULL;
omapi_socketmgr = NULL;
omapi_taskmgr = NULL;
2000-01-22 00:18:05 +00:00
}