libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit b4d4fb361f52d0d482f6b8371c0c4ffef4cce3e4
parent acfe67b3532b750843f68b8cb8e33824404aaa07
Author: Christian Grothoff <christian@grothoff.org>
Date:   Tue,  5 Jan 2010 15:42:19 +0000

code clean up

Diffstat:
Mdoc/examples/tlsauthentication.c | 79+++++++++++++++++++++++++++++++++++++++----------------------------------------
1 file changed, 39 insertions(+), 40 deletions(-)

diff --git a/doc/examples/tlsauthentication.c b/doc/examples/tlsauthentication.c @@ -10,7 +10,45 @@ #define SERVERKEYFILE "server.key" #define SERVERCERTFILE "server.pem" -char *string_to_base64 (const char *message); + +char * +string_to_base64 (const char *message) +{ + const char *lookup = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + unsigned long l; + int i; + char *tmp; + size_t length = strlen (message); + + tmp = malloc (length * 2); + if (NULL == tmp) + return tmp; + + tmp[0] = 0; + + for (i = 0; i < length; i += 3) + { + l = (((unsigned long) message[i]) << 16) + | (((i + 1) < length) ? (((unsigned long) message[i + 1]) << 8) : 0) + | (((i + 2) < length) ? ((unsigned long) message[i + 2]) : 0); + + + strncat (tmp, &lookup[(l >> 18) & 0x3F], 1); + strncat (tmp, &lookup[(l >> 12) & 0x3F], 1); + + if (i + 1 < length) + strncat (tmp, &lookup[(l >> 6) & 0x3F], 1); + if (i + 2 < length) + strncat (tmp, &lookup[l & 0x3F], 1); + } + + if (length % 3) + strncat (tmp, "===", 3 - length % 3); + + return tmp; +} + long get_file_size (const char *filename) @@ -218,42 +256,3 @@ main () return 0; } - - -char * -string_to_base64 (const char *message) -{ - const char *lookup = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - unsigned long l; - int i; - char *tmp; - size_t length = strlen (message); - - tmp = malloc (length * 2); - if (NULL == tmp) - return tmp; - - tmp[0] = 0; - - for (i = 0; i < length; i += 3) - { - l = (((unsigned long) message[i]) << 16) - | (((i + 1) < length) ? (((unsigned long) message[i + 1]) << 8) : 0) - | (((i + 2) < length) ? ((unsigned long) message[i + 2]) : 0); - - - strncat (tmp, &lookup[(l >> 18) & 0x3F], 1); - strncat (tmp, &lookup[(l >> 12) & 0x3F], 1); - - if (i + 1 < length) - strncat (tmp, &lookup[(l >> 6) & 0x3F], 1); - if (i + 2 < length) - strncat (tmp, &lookup[l & 0x3F], 1); - } - - if (length % 3) - strncat (tmp, "===", 3 - length % 3); - - return tmp; -}