ap_regex.inc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. { Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. }
  16. { Derived from PCRE's pcreposix.h.
  17. Copyright (c) 1997-2004 University of Cambridge
  18. -----------------------------------------------------------------------------
  19. Redistribution and use in source and binary forms, with or without
  20. modification, are permitted provided that the following conditions are met:
  21. * Redistributions of source code must retain the above copyright notice,
  22. this list of conditions and the following disclaimer.
  23. * Redistributions in binary form must reproduce the above copyright
  24. notice, this list of conditions and the following disclaimer in the
  25. documentation and/or other materials provided with the distribution.
  26. * Neither the name of the University of Cambridge nor the names of its
  27. contributors may be used to endorse or promote products derived from
  28. this software without specific prior written permission.
  29. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  30. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  31. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  32. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  33. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  34. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  35. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  36. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  37. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  38. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  39. POSSIBILITY OF SUCH DAMAGE.
  40. -----------------------------------------------------------------------------
  41. }
  42. {
  43. * @file ap_regex.h
  44. * @brief Apache Regex defines
  45. }
  46. //#include "apr.h"
  47. { Options for ap_regexec: }
  48. const
  49. AP_REG_ICASE = $01; { use a case-insensitive match }
  50. AP_REG_NEWLINE = $02; { don't match newlines against '.' etc }
  51. AP_REG_NOTBOL = $04; { ^ will not match against start-of-string }
  52. AP_REG_NOTEOL = $08; { $ will not match against end-of-string }
  53. AP_REG_EXTENDED = (0); { unused }
  54. AP_REG_NOSUB = (0); { unused }
  55. { Error values: }
  56. AP_REG_ASSERT = 1; { internal error ? }
  57. AP_REG_ESPACE = 2; { failed to get memory }
  58. AP_REG_INVARG = 3; { invalid argument }
  59. AP_REG_NOMATCH = 4; { match failed }
  60. { The structure representing a compiled regular expression. }
  61. type
  62. Pap_regex_t = ^ap_regex_t;
  63. ap_regex_t = record
  64. re_pcre: Pointer;
  65. re_nsub: apr_size_t;
  66. re_erroffset: apr_size_t;
  67. end;
  68. { The structure in which a captured offset is returned. }
  69. Pap_regmatch_t = ^ap_regmatch_t;
  70. ap_regmatch_t = record
  71. rm_so: Integer;
  72. rm_eo: Integer;
  73. end;
  74. { The functions }
  75. {
  76. * Compile a regular expression.
  77. * @param preg Returned compiled regex
  78. * @param regex The regular expression string
  79. * @param cflags Must be zero (currently).
  80. * @return Zero on success or non-zero on error
  81. }
  82. function ap_regcomp(preg: Pap_regex_t; const regex: PChar; cflags: Integer): Integer;
  83. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  84. external LibHTTPD name LibNamePrefix + 'ap_regcomp' + LibSuff12;
  85. {
  86. * Match a NUL-terminated string against a pre-compiled regex.
  87. * @param preg The pre-compiled regex
  88. * @param string The string to match
  89. * @param nmatch Provide information regarding the location of any matches
  90. * @param pmatch Provide information regarding the location of any matches
  91. * @param eflags Bitwise OR of any of AP_REG_* flags
  92. * @return 0 for successful match, #REG_NOMATCH otherwise
  93. }
  94. function ap_regexec(const preg: Pap_regex_t; const string_: PChar;
  95. nmatch: apr_size_t; pmatch: Pap_regmatch_t; eflags: Integer): Integer;
  96. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  97. external LibHTTPD name LibNamePrefix + 'ap_regexec' + LibSuff20;
  98. {
  99. * Return the error code returned by regcomp or regexec into error messages
  100. * @param errcode the error code returned by regexec or regcomp
  101. * @param preg The precompiled regex
  102. * @param errbuf A buffer to store the error in
  103. * @param errbuf_size The size of the buffer
  104. }
  105. function ap_regerror(errcord: Integer; const preg: Pap_regex_t;
  106. errbuf: PChar; errbuf_size: apr_size_t): apr_size_t;
  107. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  108. external LibHTTPD name LibNamePrefix + 'ap_regerror' + LibSuff16;
  109. { Destroy a pre-compiled regex.
  110. * @param preg The pre-compiled regex to free.
  111. }
  112. procedure ap_regfree(preg: Pap_regex_t);
  113. {$IFDEF WINDOWS} stdcall; {$ELSE} cdecl; {$ENDIF}
  114. external LibHTTPD name LibNamePrefix + 'ap_regfree' + LibSuff4;