re.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * $Id$
  3. *
  4. * regexp and regexp substitutions implementations
  5. *
  6. * Copyright (C) 2001-2003 FhG Fokus
  7. *
  8. * This file is part of ser, a free SIP server.
  9. *
  10. * ser is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version
  14. *
  15. * For a license to use the ser software under conditions
  16. * other than those described here, or to purchase support for this
  17. * software, please contact iptel.org by e-mail at the following addresses:
  18. * [email protected]
  19. *
  20. * ser is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  28. *
  29. *
  30. * History:
  31. * --------
  32. * 2003-08-04 created by andrei
  33. * 2004-11-12 minor api extension, added *count (andrei)
  34. */
  35. #ifndef _re_h
  36. #define _re_h
  37. #include "str.h"
  38. #include "pvar.h"
  39. #include "parser/msg_parser.h"
  40. #include <sys/types.h> /* for regex */
  41. #include <regex.h>
  42. #define WITH_SEP 1
  43. #define WITHOUT_SEP 0
  44. enum replace_special { REPLACE_NMATCH, REPLACE_CHAR, REPLACE_URI,
  45. REPLACE_SPEC };
  46. struct replace_with{
  47. int offset; /* offset in string */
  48. int size; /* size of replace "anchor" in string */
  49. enum replace_special type;
  50. union{
  51. int nmatch;
  52. char c;
  53. pv_spec_t spec;
  54. }u;
  55. };
  56. struct subst_expr{
  57. regex_t* re;
  58. str replacement;
  59. int replace_all;
  60. int n_escapes; /* escapes number (replace[] size) */
  61. int max_pmatch ; /* highest () referenced */
  62. struct replace_with replace[1]; /* 0 does not work on all compilers */
  63. };
  64. struct replace_lst{
  65. int offset;
  66. int size; /* at offset, delete size bytes and replace them with rpl */
  67. str rpl;
  68. struct replace_lst *next;
  69. };
  70. void subst_expr_free(struct subst_expr* se);
  71. void replace_lst_free(struct replace_lst* l);
  72. int parse_repl(struct replace_with * rw, char ** begin,
  73. char * end, int *max_token_nb, int flag);
  74. struct subst_expr* subst_parser(str* subst);
  75. struct replace_lst* subst_run( struct subst_expr* se, const char* input,
  76. struct sip_msg* msg, int *count);
  77. str* subst_str(const char* input, struct sip_msg* msg,
  78. struct subst_expr* se, int* count);
  79. #endif