My fork of the HTTPServer (working)
Core/arch/iputil.c@0:7a64fbb4069d, 2012-08-06 (annotated)
- Committer:
- screamer
- Date:
- Mon Aug 06 09:23:14 2012 +0000
- Revision:
- 0:7a64fbb4069d
[mbed] converted /DGWWebServer/HTTPServer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
screamer | 0:7a64fbb4069d | 1 | #include "iputil.h" |
screamer | 0:7a64fbb4069d | 2 | |
screamer | 0:7a64fbb4069d | 3 | unsigned int base64enc_len(const char *str) { |
screamer | 0:7a64fbb4069d | 4 | return (((strlen(str)-1)/3)+1)<<2; |
screamer | 0:7a64fbb4069d | 5 | } |
screamer | 0:7a64fbb4069d | 6 | |
screamer | 0:7a64fbb4069d | 7 | void base64enc(const char *input, unsigned int length, char *output) { |
screamer | 0:7a64fbb4069d | 8 | static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
screamer | 0:7a64fbb4069d | 9 | unsigned int c, c1, c2, c3; |
screamer | 0:7a64fbb4069d | 10 | for(unsigned int i = 0, j = 0; i<length; i+=3,j+=4) { |
screamer | 0:7a64fbb4069d | 11 | c1 = ((((unsigned char)*((unsigned char *)&input[i])))); |
screamer | 0:7a64fbb4069d | 12 | c2 = (length>i+1)?((((unsigned char)*((unsigned char *)&input[i+1])))):0; |
screamer | 0:7a64fbb4069d | 13 | c3 = (length>i+2)?((((unsigned char)*((unsigned char *)&input[i+2])))):0; |
screamer | 0:7a64fbb4069d | 14 | |
screamer | 0:7a64fbb4069d | 15 | c = ((c1 & 0xFC) >> 2); |
screamer | 0:7a64fbb4069d | 16 | output[j+0] = base64[c]; |
screamer | 0:7a64fbb4069d | 17 | c = ((c1 & 0x03) << 4) | ((c2 & 0xF0) >> 4); |
screamer | 0:7a64fbb4069d | 18 | output[j+1] = base64[c]; |
screamer | 0:7a64fbb4069d | 19 | c = ((c2 & 0x0F) << 2) | ((c3 & 0xC0) >> 6); |
screamer | 0:7a64fbb4069d | 20 | output[j+2] = (length>i+1)?base64[c]:'='; |
screamer | 0:7a64fbb4069d | 21 | c = (c3 & 0x3F); |
screamer | 0:7a64fbb4069d | 22 | output[j+3] = (length>i+2)?base64[c]:'='; |
screamer | 0:7a64fbb4069d | 23 | } |
screamer | 0:7a64fbb4069d | 24 | output[(((length-1)/3)+1)<<2] = '\0'; |
screamer | 0:7a64fbb4069d | 25 | } |