proto_impl.h revision 218139
1101099Srwatson/*-
2166905Srwatson * Copyright (c) 2009-2010 The FreeBSD Foundation
3126097Srwatson * All rights reserved.
4172930Srwatson *
5101099Srwatson * This software was developed by Pawel Jakub Dawidek under sponsorship from
6101099Srwatson * the FreeBSD Foundation.
7101099Srwatson *
8101099Srwatson * Redistribution and use in source and binary forms, with or without
9106393Srwatson * modification, are permitted provided that the following conditions
10106393Srwatson * are met:
11106393Srwatson * 1. Redistributions of source code must retain the above copyright
12106393Srwatson *    notice, this list of conditions and the following disclaimer.
13101099Srwatson * 2. Redistributions in binary form must reproduce the above copyright
14172930Srwatson *    notice, this list of conditions and the following disclaimer in the
15172930Srwatson *    documentation and/or other materials provided with the distribution.
16172930Srwatson *
17101099Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
18101099Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19101099Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20101099Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
21101099Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22101099Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23101099Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24101099Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25101099Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26101099Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27101099Srwatson * SUCH DAMAGE.
28101099Srwatson *
29101099Srwatson * $FreeBSD: head/sbin/hastd/proto_impl.h 218139 2011-01-31 18:35:17Z pjd $
30101099Srwatson */
31101099Srwatson
32101099Srwatson#ifndef	_PROTO_IMPL_H_
33101099Srwatson#define	_PROTO_IMPL_H_
34101099Srwatson
35101099Srwatson#include <sys/queue.h>
36101099Srwatson
37101099Srwatson#include <stdbool.h>	/* bool */
38101099Srwatson#include <stdlib.h>	/* size_t */
39101099Srwatson
40101099Srwatson#define	__constructor	__attribute__((constructor))
41101099Srwatson
42101099Srwatsontypedef int hp_client_t(const char *, void **);
43172955Srwatsontypedef int hp_connect_t(void *);
44101099Srwatsontypedef int hp_server_t(const char *, void **);
45101099Srwatsontypedef int hp_accept_t(void *, void **);
46101099Srwatsontypedef int hp_send_t(void *, const unsigned char *, size_t);
47101099Srwatsontypedef int hp_recv_t(void *, unsigned char *, size_t);
48101099Srwatsontypedef int hp_descriptor_send_t(void *, int);
49101099Srwatsontypedef int hp_descriptor_recv_t(void *, int *);
50101099Srwatsontypedef int hp_descriptor_t(const void *);
51166905Srwatsontypedef bool hp_address_match_t(const void *, const char *);
52101099Srwatsontypedef void hp_local_address_t(const void *, char *, size_t);
53101099Srwatsontypedef void hp_remote_address_t(const void *, char *, size_t);
54101099Srwatsontypedef void hp_close_t(void *);
55101099Srwatson
56101099Srwatsonstruct hast_proto {
57101099Srwatson	const char	*hp_name;
58165469Srwatson	hp_client_t	*hp_client;
59101099Srwatson	hp_connect_t	*hp_connect;
60101099Srwatson	hp_server_t	*hp_server;
61101099Srwatson	hp_accept_t	*hp_accept;
62227309Sed	hp_send_t	*hp_send;
63101099Srwatson	hp_recv_t	*hp_recv;
64101099Srwatson	hp_descriptor_send_t *hp_descriptor_send;
65172955Srwatson	hp_descriptor_recv_t *hp_descriptor_recv;
66101099Srwatson	hp_descriptor_t	*hp_descriptor;
67172955Srwatson	hp_address_match_t *hp_address_match;
68172955Srwatson	hp_local_address_t *hp_local_address;
69101099Srwatson	hp_remote_address_t *hp_remote_address;
70172955Srwatson	hp_close_t	*hp_close;
71101099Srwatson	TAILQ_ENTRY(hast_proto) hp_next;
72172955Srwatson};
73172955Srwatson
74101099Srwatsonvoid proto_register(struct hast_proto *proto, bool isdefault);
75172955Srwatson
76101099Srwatsonint proto_common_send(int sock, const unsigned char *data, size_t size);
77172955Srwatsonint proto_common_recv(int sock, unsigned char *data, size_t size);
78172955Srwatsonint proto_common_descriptor_send(int sock, int fd);
79101099Srwatsonint proto_common_descriptor_recv(int sock, int *fdp);
80172955Srwatson
81101099Srwatson#endif	/* !_PROTO_IMPL_H_ */
82172955Srwatson