onsend.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2005 iptelorg GmbH
  5. *
  6. * This file is part of ser, a free SIP server.
  7. *
  8. * ser 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. * For a license to use the ser software under conditions
  14. * other than those described here, or to purchase support for this
  15. * software, please contact iptel.org by e-mail at the following addresses:
  16. * [email protected]
  17. *
  18. * ser is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  26. */
  27. /*
  28. * History:
  29. * -------
  30. * 2005-12-11 created by andrei
  31. * 2009-06-01 Pre- and post-script callbacks of onsend route are executed (Miklos)
  32. */
  33. #ifndef onsend_h
  34. #define onsend_h
  35. #include "ip_addr.h"
  36. #include "action.h"
  37. #include "route.h"
  38. #include "script_cb.h"
  39. #include "sr_compat.h"
  40. struct onsend_info{
  41. union sockaddr_union* to; /* dest info */
  42. struct socket_info* send_sock; /* local send socket */
  43. char* buf; /* outgoing buffer */
  44. int len; /* outgoing buffer len */
  45. sip_msg_t *msg; /* original sip msg struct */
  46. };
  47. extern struct onsend_info* p_onsend;
  48. #define get_onsend_info() (p_onsend)
  49. /*
  50. * returns: 0 drop the message, >= ok, <0 error (but forward the message)
  51. * it also migh change dst->send_flags!
  52. * WARNING: buf must be 0 terminated (to allow regex matches on it) */
  53. static inline int run_onsend(struct sip_msg* orig_msg, struct dest_info* dst,
  54. char* buf, int len)
  55. {
  56. struct onsend_info onsnd_info = {0};
  57. int ret;
  58. struct run_act_ctx ra_ctx;
  59. int backup_route_type;
  60. snd_flags_t fwd_snd_flags_bak;
  61. snd_flags_t rpl_snd_flags_bak;
  62. ret=1;
  63. if (onsend_rt.rlist[DEFAULT_RT]){
  64. onsnd_info.to=&dst->to;
  65. onsnd_info.send_sock=dst->send_sock;
  66. onsnd_info.buf=buf;
  67. onsnd_info.len=len;
  68. onsnd_info.msg=orig_msg;
  69. p_onsend=&onsnd_info;
  70. backup_route_type=get_route_type();
  71. set_route_type(ONSEND_ROUTE);
  72. if (exec_pre_script_cb(orig_msg, ONSEND_CB_TYPE)>0) {
  73. /* backup orig_msg send flags */
  74. fwd_snd_flags_bak=orig_msg->fwd_send_flags;
  75. rpl_snd_flags_bak=orig_msg->rpl_send_flags;
  76. orig_msg->fwd_send_flags=dst->send_flags; /* intial value */
  77. init_run_actions_ctx(&ra_ctx);
  78. ret=run_actions(&ra_ctx, onsend_rt.rlist[DEFAULT_RT], orig_msg);
  79. /* update dst send_flags */
  80. dst->send_flags=orig_msg->fwd_send_flags;
  81. /* restore orig_msg flags */
  82. orig_msg->fwd_send_flags=fwd_snd_flags_bak;
  83. orig_msg->rpl_send_flags=rpl_snd_flags_bak;
  84. exec_post_script_cb(orig_msg, ONSEND_CB_TYPE);
  85. if((ret==0) && !(ra_ctx.run_flags&DROP_R_F)){
  86. ret = 1;
  87. }
  88. } else {
  89. ret=0; /* drop the message */
  90. }
  91. set_route_type(backup_route_type);
  92. p_onsend=0; /* reset it */
  93. }
  94. return ret;
  95. }
  96. #define onsend_route_enabled(rtype) (onsend_rt.rlist[DEFAULT_RT]?((rtype==SIP_REPLY)?onsend_route_reply:1):0)
  97. #endif