1 /**
2  * Copyright (c) 2015, Timothy Stack
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright notice, this
10  * list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  * * Neither the name of Timothy Stack nor the names of its contributors
15  * may be used to endorse or promote products derived from this software
16  * without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY
19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * @file log_search_table.hh
30  */
31 
32 #ifndef lnav_log_search_table_hh
33 #define lnav_log_search_table_hh
34 
35 #include <string>
36 #include <vector>
37 
38 #include "pcrepp/pcrepp.hh"
39 #include "shared_buffer.hh"
40 #include "log_vtab_impl.hh"
41 
42 class log_search_table : public log_vtab_impl {
43 public:
pattern_options()44     static int pattern_options() {
45         return PCRE_CASELESS;
46     }
47 
48     log_search_table(pcrepp pattern, intern_string_t table_name);
49 
50     void get_columns_int(std::vector<vtab_column> &cols);
51 
get_columns(std::vector<vtab_column> & cols) const52     void get_columns(std::vector<vtab_column> &cols) const override {
53         cols = this->lst_cols;
54     }
55 
56     void get_foreign_keys(std::vector<std::string> &keys_inout) const override;
57 
58     bool next(log_cursor &lc, logfile_sub_source &lss) override;
59 
60     void extract(std::shared_ptr<logfile> lf,
61                  uint64_t line_number,
62                  shared_buffer_ref &line,
63                  std::vector<logline_value> &values) override;
64 
65     pcrepp lst_regex;
66     shared_buffer_ref lst_current_line;
67     pcre_context_static<128> lst_match_context;
68     std::vector<logline_value_meta> lst_column_metas;
69     int64_t lst_instance;
70     std::vector<vtab_column> lst_cols;
71 };
72 
73 #endif
74