Skip to content

Commit

Permalink
add FTP client (#291)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
matth-x authored May 3, 2024
1 parent abe44ba commit b99f1c2
Show file tree
Hide file tree
Showing 9 changed files with 1,074 additions and 9 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ set(MO_SRC
src/MicroOcpp/Core/ConfigurationKeyValue.cpp
src/MicroOcpp/Core/FilesystemAdapter.cpp
src/MicroOcpp/Core/FilesystemUtils.cpp
src/MicroOcpp/Core/FtpMbedTLS.cpp
src/MicroOcpp/Core/RequestQueue.cpp
src/MicroOcpp/Core/Context.cpp
src/MicroOcpp/Core/Operation.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/MicroOcpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ void mocpp_initialize(Connection& connection, const char *bootNotificationCreden
if (certStore) {
certStoreUse = std::move(certStore);
}
#if MO_ENABLE_MBEDTLS
#if MO_ENABLE_MBEDTLS && MO_ENABLE_CERT_STORE_MBEDTLS
else {
certStoreUse = makeCertificateStoreMbedTLS(filesystem);
}
Expand Down
86 changes: 86 additions & 0 deletions src/MicroOcpp/Core/Ftp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// matth-x/MicroOcpp
// Copyright Matthias Akstaller 2019 - 2024
// MIT License

#ifndef MO_FTP_H
#define MO_FTP_H

#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct ocpp_ftp_download {
void *user_data; //set this at your choice. MO passes it back to the functions below

void (*loop)(void *user_data);
} ocpp_ftp_download;

typedef struct ocpp_ftp_upload {
void *user_data; //set this at your choice. MO passes it back to the functions below

void (*loop)(void *user_data);
} ocpp_ftp_upload;

typedef struct ocpp_ftp_client {
void *user_data; //set this at your choice. MO passes it back to the functions below

void (*loop)(void *user_data);

ocpp_ftp_download* (*get_file)(void *user_data,
const char *ftp_url, // ftp[s]://[user[:pass]@]host[:port][/directory]/filename
size_t (*file_writer)(void *mo_data, unsigned char *data, size_t len),
void (*on_close)(void *mo_data),
void *mo_data,
const char *ca_cert); // nullptr to disable cert check; will be ignored for non-TLS connections

void (*get_file_free)(void *user_data, ocpp_ftp_download*);

ocpp_ftp_upload* (*post_file)(void *user_data,
const char *ftp_url, // ftp[s]://[user[:pass]@]host[:port][/directory]/filename
size_t (*file_reader)(void *mo_data, unsigned char *buf, size_t bufsize),
void (*on_close)(void *mo_data),
void *mo_data,
const char *ca_cert); // nullptr to disable cert check; will be ignored for non-TLS connections

void (*post_file_free)(void *user_data, ocpp_ftp_upload*);
} ocpp_ftp_client;

#ifdef __cplusplus
} //extern "C"

#include <memory>
#include <functional>

namespace MicroOcpp {

class FtpDownload {
public:
virtual void loop() = 0;
};

class FtpUpload {
public:
virtual void loop() = 0;
};

class FtpClient {
public:

virtual std::unique_ptr<FtpDownload> getFile(
const char *ftp_url, // ftp[s]://[user[:pass]@]host[:port][/directory]/filename
std::function<size_t(unsigned char *data, size_t len)> fileWriter,
std::function<void()> onClose,
const char *ca_cert = nullptr) = 0; // nullptr to disable cert check; will be ignored for non-TLS connections

virtual std::unique_ptr<FtpUpload> postFile(
const char *ftp_url, // ftp[s]://[user[:pass]@]host[:port][/directory]/filename
std::function<size_t(unsigned char *out, size_t buffsize)> fileReader, //write at most buffsize bytes into out-buffer. Return number of bytes written
std::function<void()> onClose,
const char *ca_cert = nullptr) = 0; // nullptr to disable cert check; will be ignored for non-TLS connections
};

} // namespace MicroOcpp
#endif //def __cplusplus
#endif
Loading

0 comments on commit b99f1c2

Please sign in to comment.