|  | @@ -2274,6 +2274,34 @@ int mg_get_cookie(const char *cookie_header, const char *var_name,
 | 
	
		
			
				|  |  |      return len;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +#if defined(USE_WEBSOCKET) || defined(USE_LUA)
 | 
	
		
			
				|  |  | +static void base64_encode(const unsigned char *src, int src_len, char *dst)
 | 
	
		
			
				|  |  | +{
 | 
	
		
			
				|  |  | +    static const char *b64 =
 | 
	
		
			
				|  |  | +        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 | 
	
		
			
				|  |  | +    int i, j, a, b, c;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    for (i = j = 0; i < src_len; i += 3) {
 | 
	
		
			
				|  |  | +        a = src[i];
 | 
	
		
			
				|  |  | +        b = i + 1 >= src_len ? 0 : src[i + 1];
 | 
	
		
			
				|  |  | +        c = i + 2 >= src_len ? 0 : src[i + 2];
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        dst[j++] = b64[a >> 2];
 | 
	
		
			
				|  |  | +        dst[j++] = b64[((a & 3) << 4) | (b >> 4)];
 | 
	
		
			
				|  |  | +        if (i + 1 < src_len) {
 | 
	
		
			
				|  |  | +            dst[j++] = b64[(b & 15) << 2 | (c >> 6)];
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (i + 2 < src_len) {
 | 
	
		
			
				|  |  | +            dst[j++] = b64[c & 63];
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    while (j % 4 != 0) {
 | 
	
		
			
				|  |  | +        dst[j++] = '=';
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    dst[j++] = '\0';
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +#endif
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  static void convert_uri_to_file_name(struct mg_connection *conn, char *buf,
 | 
	
		
			
				|  |  |                                       size_t buf_len, struct file *filep,
 | 
	
		
			
				|  |  |                                       int * is_script_ressource)
 | 
	
	
		
			
				|  | @@ -4597,32 +4625,6 @@ static void SHA1Final(unsigned char digest[20], SHA1_CTX* context)
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  /* END OF SHA1 CODE */
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -static void base64_encode(const unsigned char *src, int src_len, char *dst)
 | 
	
		
			
				|  |  | -{
 | 
	
		
			
				|  |  | -    static const char *b64 =
 | 
	
		
			
				|  |  | -        "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 | 
	
		
			
				|  |  | -    int i, j, a, b, c;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -    for (i = j = 0; i < src_len; i += 3) {
 | 
	
		
			
				|  |  | -        a = src[i];
 | 
	
		
			
				|  |  | -        b = i + 1 >= src_len ? 0 : src[i + 1];
 | 
	
		
			
				|  |  | -        c = i + 2 >= src_len ? 0 : src[i + 2];
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -        dst[j++] = b64[a >> 2];
 | 
	
		
			
				|  |  | -        dst[j++] = b64[((a & 3) << 4) | (b >> 4)];
 | 
	
		
			
				|  |  | -        if (i + 1 < src_len) {
 | 
	
		
			
				|  |  | -            dst[j++] = b64[(b & 15) << 2 | (c >> 6)];
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        if (i + 2 < src_len) {
 | 
	
		
			
				|  |  | -            dst[j++] = b64[c & 63];
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -    while (j % 4 != 0) {
 | 
	
		
			
				|  |  | -        dst[j++] = '=';
 | 
	
		
			
				|  |  | -    }
 | 
	
		
			
				|  |  | -    dst[j++] = '\0';
 | 
	
		
			
				|  |  | -}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  static void send_websocket_handshake(struct mg_connection *conn)
 | 
	
		
			
				|  |  |  {
 | 
	
		
			
				|  |  |      static const char *magic = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
 |