mirror of
https://github.com/glest/glest-source.git
synced 2025-08-10 18:34:05 +02:00
- got my plumbers suit on and added the plumbing for FTP file xfers
This commit is contained in:
188
source/shared_lib/include/feathery_ftp/ftp.h
Executable file
188
source/shared_lib/include/feathery_ftp/ftp.h
Executable file
@@ -0,0 +1,188 @@
|
||||
/**
|
||||
* Feathery FTP-Server <https://sourceforge.net/projects/feathery>
|
||||
* Copyright (C) 2005-2010 Andreas Martin (andreas.martin@linuxmail.org)
|
||||
*
|
||||
* ftp.h - ftp-server interface-header
|
||||
*
|
||||
* Contains all internal definitions and prototypes of feathery.
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef FTP_H_
|
||||
#define FTP_H_
|
||||
|
||||
|
||||
/**
|
||||
* @brief specifies the type of operation that is in progress
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
OP_NOP = 0, ///< no operation
|
||||
OP_RETR = 1, ///< RETR command
|
||||
OP_STOR = 2, ///< STOR command
|
||||
OP_LIST = 3 ///< LIST command
|
||||
}operation_E;
|
||||
|
||||
/**
|
||||
* @brief infos about a file/directory transmittion
|
||||
* @see ftpExecTransmission
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
operation_E op; ///< active transmission
|
||||
void* fsHandle; ///< file or directory handle of current transmission
|
||||
socket_t dataSocket; ///< data socket of current transmission
|
||||
uint32_t fileSize; ///< size of file to transmit
|
||||
|
||||
}transmission_S;
|
||||
|
||||
/**
|
||||
* @brief Data of a ftp session
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int open; ///< TRUE, if the session is open
|
||||
int authenticated; ///< TRUE, if user is authenticated via USER and PASS commands
|
||||
int userId; ///< id of the dedicated user account, is 0 until execution of USER command
|
||||
int rxBufWriteIdx; ///< currect write index of receive buffer rxBuf
|
||||
char rxBuf[LEN_RXBUF]; ///< receive buffer for ftp commands
|
||||
char workingDir[MAX_PATH_LEN]; ///< current working directory (absolute path which is relative to the root-path of the user account)
|
||||
ip_t remoteIp; ///< IP of connected ftp client
|
||||
port_t remotePort; ///< Port of connected ftp client for control connection
|
||||
port_t remoteDataPort; ///< Port of connected ftp client for data connection
|
||||
int passive; ///< TRUE, if passive-mode is activated via PSV command
|
||||
int binary; ///< TRUE, if binary-mode is active
|
||||
uint32_t timeLastCmd; ///< timestamp of last ftp activity (used for timeout generation)
|
||||
socket_t ctrlSocket; ///< socket for control connection
|
||||
socket_t passiveDataSocket; ///< listener socket for data connections in passive mode
|
||||
transmission_S activeTrans; ///< infos about a currently active file/directory-transmission
|
||||
|
||||
}ftpSession_S;
|
||||
|
||||
/**
|
||||
* @brief format in which a message is to be displayed
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
MSG_NORMAL = 0, ///< normal message, no translation
|
||||
MSG_QUOTE = 1, ///< message will be displayed between doublequotes
|
||||
MSG_MULTILINE = 2 ///< message contains multiple lines
|
||||
}msgmode_E;
|
||||
|
||||
/**
|
||||
* @brief time-structure
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint16_t year; ///< year 0000-9999
|
||||
uint8_t month; ///< month 1 - 12
|
||||
uint8_t day; ///< day 1 - 31
|
||||
uint8_t hour; ///< hour 0 - 23
|
||||
uint8_t minute; ///< minute 0 - 59
|
||||
uint8_t second; ///< second 0 - 59
|
||||
|
||||
}ftpTime_S;
|
||||
|
||||
/**
|
||||
* @brief type of a file
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
TYPE_FILE = 1, ///< regular file
|
||||
TYPE_DIR = 2, ///< directory
|
||||
TYPE_LINK = 4 ///< hard link
|
||||
|
||||
}ftpFileType_E;
|
||||
|
||||
/**
|
||||
* @brief infos about a file or directory similar to stat
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
ftpFileType_E type; ///< filetype
|
||||
uint16_t mode; ///< access rights (currently unused)
|
||||
ftpTime_S cTime; ///< creation time (currently unused)
|
||||
ftpTime_S aTime; ///< last access time (currently unused)
|
||||
ftpTime_S mTime; ///< time of last modification
|
||||
uint32_t size; ///< size
|
||||
int links; ///< count of hard links
|
||||
char user[20]; ///< owner
|
||||
char group[20]; ///< group
|
||||
|
||||
}ftpPathInfo_S;
|
||||
|
||||
extern int ftpOpenSession(socket_t ctrlSocket, ip_t remoteIp, port_t remotePort);
|
||||
extern int ftpCloseSession(int id);
|
||||
extern ftpSession_S* ftpGetSession(int id);
|
||||
extern int ftpAuthSession(int id);
|
||||
extern const char* ftpGetRealPath(int id, const char* path, int normalize);
|
||||
extern int ftpChangeDir(int id, const char* path);
|
||||
extern void ftpOpenTransmission(int id, operation_E op, void* fsHandle, socket_t dataSocket, uint32_t fileSize);
|
||||
extern void ftpCloseTransmission(int id);
|
||||
extern int ftpGetActiveTransCnt(void);
|
||||
|
||||
extern int ftpFindAccount(const char* name);
|
||||
extern int ftpCheckPassword(int userId, const char* passw);
|
||||
extern int ftpCheckAccRights(int userId, int accRights);
|
||||
extern const char* ftpGetRoot(int userId, int* len);
|
||||
|
||||
extern int ftpSendMsg(msgmode_E mode, int sessionId, int ret, const char* msg);
|
||||
extern int ftpExecTransmission(int sessionId);
|
||||
extern void ftpParseCmd(int sessionId);
|
||||
|
||||
extern int ftpRemoveTrailingSlash(char* path);
|
||||
extern void ftpRemoveDoubleSlash(char* path);
|
||||
extern char* ftpMergePaths(char* dest, ...);
|
||||
extern uint32_t ftpGetUnixTime(void);
|
||||
extern char *ftpStrcpy(char *dest, const char *src);
|
||||
|
||||
|
||||
extern void ftpArchInit(void);
|
||||
extern void ftpArchCleanup(void);
|
||||
extern int ftpGetLocalTime(ftpTime_S *t);
|
||||
extern void* ftpOpenDir(const char* path);
|
||||
extern const char* ftpReadDir(void* dirHandle);
|
||||
extern int ftpCloseDir(void* dirHandle);
|
||||
extern int ftpStat(const char* path, ftpPathInfo_S *info);
|
||||
#if ANSI_FILE_IO
|
||||
# define ftpOpenFile fopen
|
||||
# define ftpCloseFile fclose
|
||||
# define ftpReadFile fread
|
||||
# define ftpWriteFile fwrite
|
||||
# define ftpRemoveFile remove
|
||||
#else
|
||||
extern void* ftpOpenFile(const char *filename, const char *mode);
|
||||
extern int ftpCloseFile(void *stream );
|
||||
extern int ftpReadFile(void *buffer, size_t size, size_t count, void *stream);
|
||||
extern int ftpWriteFile(const void *buffer, size_t size, size_t count, void *stream);
|
||||
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 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);
|
||||
extern socket_t ftpAcceptDataConnection(socket_t listner);
|
||||
extern socket_t ftpCreateServerSocket(void);
|
||||
extern socket_t ftpAcceptServerConnection(socket_t server, ip_t *remoteIP, port_t *remotePort);
|
||||
extern int ftpTrackSocket(socket_t s);
|
||||
extern int ftpUntrackSocket(socket_t s);
|
||||
extern int ftpTestSocket(socket_t s);
|
||||
extern int ftpSelect(int poll);
|
||||
|
||||
#endif /* FTP_H_ */
|
86
source/shared_lib/include/feathery_ftp/ftpConfig.h
Normal file
86
source/shared_lib/include/feathery_ftp/ftpConfig.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/**
|
||||
* Feathery FTP-Server <https://sourceforge.net/projects/feathery>
|
||||
* Copyright (C) 2005-2010 Andreas Martin (andreas.martin@linuxmail.org)
|
||||
*
|
||||
* ftpConfig.h - Compile time server configuration
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef FTPCONFIG_H_
|
||||
#define FTPCONFIG_H_
|
||||
|
||||
/**
|
||||
* @brief max. possible simultaneous FTP client connections
|
||||
*/
|
||||
#define MAX_CONNECTIONS 10
|
||||
|
||||
/**
|
||||
* @brief max. possible user accounts
|
||||
*/
|
||||
#define MAX_USERS 10
|
||||
|
||||
/**
|
||||
* @brief max. length of a user account name
|
||||
*/
|
||||
#define MAXLEN_USERNAME 10
|
||||
|
||||
/**
|
||||
* @brief max. length of a user account password
|
||||
*/
|
||||
#define MAXLEN_PASSWORD 10
|
||||
|
||||
/**
|
||||
* @brief session timeout in seconds
|
||||
*/
|
||||
#define SESSION_TIMEOUT 600
|
||||
|
||||
/**
|
||||
* @brief maximum length of a complete directory path
|
||||
*/
|
||||
#define MAX_PATH_LEN 260
|
||||
|
||||
/**
|
||||
* @brief Size of the scratch buffer
|
||||
*
|
||||
* The scratch buffer is used for
|
||||
* send / receive of files and directory listings
|
||||
*/
|
||||
#define LEN_SCRATCHBUF 1024
|
||||
|
||||
/**
|
||||
* @brief Size of the receive buffer for ftp commands
|
||||
*
|
||||
* Buffer must be big enough to hold a complete ftp command.
|
||||
* command (4) + space (1) + path (MAX_PATH_LEN) + quotes (2) + CRLF (2) + end of string (1)
|
||||
*/
|
||||
#define LEN_RXBUF (MAX_PATH_LEN + 10)
|
||||
|
||||
/**
|
||||
* @brief activates ftp extentions according to RFC 3659
|
||||
*/
|
||||
#define RFC3659 1
|
||||
|
||||
/**
|
||||
* @brief set to 1 to activate debug messages on stdout
|
||||
*/
|
||||
#define DBG_LOG 1
|
||||
|
||||
/**
|
||||
* @brief set to 1 if target-plattform supports ANSI-C file-IO functions
|
||||
*/
|
||||
#define ANSI_FILE_IO 1
|
||||
|
||||
#endif /* FTPCONFIG_H_ */
|
49
source/shared_lib/include/feathery_ftp/ftpIfc.h
Normal file
49
source/shared_lib/include/feathery_ftp/ftpIfc.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Feathery FTP-Server <https://sourceforge.net/projects/feathery>
|
||||
* Copyright (C) 2005-2010 Andreas Martin (andreas.martin@linuxmail.org)
|
||||
*
|
||||
* ftpIfc.h - ftp-server interface-header
|
||||
*
|
||||
* All exported functions and constants are defined in this header. This is
|
||||
* the only header-file that a application which uses feathery shall include.
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef FTPIFC_H_
|
||||
#define FTPIFC_H_
|
||||
|
||||
|
||||
#define FTP_ACC_RD 1
|
||||
#define FTP_ACC_WR 2
|
||||
#define FTP_ACC_LS 4
|
||||
#define FTP_ACC_DIR 8
|
||||
#define FTP_ACC_FULL (FTP_ACC_RD | FTP_ACC_WR | FTP_ACC_LS | FTP_ACC_DIR)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int ftpCreateAccount(const char* name, const char* passw, const char* root, int accRights);
|
||||
int ftpStart(void);
|
||||
int ftpShutdown(void);
|
||||
void ftpExecute(void);
|
||||
int ftpState(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* FTPIFC_H_ */
|
69
source/shared_lib/include/feathery_ftp/ftpMessages.h
Normal file
69
source/shared_lib/include/feathery_ftp/ftpMessages.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Feathery FTP-Server <https://sourceforge.net/projects/feathery>
|
||||
* Copyright (C) 2005-2010 Andreas Martin (andreas.martin@linuxmail.org)
|
||||
*
|
||||
* ftpMessages.h - FTP-Server messages
|
||||
*
|
||||
* This header exports the in ftpMessges.c defined messages.
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef FTPMESSAGES_H_
|
||||
#define FTPMESSAGES_H_
|
||||
|
||||
extern const char ftpMsg000[];
|
||||
extern const char ftpMsg001[];
|
||||
extern const char ftpMsg002[];
|
||||
extern const char ftpMsg003[];
|
||||
extern const char ftpMsg004[];
|
||||
extern const char ftpMsg005[];
|
||||
extern const char ftpMsg006[];
|
||||
extern const char ftpMsg007[];
|
||||
extern const char ftpMsg008[];
|
||||
extern const char ftpMsg009[];
|
||||
extern const char ftpMsg010[];
|
||||
extern const char ftpMsg011[];
|
||||
extern const char ftpMsg012[];
|
||||
extern const char ftpMsg013[];
|
||||
extern const char ftpMsg014[];
|
||||
extern const char ftpMsg015[];
|
||||
extern const char ftpMsg016[];
|
||||
extern const char ftpMsg018[];
|
||||
extern const char ftpMsg019[];
|
||||
extern const char ftpMsg020[];
|
||||
extern const char ftpMsg021[];
|
||||
extern const char ftpMsg022[];
|
||||
extern const char ftpMsg023[];
|
||||
extern const char ftpMsg024[];
|
||||
extern const char ftpMsg025[];
|
||||
extern const char ftpMsg026[];
|
||||
extern const char ftpMsg027[];
|
||||
extern const char ftpMsg028[];
|
||||
extern const char ftpMsg029[];
|
||||
extern const char ftpMsg030[];
|
||||
extern const char ftpMsg031[];
|
||||
extern const char ftpMsg032[];
|
||||
extern const char ftpMsg033[];
|
||||
extern const char ftpMsg034[];
|
||||
extern const char ftpMsg035[];
|
||||
extern const char ftpMsg036[];
|
||||
extern const char ftpMsg037[];
|
||||
extern const char ftpMsg038[];
|
||||
extern const char ftpMsg039[];
|
||||
extern const char ftpMsg040[];
|
||||
|
||||
|
||||
#endif /* FTPMESSAGES_H_ */
|
63
source/shared_lib/include/feathery_ftp/ftpTypes.h
Executable file
63
source/shared_lib/include/feathery_ftp/ftpTypes.h
Executable file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Feathery FTP-Server <https://sourceforge.net/projects/feathery>
|
||||
* Copyright (C) 2005-2010 Andreas Martin (andreas.martin@linuxmail.org)
|
||||
*
|
||||
* ftpTypes.h - global type definitions
|
||||
*
|
||||
* Definitions of fixed size integers an helper macros.
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef FTPTYPES_H_
|
||||
#define FTPTYPES_H_
|
||||
|
||||
|
||||
// if the compiler is c99 complient, we don't need to define our own types
|
||||
#if __STDC_VERSION__ == 199901L
|
||||
# include <stdint.h>
|
||||
#else
|
||||
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef signed int int32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
|
||||
#endif
|
||||
|
||||
typedef int socket_t;
|
||||
typedef uint32_t ip_t;
|
||||
typedef uint16_t port_t;
|
||||
|
||||
/**
|
||||
* @brief returns the number of elements of an array
|
||||
*/
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
|
||||
/**
|
||||
* @brief defines functions/variables local to a module
|
||||
*/
|
||||
#define LOCAL static
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user