mohq_common.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2013 Robert Boisvert
  5. *
  6. * This file is part of the mohqueue module for sip-router, a free SIP server.
  7. *
  8. * The mohqueue module 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. * The mohqueue module 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. #ifndef MOHQ_COMMON_H
  24. #define MOHQ_COMMON_H
  25. #include <assert.h>
  26. #include <sys/stat.h>
  27. #include "../rr/api.h"
  28. #include "../../data_lump.h"
  29. #include "../../data_lump_rpl.h"
  30. #include "../../dprint.h"
  31. #include "../../dset.h"
  32. #include "../../flags.h"
  33. #include "../../hashes.h"
  34. #include "../../locking.h"
  35. #include "../../lvalue.h"
  36. #include "../../mod_fix.h"
  37. #include "../../sr_module.h"
  38. #include "../../str.h"
  39. #include "../../lib/kcore/cmpapi.h"
  40. #include "../../lib/kmi/mi.h"
  41. #include "../../lib/srdb1/db.h"
  42. #include "../../mem/mem.h"
  43. #include "../../mem/shm_mem.h"
  44. #include "../../modules/sl/sl.h"
  45. #include "../../modules/tm/tm_load.h"
  46. #include "../../parser/hf.h"
  47. #include "../../parser/msg_parser.h"
  48. #include "../../parser/contact/parse_contact.h"
  49. #include "../../parser/parse_expires.h"
  50. #include "../../parser/parse_from.h"
  51. #include "../../parser/sdp/sdp.h"
  52. /* convenience macros */
  53. #define MOHQ_STRUCT_PTR_OFFSET( struct1, cast1, offset1 ) \
  54. (cast1)(struct1) + (offset1)
  55. #define MOHQ_STR_COPY( str1, str2 ) \
  56. memcpy((str1)->s, (str2)->s, (str2)->len ); \
  57. (str1)->len = (str2)->len;
  58. #define MOHQ_STR_APPEND( str1, str2 ) \
  59. memcpy((str1)->s + (str1)->len, (str2)->s, (str2)->len); \
  60. (str1)->len += (str2)->len;
  61. #define MOHQ_STR_APPEND_L( str1, str1_lim, s2, s2_len ) \
  62. if ((str1)->len + (s2_len) >= (str1_lim)) { \
  63. LM_ERR( "Failed to append to str: too long" ); \
  64. } else { \
  65. MOHQ_STR_APPEND((str1), (s2), (s2_len)); \
  66. (str1_lim) -= (s2_len); \
  67. }
  68. #define MOHQ_STR_COPY_CSTR( str1, cstr1 ) \
  69. memcpy((str1)->s + (str1)->len, (cstr1), strlen((cstr1))); \
  70. (str1)->len += strlen((cstr1));
  71. #define MOHQ_STR_APPEND_CSTR( str1, cstr1 ) \
  72. MOHQ_STR_COPY_CSTR((str1), (cstr1))
  73. #define MOHQ_STR_APPEND_CSTR_L( str1, str1_lim, cstr1 ) \
  74. if ((str1)->len + strlen(cstr1) >= (str1_lim)) { \
  75. LM_ERR( "Failed to append to str: too long" ); \
  76. } else { \
  77. MOHQ_STR_APPEND_CSTR((str1), (cstr1)); \
  78. }
  79. /* STR_EQ assumes we're not using str pointers, which is obnoxious */
  80. #define MOHQ_STR_EQ( str1, str2 ) \
  81. (((str1)->len == (str2)->len) && \
  82. memcmp((str1)->s, (str2)->s, (str1)->len) == 0)
  83. #define MOHQ_STR_EMPTY( str1 ) \
  84. (((str1) != NULL && ((str1)->s == NULL || (str1)->len <= 0 )) \
  85. || (str1) == NULL )
  86. #define MOHQ_HEADER_EMPTY( hdr1 ) \
  87. ((hdr1) == NULL || MOHQ_STR_EMPTY( &(hdr1)->body ))
  88. #endif /* MOHQ_COMMON_H */