data_lump_rpl.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * $Id$
  3. *
  4. *
  5. * Copyright (C) 2001-2003 Fhg Fokus
  6. *
  7. * This file is part of ser, a free SIP server.
  8. *
  9. * ser is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version
  13. *
  14. * For a license to use the ser software under conditions
  15. * other than those described here, or to purchase support for this
  16. * software, please contact iptel.org by e-mail at the following addresses:
  17. * [email protected]
  18. *
  19. * ser is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. */
  28. #include <string.h>
  29. #include "dprint.h"
  30. #include "mem/mem.h"
  31. #include "data_lump_rpl.h"
  32. struct lump_rpl* build_lump_rpl( char* text, int len )
  33. {
  34. struct lump_rpl *lump = 0;
  35. lump = (struct lump_rpl*) pkg_malloc(sizeof(struct lump_rpl));
  36. if (!lump)
  37. {
  38. LOG(L_ERR,"ERROR:build_lump_rpl : no free memory (struct)!\n");
  39. goto error;
  40. }
  41. lump->text.s = pkg_malloc( len );
  42. if (!lump->text.s)
  43. {
  44. LOG(L_ERR,"ERROR:build_lump_rpl : no free memory (%d)!\n", len );
  45. goto error;
  46. }
  47. memcpy(lump->text.s,text,len);
  48. lump->text.len = len;
  49. lump->next = 0;
  50. return lump;
  51. error:
  52. if (lump) pkg_free(lump);
  53. return 0;
  54. }
  55. void add_lump_rpl(struct sip_msg * msg, struct lump_rpl* lump)
  56. {
  57. struct lump_rpl *foo;
  58. if (!msg->reply_lump)
  59. {
  60. msg->reply_lump = lump;
  61. }else{
  62. for(foo=msg->reply_lump;foo->next;foo=foo->next);
  63. foo->next = lump;
  64. }
  65. }
  66. void free_lump_rpl(struct lump_rpl* lump)
  67. {
  68. if (lump && lump->text.s) pkg_free(lump->text.s);
  69. if (lump) pkg_free(lump);
  70. }