mirror of
https://github.com/falcosecurity/falco.git
synced 2025-08-29 03:11:02 +00:00
new(userspace/falco): grpc context and stream context
Co-authored-by: Lorenzo Fontana <lo@linux.com> Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
This commit is contained in:
parent
e394bcf119
commit
5d0266a09e
35
userspace/falco/grpc_context.cpp
Normal file
35
userspace/falco/grpc_context.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
Copyright (C) 2016-2019 The Falco Authors
|
||||
|
||||
This file is part of falco.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#include "grpc_context.h"
|
||||
|
||||
context::context(grpc::ServerContext* ctx):
|
||||
m_ctx(ctx)
|
||||
{
|
||||
// todo: set thread-specific prefix "[session id][request id]"
|
||||
}
|
||||
|
||||
void context::get_metadata(std::string key, std::string& val)
|
||||
{
|
||||
const std::multimap<grpc::string_ref, grpc::string_ref>& client_metadata = m_ctx->client_metadata();
|
||||
auto it = client_metadata.find(key);
|
||||
if(it != client_metadata.end())
|
||||
{
|
||||
val.assign(it->second.data(), it->second.size());
|
||||
}
|
||||
}
|
56
userspace/falco/grpc_context.h
Normal file
56
userspace/falco/grpc_context.h
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright (C) 2016-2019 The Falco Authors
|
||||
|
||||
This file is part of falco.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef GRPC_INCLUDE_IS_GRPCPP
|
||||
#include <grpcpp/grpcpp.h>
|
||||
#else
|
||||
#include <grpc++/grpc++.h>
|
||||
#endif
|
||||
|
||||
class context
|
||||
{
|
||||
public:
|
||||
context(grpc::ServerContext* ctx);
|
||||
~context() = default;
|
||||
|
||||
void get_metadata(std::string key, std::string& val);
|
||||
|
||||
private:
|
||||
grpc::ServerContext* m_ctx = nullptr;
|
||||
};
|
||||
|
||||
class stream_context : public context
|
||||
{
|
||||
public:
|
||||
stream_context(grpc::ServerContext* ctx): context(ctx) {}
|
||||
~stream_context() = default;
|
||||
|
||||
private:
|
||||
enum : char
|
||||
{
|
||||
STREAMING = 1,
|
||||
SUCCESS,
|
||||
ERROR
|
||||
} m_status = STREAMING;
|
||||
// Request-specific stream data
|
||||
mutable void* m_stream = nullptr;
|
||||
// Are there more responses to stream?
|
||||
mutable bool m_has_more = false;
|
||||
};
|
Loading…
Reference in New Issue
Block a user