tls.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // One of the headers for HaxServ
  2. //
  3. // Written by: Test_User <hax@andrewyu.org>
  4. //
  5. // This is free and unencumbered software released into the public
  6. // domain.
  7. //
  8. // Anyone is free to copy, modify, publish, use, compile, sell, or
  9. // distribute this software, either in source code form or as a compiled
  10. // binary, for any purpose, commercial or non-commercial, and by any
  11. // means.
  12. //
  13. // In jurisdictions that recognize copyright laws, the author or authors
  14. // of this software dedicate any and all copyright interest in the
  15. // software to the public domain. We make this dedication for the benefit
  16. // of the public at large and to the detriment of our heirs and
  17. // successors. We intend this dedication to be an overt act of
  18. // relinquishment in perpetuity of all present and future rights to this
  19. // software under copyright law.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  24. // IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  25. // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  26. // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  27. // OTHER DEALINGS IN THE SOFTWARE.
  28. #include <gnutls/gnutls.h>
  29. #if LOGALL
  30. extern ssize_t SEND(struct string msg);
  31. #else
  32. #define SEND(x) gnutls_record_send(session, x.data, x.len)
  33. #endif
  34. extern gnutls_session_t session;
  35. extern int connect_tls(void);
  36. inline size_t RECV(char *buf, size_t buflen, char *timeout) {
  37. int len;
  38. do {
  39. len = gnutls_record_recv(session, buf, buflen);
  40. } while (len == GNUTLS_E_AGAIN || len == GNUTLS_E_INTERRUPTED);
  41. *timeout = (len == GNUTLS_E_TIMEDOUT);
  42. if (len < 0)
  43. return 0;
  44. else
  45. return (size_t)len;
  46. }