SipUri.cxx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2010-2011 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango.org>
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO 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 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO 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 DOUBANGO.
  20. *
  21. */
  22. #include "SipUri.h"
  23. SipUri::SipUri(const char* uriString, const char* displayName/*=tsk_null*/)
  24. {
  25. if((m_pUri = tsip_uri_parse(uriString, (tsk_size_t)tsk_strlen(uriString))) && displayName) {
  26. m_pUri->display_name = tsk_strdup(displayName);
  27. }
  28. }
  29. SipUri::~SipUri()
  30. {
  31. TSK_OBJECT_SAFE_FREE(m_pUri);
  32. }
  33. bool SipUri::isValid(const char* uriString)
  34. {
  35. tsip_uri_t* uri;
  36. bool ret = false;
  37. if((uri = tsip_uri_parse(uriString, (tsk_size_t)tsk_strlen(uriString)))) {
  38. ret = (uri->type != uri_unknown)
  39. && (!tsk_strnullORempty(uri->host));
  40. TSK_OBJECT_SAFE_FREE(uri);
  41. }
  42. return ret;
  43. }
  44. bool SipUri::isValid()
  45. {
  46. return (m_pUri != tsk_null);
  47. }
  48. const char* SipUri::getScheme()
  49. {
  50. if(m_pUri) {
  51. return m_pUri->scheme;
  52. }
  53. return tsk_null;
  54. }
  55. const char* SipUri::getHost()
  56. {
  57. return m_pUri ? m_pUri->host : tsk_null;
  58. }
  59. unsigned short SipUri::getPort()
  60. {
  61. return m_pUri ? m_pUri->port : 0;
  62. }
  63. const char* SipUri::getUserName()
  64. {
  65. return m_pUri ? m_pUri->user_name : tsk_null;
  66. }
  67. const char* SipUri::getPassword()
  68. {
  69. return m_pUri ? m_pUri->password : tsk_null;
  70. }
  71. const char* SipUri::getDisplayName()
  72. {
  73. return m_pUri ? m_pUri->display_name : tsk_null;
  74. }
  75. void SipUri::setDisplayName(const char* displayName)
  76. {
  77. if(m_pUri) {
  78. tsk_strupdate(&m_pUri->display_name, displayName);
  79. }
  80. }
  81. const char* SipUri::getParamValue(const char* pname)
  82. {
  83. if(m_pUri && m_pUri->params) {
  84. const char* pvalue = tsk_params_get_param_value(m_pUri->params, pname);
  85. return pvalue;
  86. }
  87. return tsk_null;
  88. }