155682Smarkm/* $NetBSD$ */ 255682Smarkm 355682Smarkm/* 455682Smarkm * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC") 555682Smarkm * Copyright (C) 1999-2001 Internet Software Consortium. 655682Smarkm * 755682Smarkm * Permission to use, copy, modify, and/or distribute this software for any 855682Smarkm * purpose with or without fee is hereby granted, provided that the above 955682Smarkm * copyright notice and this permission notice appear in all copies. 1055682Smarkm * 1155682Smarkm * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 1255682Smarkm * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 1355682Smarkm * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 1455682Smarkm * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 1555682Smarkm * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 1655682Smarkm * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 1755682Smarkm * PERFORMANCE OF THIS SOFTWARE. 1855682Smarkm */ 1955682Smarkm 2055682Smarkm/* Id: tcpmsg.h,v 1.22 2007/06/19 23:47:17 tbox Exp */ 2155682Smarkm 2255682Smarkm#ifndef DNS_TCPMSG_H 2355682Smarkm#define DNS_TCPMSG_H 1 2455682Smarkm 2555682Smarkm/*! \file dns/tcpmsg.h */ 2655682Smarkm 2755682Smarkm#include <isc/buffer.h> 2855682Smarkm#include <isc/lang.h> 2955682Smarkm#include <isc/socket.h> 3055682Smarkm 3155682Smarkmtypedef struct dns_tcpmsg { 3255682Smarkm /* private (don't touch!) */ 3355682Smarkm unsigned int magic; 3455682Smarkm isc_uint16_t size; 3555682Smarkm isc_buffer_t buffer; 3655682Smarkm unsigned int maxsize; 3755682Smarkm isc_mem_t *mctx; 3855682Smarkm isc_socket_t *sock; 3955682Smarkm isc_task_t *task; 4055682Smarkm isc_taskaction_t action; 4155682Smarkm void *arg; 4255682Smarkm isc_event_t event; 4355682Smarkm /* public (read-only) */ 4455682Smarkm isc_result_t result; 4555682Smarkm isc_sockaddr_t address; 4655682Smarkm} dns_tcpmsg_t; 4755682Smarkm 4855682SmarkmISC_LANG_BEGINDECLS 4955682Smarkm 5055682Smarkmvoid 5155682Smarkmdns_tcpmsg_init(isc_mem_t *mctx, isc_socket_t *sock, dns_tcpmsg_t *tcpmsg); 5255682Smarkm/*%< 5355682Smarkm * Associate a tcp message state with a given memory context and 5455682Smarkm * TCP socket. 5555682Smarkm * 5655682Smarkm * Requires: 5755682Smarkm * 5855682Smarkm *\li "mctx" and "sock" be non-NULL and valid types. 5955682Smarkm * 6055682Smarkm *\li "sock" be a read/write TCP socket. 6155682Smarkm * 6255682Smarkm *\li "tcpmsg" be non-NULL and an uninitialized or invalidated structure. 6355682Smarkm * 6455682Smarkm * Ensures: 6555682Smarkm * 6655682Smarkm *\li "tcpmsg" is a valid structure. 6755682Smarkm */ 6855682Smarkm 6955682Smarkmvoid 7055682Smarkmdns_tcpmsg_setmaxsize(dns_tcpmsg_t *tcpmsg, unsigned int maxsize); 7155682Smarkm/*%< 7255682Smarkm * Set the maximum packet size to "maxsize" 7355682Smarkm * 7455682Smarkm * Requires: 7555682Smarkm * 7655682Smarkm *\li "tcpmsg" be valid. 7755682Smarkm * 7855682Smarkm *\li 512 <= "maxsize" <= 65536 7955682Smarkm */ 8055682Smarkm 8155682Smarkmisc_result_t 8255682Smarkmdns_tcpmsg_readmessage(dns_tcpmsg_t *tcpmsg, 8355682Smarkm isc_task_t *task, isc_taskaction_t action, void *arg); 8455682Smarkm/*%< 8555682Smarkm * Schedule an event to be delivered when a DNS message is readable, or 8655682Smarkm * when an error occurs on the socket. 8755682Smarkm * 8855682Smarkm * Requires: 8955682Smarkm * 9055682Smarkm *\li "tcpmsg" be valid. 9155682Smarkm * 9255682Smarkm *\li "task", "taskaction", and "arg" be valid. 9355682Smarkm * 9455682Smarkm * Returns: 9555682Smarkm * 9655682Smarkm *\li ISC_R_SUCCESS -- no error 9755682Smarkm *\li Anything that the isc_socket_recv() call can return. XXXMLG 9855682Smarkm * 9955682Smarkm * Notes: 10055682Smarkm * 10155682Smarkm *\li The event delivered is a fully generic event. It will contain no 10255682Smarkm * actual data. The sender will be a pointer to the dns_tcpmsg_t. 10355682Smarkm * The result code inside that structure should be checked to see 10455682Smarkm * what the final result was. 10555682Smarkm */ 10655682Smarkm 10755682Smarkmvoid 10855682Smarkmdns_tcpmsg_cancelread(dns_tcpmsg_t *tcpmsg); 10955682Smarkm/*%< 11055682Smarkm * Cancel a readmessage() call. The event will still be posted with a 11155682Smarkm * CANCELED result code. 11255682Smarkm * 11355682Smarkm * Requires: 11455682Smarkm * 11555682Smarkm *\li "tcpmsg" be valid. 11655682Smarkm */ 11755682Smarkm 11855682Smarkmvoid 11955682Smarkmdns_tcpmsg_keepbuffer(dns_tcpmsg_t *tcpmsg, isc_buffer_t *buffer); 12055682Smarkm/*%< 12155682Smarkm * If a dns buffer is to be kept between calls, this function marks the 12255682Smarkm * internal state-machine buffer as invalid, and copies all the contents 12355682Smarkm * of the state into "buffer". 12455682Smarkm * 12555682Smarkm * Requires: 12655682Smarkm * 12755682Smarkm *\li "tcpmsg" be valid. 12855682Smarkm * 12955682Smarkm *\li "buffer" be non-NULL. 13055682Smarkm */ 13155682Smarkm 13255682Smarkmvoid 13355682Smarkmdns_tcpmsg_invalidate(dns_tcpmsg_t *tcpmsg); 13455682Smarkm/*%< 13555682Smarkm * Clean up all allocated state, and invalidate the structure. 13655682Smarkm * 13755682Smarkm * Requires: 13855682Smarkm * 13955682Smarkm *\li "tcpmsg" be valid. 14055682Smarkm * 14155682Smarkm * Ensures: 14255682Smarkm * 14355682Smarkm *\li "tcpmsg" is invalidated and disassociated with all memory contexts, 14455682Smarkm * sockets, etc. 14555682Smarkm */ 14655682Smarkm 14755682SmarkmISC_LANG_ENDDECLS 14855682Smarkm 14955682Smarkm#endif /* DNS_TCPMSG_H */ 15055682Smarkm