libwebsockets
Lightweight C library for HTML5 websockets
lws-callbacks.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 
37 
38 struct lws_ssl_info {
39  int where;
40  int ret;
41 };
42 
43 enum lws_cert_update_state {
44  LWS_CUS_IDLE,
45  LWS_CUS_STARTING,
46  LWS_CUS_SUCCESS,
47  LWS_CUS_FAILED,
48 
49  LWS_CUS_CREATE_KEYS,
50  LWS_CUS_REG,
51  LWS_CUS_AUTH,
52  LWS_CUS_CHALLENGE,
53  LWS_CUS_CREATE_REQ,
54  LWS_CUS_REQ,
55  LWS_CUS_CONFIRM,
56  LWS_CUS_ISSUE,
57 };
58 
59 enum {
60  LWS_TLS_REQ_ELEMENT_COUNTRY,
61  LWS_TLS_REQ_ELEMENT_STATE,
62  LWS_TLS_REQ_ELEMENT_LOCALITY,
63  LWS_TLS_REQ_ELEMENT_ORGANIZATION,
64  LWS_TLS_REQ_ELEMENT_COMMON_NAME,
65  LWS_TLS_REQ_ELEMENT_SUBJECT_ALT_NAME,
66  LWS_TLS_REQ_ELEMENT_EMAIL,
67 
68  LWS_TLS_REQ_ELEMENT_COUNT,
69 
70  LWS_TLS_SET_DIR_URL = LWS_TLS_REQ_ELEMENT_COUNT,
71  LWS_TLS_SET_AUTH_PATH,
72  LWS_TLS_SET_CERT_PATH,
73  LWS_TLS_SET_KEY_PATH,
74 
75  LWS_TLS_TOTAL_COUNT
76 };
77 
79  struct lws_vhost *vh;
80  const char *element_overrides[LWS_TLS_TOTAL_COUNT]; /* NULL = use pvo */
81 };
82 
83 /*
84  * With LWS_CALLBACK_FILTER_NETWORK_CONNECTION callback, user_data pointer
85  * points to one of these
86  */
87 
89  struct sockaddr_storage cli_addr;
90  socklen_t clilen;
91  lws_sockfd_type accept_fd;
92 };
93 
94 /*
95  * NOTE: These public enums are part of the abi. If you want to add one,
96  * add it at where specified so existing users are unaffected.
97  */
100 
101  /* ---------------------------------------------------------------------
102  * ----- Callbacks related to wsi and protocol binding lifecycle -----
103  */
104 
125  /* ---------------------------------------------------------------------
126  * ----- Callbacks related to Server TLS -----
127  */
128 
170  /* ---------------------------------------------------------------------
171  * ----- Callbacks related to Client TLS -----
172  */
173 
205  /* ---------------------------------------------------------------------
206  * ----- Callbacks related to HTTP Server -----
207  */
208 
217  LWS_CALLBACK_HTTP = 12,
344  /* ---------------------------------------------------------------------
345  * ----- Callbacks related to HTTP Client -----
346  */
347 
398  LWS_CALLBACK_CLIENT_HTTP_BIND_PROTOCOL = 85,
399  LWS_CALLBACK_CLIENT_HTTP_DROP_PROTOCOL = 76,
400 
401  /* ---------------------------------------------------------------------
402  * ----- Callbacks related to Websocket Server -----
403  */
404 
461  LWS_CALLBACK_WS_SERVER_BIND_PROTOCOL = 77,
462  LWS_CALLBACK_WS_SERVER_DROP_PROTOCOL = 78,
463 
464  /* ---------------------------------------------------------------------
465  * ----- Callbacks related to Websocket Client -----
466  */
467 
602  LWS_CALLBACK_WS_CLIENT_BIND_PROTOCOL = 79,
603  LWS_CALLBACK_WS_CLIENT_DROP_PROTOCOL = 80,
604 
605  /* ---------------------------------------------------------------------
606  * ----- Callbacks related to external poll loop integration -----
607  */
608 
614  /* external poll() management support */
664  /* ---------------------------------------------------------------------
665  * ----- Callbacks related to CGI serving -----
666  */
667 
668  LWS_CALLBACK_CGI = 40,
696  /* ---------------------------------------------------------------------
697  * ----- Callbacks related to Generic Sessions -----
698  */
699 
716  /* ---------------------------------------------------------------------
717  * ----- Callbacks related to RAW PROXY -----
718  */
719 
746  LWS_CALLBACK_RAW_PROXY_CLI_BIND_PROTOCOL = 97,
747  LWS_CALLBACK_RAW_PROXY_SRV_BIND_PROTOCOL = 98,
748  LWS_CALLBACK_RAW_PROXY_CLI_DROP_PROTOCOL = 99,
749  LWS_CALLBACK_RAW_PROXY_SRV_DROP_PROTOCOL = 100,
750 
751 
752  /* ---------------------------------------------------------------------
753  * ----- Callbacks related to RAW sockets -----
754  */
755 
756  LWS_CALLBACK_RAW_RX = 59,
771  LWS_CALLBACK_RAW_SKT_BIND_PROTOCOL = 81,
772  LWS_CALLBACK_RAW_SKT_DROP_PROTOCOL = 82,
773 
774  /* ---------------------------------------------------------------------
775  * ----- Callbacks related to RAW file handles -----
776  */
777 
793  LWS_CALLBACK_RAW_FILE_BIND_PROTOCOL = 83,
794  LWS_CALLBACK_RAW_FILE_DROP_PROTOCOL = 84,
795 
796  /* ---------------------------------------------------------------------
797  * ----- Callbacks related to generic wsi events -----
798  */
799 
800  LWS_CALLBACK_TIMER = 73,
829  /* ---------------------------------------------------------------------
830  * ----- Callbacks related to TLS certificate management -----
831  */
832 
852  /* ---------------------------------------------------------------------
853  * ----- Callbacks related to MQTT Client -----
854  */
855 
856  LWS_CALLBACK_MQTT_NEW_CLIENT_INSTANTIATED = 200,
857  LWS_CALLBACK_MQTT_IDLE = 201,
858  LWS_CALLBACK_MQTT_CLIENT_ESTABLISHED = 202,
859  LWS_CALLBACK_MQTT_SUBSCRIBED = 203,
860  LWS_CALLBACK_MQTT_CLIENT_WRITEABLE = 204,
861  LWS_CALLBACK_MQTT_CLIENT_RX = 205,
862  LWS_CALLBACK_MQTT_UNSUBSCRIBED = 206,
863  LWS_CALLBACK_MQTT_DROP_PROTOCOL = 207,
864  LWS_CALLBACK_MQTT_CLIENT_CLOSED = 208,
865  LWS_CALLBACK_MQTT_ACK = 209,
887  /****** add new things just above ---^ ******/
888 
889  LWS_CALLBACK_USER = 1000,
891 };
892 
893 
894 
910 typedef int
911 lws_callback_function(struct lws *wsi, enum lws_callback_reasons reason,
912  void *user, void *in, size_t len);
913 
914 #define LWS_CB_REASON_AUX_BF__CGI 1
915 #define LWS_CB_REASON_AUX_BF__PROXY 2
916 #define LWS_CB_REASON_AUX_BF__CGI_CHUNK_END 4
917 #define LWS_CB_REASON_AUX_BF__CGI_HEADERS 8
918 #define LWS_CB_REASON_AUX_BF__PROXY_TRANS_END 16
919 #define LWS_CB_REASON_AUX_BF__PROXY_HEADERS 32
int lws_callback_function(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len)
Definition: lws-callbacks.h:911
lws_callback_reasons
Definition: lws-callbacks.h:99
@ LWS_CALLBACK_FILTER_NETWORK_CONNECTION
Definition: lws-callbacks.h:582
@ LWS_CALLBACK_VERIFY_BASIC_AUTHORIZATION
Definition: lws-callbacks.h:288
@ LWS_CALLBACK_HTTP_BIND_PROTOCOL
Definition: lws-callbacks.h:312
@ LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS
Definition: lws-callbacks.h:137
@ LWS_CALLBACK_UNLOCK_POLL
Definition: lws-callbacks.h:661
@ LWS_CALLBACK_CLIENT_RECEIVE_PONG
Definition: lws-callbacks.h:551
@ LWS_CALLBACK_RAW_ADOPT
Definition: lws-callbacks.h:765
@ LWS_CALLBACK_OPENSSL_PERFORM_SERVER_CERT_VERIFICATION
Definition: lws-callbacks.h:174
@ LWS_CALLBACK_COMPLETED_CLIENT_HTTP
Definition: lws-callbacks.h:380
@ LWS_CALLBACK_CLIENT_CLOSED
Definition: lws-callbacks.h:525
@ LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED
Definition: lws-callbacks.h:563
@ LWS_CALLBACK_DEL_POLL_FD
Definition: lws-callbacks.h:632
@ LWS_CALLBACK_CGI
Definition: lws-callbacks.h:668
@ LWS_CALLBACK_RAW_PROXY_CLI_CLOSE
Definition: lws-callbacks.h:726
@ LWS_CALLBACK_ESTABLISHED
Definition: lws-callbacks.h:405
@ LWS_CALLBACK_RECEIVE_PONG
Definition: lws-callbacks.h:424
@ LWS_CALLBACK_HTTP_BODY_COMPLETION
Definition: lws-callbacks.h:236
@ LWS_CALLBACK_RAW_PROXY_SRV_CLOSE
Definition: lws-callbacks.h:729
@ LWS_CALLBACK_MQTT_ACK
Definition: lws-callbacks.h:865
@ LWS_CALLBACK_CGI_PROCESS_ATTACH
Definition: lws-callbacks.h:692
@ LWS_CALLBACK_HTTP_CONFIRM_UPGRADE
Definition: lws-callbacks.h:330
@ LWS_CALLBACK_CONFIRM_EXTENSION_OKAY
Definition: lws-callbacks.h:450
@ LWS_CALLBACK_MQTT_RESEND
Definition: lws-callbacks.h:871
@ LWS_CALLBACK_TIMER
Definition: lws-callbacks.h:800
@ LWS_CALLBACK_HTTP_DROP_PROTOCOL
Definition: lws-callbacks.h:324
@ LWS_CALLBACK_VHOST_CERT_AGING
Definition: lws-callbacks.h:833
@ LWS_CALLBACK_RAW_ADOPT_FILE
Definition: lws-callbacks.h:778
@ LWS_CALLBACK_CLOSED
Definition: lws-callbacks.h:413
@ LWS_CALLBACK_RECEIVE
Definition: lws-callbacks.h:419
@ LWS_CALLBACK_SSL_INFO
Definition: lws-callbacks.h:163
@ LWS_CALLBACK_VHOST_CERT_UPDATE
Definition: lws-callbacks.h:846
@ LWS_CALLBACK_PROTOCOL_DESTROY
Definition: lws-callbacks.h:109
@ LWS_CALLBACK_RAW_PROXY_SRV_WRITEABLE
Definition: lws-callbacks.h:735
@ LWS_CALLBACK_CGI_STDIN_DATA
Definition: lws-callbacks.h:681
@ LWS_CALLBACK_RAW_PROXY_CLI_RX
Definition: lws-callbacks.h:720
@ LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP
Definition: lws-callbacks.h:348
@ LWS_CALLBACK_RAW_RX
Definition: lws-callbacks.h:756
@ LWS_CALLBACK_FILTER_HTTP_CONNECTION
Definition: lws-callbacks.h:248
@ LWS_CALLBACK_CLIENT_ESTABLISHED
Definition: lws-callbacks.h:521
@ LWS_CALLBACK_SERVER_WRITEABLE
Definition: lws-callbacks.h:416
@ LWS_CALLBACK_WSI_TX_CREDIT_GET
Definition: lws-callbacks.h:121
@ LWS_CALLBACK_CLOSED_HTTP
Definition: lws-callbacks.h:245
@ LWS_CALLBACK_CONNECTING
Definition: lws-callbacks.h:820
@ LWS_CALLBACK_LOCK_POLL
Definition: lws-callbacks.h:648
@ LWS_CALLBACK_PROCESS_HTML
Definition: lws-callbacks.h:304
@ LWS_CALLBACK_RAW_PROXY_SRV_RX
Definition: lws-callbacks.h:723
@ LWS_CALLBACK_CLIENT_WRITEABLE
Definition: lws-callbacks.h:554
@ LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER
Definition: lws-callbacks.h:528
@ LWS_CALLBACK_USER
Definition: lws-callbacks.h:889
@ LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH
Definition: lws-callbacks.h:513
@ LWS_CALLBACK_HTTP_PMO
Definition: lws-callbacks.h:710
@ LWS_CALLBACK_HTTP_FILE_COMPLETION
Definition: lws-callbacks.h:239
@ LWS_CALLBACK_CHILD_CLOSING
Definition: lws-callbacks.h:815
@ LWS_CALLBACK_CHANGE_MODE_POLL_FD
Definition: lws-callbacks.h:639
@ LWS_CALLBACK_RAW_CONNECTED
Definition: lws-callbacks.h:768
@ LWS_CALLBACK_RECEIVE_CLIENT_HTTP
Definition: lws-callbacks.h:362
@ LWS_CALLBACK_ADD_POLL_FD
Definition: lws-callbacks.h:615
@ LWS_CALLBACK_EVENT_WAIT_CANCELLED
Definition: lws-callbacks.h:808
@ LWS_CALLBACK_ADD_HEADERS
Definition: lws-callbacks.h:261
@ LWS_CALLBACK_CLIENT_RECEIVE
Definition: lws-callbacks.h:547
@ LWS_CALLBACK_WS_EXT_DEFAULTS
Definition: lws-callbacks.h:573
@ LWS_CALLBACK_SESSION_INFO
Definition: lws-callbacks.h:700
@ LWS_CALLBACK_WS_PEER_INITIATED_CLOSE
Definition: lws-callbacks.h:427
@ LWS_CALLBACK_CLOSED_CLIENT_HTTP
Definition: lws-callbacks.h:352
@ LWS_CALLBACK_HTTP_BODY
Definition: lws-callbacks.h:232
@ LWS_CALLBACK_RAW_WRITEABLE_FILE
Definition: lws-callbacks.h:787
@ LWS_CALLBACK_RAW_RX_FILE
Definition: lws-callbacks.h:781
@ LWS_CALLBACK_CGI_TERMINATED
Definition: lws-callbacks.h:674
@ LWS_CALLBACK_WSI_DESTROY
Definition: lws-callbacks.h:118
@ LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION
Definition: lws-callbacks.h:437
@ LWS_CALLBACK_RAW_WRITEABLE
Definition: lws-callbacks.h:762
@ LWS_CALLBACK_RAW_PROXY_CLI_ADOPT
Definition: lws-callbacks.h:738
@ LWS_CALLBACK_RAW_CLOSE_FILE
Definition: lws-callbacks.h:790
@ LWS_CALLBACK_PROTOCOL_INIT
Definition: lws-callbacks.h:105
@ LWS_CALLBACK_CGI_STDIN_COMPLETED
Definition: lws-callbacks.h:687
@ LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ
Definition: lws-callbacks.h:355
@ LWS_CALLBACK_CLIENT_CONNECTION_ERROR
Definition: lws-callbacks.h:468
@ LWS_CALLBACK_RAW_PROXY_CLI_WRITEABLE
Definition: lws-callbacks.h:732
@ LWS_CALLBACK_GET_THREAD_ID
Definition: lws-callbacks.h:609
@ LWS_CALLBACK_MQTT_UNSUBSCRIBE_TIMEOUT
Definition: lws-callbacks.h:876
@ LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS
Definition: lws-callbacks.h:129
@ LWS_CALLBACK_MQTT_SHADOW_TIMEOUT
Definition: lws-callbacks.h:881
@ LWS_CALLBACK_RAW_CLOSE
Definition: lws-callbacks.h:759
@ LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION
Definition: lws-callbacks.h:144
@ LWS_CALLBACK_HTTP
Definition: lws-callbacks.h:217
@ LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED
Definition: lws-callbacks.h:209
@ LWS_CALLBACK_CLIENT_HTTP_WRITEABLE
Definition: lws-callbacks.h:385
@ LWS_CALLBACK_GS_EVENT
Definition: lws-callbacks.h:706
@ LWS_CALLBACK_CLIENT_HTTP_REDIRECT
Definition: lws-callbacks.h:395
@ LWS_CALLBACK_CHECK_ACCESS_RIGHTS
Definition: lws-callbacks.h:297
@ LWS_CALLBACK_RAW_PROXY_SRV_ADOPT
Definition: lws-callbacks.h:742
@ LWS_CALLBACK_WSI_CREATE
Definition: lws-callbacks.h:115
@ LWS_CALLBACK_HTTP_WRITEABLE
Definition: lws-callbacks.h:242
Definition: lws-callbacks.h:78
Definition: lws-callbacks.h:88
Definition: lws-callbacks.h:38