diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
commit | ec05778d5718a7912e506764d443a78d6a6179e3 (patch) | |
tree | 78a9a01532180030c095acefc45763f07c14edb8 /src/stable/protocolhttp.cpp | |
parent | b20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff) | |
download | libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2 libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip |
Converted tabs to spaces with tabconv.
Diffstat (limited to 'src/stable/protocolhttp.cpp')
-rw-r--r-- | src/stable/protocolhttp.cpp | 362 |
1 files changed, 181 insertions, 181 deletions
diff --git a/src/stable/protocolhttp.cpp b/src/stable/protocolhttp.cpp index ea1a86e..352f7c7 100644 --- a/src/stable/protocolhttp.cpp +++ b/src/stable/protocolhttp.cpp | |||
@@ -8,7 +8,7 @@ | |||
8 | #include <dirent.h> | 8 | #include <dirent.h> |
9 | 9 | ||
10 | #ifndef WIN32 | 10 | #ifndef WIN32 |
11 | #include <sys/wait.h> | 11 | #include <sys/wait.h> |
12 | #endif | 12 | #endif |
13 | 13 | ||
14 | #include <errno.h> | 14 | #include <errno.h> |
@@ -32,9 +32,9 @@ Bu::ProtocolHttp::~ProtocolHttp() | |||
32 | 32 | ||
33 | void Bu::ProtocolHttp::onNewConnection( Bu::Client *pClient ) | 33 | void Bu::ProtocolHttp::onNewConnection( Bu::Client *pClient ) |
34 | { | 34 | { |
35 | this->pClient = pClient; | 35 | this->pClient = pClient; |
36 | 36 | ||
37 | iState = 0; | 37 | iState = 0; |
38 | } | 38 | } |
39 | 39 | ||
40 | #define SDB( i ) (void)0 | 40 | #define SDB( i ) (void)0 |
@@ -42,196 +42,196 @@ void Bu::ProtocolHttp::onNewConnection( Bu::Client *pClient ) | |||
42 | 42 | ||
43 | void Bu::ProtocolHttp::onNewData( Bu::Client *pClient ) | 43 | void Bu::ProtocolHttp::onNewData( Bu::Client *pClient ) |
44 | { | 44 | { |
45 | /* logHexDump( | 45 | /* logHexDump( |
46 | 1, | 46 | 1, |
47 | pClient->getInput().getStr(), | 47 | pClient->getInput().getStr(), |
48 | pClient->getInput().getSize(), | 48 | pClient->getInput().getSize(), |
49 | "input" | 49 | "input" |
50 | );*/ | 50 | );*/ |
51 | 51 | ||
52 | for(;;) | 52 | for(;;) |
53 | { | 53 | { |
54 | Bu::String sToken; | 54 | Bu::String sToken; |
55 | TokenType tt = getToken( sToken ); | 55 | TokenType tt = getToken( sToken ); |
56 | 56 | ||
57 | if( tt == ttOutOfData ) | 57 | if( tt == ttOutOfData ) |
58 | return; | 58 | return; |
59 | 59 | ||
60 | switch( iState ) | 60 | switch( iState ) |
61 | { | 61 | { |
62 | case 0: // Start token, should be "method" (get, put, etc) | 62 | case 0: // Start token, should be "method" (get, put, etc) |
63 | SDB( 0 ); | 63 | SDB( 0 ); |
64 | sMethod = sToken; | 64 | sMethod = sToken; |
65 | iState = 1; | 65 | iState = 1; |
66 | break; | 66 | break; |
67 | 67 | ||
68 | case 1: // The path requested | 68 | case 1: // The path requested |
69 | SDB( 1 ); | 69 | SDB( 1 ); |
70 | sPath = sToken; | 70 | sPath = sToken; |
71 | iState = 2; | 71 | iState = 2; |
72 | break; | 72 | break; |
73 | 73 | ||
74 | case 2: // The protocol name and version | 74 | case 2: // The protocol name and version |
75 | SDB( 2 ); | 75 | SDB( 2 ); |
76 | if( strncmp( sToken.getStr(), "HTTP/", 5 ) ) | 76 | if( strncmp( sToken.getStr(), "HTTP/", 5 ) ) |
77 | { | 77 | { |
78 | pClient->disconnect(); | 78 | pClient->disconnect(); |
79 | return; | 79 | return; |
80 | } | 80 | } |
81 | else | 81 | else |
82 | { | 82 | { |
83 | char *s, *s2; | 83 | char *s, *s2; |
84 | s = sToken.getStr()+5; | 84 | s = sToken.getStr()+5; |
85 | iMajor = strtol( s, &s2, 10 ); | 85 | iMajor = strtol( s, &s2, 10 ); |
86 | iMinor = strtol( s2+1, NULL, 10 ); | 86 | iMinor = strtol( s2+1, NULL, 10 ); |
87 | iState = 3; | 87 | iState = 3; |
88 | } | 88 | } |
89 | break; | 89 | break; |
90 | 90 | ||
91 | case 3: // End of initial header, now comes mime-style blocks. | 91 | case 3: // End of initial header, now comes mime-style blocks. |
92 | SDB( 3 ); | 92 | SDB( 3 ); |
93 | if( tt == ttNewline ) | 93 | if( tt == ttNewline ) |
94 | { | 94 | { |
95 | iState = 10; | 95 | iState = 10; |
96 | } | 96 | } |
97 | else if( tt == ttDoubleNewline ) | 97 | else if( tt == ttDoubleNewline ) |
98 | { | 98 | { |
99 | earlyResponse(); | 99 | earlyResponse(); |
100 | } | 100 | } |
101 | else | 101 | else |
102 | { | 102 | { |
103 | pClient->disconnect(); | 103 | pClient->disconnect(); |
104 | return; | 104 | return; |
105 | } | 105 | } |
106 | break; | 106 | break; |
107 | 107 | ||
108 | case 10: // HTTP-Message (skipped for now...) | 108 | case 10: // HTTP-Message (skipped for now...) |
109 | SDB( 10 ); | 109 | SDB( 10 ); |
110 | if( tt == ttString ) | 110 | if( tt == ttString ) |
111 | { | 111 | { |
112 | iState = 11; | 112 | iState = 11; |
113 | } | 113 | } |
114 | else | 114 | else |
115 | { | 115 | { |
116 | pClient->disconnect(); | 116 | pClient->disconnect(); |
117 | } | 117 | } |
118 | break; | 118 | break; |
119 | 119 | ||
120 | case 11: // Should be a colon... | 120 | case 11: // Should be a colon... |
121 | SDB( 11 ); | 121 | SDB( 11 ); |
122 | if( tt == ttSeperator && sToken == ":" ) | 122 | if( tt == ttSeperator && sToken == ":" ) |
123 | { | 123 | { |
124 | iState = 12; | 124 | iState = 12; |
125 | } | 125 | } |
126 | else | 126 | else |
127 | { | 127 | { |
128 | pClient->disconnect(); | 128 | pClient->disconnect(); |
129 | } | 129 | } |
130 | break; | 130 | break; |
131 | 131 | ||
132 | case 12: | 132 | case 12: |
133 | SDB( 12 ); | 133 | SDB( 12 ); |
134 | if( tt == ttNewline ) | 134 | if( tt == ttNewline ) |
135 | { | 135 | { |
136 | iState = 10; | 136 | iState = 10; |
137 | } | 137 | } |
138 | if( tt == ttDoubleNewline ) | 138 | if( tt == ttDoubleNewline ) |
139 | { | 139 | { |
140 | earlyResponse(); | 140 | earlyResponse(); |
141 | } | 141 | } |
142 | break; | 142 | break; |
143 | 143 | ||
144 | case 20: | 144 | case 20: |
145 | SDB( 20 ); | 145 | SDB( 20 ); |
146 | break; | 146 | break; |
147 | } | 147 | } |
148 | } | 148 | } |
149 | } | 149 | } |
150 | 150 | ||
151 | Bu::ProtocolHttp::TokenType Bu::ProtocolHttp::getToken( Bu::String &line ) | 151 | Bu::ProtocolHttp::TokenType Bu::ProtocolHttp::getToken( Bu::String &line ) |
152 | { | 152 | { |
153 | char s; | 153 | char s; |
154 | int jmax = pClient->getInputSize(); | 154 | int jmax = pClient->getInputSize(); |
155 | bool bNonWS = false; | 155 | bool bNonWS = false; |
156 | 156 | ||
157 | for( int j = 0; j < jmax; j++ ) | 157 | for( int j = 0; j < jmax; j++ ) |
158 | { | 158 | { |
159 | pClient->peek( &s, 1, j ); | 159 | pClient->peek( &s, 1, j ); |
160 | if( iState > 2 && isSeperator( s ) ) | 160 | if( iState > 2 && isSeperator( s ) ) |
161 | { | 161 | { |
162 | if( j == 0 ) | 162 | if( j == 0 ) |
163 | { | 163 | { |
164 | line += s; | 164 | line += s; |
165 | pClient->seek( 1 ); | 165 | pClient->seek( 1 ); |
166 | return ttSeperator; | 166 | return ttSeperator; |
167 | } | 167 | } |
168 | else | 168 | else |
169 | { | 169 | { |
170 | pClient->seek( j ); | 170 | pClient->seek( j ); |
171 | return ttString; | 171 | return ttString; |
172 | } | 172 | } |
173 | } | 173 | } |
174 | else if( isWS( s ) ) | 174 | else if( isWS( s ) ) |
175 | { | 175 | { |
176 | if( bNonWS ) | 176 | if( bNonWS ) |
177 | { | 177 | { |
178 | pClient->seek( j ); | 178 | pClient->seek( j ); |
179 | return ttString; | 179 | return ttString; |
180 | } | 180 | } |
181 | } | 181 | } |
182 | else if( s == CR ) | 182 | else if( s == CR ) |
183 | { | 183 | { |
184 | if( pClient->getInputSize() < 4 ) | 184 | if( pClient->getInputSize() < 4 ) |
185 | return ttOutOfData; | 185 | return ttOutOfData; |
186 | 186 | ||
187 | char ss[3]; | 187 | char ss[3]; |
188 | pClient->peek( ss, 3, j+1 ); | 188 | pClient->peek( ss, 3, j+1 ); |
189 | if( ss[0] == LF && ss[1] != ' ' && ss[1] != '\t' ) | 189 | if( ss[0] == LF && ss[1] != ' ' && ss[1] != '\t' ) |
190 | { | 190 | { |
191 | if( bNonWS ) | 191 | if( bNonWS ) |
192 | { | 192 | { |
193 | pClient->seek( j ); | 193 | pClient->seek( j ); |
194 | return ttString; | 194 | return ttString; |
195 | } | 195 | } |
196 | else if( ss[1] == CR && ss[2] == LF ) | 196 | else if( ss[1] == CR && ss[2] == LF ) |
197 | { | 197 | { |
198 | pClient->seek( 4 ); | 198 | pClient->seek( 4 ); |
199 | return ttDoubleNewline; | 199 | return ttDoubleNewline; |
200 | } | 200 | } |
201 | else | 201 | else |
202 | { | 202 | { |
203 | pClient->seek( 2 ); | 203 | pClient->seek( 2 ); |
204 | return ttNewline; | 204 | return ttNewline; |
205 | } | 205 | } |
206 | } | 206 | } |
207 | 207 | ||
208 | j += 2; | 208 | j += 2; |
209 | if( bNonWS ) | 209 | if( bNonWS ) |
210 | { | 210 | { |
211 | pClient->seek( j ); | 211 | pClient->seek( j ); |
212 | return ttString; | 212 | return ttString; |
213 | } | 213 | } |
214 | } | 214 | } |
215 | else | 215 | else |
216 | { | 216 | { |
217 | line += s; | 217 | line += s; |
218 | bNonWS = true; | 218 | bNonWS = true; |
219 | } | 219 | } |
220 | } | 220 | } |
221 | 221 | ||
222 | return ttOutOfData; | 222 | return ttOutOfData; |
223 | } | 223 | } |
224 | 224 | ||
225 | bool Bu::ProtocolHttp::isWS( char buf ) | 225 | bool Bu::ProtocolHttp::isWS( char buf ) |
226 | { | 226 | { |
227 | return (buf == ' ' || buf == '\t'); | 227 | return (buf == ' ' || buf == '\t'); |
228 | } | 228 | } |
229 | 229 | ||
230 | bool Bu::ProtocolHttp::isSeperator( char buf ) | 230 | bool Bu::ProtocolHttp::isSeperator( char buf ) |
231 | { | 231 | { |
232 | return (buf == '(' || buf == ')' || buf == '<' || buf == '>' || | 232 | return (buf == '(' || buf == ')' || buf == '<' || buf == '>' || |
233 | buf == '@' || buf == ',' || buf == ';' || buf == ':' || | 233 | buf == '@' || buf == ',' || buf == ';' || buf == ':' || |
234 | buf == '\\' || buf == '\"' || buf == '/' || buf == '[' || | 234 | buf == '\\' || buf == '\"' || buf == '/' || buf == '[' || |
235 | buf == ']' || buf == '?' || buf == '=' || buf == '{' || | 235 | buf == ']' || buf == '?' || buf == '=' || buf == '{' || |
236 | buf == '}' ); | 236 | buf == '}' ); |
237 | } | 237 | } |