libclamav/regex_pcre.h
5fa73369
 /*
  *  Support for PCRE regex variant
  *
e1cbc270
  *  Copyright (C) 2013-2019 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
5fa73369
  *  Copyright (C) 2007-2013 Sourcefire, Inc.
  *
  *  Authors: Kevin Lin
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2 as
  *  published by the Free Software Foundation.
  *
  *  This program is distributed in the hope that it will be useful,
  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  *  MA 02110-1301, USA.
  */
 
 #ifndef _REGEX_PCRE_H_
 #define _REGEX_PCRE_H_
 
 #if HAVE_CONFIG_H
 #include "clamav-config.h"
 #endif
df3e211a
 #if HAVE_PCRE
5fa73369
 
5841080a
 #if USING_PCRE2
 #define PCRE2_CODE_UNIT_WIDTH 8
 #include <pcre2.h>
 #else
5fa73369
 #include <pcre.h>
5841080a
 #endif
5fa73369
 
e030ba4f
 #include "clamav-types.h"
5fa73369
 #include "mpool.h"
 
e33697ef
 /* used for setting overrides */
 #define CLI_PCREMATCH_NOOFFSETOVERRIDE -1
f40a96fb
 /* must be multiple of 3 */
 #define OVECCOUNT 300
5fa73369
 
5841080a
 #if USING_PCRE2
 struct cli_pcre_data {
288057e9
     pcre2_code *re;            /* compiled pcre regex */
     pcre2_match_context *mctx; /* match context */
     int options;               /* pcre options */
     char *expression;          /* copied regular expression */
     uint32_t search_offset;    /* start offset to search at for pcre_exec */
5841080a
 };
 
 struct cli_pcre_results {
     int err;
     uint32_t match[2]; /* populated by cli_pcre_match to be start (0) and end (1) offset of match */
 
     pcre2_match_data *match_data;
 };
 #else
5fa73369
 struct cli_pcre_data {
     pcre *re;               /* compiled pcre regex */
     pcre_extra *ex;         /* pcre extra data - limits */
     int options;            /* pcre options */
     char *expression;       /* copied regular expression */
     uint32_t search_offset; /* start offset to search at for pcre_exec */
 };
 
5841080a
 struct cli_pcre_results {
     int err;
     uint32_t match[2]; /* populated by cli_pcre_match to be start (0) and end (1) offset of match */
 
     int ovector[OVECCOUNT];
 };
 #endif
 
102cd430
 cl_error_t cli_pcre_init_internal();
 cl_error_t cli_pcre_addoptions(struct cli_pcre_data *pd, const char **opt, int errout);
 cl_error_t cli_pcre_compile(struct cli_pcre_data *pd, long long unsigned match_limit, long long unsigned match_limit_recursion, unsigned int options, int opt_override);
f9ac6811
 int cli_pcre_match(struct cli_pcre_data *pd, const unsigned char *buffer, size_t buflen, size_t override_offset, int options, struct cli_pcre_results *results);
 void cli_pcre_report(const struct cli_pcre_data *pd, const unsigned char *buffer, size_t buflen, int rc, struct cli_pcre_results *results);
5841080a
 
102cd430
 cl_error_t cli_pcre_results_reset(struct cli_pcre_results *results, const struct cli_pcre_data *pd);
5841080a
 void cli_pcre_results_free(struct cli_pcre_results *results);
5fa73369
 void cli_pcre_free_single(struct cli_pcre_data *pd);
7afaa9bd
 #endif /* HAVE_PCRE */
9bc7c138
 #endif /*_REGEX_PCRE_H_*/