2 * uclient - ustream based protocol client library
4 * Copyright (C) 2014 Felix Fietkau <nbd@openwrt.org>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #ifndef __UCLIENT_UTILS_H
19 #define __UCLIENT_UTILS_H
23 struct http_digest_data
{
27 const char *auth_hash
; /* H(A1) */
34 static inline int base64_len(int len
)
36 return ((len
+ 2) / 3) * 4;
39 void base64_encode(const void *inbuf
, unsigned int len
, void *out
);
40 void bin_to_hex(char *dest
, const void *buf
, int len
);
42 int uclient_urldecode(const char *in
, char *out
, bool decode_plus
);
44 void http_digest_calculate_auth_hash(char *dest
, const char *user
, const char *realm
, const char *password
);
45 void http_digest_calculate_response(char *dest
, const struct http_digest_data
*data
);
47 char *uclient_get_url_filename(const char *url
, const char *default_name
);