-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathssh_plugin.h
80 lines (62 loc) · 2.5 KB
/
ssh_plugin.h
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2012 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SSH_PLUGIN_H
#define SSH_PLUGIN_H
#include <string>
#include <map>
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/var.h"
#include "ppapi/cpp/var_array.h"
#include "ppapi/cpp/var_dictionary.h"
#include "pthread_helpers.h"
#include "file_system.h"
class SshPluginInstance : public pp::Instance,
public OutputInterface {
public:
explicit SshPluginInstance(PP_Instance instance);
virtual ~SshPluginInstance();
virtual void HandleMessage(const pp::Var& message_data);
static SshPluginInstance* GetInstance() { return instance_; }
pp::Core* core() { return core_; }
pthread_t openssh_thread() { return openssh_thread_; }
// Implements OutputInterface.
virtual bool OpenFile(int fd, const char* name, int mode,
InputInterface* stream);
virtual bool OpenSocket(int fd, const char* host, uint16_t port,
InputInterface* stream);
virtual bool Write(int fd, const char* data, size_t size);
virtual bool Read(int fd, size_t size);
virtual bool Close(int fd);
virtual void ReadPass(const char* prompt, size_t size, bool echo);
virtual size_t GetWriteWindow();
virtual void SendExitCode(int error);
private:
typedef std::map<int, InputInterface*> InputStreams;
void StartSession(const pp::VarArray& args);
void OnOpen(const pp::VarArray& args);
void OnRead(const pp::VarArray& args);
void OnWriteAcknowledge(const pp::VarArray& args);
void OnClose(const pp::VarArray& args);
void OnReadReady(const pp::VarArray& args);
void OnResize(const pp::VarArray& args);
void OnExitAcknowledge(const pp::VarArray& args);
void OnReadPass(const pp::VarArray& args);
void SessionThreadImpl();
static void* SessionThread(void* arg);
void Invoke(const std::string& function, const pp::VarArray& args);
void InvokeJS(const std::string& function, const pp::VarArray& args);
void PrintLog(const std::string& msg);
void PrintLogImpl(int32_t result, const std::string& msg);
void SendExitCodeImpl(int32_t result, int error);
static SshPluginInstance* instance_;
pp::Core* core_;
pthread_t openssh_thread_;
pp::VarDictionary session_args_;
pp::CompletionCallbackFactory<SshPluginInstance> factory_;
InputStreams streams_;
FileSystem file_system_;
DISALLOW_COPY_AND_ASSIGN(SshPluginInstance);
};
#endif // SSH_PLUGIN_H