"Fossies" - the Fresh Open Source Software Archive

Member "sysdig-0.26.1/userspace/libsinsp/protodecoder.h" (24 May 2019, 4029 Bytes) of package /linux/misc/sysdig-0.26.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "protodecoder.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2 Copyright (C) 2013-2018 Draios Inc dba Sysdig.
    3 
    4 This file is part of sysdig.
    5 
    6 Licensed under the Apache License, Version 2.0 (the "License");
    7 you may not use this file except in compliance with the License.
    8 You may obtain a copy of the License at
    9 
   10     http://www.apache.org/licenses/LICENSE-2.0
   11 
   12 Unless required by applicable law or agreed to in writing, software
   13 distributed under the License is distributed on an "AS IS" BASIS,
   14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   15 See the License for the specific language governing permissions and
   16 limitations under the License.
   17 
   18 */
   19 
   20 #pragma once
   21 
   22 ///////////////////////////////////////////////////////////////////////////////
   23 // The protocol decoder interface
   24 ///////////////////////////////////////////////////////////////////////////////
   25 class sinsp_protodecoder
   26 {
   27 public:
   28     sinsp_protodecoder();
   29     
   30     virtual ~sinsp_protodecoder()
   31     {
   32     }
   33 
   34     //
   35     // Allocate a new decoder of the same type.
   36     // Every protodecoder plugin must implement this.
   37     //
   38     virtual sinsp_protodecoder* allocate_new() = 0;
   39 
   40     //
   41     // Allocate a new decoder of the same type.
   42     // Every protodecoder plugin must implement this.
   43     //
   44     virtual void init() = 0;
   45 
   46     //
   47     // Return the protocol decoder name
   48     //
   49     const string& get_name()
   50     {
   51         return m_name;
   52     }
   53 
   54     //
   55     // Called by the engine for each of the FDs that are added from proc 
   56     // (or from the file) at the beginning of a capture.
   57     //
   58     virtual void on_fd_from_proc(sinsp_fdinfo_t* fdinfo) = 0;
   59 
   60     //
   61     // Called by the engine after an event has been received and parsed.
   62     //
   63     virtual void on_event(sinsp_evt* evt, sinsp_pd_callback_type etype) = 0;
   64     
   65     //
   66     // These are not part of on_event for performance reasons
   67     //
   68     virtual void on_read(sinsp_evt* evt, char *data, uint32_t len);
   69     virtual void on_write(sinsp_evt* evt, char *data, uint32_t len);
   70     virtual void on_reset(sinsp_evt* evt);
   71 
   72     //
   73     // Used by the engine to retrieve the info line for the last event.
   74     // Must return true if the line is valid.
   75     //
   76     virtual bool get_info_line(char** res) = 0;
   77 
   78 protected:
   79     //
   80     // Interface for the plugins
   81     //
   82     void register_event_callback(sinsp_pd_callback_type etype);
   83     void register_read_callback(sinsp_fdinfo_t* fdinfo);
   84     void register_write_callback(sinsp_fdinfo_t* fdinfo);
   85 
   86     void unregister_read_callback(sinsp_fdinfo_t* fdinfo);
   87     void unregister_write_callback(sinsp_fdinfo_t* fdinfo);
   88 
   89     string m_name;
   90     sinsp* m_inspector;
   91 
   92 private:
   93     void set_inspector(sinsp* inspector);
   94 
   95 friend class sinsp_protodecoder_list;
   96 };
   97 
   98 ///////////////////////////////////////////////////////////////////////////////
   99 // Global class that stores the list of protocol decoders and offers
  100 // functions to work with it.
  101 ///////////////////////////////////////////////////////////////////////////////
  102 class sinsp_protodecoder_list
  103 {
  104 public:
  105     sinsp_protodecoder_list();
  106     ~sinsp_protodecoder_list();
  107     void add_protodecoder(sinsp_protodecoder* protodecoder);
  108     sinsp_protodecoder* new_protodecoder_from_name(const string& name, sinsp* inspector);
  109 
  110 private:
  111     vector<sinsp_protodecoder*> m_decoders_list;
  112 };
  113 
  114 ///////////////////////////////////////////////////////////////////////////////
  115 // Decoder classes
  116 // NOTE: these should be moved to a separate file but, since we have only one
  117 //       for the moment, we keep it here
  118 ///////////////////////////////////////////////////////////////////////////////
  119 class sinsp_decoder_syslog : public sinsp_protodecoder
  120 {
  121 public:
  122     sinsp_decoder_syslog();
  123     sinsp_protodecoder* allocate_new();
  124     void init();
  125     void on_fd_from_proc(sinsp_fdinfo_t* fdinfo);
  126     void on_event(sinsp_evt* evt, sinsp_pd_callback_type etype);
  127     void on_write(sinsp_evt* evt, char *data, uint32_t len);
  128     void on_reset(sinsp_evt* evt);
  129     bool get_info_line(char** res);
  130 
  131     bool is_data_valid();
  132 
  133     const char* get_severity_str();
  134     const char* get_facility_str();
  135 
  136     int32_t m_priority;
  137     uint32_t m_facility;
  138     uint32_t m_severity;
  139     string m_msg;
  140 
  141 private:
  142     void decode_message(char *data, uint32_t len, char* pristr, uint32_t pristrlen);
  143     string m_infostr;
  144 };