]> git.vomp.tv Git - vompserver.git/blob - tftpd.c
TFTP server (not quite finished)
[vompserver.git] / tftpd.c
1 /*
2     Copyright 2006 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "tftpd.h"
22
23 Tftpd::Tftpd()
24 {
25   log = Log::getInstance();
26 }
27
28 Tftpd::~Tftpd()
29 {
30   shutdown();
31 }
32
33 int Tftpd::shutdown()
34 {
35   if (threadIsActive()) threadCancel();
36   ds.shutdown();
37
38   return 1;
39 }
40
41 int Tftpd::run()
42 {
43   if (threadIsActive()) return 1;
44   log->log("Tftpd", Log::DEBUG, "Starting Tftpd");
45
46   if (!ds.init(16869))
47   {
48     log->log("Tftpd", Log::DEBUG, "DSock init error");
49     shutdown();
50     return 0;
51   }
52
53   if (!threadStart())
54   {
55     log->log("Tftpd", Log::DEBUG, "Thread start error");
56     shutdown();
57     return 0;
58   }
59
60   log->log("Tftpd", Log::DEBUG, "Bootp replier started");
61   return 1;
62 }
63
64 void Tftpd::threadMethod()
65 {
66   int retval;
67   while(1)
68   {
69     log->log("Tftpd", Log::DEBUG, "Starting wait");
70     retval = ds.waitforMessage(0);
71     log->log("Tftpd", Log::DEBUG, "Wait finished");
72
73     if (retval == 0)
74     {
75       log->log("Tftpd", Log::CRIT, "Wait for packet error");
76       return;
77     }
78     else if (retval == 1)
79     {
80       continue;
81     }
82     else
83     {
84       TftpClient* t = new TftpClient();
85       t->run(ds.getFromIPA(), ds.getFromPort(), (UCHAR*)ds.getData(), ds.getDataLength());
86     }
87   }
88 }
89