aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/unstable/protocolwebsocket.cpp36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/unstable/protocolwebsocket.cpp b/src/unstable/protocolwebsocket.cpp
index 756c177..3c0d091 100644
--- a/src/unstable/protocolwebsocket.cpp
+++ b/src/unstable/protocolwebsocket.cpp
@@ -158,14 +158,17 @@ bool Bu::ProtocolWebSocket::stateProtoId()
158 158
159bool Bu::ProtocolWebSocket::stateHandshake() 159bool Bu::ProtocolWebSocket::stateHandshake()
160{ 160{
161 DEBUG( Bu::println("websocket: Begining handshake.") ); 161 DEBUG( Bu::println("websocket: Processing header line (stateHandshake).") );
162 162
163 Bu::String sLine; 163 Bu::String sLine;
164 if( !readHttpHdrLine( sLine ) ) 164 if( !readHttpHdrLine( sLine ) )
165 return false; 165 return false;
166
167 DEBUG( Bu::println("Hdr: >>%1<<").arg( sLine ) );
166 168
167 if( sLine.getSize() == 0 ) 169 if( sLine.getSize() == 0 )
168 { 170 {
171 DEBUG( Bu::println("websocket: Out of header lines, completing handshake.") );
169 if( !processHeaders() ) 172 if( !processHeaders() )
170 return false; 173 return false;
171 onHandshakeComplete(); 174 onHandshakeComplete();
@@ -191,26 +194,39 @@ bool Bu::ProtocolWebSocket::stateHandshake()
191 } 194 }
192 hHeader.get( sKey ).append( sValue ); 195 hHeader.get( sKey ).append( sValue );
193 196
194 DEBUG( Bu::println("Hdr: >>%1<<").arg( sLine ) ); 197 DEBUG( Bu::println(" -->%1 = %2").arg( sKey ).arg( sValue ) );
195 DEBUG( Bu::println("%1 = %2").arg( sKey ).arg( sValue ) );
196 198
197 return true; 199 return true;
198} 200}
199 201
200bool Bu::ProtocolWebSocket::readHttpHdrLine( Bu::String &sLine ) 202bool Bu::ProtocolWebSocket::readHttpHdrLine( Bu::String &sLine )
201{ 203{
202 char buf[1024]; 204#define BUF_SIZ 512
203 int iSize = pClient->peek( buf, 1024 ); 205 char buf[BUF_SIZ];
204 for( int j = 0; j < iSize-1; j++ ) 206 int iOffset = 0;
207 sLine.clear();
208 for(;;)
205 { 209 {
206 if( buf[j] == '\r' && buf[j+1] == '\n' ) 210 int iSize = pClient->peek( buf, BUF_SIZ, iOffset );
211 DEBUG( Bu::println(" $$ readHttpHdrLine: peek found %1 bytes (%1 offset).").arg( iSize ).arg( iOffset ) );
212 for( int j = 0; j < iSize-1; j++ )
207 { 213 {
208 pClient->seek(j+2); 214 if( buf[j] == '\r' && buf[j+1] == '\n' )
209 sLine.set( buf, j ); 215 {
210 return true; 216 pClient->seek(iOffset+j+2);
217 sLine.append( buf, j );
218 return true;
219 }
211 } 220 }
221
222 if( iSize < BUF_SIZ )
223 return false;
224
225 sLine.append( buf, iSize );
226 iOffset += BUF_SIZ;
212 } 227 }
213 return false; 228 return false;
229#undef BUF_SIZ
214} 230}
215 231
216bool Bu::ProtocolWebSocket::processHeaders() 232bool Bu::ProtocolWebSocket::processHeaders()