PageRenderTime 59ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/doubango/tinySIP/src/headers/tsip_header_WWW_Authenticate.c

https://gitlab.com/iwan.aucamp/doubango
C | 160 lines | 95 code | 33 blank | 32 comment | 6 complexity | 2c3bee0e2366db7f47976b0943aa8f95 MD5 | raw file
  1. /* #line 1 "tsip_parser_header_WWW_Authenticate.rl" */
  2. /*
  3. * Copyright (C) 2010-2011 Mamadou Diop.
  4. *
  5. * Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
  6. *
  7. * This file is part of Open Source Doubango Framework.
  8. *
  9. * DOUBANGO 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 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * DOUBANGO is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with DOUBANGO.
  21. *
  22. */
  23. /**@file tsip_header_WWW_Authenticate.c
  24. * @brief SIP WWW-Authenticate header.
  25. *
  26. * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
  27. *
  28. */
  29. #include "tinysip/headers/tsip_header_WWW_Authenticate.h"
  30. #include "tinyhttp/headers/thttp_header_WWW_Authenticate.h"
  31. #include "tsk_debug.h"
  32. #include "tsk_memory.h"
  33. #include "tsk_time.h"
  34. #include <string.h>
  35. tsip_header_WWW_Authenticate_t* tsip_header_WWW_Authenticate_create()
  36. {
  37. return tsk_object_new(tsip_header_WWW_Authenticate_def_t);
  38. }
  39. int tsip_header_WWW_Authenticate_serialize(const tsip_header_t* header, tsk_buffer_t* output)
  40. {
  41. if(header){
  42. const tsip_header_WWW_Authenticate_t *WWW_Authenticate = (const tsip_header_WWW_Authenticate_t *)header;
  43. if(WWW_Authenticate && WWW_Authenticate->scheme){
  44. return tsk_buffer_append_2(output, "%s realm=\"%s\"%s%s%s%s%s%s%s%s%s%s%s%s,stale=%s%s%s",
  45. WWW_Authenticate->scheme,
  46. WWW_Authenticate->realm ? WWW_Authenticate->realm : "",
  47. WWW_Authenticate->domain ? ",domain=\"" : "",
  48. WWW_Authenticate->domain ? WWW_Authenticate->domain : "",
  49. WWW_Authenticate->domain ? "\"" : "",
  50. WWW_Authenticate->qop ? ",qop=\"" : "",
  51. WWW_Authenticate->qop ? WWW_Authenticate->qop : "",
  52. WWW_Authenticate->qop ? "\"" : "",
  53. WWW_Authenticate->nonce ? ",nonce=\"" : "",
  54. WWW_Authenticate->nonce ? WWW_Authenticate->nonce : "",
  55. WWW_Authenticate->nonce ? "\"" : "",
  56. WWW_Authenticate->opaque ? ",opaque=\"" : "",
  57. WWW_Authenticate->opaque ? WWW_Authenticate->opaque : "",
  58. WWW_Authenticate->opaque ? "\"" : "",
  59. WWW_Authenticate->stale ? "TRUE" : "FALSE",
  60. WWW_Authenticate->algorithm ? ",algorithm=" : "",
  61. WWW_Authenticate->algorithm ? WWW_Authenticate->algorithm : ""
  62. );
  63. }
  64. }
  65. return -1;
  66. }
  67. tsip_header_WWW_Authenticate_t *tsip_header_WWW_Authenticate_parse(const char *data, tsk_size_t size)
  68. {
  69. tsip_header_WWW_Authenticate_t *sip_hdr = 0;
  70. thttp_header_WWW_Authenticate_t* http_hdr;
  71. if((http_hdr = thttp_header_WWW_Authenticate_parse(data, size))){
  72. sip_hdr = tsip_header_WWW_Authenticate_create();
  73. sip_hdr->scheme = tsk_strdup(http_hdr->scheme);
  74. sip_hdr->realm = tsk_strdup(http_hdr->realm);
  75. sip_hdr->domain = tsk_strdup(http_hdr->domain);
  76. sip_hdr->nonce = tsk_strdup(http_hdr->nonce);
  77. sip_hdr->opaque = tsk_strdup(http_hdr->opaque);
  78. sip_hdr->algorithm = tsk_strdup(http_hdr->algorithm);
  79. sip_hdr->qop = tsk_strdup(http_hdr->qop);
  80. sip_hdr->stale = http_hdr->stale;
  81. TSIP_HEADER(sip_hdr)->params = tsk_object_ref(THTTP_HEADER(http_hdr)->params);
  82. TSK_OBJECT_SAFE_FREE(http_hdr);
  83. }
  84. return sip_hdr;
  85. }
  86. //========================================================
  87. // WWW_Authenticate header object definition
  88. //
  89. static tsk_object_t* tsip_header_WWW_Authenticate_ctor(tsk_object_t *self, va_list * app)
  90. {
  91. tsip_header_WWW_Authenticate_t *WWW_Authenticate = self;
  92. if(WWW_Authenticate){
  93. TSIP_HEADER(WWW_Authenticate)->type = tsip_htype_WWW_Authenticate;
  94. TSIP_HEADER(WWW_Authenticate)->serialize = tsip_header_WWW_Authenticate_serialize;
  95. }
  96. else{
  97. TSK_DEBUG_ERROR("Failed to create new WWW_Authenticate header.");
  98. }
  99. return self;
  100. }
  101. static tsk_object_t* tsip_header_WWW_Authenticate_dtor(tsk_object_t *self)
  102. {
  103. tsip_header_WWW_Authenticate_t *WWW_Authenticate = self;
  104. if(WWW_Authenticate){
  105. TSK_FREE(WWW_Authenticate->scheme);
  106. TSK_FREE(WWW_Authenticate->realm);
  107. TSK_FREE(WWW_Authenticate->domain);
  108. TSK_FREE(WWW_Authenticate->nonce);
  109. TSK_FREE(WWW_Authenticate->opaque);
  110. TSK_FREE(WWW_Authenticate->algorithm);
  111. TSK_FREE(WWW_Authenticate->qop);
  112. TSK_OBJECT_SAFE_FREE(TSIP_HEADER_PARAMS(WWW_Authenticate));
  113. }
  114. else{
  115. TSK_DEBUG_ERROR("Null WWW_Authenticate header.");
  116. }
  117. return self;
  118. }
  119. static const tsk_object_def_t tsip_header_WWW_Authenticate_def_s =
  120. {
  121. sizeof(tsip_header_WWW_Authenticate_t),
  122. tsip_header_WWW_Authenticate_ctor,
  123. tsip_header_WWW_Authenticate_dtor,
  124. tsk_null
  125. };
  126. const tsk_object_def_t *tsip_header_WWW_Authenticate_def_t = &tsip_header_WWW_Authenticate_def_s;