wslay_frame.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Wslay - The WebSocket Library
  3. *
  4. * Copyright (c) 2011, 2012 Tatsuhiro Tsujikawa
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef WSLAY_FRAME_H
  26. #define WSLAY_FRAME_H
  27. #ifdef HAVE_CONFIG_H
  28. # include <config.h>
  29. #endif /* HAVE_CONFIG_H */
  30. #include <wslay/wslay.h>
  31. enum wslay_frame_state {
  32. PREP_HEADER,
  33. PREP_HEADER_NOBUF,
  34. SEND_HEADER,
  35. SEND_PAYLOAD,
  36. RECV_HEADER1,
  37. RECV_PAYLOADLEN,
  38. RECV_EXT_PAYLOADLEN,
  39. RECV_MASKKEY,
  40. RECV_PAYLOAD
  41. };
  42. struct wslay_frame_opcode_memo {
  43. uint8_t fin;
  44. uint8_t opcode;
  45. uint8_t rsv;
  46. };
  47. struct wslay_frame_context {
  48. uint8_t ibuf[4096];
  49. uint8_t *ibufmark;
  50. uint8_t *ibuflimit;
  51. struct wslay_frame_opcode_memo iom;
  52. uint64_t ipayloadlen;
  53. uint64_t ipayloadoff;
  54. uint8_t imask;
  55. uint8_t imaskkey[4];
  56. enum wslay_frame_state istate;
  57. size_t ireqread;
  58. uint8_t oheader[14];
  59. uint8_t *oheadermark;
  60. uint8_t *oheaderlimit;
  61. uint64_t opayloadlen;
  62. uint64_t opayloadoff;
  63. uint8_t omask;
  64. uint8_t omaskkey[4];
  65. enum wslay_frame_state ostate;
  66. struct wslay_frame_callbacks callbacks;
  67. void *user_data;
  68. };
  69. #endif /* WSLAY_FRAME_H */