1/* hey emacs! -*- Mode: C; c-file-style: "k&r"; indent-tabs-mode: nil -*- */
2/*
3 * tftpd.h
4 *
5 * $Id: tftpd.h,v 1.22 2004/02/27 02:05:26 jp Exp $
6 *
7 * Copyright (c) 2000 Jean-Pierre Lefebvre <helix@step.polymtl.ca>
8 *                and Remi Lefebvre <remi@debian.org>
9 *
10 * atftp is free software; you can redistribute them and/or modify them
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
14 *
15 */
16
17#ifndef tftpd_h
18#define tftpd_h
19
20#include <pthread.h>
21#include <arpa/tftp.h>
22#include <arpa/inet.h>
23#include "tftp_io.h"
24
25/*
26 * Per thread data. There is a thread for each client or group
27 * (multicast) of client.
28 */
29struct thread_data {
30     pthread_t tid;
31
32     /* private to thread */
33     char *data_buffer;
34     int data_buffer_size;
35
36     int timeout;
37     int checkport;             /* Disable TID check. Violate RFC */
38     int mcast_switch_client;   /* When set, server will switch to next client
39                                   on first timeout from the current client. */
40     int trace;
41
42     int sockfd;
43
44     /* multicast stuff */
45     short mc_port;             /* multicast port */
46     char *mc_addr;             /* multicast address */
47     struct sockaddr_in sa_mcast;
48     struct ip_mreq mcastaddr;
49     u_char mcast_ttl;
50
51     /*
52      * Self can read/write until client_ready is set. Then only allowed to read.
53      * Other thread can read it only when client_ready is set. Remember that access
54      * to client_ready bellow is protected by a mutex.
55      */
56     struct tftp_opt *tftp_options;
57
58     /*
59      * Must lock to insert in the list or search, but not to read or write
60      * in the client_info structure, since only the propriotary thread do it.
61      */
62     pthread_mutex_t client_mutex;
63     struct client_info *client_info;
64     int client_ready;        /* one if other thread may add client */
65
66     /* must be lock (list lock) to update */
67     struct thread_data *prev;
68     struct thread_data *next;
69};
70
71struct client_info {
72     struct sockaddr_in client;
73     int done;                  /* that client as receive it's file */
74     struct client_info *next;
75};
76
77/*
78 * Functions defined in tftpd_file.c
79 */
80int tftpd_rules_check(char *filename);
81int tftpd_receive_file(struct thread_data *data);
82int tftpd_send_file(struct thread_data *data);
83
84/*
85 * Defined in tftpd_list.c, operation on thread_data list.
86 */
87int tftpd_list_add(struct thread_data *new);
88int tftpd_list_remove(struct thread_data *old);
89int tftpd_list_num_of_thread(void);
90int tftpd_list_find_multicast_server_and_add(struct thread_data **thread,
91                                             struct thread_data *data,
92                                             struct client_info *client);
93/*
94 * Defined in tftpd_list.c, operation on client structure list.
95 */
96inline void tftpd_clientlist_ready(struct thread_data *thread);
97void tftpd_clientlist_remove(struct thread_data *thread,
98                             struct client_info *client);
99void tftpd_clientlist_free(struct thread_data *thread);
100int tftpd_clientlist_done(struct thread_data *thread,
101                          struct client_info *client,
102                          struct sockaddr_in *sock);
103int tftpd_clientlist_next(struct thread_data *thread,
104                          struct client_info **client);
105void tftpd_list_kill_threads(void);
106
107/*
108 * Defines in tftpd_mcast.c
109 */
110int tftpd_mcast_get_tid(char **addr, short *port);
111int tftpd_mcast_free_tid(char *addr, short port);
112int tftpd_mcast_parse_opt(char *addr, char *ports);
113
114#endif
115