Skip to content
This repository has been archived by the owner on Oct 8, 2020. It is now read-only.

Commit

Permalink
not tested. opening handshake
Browse files Browse the repository at this point in the history
  • Loading branch information
m8rge committed Aug 19, 2012
1 parent 02ca923 commit 6a06d03
Show file tree
Hide file tree
Showing 10 changed files with 620 additions and 348 deletions.
9 changes: 4 additions & 5 deletions README.md
@@ -1,8 +1,9 @@
## Overview
cWebsocket is lightweight websocket server library written in C. This library include functions for easy creating websocket server. It implements [websocket protocol draft 76](http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76).
cWebsocket is lightweight websocket server library written in C. This library include functions for easy creating websocket server. It implements [websocket protocol rfc6455](http://tools.ietf.org/html/rfc6455).

This comment has been minimized.

Copy link
@m8rge

m8rge Aug 19, 2012

Author Owner

#1 started upgrade to rfc6455


## Features
This library consist of one main cwebsocket.c file and md5 implementation files.
Pure C.
It's tiny!
It very easy to embed in any your application at any platform.
Library design was made with microcontrollers architecture in mind.

Expand All @@ -13,6 +14,4 @@ With this library you can get realtime properties from your microcontroller only
### Not supported
* frames with raw data (implemented, but not tested)
* non-latin characters in text frames

### Browser support
Google Chrome 6 (up to 6.0.472.0) doesn't have disconnect sequence. It just drops connection on `javascript:WebSocket.close()` method.
* websocket extensions
117 changes: 117 additions & 0 deletions base64_enc.c
@@ -0,0 +1,117 @@
/* base64_enc.c */
/*
* This file is part of the AVR-Crypto-Lib.
* Copyright (C) 2006, 2007, 2008 Daniel Otte (daniel.otte@rub.de)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


/**
* base64 encoder (RFC3548)
* Author: Daniel Otte
* License: GPLv3
*
*
*/

#include <stdint.h>
#include "base64_enc.h"

#if 1
#include <avr/pgmspace.h>

const char base64_alphabet[64] PROGMEM = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/' };

static
char bit6toAscii(uint8_t a){
a &= (uint8_t)0x3F;
return pgm_read_byte(base64_alphabet+a);
}

#else

static
char bit6toAscii(uint8_t a){
a &= (uint8_t)0x3F;

if(a<=25){
return a+'A';
} else {
if(a<=51){
return a-26+'a';
} else {
if(a<=61){
return a-52+'0';
} else {
if(a==62){
return '+';
} else {
return '/'; /* a == 63 */
}
}
}
}
}

#endif

void base64enc(char* dest,const void* src, uint16_t length){
uint16_t i,j;
uint8_t a[4];
for(i=0; i<length/3; ++i){
a[0]= (((uint8_t*)src)[i*3+0])>>2;
a[1]= (((((uint8_t*)src)[i*3+0])<<4) | ((((uint8_t*)src)[i*3+1])>>4)) & 0x3F;
a[2]= (((((uint8_t*)src)[i*3+1])<<2) | ((((uint8_t*)src)[i*3+2])>>6)) & 0x3F;
a[3]= (((uint8_t*)src)[i*3+2]) & 0x3F;
for(j=0; j<4; ++j){
*dest++=bit6toAscii(a[j]);
}
}
/* now we do the rest */
switch(length%3){
case 0:
break;
case 1:
a[0]=(((uint8_t*)src)[i*3+0])>>2;
a[1]=((((uint8_t*)src)[i*3+0])<<4)&0x3F;
*dest++ = bit6toAscii(a[0]);
*dest++ = bit6toAscii(a[1]);
*dest++ = '=';
*dest++ = '=';
break;
case 2:
a[0]= (((uint8_t*)src)[i*3+0])>>2;
a[1]= (((((uint8_t*)src)[i*3+0])<<4) | ((((uint8_t*)src)[i*3+1])>>4)) & 0x3F;
a[2]= ((((uint8_t*)src)[i*3+1])<<2) & 0x3F;
*dest++ = bit6toAscii(a[0]);
*dest++ = bit6toAscii(a[1]);
*dest++ = bit6toAscii(a[2]);
*dest++ = '=';
break;
default: /* this will not happen! */
break;
}
/* finalize: */
*dest='\0';
}

28 changes: 28 additions & 0 deletions base64_enc.h
@@ -0,0 +1,28 @@
/* base64_enc.h */
/*
* This file is part of the AVR-Crypto-Lib.
* Copyright (C) 2006, 2007, 2008 Daniel Otte (daniel.otte@rub.de)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/


#ifndef BASE64_ENC_H_
#define BASE64_ENC_H_

#include <stdint.h>

void base64enc(char* dest, const void* src, uint16_t length);

#endif /*BASE64_ENC_H_*/
18 changes: 18 additions & 0 deletions main.c
@@ -0,0 +1,18 @@
/*
* File: main.c
* Author: merge
*
* Created on August 19, 2012, 10:04 PM
*/

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

/*
*
*/
int main(int argc, char** argv) {

return (EXIT_SUCCESS);
}

186 changes: 0 additions & 186 deletions md5.c

This file was deleted.

0 comments on commit 6a06d03

Please sign in to comment.