VirtualBox

source: vbox/trunk/include/iprt/ftp.h@ 82721

Last change on this file since 82721 was 82715, checked in by vboxsync, 5 years ago

IPRT/FTP: More protocol handling and callback work. bugref:9437

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 KB
Line 
1/* $Id: ftp.h 82715 2020-01-10 14:04:36Z vboxsync $ */
2/** @file
3 * Header file for FTP client / server implementations.
4 */
5
6/*
7 * Copyright (C) 2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef IPRT_INCLUDED_ftp_h
28#define IPRT_INCLUDED_ftp_h
29#ifndef RT_WITHOUT_PRAGMA_ONCE
30# pragma once
31#endif
32
33#include <iprt/types.h>
34
35RT_C_DECLS_BEGIN
36
37/** @defgroup grp_rt_ftp RTFTPServer - FTP server implementation.
38 * @ingroup grp_rt
39 * @{
40 */
41
42/** @todo the following three definitions may move the iprt/types.h later. */
43/** FTP server handle. */
44typedef R3PTRTYPE(struct RTFTPSERVERINTERNAL *) RTFTPSERVER;
45/** Pointer to a FTP server handle. */
46typedef RTFTPSERVER *PRTFTPSERVER;
47/** Nil FTP client handle. */
48#define NIL_RTFTPSERVER ((RTFTPSERVER)0)
49
50/** Maximum length (in characters) a command can have (without parameters). */
51#define RTFTPSERVER_MAX_CMD_LEN 64
52
53/**
54 * Enumeration for defining the current server connection mode.
55 */
56typedef enum RTFTPSERVER_CONNECTION_MODE
57{
58 /** Normal mode, nothing to transfer. */
59 RTFTPSERVER_CONNECTION_MODE_NORMAL = 0,
60 /** Server is in passive mode (is listening). */
61 RTFTPSERVER_CONNECTION_MODE_PASSIVE,
62 /** Server connects via port to the client. */
63 RTFTPSERVER_CONNECTION_MODE_MODE_PORT,
64 /** The usual 32-bit hack. */
65 RTFTPSERVER_CONNECTION_MODE_32BIT_HACK = 0x7fffffff
66} RTFTPSERVER_CONNECTION_MODE;
67
68/**
69 * Enumeration for defining the data transfer mode.
70 */
71typedef enum RTFTPSERVER_TRANSFER_MODE
72{
73 RTFTPSERVER_TRANSFER_MODE_UNKNOWN = 0,
74 RTFTPSERVER_TRANSFER_MODE_STREAM,
75 RTFTPSERVER_TRANSFER_MODE_BLOCK,
76 RTFTPSERVER_TRANSFER_MODE_COMPRESSED,
77 /** The usual 32-bit hack. */
78 RTFTPSERVER_DATA_MODE_32BIT_HACK = 0x7fffffff
79} RTFTPSERVER_DATA_MODE;
80
81/**
82 * Enumeration for defining the data type.
83 */
84typedef enum RTFTPSERVER_DATA_TYPE
85{
86 RTFTPSERVER_DATA_TYPE_UNKNOWN = 0,
87 RTFTPSERVER_DATA_TYPE_ASCII,
88 RTFTPSERVER_DATA_TYPE_EBCDIC,
89 RTFTPSERVER_DATA_TYPE_IMAGE,
90 RTFTPSERVER_DATA_TYPE_LOCAL,
91 /** The usual 32-bit hack. */
92 RTFTPSERVER_DATA_TYPE_32BIT_HACK = 0x7fffffff
93} RTFTPSERVER_DATA_TYPE;
94
95/**
96 * Enumeration for FTP server reply codes.
97 *
98 ** @todo Might needs more codes, not complete yet.
99 */
100typedef enum RTFTPSERVER_REPLY
101{
102 /** Invalid reply type, do not use. */
103 RTFTPSERVER_REPLY_INVALID = 0,
104 /** Command not implemented, superfluous at this site. */
105 RTFTPSERVER_REPLY_ERROR_CMD_NOT_IMPL_SUPERFLUOUS = 202,
106 /** Command okay. */
107 RTFTPSERVER_REPLY_OKAY = 200,
108 /** Service ready for new user. */
109 RTFTPSERVER_REPLY_READY_FOR_NEW_USER = 220,
110 /** Service is closing control connection. */
111 RTFTPSERVER_REPLY_CLOSING_CTRL_CONN = 221,
112 /** Closing data connection. */
113 RTFTPSERVER_REPLY_CLOSING_DATA_CONN = 226,
114 /** User logged in, proceed. */
115 RTFTPSERVER_REPLY_LOGGED_IN_PROCEED = 230,
116 /** User name okay, need password. */
117 RTFTPSERVER_REPLY_USERNAME_OKAY_NEED_PASSWORD = 331,
118 /** Connection closed; transfer aborted. */
119 RTFTPSERVER_REPLY_CONN_CLOSED_TRANSFER_ABORTED = 426,
120 /** Syntax error, command unrecognized. */
121 RTFTPSERVER_REPLY_ERROR_CMD_NOT_RECOGNIZED = 500,
122 /** Syntax error in parameters or arguments. */
123 RTFTPSERVER_REPLY_ERROR_INVALID_PARAMETERS = 501,
124 /** Command not implemented. */
125 RTFTPSERVER_REPLY_ERROR_CMD_NOT_IMPL = 502,
126 /** Bad sequence of commands. */
127 RTFTPSERVER_REPLY_ERROR_BAD_SEQUENCE = 503,
128 /** Command not implemented for that parameter. */
129 RTFTPSERVER_REPLY_ERROR_CMD_NOT_IMPL_PARAM = 504,
130 /** Not logged in. */
131 RTFTPSERVER_REPLY_NOT_LOGGED_IN = 530,
132 /** The usual 32-bit hack. */
133 RTFTPSERVER_REPLY_32BIT_HACK = 0x7fffffff
134} RTFTPSERVER_REPLY;
135
136/**
137 * Structure for maintaining a FTP server client state.
138 */
139typedef struct RTFTPSERVERCLIENTSTATE
140{
141 /** User name. */
142 char *pszUser;
143 /** Number of failed login attempts. */
144 uint8_t cFailedLoginAttempts;
145 /** Timestamp (in ms) of last command issued by the client. */
146 uint64_t tsLastCmdMs;
147} RTFTPSERVERCLIENTSTATE;
148/** Pointer to a FTP server client state. */
149typedef RTFTPSERVERCLIENTSTATE *PRTFTPSERVERCLIENTSTATE;
150
151/**
152 * Structure for storing FTP server callback data.
153 */
154typedef struct RTFTPCALLBACKDATA
155{
156 /** Pointer to the client state. */
157 PRTFTPSERVERCLIENTSTATE pClient;
158 /** Saved user pointer. */
159 void *pvUser;
160 /** Size (in bytes) of data at user pointer. */
161 size_t cbUser;
162} RTFTPCALLBACKDATA;
163/** Pointer to FTP server callback data. */
164typedef RTFTPCALLBACKDATA *PRTFTPCALLBACKDATA;
165
166/**
167 * Function callback table for the FTP server implementation.
168 *
169 * All callbacks are optional and therefore can be NULL.
170 */
171typedef struct RTFTPSERVERCALLBACKS
172{
173 /** User pointer to data. Optional and can be NULL. */
174 void *pvUser;
175 /** Size (in bytes) of user data pointing at. Optional and can be 0. */
176 size_t cbUser;
177 /**
178 * Callback which gets invoked when a user connected.
179 *
180 * @returns VBox status code.
181 * @param pcszUser User name.
182 */
183 DECLCALLBACKMEMBER(int, pfnOnUserConnect)(PRTFTPCALLBACKDATA pData, const char *pcszUser);
184 /**
185 * Callback which gets invoked when a user tries to authenticate with a password.
186 *
187 * @returns VBox status code.
188 * @param pcszUser User name to authenticate.
189 * @param pcszPassword Password to authenticate with.
190 */
191 DECLCALLBACKMEMBER(int, pfnOnUserAuthenticate)(PRTFTPCALLBACKDATA pData, const char *pcszUser, const char *pcszPassword);
192 /**
193 * Callback which gets invoked when a user disconnected.
194 *
195 * @returns VBox status code.
196 * @param pcszUser User name which disconnected.
197 */
198 DECLCALLBACKMEMBER(int, pfnOnUserDisconnect)(PRTFTPCALLBACKDATA pData);
199 /**
200 * Callback which gets invoked when setting the current working directory.
201 *
202 * @returns VBox status code.
203 * @param pcszCWD Current working directory to set.
204 */
205 DECLCALLBACKMEMBER(int, pfnOnPathSetCurrent)(PRTFTPCALLBACKDATA pData, const char *pcszCWD);
206 /**
207 * Callback which gets invoked when a client wants to retrieve the current working directory.
208 *
209 * @returns VBox status code.
210 * @param pszPWD Where to store the current working directory.
211 * @param cbPWD Size of buffer in bytes.
212 */
213 DECLCALLBACKMEMBER(int, pfnOnPathGetCurrent)(PRTFTPCALLBACKDATA pData, char *pszPWD, size_t cbPWD);
214 /**
215 * Callback which gets invoked when the client wants to move up a directory (relative to the current working directory).
216 *
217 * @returns VBox status code.
218 */
219 DECLCALLBACKMEMBER(int, pfnOnPathUp)(PRTFTPCALLBACKDATA pData);
220 /**
221 * Callback which gets invoked when the client wants to list a directory or file.
222 *
223 * @param pcszPath Path of file / directory to list. Optional. If NULL, the current directory will be listed.
224 * @param ppvData Where to return the listing data. Must be free'd by the caller.
225 * @param pcbvData Where to return the listing data size in bytes.
226 * @returns VBox status code.
227 */
228 DECLCALLBACKMEMBER(int, pfnOnList)(PRTFTPCALLBACKDATA pData, const char *pcszPath, void **ppvData, size_t *pcbData);
229} RTFTPSERVERCALLBACKS;
230/** Pointer to a FTP server callback data table. */
231typedef RTFTPSERVERCALLBACKS *PRTFTPSERVERCALLBACKS;
232
233/**
234 * Creates a FTP server instance.
235 *
236 * @returns IPRT status code.
237 * @param phFTPServer Where to store the FTP server handle.
238 * @param pcszAddress The address for creating a listening socket.
239 * If NULL or empty string the server is bound to all interfaces.
240 * @param uPort The port for creating a listening socket.
241 * @param pCallbacks Callback table to use.
242 */
243RTR3DECL(int) RTFtpServerCreate(PRTFTPSERVER phFTPServer, const char *pcszAddress, uint16_t uPort,
244 PRTFTPSERVERCALLBACKS pCallbacks);
245
246/**
247 * Destroys a FTP server instance.
248 *
249 * @returns IPRT status code.
250 * @param hFTPServer Handle to the FTP server handle.
251 */
252RTR3DECL(int) RTFtpServerDestroy(RTFTPSERVER hFTPServer);
253
254RT_C_DECLS_END
255
256#endif /* !IPRT_INCLUDED_ftp_h */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette