正在显示
1 个修改的文件
包含
146 行增加
和
0 行删除
src/server/spserver/sphttpmsg.hpp
0 → 100644
1 | +/* | ||
2 | + * Copyright 2007 Stephen Liu | ||
3 | + * For license terms, see the file COPYING along with this library. | ||
4 | + */ | ||
5 | + | ||
6 | +#ifndef __sphttpmsg_hpp__ | ||
7 | +#define __sphttpmsg_hpp__ | ||
8 | + | ||
9 | +class SP_ArrayList; | ||
10 | +class SP_HttpRequest; | ||
11 | +class SP_HttpResponse; | ||
12 | +class SP_HttpMessage; | ||
13 | + | ||
14 | +class SP_HttpMsgParser { | ||
15 | +public: | ||
16 | + SP_HttpMsgParser(); | ||
17 | + ~SP_HttpMsgParser(); | ||
18 | + | ||
19 | + void setIgnoreContent( int ignoreContent ); | ||
20 | + int isIgnoreContent() const; | ||
21 | + | ||
22 | + int append( const void * buffer, int len ); | ||
23 | + | ||
24 | + // 0 : incomplete, 1 : complete | ||
25 | + int isCompleted() const; | ||
26 | + | ||
27 | + SP_HttpRequest * getRequest() const; | ||
28 | + | ||
29 | + SP_HttpResponse * getResponse() const; | ||
30 | + | ||
31 | +private: | ||
32 | + static int parseStartLine( SP_HttpMessage ** message, | ||
33 | + const void * buffer, int len ); | ||
34 | + static int parseHeader( SP_HttpMessage * message, | ||
35 | + const void * buffer, int len ); | ||
36 | + static int parseChunked( SP_HttpMessage * message, | ||
37 | + const void * buffer, int len, int * status ); | ||
38 | + static int parseContent( SP_HttpMessage * message, | ||
39 | + const void * buffer, int len, int * status ); | ||
40 | + static void postProcess( SP_HttpMessage * message ); | ||
41 | + | ||
42 | + static int getLine( const void * buffer, int len, char * line, int size ); | ||
43 | + | ||
44 | + SP_HttpMessage * mMessage; | ||
45 | + | ||
46 | + enum { eStartLine, eHeader, eContent, eCompleted }; | ||
47 | + int mStatus; | ||
48 | + | ||
49 | + int mIgnoreContent; | ||
50 | +}; | ||
51 | + | ||
52 | +class SP_HttpMessage { | ||
53 | +public: | ||
54 | + static const char * HEADER_CONTENT_LENGTH; | ||
55 | + static const char * HEADER_CONTENT_TYPE; | ||
56 | + static const char * HEADER_CONNECTION; | ||
57 | + static const char * HEADER_PROXY_CONNECTION; | ||
58 | + static const char * HEADER_TRANSFER_ENCODING; | ||
59 | + static const char * HEADER_DATE; | ||
60 | + static const char * HEADER_SERVER; | ||
61 | + | ||
62 | +public: | ||
63 | + SP_HttpMessage( int type ); | ||
64 | + virtual ~SP_HttpMessage(); | ||
65 | + | ||
66 | + enum { eRequest, eResponse }; | ||
67 | + int getType() const; | ||
68 | + | ||
69 | + void setVersion( const char * version ); | ||
70 | + const char * getVersion() const; | ||
71 | + | ||
72 | + void appendContent( const void * content, int length = 0, int maxLength = 0 ); | ||
73 | + void setContent( const void * content, int length = 0 ); | ||
74 | + void directSetContent( void * content, int length = 0 ); | ||
75 | + const void * getContent() const; | ||
76 | + int getContentLength() const; | ||
77 | + | ||
78 | + void addHeader( const char * name, const char * value ); | ||
79 | + int removeHeader( const char * name ); | ||
80 | + int removeHeader( int index ); | ||
81 | + int getHeaderCount() const; | ||
82 | + const char * getHeaderName( int index ) const; | ||
83 | + const char * getHeaderValue( int index ) const; | ||
84 | + const char * getHeaderValue( const char * name ) const; | ||
85 | + | ||
86 | + int isKeepAlive() const; | ||
87 | + | ||
88 | +protected: | ||
89 | + const int mType; | ||
90 | + | ||
91 | + char mVersion[ 16 ]; | ||
92 | + void * mContent; | ||
93 | + int mMaxLength, mContentLength; | ||
94 | + | ||
95 | + SP_ArrayList * mHeaderNameList, * mHeaderValueList; | ||
96 | +}; | ||
97 | + | ||
98 | +class SP_HttpRequest : public SP_HttpMessage { | ||
99 | +public: | ||
100 | + SP_HttpRequest(); | ||
101 | + virtual ~SP_HttpRequest(); | ||
102 | + | ||
103 | + void setMethod( const char * method ); | ||
104 | + const char * getMethod() const; | ||
105 | + | ||
106 | + void setURI( const char * uri ); | ||
107 | + const char * getURI() const; | ||
108 | + | ||
109 | + void setURL( const char * url ); | ||
110 | + const char * getURL() const; | ||
111 | + | ||
112 | + void setClinetIP( const char * clientIP ); | ||
113 | + const char * getClientIP() const; | ||
114 | + | ||
115 | + void addParam( const char * name, const char * value ); | ||
116 | + int removeParam( const char * name ); | ||
117 | + int getParamCount() const; | ||
118 | + const char * getParamName( int index ) const; | ||
119 | + const char * getParamValue( int index ) const; | ||
120 | + const char * getParamValue( const char * name ) const; | ||
121 | + | ||
122 | +private: | ||
123 | + char mMethod[ 16 ], mClientIP[ 16 ]; | ||
124 | + char * mURI, * mURL; | ||
125 | + | ||
126 | + SP_ArrayList * mParamNameList, * mParamValueList; | ||
127 | +}; | ||
128 | + | ||
129 | +class SP_HttpResponse : public SP_HttpMessage { | ||
130 | +public: | ||
131 | + SP_HttpResponse(); | ||
132 | + virtual ~SP_HttpResponse(); | ||
133 | + | ||
134 | + void setStatusCode( int statusCode ); | ||
135 | + int getStatusCode() const; | ||
136 | + | ||
137 | + void setReasonPhrase( const char * reasonPhrase ); | ||
138 | + const char * getReasonPhrase() const; | ||
139 | + | ||
140 | +private: | ||
141 | + int mStatusCode; | ||
142 | + char mReasonPhrase[ 128 ]; | ||
143 | +}; | ||
144 | + | ||
145 | +#endif | ||
146 | + |
请
注册
或
登录
后发表评论