portreg.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. /*
  5. * shexp.h: Defines and prototypes for shell exp. match routines
  6. *
  7. * This routine will match a string with a shell expression. The expressions
  8. * accepted are based loosely on the expressions accepted by zsh.
  9. *
  10. * o * matches anything
  11. * o ? matches one character
  12. * o \ will escape a special character
  13. * o $ matches the end of the string
  14. * Bracketed expressions:
  15. * o [abc] matches one occurence of a, b, or c.
  16. * o [^abc] matches any character except a, b, or c.
  17. * To be matched between [ and ], these characters must be escaped: \ ]
  18. * No other characters need be escaped between brackets.
  19. * Unnecessary escaping is permitted.
  20. * o [a-z] matches any character between a and z, inclusive.
  21. * The two range-definition characters must be alphanumeric ASCII.
  22. * If one is upper case and the other is lower case, then the ASCII
  23. * non-alphanumeric characters between Z and a will also be in range.
  24. * o [^a-z] matches any character except those between a and z, inclusive.
  25. * These forms cannot be combined, e.g [a-gp-z] does not work.
  26. * o Exclusions:
  27. * As a top level, outter-most expression only, the expression
  28. * foo~bar will match the expression foo, provided it does not also
  29. * match the expression bar. Either expression or both may be a union.
  30. * Except between brackets, any unescaped ~ is an exclusion.
  31. * At most one exclusion is permitted.
  32. * Exclusions cannot be nested (contain other exclusions).
  33. * example: *~abc will match any string except abc
  34. * o Unions:
  35. * (foo|bar) will match either the expression foo, or the expression bar.
  36. * At least one '|' separator is required. More are permitted.
  37. * Expressions inside unions may not include unions or exclusions.
  38. * Inside a union, to be matched and not treated as a special character,
  39. * these characters must be escaped: \ ( | ) [ ~ except when they occur
  40. * inside a bracketed expression, where only \ and ] require escaping.
  41. *
  42. * The public interface to these routines is documented below.
  43. *
  44. */
  45. #ifndef SHEXP_H
  46. #define SHEXP_H
  47. #include "utilrename.h"
  48. /*
  49. * Requires that the macro MALLOC be set to a "safe" malloc that will
  50. * exit if no memory is available.
  51. */
  52. /* --------------------------- Public routines ---------------------------- */
  53. /*
  54. * shexp_valid takes a shell expression exp as input. It returns:
  55. *
  56. * NON_SXP if exp is a standard string
  57. * INVALID_SXP if exp is a shell expression, but invalid
  58. * VALID_SXP if exp is a valid shell expression
  59. */
  60. #define NON_SXP -1
  61. #define INVALID_SXP -2
  62. #define VALID_SXP 1
  63. SEC_BEGIN_PROTOS
  64. extern int PORT_RegExpValid(const char *exp);
  65. extern int PORT_RegExpSearch(const char *str, const char *exp);
  66. /* same as above but uses case insensitive search */
  67. extern int PORT_RegExpCaseSearch(const char *str, const char *exp);
  68. SEC_END_PROTOS
  69. #endif