bunkerweb/src/utils/string.h
Théophile Diot e0a89a2fcd Squashed 'src/deps/src/modsecurity/' changes from 205dac0e8..ccc2d9b53
ccc2d9b53 Change release version to v3.0.10
092921d87 Merge pull request #2934 from martinhsv/v3/master
ab5658f2d Fix: worst-case time in implementation of four transformations
3f0971666 CHANGES entry for previous PR
fea6e6d60 Merge pull request #2901 from airween/v3/pcrelimittx
2cb6344bf Merge pull request #2916 from martinhsv/v3/master
f812a3d72 Make MULTIPART_PART_HEADERS accessible to lua
85c876077 Merge pull request #2915 from martinhsv/v3/master
63bbf624d Remove check-static from macos builds
b8e1aedef Fix: Lua scripts cannot read whole collection at once
b84f32d6f Merge pull request #2909 from martinhsv/v3/master
938707d11 Fix: quoted Include config with wildcard
4403a163c Set TX:MSC_PCRE_LIMITS_EXCEEDED variable is limits exceeded
2121938c5 Change some parms to reference-to-const to satisfy cppcheck
da8782ce7 Minor whitespace adjustment
fdeaf17c6 CHANGES entry for previous PR
1ca282a5e Add exclusions due to newer cppcheck version
f8ec87337 github workflow: update macos version to macos-11
09a135baa Merge pull request #2736 from brandonpayton/add-regex-match-limits-and-error-reporting
62bbd7b07 Correction to previous cppcheck suppression adjustment
95c7009b8 Add cppcheck suppressions
1078a7cfa Change some parms from pass-by-value to reference-to-const
8d91a5084 github workflow: toggle pcre2 instead of ssdeep in Ubuntu tests
4fac8d72f Address some constParameter complaints from cppcheck
e9277e199 CHANGES entry for previous PR
4050c840f Merge pull request #2868 from grnet/v3/fix-multimatch-chain
12add9aef Fix meta-actions not being applied if multiMatch is enabled in the chain starter rule
808148ce0 CHANGES entry and cppcheck suppression adjustment for prev PR
5b709d9da Merge pull request #2866 from grnet/v3/fix-multimatch-tags
7ca571952 CHANGES entry for previous PR
7cf0445ad Merge pull request #2870 from airween/v3/multipartpartheaderfix
6623c0ae2 Changed strip methodology to MULTIPART_PART_HEADERS
6fbdee9ff Merge branch 'v3/master' of https://github.com/SpiderLabs/ModSecurity into v3/multipartpartheaderfix
a830ef634 Merge pull request #2894 from martinhsv/v3/master
8d62ac4b0 Configure: use AS_ECHO_N instead echo -n
6fc270e22 Merge pull request #2891 from martinhsv/v3/master
b9eb39af8 Adjust position of memset from 2890
09568351d CHANGES entry for previous PR
5365a17c5 Merge pull request #2846 from tomsommer/patch-1
f8db5fc85 Remove no-longer-needed cppcheck suppressions
a5320add2 Refactoring: remove two unneeded local vars from multipart parser
9ea50a497 Change arg from pass-by-value (satisify cppcheck)
c34bd91a4 CHANGES: Preparing for next version
d875738bd Add PCRE error tests for rx operator
6f1bd27fe Move var into conditional block where used
23a0e2617 Give PCRE error vars initial value
f3d8198b8 Respond to code review feedback
0c42ee229 Switch to simpler PCRE error flags
8c4b7c18e Fix some style issues in regex util header
8c269d31c Update Regex util to support match limits
18adbb6fd Merge branch 'v3/master' of https://github.com/SpiderLabs/ModSecurity into v3/multipartpartheaderfix
0a296af37 Add regression test case
514abeb51 Remove EOL chars from MULTIPART_PART_HEADER variable
d3a6b6a6f Fix tags not being populated in audit log when multiMatch is enabled
3caac9942 Also test empty lines

git-subtree-dir: src/deps/src/modsecurity
git-subtree-split: ccc2d9b53632fb5088673bbaafedf0d8d4b5f1d8
2023-09-15 14:07:48 +02:00

84 lines
4.7 KiB
C++

/*
* ModSecurity, http://www.modsecurity.org/
* Copyright (c) 2015 - 2021 Trustwave Holdings, Inc. (http://www.trustwave.com/)
*
* You may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* If any of the files related to licensing are missing or if you have any
* other questions related to licensing please contact Trustwave Holdings, Inc.
* directly using the email address security@modsecurity.org.
*
*/
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#ifndef SRC_UTILS_STRING_H_
#define SRC_UTILS_STRING_H_
#define VALID_HEX(X) (((X >= '0') && (X <= '9')) || \
((X >= 'a') && (X <= 'f')) || ((X >= 'A') && (X <= 'F')))
#define ISODIGIT(X) ((X >= '0') && (X <= '7'))
#define NBSP 160
namespace modsecurity {
namespace utils {
namespace string {
const char HEX2DEC[256] = {
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
/* 0 */ (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1,
/* 1 */ (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1,
/* 2 */ (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1,
/* 3 */ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1,
/* 4 */ (char)-1, 10, 11, 12, 13, 14, 15, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1,
/* 5 */ (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1,
/* 6 */ (char)-1, 10, 11, 12, 13, 14, 15, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1,
/* 7 */ (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1,
/* 8 */ (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1,
/* 9 */ (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1,
/* A */ (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1,
/* B */ (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1,
/* C */ (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1,
/* D */ (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1,
/* E */ (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1,
/* F */ (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1, (char)-1
};
std::string ascTime(time_t *t);
std::string dash_if_empty(const char *str);
std::string dash_if_empty(const std::string *str);
std::string limitTo(int amount, const std::string &str);
std::string removeBracketsIfNeeded(std::string a);
std::string string_to_hex(const std::string& input);
std::string toHexIfNeeded(const std::string &str, bool escape_spec = false);
std::string tolower(std::string str);
std::string toupper(std::string str);
std::vector<std::string> ssplit(std::string str, char delimiter);
std::pair<std::string, std::string> ssplit_pair(const std::string& str, char delimiter);
std::vector<std::string> split(std::string str, char delimiter);
void chomp(std::string *str);
void replaceAll(std::string *str, const std::string& from,
const std::string& to);
std::string removeWhiteSpacesIfNeeded(std::string a);
std::string parserSanitizer(std::string a);
unsigned char x2c(const unsigned char *what);
unsigned char xsingle2c(const unsigned char *what);
unsigned char *c2x(unsigned what, unsigned char *where);
} // namespace string
} // namespace utils
} // namespace modsecurity
#endif // SRC_UTILS_STRING_H_