#pragma once #include #include #include "services/file_ops.h" #include "services/storage_service.h" #include "services/wifi_service.h" #include "share_rules.h" namespace roro { // Sharing the SD card with a browser on the same network (issue #88): a small HTTP server with // one page and a few requests behind it: list, download, upload, new folder, delete. It runs only // between start() and stop(), which the Storage App's "Share" screen calls on opening and // closing. Whoever has typed the code that screen shows may use it; nothing is encrypted. // // The server has its own task. Every access to the card is handed to the storage task, a piece // at a time, as everywhere else. class WebShare { public: WebShare(StorageService& storage, FileOps& ops, WifiService& wifi) : storage_(storage), ops_(ops), wifi_(wifi) {} std::string start(); // "" or why it can't void stop(); bool running() const { return server_ != nullptr; } std::string url() const; // http://
/ const std::string& code() const { return auth_.code(); } // For the screen. uint32_t requests() const { return requests_; } uint32_t bytesIn() const { return bytesIn_; } uint32_t bytesOut() const { return bytesOut_; } std::string last() const; // the last thing asked for // Used by the request handlers (web_share.cpp). StorageService& storage() { return storage_; } FileOps& ops() { return ops_; } files::ShareAuth& auth() { return auth_; } void note(const char* what, const std::string& path); void counted(uint32_t in, uint32_t out) { bytesIn_ += in; bytesOut_ += out; } private: StorageService& storage_; FileOps& ops_; WifiService& wifi_; files::ShareAuth auth_; void* server_ = nullptr; // httpd_handle_t std::atomic requests_{0}, bytesIn_{0}, bytesOut_{0}; char last_[56] = ""; }; } // namespace roro