PageRenderTime 15ms CodeModel.GetById 8ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

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