ut.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * $Id$
  3. *
  4. * utilities
  5. *
  6. *
  7. * Copyright (C) 2001-2003 Fhg Fokus
  8. *
  9. * This file is part of ser, a free SIP server.
  10. *
  11. * ser is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version
  15. *
  16. * For a license to use the ser software under conditions
  17. * other than those described here, or to purchase support for this
  18. * software, please contact iptel.org by e-mail at the following addresses:
  19. * [email protected]
  20. *
  21. * ser is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  29. */
  30. #ifndef _TM_UT_H
  31. #define _TM_UT_H
  32. #include "../../dprint.h"
  33. #include "../../error.h"
  34. #include "../../ut.h"
  35. #include "../../str.h"
  36. #include "../../parser/msg_parser.h"
  37. inline static struct proxy_l *uri2proxy( str *uri )
  38. {
  39. struct sip_uri parsed_uri;
  40. unsigned int port;
  41. struct proxy_l *p;
  42. int err;
  43. if (parse_uri(uri->s, uri->len, &parsed_uri)<0) {
  44. LOG(L_ERR, "ERROR: t_relay: bad_uri: %.*s\n",
  45. uri->len, uri->s );
  46. return 0;
  47. }
  48. if (parsed_uri.port.s){
  49. port=str2s((unsigned char*)parsed_uri.port.s, parsed_uri.port.len, &err);
  50. if (err){
  51. LOG(L_ERR, "ERROR: t_relay: bad port in uri: <%.*s>\n",
  52. parsed_uri.port.len, parsed_uri.port.s);
  53. goto error;
  54. }
  55. /* fixed use of SRV resolver
  56. } else port=SIP_PORT; */
  57. } else port=0;
  58. p=mk_proxy(parsed_uri.host.s, port);
  59. if (p==0) {
  60. LOG(L_ERR, "ERROR: t_relay: bad host name in URI <%.*s>\n",
  61. uri->len, uri->s);
  62. goto error;
  63. }
  64. free_uri( &parsed_uri );
  65. return p;
  66. error:
  67. free_uri( &parsed_uri );
  68. return 0;
  69. }
  70. #endif