- bunch of bugfixes for FTP file transfer:

- failed attempts should now properly cleanup partial downloaded files
  - better logging and resource usage to track down problems
This commit is contained in:
Mark Vejvoda 2011-01-15 21:53:00 +00:00
parent 67e0c27b60
commit 385fb0b3f0
13 changed files with 249 additions and 92 deletions

View File

@ -1379,7 +1379,7 @@ int glestMain(int argc, char** argv) {
disableBacktrace = true;
}
bool haveSpecialOutputCommandLineOption = false;
bool haveSpecialOutputCommandLineOption = false;
if( hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_OPENGL_INFO]) == true ||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_SDL_INFO]) == true ||
@ -1522,6 +1522,11 @@ int glestMain(int argc, char** argv) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
//
//removeFolder("/home/softcoder/Code/megaglest/trunk/mk/linux/mydata/tilesets/mother_board");
//return -1;
//
program= new Program();
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);

View File

@ -174,7 +174,7 @@ extern int ftpRemoveFile(const char* path);
#endif
extern int ftpMakeDir(const char* path);
extern int ftpRemoveDir(const char* path);
extern int ftpCloseSocket(socket_t s);
extern int ftpCloseSocket(socket_t *s);
extern int ftpSend(socket_t s, const void *data, int len);
extern int ftpReceive(socket_t s, void *data, int len);
extern socket_t ftpEstablishDataConnection(int passive, ip_t *ip, port_t *port, int sessionId);

View File

@ -43,7 +43,8 @@ int ftpCreateAccount(const char* name, const char* passw, const char* root, int
int ftpStart(int portNumber);
int ftpShutdown(void);
int ftpExecute(void);
int ftpState(void);
int ftpState(void);
void ftpSignalShutdown(void);
#ifdef __cplusplus
}

View File

@ -112,6 +112,7 @@ bool isdir(const char *path);
void findDirs(const vector<string> &paths, vector<string> &results, bool errorOnNotFound=false,bool keepDuplicates=false);
void findAll(const vector<string> &paths, const string &fileFilter, vector<string> &results, bool cutExtension=false, bool errorOnNotFound=true,bool keepDuplicates=false);
void findAll(const string &path, vector<string> &results, bool cutExtension=false, bool errorOnNotFound=true);
vector<string> getFolderTreeContentsListRecursively(const string &path, const string &filterFileExt, bool includeFolders=false, vector<string> *recursiveMap=NULL);
int32 getFolderTreeContentsCheckSumRecursively(vector<string> paths, string pathSearchString, const string filterFileExt, Checksum *recursiveChecksum);
int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string &filterFileExt, Checksum *recursiveChecksum);

View File

