rfc7230.hpp 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. //
  2. // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/beast
  8. //
  9. #ifndef BOOST_BEAST_HTTP_IMPL_RFC7230_HPP
  10. #define BOOST_BEAST_HTTP_IMPL_RFC7230_HPP
  11. #include <boost/beast/http/detail/rfc7230.hpp>
  12. #include <iterator>
  13. namespace boost {
  14. namespace beast {
  15. namespace http {
  16. class param_list::const_iterator
  17. {
  18. using iter_type = string_view::const_iterator;
  19. std::string s_;
  20. detail::param_iter pi_;
  21. public:
  22. using value_type = param_list::value_type;
  23. using pointer = value_type const*;
  24. using reference = value_type const&;
  25. using difference_type = std::ptrdiff_t;
  26. using iterator_category = std::input_iterator_tag;
  27. const_iterator() = default;
  28. bool
  29. operator==(const_iterator const& other) const
  30. {
  31. return
  32. other.pi_.it == pi_.it &&
  33. other.pi_.last == pi_.last &&
  34. other.pi_.first == pi_.first;
  35. }
  36. bool
  37. operator!=(const_iterator const& other) const
  38. {
  39. return !(*this == other);
  40. }
  41. reference
  42. operator*() const
  43. {
  44. return pi_.v;
  45. }
  46. pointer
  47. operator->() const
  48. {
  49. return &*(*this);
  50. }
  51. const_iterator&
  52. operator++()
  53. {
  54. increment();
  55. return *this;
  56. }
  57. const_iterator
  58. operator++(int)
  59. {
  60. auto temp = *this;
  61. ++(*this);
  62. return temp;
  63. }
  64. private:
  65. friend class param_list;
  66. const_iterator(iter_type first, iter_type last)
  67. {
  68. pi_.it = first;
  69. pi_.first = first;
  70. pi_.last = last;
  71. increment();
  72. }
  73. BOOST_BEAST_DECL
  74. static
  75. std::string
  76. unquote(string_view sr);
  77. BOOST_BEAST_DECL
  78. void
  79. increment();
  80. };
  81. inline
  82. auto
  83. param_list::
  84. begin() const ->
  85. const_iterator
  86. {
  87. return const_iterator{s_.begin(), s_.end()};
  88. }
  89. inline
  90. auto
  91. param_list::
  92. end() const ->
  93. const_iterator
  94. {
  95. return const_iterator{s_.end(), s_.end()};
  96. }
  97. inline
  98. auto
  99. param_list::
  100. cbegin() const ->
  101. const_iterator
  102. {
  103. return const_iterator{s_.begin(), s_.end()};
  104. }
  105. inline
  106. auto
  107. param_list::
  108. cend() const ->
  109. const_iterator
  110. {
  111. return const_iterator{s_.end(), s_.end()};
  112. }
  113. //------------------------------------------------------------------------------
  114. class ext_list::const_iterator
  115. {
  116. ext_list::value_type v_;
  117. iter_type it_;
  118. iter_type first_;
  119. iter_type last_;
  120. public:
  121. using value_type = ext_list::value_type;
  122. using pointer = value_type const*;
  123. using reference = value_type const&;
  124. using difference_type = std::ptrdiff_t;
  125. using iterator_category = std::forward_iterator_tag;
  126. const_iterator() = default;
  127. bool
  128. operator==(const_iterator const& other) const
  129. {
  130. return
  131. other.it_ == it_ &&
  132. other.first_ == first_ &&
  133. other.last_ == last_;
  134. }
  135. bool
  136. operator!=(const_iterator const& other) const
  137. {
  138. return !(*this == other);
  139. }
  140. reference
  141. operator*() const
  142. {
  143. return v_;
  144. }
  145. pointer
  146. operator->() const
  147. {
  148. return &*(*this);
  149. }
  150. const_iterator&
  151. operator++()
  152. {
  153. increment();
  154. return *this;
  155. }
  156. const_iterator
  157. operator++(int)
  158. {
  159. auto temp = *this;
  160. ++(*this);
  161. return temp;
  162. }
  163. private:
  164. friend class ext_list;
  165. const_iterator(iter_type begin, iter_type end)
  166. {
  167. it_ = begin;
  168. first_ = begin;
  169. last_ = end;
  170. increment();
  171. }
  172. BOOST_BEAST_DECL
  173. void
  174. increment();
  175. };
  176. inline
  177. auto
  178. ext_list::
  179. begin() const ->
  180. const_iterator
  181. {
  182. return const_iterator{s_.begin(), s_.end()};
  183. }
  184. inline
  185. auto
  186. ext_list::
  187. end() const ->
  188. const_iterator
  189. {
  190. return const_iterator{s_.end(), s_.end()};
  191. }
  192. inline
  193. auto
  194. ext_list::
  195. cbegin() const ->
  196. const_iterator
  197. {
  198. return const_iterator{s_.begin(), s_.end()};
  199. }
  200. inline
  201. auto
  202. ext_list::
  203. cend() const ->
  204. const_iterator
  205. {
  206. return const_iterator{s_.end(), s_.end()};
  207. }
  208. //------------------------------------------------------------------------------
  209. class token_list::const_iterator
  210. {
  211. token_list::value_type v_;
  212. iter_type it_;
  213. iter_type first_;
  214. iter_type last_;
  215. public:
  216. using value_type = token_list::value_type;
  217. using pointer = value_type const*;
  218. using reference = value_type const&;
  219. using difference_type = std::ptrdiff_t;
  220. using iterator_category = std::forward_iterator_tag;
  221. const_iterator() = default;
  222. bool
  223. operator==(const_iterator const& other) const
  224. {
  225. return
  226. other.it_ == it_ &&
  227. other.first_ == first_ &&
  228. other.last_ == last_;
  229. }
  230. bool
  231. operator!=(const_iterator const& other) const
  232. {
  233. return !(*this == other);
  234. }
  235. reference
  236. operator*() const
  237. {
  238. return v_;
  239. }
  240. pointer
  241. operator->() const
  242. {
  243. return &*(*this);
  244. }
  245. const_iterator&
  246. operator++()
  247. {
  248. increment();
  249. return *this;
  250. }
  251. const_iterator
  252. operator++(int)
  253. {
  254. auto temp = *this;
  255. ++(*this);
  256. return temp;
  257. }
  258. private:
  259. friend class token_list;
  260. const_iterator(iter_type begin, iter_type end)
  261. {
  262. it_ = begin;
  263. first_ = begin;
  264. last_ = end;
  265. increment();
  266. }
  267. BOOST_BEAST_DECL
  268. void
  269. increment();
  270. };
  271. inline
  272. auto
  273. token_list::
  274. begin() const ->
  275. const_iterator
  276. {
  277. return const_iterator{s_.begin(), s_.end()};
  278. }
  279. inline
  280. auto
  281. token_list::
  282. end() const ->
  283. const_iterator
  284. {
  285. return const_iterator{s_.end(), s_.end()};
  286. }
  287. inline
  288. auto
  289. token_list::
  290. cbegin() const ->
  291. const_iterator
  292. {
  293. return const_iterator{s_.begin(), s_.end()};
  294. }
  295. inline
  296. auto
  297. token_list::
  298. cend() const ->
  299. const_iterator
  300. {
  301. return const_iterator{s_.end(), s_.end()};
  302. }
  303. template<class Policy>
  304. bool
  305. validate_list(detail::basic_parsed_list<
  306. Policy> const& list)
  307. {
  308. auto const last = list.end();
  309. auto it = list.begin();
  310. if(it.error())
  311. return false;
  312. while(it != last)
  313. {
  314. ++it;
  315. if(it.error())
  316. return false;
  317. if(it == last)
  318. break;
  319. }
  320. return true;
  321. }
  322. } // http
  323. } // beast
  324. } // boost
  325. #ifdef BOOST_BEAST_HEADER_ONLY
  326. #include <boost/beast/http/impl/rfc7230.ipp>
  327. #endif
  328. #endif