re.h 2.3 KB

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