"Fossies" - the Fresh Open Source Software Archive

Member "openlitespeed-1.6.6/src/util/aho.h" (22 Jan 2020, 2756 Bytes) of package /linux/www/openlitespeed-1.6.6.src.tgz:


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 "aho.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.6.5_vs_1.6.6.

    1 /*****************************************************************************
    2 *    Open LiteSpeed is an open source HTTP server.                           *
    3 *    Copyright (C) 2013 - 2020  LiteSpeed Technologies, Inc.                 *
    4 *                                                                            *
    5 *    This program is free software: you can redistribute it and/or modify    *
    6 *    it under the terms of the GNU General Public License as published by    *
    7 *    the Free Software Foundation, either version 3 of the License, or       *
    8 *    (at your option) any later version.                                     *
    9 *                                                                            *
   10 *    This program is distributed in the hope that it will be useful,         *
   11 *    but WITHOUT ANY WARRANTY; without even the implied warranty of          *
   12 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the            *
   13 *    GNU General Public License for more details.                            *
   14 *                                                                            *
   15 *    You should have received a copy of the GNU General Public License       *
   16 *    along with this program. If not, see http://www.gnu.org/licenses/.      *
   17 *****************************************************************************/
   18 #ifndef AHO_H
   19 #define AHO_H
   20 
   21 #include <lsr/ls_aho.h>
   22 
   23 #include <stdio.h>
   24 #include <string.h>
   25 #include <ctype.h>
   26 #include <stdlib.h>
   27 
   28 
   29 
   30 #define MAX_STRING_LEN 8192
   31 #define MAX_FIRST_CHARS 256
   32 
   33 
   34 
   35 typedef ls_aho_state_t AhoState;
   36 typedef ls_aho_state_t ac_state_t;
   37 typedef struct ls_aho_s  ls_aho_t;
   38 
   39 class Aho : private ls_aho_t
   40 {
   41 private:
   42     Aho(const Aho &rhs);
   43     void operator=(const Aho &rhs);
   44 public:
   45     Aho(int case_insensitive)
   46     {   ls_aho(this, case_insensitive);    }
   47 
   48     ~Aho()
   49     {   ls_aho_d(this);  }
   50 
   51     AhoState *getZeroState()
   52     {   return zero_state;    }
   53 
   54     int addPattern(const char *pattern, size_t size, void *ctx)
   55     {   return ls_aho_addpattern(this, pattern, size, ctx);   }
   56 
   57     int addPatternsFromFile(const char *filename)
   58     {   return ls_aho_addfromfile(this, filename);    }
   59 
   60     int makeTree()
   61     {   return ls_aho_maketree(this, 1);   }
   62 
   63     int optimizeTree()
   64     {   return ls_aho_optimizetree(this);    }
   65 
   66     /* search for matches in an aho corasick tree. */
   67     unsigned int search(AhoState *start_state, const char *string, size_t size,
   68                         size_t startpos, size_t *out_start, size_t *out_end, 
   69                         AhoState **out_last_state, void **pattern_ctx)
   70     {
   71         return ls_aho_search(this, start_state, string, size, startpos,
   72                              out_start, out_end, out_last_state, pattern_ctx);
   73     }
   74 };
   75 
   76 #endif