Skip to content

Commit

Permalink
Websockets :
Browse files Browse the repository at this point in the history
- Backward compatibility (< rev 76)
  • Loading branch information
paraboul committed Jul 4, 2010
1 parent fc14397 commit 8e1f24b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 100 deletions.
4 changes: 3 additions & 1 deletion src/handle_http.c
Expand Up @@ -149,7 +149,9 @@ subuser *checkrecv(ape_socket *co, acetables *g_ape)
sendbin(co->fd, http->host, strlen(http->host), 0, g_ape); sendbin(co->fd, http->host, strlen(http->host), 0, g_ape);
sendbin(co->fd, http->uri, strlen(http->uri), 0, g_ape); sendbin(co->fd, http->uri, strlen(http->uri), 0, g_ape);
sendbin(co->fd, CONST_STR_LEN("\r\n\r\n"), 0, g_ape); sendbin(co->fd, CONST_STR_LEN("\r\n\r\n"), 0, g_ape);
sendbin(co->fd, (char *)md5sum, 16, 0, g_ape); if (is_rev_76) {
sendbin(co->fd, (char *)md5sum, 16, 0, g_ape);
}
FLUSH_TCP(co->fd); FLUSH_TCP(co->fd);




Expand Down
6 changes: 5 additions & 1 deletion src/http.c
Expand Up @@ -182,7 +182,7 @@ void process_http(ape_socket *co, acetables *g_ape)
/* TODO : endieness */ /* TODO : endieness */
switch(*(unsigned int *)data) { switch(*(unsigned int *)data) {
case 542393671: /* GET + space */ case 542393671: /* GET + space */
http->type = (*(unsigned int *)&data[4] == (0x202F002F | WS_MAGIC_VALUE) ? HTTP_GET_WS : HTTP_GET); /* hack : check for WebSockets URI (/6/) */ http->type = HTTP_GET;
p = 4; p = 4;
break; break;
case 1414745936: /* POST */ case 1414745936: /* POST */
Expand Down Expand Up @@ -285,6 +285,10 @@ void process_http(ape_socket *co, acetables *g_ape)
http->contentlength = cl; http->contentlength = cl;


} }
} else if (http->type == HTTP_GET) {
if (strncasecmp("Sec-WebSocket-Key1: ", data, 20) == 0) {
http->type = HTTP_GET_WS;
}
} }
} }
http->pos += pos; http->pos += pos;
Expand Down
98 changes: 0 additions & 98 deletions src/md5.c
Expand Up @@ -252,102 +252,4 @@ void md5_finish( md5_context *ctx, uint8 digest[16] )
PUT_UINT32( ctx->state[3], digest, 12 ); PUT_UINT32( ctx->state[3], digest, 12 );
} }


#ifdef TEST

#include <stdlib.h>
#include <stdio.h>

/*
* those are the standard RFC 1321 test vectors
*/

static char *msg[] =
{
"",
"a",
"abc",
"message digest",
"abcdefghijklmnopqrstuvwxyz",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"12345678901234567890123456789012345678901234567890123456789012" \
"345678901234567890"
};

static char *val[] =
{
"d41d8cd98f00b204e9800998ecf8427e",
"0cc175b9c0f1b6a831c399e269772661",
"900150983cd24fb0d6963f7d28e17f72",
"f96b697d7cb7938d525a2f31aaf161d0",
"c3fcd3d76192e4007dfb496cca67e13b",
"d174ab98d277d9f5a5611c2c9f419d9f",
"57edf4a22be3c955ac49da2e2107b67a"
};

int main( int argc, char *argv[] )
{
FILE *f;
int i, j;
char output[33];
md5_context ctx;
unsigned char buf[1000];
unsigned char md5sum[16];

if( argc < 2 )
{
printf( "\n MD5 Validation Tests:\n\n" );

for( i = 0; i < 7; i++ )
{
printf( " Test %d ", i + 1 );

md5_starts( &ctx );
md5_update( &ctx, (uint8 *) msg[i], strlen( msg[i] ) );
md5_finish( &ctx, md5sum );

for( j = 0; j < 16; j++ )
{
sprintf( output + j * 2, "%02x", md5sum[j] );
}

if( memcmp( output, val[i], 32 ) )
{
printf( "failed!\n" );
return( 1 );
}

printf( "passed.\n" );
}

printf( "\n" );
}
else
{
if( ! ( f = fopen( argv[1], "rb" ) ) )
{
perror( "fopen" );
return( 1 );
}

md5_starts( &ctx );

while( ( i = fread( buf, 1, sizeof( buf ), f ) ) > 0 )
{
md5_update( &ctx, buf, i );
}

md5_finish( &ctx, md5sum );

for( j = 0; j < 16; j++ )
{
printf( "%02x", md5sum[j] );
}

printf( " %s\n", argv[1] );
}

return( 0 );
}

#endif


0 comments on commit 8e1f24b

Please sign in to comment.