|
| 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