Large file support added, bug fixes

This commit is contained in:
Ugo Cirmignani
2018-05-03 19:49:43 +02:00
parent 35be005379
commit 0e5db65447
28 changed files with 387 additions and 288 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#define _LARGEFILE64_SOURCE
#include <sys/types.h>
#include <sys/socket.h>
@ -798,7 +799,7 @@ int parseCommandSize(clientDataType *theClientData)
{
int returnCode;
int isSafePath;
unsigned long long int theSize;
long long int theSize;
char *theFileName;
dynamicStringDataType theResponse;
dynamicStringDataType getSizeFromFileName;
@ -963,16 +964,15 @@ int parseCommandCdup(clientDataType *theClientData)
return 1;
}
int writeRetrFile(char * theFilename, int thePasvSocketConnection, int startFrom, FILE *retrFP)
long long int writeRetrFile(char * theFilename, int thePasvSocketConnection, long long int startFrom, FILE *retrFP)
{
long int readen = 0;
long int toReturn = 0, writtenSize = 0;
long int currentPosition = 0;
long long int readen = 0;
long long int toReturn = 0, writtenSize = 0;
long long int currentPosition = 0;
long long int theFileSize;
char buffer[FTP_COMMAND_ELABORATE_CHAR_BUFFER];
retrFP = fopen(theFilename, "rb");
retrFP = fopen64(theFilename, "rb");
if (retrFP == NULL)
{
return -1;
@ -983,7 +983,7 @@ int writeRetrFile(char * theFilename, int thePasvSocketConnection, int startFrom
if (startFrom > 0)
{
//printf("\nSeek startFrom: %d", startFrom);
currentPosition = (long int) lseek(fileno(retrFP), startFrom, SEEK_SET);
currentPosition = (long long int) lseek64(fileno(retrFP), startFrom, SEEK_SET);
// printf("\nSeek result: %ld", currentPosition);
if (currentPosition == -1)
{
@ -993,7 +993,7 @@ int writeRetrFile(char * theFilename, int thePasvSocketConnection, int startFrom
}
}
while ((readen = (long int) fread(buffer, sizeof(char), FTP_COMMAND_ELABORATE_CHAR_BUFFER, retrFP)) > 0)
while ((readen = (long long int) fread(buffer, sizeof(char), FTP_COMMAND_ELABORATE_CHAR_BUFFER, retrFP)) > 0)
{
writtenSize = write(thePasvSocketConnection, buffer, readen);

View File

@ -72,7 +72,7 @@ int parseCommandOpts(clientDataType *theClientData);
int parseCommandRnfr(clientDataType *theClientData);
int parseCommandRnto(clientDataType *theClientData);
int writeRetrFile(char * theFilename, int thePasvSocketConnection, int startFrom, FILE *retrFP);
long long int writeRetrFile(char * theFilename, int thePasvSocketConnection, long long int startFrom, FILE *retrFP);
char *getFtpCommandArg(char * theCommand, char *theCommandString, int skipArgs);
int getFtpCommandArgWithOptions(char * theCommand, char *theCommandString, ftpCommandDataType *ftpCommand);
int setPermissions(char * permissionsCommand, char * basePath, ownerShip_DataType ownerShip);

172
ftpData.c
View File

@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#define _LARGEFILE64_SOURCE
#include <string.h>
#include <stdio.h>
@ -217,6 +218,162 @@ void setRandomicPort(ftpDataType *data, int socketPosition)
printf("data->clients[%d].workerData.connectionPort = %d", socketPosition, data->clients[socketPosition].workerData.connectionPort);
}
int writeListDataInfoToSocket(char * thePath, int theSocket, int *filesNumber, int commandType)
{
int i, x, returnCode;
int fileAndFoldersCount = 0;
char **fileList = NULL;
FILE_GetDirectoryInodeList(thePath, &fileList, &fileAndFoldersCount, 0);
*filesNumber = fileAndFoldersCount;
returnCode = dprintf(theSocket, "total %d\r\n", fileAndFoldersCount);
if (returnCode <= 0)
{
return -1;
}
for (i = 0; i < fileAndFoldersCount; i++)
{
ftpListDataType data;
data.owner = NULL;
data.groupOwner = NULL;
data.inodePermissionString = NULL;
data.fileNameWithPath = NULL;
data.finalStringPath = NULL;
data.linkPath = NULL;
data.numberOfSubDirectories = 1; /* to Do*/
data.isFile = 0;
data.isDirectory = 0;
printf("\nPROCESSING: %s", fileList[i]);
fflush(0);
if (FILE_IsDirectory(fileList[i]) == 1)
{
printf("\nis directory");
fflush(0);
data.isDirectory = 1;
data.isFile = 0;
data.isLink = 0;
data.fileSize = 4096;
}
else if (FILE_IsFile(fileList[i]) == 1)
{
printf("\nis file");
fflush(0);
data.isDirectory = 0;
data.isFile = 1;
data.isLink = 0;
data.fileSize = FILE_GetFileSizeFromPath(fileList[i]);
}
if (data.isDirectory == 0 && data.isFile == 0)
{
printf("\nNot a directory, not a file, broken link");
continue;
}
printf("\nFILE SIZE : %lld", data.fileSize);
data.owner = FILE_GetOwner(fileList[i]);
data.groupOwner = FILE_GetGroupOwner(fileList[i]);
data.fileNameWithPath = fileList[i];
data.fileNameNoPath = FILE_GetFilenameFromPath(fileList[i]);
data.inodePermissionString = FILE_GetListPermissionsString(fileList[i]);
data.lastModifiedData = FILE_GetLastModifiedData(fileList[i]);
if (strlen(data.fileNameNoPath) > 0)
{
data.finalStringPath = (char *) malloc (strlen(data.fileNameNoPath)+1);
strcpy(data.finalStringPath, data.fileNameNoPath);
}
if (data.inodePermissionString != NULL &&
strlen(data.inodePermissionString) > 0 &&
data.inodePermissionString[0] == 'l')
{
int len = 0;
data.isLink = 1;
data.linkPath = (char *) malloc (CLIENT_COMMAND_STRING_SIZE*sizeof(char));
if ((len = readlink (fileList[i], data.linkPath, CLIENT_COMMAND_STRING_SIZE)) > 0)
{
data.linkPath[len] = 0;
FILE_AppendToString(&data.finalStringPath, " -> ");
FILE_AppendToString(&data.finalStringPath, data.linkPath);
}
}
memset(data.lastModifiedDataString, 0, LIST_DATA_TYPE_MODIFIED_DATA_STR_SIZE);
strftime(data.lastModifiedDataString, LIST_DATA_TYPE_MODIFIED_DATA_STR_SIZE, "%b %d %Y", localtime(&data.lastModifiedData));
switch (commandType)
{
case COMMAND_TYPE_LIST:
{
returnCode = dprintf(theSocket, "%s %d %s %s %lld %s %s\r\n",
data.inodePermissionString == NULL? "Uknown" : data.inodePermissionString
,data.numberOfSubDirectories
,data.owner == NULL? "Uknown" : data.owner
,data.groupOwner == NULL? "Uknown" : data.groupOwner
,data.fileSize
,data.lastModifiedDataString == NULL? "Uknown" : data.lastModifiedDataString
,data.finalStringPath == NULL? "Uknown" : data.finalStringPath);
}
break;
case COMMAND_TYPE_NLIST:
{
returnCode = dprintf(theSocket, "%s\r\n",data.fileNameNoPath);
}
break;
default:
{
printf("\nWarning switch default in function writeListDataInfoToSocket (%d)", commandType);
}
break;
}
if (data.fileNameWithPath != NULL)
free(data.fileNameWithPath);
if (data.linkPath != NULL)
free(data.linkPath);
if (data.finalStringPath != NULL)
free(data.finalStringPath);
if (data.owner != NULL)
free(data.owner);
if (data.groupOwner != NULL)
free(data.groupOwner);
if (data.inodePermissionString != NULL)
free(data.inodePermissionString);
if (returnCode <= 0)
{
for (x = i+1; x < fileAndFoldersCount; x++)
free (fileList[x]);
free (fileList);
return -1;
}
}
free (fileList);
return 1;
}
void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo)
{
int i;
@ -224,6 +381,9 @@ void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo)
ftpListDataType data;
FILE_GetDirectoryInodeList(thePath, &data.fileList, &fileAndFoldersCount, 0);
printf("\nNUMBER OF FILES: %d", fileAndFoldersCount);
fflush(0);
for (i = 0; i < fileAndFoldersCount; i++)
{
data.owner = NULL;
@ -237,8 +397,14 @@ void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo)
data.isFile = 0;
data.isDirectory = 0;
printf("\nPROCESSING: %s", data.fileList[i]);
fflush(0);
if (FILE_IsDirectory(data.fileList[i]) == 1)
{
printf("\nis file");
fflush(0);
data.isDirectory = 1;
data.isFile = 0;
data.isLink = 0;
@ -246,6 +412,8 @@ void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo)
}
else if (FILE_IsFile(data.fileList[i]) == 1)
{
printf("\nis file");
fflush(0);
data.isDirectory = 0;
data.isFile = 1;
data.isLink = 0;
@ -253,10 +421,12 @@ void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo)
}
if (data.isDirectory == 0 && data.isFile == 0)
{
//printf("\nNot a directory, not a file, broken link");
printf("\nNot a directory, not a file, broken link");
continue;
}
printf("\nFILE SIZE : %lld", data.fileSize);
data.owner = FILE_GetOwner(data.fileList[i]);
data.groupOwner = FILE_GetGroupOwner(data.fileList[i]);
data.fileNameWithPath = data.fileList[i];

View File

@ -25,7 +25,7 @@
#ifndef FTPDATA_H
#define FTPDATA_H
#define _LARGEFILE64_SOURCE
#include <netinet/in.h>
#include "library/dynamicVectors.h"
@ -33,7 +33,10 @@
#define CLIENT_COMMAND_STRING_SIZE 2048
#define CLIENT_BUFFER_STRING_SIZE 2048
#define LIST_DATA_TYPE_MODIFIED_DATA_STR_SIZE 80
#define LIST_DATA_TYPE_MODIFIED_DATA_STR_SIZE 1024
#define COMMAND_TYPE_LIST 0
#define COMMAND_TYPE_NLIST 1
#ifdef __cplusplus
@ -128,7 +131,7 @@ struct workerData
char theCommandReceived[CLIENT_COMMAND_STRING_SIZE];
int commandReceived;
unsigned long int retrRestartAtByte;
long long int retrRestartAtByte;
/* The PASV thread will wait the signal before start */
pthread_mutex_t conditionMutex;
@ -208,7 +211,7 @@ struct ftpListData
int isLink;
char *owner;
char *groupOwner;
int fileSize;
long long int fileSize;
char *inodePermissionString;
char **fileList;
time_t lastModifiedData;
@ -222,6 +225,7 @@ int getSafePath(dynamicStringDataType *safePath, char *theDirectoryName, loginDa
void appendToDynamicStringDataType(dynamicStringDataType *dynamicString, char *theString, int stringLen);
void setRandomicPort(ftpDataType *data, int socketPosition);
void getListDataInfo(char * thePath, DYNV_VectorGenericDataType *directoryInfo);
int writeListDataInfoToSocket(char * thePath, int theSocket, int *filesNumber, int commandType);
void deleteListDataInfoVector(void *TheElementToDelete);
void resetWorkerData(workerDataType *pasvData, int isInitialization);
void resetClientData(clientDataType *clientData, int isInitialization);

View File

@ -22,6 +22,8 @@
* THE SOFTWARE.
*/
#define _LARGEFILE64_SOURCE
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
@ -171,7 +173,7 @@ void *connectionWorkerHandle(void * socketId)
{
char theResponse[FTP_COMMAND_ELABORATE_CHAR_BUFFER];
memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER);
ftpData.clients[theSocketId].workerData.theStorFile = fopen(ftpData.clients[theSocketId].fileToStor.text, "wb");
ftpData.clients[theSocketId].workerData.theStorFile = fopen64(ftpData.clients[theSocketId].fileToStor.text, "wb");
if (ftpData.clients[theSocketId].workerData.theStorFile == NULL)
{
@ -238,122 +240,45 @@ void *connectionWorkerHandle(void * socketId)
break;
}
else if (ftpData.clients[theSocketId].workerData.commandReceived == 1 &&
(compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "LIST", strlen("LIST")) == 1))
( (compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "LIST", strlen("LIST")) == 1)
|| (compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "NLST", strlen("NLST")) == 1))
)
{
int i;
char theResponse[FTP_COMMAND_ELABORATE_CHAR_BUFFER];
char theBufferWrite[FTP_COMMAND_ELABORATE_CHAR_BUFFER_BIG];
memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER);
getListDataInfo(ftpData.clients[theSocketId].listPath.text, &ftpData.clients[theSocketId].workerData.directoryInfo);
int theFiles = 0, theCommandType;
printf("\nPasv (%d) ftpData.clients[theSocketId].listPath.text = %s", theSocketId, ftpData.clients[theSocketId].listPath.text);
strcpy(theResponse, "150 Accepted data connection\r\n");
returnCode = write(ftpData.clients[theSocketId].socketDescriptor, theResponse, strlen(theResponse));
if (compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "LIST", strlen("LIST")) == 1)
theCommandType = COMMAND_TYPE_LIST;
else if (compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "NLST", strlen("NLST")) == 1)
theCommandType = COMMAND_TYPE_NLIST;
returnCode = dprintf(ftpData.clients[theSocketId].socketDescriptor, "150 Accepted data connection\r\n");
if (returnCode <= 0)
{
ftpData.clients[theSocketId].closeTheClient = 1;
pthread_exit(NULL);
}
memset(theBufferWrite, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER_BIG);
sprintf(theBufferWrite, "total %d\r\n", ftpData.clients[theSocketId].workerData.directoryInfo.Size);
returnCode = write(ftpData.clients[theSocketId].workerData.socketConnection, theBufferWrite, strlen(theBufferWrite));
if (returnCode <= 0)
{
pthread_exit(NULL);
}
//printf("%s", theBufferWrite);
for (i = 0; i < ftpData.clients[theSocketId].workerData.directoryInfo.Size; i++)
{
memset(theBufferWrite, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER_BIG);
sprintf(theBufferWrite, "%s %d %s %s %d %s %s\r\n",
((((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->inodePermissionString) == NULL? "Uknown" : (((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->inodePermissionString))
,((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->numberOfSubDirectories
,((((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->owner) == NULL? "Uknown" : (((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->owner))
,((((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->groupOwner) == NULL? "Uknown" : (((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->groupOwner))
,((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->fileSize
,((((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->lastModifiedDataString) == NULL? "Uknown" : (((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->lastModifiedDataString))
,((((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->finalStringPath) == NULL? "Uknown" : (((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->finalStringPath)));
printf("\n%s", theBufferWrite);
returnCode = write(ftpData.clients[theSocketId].workerData.socketConnection, theBufferWrite, strlen(theBufferWrite));
if (returnCode <= 0)
{
pthread_exit(NULL);
}
}
memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER);
sprintf(theResponse, "226 %d matches total\r\n", ftpData.clients[theSocketId].workerData.directoryInfo.Size);
returnCode = write(ftpData.clients[theSocketId].socketDescriptor, theResponse, strlen(theResponse));
returnCode = writeListDataInfoToSocket(ftpData.clients[theSocketId].listPath.text, ftpData.clients[theSocketId].workerData.socketConnection, &theFiles, theCommandType);
if (returnCode <= 0)
{
ftpData.clients[theSocketId].closeTheClient = 1;
pthread_exit(NULL);
}
returnCode = dprintf(ftpData.clients[theSocketId].socketDescriptor, "226 %d matches total\r\n", theFiles);
if (returnCode <= 0)
{
ftpData.clients[theSocketId].closeTheClient = 1;
pthread_exit(NULL);
}
printf("\nPasv (%d) List end", theSocketId);
break;
}
else if (ftpData.clients[theSocketId].workerData.commandReceived == 1 &&
compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "NLST", strlen("NLST")) == 1)
{
int i;
char theBufferWrite[FTP_COMMAND_ELABORATE_CHAR_BUFFER_BIG];
char theResponse[FTP_COMMAND_ELABORATE_CHAR_BUFFER];
getListDataInfo(ftpData.clients[theSocketId].nlistPath.text, &ftpData.clients[theSocketId].workerData.directoryInfo);
printf("\nPasv (%d) ftpData.clients[theSocketId].login.absolutePath.text = %s",theSocketId, ftpData.clients[theSocketId].login.absolutePath.text);
memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER);
strcpy(theResponse, "150 Accepted data connection\r\n");
returnCode = write(ftpData.clients[theSocketId].socketDescriptor, theResponse, strlen(theResponse));
if (returnCode <= 0)
{
ftpData.clients[theSocketId].closeTheClient = 1;
pthread_exit(NULL);
}
memset(theBufferWrite, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER_BIG);
sprintf(theBufferWrite, "total %d\r\n", ftpData.clients[theSocketId].workerData.directoryInfo.Size);
returnCode = write(ftpData.clients[theSocketId].workerData.socketConnection, theBufferWrite, strlen(theBufferWrite));
if (returnCode <= 0)
{
pthread_exit(NULL);
}
//printf("%s", theBufferWrite);
for (i = 0; i < ftpData.clients[theSocketId].workerData.directoryInfo.Size; i++)
{
memset(theBufferWrite, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER_BIG);
sprintf(theBufferWrite, "%s\r\n"
,((ftpListDataType *) ftpData.clients[theSocketId].workerData.directoryInfo.Data[i])->fileNameNoPath);
//printf("%s", theBufferWrite);
returnCode = write(ftpData.clients[theSocketId].workerData.socketConnection, theBufferWrite, strlen(theBufferWrite));
if (returnCode <= 0)
{
pthread_exit(NULL);
}
}
memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER);
sprintf(theResponse, "226 %d matches total\r\n", ftpData.clients[theSocketId].workerData.directoryInfo.Size);
returnCode = write(ftpData.clients[theSocketId].socketDescriptor, theResponse, strlen(theResponse));
if (returnCode <= 0)
{
ftpData.clients[theSocketId].closeTheClient = 1;
pthread_exit(NULL);
}
printf("\nPasv (%d) List end", theSocketId);
break;
}
else if (ftpData.clients[theSocketId].workerData.commandReceived == 1 &&
compareStringCaseInsensitive(ftpData.clients[theSocketId].workerData.theCommandReceived, "RETR", strlen("RETR")) == 1)
{
int writenSize = 0, writeReturn = 0;
long long int writenSize = 0, writeReturn = 0;
char theResponse[FTP_COMMAND_ELABORATE_CHAR_BUFFER];
memset(theResponse, 0, FTP_COMMAND_ELABORATE_CHAR_BUFFER);
strcpy(theResponse, "150 Accepted data connection\r\n");

View File

@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#define _LARGEFILE64_SOURCE
#include <stdio.h>
#include <stdlib.h>

View File

@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#define _LARGEFILE64_SOURCE
#include <stdio.h>
#include <sys/types.h>

View File

@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#define _LARGEFILE64_SOURCE
#include <unistd.h>
#include <stdlib.h>

View File

@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#define _LARGEFILE64_SOURCE
#include <stdio.h>
#include <stdlib.h>

View File

@ -23,6 +23,8 @@
*/
#define _LARGEFILE64_SOURCE
#include <pwd.h>
#include <grp.h>
@ -65,13 +67,13 @@ int FILE_IsDirectory(char *DirectoryPath)
{
struct stat sb;
if (stat(DirectoryPath, &sb) == 0 && S_ISDIR(sb.st_mode))
{
{
return 1;
}
}
else
{
{
return 0;
}
}
return 0;
}
@ -91,27 +93,29 @@ long int FILE_GetAvailableSpace(const char* path)
}
/* Get the file size */
int FILE_GetFileSize(FILE *TheFilePointer)
long long int FILE_GetFileSize(FILE *TheFilePointer)
{
int Prev = 0, TheFileSize = 0;
Prev = ftell(TheFilePointer);
fseek(TheFilePointer, 0L, SEEK_END);
TheFileSize = ftell(TheFilePointer);
fseek(TheFilePointer, Prev, SEEK_SET);
long long int Prev = 0, TheFileSize = 0;
Prev = ftello64(TheFilePointer);
fseeko64(TheFilePointer, 0, SEEK_END);
TheFileSize = ftello64(TheFilePointer);
fseeko64(TheFilePointer, Prev, SEEK_SET);
return TheFileSize;
}
int FILE_GetFileSizeFromPath(char *TheFileName)
long long int FILE_GetFileSizeFromPath(char *TheFileName)
{
if (FILE_IsFile(TheFileName) == 1)
{
FILE *TheFilePointer;
TheFilePointer = fopen(TheFileName, "rb");
int Prev = 0, TheFileSize = 0;
Prev = ftell(TheFilePointer);
fseek(TheFilePointer, 0L, SEEK_END);
TheFileSize = ftell(TheFilePointer);
fseek(TheFilePointer, Prev, SEEK_SET);
TheFilePointer = fopen64(TheFileName, "rb");
long long int Prev = 0, TheFileSize = 0;
Prev = ftello64(TheFilePointer);
fseeko64(TheFilePointer, 0L, SEEK_END);
TheFileSize = ftello64(TheFilePointer);
printf("ftello64(TheFilePointer) == %lli", ftello64(TheFilePointer));
fseeko64(TheFilePointer, Prev, SEEK_SET);
fclose(TheFilePointer);
return TheFileSize;
}
@ -125,9 +129,9 @@ int FILE_GetFileSizeFromPath(char *TheFileName)
int FILE_IsFile(const char *TheFileName)
{
FILE *TheFile;
TheFile = fopen(TheFileName, "rb");
TheFile = fopen64(TheFileName, "rb");
if (TheFile)
if (TheFile != NULL)
{
fclose(TheFile);
return 1;
@ -188,7 +192,7 @@ void FILE_GetDirectoryInodeList(char * DirectoryInodeName, char *** InodeList, i
int FILE_GetStringFromFile(char * filename, char **file_content)
{
int file_size = 0;
long long int file_size = 0;
int c, count;
if (FILE_IsFile(filename) == 0)
@ -219,134 +223,134 @@ int FILE_GetStringFromFile(char * filename, char **file_content)
}
void FILE_ReadStringParameters(char * filename, DYNV_VectorGenericDataType *ParametersVector)
{
FILE *File;
char Line[FILE_MAX_LINE_LENGHT];
int i;
int c;
char FirstChar = 0;
char SeparatorChar = 0;
char ParameterChar = 0;
int BufferNameCursor = 0;
int BufferValueCursor = 0;
FILE_StringParameter_DataType TheParameter;
{
FILE *File;
char Line[FILE_MAX_LINE_LENGHT];
int i;
int c;
char FirstChar = 0;
char SeparatorChar = 0;
char ParameterChar = 0;
int BufferNameCursor = 0;
int BufferValueCursor = 0;
FILE_StringParameter_DataType TheParameter;
memset (TheParameter.Name, 0, FILE_MAX_PAR_VAR_SIZE);
memset (TheParameter.Value, 0, FILE_MAX_PAR_VAR_SIZE);
memset (TheParameter.Name, 0, FILE_MAX_PAR_VAR_SIZE);
memset (TheParameter.Value, 0, FILE_MAX_PAR_VAR_SIZE);
File = fopen(filename, "r");
if(File == NULL)
{
printf("error while opening file %s", filename);
}
else
{
printf("Parameter initializing from file %s", filename);
File = fopen(filename, "r");
if(File == NULL)
{
printf("error while opening file %s", filename);
}
else
{
printf("Parameter initializing from file %s", filename);
while(fgets(Line, FILE_MAX_LINE_LENGHT, File) != NULL)
{
//printf("LINE: %s", Line);
i = 0;
while(fgets(Line, FILE_MAX_LINE_LENGHT, File) != NULL)
{
//printf("LINE: %s", Line);
i = 0;
while (i<FILE_MAX_LINE_LENGHT)
{
c = Line[i++];
if (((char) c == ' ' && FirstChar != '#') || (char) c == '\r' || (c == 9 && FirstChar != '#' ) || (c == 10) || (c == 13))
{
continue;
}
while (i<FILE_MAX_LINE_LENGHT)
{
c = Line[i++];
if (((char) c == ' ' && FirstChar != '#') || (char) c == '\r' || (c == 9 && FirstChar != '#' ) || (c == 10) || (c == 13))
{
continue;
}
if ((char) c == '\0' )
{
if ((FirstChar != '#' && FirstChar != '=' && FirstChar != 0 ) && SeparatorChar == '=' && ParameterChar != 0 )
{
TheParameter.Name[BufferNameCursor] = '\0';
TheParameter.Value[BufferValueCursor] = '\0';
printf("Adding name: %s value: %s", TheParameter.Name, TheParameter.Value);
//printf("TheParameter.Name[0] = %d", TheParameter.Name[0]);
if ((char) c == '\0' )
{
if ((FirstChar != '#' && FirstChar != '=' && FirstChar != 0 ) && SeparatorChar == '=' && ParameterChar != 0 )
{
TheParameter.Name[BufferNameCursor] = '\0';
TheParameter.Value[BufferValueCursor] = '\0';
printf("Adding name: %s value: %s", TheParameter.Name, TheParameter.Value);
//printf("TheParameter.Name[0] = %d", TheParameter.Name[0]);
ParametersVector->PushBack(ParametersVector, &TheParameter, sizeof(FILE_StringParameter_DataType));
BufferNameCursor = 0;
BufferValueCursor = 0;
memset (TheParameter.Name, 0, FILE_MAX_PAR_VAR_SIZE);
memset (TheParameter.Value, 0, FILE_MAX_PAR_VAR_SIZE);
}
ParametersVector->PushBack(ParametersVector, &TheParameter, sizeof(FILE_StringParameter_DataType));
BufferNameCursor = 0;
BufferValueCursor = 0;
memset (TheParameter.Name, 0, FILE_MAX_PAR_VAR_SIZE);
memset (TheParameter.Value, 0, FILE_MAX_PAR_VAR_SIZE);
}
FirstChar = 0;
SeparatorChar = 0;
ParameterChar = 0;
FirstChar = 0;
SeparatorChar = 0;
ParameterChar = 0;
if ((char) c == '\0')
{
break;
}
}
else
{
//printf("Checking chars");
if ((char) c == '\0')
{
break;
}
}
else
{
//printf("Checking chars");
//first char, parameter name
if (FirstChar == 0)
{
FirstChar = (char) c;
//printf("FirstChar = %c", FirstChar);
}
else if (FirstChar != 0 && SeparatorChar == 0 && (char) c == '=')
{
SeparatorChar = (char) c;
//printf("SeparatorChar = %c", SeparatorChar);
}
else if (FirstChar != 0 && SeparatorChar != 0 && ParameterChar == 0)
{
ParameterChar = (char) c;
//printf("ParameterChar = %c", ParameterChar);
}
//first char, parameter name
if (FirstChar == 0)
{
FirstChar = (char) c;
//printf("FirstChar = %c", FirstChar);
}
else if (FirstChar != 0 && SeparatorChar == 0 && (char) c == '=')
{
SeparatorChar = (char) c;
//printf("SeparatorChar = %c", SeparatorChar);
}
else if (FirstChar != 0 && SeparatorChar != 0 && ParameterChar == 0)
{
ParameterChar = (char) c;
//printf("ParameterChar = %c", ParameterChar);
}
//Get the parameter name
if ( FirstChar != '#' && FirstChar != 0 && SeparatorChar == 0 && BufferNameCursor < FILE_MAX_PAR_VAR_SIZE )
if(BufferNameCursor < FILE_MAX_PAR_VAR_SIZE)
TheParameter.Name[BufferNameCursor++] = (char) c;
//Get the parameter name
if ( FirstChar != '#' && FirstChar != 0 && SeparatorChar == 0 && BufferNameCursor < FILE_MAX_PAR_VAR_SIZE )
if(BufferNameCursor < FILE_MAX_PAR_VAR_SIZE)
TheParameter.Name[BufferNameCursor++] = (char) c;
//Get the parameter value
if ( FirstChar != '#' && FirstChar != 0 && SeparatorChar != 0 && ParameterChar != 0 && BufferValueCursor < FILE_MAX_PAR_VAR_SIZE )
if(BufferValueCursor < FILE_MAX_PAR_VAR_SIZE)
TheParameter.Value[BufferValueCursor++] = (char) c;
}
}
}
//Get the parameter value
if ( FirstChar != '#' && FirstChar != 0 && SeparatorChar != 0 && ParameterChar != 0 && BufferValueCursor < FILE_MAX_PAR_VAR_SIZE )
if(BufferValueCursor < FILE_MAX_PAR_VAR_SIZE)
TheParameter.Value[BufferValueCursor++] = (char) c;
}
}
}
fclose(File);
}
fclose(File);
}
printf("ParametersVector->Size %d", ParametersVector->Size);
printf("ParametersVector->Size %d", ParametersVector->Size);
for (i = 0; i < ParametersVector->Size; i++)
{
printf("ParametersVector->Data[%d])->Name = %s",i, ((FILE_StringParameter_DataType *)ParametersVector->Data[i])->Name);
}
for (i = 0; i < ParametersVector->Size; i++)
{
printf("ParametersVector->Data[%d])->Name = %s",i, ((FILE_StringParameter_DataType *)ParametersVector->Data[i])->Name);
}
qsort(ParametersVector->Data, ParametersVector->Size, sizeof(void *), FILE_CompareStringParameter);
qsort(ParametersVector->Data, ParametersVector->Size, sizeof(void *), FILE_CompareStringParameter);
printf("Sorted");
for (i = 0; i < ParametersVector->Size; i++)
{
printf("ParametersVector->Data[%d])->Name = %s",i, ((FILE_StringParameter_DataType *)ParametersVector->Data[i])->Name);
}
printf("Sorted");
for (i = 0; i < ParametersVector->Size; i++)
{
printf("ParametersVector->Data[%d])->Name = %s",i, ((FILE_StringParameter_DataType *)ParametersVector->Data[i])->Name);
}
}
}
int FILE_StringParametersLinearySearch(DYNV_VectorGenericDataType *TheVectorGeneric, void * name)
{
int i;
for(i=0; i<TheVectorGeneric->Size; i++)
{
if(strcmp(((FILE_StringParameter_DataType *)TheVectorGeneric->Data[i])->Name, (char *) name) == 0)
{
return i;
}
}
return -1;
}
{
int i;
for(i=0; i<TheVectorGeneric->Size; i++)
{
if(strcmp(((FILE_StringParameter_DataType *)TheVectorGeneric->Data[i])->Name, (char *) name) == 0)
{
return i;
}
}
return -1;
}
int FILE_StringParametersBinarySearch(DYNV_VectorGenericDataType *TheVectorGeneric, void * Needle)
{
@ -490,47 +494,40 @@ time_t FILE_GetLastModifiedData(char *path)
void FILE_AppendToString(char ** sourceString, char *theString)
{
//printf("\n sourcestring = %s", *sourceString);
//printf("\n theString = %s", theString);
int theNewSize = strlen(*sourceString) + strlen(theString);
*sourceString = realloc(*sourceString, theNewSize + 10);
strcat(*sourceString, theString);
(*sourceString)[theNewSize] = '\0';
// printf("\n sourcestring = %s", *sourceString);
// printf("\n theString = %s", theString);
// printf("\n theNewSize = %d", theNewSize);
int theNewSize = strlen(*sourceString) + strlen(theString);
*sourceString = realloc(*sourceString, theNewSize + 10);
strcat(*sourceString, theString);
(*sourceString)[theNewSize] = '\0';
}
void FILE_DirectoryToParent(char ** sourceString)
{
//printf("\n");
int i = 0, theLastSlash = -1, strLen = 0;
//printf("\n");
int i = 0, theLastSlash = -1, strLen = 0;
strLen = strlen(*sourceString);
//printf("\nstrLen = %d", strLen);
strLen = strlen(*sourceString);
//printf("\nstrLen = %d", strLen);
for (i = 0; i < strLen; i++)
{
//printf("%c", (*sourceString)[i]);
if ( (*sourceString)[i] == '/')
{
theLastSlash = i;
//printf("\n theLastSlash = %d", theLastSlash);
}
}
for (i = 0; i < strLen; i++)
{
//printf("%c", (*sourceString)[i]);
if ( (*sourceString)[i] == '/')
{
theLastSlash = i;
//printf("\n theLastSlash = %d", theLastSlash);
}
}
if (theLastSlash > -1)
{
int theNewSize = theLastSlash;
if (theLastSlash == 0)
{
theNewSize = 1;
}
*sourceString = realloc(*sourceString, theNewSize+1);
(*sourceString)[theNewSize] = '\0';
}
if (theLastSlash > -1)
{
int theNewSize = theLastSlash;
if (theLastSlash == 0)
{
theNewSize = 1;
}
*sourceString = realloc(*sourceString, theNewSize+1);
(*sourceString)[theNewSize] = '\0';
}
}

View File

@ -23,7 +23,7 @@
*/
#ifndef GEN_FILE_MANAGEMENT_TYPES
#define _LARGEFILE64_SOURCE
#include <stdio.h>
#include <time.h>
#include <sys/types.h>
@ -48,9 +48,9 @@
}
FILE_fileInfo_DataType;
int FILE_GetFileSize(FILE *theFilePointer);
long long int FILE_GetFileSize(FILE *theFilePointer);
long int FILE_GetAvailableSpace(const char* ThePath);
int FILE_GetFileSizeFromPath(char *TheFileName);
long long int FILE_GetFileSizeFromPath(char *TheFileName);
int FILE_IsFile(const char *theFileName);
int FILE_IsDirectory (char *directory_path);
void FILE_GetDirectoryInodeList(char * DirectoryInodeName, char *** InodeList, int * filesandfolders, int recursive);

View File

@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#define _LARGEFILE64_SOURCE
#include <time.h>
#include "logFunctions.h"

View File

@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#define _LARGEFILE64_SOURCE
#include <stdio.h>
#include <signal.h>

View File

@ -7,10 +7,7 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpData.c</file>
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpCommandElaborate.c</file>
<file>file:/home/ugo/NetBeansProjects/uFTP/ftpServer.c</file>
<file>file:/home/ugo/NetBeansProjects/uFTP/uFTP.c</file>
<file>file:/home/ugo/NetBeansProjects/uFTP/library/configRead.c</file>
</group>
</open-files>

2
uFTP.c
View File

@ -21,6 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#define _LARGEFILE64_SOURCE
#include <stdio.h>
#include <stdlib.h>
@ -31,4 +32,3 @@ int main(int argc, char** argv)
runFtpServer();
return (EXIT_SUCCESS);
}