thttp_auth.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (C) 2010-2011 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with DOUBANGO.
  20. *
  21. */
  22. /**@file thttp_auth.h
  23. * @brief HTTP basic/digest authetication (RFC 2617) implementations.
  24. *
  25. * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
  26. *
  27. */
  28. #ifndef TINYHTTP_THTTP_AUTH_H
  29. #define TINYHTTP_THTTP_AUTH_H
  30. #include "tinyhttp_config.h"
  31. #include "tsk_md5.h"
  32. #include "tsk_buffer.h"
  33. THTTP_BEGIN_DECLS
  34. typedef char nonce_count_t[9];
  35. typedef char thttp_auth_ws_keystring_t[255];
  36. #define THTTP_NCOUNT_2_STRING(nc_int32, nc_string) \
  37. { \
  38. tsk_size_t i = 7; \
  39. do{ \
  40. nc_string[7-i]= "0123456789abcdef"[(nc_int32 >> i*4) & 0xF]; \
  41. } \
  42. while(i--); \
  43. nc_string[8] = '\0'; \
  44. }
  45. TINYHTTP_API tsk_size_t thttp_auth_basic_response(const char* userid, const char* password, char** response);
  46. TINYHTTP_API int thttp_auth_digest_HA1(const char* username, const char* realm, const char* password, tsk_md5string_t* ha1);
  47. TINYHTTP_API int thttp_auth_digest_HA1sess(const char* username, const char* realm, const char* password, const char* nonce, const char* cnonce, tsk_md5string_t* ha1sess);
  48. TINYHTTP_API int thttp_auth_digest_HA2(const char* method, const char* url, const tsk_buffer_t* entity_body, const char* qop, tsk_md5string_t* ha2);
  49. TINYHTTP_API int thttp_auth_digest_response(const tsk_md5string_t *ha1, const char* nonce, const nonce_count_t noncecount, const char* cnonce,
  50. const char* qop, const tsk_md5string_t* ha2, tsk_md5string_t* response);
  51. TINYHTTP_API tsk_size_t thttp_auth_ws_response(const char* key, thttp_auth_ws_keystring_t* response);
  52. THTTP_END_DECLS
  53. #endif /* TINYHTTP_THTTP_H */