BSSLConnection.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * @file BSSLConnection.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN 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 along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. */
  22. #ifndef BADVPN_BSSLCONNECTION_H
  23. #define BADVPN_BSSLCONNECTION_H
  24. #include <prio.h>
  25. #include <misc/debug.h>
  26. #include <misc/debugerror.h>
  27. #include <base/DebugObject.h>
  28. #include <system/BReactor.h>
  29. #include <flow/StreamPassInterface.h>
  30. #include <flow/StreamRecvInterface.h>
  31. #define BSSLCONNECTION_EVENT_UP 1
  32. #define BSSLCONNECTION_EVENT_ERROR 2
  33. #define BSSLCONNECTION_BUF_SIZE 4096
  34. typedef void (*BSSLConnection_handler) (void *user, int event);
  35. struct BSSLConnection_backend;
  36. typedef struct {
  37. PRFileDesc *prfd;
  38. BReactor *reactor;
  39. void *user;
  40. BSSLConnection_handler handler;
  41. struct BSSLConnection_backend *backend;
  42. int have_error;
  43. int up;
  44. BPending init_job;
  45. StreamPassInterface send_if;
  46. StreamRecvInterface recv_if;
  47. BPending recv_job;
  48. const uint8_t *send_data;
  49. int send_len;
  50. uint8_t *recv_data;
  51. int recv_avail;
  52. DebugError d_err;
  53. DebugObject d_obj;
  54. } BSSLConnection;
  55. struct BSSLConnection_backend {
  56. StreamPassInterface *send_if;
  57. StreamRecvInterface *recv_if;
  58. BSSLConnection *con;
  59. uint8_t send_buf[BSSLCONNECTION_BUF_SIZE];
  60. int send_pos;
  61. int send_len;
  62. uint8_t recv_buf[BSSLCONNECTION_BUF_SIZE];
  63. int recv_busy;
  64. int recv_pos;
  65. int recv_len;
  66. };
  67. int BSSLConnection_GlobalInit (void) WARN_UNUSED;
  68. int BSSLConnection_MakeBackend (PRFileDesc *prfd, StreamPassInterface *send_if, StreamRecvInterface *recv_if) WARN_UNUSED;
  69. void BSSLConnection_Init (BSSLConnection *o, PRFileDesc *prfd, int force_handshake, BReactor *reactor, void *user,
  70. BSSLConnection_handler handler);
  71. void BSSLConnection_Free (BSSLConnection *o);
  72. StreamPassInterface * BSSLConnection_GetSendIf (BSSLConnection *o);
  73. StreamRecvInterface * BSSLConnection_GetRecvIf (BSSLConnection *o);
  74. #endif