forked from gezedo/lwftp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lwftp.h
109 lines (100 loc) · 3.59 KB
/
lwftp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* lwftp.h : a lightweight FTP client using raw API of LWIP
*
* Copyright (c) 2014 GEZEDO
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* Author: Laurent GONZALEZ <lwip@gezedo.com>
*
*/
#ifndef LWFTP_H
#define LWFTP_H
#include "lwip/opt.h"
#include "lwip/ip.h"
#ifdef __cplusplus
extern "C" {
#endif
enum lwftp_results {
LWFTP_RESULT_OK=0,
LWFTP_RESULT_INPROGRESS,
LWFTP_RESULT_LOGGED,
LWFTP_RESULT_ERR_UNKNOWN, /** Unknown error */
LWFTP_RESULT_ERR_ARGUMENT, /** Wrong argument */
LWFTP_RESULT_ERR_MEMORY, /** Out of memory */
LWFTP_RESULT_ERR_CONNECT, /** Connection to server failed */
LWFTP_RESULT_ERR_HOSTNAME, /** Failed to resolve server hostname */
LWFTP_RESULT_ERR_CLOSED, /** Connection unexpectedly closed by remote server */
LWFTP_RESULT_ERR_TIMEOUT, /** Connection timed out (server didn't respond in time) */
LWFTP_RESULT_ERR_SRVR_RESP, /** Server responded with an unknown response code */
LWFTP_RESULT_ERR_INTERNAL, /** Internal network stack error */
LWFTP_RESULT_ERR_LOCAL, /** Local storage error */
LWFTP_RESULT_ERR_FILENAME /** Remote host could not find file */
};
/** LWFTP control connection state */
typedef enum {
LWFTP_CLOSED=0,
LWFTP_CONNECTED,
LWFTP_USER_SENT,
LWFTP_PASS_SENT,
LWFTP_LOGGED,
LWFTP_TYPE_SENT,
LWFTP_PASV_SENT,
LWFTP_RETR_SENT,
LWFTP_STOR_SENT,
LWFTP_XFERING,
LWFTP_DATAEND,
LWFTP_QUIT,
LWFTP_QUIT_SENT,
LWFTP_CLOSING,
} lwftp_state_t;
/** LWFTP session structure */
typedef struct {
// User interface
ip_addr_t server_ip;
u16_t server_port;
const char *remote_path;
const char *user;
const char *pass;
void *handle;
uint (*data_source)(void*, const char**, uint);
uint (*data_sink)(void*, const char*, uint);
void (*done_fn)(void*, int);
uint timeout;
// Internal data
lwftp_state_t control_state;
lwftp_state_t target_state;
lwftp_state_t data_state;
struct tcp_pcb *control_pcb;
struct tcp_pcb *data_pcb;
} lwftp_session_t;
// LWFTP API
err_t lwftp_connect(lwftp_session_t *s);
err_t lwftp_store(lwftp_session_t *s);
err_t lwftp_retrieve(lwftp_session_t *s);
void lwftp_close(lwftp_session_t *s);
#ifdef __cplusplus
}
#endif
#endif // LWFTP_H