From 203a7732f5fafb5f9b7e8564bd3bd4587e168134 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 7 Apr 2014 21:25:44 +0100 Subject: Add support for querying client environement variables At connection, a remote client sends all its environement to the server, which then provides access to client env through kak_client_env_VAR_NAME variables in the shell. --- src/remote.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/remote.cc') diff --git a/src/remote.cc b/src/remote.cc index 2d71a888..72e3425f 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -74,6 +74,17 @@ public: write(memoryview(vec)); } + template + void write(const std::unordered_map& map) + { + write(map.size()); + for (auto& val : map) + { + write(val.first); + write(val.second); + } + } + void write(Color color) { write(color.color); @@ -210,6 +221,20 @@ DisplayBuffer read(int socket) return db; } +template +std::unordered_map read_map(int socket) +{ + uint32_t size = read(socket); + std::unordered_map res; + while (size--) + { + auto key = read(socket); + auto val = read(socket); + res.insert({std::move(key), std::move(val)}); + } + return res; +} + class RemoteUI : public UserInterface { public: @@ -368,12 +393,15 @@ void RemoteUI::set_input_callback(InputCallback callback) } RemoteClient::RemoteClient(int socket, std::unique_ptr&& ui, + const EnvVarMap& env_vars, const String& init_command) : m_ui(std::move(ui)), m_dimensions(m_ui->dimensions()), m_socket_watcher{socket, [this](FDWatcher&){ process_next_message(); }} { Message msg(socket); msg.write(init_command.c_str(), (int)init_command.length()+1); + msg.write(env_vars); + Key key{ resize_modifier, Codepoint(((int)m_dimensions.line << 16) | (int)m_dimensions.column) }; msg.write(key); @@ -446,6 +474,7 @@ void RemoteClient::write_next_key() std::unique_ptr connect_to(const String& session, std::unique_ptr&& ui, + const EnvVarMap& env_vars, const String& init_command) { auto filename = "/tmp/kak-" + session; @@ -459,6 +488,7 @@ std::unique_ptr connect_to(const String& session, throw connection_failed(filename); return std::unique_ptr{new RemoteClient{sock, std::move(ui), + env_vars, init_command}}; } @@ -525,8 +555,10 @@ private: } if (c == 0) // end of initial command stream, go to interactive ui { + EnvVarMap env_vars = read_map(socket); std::unique_ptr ui{new RemoteUI{socket}}; ClientManager::instance().create_client(std::move(ui), + std::move(env_vars), m_buffer); Server::instance().remove_accepter(this); return; -- cgit v1.2.3