📄 message.c
字号:
/* message.c Subroutines for dealing with message objects. *//* * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC") * Copyright (c) 1999-2003 by Internet Software Consortium * * 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 ISC DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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. * * Internet Systems Consortium, Inc. * 950 Charter Street * Redwood City, CA 94063 * <info@isc.org> * http://www.isc.org/ * * This software has been written for Internet Systems Consortium * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc. * To learn more about Internet Systems Consortium, see * ``http://www.isc.org/''. To learn more about Vixie Enterprises, * see ``http://www.vix.com''. To learn more about Nominum, Inc., see * ``http://www.nominum.com''. */#include <omapip/omapip_p.h>OMAPI_OBJECT_ALLOC (omapi_message, omapi_message_object_t, omapi_type_message)omapi_message_object_t *omapi_registered_messages;isc_result_t omapi_message_new (omapi_object_t **o, const char *file, int line){ omapi_message_object_t *m; omapi_object_t *g; isc_result_t status; m = (omapi_message_object_t *)0; status = omapi_message_allocate (&m, file, line); if (status != ISC_R_SUCCESS) return status; g = (omapi_object_t *)0; status = omapi_generic_new (&g, file, line); if (status != ISC_R_SUCCESS) { dfree (m, file, line); return status; } status = omapi_object_reference (&m -> inner, g, file, line); if (status != ISC_R_SUCCESS) { omapi_object_dereference ((omapi_object_t **)&m, file, line); omapi_object_dereference (&g, file, line); return status; } status = omapi_object_reference (&g -> outer, (omapi_object_t *)m, file, line); if (status != ISC_R_SUCCESS) { omapi_object_dereference ((omapi_object_t **)&m, file, line); omapi_object_dereference (&g, file, line); return status; } status = omapi_object_reference (o, (omapi_object_t *)m, file, line); omapi_message_dereference (&m, file, line); omapi_object_dereference (&g, file, line); if (status != ISC_R_SUCCESS) return status; return status;}isc_result_t omapi_message_set_value (omapi_object_t *h, omapi_object_t *id, omapi_data_string_t *name, omapi_typed_data_t *value){ omapi_message_object_t *m; isc_result_t status; if (h -> type != omapi_type_message) return ISC_R_INVALIDARG; m = (omapi_message_object_t *)h; /* Can't set authlen. */ /* Can set authenticator, but the value must be typed data. */ if (!omapi_ds_strcmp (name, "authenticator")) { if (m -> authenticator) omapi_typed_data_dereference (&m -> authenticator, MDL); omapi_typed_data_reference (&m -> authenticator, value, MDL); return ISC_R_SUCCESS; } else if (!omapi_ds_strcmp (name, "object")) { if (value -> type != omapi_datatype_object) return ISC_R_INVALIDARG; if (m -> object) omapi_object_dereference (&m -> object, MDL); omapi_object_reference (&m -> object, value -> u.object, MDL); return ISC_R_SUCCESS; } else if (!omapi_ds_strcmp (name, "notify-object")) { if (value -> type != omapi_datatype_object) return ISC_R_INVALIDARG; if (m -> notify_object) omapi_object_dereference (&m -> notify_object, MDL); omapi_object_reference (&m -> notify_object, value -> u.object, MDL); return ISC_R_SUCCESS; /* Can set authid, but it has to be an integer. */ } else if (!omapi_ds_strcmp (name, "authid")) { if (value -> type != omapi_datatype_int) return ISC_R_INVALIDARG; m -> authid = value -> u.integer; return ISC_R_SUCCESS; /* Can set op, but it has to be an integer. */ } else if (!omapi_ds_strcmp (name, "op")) { if (value -> type != omapi_datatype_int) return ISC_R_INVALIDARG; m -> op = value -> u.integer; return ISC_R_SUCCESS; /* Handle also has to be an integer. */ } else if (!omapi_ds_strcmp (name, "handle")) { if (value -> type != omapi_datatype_int) return ISC_R_INVALIDARG; m -> h = value -> u.integer; return ISC_R_SUCCESS; /* Transaction ID has to be an integer. */ } else if (!omapi_ds_strcmp (name, "id")) { if (value -> type != omapi_datatype_int) return ISC_R_INVALIDARG; m -> id = value -> u.integer; return ISC_R_SUCCESS; /* Remote transaction ID has to be an integer. */ } else if (!omapi_ds_strcmp (name, "rid")) { if (value -> type != omapi_datatype_int) return ISC_R_INVALIDARG; m -> rid = value -> u.integer; return ISC_R_SUCCESS; } /* Try to find some inner object that can take the value. */ if (h -> inner && h -> inner -> type -> set_value) { status = ((*(h -> inner -> type -> set_value)) (h -> inner, id, name, value)); if (status == ISC_R_SUCCESS) return status; } return ISC_R_NOTFOUND;}isc_result_t omapi_message_get_value (omapi_object_t *h, omapi_object_t *id, omapi_data_string_t *name, omapi_value_t **value){ omapi_message_object_t *m; if (h -> type != omapi_type_message) return ISC_R_INVALIDARG; m = (omapi_message_object_t *)h; /* Look for values that are in the message data structure. */ if (!omapi_ds_strcmp (name, "authlen")) return omapi_make_int_value (value, name, (int)m -> authlen, MDL); else if (!omapi_ds_strcmp (name, "authenticator")) { if (m -> authenticator) return omapi_make_value (value, name, m -> authenticator, MDL); else return ISC_R_NOTFOUND; } else if (!omapi_ds_strcmp (name, "authid")) { return omapi_make_int_value (value, name, (int)m -> authid, MDL); } else if (!omapi_ds_strcmp (name, "op")) { return omapi_make_int_value (value, name, (int)m -> op, MDL); } else if (!omapi_ds_strcmp (name, "handle")) { return omapi_make_int_value (value, name, (int)m -> h, MDL); } else if (!omapi_ds_strcmp (name, "id")) { return omapi_make_int_value (value, name, (int)m -> id, MDL); } else if (!omapi_ds_strcmp (name, "rid")) { return omapi_make_int_value (value, name, (int)m -> rid, MDL); } /* See if there's an inner object that has the value. */ if (h -> inner && h -> inner -> type -> get_value) return (*(h -> inner -> type -> get_value)) (h -> inner, id, name, value); return ISC_R_NOTFOUND;}isc_result_t omapi_message_destroy (omapi_object_t *h, const char *file, int line){ int i; omapi_message_object_t *m; if (h -> type != omapi_type_message) return ISC_R_INVALIDARG; m = (omapi_message_object_t *)h; if (m -> authenticator) { omapi_typed_data_dereference (&m -> authenticator, file, line); } if (!m -> prev && omapi_registered_messages != m) omapi_message_unregister (h); if (m -> id_object) omapi_object_dereference (&m -> id_object, file, line); if (m -> object) omapi_object_dereference (&m -> object, file, line); if (m -> notify_object) omapi_object_dereference (&m -> notify_object, file, line); if (m -> protocol_object) omapi_protocol_dereference (&m -> protocol_object, file, line); return ISC_R_SUCCESS;}isc_result_t omapi_message_signal_handler (omapi_object_t *h, const char *name, va_list ap){ omapi_message_object_t *m; if (h -> type != omapi_type_message) return ISC_R_INVALIDARG; m = (omapi_message_object_t *)h; if (!strcmp (name, "status")) { if (m -> notify_object && m -> notify_object -> type -> signal_handler) return ((m -> notify_object -> type -> signal_handler)) (m -> notify_object, name, ap); else if (m -> object && m -> object -> type -> signal_handler) return ((m -> object -> type -> signal_handler)) (m -> object, name, ap); } if (h -> inner && h -> inner -> type -> signal_handler) return (*(h -> inner -> type -> signal_handler)) (h -> inner, name, ap); return ISC_R_NOTFOUND;}/* Write all the published values associated with the object through the specified connection. */isc_result_t omapi_message_stuff_values (omapi_object_t *c, omapi_object_t *id, omapi_object_t *m){ int i; if (m -> type != omapi_type_message) return ISC_R_INVALIDARG; if (m -> inner && m -> inner -> type -> stuff_values) return (*(m -> inner -> type -> stuff_values)) (c, id, m -> inner); return ISC_R_SUCCESS;}isc_result_t omapi_message_register (omapi_object_t *mo){ omapi_message_object_t *m; if (mo -> type != omapi_type_message) return ISC_R_INVALIDARG; m = (omapi_message_object_t *)mo; /* Already registered? */ if (m -> prev || m -> next || omapi_registered_messages == m) return ISC_R_INVALIDARG; if (omapi_registered_messages) { omapi_object_reference ((omapi_object_t **)&m -> next, (omapi_object_t *)omapi_registered_messages, MDL); omapi_object_reference ((omapi_object_t **)&omapi_registered_messages -> prev, (omapi_object_t *)m, MDL); omapi_object_dereference ((omapi_object_t **)&omapi_registered_messages, MDL); } omapi_object_reference ((omapi_object_t **)&omapi_registered_messages, (omapi_object_t *)m, MDL); return ISC_R_SUCCESS;;}isc_result_t omapi_message_unregister (omapi_object_t *mo){ omapi_message_object_t *m; omapi_message_object_t *n; if (mo -> type != omapi_type_message) return ISC_R_INVALIDARG; m = (omapi_message_object_t *)mo; /* Not registered? */ if (!m -> prev && omapi_registered_messages != m) return ISC_R_INVALIDARG; n = (omapi_message_object_t *)0; if (m -> next) { omapi_object_reference ((omapi_object_t **)&n, (omapi_object_t *)m -> next, MDL); omapi_object_dereference ((omapi_object_t **)&m -> next, MDL); omapi_object_dereference ((omapi_object_t **)&n -> prev, MDL); } if (m -> prev) { omapi_message_object_t *tmp = (omapi_message_object_t *)0; omapi_object_reference ((omapi_object_t **)&tmp, (omapi_object_t *)m -> prev, MDL); omapi_object_dereference ((omapi_object_t **)&m -> prev, MDL); if (tmp -> next) omapi_object_dereference ((omapi_object_t **)&tmp -> next, MDL); if (n) omapi_object_reference ((omapi_object_t **)&tmp -> next, (omapi_object_t *)n, MDL); omapi_object_dereference ((omapi_object_t **)&tmp, MDL); } else { omapi_object_dereference ((omapi_object_t **)&omapi_registered_messages, MDL); if (n) omapi_object_reference ((omapi_object_t **)&omapi_registered_messages, (omapi_object_t *)n, MDL); } if (n) omapi_object_dereference ((omapi_object_t **)&n, MDL); return ISC_R_SUCCESS;}#ifdef DEBUG_PROTOCOLstatic const char *omapi_message_op_name(int op) { switch (op) { case OMAPI_OP_OPEN: return "OMAPI_OP_OPEN"; case OMAPI_OP_REFRESH: return "OMAPI_OP_REFRESH"; case OMAPI_OP_UPDATE: return "OMAPI_OP_UPDATE"; case OMAPI_OP_STATUS: return "OMAPI_OP_STATUS"; case OMAPI_OP_DELETE: return "OMAPI_OP_DELETE"; case OMAPI_OP_NOTIFY: return "OMAPI_OP_NOTIFY"; default: return "(unknown op)"; }}#endifstatic isc_result_tomapi_message_process_internal (omapi_object_t *, omapi_object_t *);isc_result_t omapi_message_process (omapi_object_t *mo, omapi_object_t *po){ isc_result_t status;#if defined (DEBUG_MEMORY_LEAKAGE) unsigned long previous_outstanding = dmalloc_outstanding;#endif status = omapi_message_process_internal (mo, po);#if defined (DEBUG_MEMORY_LEAKAGE) && 0 log_info ("generation %ld: %ld new, %ld outstanding, %ld long-term", dmalloc_generation, dmalloc_outstanding - previous_outstanding, dmalloc_outstanding, dmalloc_longterm);#endif#if defined (DEBUG_MEMORY_LEAKAGE) && 0 dmalloc_dump_outstanding ();#endif#if defined (DEBUG_RC_HISTORY_EXHAUSTIVELY) && 0 dump_rc_history ();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -