Brandon Fictorie / Mbed 2 deprecated BF_Websocket

Dependencies:   mbed

Committer:
bfictorie
Date:
Sun Mar 25 17:26:30 2012 +0000
Revision:
0:8cdad1c73e8e

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bfictorie 0:8cdad1c73e8e 1
bfictorie 0:8cdad1c73e8e 2 /*
bfictorie 0:8cdad1c73e8e 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
bfictorie 0:8cdad1c73e8e 4
bfictorie 0:8cdad1c73e8e 5 Permission is hereby granted, free of charge, to any person obtaining a copy
bfictorie 0:8cdad1c73e8e 6 of this software and associated documentation files (the "Software"), to deal
bfictorie 0:8cdad1c73e8e 7 in the Software without restriction, including without limitation the rights
bfictorie 0:8cdad1c73e8e 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
bfictorie 0:8cdad1c73e8e 9 copies of the Software, and to permit persons to whom the Software is
bfictorie 0:8cdad1c73e8e 10 furnished to do so, subject to the following conditions:
bfictorie 0:8cdad1c73e8e 11
bfictorie 0:8cdad1c73e8e 12 The above copyright notice and this permission notice shall be included in
bfictorie 0:8cdad1c73e8e 13 all copies or substantial portions of the Software.
bfictorie 0:8cdad1c73e8e 14
bfictorie 0:8cdad1c73e8e 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
bfictorie 0:8cdad1c73e8e 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
bfictorie 0:8cdad1c73e8e 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
bfictorie 0:8cdad1c73e8e 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
bfictorie 0:8cdad1c73e8e 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
bfictorie 0:8cdad1c73e8e 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
bfictorie 0:8cdad1c73e8e 21 THE SOFTWARE.
bfictorie 0:8cdad1c73e8e 22 */
bfictorie 0:8cdad1c73e8e 23
bfictorie 0:8cdad1c73e8e 24 #include "base64.h"
bfictorie 0:8cdad1c73e8e 25 //Originaly from Rolf's iputil.c
bfictorie 0:8cdad1c73e8e 26
bfictorie 0:8cdad1c73e8e 27 #ifdef __cplusplus
bfictorie 0:8cdad1c73e8e 28 extern "C" {
bfictorie 0:8cdad1c73e8e 29 #endif
bfictorie 0:8cdad1c73e8e 30
bfictorie 0:8cdad1c73e8e 31 #include <string.h>
bfictorie 0:8cdad1c73e8e 32
bfictorie 0:8cdad1c73e8e 33 unsigned int base64enc_len(const char* str) {
bfictorie 0:8cdad1c73e8e 34 return (((strlen(str)-1)/3)+1)<<2;
bfictorie 0:8cdad1c73e8e 35 }
bfictorie 0:8cdad1c73e8e 36
bfictorie 0:8cdad1c73e8e 37 void base64enc(const char *input, unsigned int length, char *output) {
bfictorie 0:8cdad1c73e8e 38 static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
bfictorie 0:8cdad1c73e8e 39 unsigned int c, c1, c2, c3;
bfictorie 0:8cdad1c73e8e 40 for(unsigned int i = 0, j = 0; i<length; i+=3,j+=4) {
bfictorie 0:8cdad1c73e8e 41 c1 = ((((unsigned char)*((unsigned char *)&input[i]))));
bfictorie 0:8cdad1c73e8e 42 c2 = (length>i+1)?((((unsigned char)*((unsigned char *)&input[i+1])))):0;
bfictorie 0:8cdad1c73e8e 43 c3 = (length>i+2)?((((unsigned char)*((unsigned char *)&input[i+2])))):0;
bfictorie 0:8cdad1c73e8e 44
bfictorie 0:8cdad1c73e8e 45 c = ((c1 & 0xFC) >> 2);
bfictorie 0:8cdad1c73e8e 46 output[j+0] = base64[c];
bfictorie 0:8cdad1c73e8e 47 c = ((c1 & 0x03) << 4) | ((c2 & 0xF0) >> 4);
bfictorie 0:8cdad1c73e8e 48 output[j+1] = base64[c];
bfictorie 0:8cdad1c73e8e 49 c = ((c2 & 0x0F) << 2) | ((c3 & 0xC0) >> 6);
bfictorie 0:8cdad1c73e8e 50 output[j+2] = (length>i+1)?base64[c]:'=';
bfictorie 0:8cdad1c73e8e 51 c = (c3 & 0x3F);
bfictorie 0:8cdad1c73e8e 52 output[j+3] = (length>i+2)?base64[c]:'=';
bfictorie 0:8cdad1c73e8e 53 }
bfictorie 0:8cdad1c73e8e 54 output[(((length-1)/3)+1)<<2] = '\0';
bfictorie 0:8cdad1c73e8e 55 }
bfictorie 0:8cdad1c73e8e 56
bfictorie 0:8cdad1c73e8e 57 #ifdef __cplusplus
bfictorie 0:8cdad1c73e8e 58 }
bfictorie 0:8cdad1c73e8e 59 #endif
bfictorie 0:8cdad1c73e8e 60