xref: /freebsd/libexec/tftpd/tftp-options.h (revision 1d386b48)
1e6209940SPedro F. Giffuni /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3e6209940SPedro F. Giffuni  *
4e7ff5475SWarner Losh  * Copyright (C) 2008 Edwin Groothuis. All rights reserved.
5e7ff5475SWarner Losh  *
6e7ff5475SWarner Losh  * Redistribution and use in source and binary forms, with or without
7e7ff5475SWarner Losh  * modification, are permitted provided that the following conditions
8e7ff5475SWarner Losh  * are met:
9e7ff5475SWarner Losh  * 1. Redistributions of source code must retain the above copyright
10e7ff5475SWarner Losh  *    notice, this list of conditions and the following disclaimer.
11e7ff5475SWarner Losh  * 2. Redistributions in binary form must reproduce the above copyright
12e7ff5475SWarner Losh  *    notice, this list of conditions and the following disclaimer in the
13e7ff5475SWarner Losh  *    documentation and/or other materials provided with the distribution.
14e7ff5475SWarner Losh  *
15e7ff5475SWarner Losh  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16e7ff5475SWarner Losh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17e7ff5475SWarner Losh  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18e7ff5475SWarner Losh  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
19e7ff5475SWarner Losh  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20e7ff5475SWarner Losh  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21e7ff5475SWarner Losh  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22e7ff5475SWarner Losh  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23e7ff5475SWarner Losh  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24e7ff5475SWarner Losh  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25e7ff5475SWarner Losh  * SUCH DAMAGE.
26e7ff5475SWarner Losh  */
27e7ff5475SWarner Losh 
28e7ff5475SWarner Losh #include <sys/cdefs.h>
29e7ff5475SWarner Losh /*
30e7ff5475SWarner Losh  * Options
31e7ff5475SWarner Losh  */
32e7ff5475SWarner Losh 
33e7ff5475SWarner Losh void		init_options(void);
34e7ff5475SWarner Losh uint16_t	make_options(int peer, char *buffer, uint16_t size);
35e7ff5475SWarner Losh int		parse_options(int peer, char *buffer, uint16_t size);
36e7ff5475SWarner Losh 
37e7ff5475SWarner Losh /* Call back functions */
38e7ff5475SWarner Losh int	option_tsize(int peer, struct tftphdr *, int, struct stat *);
39e7ff5475SWarner Losh int	option_timeout(int peer);
40e7ff5475SWarner Losh int	option_blksize(int peer);
41e7ff5475SWarner Losh int	option_blksize2(int peer);
42e7ff5475SWarner Losh int	option_rollover(int peer);
43fdf929ffSJohn Baldwin int	option_windowsize(int peer);
44e7ff5475SWarner Losh 
45e7ff5475SWarner Losh extern int options_extra_enabled;
46e7ff5475SWarner Losh extern int options_rfc_enabled;
47e7ff5475SWarner Losh 
48e7ff5475SWarner Losh struct options {
49e7ff5475SWarner Losh 	const char	*o_type;
50e7ff5475SWarner Losh 	char		*o_request;
51e7ff5475SWarner Losh 	char		*o_reply;
52e7ff5475SWarner Losh 	int		(*o_handler)(int peer);
53e7ff5475SWarner Losh 	int		rfc;
54e7ff5475SWarner Losh };
55e7ff5475SWarner Losh 
56e7ff5475SWarner Losh extern struct options	options[];
57e7ff5475SWarner Losh enum opt_enum {
58e7ff5475SWarner Losh 	OPT_TSIZE = 0,
59e7ff5475SWarner Losh 	OPT_TIMEOUT,
60e7ff5475SWarner Losh 	OPT_BLKSIZE,
61e7ff5475SWarner Losh 	OPT_BLKSIZE2,
62e7ff5475SWarner Losh 	OPT_ROLLOVER,
63fdf929ffSJohn Baldwin 	OPT_WINDOWSIZE,
64e7ff5475SWarner Losh };
65b15e052eSDag-Erling Smørgrav 
66b15e052eSDag-Erling Smørgrav int	options_set_request(enum opt_enum, const char *, ...)
678576f84bSJohn Baldwin 	__printf0like(2, 3);
68b15e052eSDag-Erling Smørgrav int	options_set_reply(enum opt_enum, const char *, ...)
698576f84bSJohn Baldwin 	__printf0like(2, 3);
70