PageRenderTime 58ms CodeModel.GetById 5ms RepoModel.GetById 1ms app.codeStats 0ms

/amanda/trunk/common-src/match.h

#
C Header | 147 lines | 19 code | 34 blank | 94 comment | 0 complexity | 07e3f927dd7343b86bac741e4a119614 MD5 | raw file
  1. /*
  2. * Copyright (c) 2010 Zmanda, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License version 2 as published
  6. * by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. * for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. *
  17. * Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
  18. * Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
  19. */
  20. #ifndef MATCH_H
  21. #define MATCH_H
  22. #include <glib.h>
  23. /*
  24. * Regular expressions
  25. */
  26. /* The regular expressions used here are POSIX extended regular expressions;
  27. * see http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap09.html
  28. */
  29. /* validate that REGEX is a valid POSIX regular expression by calling regcomp.
  30. * Returns a statically allocated error message on failure or NULL on success. */
  31. char * validate_regexp(const char *regex);
  32. /*
  33. * Match the string "str" against POSIX regex "regex" with regexec(), with
  34. * REG_NEWLINE set (match_newline == TRUE) or not.
  35. *
  36. * REG_NEWLINE means two things:
  37. * - the dot won't match a newline;
  38. * - ^ and $ will match around \n in the input string (as well as the beginning
  39. * and end of the input).
  40. */
  41. int do_match(const char *regex, const char *str, gboolean match_newline);
  42. #define match(regex, str) do_match(regex, str, TRUE)
  43. #define match_no_newline(regex, str) do_match(regex, str, FALSE)
  44. /*
  45. * Cleanup a regular expression by escaping all non alphanumeric characters, and
  46. * append beginning/end anchors if need be. Returns a dynamically allocated
  47. * string. It is the caller's responsibility to g_free() that string.
  48. *
  49. * @param str: the regular expression string
  50. * @param anchor: if true, the regex will be anchored at the beginning/end
  51. * (resp. with ^ and $)
  52. * @returns: the resulting regex
  53. */
  54. char *clean_regex(const char *str, gboolean anchor);
  55. /*
  56. * Globs
  57. */
  58. /*
  59. * A "glob expression" is similar to shell globs; it supports metacharacters
  60. * "*" and "?", as well as character classes like "[...]" and "[!...]"
  61. * (negated). The "*" and "?" do not match filename separators ("/"). The
  62. * entire expression is anchored, so it must match the string, not just a single
  63. * filename component.
  64. */
  65. /* Validate that GLOB is a legal GLOB expression. Returns a statically
  66. * allocated error message on failure, or NULL on success. */
  67. char * validate_glob(const char *glob);
  68. /* Convert a GLOB expression into a dynamically allocated regular expression */
  69. char * glob_to_regex(const char *glob);
  70. /* Like match(), but with a glob expression */
  71. int match_glob(const char *glob, const char *str);
  72. /*
  73. * Tar Patterns
  74. */
  75. /* A "tar expression" is almost the same as a glob, except that "*" can match a
  76. * filename separator ("?" cannot). It is used by calcsize to emulate tar's exclude
  77. * list patterns, which are actually significantly more complicated than this.
  78. */
  79. /* Like match(), but with a tar expression */
  80. int match_tar(const char *glob, const char *str);
  81. /*
  82. * Host expressions
  83. */
  84. /* Host expressions are described in amanda(8). */
  85. /* Make an Amanda host expression that will match the given string exactly.
  86. * There is a little bit of fuzz here involving leading and trailing "."
  87. * chararacters, (so "host.org", "host.org.", and ".host.org" will all match
  88. * the same expressions) but DNS considers them equivalent, too. */
  89. char * make_exact_host_expression(const char *host);
  90. /* Like match(), but using a host expression */
  91. int match_host(const char *glob, const char *host);
  92. /*
  93. * Disk expressions
  94. */
  95. /* Disk expressions are described in amanda(8) */
  96. /* Make an Amanda disk expression that will match the given string exactly. */
  97. char * make_exact_disk_expression(const char *disk);
  98. /* Like match(), but using a disk expression */
  99. int match_disk(const char *glob, const char *disk);
  100. /*
  101. * Datestamp expressions
  102. */
  103. /* Datestamp expressions are described in amanda(8) */
  104. int match_datestamp(const char *dateexp, const char *datestamp);
  105. /*
  106. * Level expressions
  107. */
  108. /* Level expressions are either prefix matches e.g., "1", which matches "1", "10", and "123",
  109. * absolute matches e.g., "3$" which only matches "3", or a range e.g., "3-5" which only
  110. * matches levels 3, 4, and 5. */
  111. /* Like match(), but using a level expression */
  112. int match_level(const char *levelexp, const char *level);
  113. #endif /* MATCH_H */