PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/amanda/tags/3_3_0beta1/common-src/match.h

#
C Header | 139 lines | 19 code | 33 blank | 87 comment | 0 complexity | 5ed82eac96cd9659228b368426e6c841 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. /* quote any non-alphanumeric characters in str, so that the result will only
  45. * match the original string. If anchor is true, then add ^ and $ to make sure
  46. * that substrings will not match. */
  47. char * clean_regex(const char *str, gboolean anchor);
  48. /*
  49. * Globs
  50. */
  51. /*
  52. * A "glob expression" is similar to shell globs; it supports metacharacters
  53. * "*" and "?", as well as character classes like "[...]" and "[!...]"
  54. * (negated). The "*" and "?" do not match filename separators ("/"). The
  55. * entire expression is anchored, so it must match the string, not just a single
  56. * filename component.
  57. */
  58. /* Validate that GLOB is a legal GLOB expression. Returns a statically
  59. * allocated error message on failure, or NULL on success. */
  60. char * validate_glob(const char *glob);
  61. /* Convert a GLOB expression into a dynamically allocated regular expression */
  62. char * glob_to_regex(const char *glob);
  63. /* Like match(), but with a glob expression */
  64. int match_glob(const char *glob, const char *str);
  65. /*
  66. * Tar Patterns
  67. */
  68. /* A "tar expression" is almost the same as a glob, except that "*" can match a
  69. * filename separator ("?" cannot). It is used by calcsize to emulate tar's exclude
  70. * list patterns, which are actually significantly more complicated than this.
  71. */
  72. /* Like match(), but with a tar expression */
  73. int match_tar(const char *glob, const char *str);
  74. /*
  75. * Host expressions
  76. */
  77. /* Host expressions are described in amanda(8). */
  78. /* Make an Amanda host expression that will match the given string exactly.
  79. * There is a little bit of fuzz here involving leading and trailing "."
  80. * chararacters, (so "host.org", "host.org.", and ".host.org" will all match
  81. * the same expressions) but DNS considers them equivalent, too. */
  82. char * make_exact_host_expression(const char *host);
  83. /* Like match(), but using a host expression */
  84. int match_host(const char *glob, const char *host);
  85. /*
  86. * Disk expressions
  87. */
  88. /* Disk expressions are described in amanda(8) */
  89. /* Make an Amanda disk expression that will match the given string exactly. */
  90. char * make_exact_disk_expression(const char *disk);
  91. /* Like match(), but using a disk expression */
  92. int match_disk(const char *glob, const char *disk);
  93. /*
  94. * Datestamp expressions
  95. */
  96. /* Datestamp expressions are described in amanda(8) */
  97. int match_datestamp(const char *dateexp, const char *datestamp);
  98. /*
  99. * Level expressions
  100. */
  101. /* Level expressions are either prefix matches e.g., "1", which matches "1", "10", and "123",
  102. * absolute matches e.g., "3$" which only matches "3", or a range e.g., "3-5" which only
  103. * matches levels 3, 4, and 5. */
  104. /* Like match(), but using a level expression */
  105. int match_level(const char *levelexp, const char *level);
  106. #endif /* MATCH_H */