Skip to content

Commit b99f1c2

Browse files
authored
add FTP client (#291)
* migrate FTP from matth-x/MicroFtp * fix compilation errors * add extra switch or certs store * fix disable MbedTLS by default * add FTP client to CMakeLists * add FTP client to CMakeLists II
1 parent abe44ba commit b99f1c2

File tree

9 files changed

+1074
-9
lines changed

9 files changed

+1074
-9
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ set(MO_SRC
1313
src/MicroOcpp/Core/ConfigurationKeyValue.cpp
1414
src/MicroOcpp/Core/FilesystemAdapter.cpp
1515
src/MicroOcpp/Core/FilesystemUtils.cpp
16+
src/MicroOcpp/Core/FtpMbedTLS.cpp
1617
src/MicroOcpp/Core/RequestQueue.cpp
1718
src/MicroOcpp/Core/Context.cpp
1819
src/MicroOcpp/Core/Operation.cpp

src/MicroOcpp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ void mocpp_initialize(Connection& connection, const char *bootNotificationCreden
313313
if (certStore) {
314314
certStoreUse = std::move(certStore);
315315
}
316-
#if MO_ENABLE_MBEDTLS
316+
#if MO_ENABLE_MBEDTLS && MO_ENABLE_CERT_STORE_MBEDTLS
317317
else {
318318
certStoreUse = makeCertificateStoreMbedTLS(filesystem);
319319
}

src/MicroOcpp/Core/Ftp.h

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// matth-x/MicroOcpp
2+
// Copyright Matthias Akstaller 2019 - 2024
3+
// MIT License
4+
5+
#ifndef MO_FTP_H
6+
#define MO_FTP_H
7+
8+
#include <stddef.h>
9+
10+
#ifdef __cplusplus
11+
extern "C" {
12+
#endif
13+
14+
typedef struct ocpp_ftp_download {
15+
void *user_data; //set this at your choice. MO passes it back to the functions below
16+
17+
void (*loop)(void *user_data);
18+
} ocpp_ftp_download;
19+
20+
typedef struct ocpp_ftp_upload {
21+
void *user_data; //set this at your choice. MO passes it back to the functions below
22+
23+
void (*loop)(void *user_data);
24+
} ocpp_ftp_upload;
25+
26+
typedef struct ocpp_ftp_client {
27+
void *user_data; //set this at your choice. MO passes it back to the functions below
28+
29+
void (*loop)(void *user_data);
30+
31+
ocpp_ftp_download* (*get_file)(void *user_data,
32+
const char *ftp_url, // ftp[s]://[user[:pass]@]host[:port][/directory]/filename
33+
size_t (*file_writer)(void *mo_data, unsigned char *data, size_t len),
34+
void (*on_close)(void *mo_data),
35+
void *mo_data,
36+
const char *ca_cert); // nullptr to disable cert check; will be ignored for non-TLS connections
37+
38+
void (*get_file_free)(void *user_data, ocpp_ftp_download*);
39+
40+
ocpp_ftp_upload* (*post_file)(void *user_data,
41+
const char *ftp_url, // ftp[s]://[user[:pass]@]host[:port][/directory]/filename
42+
size_t (*file_reader)(void *mo_data, unsigned char *buf, size_t bufsize),
43+
void (*on_close)(void *mo_data),
44+
void *mo_data,
45+
const char *ca_cert); // nullptr to disable cert check; will be ignored for non-TLS connections
46+
47+
void (*post_file_free)(void *user_data, ocpp_ftp_upload*);
48+
} ocpp_ftp_client;
49+
50+
#ifdef __cplusplus
51+
} //extern "C"
52+
53+
#include <memory>
54+
#include <functional>
55+
56+
namespace MicroOcpp {
57+
58+
class FtpDownload {
59+
public:
60+
virtual void loop() = 0;
61+
};
62+
63+
class FtpUpload {
64+
public:
65+
virtual void loop() = 0;
66+
};
67+
68+
class FtpClient {
69+
public:
70+
71+
virtual std::unique_ptr<FtpDownload> getFile(
72+
const char *ftp_url, // ftp[s]://[user[:pass]@]host[:port][/directory]/filename
73+
std::function<size_t(unsigned char *data, size_t len)> fileWriter,
74+
std::function<void()> onClose,
75+
const char *ca_cert = nullptr) = 0; // nullptr to disable cert check; will be ignored for non-TLS connections
76+
77+
virtual std::unique_ptr<FtpUpload> postFile(
78+
const char *ftp_url, // ftp[s]://[user[:pass]@]host[:port][/directory]/filename
79+
std::function<size_t(unsigned char *out, size_t buffsize)> fileReader, //write at most buffsize bytes into out-buffer. Return number of bytes written
80+
std::function<void()> onClose,
81+
const char *ca_cert = nullptr) = 0; // nullptr to disable cert check; will be ignored for non-TLS connections
82+
};
83+
84+
} // namespace MicroOcpp
85+
#endif //def __cplusplus
86+
#endif

0 commit comments

Comments
 (0)