tls_bio.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Kamailio TLS module
  3. *
  4. * Copyright (C) 2010 iptelorg GmbH
  5. *
  6. * Permission to use, copy, modify, and 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. /** openssl BIOs for reading/writing via a fixed memory buffer.
  19. * @file modules/tls/tls_bio.h
  20. * @ingroup tls
  21. */
  22. #ifndef __tls_bio_h
  23. #define __tls_bio_h
  24. #include <openssl/bio.h>
  25. /* memory buffer used for tls I/O */
  26. struct tls_mbuf {
  27. unsigned char* buf;
  28. int pos; /**< current position in the buffer while reading or writing*/
  29. int used; /**< how much it's used (read or write)*/
  30. int size; /**< total buffer size (fixed) */
  31. };
  32. struct tls_bio_mbuf_data {
  33. struct tls_mbuf* rd;
  34. struct tls_mbuf* wr;
  35. };
  36. BIO_METHOD* tls_BIO_mbuf(void);
  37. BIO* tls_BIO_new_mbuf(struct tls_mbuf* rd, struct tls_mbuf* wr);
  38. int tls_BIO_mbuf_set(BIO* b, struct tls_mbuf* rd, struct tls_mbuf* wr);
  39. /** intialize an mbuf structure.
  40. * @param mb - struct tls_mbuf pointer that will be intialized.
  41. * @param b - buffer (unsigned char*).
  42. * @param sz - suze of the buffer (int).
  43. * WARNING: the buffer will not be copied, but referenced.
  44. */
  45. #define tls_mbuf_init(mb, b, sz) \
  46. do { \
  47. (mb)->buf = (b); \
  48. (mb)->size = (sz); \
  49. (mb)->pos = 0; \
  50. (mb)->used = 0; \
  51. } while(0)
  52. #endif /*__tls_bio_h*/
  53. /* vi: set ts=4 sw=4 tw=79:ai:cindent: */