@ -27,9 +27,10 @@ namespace Shared { namespace PlatformCommon {
// =====================================================
enum FTP_Client_ResultType {
ftp_crt_SUCCESS = 0,
ftp_crt_FAIL = 1,
ftp_crt_ABORTED = 2
ftp_crt_SUCCESS = 0,
ftp_crt_PARTIALFAIL = 1,
ftp_crt_FAIL = 2,
ftp_crt_ABORTED = 3
};
enum FTP_Client_CallbackType {

View File

@ -225,7 +225,7 @@ LOCAL int ftpCmdPort(int sessionId, const char* args, int len)
clientIp[0] = clientIp[0];
if(ftpGetSession(sessionId)->passiveDataSocket >= 0)
{
ftpCloseSocket(ftpGetSession(sessionId)->passiveDataSocket);
ftpCloseSocket(&ftpGetSession(sessionId)->passiveDataSocket);
ftpGetSession(sessionId)->passiveDataSocket = -1;
}
//ftpGetSession(sessionId)->passiveDataSocket = -1;
@ -437,7 +437,7 @@ LOCAL int ftpCmdList(int sessionId, const char* args, int len)
}
}
sendListing(s, sessionId, realPath, LIST);
ftpCloseSocket(s);
ftpCloseSocket(&s);
return 0;
}
@ -472,7 +472,7 @@ LOCAL int ftpCmdNlst(int sessionId, const char* args, int len)
}
}
sendListing(s, sessionId, realPath, NLST);
ftpCloseSocket(s);
ftpCloseSocket(&s);
return 0;
}
@ -526,7 +526,7 @@ if(VERBOSE_MODE_ENABLED) printf("stat() = %d fileInfo.type = %d\n", statResult,f
else
{
ftpSendMsg(MSG_NORMAL, sessionId, 451, ftpMsg015);
ftpCloseSocket(s);
ftpCloseSocket(&s);
}
return 0;
@ -568,7 +568,7 @@ LOCAL int ftpCmdStor(int sessionId, const char* args, int len)
else
{
ftpSendMsg(MSG_NORMAL, sessionId, 451, ftpMsg015);
ftpCloseSocket(s);
ftpCloseSocket(&s);
}
return 0;
@ -661,7 +661,7 @@ LOCAL int ftpCmdPasv(int sessionId, const char* args, int len)
if(ftpGetSession(sessionId)->passiveDataSocket >= 0)
{
ftpCloseSocket(ftpGetSession(sessionId)->passiveDataSocket);
ftpCloseSocket(&ftpGetSession(sessionId)->passiveDataSocket);
ftpGetSession(sessionId)->passiveDataSocket = -1;
}
//ftpGetSession(sessionId)->passiveDataSocket = -1;
@ -824,7 +824,7 @@ LOCAL int ftpCmdMlsd(int sessionId, const char* args, int len)
}
}
sendListing(s, sessionId, realPath, MLSD);
ftpCloseSocket(s);
ftpCloseSocket(&s);
return 0;
}

View File

@ -158,12 +158,20 @@ int ftpExecute(void)
}
}
//if(ftpGetActiveTransCnt()) // don't block if there's still something to do
socksRdy = ftpSelect(TRUE);
//else
// socksRdy = ftpSelect(FALSE);
if(ftpGetActiveTransCnt()) // don't block if there's still something to do
{
socksRdy = ftpSelect(TRUE);
}
else
{
//if(VERBOSE_MODE_ENABLED) printf("ftpExecute calling blocking select\n");
socksRdy = ftpSelect(FALSE);
}
if(socksRdy > 0)
{
{
if(VERBOSE_MODE_ENABLED) printf("ftpExecute socksRdy = %d\n",socksRdy);
processedWork = 1;
if(ftpTestSocket(server)) // server listner-socket signaled?
{
@ -183,9 +191,9 @@ int ftpExecute(void)
}
else
{
if(VERBOSE_MODE_ENABLED) printf("Connection refused; Session limit reached.\n");
if(VERBOSE_MODE_ENABLED) printf("ERROR: Connection refused; Session limit reached.\n");
ftpCloseSocket(clientSocket);
ftpCloseSocket(&clientSocket);
}
}
}
@ -239,11 +247,15 @@ if(VERBOSE_MODE_ENABLED) printf("Connection refused; Session limit reached.\n");
*/
int ftpShutdown(void)
{
if(VERBOSE_MODE_ENABLED) printf("About to Shutdown Feathery FTP-Server server [%d]\n",server);
int n;
ftpUntrackSocket(server);
ftpCloseSocket(server);
ftpCloseSocket(&server);
//ftpCloseSocket(serverPassivePort);
if(VERBOSE_MODE_ENABLED) printf("About to Shutdown clients\n");
for(n = 0; n < MAX_CONNECTIONS; n++)
{
if(ftpGetSession(n)->open)
@ -253,6 +265,7 @@ int ftpShutdown(void)
ftpCloseSession(n);
}
if(VERBOSE_MODE_ENABLED) printf("About to Shutdown stack\n");
ftpArchCleanup();
return 0;

View File

@ -133,16 +133,14 @@ if(VERBOSE_MODE_ENABLED) printf("In ftpCmdPasv sessionId = %d, removing UPNP por
}
}
if(sessions[id].open) {
ftpCloseSocket(sessions[id].ctrlSocket);
ftpCloseSocket(&sessions[id].ctrlSocket);
ftpCloseTransmission(id);
if(sessions[id].passiveDataSocket > 0)
{
ftpCloseSocket(sessions[id].passiveDataSocket);
}
ftpCloseSocket(&sessions[id].passiveDataSocket);
}
sessions[id].remoteIp = 0;
sessions[id].ctrlSocket = 0;
sessions[id].passiveDataSocket = 0;
sessions[id].activeTrans.dataSocket = 0;
sessions[id].open = FALSE;
if(VERBOSE_MODE_ENABLED) printf("Session %d closed\n", id);
@ -329,7 +327,7 @@ void ftpCloseTransmission(int id)
{
if(sessions[id].activeTrans.op != OP_NOP) // is thera an active transmission?
{
ftpCloseSocket(sessions[id].activeTrans.dataSocket);
ftpCloseSocket(&sessions[id].activeTrans.dataSocket);
if(sessions[id].activeTrans.op == OP_LIST)
{
ftpCloseDir(sessions[id].activeTrans.fsHandle);
@ -339,6 +337,7 @@ void ftpCloseTransmission(int id)
ftpCloseFile(sessions[id].activeTrans.fsHandle);
}
sessions[id].activeTrans.op = OP_NOP;
sessions[id].activeTrans.dataSocket = 0;
actTransCnt--;
}
}

