* Sync up to trunk head (r65095).
[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 #define MYBYTE unsigned char
22 #define MYWORD unsigned short
23 #define MYDWORD unsigned int
24
25 #ifdef _MSC_VER
26 #define strcasecmp _stricmp
27 #define _CRT_SECURE_NO_WARNINGS
28 #pragma comment(lib, "ws2_32.lib")
29 #pragma comment(lib, "iphlpapi.lib")
30 #endif
31
32 //Constants
33 #define my_inet_addr inet_addr
34 #define MAX_SERVERS 8
35
36 //Structs
37 struct home
38 {
39 char alias[64];
40 char target[256];
41 };
42
43 struct tftpConnType
44 {
45 SOCKET sock;
46 sockaddr_in addr;
47 MYDWORD server;
48 MYWORD port;
49 bool loaded;
50 bool ready;
51 };
52
53 struct acknowledgement
54 {
55 MYWORD opcode;
56 MYWORD block;
57 };
58
59 struct message
60 {
61 MYWORD opcode;
62 char buffer[514];
63 };
64
65 struct tftperror
66 {
67 MYWORD opcode;
68 MYWORD errorcode;
69 char errormessage[512];
70 };
71
72 struct packet
73 {
74 MYWORD opcode;
75 MYWORD block;
76 char buffer;
77 };
78
79 struct data12
80 {
81 MYDWORD rangeStart;
82 MYDWORD rangeEnd;
83 };
84
85 struct request
86 {
87 timeval tv;
88 fd_set readfds;
89 time_t expiry;
90 SOCKET sock;
91 SOCKET knock;
92 MYBYTE sockInd;
93 MYBYTE attempt;
94 char path[256];
95 FILE *file;
96 char *filename;
97 char *mode;
98 char *alias;
99 MYDWORD tsize;
100 MYDWORD fblock;
101 int bytesReady;
102 int bytesRecd;
103 int bytesRead[2];
104 packet* pkt[2];
105 sockaddr_in client;
106 socklen_t clientsize;
107 union
108 {
109 tftperror serverError;
110 message mesout;
111 acknowledgement acout;
112 };
113 union
114 {
115 tftperror clientError;
116 message mesin;
117 acknowledgement acin;
118 };
119 MYWORD blksize;
120 MYWORD timeout;
121 MYWORD block;
122 MYWORD tblock;
123 };
124
125 struct data1
126 {
127 tftpConnType tftpConn[MAX_SERVERS];
128 MYDWORD allServers[MAX_SERVERS];
129 MYDWORD staticServers[MAX_SERVERS];
130 MYDWORD listenServers[MAX_SERVERS];
131 MYWORD listenPorts[MAX_SERVERS];
132 SOCKET maxFD;
133 bool ready;
134 bool busy;
135 };
136
137 struct data2
138 {
139 WSADATA wsaData;
140 home homes[8];
141 FILE *logfile;
142 data12 hostRanges[32];
143 char fileRead;
144 char fileWrite;
145 char fileOverwrite;
146 int minport;
147 int maxport;
148 MYDWORD failureCount;
149 MYBYTE logLevel;
150 bool ifspecified;
151 };
152
153 struct data15
154 {
155 union
156 {
157 //MYDWORD ip;
158 unsigned ip:32;
159 MYBYTE octate[4];
160 };
161 };
162
163 //Functions
164 bool detectChange();
165 void closeConn();
166 void getInterfaces(data1*);
167 void runProg();
168 void processRequest(LPVOID lpParam);
169 char* myGetToken(char*, MYBYTE);
170 char* myTrim(char*, char*);
171 void init(void*);
172 bool cleanReq(request*);
173 bool addServer(MYDWORD*, MYDWORD);
174 FILE* openSection(const char*, MYBYTE, char*);
175 char* readSection(char*, FILE*);
176 bool getSection(const char*, char*, MYBYTE, char*);
177 bool isIP(char*s);
178 char* myLower(char*);
179 char* myUpper(char*);
180 char* IP2String(char*, MYDWORD);
181 MYDWORD* findServer(MYDWORD*, MYDWORD);
182 void printWindowsError();
183 void logMess(request*, MYBYTE);
184 void logMess(char*, MYBYTE);