faked_msg.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * $Id$
  3. *
  4. * Copyright (C) 2009 Daniel-Constantin Mierla (asipto.com)
  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. #include "../../dprint.h"
  23. #include "../../globals.h"
  24. #include "../../dset.h"
  25. #include "faked_msg.h"
  26. #define FAKED_SIP_MSG "OPTIONS sip:[email protected] SIP/2.0\r\nVia: SIP/2.0/UDP 127.0.0.1\r\nFrom: <[email protected]>;tag=123\r\nTo: <[email protected]>\r\nCall-ID: 123\r\nCSeq: 1 OPTIONS\r\nContent-Length: 0\r\n\r\n"
  27. #define FAKED_SIP_MSG_LEN (sizeof(FAKED_SIP_MSG)-1)
  28. static char _faked_sip_buf[FAKED_SIP_MSG_LEN+1];
  29. static struct sip_msg _faked_msg;
  30. static unsigned int _faked_msg_no = 0;
  31. int faked_msg_init(void)
  32. {
  33. if(_faked_msg_no>0)
  34. return 0;
  35. /* init faked sip msg */
  36. memcpy(_faked_sip_buf, FAKED_SIP_MSG, FAKED_SIP_MSG_LEN);
  37. _faked_sip_buf[FAKED_SIP_MSG_LEN] = '\0';
  38. memset(&_faked_msg, 0, sizeof(struct sip_msg));
  39. _faked_msg.buf=_faked_sip_buf;
  40. _faked_msg.len=FAKED_SIP_MSG_LEN;
  41. _faked_msg.set_global_address=default_global_address;
  42. _faked_msg.set_global_port=default_global_port;
  43. if (parse_msg(_faked_msg.buf, _faked_msg.len, &_faked_msg)!=0)
  44. {
  45. LM_ERR("parse_msg failed\n");
  46. return -1;
  47. }
  48. _faked_msg.rcv.proto = PROTO_UDP;
  49. _faked_msg.rcv.src_port = 5060;
  50. _faked_msg.rcv.src_ip.u.addr32[0] = 0x7f000001;
  51. _faked_msg.rcv.src_ip.af = AF_INET;
  52. _faked_msg.rcv.src_ip.len = 4;
  53. _faked_msg.rcv.dst_port = 5060;
  54. _faked_msg.rcv.dst_ip.u.addr32[0] = 0x7f000001;
  55. _faked_msg.rcv.dst_ip.af = AF_INET;
  56. _faked_msg.rcv.dst_ip.len = 4;
  57. return 0;
  58. }
  59. struct sip_msg* faked_msg_next(void)
  60. {
  61. _faked_msg.id = 1 + _faked_msg_no++;
  62. _faked_msg.pid = my_pid();
  63. memset(&_faked_msg.tval, 0, sizeof(struct timeval));
  64. clear_branches();
  65. return &_faked_msg;
  66. }