summaryrefslogtreecommitdiff
path: root/src/state/activating_state.hpp
blob: bd1688f67d1491afc8bef4f5db681e4a2890ddfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once

#include "basic_state.hpp"

struct ActivatingState : public BasicStateT<ActivatingState>
{
    static std::string_view stateName()
    {
        return "ActivatingState";
    }

    ActivatingState(interfaces::MountPointStateMachine& machine);

    std::unique_ptr<BasicState> onEnter() override;

    std::unique_ptr<BasicState> handleEvent(UdevStateChangeEvent event);
    std::unique_ptr<BasicState> handleEvent(SubprocessStoppedEvent event);

    template <class AnyEvent>
    std::unique_ptr<BasicState> handleEvent(AnyEvent event)
    {
        LogMsg(Logger::Error, "Invalid event: ", event.eventName);
        return nullptr;
    }

  private:
    std::unique_ptr<BasicState> activateProxyMode();
    std::unique_ptr<BasicState> activateLegacyMode();
    std::unique_ptr<BasicState> mountSmbShare();
    std::unique_ptr<BasicState> mountHttpsShare();

    static std::unique_ptr<resource::Process>
        spawnNbdKit(interfaces::MountPointStateMachine& machine,
                    std::unique_ptr<utils::VolatileFile>&& secret,
                    const std::vector<std::string>& params);
    static std::unique_ptr<resource::Process>
        spawnNbdKit(interfaces::MountPointStateMachine& machine,
                    const fs::path& file);
    static std::unique_ptr<resource::Process>
        spawnNbdKit(interfaces::MountPointStateMachine& machine,
                    const std::string& url);

    static bool checkUrl(const std::string& urlScheme,
                         const std::string& imageUrl);
    static bool getImagePathFromUrl(const std::string& urlScheme,
                                    const std::string& imageUrl,
                                    std::string* imagePath);
    static bool isHttpsUrl(const std::string& imageUrl);
    static bool getImagePathFromHttpsUrl(const std::string& imageUrl,
                                         std::string* imagePath);

    static bool isCifsUrl(const std::string& imageUrl);
    static bool getImagePathFromCifsUrl(const std::string& imageUrl,
                                        std::string* imagePath);
    static fs::path getImagePath(const std::string& imageUrl);

    std::unique_ptr<resource::Process> process;
    std::unique_ptr<resource::Gadget> gadget;
};