BSSLConnection.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * @file BSSLConnection.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the author nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #ifndef BADVPN_BSSLCONNECTION_H
  30. #define BADVPN_BSSLCONNECTION_H
  31. #include <prio.h>
  32. #include <misc/debug.h>
  33. #include <misc/debugerror.h>
  34. #include <base/DebugObject.h>
  35. #include <base/BPending.h>
  36. #include <flow/StreamPassInterface.h>
  37. #include <flow/StreamRecvInterface.h>
  38. #define BSSLCONNECTION_EVENT_UP 1
  39. #define BSSLCONNECTION_EVENT_ERROR 2
  40. #define BSSLCONNECTION_BUF_SIZE 4096
  41. typedef void (*BSSLConnection_handler) (void *user, int event);
  42. struct BSSLConnection_backend;
  43. typedef struct {
  44. PRFileDesc *prfd;
  45. BPendingGroup *pg;
  46. void *user;
  47. BSSLConnection_handler handler;
  48. struct BSSLConnection_backend *backend;
  49. int have_error;
  50. int up;
  51. BPending init_job;
  52. StreamPassInterface send_if;
  53. StreamRecvInterface recv_if;
  54. BPending recv_job;
  55. const uint8_t *send_data;
  56. int send_len;
  57. uint8_t *recv_data;
  58. int recv_avail;
  59. DebugError d_err;
  60. DebugObject d_obj;
  61. } BSSLConnection;
  62. struct BSSLConnection_backend {
  63. StreamPassInterface *send_if;
  64. StreamRecvInterface *recv_if;
  65. BSSLConnection *con;
  66. uint8_t send_buf[BSSLCONNECTION_BUF_SIZE];
  67. int send_pos;
  68. int send_len;
  69. uint8_t recv_buf[BSSLCONNECTION_BUF_SIZE];
  70. int recv_busy;
  71. int recv_pos;
  72. int recv_len;
  73. };
  74. int BSSLConnection_GlobalInit (void) WARN_UNUSED;
  75. int BSSLConnection_MakeBackend (PRFileDesc *prfd, StreamPassInterface *send_if, StreamRecvInterface *recv_if) WARN_UNUSED;
  76. void BSSLConnection_Init (BSSLConnection *o, PRFileDesc *prfd, int force_handshake, BPendingGroup *pg, void *user,
  77. BSSLConnection_handler handler);
  78. void BSSLConnection_Free (BSSLConnection *o);
  79. StreamPassInterface * BSSLConnection_GetSendIf (BSSLConnection *o);
  80. StreamRecvInterface * BSSLConnection_GetRecvIf (BSSLConnection *o);
  81. #endif