<commit_before>/*
 * Copyright (C) 1996, 1997, 1998, 1999, 2000  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 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.
 */

/*
 * Subroutines for dealing with message objects.
 */

#include <config.h>

#include <stddef.h>

#include <isc/buffer.h>
#include <isc/string.h>
#include <isc/util.h>

#include <omapi/private.h>
#include <omapi/result.h>

omapi_message_t *registered_messages;

isc_result_t
omapi_message_create(omapi_object_t **o) {
	omapi_message_t *message = NULL;
	omapi_object_t *g;
	isc_result_t result;

	result = omapi_object_create((omapi_object_t **)&message,
				     omapi_type_message, sizeof(*message));
	if (result != ISC_R_SUCCESS)
		return (result);

	g = NULL;
	result = omapi_object_create(&g, NULL, 0);
	if (result != ISC_R_SUCCESS) {
		OBJECT_DEREF(&message);
		return (result);
	}

	OBJECT_REF(&message->inner, g);
	OBJECT_REF(&g->outer, message);
	OBJECT_REF(o, message);

	OBJECT_DEREF(&message);
	OBJECT_DEREF(&g);

	return (result);
}

/*
 * XXXDCL Make register/unregister implicitly part of omapi_message_send?
 */
void
omapi_message_register(omapi_object_t *h) {
	omapi_message_t *m;

	REQUIRE(h != NULL && h->type == omapi_type_message);

	m = (omapi_message_t *)h;
	
	/*
	 * Already registered?
	 */
	REQUIRE(m->prev == NULL && m->next == NULL &&
		registered_messages != m);

	if (registered_messages != NULL) {
		OBJECT_REF(&m->next, registered_messages);
		OBJECT_REF(&registered_messages->prev, m);
		OBJECT_DEREF(&registered_messages);
	}

	OBJECT_REF(&registered_messages, m);
}

void
omapi_message_unregister(omapi_object_t *h) {
	omapi_message_t *m;
	omapi_message_t *n;

	REQUIRE(h != NULL && h->type == omapi_type_message);

	m = (omapi_message_t *)h;
	
	/*
	 * Not registered?
	 */
	REQUIRE(m->prev != NULL || registered_messages == m);

	n = NULL;
	if (m->next != NULL) {
		OBJECT_REF(&n, m->next);
		OBJECT_DEREF(&m->next);
	}

	if (m->prev != NULL) {
		omapi_message_t *tmp = NULL;
		OBJECT_REF(&tmp, m->prev);
		OBJECT_DEREF(&m->prev);

		if (tmp->next != NULL)
			OBJECT_DEREF(&tmp->next);

		if (n != NULL)
			OBJECT_REF(&tmp->next, n);

		OBJECT_DEREF(&tmp);

	} else {
		OBJECT_DEREF(&registered_messages);
		if (n != NULL)
			OBJECT_REF(&registered_messages, n);
	}

	if (n != NULL)
		OBJECT_DEREF(&n);
}

