Blame apache2/acmp.h

Packit 284210
/*
Packit 284210
* ModSecurity for Apache 2.x, http://www.modsecurity.org/
Packit 284210
* Copyright (c) 2004-2013 Trustwave Holdings, Inc. (http://www.trustwave.com/)
Packit 284210
*
Packit 284210
* You may not use this file except in compliance with
Packit 284210
* the License.  You may obtain a copy of the License at
Packit 284210
*
Packit 284210
*     http://www.apache.org/licenses/LICENSE-2.0
Packit 284210
*
Packit 284210
* If any of the files related to licensing are missing or if you have any
Packit 284210
* other questions related to licensing please contact Trustwave Holdings, Inc.
Packit 284210
* directly using the email address security@modsecurity.org.
Packit 284210
*/
Packit 284210
Packit 284210
#ifndef ACMP_H_
Packit 284210
#define ACMP_H_
Packit 284210
Packit 284210
#include <apr.h>
Packit 284210
#include <apr_pools.h>
Packit 284210
Packit 284210
#define ACMP_FLAG_BYTE               0
Packit 284210
#define ACMP_FLAG_CASE_SENSITIVE     1
Packit 284210
#define ACMP_FLAG_CASE_INSENSITIVE   0
Packit 284210
#ifdef ACMP_USE_UTF8
Packit 284210
#define ACMP_FLAG_UTF8               0x100
Packit 284210
#endif
Packit 284210
Packit 284210
/**
Packit 284210
 * Opaque struct with parser data
Packit 284210
 */
Packit 284210
typedef struct ACMP ACMP;
Packit 284210
Packit 284210
/**
Packit 284210
 * Used to separate state from the trie for acmp_process_quick function
Packit 284210
 */
Packit 284210
typedef struct {
Packit 284210
    ACMP *parser;
Packit 284210
    void *ptr;
Packit 284210
} ACMPT;
Packit 284210
Packit 284210
/**
Packit 284210
 * Callback function. Arguments are:
Packit 284210
 * ACMP * - acmp parser that initiated callback
Packit 284210
 * void * - custom data you supplied when adding callback
Packit 284210
 * apr_size_t - position in bytes where pattern was found
Packit 284210
 * apr_size_t - position in chars where pattern was found, for multibyte strings
Packit 284210
 */
Packit 284210
typedef void (*acmp_callback_t)(ACMP *, void *, apr_size_t, apr_size_t);
Packit 284210
Packit 284210
/**
Packit 284210
 * flags - OR-ed values of ACMP_FLAG constants
Packit 284210
 * pool  - apr_pool to use as parent pool, can be set to NULL
Packit 284210
 */
Packit 284210
ACMP *acmp_create(int flags, apr_pool_t *pool);
Packit 284210
Packit 284210
/**
Packit 284210
 * Destroys previously created parser
Packit 284210
 */
Packit 284210
void acmp_destroy(ACMP *parser);
Packit 284210
Packit 284210
/**
Packit 284210
 * Creates parser with same options and same patterns
Packit 284210
 * parser - ACMP parser to duplicate
Packit 284210
 * pool - parent pool to use, if left as NULL original parser's parent pool is used
Packit 284210
 */
Packit 284210
ACMP *acmp_duplicate(ACMP *parser, apr_pool_t *pool);
Packit 284210
Packit 284210
/**
Packit 284210
 * Adds pattern to parser. Cannot be done after starting the search.
Packit 284210
 * parser - ACMP parser
Packit 284210
 * pattern - string with pattern to match
Packit 284210
 * callback - Optional, pointer to an acmp_callback_t function
Packit 284210
 * data - pointer to data that will be passed to callback function, only used if callback
Packit 284210
 *   is supplied
Packit 284210
 * len - Length of pattern in characters, if zero string length is used.
Packit 284210
 */
Packit 284210
apr_status_t acmp_add_pattern(ACMP *parser, const char *pattern,
Packit 284210
    acmp_callback_t callback, void *data, apr_size_t len);
Packit 284210
Packit 284210
/**
Packit 284210
 * Called to process incoming data stream. You must call acmp_done after sending
Packit 284210
 *   last data packet
Packit 284210
 *
Packit 284210
 * data - ptr to incoming data
Packit 284210
 * len  - size of data in bytes
Packit 284210
 */
Packit 284210
apr_status_t acmp_process(ACMP *parser, const char *data, apr_size_t len);
Packit 284210
Packit 284210
/**
Packit 284210
 * Returns number of matches on all patterns combined
Packit 284210
 */
Packit 284210
apr_size_t acmp_match_count_total(ACMP *parser);
Packit 284210
Packit 284210
/**
Packit 284210
 * Returns number of matches for given pattern
Packit 284210
 */
Packit 284210
apr_size_t acmp_match_count(ACMP *parser, const char *pattern);
Packit 284210
Packit 284210
/**
Packit 284210
 * Resets the state of parser so you can start using it with new set of data,
Packit 284210
 * or add new patterns.
Packit 284210
 */
Packit 284210
void acmp_reset(ACMP *parser);
Packit 284210
Packit 284210
/**
Packit 284210
 * Creates an ACMPT struct that will use parser's tree, without duplicating its data
Packit 284210
 */
Packit 284210
ACMPT *acmp_duplicate_quick(ACMP *parser, apr_pool_t *pool);
Packit 284210
Packit 284210
/**
Packit 284210
 * Process the data using ACMPT to keep state, and ACMPT's parser to keep the tree
Packit 284210
 */
Packit 284210
apr_status_t acmp_process_quick(ACMPT *acmpt, const char **match, const char *data, apr_size_t len);
Packit 284210
Packit 284210
/**
Packit 284210
 * Prepares parser for searching
Packit 284210
 */
Packit 284210
apr_status_t acmp_prepare(ACMP *parser);
Packit 284210
Packit 284210
Packit 284210
#endif /*ACMP_H_*/