View File

@ -177,10 +177,17 @@ int ftpRemoveDir(const char* path)
return rmdir(path);
}
int ftpCloseSocket(socket_t s)
int ftpCloseSocket(socket_t *s)
{
if(VERBOSE_MODE_ENABLED) printf("\nClosing socket: %d\n",s);
return close(s);
if(VERBOSE_MODE_ENABLED) printf("\nClosing socket: %d\n",*s);
int ret = 0;
if(*s > 0) {
shutdown(*s,2);
ret = close(*s);
*s = 0;
}
return ret;
}
int ftpSend(socket_t s, const void *data, int len)
@ -228,7 +235,7 @@ socket_t ftpEstablishDataConnection(int passive, ip_t *ip, port_t *port, int ses
{
if(setsockopt(dataSocket, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)))
{
close(dataSocket);
ftpCloseSocket(&dataSocket);
return -1;
}
myAddr.sin_family = AF_INET;
@ -236,7 +243,7 @@ socket_t ftpEstablishDataConnection(int passive, ip_t *ip, port_t *port, int ses
myAddr.sin_port = htons(20);
if(bind(dataSocket, (struct sockaddr *)&myAddr, sizeof(myAddr)))
{
close(dataSocket);
ftpCloseSocket(&dataSocket);
return -1;
}
clientAddr.sin_family = AF_INET;
@ -244,7 +251,7 @@ socket_t ftpEstablishDataConnection(int passive, ip_t *ip, port_t *port, int ses
clientAddr.sin_port = htons(*port);
if(connect(dataSocket, (struct sockaddr *)&clientAddr, sizeof(clientAddr)))
{
close(dataSocket);
ftpCloseSocket(&dataSocket);
return -1;
}
}
@ -264,7 +271,7 @@ socket_t ftpEstablishDataConnection(int passive, ip_t *ip, port_t *port, int ses
{
if(VERBOSE_MODE_ENABLED) printf("\nPASSIVE CONNECTION for sessionId = %d using port #: %d FAILED: %d\n",sessionId,passivePort,dataSocket);
close(dataSocket);
ftpCloseSocket(&dataSocket);
return -1;
}
@ -273,7 +280,7 @@ socket_t ftpEstablishDataConnection(int passive, ip_t *ip, port_t *port, int ses
len = sizeof(myAddr);
if(getsockname(dataSocket, (struct sockaddr *)&myAddr, &len)) // Port des Server-Sockets ermitteln
{
close(dataSocket);
ftpCloseSocket(&dataSocket);
return -1;
}
@ -286,7 +293,7 @@ socket_t ftpEstablishDataConnection(int passive, ip_t *ip, port_t *port, int ses
{
if(VERBOSE_MODE_ENABLED) printf("\nPASSIVE CONNECTION for sessionId = %d using port #: %d FAILED #2: %d\n",sessionId,passivePort,dataSocket);
close(dataSocket);
ftpCloseSocket(&dataSocket);
return -1;
}
@ -308,17 +315,18 @@ socket_t ftpAcceptDataConnection(socket_t listner)
dataSocket = accept(listner, (struct sockaddr *)&clientinfo, &len);
if(dataSocket < 0)
{
if(VERBOSE_MODE_ENABLED) printf("ftpAcceptDataConnection accept failed, dataSocket = %d\n", dataSocket);
dataSocket = -1;
}
close(listner); // Server-Socket wird nicht mehr gebrauch deshalb schließen
ftpCloseSocket(&listner); // Server-Socket wird nicht mehr gebrauch deshalb schließen
ip_t remoteIP = ntohl(clientinfo.sin_addr.s_addr);
if(ftpIsValidClient && ftpIsValidClient(remoteIP) == 0)
{
if(VERBOSE_MODE_ENABLED) printf("Connection with %s is NOT a valid trusted client, dropping connection.\n", inet_ntoa(clientinfo.sin_addr));
close(dataSocket);
ftpCloseSocket(&dataSocket);
dataSocket = -1;
}
@ -345,13 +353,13 @@ socket_t ftpCreateServerSocket(int portNumber)
if(bind(theServer, (struct sockaddr *)&serverinfo, len))
{
ftpCloseSocket(theServer);
ftpCloseSocket(&theServer);
return -2;
}
if(listen(theServer, 16))
{
ftpCloseSocket(theServer);
ftpCloseSocket(&theServer);
return -3;
}
@ -367,6 +375,11 @@ socket_t ftpAcceptServerConnection(socket_t server, ip_t *remoteIP, port_t *remo
len = sizeof(sockinfo);
clientSocket = accept(server, (struct sockaddr *)&sockinfo, &len);
if(clientSocket < 0) {
if(VERBOSE_MODE_ENABLED) printf("ftpAcceptServerConnection accept failed, dataSocket = %d\n", clientSocket);
}
*remoteIP = ntohl(sockinfo.sin_addr.s_addr);
*remotePort = ntohs(sockinfo.sin_port);
@ -387,7 +400,7 @@ if(VERBOSE_MODE_ENABLED) printf("Connection with %s on Port %d accepted.\n", ine
{
if(VERBOSE_MODE_ENABLED) printf("Connection with %s on Port %d is NOT a valid trusted client, dropping connection.\n", inet_ntoa(sockinfo.sin_addr), *remotePort);
close(clientSocket);
ftpCloseSocket(&clientSocket);
clientSocket = -1;
}
@ -421,11 +434,16 @@ int ftpSelect(int poll)
if(poll)
{
struct timeval t = {0};
t.tv_usec = 100;
//t.tv_usec = 100;
return select(maxSockNr+1, &signaledSockets, NULL, NULL, &t);
}
else
return select(maxSockNr+1, &signaledSockets, NULL, NULL, NULL);
{
struct timeval t = {0};
t.tv_usec = 1000;
return select(maxSockNr+1, &signaledSockets, NULL, NULL, &t);
}
}
#endif

View File

@ -31,8 +31,8 @@
#pragma comment(lib, "ws2_32")
#pragma comment(lib, "MSWSOCK")
#define MSG_NOSIGNAL 0
#define MSG_NOSIGNAL 0
ip_t ownIp;
@ -209,10 +209,16 @@ int ftpRemoveDir(const char* path)
}
int ftpCloseSocket(socket_t s)
int ftpCloseSocket(socket_t *s)
{
if(VERBOSE_MODE_ENABLED) printf("\nClosing socket: %d\n",s);
return closesocket((SOCKET)s);
if(VERBOSE_MODE_ENABLED) printf("\nClosing socket: %d\n",*s);
int ret = 0;
if(*s > 0) {
shutdown((SOCKET)*s,2);
ret = closesocket((SOCKET)*s);
*s = 0;
}
return ret;
}
int ftpSend(socket_t s, const void *data, int len)
@ -220,12 +226,12 @@ int ftpSend(socket_t s, const void *data, int len)
int currLen = 0;
do
{
{
#ifdef __APPLE__
currLen = send((SOCKET)s, data, len, SO_NOSIGPIPE);
#else
currLen = send((SOCKET)s, data, len, MSG_NOSIGNAL);
#endif
currLen = send((SOCKET)s, data, len, SO_NOSIGPIPE);
#else
currLen = send((SOCKET)s, data, len, MSG_NOSIGNAL);
#endif
if(currLen >= 0)
{
@ -260,16 +266,15 @@ socket_t ftpEstablishDataConnection(int passive, ip_t *ip, port_t *port, int ses
{
if(setsockopt(dataSocket, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on)))
{
closesocket(dataSocket);
ftpCloseSocket(&dataSocket);
return -1;
}
myAddr.sin_family = AF_INET;
myAddr.sin_addr.s_addr = INADDR_ANY;
myAddr.sin_port = htons(20);
if(bind(dataSocket, (struct sockaddr *)&myAddr, sizeof(myAddr)))
{
closesocket(dataSocket);
ftpCloseSocket(&dataSocket);
return -1;
}
clientAddr.sin_family = AF_INET;
@ -277,7 +282,7 @@ socket_t ftpEstablishDataConnection(int passive, ip_t *ip, port_t *port, int ses
clientAddr.sin_port = htons(*port);
if(connect(dataSocket, (struct sockaddr *)&clientAddr, sizeof(clientAddr)))
{
closesocket(dataSocket);
ftpCloseSocket(&dataSocket);
return -1;
}
}
@ -285,6 +290,7 @@ socket_t ftpEstablishDataConnection(int passive, ip_t *ip, port_t *port, int ses
{
int passivePort = ftpGetPassivePort() + sessionId;
if(VERBOSE_MODE_ENABLED) printf("\nPASSIVE CONNECTION for sessionId = %d using port #: %d\n",sessionId,passivePort);
myAddr.sin_family = AF_INET;
myAddr.sin_addr.s_addr = INADDR_ANY;
myAddr.sin_port = htons(passivePort);
@ -296,7 +302,7 @@ socket_t ftpEstablishDataConnection(int passive, ip_t *ip, port_t *port, int ses
{
if(VERBOSE_MODE_ENABLED) printf("\nPASSIVE CONNECTION for sessionId = %d using port #: %d FAILED: %d\n",sessionId,passivePort,dataSocket);
closesocket(dataSocket);
ftpCloseSocket(&dataSocket);
return -1;
}
@ -305,7 +311,7 @@ socket_t ftpEstablishDataConnection(int passive, ip_t *ip, port_t *port, int ses
len = sizeof(myAddr);
if(getsockname(dataSocket, (struct sockaddr *)&myAddr, &len)) // Port des Server-Sockets ermitteln
{
closesocket(dataSocket);
ftpCloseSocket(&dataSocket);
return -1;
}
@ -318,7 +324,7 @@ socket_t ftpEstablishDataConnection(int passive, ip_t *ip, port_t *port, int ses
{
if(VERBOSE_MODE_ENABLED) printf("\nPASSIVE CONNECTION for sessionId = %d using port #: %d FAILED #2: %d\n",sessionId,passivePort,dataSocket);
closesocket(dataSocket);
ftpCloseSocket(&dataSocket);
return -1;
}
@ -334,24 +340,24 @@ socket_t ftpAcceptDataConnection(socket_t listner)
struct sockaddr_in clientinfo;
unsigned len;
SOCKET dataSocket;
ip_t remoteIP;
len = sizeof(clientinfo);
dataSocket = accept(listner, (struct sockaddr *)&clientinfo, &len);
if(dataSocket < 0)
{
if(VERBOSE_MODE_ENABLED) printf("ftpAcceptDataConnection accept failed, dataSocket = %d\n", dataSocket);
dataSocket = -1;
}
closesocket(listner); // Server-Socket wird nicht mehr gebrauch deshalb schließen
ftpCloseSocket(&listner); // Server-Socket wird nicht mehr gebrauch deshalb schließen
remoteIP = ntohl(clientinfo.sin_addr.s_addr);
ip_t remoteIP = ntohl(clientinfo.sin_addr.s_addr);
if(ftpIsValidClient && ftpIsValidClient(remoteIP) == 0)
{
if(VERBOSE_MODE_ENABLED) printf("Connection with %s is NOT a valid trusted client, dropping connection.\n", inet_ntoa(clientinfo.sin_addr));
close(dataSocket);
ftpCloseSocket(&dataSocket);
dataSocket = -1;
}
@ -378,13 +384,13 @@ socket_t ftpCreateServerSocket(int portNumber)
if(bind(theServer, (struct sockaddr *)&serverinfo, len))
{
ftpCloseSocket(theServer);
ftpCloseSocket(&theServer);
return -2;
}
if(listen(theServer, 16))
{
ftpCloseSocket(theServer);
ftpCloseSocket(&theServer);
return -3;
}
@ -400,6 +406,11 @@ socket_t ftpAcceptServerConnection(socket_t server, ip_t *remoteIP, port_t *remo
len = sizeof(sockinfo);
clientSocket = accept(server, (struct sockaddr *)&sockinfo, &len);
if(clientSocket < 0) {
if(VERBOSE_MODE_ENABLED) printf("ftpAcceptServerConnection accept failed, dataSocket = %d\n", clientSocket);
}
*remoteIP = ntohl(sockinfo.sin_addr.s_addr);
*remotePort = ntohs(sockinfo.sin_port);
@ -420,7 +431,7 @@ if(VERBOSE_MODE_ENABLED) printf("Connection with %s on Port %d accepted.\n", ine
{
if(VERBOSE_MODE_ENABLED) printf("Connection with %s on Port %d is NOT a valid trusted client, dropping connection.\n", inet_ntoa(sockinfo.sin_addr), *remotePort);
close(clientSocket);
ftpCloseSocket(&clientSocket);
clientSocket = -1;
}
@ -453,12 +464,18 @@ int ftpSelect(int poll)
if(poll)
{
struct timeval t = {0};
t.tv_usec = 100;
struct timeval t = {0};
//t.tv_usec = 100;
return select(maxSockNr+1, &signaledSockets, NULL, NULL, &t);
}
else
return select(maxSockNr+1, &signaledSockets, NULL, NULL, NULL);
{
struct timeval t = {0};
t.tv_usec = 100;
return select(maxSockNr+1, &signaledSockets, NULL, NULL, &t);
}
}
#endif

View File

@ -339,31 +339,32 @@ void removeFolder(const string path) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str());
string deletePath = path + "*";
vector<string> results;
findAll(deletePath, results, false, false);
//vector<string> results;
//findAll(deletePath, results, false, false);
vector<string> results = getFolderTreeContentsListRecursively(deletePath, "", true);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path [%s] results.size() = %d\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),results.size());
// First delete files
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] DELETE FILES\n",__FILE__,__FUNCTION__,__LINE__);
for(int i = results.size() -1; i >= 0; --i) {
string item = results[i];
if(isdir(item.c_str()) == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] item [%s]\n",__FILE__,__FUNCTION__,__LINE__,item.c_str());
rmdir(item.c_str());
}
else {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] item [%s]\n",__FILE__,__FUNCTION__,__LINE__,item.c_str());
unlink(item.c_str());
if(isdir(item.c_str()) == false) {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] file item [%s]\n",__FILE__,__FUNCTION__,__LINE__,item.c_str());
int result = unlink(item.c_str());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fileitem [%s] result = %d\n",__FILE__,__FUNCTION__,__LINE__,item.c_str(),result);
}
}
// Now delete folders
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] DELETE FOLDERS\n",__FILE__,__FUNCTION__,__LINE__);
for(int i = results.size() -1; i >= 0; --i) {
string item = results[i];
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] item [%s] isdir(item.c_str()) = %d\n",__FILE__,__FUNCTION__,__LINE__,item.c_str(), isdir(item.c_str()));
if(isdir(item.c_str()) == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] item [%s]\n",__FILE__,__FUNCTION__,__LINE__,item.c_str());
rmdir(item.c_str());
}
else {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] item [%s]\n",__FILE__,__FUNCTION__,__LINE__,item.c_str());
unlink(item.c_str());
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] item [%s]\n",__FILE__,__FUNCTION__,__LINE__,item.c_str());
int result = rmdir(item.c_str());
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] item [%s] result = %d\n",__FILE__,__FUNCTION__,__LINE__,item.c_str(),result);
}
}
}
@ -568,6 +569,97 @@ vector<std::pair<string,int32> > getFolderTreeContentsCheckSumListRecursively(ve
return crcTreeCache[cacheKey];
}
//finds all filenames like path and gets the checksum of each file
vector<string> getFolderTreeContentsListRecursively(const string &path, const string &filterFileExt, bool includeFolders, vector<string> *recursiveMap) {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s] filterFileExt = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),filterFileExt.c_str());
bool topLevelCaller = (recursiveMap == NULL);
vector<string> resultFiles = (recursiveMap == NULL ? vector<string>() : *recursiveMap);
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s]\n",__FILE__,__FUNCTION__,path.c_str());
std::string mypath = path;
/** Stupid win32 is searching for all files without extension when *. is
* specified as wildcard
*/
if(mypath.compare(mypath.size() - 2, 2, "*.") == 0) {
mypath = mypath.substr(0, mypath.size() - 2);
mypath += "*";
}
glob_t globbuf;
int res = glob(mypath.c_str(), 0, 0, &globbuf);
if(res < 0) {
std::stringstream msg;
msg << "Couldn't scan directory '" << mypath << "': " << strerror(errno);
throw runtime_error(msg.str());
}
for(int i = 0; i < globbuf.gl_pathc; ++i) {
const char* p = globbuf.gl_pathv[i];
if(isdir(p) == false) {
bool addFile = true;
//if(EndsWith(p, ".") == true || EndsWith(p, "..") == true || EndsWith(p, ".svn") == true) {
// addFile = false;
//}
//else
if(filterFileExt != "") {
addFile = EndsWith(p, filterFileExt);
}
if(addFile) {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] adding file [%s]\n",__FILE__,__FUNCTION__,p);
resultFiles.push_back(p);
}
}
else if(includeFolders == true) {
resultFiles.push_back(p);
}
}
globfree(&globbuf);
// Look recursively for sub-folders
#if defined(__APPLE__) || defined(__FreeBSD__)
res = glob(mypath.c_str(), 0, 0, &globbuf);
#else //APPLE doesn't have the GLOB_ONLYDIR definition..
res = glob(mypath.c_str(), GLOB_ONLYDIR, 0, &globbuf);
#endif
if(res < 0) {
std::stringstream msg;
msg << "Couldn't scan directory '" << mypath << "': " << strerror(errno);
throw runtime_error(msg.str());
}
for(int i = 0; i < globbuf.gl_pathc; ++i) {
#if defined(__APPLE__) || defined(__FreeBSD__)
struct stat statStruct;
// only get if dir..
int actStat = lstat( globbuf.gl_pathv[ i], &statStruct);
if( S_ISDIR(statStruct.st_mode) == 0)
continue;
#endif
const char* p = globbuf.gl_pathv[i];
if(includeFolders == true) {
resultFiles.push_back(p);
}
resultFiles = getFolderTreeContentsListRecursively(string(p) + "/*", filterFileExt, includeFolders,&resultFiles);
}
globfree(&globbuf);
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] scanning [%s]\n",__FILE__,__FUNCTION__,path.c_str());
if(topLevelCaller == true) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] EXITING TOP LEVEL RECURSION\n",__FILE__,__FUNCTION__,__LINE__);
}
return resultFiles;
}
//finds all filenames like path and gets the checksum of each file
vector<std::pair<string,int32> > getFolderTreeContentsCheckSumListRecursively(const string &path, const string &filterFileExt, vector<std::pair<string,int32> > *recursiveMap) {
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s] filterFileExt = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),filterFileExt.c_str());