isc_result_t
omapi_message_send(omapi_object_t *message, omapi_object_t *protocol) {
	/*
	 * For this function, at least, generic objects have fully spelled
	 * names and special type objects have short names.
	 * XXXDCL It would be good to be more consistent about this throughout
	 * the omapi library code.
	 */
	omapi_protocol_t *p;
	omapi_connection_t *c;
	omapi_message_t *m;
	omapi_object_t *connection;
	int authlen = 0;
	isc_result_t result = ISC_R_SUCCESS;

	REQUIRE(message != NULL && message->type == omapi_type_message);
	/*
	 * Allow the function to be called with an object that is managing
	 * the client side.
	 */
	REQUIRE((protocol != NULL && protocol->type == omapi_type_protocol) ||
		(protocol->outer != NULL &&
		 protocol->outer->type == omapi_type_protocol));

	if (protocol->type != omapi_type_protocol)
		protocol = protocol->outer;

	p = (omapi_protocol_t *)protocol;

	connection = (omapi_object_t *)(protocol->outer);
	c = (omapi_connection_t *)connection;
<commit_msg>changed authlen from signed int to unsigned int in omapi_message_send<commit_after>/*
 * Copyright (C) 1996, 1997, 1998, 1999, 2000  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 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.
 */

/*
 * Subroutines for dealing with message objects.
 */

#include <config.h>

#include <stddef.h>

#include <isc/buffer.h>
#include <isc/string.h>
#include <isc/util.h>

#include <omapi/private.h>
#include <omapi/result.h>

omapi_message_t *registered_messages;

isc_result_t
omapi_message_create(omapi_object_t **o) {
	omapi_message_t *message = NULL;
	omapi_object_t *g;
	isc_result_t result;

	result = omapi_object_create((omapi_object_t **)&message,
				     omapi_type_message, sizeof(*message));
	if (result != ISC_R_SUCCESS)
		return (result);

	g = NULL;
	result = omapi_object_create(&g, NULL, 0);
	if (result != ISC_R_SUCCESS) {
		OBJECT_DEREF(&message);
		return (result);
	}

	OBJECT_REF(&message->inner, g);
	OBJECT_REF(&g->outer, message);
	OBJECT_REF(o, message);

	OBJECT_DEREF(&message);
	OBJECT_DEREF(&g);

	return (result);
}

/*
 * XXXDCL Make register/unregister implicitly part of omapi_message_send?
 */
void
omapi_message_register(omapi_object_t *h) {
	omapi_message_t *m;

	REQUIRE(h != NULL && h->type == omapi_type_message);

	m = (omapi_message_t *)h;
	
	/*
	 * Already registered?
	 */
	REQUIRE(m->prev == NULL && m->next == NULL &&
		registered_messages != m);

	if (registered_messages != NULL) {
		OBJECT_REF(&m->next, registered_messages);
		OBJECT_REF(&registered_messages->prev, m);
		OBJECT_DEREF(&registered_messages);
	}

	OBJECT_REF(&registered_messages, m);
}

void
omapi_message_unregister(omapi_object_t *h) {
	omapi_message_t *m;
	omapi_message_t *n;

	REQUIRE(h != NULL && h->type == omapi_type_message);

	m = (omapi_message_t *)h;
	
	/*
	 * Not registered?
	 */
	REQUIRE(m->prev != NULL || registered_messages == m);

	n = NULL;
	if (m->next != NULL) {
		OBJECT_REF(&n, m->next);
		OBJECT_DEREF(&m->next);
	}

	if (m->prev != NULL) {
		omapi_message_t *tmp = NULL;
		OBJECT_REF(&tmp, m->prev);
		OBJECT_DEREF(&m->prev);

		if (tmp->next != NULL)
			OBJECT_DEREF(&tmp->next);

		if (n != NULL)
			OBJECT_REF(&tmp->next, n);

		OBJECT_DEREF(&tmp);

	} else {
		OBJECT_DEREF(&registered_messages);
		if (n != NULL)
			OBJECT_REF(&registered_messages, n);
	}

	if (n != NULL)
		OBJECT_DEREF(&n);
}

isc_result_t
omapi_message_send(omapi_object_t *message, omapi_object_t *protocol) {
	/*
	 * For this function, at least, generic objects have fully spelled
	 * names and special type objects have short names.
	 * XXXDCL It would be good to be more consistent about this throughout
	 * the omapi library code.
	 */
	omapi_protocol_t *p;
	omapi_connection_t *c;
	omapi_message_t *m;
	omapi_object_t *connection;
	unsigned int authlen = 0;
	isc_result_t result = ISC_R_SUCCESS;

	REQUIRE(message != NULL && message->type == omapi_type_message);
	/*
	 * Allow the function to be called with an object that is managing
	 * the client side.
	 */
	REQUIRE((protocol != NULL && protocol->type == omapi_type_protocol) ||
		(protocol->outer != NULL &&
		 protocol->outer->type == omapi_type_protocol));

	if (protocol->type != omapi_type_protocol)
		protocol = protocol->outer;

	p = (omapi_protocol_t *)protocol;

	connection = (omapi_object_t *)(protocol->outer);
	c = (omapi_connection_t *)connection;

{'fraction_non_alphanumeric': 0.12266600717200445, 'fraction_numerical': 0.005440830963274391, 'mean_word_length': 4.475964793500339, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3263208', 'n_tokens_mistral': 2986, 'n_tokens_neox': 2761, 'n_words': 764}