libwebsockets
Lightweight C library for HTML5 websockets
lws-write.h
1 /*
2  * libwebsockets - small server side websockets and web server implementation
3  *
4  * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22  * IN THE SOFTWARE.
23  */
24 
30 #define LWS_WRITE_RAW LWS_WRITE_HTTP
31 
32 /*
33  * NOTE: These public enums are part of the abi. If you want to add one,
34  * add it at where specified so existing users are unaffected.
35  */
36 enum lws_write_protocol {
37  LWS_WRITE_TEXT = 0,
42  LWS_WRITE_BINARY = 1,
47  LWS_WRITE_CONTINUATION = 2,
50  LWS_WRITE_HTTP = 3,
53  /* LWS_WRITE_CLOSE is handled by lws_close_reason() */
54  LWS_WRITE_PING = 5,
55  LWS_WRITE_PONG = 6,
56 
57  /* Same as write_http but we know this write ends the transaction */
58  LWS_WRITE_HTTP_FINAL = 7,
59 
60  /* HTTP2 */
61 
62  LWS_WRITE_HTTP_HEADERS = 8,
68  LWS_WRITE_HTTP_HEADERS_CONTINUATION = 9,
72  /****** add new things just above ---^ ******/
73 
74  /* flags */
75 
76  LWS_WRITE_BUFLIST = 0x20,
84  LWS_WRITE_NO_FIN = 0x40,
87  LWS_WRITE_H2_STREAM_END = 0x80,
92  LWS_WRITE_CLIENT_IGNORE_XOR_MASK = 0x80
96 };
97 
98 /* used with LWS_CALLBACK_CHILD_WRITE_VIA_PARENT */
99 
101  struct lws *wsi;
102  unsigned char *buf;
103  size_t len;
104  enum lws_write_protocol wp;
105 };
106 
107 
208 LWS_VISIBLE LWS_EXTERN int
209 lws_write(struct lws *wsi, unsigned char *buf, size_t len,
210  enum lws_write_protocol protocol);
211 
212 /* helper for case where buffer may be const */
213 #define lws_write_http(wsi, buf, len) \
214  lws_write(wsi, (unsigned char *)(buf), len, LWS_WRITE_HTTP)
215 
227 static LWS_INLINE int
228 lws_write_ws_flags(int initial, int is_start, int is_end)
229 {
230  int r;
231 
232  if (is_start)
233  r = initial;
234  else
235  r = LWS_WRITE_CONTINUATION;
236 
237  if (!is_end)
238  r |= LWS_WRITE_NO_FIN;
239 
240  return r;
241 }
242 
256 LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
257 lws_raw_transaction_completed(struct lws *wsi);
258 
Definition: lws-write.h:100