Sync with trunk r63831.
[reactos.git] / base / services / tftpd / tftpd.h
1 /**************************************************************************
2 * Copyright (C) 2005 by Achal Dhir *
3 * achaldhir@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 // TFTPServer.cpp
21
22 #ifdef _MSC_VER
23 #define strcasecmp _stricmp
24 #define _CRT_SECURE_NO_WARNINGS
25 #pragma comment(lib, "ws2_32.lib")
26 #pragma comment(lib, "iphlpapi.lib")
27 #endif
28
29 //Constants
30 #define my_inet_addr inet_addr
31 #define MAX_SERVERS 8
32
33 //Structs
34 struct home
35 {
36 char alias[64];
37 char target[256];
38 };
39
40 struct tftpConnType
41 {
42 SOCKET sock;
43 sockaddr_in addr;
44 DWORD server;
45 WORD port;
46 };
47
48 struct acknowledgement
49 {
50 WORD opcode;
51 WORD block;
52 };
53
54 struct message
55 {
56 WORD opcode;
57 char buffer[514];
58 };
59
60 struct tftperror
61 {
62 WORD opcode;
63 WORD errorcode;
64 char errormessage[512];
65 };
66
67 struct packet
68 {
69 WORD opcode;
70 WORD block;
71 char buffer;
72 };
73
74 struct data12
75 {
76 DWORD rangeStart;
77 DWORD rangeEnd;
78 };
79
80 struct request
81 {
82 timeval tv;
83 fd_set readfds;
84 time_t expiry;
85 SOCKET sock;
86 SOCKET knock;
87 BYTE sockInd;
88 BYTE attempt;
89 char path[256];
90 FILE *file;
91 char *filename;
92 char *mode;
93 char *alias;
94 DWORD tsize;
95 DWORD fblock;
96 int bytesReady;
97 int bytesRecd;
98 int bytesRead[2];
99 packet* pkt[2];
100 sockaddr_in client;
101 socklen_t clientsize;
102 union
103 {
104 tftperror serverError;
105 message mesout;
106 acknowledgement acout;
107 };
108 union
109 {
110 tftperror clientError;
111 message mesin;
112 acknowledgement acin;
113 };
114 WORD blksize;
115 WORD timeout;
116 WORD block;
117 WORD tblock;
118 };
119
120 struct data2
121 {
122 WSADATA wsaData;
123 tftpConnType tftpConn[MAX_SERVERS];
124 DWORD servers[MAX_SERVERS];
125 WORD ports[MAX_SERVERS];
126 home homes[8];
127 FILE *logfile;
128 data12 hostRanges[32];
129 char fileRead;
130 char fileWrite;
131 char fileOverwrite;
132 int minport;
133 int maxport;
134 SOCKET maxFD;
135 BYTE logLevel;
136 };
137
138 struct data15
139 {
140 union
141 {
142 //DWORD ip;
143 unsigned ip:32;
144 BYTE octate[4];
145 };
146 };
147
148 //Functions
149 void runProg(void);
150 void processRequest(LPVOID lpParam);
151 char* myGetToken(char*, BYTE);
152 void init(void);
153 bool cleanReq(request*);
154 bool getSection(const char*, char*, BYTE, char*);
155 bool isIP(char*s);
156 char* myLower(char*);
157 char* myUpper(char*);
158 char* IP2String(char*, DWORD);
159 void printWindowsError(void);
160 void logMess(request*, BYTE);
161 void logMess(char*, BYTE);