wslay_frame.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. SEND_HEADER,
  34. SEND_PAYLOAD,
  35. RECV_HEADER1,
  36. RECV_PAYLOADLEN,
  37. RECV_EXT_PAYLOADLEN,
  38. RECV_MASKKEY,
  39. RECV_PAYLOAD
  40. };
  41. struct wslay_frame_opcode_memo {
  42. uint8_t fin;
  43. uint8_t opcode;
  44. uint8_t rsv;
  45. };
  46. struct wslay_frame_context {
  47. uint8_t ibuf[4096];
  48. uint8_t *ibufmark;
  49. uint8_t *ibuflimit;
  50. struct wslay_frame_opcode_memo iom;
  51. uint64_t ipayloadlen;
  52. uint64_t ipayloadoff;
  53. uint8_t imask;
  54. uint8_t imaskkey[4];
  55. enum wslay_frame_state istate;
  56. size_t ireqread;
  57. uint8_t oheader[14];
  58. uint8_t *oheadermark;
  59. uint8_t *oheaderlimit;
  60. uint64_t opayloadlen;
  61. uint64_t opayloadoff;
  62. uint8_t omask;
  63. uint8_t omaskkey[4];
  64. enum wslay_frame_state ostate;
  65. struct wslay_frame_callbacks callbacks;
  66. void *user_data;
  67. };
  68. #endif /* WSLAY_FRAME_H */