/mordor/http/parser.h

http://github.com/mozy/mordor · C Header · 127 lines · 107 code · 17 blank · 3 comment · 0 complexity · 93f87bfcbd46f7315afcc0070b5d179e MD5 · raw file

  1. #ifndef __MORDOR_HTTP_PARSER_H__
  2. #define __MORDOR_HTTP_PARSER_H__
  3. // Copyright (c) 2009 - Mozy, Inc.
  4. #include "http.h"
  5. #include "mordor/ragel.h"
  6. namespace Mordor {
  7. namespace HTTP {
  8. struct BadFieldValueException : virtual Exception
  9. {
  10. const std::string name;
  11. const std::string value;
  12. BadFieldValueException(const std::string& k,
  13. const std::string& v)
  14. : name(k), value(v) {}
  15. ~BadFieldValueException() throw() {}
  16. };
  17. class Parser : public RagelParserWithStack
  18. {
  19. public:
  20. void init();
  21. protected:
  22. Parser(bool strict) : m_strict(strict) { init(); }
  23. const char *earliestPointer() const;
  24. void adjustPointers(ptrdiff_t offset);
  25. // Pointers to current headers
  26. std::string *m_string;
  27. StringSet *m_set;
  28. std::vector<std::string> *m_list;
  29. ParameterizedList *m_parameterizedList;
  30. AcceptList *m_acceptList;
  31. AcceptListWithParameters *m_acceptListWithParams;
  32. StringMap *m_parameters;
  33. AuthParams *m_auth;
  34. ChallengeList *m_challengeList;
  35. unsigned long long *m_ulong;
  36. ETag *m_eTag;
  37. Product m_product;
  38. std::set<ETag> *m_eTagSet;
  39. ProductAndCommentList *m_productAndCommentList;
  40. boost::posix_time::ptime *m_date;
  41. const bool m_strict;
  42. // Temp storage
  43. std::string m_temp1, m_temp2, m_genericHeaderName;
  44. const char *mark2;
  45. bool m_isBadValue;
  46. ETag m_tempETag;
  47. };
  48. class RequestParser : public Parser
  49. {
  50. public:
  51. RequestParser(Request& request, bool strict = false);
  52. void init();
  53. bool final() const;
  54. bool error() const;
  55. protected:
  56. void exec();
  57. private:
  58. Request *m_request;
  59. Version *m_ver;
  60. URI *m_uri;
  61. std::vector<std::string> *m_segments;
  62. URI::Authority *m_authority;
  63. GeneralHeaders *m_general;
  64. EntityHeaders *m_entity;
  65. };
  66. class ResponseParser : public Parser
  67. {
  68. public:
  69. ResponseParser(Response& response, bool strict = false);
  70. void init();
  71. bool final() const;
  72. bool error() const;
  73. protected:
  74. void exec();
  75. private:
  76. Response *m_response;
  77. Version *m_ver;
  78. URI *m_uri;
  79. std::vector<std::string> *m_segments;
  80. URI::Authority *m_authority;
  81. GeneralHeaders *m_general;
  82. EntityHeaders *m_entity;
  83. };
  84. class TrailerParser : public Parser
  85. {
  86. public:
  87. TrailerParser(EntityHeaders& entity, bool strict = false);
  88. void init();
  89. bool final() const;
  90. bool error() const;
  91. protected:
  92. void exec();
  93. private:
  94. EntityHeaders *m_entity;
  95. };
  96. class ListParser : public RagelParserWithStack
  97. {
  98. public:
  99. ListParser(StringSet &stringSet);
  100. void init();
  101. bool final() const;
  102. bool error() const;
  103. protected:
  104. void exec();
  105. private:
  106. StringSet *m_set;
  107. std::vector<std::string> *m_list;
  108. };
  109. }}
  110. #endif