View File

@ -262,10 +262,14 @@ FTP_Client_ResultType FTPClientThread::getMapFromServer(string mapFileName, stri
if(SystemFlags::VERBOSE_MODE_ENABLED) curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
CURLcode res = curl_easy_perform(curl);
if(CURLE_OK != res) {
if(res != CURLE_OK) {
// we failed
printf("curl FAILED with: %d [%s] szBuf [%s]\n", res,curl_easy_strerror(res),szBuf);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"curl FAILED with: %d [%s] szBuf [%s]\n", res,curl_easy_strerror(res),szBuf);
if(res == CURLE_PARTIAL_FILE) {
result = ftp_crt_PARTIALFAIL;
}
}
else {
result = ftp_crt_SUCCESS;
@ -287,11 +291,11 @@ FTP_Client_ResultType FTPClientThread::getMapFromServer(string mapFileName, stri
void FTPClientThread::getMapFromServer(string mapFileName) {
FTP_Client_ResultType result = getMapFromServer(mapFileName + ".mgm", FTP_MAPS_CUSTOM_USERNAME, FTP_COMMON_PASSWORD);
if(result != ftp_crt_SUCCESS && this->getQuitStatus() == false) {
if(result == ftp_crt_FAIL && this->getQuitStatus() == false) {
result = getMapFromServer(mapFileName + ".gbm", FTP_MAPS_CUSTOM_USERNAME, FTP_COMMON_PASSWORD);
if(result != ftp_crt_SUCCESS && this->getQuitStatus() == false) {
if(result == ftp_crt_FAIL && this->getQuitStatus() == false) {
result = getMapFromServer(mapFileName + ".mgm", FTP_MAPS_USERNAME, FTP_COMMON_PASSWORD);
if(result != ftp_crt_SUCCESS && this->getQuitStatus() == false) {
if(result == ftp_crt_FAIL && this->getQuitStatus() == false) {
result = getMapFromServer(mapFileName + ".gbm", FTP_MAPS_USERNAME, FTP_COMMON_PASSWORD);
}
}
@ -319,7 +323,7 @@ void FTPClientThread::addTilesetToRequests(string tileSetName) {
void FTPClientThread::getTilesetFromServer(string tileSetName) {
FTP_Client_ResultType result = getTilesetFromServer(tileSetName, "", FTP_TILESETS_CUSTOM_USERNAME, FTP_COMMON_PASSWORD);
if(result != ftp_crt_SUCCESS && this->getQuitStatus() == false) {
if(result == ftp_crt_FAIL && this->getQuitStatus() == false) {
result = getTilesetFromServer(tileSetName, "", FTP_TILESETS_USERNAME, FTP_COMMON_PASSWORD);
}
@ -420,11 +424,15 @@ FTP_Client_ResultType FTPClientThread::getTilesetFromServer(string tileSetName,
CURLcode res = curl_easy_perform(curl);
if(CURLE_OK != res) {
if(res != CURLE_OK) {
// we failed
printf("curl FAILED with: %d [%s] attempting to remove folder contents [%s] szBuf [%s]\n", res,curl_easy_strerror(res),destRootFolder.c_str(),szBuf);
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"curl FAILED with: %d [%s] attempting to remove folder contents [%s] szBuf [%s]\n", res,curl_easy_strerror(res),destRootFolder.c_str(),szBuf);
if(res == CURLE_PARTIAL_FILE) {
result = ftp_crt_PARTIALFAIL;
}
if(destRootFolder != "") {
//unlink(destRootFolder.c_str());
removeFolder(destRootFolder);

View File

@ -58,7 +58,8 @@ FTPServerThread::FTPServerThread(std::pair<string,string> mapsPath,std::pair<str
}
FTPServerThread::~FTPServerThread() {
// Remove any UPNP port forwarded ports
ftpShutdown();
// Remove any UPNP port forwarded ports
UPNP_Tools::upnp_rem_redirect(ServerSocket::getFTPServerPort());
for(int clientIndex = 1; clientIndex <= maxPlayers; ++clientIndex) {
UPNP_Tools::upnp_rem_redirect(ServerSocket::getFTPServerPort() + clientIndex);
@ -68,6 +69,7 @@ FTPServerThread::~FTPServerThread() {
void FTPServerThread::signalQuit() {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Server: signalQuit\n");
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"===> FTP Server: signalQuit\n");
ftpShutdown();
BaseThread::signalQuit();
}