uclient-utils.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * uclient - ustream based protocol client library
  3. *
  4. * Copyright (C) 2014 Felix Fietkau <nbd@openwrt.org>
  5. *
  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.
  9. *
  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.
  17. */
  18. #ifndef __UCLIENT_UTILS_H
  19. #define __UCLIENT_UTILS_H
  20. #include <stdbool.h>
  21. struct http_digest_data {
  22. const char *uri;
  23. const char *method;
  24. const char *auth_hash; /* H(A1) */
  25. const char *qop;
  26. const char *nc;
  27. const char *nonce;
  28. const char *cnonce;
  29. };
  30. static inline int base64_len(int len)
  31. {
  32. return ((len + 2) / 3) * 4;
  33. }
  34. void base64_encode(const void *inbuf, unsigned int len, void *out);
  35. void bin_to_hex(char *dest, const void *buf, int len);
  36. int uclient_urldecode(const char *in, char *out, bool decode_plus);
  37. void http_digest_calculate_auth_hash(char *dest, const char *user, const char *realm, const char *password);
  38. void http_digest_calculate_response(char *dest, const struct http_digest_data *data);
  39. #endif