LwFTP/LWFTPC/lwftpc.h

94 lines
2.3 KiB
C

/*
* lwftpc.h
*
* Created on: Feb 20, 2024
* Author: "SeungJu Lim"
*/
#include <stdio.h>
#include <string.h>
#include "lwip/api.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef LWFTPC_H_
#define LWFTPC_H_
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 */
};
/** LWFTPC 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;
/** LWFTPC session structure */
typedef struct {
// User interface
ip_addr_t cli_ip;
ip_addr_t svr_ip;
u16_t svr_port;
u16_t data_port;
const char *user;
const char *pass;
// Internal data
lwftp_state_t control_state;
lwftp_state_t data_state;
lwftp_state_t target_state;
struct netconn *conn;
struct netconn *data_conn;
} lwftp_session_t;
/** LWFTPC API prototypes*/
err_t lwftp_send(struct netconn *conn, const char *data);
err_t lwftp_data_open(lwftp_session_t *s, const char *response);
void lwftp_data_thread(void *arg);
void lwftp_ctrl_thread(void *arg);
/** for callback*/
typedef void (*lwftp_transfer_callback)(err_t result, void *context);
void onDataReceived(void* data, size_t size);
err_t lwftp_store(lwftp_session_t *s, const char *filename, const char *data);
err_t lwftp_retrieve(lwftp_session_t *s, const char *filename);
err_t lwftp_list(lwftp_session_t *s);
#ifdef __cplusplus
}
#endif
#endif /* LWFTPC_H_ */