tsip_parser_header_Authorization.rl 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. ///*
  2. //* Copyright (C) 2010-2011 Mamadou Diop.
  3. //*
  4. //* Contact: Mamadou Diop <diopmamadou(at)doubango[dot]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. //
  23. ///**@file tsip_header_Authorization.c
  24. // * @brief SIP Authorization header.
  25. // *
  26. // * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
  27. // *
  28. //
  29. // */
  30. //#include "tinysip/headers/tsip_header_Authorization.h"
  31. //
  32. //#include "tinysip/parsers/tsip_parser_uri.h"
  33. //
  34. //#include "tsk_debug.h"
  35. //#include "tsk_memory.h"
  36. //#include "tsk_time.h"
  37. //
  38. //#include <string.h>
  39. //
  40. //
  41. ///***********************************
  42. //* Ragel state machine.
  43. //*/
  44. //%%{
  45. // machine tsip_machine_parser_header_Authorization;
  46. //
  47. // # Includes
  48. // include tsip_machine_utils "./ragel/tsip_machine_utils.rl";
  49. //
  50. // action tag
  51. // {
  52. // tag_start = p;
  53. // }
  54. //
  55. // action is_digest
  56. // {
  57. // #//FIXME: Only Digest is supported
  58. // hdr_Authorization->scheme = tsk_strdup("Digest");
  59. // }
  60. //
  61. // action parse_username
  62. // {
  63. // TSK_PARSER_SET_STRING(hdr_Authorization->username);
  64. // tsk_strunquote(&hdr_Authorization->username);
  65. // }
  66. //
  67. // action parse_realm
  68. // {
  69. // TSK_PARSER_SET_STRING(hdr_Authorization->realm);
  70. // tsk_strunquote(&hdr_Authorization->realm);
  71. // }
  72. //
  73. // action parse_nonce
  74. // {
  75. // TSK_PARSER_SET_STRING(hdr_Authorization->nonce);
  76. // tsk_strunquote(&hdr_Authorization->nonce);
  77. // }
  78. //
  79. // action parse_uri
  80. // {
  81. // TSK_PARSER_SET_STRING(hdr_Authorization->line.request.uri);
  82. // }
  83. //
  84. // action parse_response
  85. // {
  86. // TSK_PARSER_SET_STRING(hdr_Authorization->response);
  87. // tsk_strunquote(&hdr_Authorization->response);
  88. // }
  89. //
  90. // action parse_algorithm
  91. // {
  92. // TSK_PARSER_SET_STRING(hdr_Authorization->algorithm);
  93. // }
  94. //
  95. // action parse_cnonce
  96. // {
  97. // TSK_PARSER_SET_STRING(hdr_Authorization->cnonce);
  98. // tsk_strunquote(&hdr_Authorization->cnonce);
  99. // }
  100. //
  101. // action parse_opaque
  102. // {
  103. // TSK_PARSER_SET_STRING(hdr_Authorization->opaque);
  104. // tsk_strunquote(&hdr_Authorization->opaque);
  105. // }
  106. //
  107. // action parse_qop
  108. // {
  109. // TSK_PARSER_SET_STRING(hdr_Authorization->qop);
  110. // //tsk_strunquote(&hdr_Authorization->qop);
  111. // }
  112. //
  113. // action parse_nc
  114. // {
  115. // TSK_PARSER_SET_STRING(hdr_Authorization->nc);
  116. // }
  117. //
  118. // action parse_param
  119. // {
  120. // TSK_PARSER_ADD_PARAM(TSIP_HEADER_PARAMS(hdr_Authorization));
  121. // }
  122. //
  123. // action eob
  124. // {
  125. // }
  126. //
  127. // #FIXME: Only Digest (MD5, AKAv1-MD5 and AKAv2-MD5) is supported
  128. // qop_value = "auth" | "auth-int" | token;
  129. // other_response = (any+);
  130. // auth_param = generic_param>tag %parse_param;
  131. //
  132. // username = "username"i EQUAL quoted_string>tag %parse_username;
  133. // realm = "realm"i EQUAL quoted_string>tag %parse_realm;
  134. // nonce = "nonce"i EQUAL quoted_string>tag %parse_nonce;
  135. // digest_uri = "uri"i EQUAL LDQUOT <: (any*)>tag %parse_uri :> RDQUOT;
  136. // #dresponse = "response"i EQUAL LDQUOT <: (LHEX{32})>tag %parse_response :> RDQUOT;
  137. // dresponse = "response"i EQUAL quoted_string>tag %parse_response;
  138. // algorithm = "algorithm"i EQUAL <:token>tag %parse_algorithm;
  139. // cnonce = "cnonce"i EQUAL quoted_string>tag %parse_cnonce;
  140. // opaque = "opaque"i EQUAL quoted_string>tag %parse_opaque;
  141. // message_qop = "qop"i EQUAL qop_value>tag %parse_qop;
  142. // nonce_count = "nc"i EQUAL (LHEX{8})>tag %parse_nc;
  143. //
  144. // dig_resp = (username | realm | nonce | digest_uri | dresponse | algorithm | cnonce | opaque | message_qop | nonce_count)@1 | auth_param@0;
  145. // digest_response = dig_resp ( COMMA <:dig_resp )*;
  146. // credentials = ( "Digest"i LWS digest_response )>is_digest | other_response;
  147. // Authorization = "Authorization"i HCOLON credentials;
  148. //
  149. // # Entry point
  150. // main := Authorization :>CRLF @eob;
  151. //
  152. //}%%
  153. //
  154. //int tsip_header_Authorization_serialize(const tsip_header_t* header, tsk_buffer_t* output)
  155. //{
  156. // if(header)
  157. // {
  158. // const tsip_header_Authorization_t *Authorization = header;
  159. // if(Authorization && Authorization->scheme)
  160. // {
  161. // return tsk_buffer_append_2(output, "%s %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
  162. // Authorization->scheme,
  163. //
  164. // Authorization->username ? "username=\"" : "",
  165. // Authorization->username ? Authorization->username : "",
  166. // Authorization->username ? "\"" : "",
  167. //
  168. // Authorization->realm ? ",realm=\"" : "",
  169. // Authorization->realm ? Authorization->realm : "",
  170. // Authorization->realm ? "\"" : "",
  171. //
  172. // Authorization->nonce ? ",nonce=\"" : "",
  173. // Authorization->nonce ? Authorization->nonce : "",
  174. // Authorization->nonce ? "\"" : "",
  175. //
  176. // Authorization->line.request.uri ? ",uri=\"" : "",
  177. // Authorization->line.request.uri ? Authorization->line.request.uri : "",
  178. // Authorization->line.request.uri ? "\"" : "",
  179. //
  180. // Authorization->response ? ",response=\"" : "",
  181. // Authorization->response ? Authorization->response : "",
  182. // Authorization->response ? "\"" : "",
  183. //
  184. // Authorization->algorithm ? ",algorithm=" : "",
  185. // Authorization->algorithm ? Authorization->algorithm : "",
  186. //
  187. // Authorization->cnonce ? ",cnonce=\"" : "",
  188. // Authorization->cnonce ? Authorization->cnonce : "",
  189. // Authorization->cnonce ? "\"" : "",
  190. //
  191. // Authorization->opaque ? ",opaque=\"" : "",
  192. // Authorization->opaque ? Authorization->opaque : "",
  193. // Authorization->opaque ? "\"" : "",
  194. //
  195. // Authorization->qop ? ",qop=" : "",
  196. // Authorization->qop ? Authorization->qop : "",
  197. //
  198. // Authorization->nc ? ",nc=" : "",
  199. // Authorization->nc ? Authorization->nc : ""
  200. // );
  201. // }
  202. // }
  203. // return -1;
  204. //}
  205. //
  206. //tsip_header_Authorization_t *tsip_header_Authorization_parse(const char *data, tsk_size_t size)
  207. //{
  208. // int cs = 0;
  209. // const char *p = data;
  210. // const char *pe = p + size;
  211. // const char *eof = pe;
  212. // tsip_header_Authorization_t *hdr_Authorization = tsip_header_Authorization_create();
  213. //
  214. // const char *tag_start = tsk_null;
  215. //
  216. // %%write data;
  217. // %%write init;
  218. // %%write exec;
  219. //
  220. // if( cs < %%{ write first_final; }%% )
  221. // {
  222. // TSK_OBJECT_SAFE_FREE(hdr_Authorization);
  223. // }
  224. //
  225. // return hdr_Authorization;
  226. //}
  227. //
  228. //
  229. //
  230. //
  231. //
  232. //
  233. //
  234. ////========================================================
  235. //// Authorization header object definition
  236. ////
  237. //
  238. //static tsk_object_t* tsip_header_Authorization_ctor(tsk_object_t *self, va_list * app)
  239. //{
  240. // tsip_header_Authorization_t *Authorization = self;
  241. // if(Authorization)
  242. // {
  243. // TSIP_HEADER(Authorization)->type = tsip_htype_Authorization;
  244. // TSIP_HEADER(Authorization)->serialize = tsip_header_Authorization_serialize;
  245. // }
  246. // else
  247. // {
  248. // TSK_DEBUG_ERROR("Failed to create new Authorization header.");
  249. // }
  250. // return self;
  251. //}
  252. //
  253. //static tsk_object_t* tsip_header_Authorization_dtor(tsk_object_t *self)
  254. //{
  255. // tsip_header_Authorization_t *Authorization = self;
  256. // if(Authorization)
  257. // {
  258. // TSK_FREE(Authorization->scheme);
  259. // TSK_FREE(Authorization->username);
  260. // TSK_FREE(Authorization->realm);
  261. // TSK_FREE(Authorization->nonce);
  262. // TSK_FREE(Authorization->line.request.uri);
  263. // TSK_FREE(Authorization->response);
  264. // TSK_FREE(Authorization->algorithm);
  265. // TSK_FREE(Authorization->cnonce);
  266. // TSK_FREE(Authorization->opaque);
  267. // TSK_FREE(Authorization->qop);
  268. // TSK_FREE(Authorization->nc);
  269. //
  270. // TSK_OBJECT_SAFE_FREE(TSIP_HEADER_PARAMS(Authorization));
  271. // }
  272. // else TSK_DEBUG_ERROR("Null Authorization header.");
  273. //
  274. // return self;
  275. //}
  276. //
  277. //static const tsk_object_def_t tsip_header_Authorization_def_s =
  278. //{
  279. // sizeof(tsip_header_Authorization_t),
  280. // tsip_header_Authorization_ctor,
  281. // tsip_header_Authorization_dtor,
  282. // 0
  283. //};
  284. //const void *tsip_header_Authorization_def_t = &tsip_header_Authorization_def_s;