private.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * libwebsockets - small server side websockets and web server implementation
  3. *
  4. * Copyright (C) 2010 - 2018 Andy Green <[email protected]>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation:
  9. * version 2.1 of the License.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  19. * MA 02110-1301 USA
  20. *
  21. * This is included from core/private.h if LWS_ROLE_WS
  22. */
  23. extern struct lws_role_ops role_ops_ws;
  24. #define lwsi_role_ws(wsi) (wsi->role_ops == &role_ops_ws)
  25. enum lws_rx_parse_state {
  26. LWS_RXPS_NEW,
  27. LWS_RXPS_04_mask_1,
  28. LWS_RXPS_04_mask_2,
  29. LWS_RXPS_04_mask_3,
  30. LWS_RXPS_04_FRAME_HDR_1,
  31. LWS_RXPS_04_FRAME_HDR_LEN,
  32. LWS_RXPS_04_FRAME_HDR_LEN16_2,
  33. LWS_RXPS_04_FRAME_HDR_LEN16_1,
  34. LWS_RXPS_04_FRAME_HDR_LEN64_8,
  35. LWS_RXPS_04_FRAME_HDR_LEN64_7,
  36. LWS_RXPS_04_FRAME_HDR_LEN64_6,
  37. LWS_RXPS_04_FRAME_HDR_LEN64_5,
  38. LWS_RXPS_04_FRAME_HDR_LEN64_4,
  39. LWS_RXPS_04_FRAME_HDR_LEN64_3,
  40. LWS_RXPS_04_FRAME_HDR_LEN64_2,
  41. LWS_RXPS_04_FRAME_HDR_LEN64_1,
  42. LWS_RXPS_07_COLLECT_FRAME_KEY_1,
  43. LWS_RXPS_07_COLLECT_FRAME_KEY_2,
  44. LWS_RXPS_07_COLLECT_FRAME_KEY_3,
  45. LWS_RXPS_07_COLLECT_FRAME_KEY_4,
  46. LWS_RXPS_WS_FRAME_PAYLOAD
  47. };
  48. enum lws_websocket_opcodes_07 {
  49. LWSWSOPC_CONTINUATION = 0,
  50. LWSWSOPC_TEXT_FRAME = 1,
  51. LWSWSOPC_BINARY_FRAME = 2,
  52. LWSWSOPC_NOSPEC__MUX = 7,
  53. /* control extensions 8+ */
  54. LWSWSOPC_CLOSE = 8,
  55. LWSWSOPC_PING = 9,
  56. LWSWSOPC_PONG = 0xa,
  57. };
  58. /* this is not usable directly by user code any more, lws_close_reason() */
  59. #define LWS_WRITE_CLOSE 4
  60. #define ALREADY_PROCESSED_IGNORE_CHAR 1
  61. #define ALREADY_PROCESSED_NO_CB 2
  62. #if !defined(LWS_WITHOUT_EXTENSIONS)
  63. struct lws_vhost_role_ws {
  64. const struct lws_extension *extensions;
  65. };
  66. struct lws_pt_role_ws {
  67. struct lws *rx_draining_ext_list;
  68. struct lws *tx_draining_ext_list;
  69. };
  70. #endif
  71. struct _lws_websocket_related {
  72. char *rx_ubuf;
  73. #if !defined(LWS_WITHOUT_EXTENSIONS)
  74. const struct lws_extension *active_extensions[LWS_MAX_EXTENSIONS_ACTIVE];
  75. void *act_ext_user[LWS_MAX_EXTENSIONS_ACTIVE];
  76. struct lws *rx_draining_ext_list;
  77. struct lws *tx_draining_ext_list;
  78. #endif
  79. /* Also used for close content... control opcode == < 128 */
  80. uint8_t ping_payload_buf[128 - 3 + LWS_PRE];
  81. uint8_t mask[4];
  82. time_t time_next_ping_check;
  83. size_t rx_packet_length;
  84. uint32_t rx_ubuf_head;
  85. uint32_t rx_ubuf_alloc;
  86. uint8_t ping_payload_len;
  87. uint8_t mask_idx;
  88. uint8_t opcode;
  89. uint8_t rsv;
  90. uint8_t rsv_first_msg;
  91. /* zero if no info, or length including 2-byte close code */
  92. uint8_t close_in_ping_buffer_len;
  93. uint8_t utf8;
  94. uint8_t stashed_write_type;
  95. uint8_t tx_draining_stashed_wp;
  96. uint8_t ietf_spec_revision;
  97. unsigned int final:1;
  98. unsigned int frame_is_binary:1;
  99. unsigned int all_zero_nonce:1;
  100. unsigned int this_frame_masked:1;
  101. unsigned int inside_frame:1; /* next write will be more of frame */
  102. unsigned int clean_buffer:1; /* buffer not rewritten by extension */
  103. unsigned int payload_is_close:1; /* process as PONG, but it is close */
  104. unsigned int ping_pending_flag:1;
  105. unsigned int continuation_possible:1;
  106. unsigned int owed_a_fin:1;
  107. unsigned int check_utf8:1;
  108. unsigned int defeat_check_utf8:1;
  109. unsigned int stashed_write_pending:1;
  110. unsigned int send_check_ping:1;
  111. unsigned int first_fragment:1;
  112. unsigned int peer_has_sent_close:1;
  113. #if !defined(LWS_WITHOUT_EXTENSIONS)
  114. unsigned int extension_data_pending:1;
  115. unsigned int rx_draining_ext:1;
  116. unsigned int tx_draining_ext:1;
  117. uint8_t count_act_ext;
  118. #endif
  119. };
  120. int
  121. lws_ws_handshake_client(struct lws *wsi, unsigned char **buf, size_t len);
  122. #if !defined(LWS_WITHOUT_EXTENSIONS)
  123. LWS_VISIBLE void
  124. lws_context_init_extensions(const struct lws_context_creation_info *info,
  125. struct lws_context *context);
  126. LWS_EXTERN int
  127. lws_any_extension_handled(struct lws *wsi, enum lws_extension_callback_reasons r,
  128. void *v, size_t len);
  129. LWS_EXTERN int
  130. lws_ext_cb_active(struct lws *wsi, int reason, void *buf, int len);
  131. LWS_EXTERN int
  132. lws_ext_cb_all_exts(struct lws_context *context, struct lws *wsi, int reason,
  133. void *arg, int len);
  134. #endif
  135. int
  136. handshake_0405(struct lws_context *context, struct lws *wsi);
  137. int
  138. lws_process_ws_upgrade(struct lws *wsi);
  139. int
  140. lws_server_init_wsi_for_ws(struct lws *wsi);