2
0

onsend.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2005 iptelorg GmbH
  3. *
  4. * This file is part of Kamailio, a free SIP server.
  5. *
  6. * Kamailio is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version
  10. *
  11. * Kamailio is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /*!
  21. * \file
  22. * \brief Kamailio core :: IP address handling
  23. * \author andrei
  24. * \ingroup core
  25. * Module: \ref core
  26. */
  27. #ifndef onsend_h
  28. #define onsend_h
  29. #include "ip_addr.h"
  30. #include "action.h"
  31. #include "route.h"
  32. #include "script_cb.h"
  33. #include "sr_compat.h"
  34. struct onsend_info{
  35. union sockaddr_union* to; /* dest info */
  36. struct socket_info* send_sock; /* local send socket */
  37. char* buf; /* outgoing buffer */
  38. int len; /* outgoing buffer len */
  39. sip_msg_t *msg; /* original sip msg struct */
  40. };
  41. extern struct onsend_info* p_onsend;
  42. #define get_onsend_info() (p_onsend)
  43. /*
  44. * returns: 0 drop the message, >= ok, <0 error (but forward the message)
  45. * it also migh change dst->send_flags!
  46. * WARNING: buf must be 0 terminated (to allow regex matches on it) */
  47. static inline int run_onsend(struct sip_msg* orig_msg, struct dest_info* dst,
  48. char* buf, int len)
  49. {
  50. struct onsend_info onsnd_info = {0};
  51. int ret;
  52. struct run_act_ctx ra_ctx;
  53. int backup_route_type;
  54. snd_flags_t fwd_snd_flags_bak;
  55. snd_flags_t rpl_snd_flags_bak;
  56. ret=1;
  57. if (onsend_rt.rlist[DEFAULT_RT]){
  58. onsnd_info.to=&dst->to;
  59. onsnd_info.send_sock=dst->send_sock;
  60. onsnd_info.buf=buf;
  61. onsnd_info.len=len;
  62. onsnd_info.msg=orig_msg;
  63. p_onsend=&onsnd_info;
  64. backup_route_type=get_route_type();
  65. set_route_type(ONSEND_ROUTE);
  66. if (exec_pre_script_cb(orig_msg, ONSEND_CB_TYPE)>0) {
  67. /* backup orig_msg send flags */
  68. fwd_snd_flags_bak=orig_msg->fwd_send_flags;
  69. rpl_snd_flags_bak=orig_msg->rpl_send_flags;
  70. orig_msg->fwd_send_flags=dst->send_flags; /* intial value */
  71. init_run_actions_ctx(&ra_ctx);
  72. ret=run_actions(&ra_ctx, onsend_rt.rlist[DEFAULT_RT], orig_msg);
  73. /* update dst send_flags */
  74. dst->send_flags=orig_msg->fwd_send_flags;
  75. /* restore orig_msg flags */
  76. orig_msg->fwd_send_flags=fwd_snd_flags_bak;
  77. orig_msg->rpl_send_flags=rpl_snd_flags_bak;
  78. exec_post_script_cb(orig_msg, ONSEND_CB_TYPE);
  79. if((ret==0) && !(ra_ctx.run_flags&DROP_R_F)){
  80. ret = 1;
  81. }
  82. } else {
  83. ret=0; /* drop the message */
  84. }
  85. set_route_type(backup_route_type);
  86. p_onsend=0; /* reset it */
  87. }
  88. return ret;
  89. }
  90. #define onsend_route_enabled(rtype) (onsend_rt.rlist[DEFAULT_RT]?((rtype==SIP_REPLY)?onsend_route_reply:1):0)
  91. #endif