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 
179  /* ---------------------------------------------------------------------
180  * ----- Callbacks related to Client TLS -----
181  */
182 
214  /* ---------------------------------------------------------------------
215  * ----- Callbacks related to HTTP Server -----
216  */
217 
226  LWS_CALLBACK_HTTP = 12,
353  /* ---------------------------------------------------------------------
354  * ----- Callbacks related to HTTP Client -----
355  */
356 
407  LWS_CALLBACK_CLIENT_HTTP_BIND_PROTOCOL = 85,
408  LWS_CALLBACK_CLIENT_HTTP_DROP_PROTOCOL = 76,
409 
410  /* ---------------------------------------------------------------------
411  * ----- Callbacks related to Websocket Server -----
412  */
413 
470  LWS_CALLBACK_WS_SERVER_BIND_PROTOCOL = 77,
471  LWS_CALLBACK_WS_SERVER_DROP_PROTOCOL = 78,
472 
473  /* ---------------------------------------------------------------------
474  * ----- Callbacks related to Websocket Client -----
475  */
476 
611  LWS_CALLBACK_WS_CLIENT_BIND_PROTOCOL = 79,
612  LWS_CALLBACK_WS_CLIENT_DROP_PROTOCOL = 80,
613 
614  /* ---------------------------------------------------------------------
615  * ----- Callbacks related to external poll loop integration -----
616  */
617 
623  /* external poll() management support */
673  /* ---------------------------------------------------------------------
674  * ----- Callbacks related to CGI serving -----
675  */
676 
677  LWS_CALLBACK_CGI = 40,
705  /* ---------------------------------------------------------------------
706  * ----- Callbacks related to Generic Sessions -----
707  */
708 
725  /* ---------------------------------------------------------------------
726  * ----- Callbacks related to RAW PROXY -----
727  */
728 
755  LWS_CALLBACK_RAW_PROXY_CLI_BIND_PROTOCOL = 97,
756  LWS_CALLBACK_RAW_PROXY_SRV_BIND_PROTOCOL = 98,
757  LWS_CALLBACK_RAW_PROXY_CLI_DROP_PROTOCOL = 99,
758  LWS_CALLBACK_RAW_PROXY_SRV_DROP_PROTOCOL = 100,
759 
760 
761  /* ---------------------------------------------------------------------
762  * ----- Callbacks related to RAW sockets -----
763  */
764 
765  LWS_CALLBACK_RAW_RX = 59,
780  LWS_CALLBACK_RAW_SKT_BIND_PROTOCOL = 81,
781  LWS_CALLBACK_RAW_SKT_DROP_PROTOCOL = 82,
782 
783  /* ---------------------------------------------------------------------
784  * ----- Callbacks related to RAW file handles -----
785  */
786 
802  LWS_CALLBACK_RAW_FILE_BIND_PROTOCOL = 83,
803  LWS_CALLBACK_RAW_FILE_DROP_PROTOCOL = 84,
804 
805  /* ---------------------------------------------------------------------
806  * ----- Callbacks related to generic wsi events -----
807  */
808 
809  LWS_CALLBACK_TIMER = 73,
838  /* ---------------------------------------------------------------------
839  * ----- Callbacks related to TLS certificate management -----
840  */
841 
861  /* ---------------------------------------------------------------------
862  * ----- Callbacks related to MQTT Client -----
863  */
864 
865  LWS_CALLBACK_MQTT_NEW_CLIENT_INSTANTIATED = 200,
866  LWS_CALLBACK_MQTT_IDLE = 201,
867  LWS_CALLBACK_MQTT_CLIENT_ESTABLISHED = 202,
868  LWS_CALLBACK_MQTT_SUBSCRIBED = 203,
869  LWS_CALLBACK_MQTT_CLIENT_WRITEABLE = 204,
870  LWS_CALLBACK_MQTT_CLIENT_RX = 205,
871  LWS_CALLBACK_MQTT_UNSUBSCRIBED = 206,
872  LWS_CALLBACK_MQTT_DROP_PROTOCOL = 207,
873  LWS_CALLBACK_MQTT_CLIENT_CLOSED = 208,
874  LWS_CALLBACK_MQTT_ACK = 209,
891  /****** add new things just above ---^ ******/
892 
893  LWS_CALLBACK_USER = 1000,
895 };
896 
897 
898 
914 typedef int
915 lws_callback_function(struct lws *wsi, enum lws_callback_reasons reason,
916  void *user, void *in, size_t len);
917 
918 #define LWS_CB_REASON_AUX_BF__CGI 1
919 #define LWS_CB_REASON_AUX_BF__PROXY 2
920 #define LWS_CB_REASON_AUX_BF__CGI_CHUNK_END 4
921 #define LWS_CB_REASON_AUX_BF__CGI_HEADERS 8
922 #define LWS_CB_REASON_AUX_BF__PROXY_TRANS_END 16
923 #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:915
lws_callback_reasons
Definition: lws-callbacks.h:99
@ LWS_CALLBACK_FILTER_NETWORK_CONNECTION
Definition: lws-callbacks.h:591
@ LWS_CALLBACK_VERIFY_BASIC_AUTHORIZATION
Definition: lws-callbacks.h:297
@ LWS_CALLBACK_HTTP_BIND_PROTOCOL
Definition: lws-callbacks.h:321
@ LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS
Definition: lws-callbacks.h:137
@ LWS_CALLBACK_UNLOCK_POLL
Definition: lws-callbacks.h:670
@ LWS_CALLBACK_CLIENT_RECEIVE_PONG
Definition: lws-callbacks.h:560
@ LWS_CALLBACK_RAW_ADOPT
Definition: lws-callbacks.h:774
@ LWS_CALLBACK_OPENSSL_PERFORM_SERVER_CERT_VERIFICATION
Definition: lws-callbacks.h:183
@ LWS_CALLBACK_COMPLETED_CLIENT_HTTP
Definition: lws-callbacks.h:389
@ LWS_CALLBACK_CLIENT_CLOSED
Definition: lws-callbacks.h:534
@ LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED
Definition: lws-callbacks.h:572
@ LWS_CALLBACK_DEL_POLL_FD
Definition: lws-callbacks.h:641
@ LWS_CALLBACK_CGI
Definition: lws-callbacks.h:677
@ LWS_CALLBACK_RAW_PROXY_CLI_CLOSE
Definition: lws-callbacks.h:735
@ LWS_CALLBACK_ESTABLISHED
Definition: lws-callbacks.h:414
@ LWS_CALLBACK_RECEIVE_PONG
Definition: lws-callbacks.h:433
@ LWS_CALLBACK_HTTP_BODY_COMPLETION
Definition: lws-callbacks.h:245
@ LWS_CALLBACK_RAW_PROXY_SRV_CLOSE
Definition: lws-callbacks.h:738
@ LWS_CALLBACK_MQTT_ACK
Definition: lws-callbacks.h:874
@ LWS_CALLBACK_CGI_PROCESS_ATTACH
Definition: lws-callbacks.h:701
@ LWS_CALLBACK_HTTP_CONFIRM_UPGRADE
Definition: lws-callbacks.h:339
@ LWS_CALLBACK_CONFIRM_EXTENSION_OKAY
Definition: lws-callbacks.h:459
@ LWS_CALLBACK_MQTT_RESEND
Definition: lws-callbacks.h:880
@ LWS_CALLBACK_TIMER
Definition: lws-callbacks.h:809
@ LWS_CALLBACK_HTTP_DROP_PROTOCOL
Definition: lws-callbacks.h:333
@ LWS_CALLBACK_VHOST_CERT_AGING
Definition: lws-callbacks.h:842
@ LWS_CALLBACK_RAW_ADOPT_FILE
Definition: lws-callbacks.h:787
@ LWS_CALLBACK_CLOSED
Definition: lws-callbacks.h:422
@ LWS_CALLBACK_RECEIVE
Definition: lws-callbacks.h:428
@ LWS_CALLBACK_SSL_INFO
Definition: lws-callbacks.h:172
@ LWS_CALLBACK_VHOST_CERT_UPDATE
Definition: lws-callbacks.h:855
@ LWS_CALLBACK_PROTOCOL_DESTROY
Definition: lws-callbacks.h:109
@ LWS_CALLBACK_RAW_PROXY_SRV_WRITEABLE
Definition: lws-callbacks.h:744
@ LWS_CALLBACK_CGI_STDIN_DATA
Definition: lws-callbacks.h:690
@ LWS_CALLBACK_RAW_PROXY_CLI_RX
Definition: lws-callbacks.h:729
@ LWS_CALLBACK_ESTABLISHED_CLIENT_HTTP
Definition: lws-callbacks.h:357
@ LWS_CALLBACK_RAW_RX
Definition: lws-callbacks.h:765
@ LWS_CALLBACK_FILTER_HTTP_CONNECTION
Definition: lws-callbacks.h:257
@ LWS_CALLBACK_CLIENT_ESTABLISHED
Definition: lws-callbacks.h:530
@ LWS_CALLBACK_SERVER_WRITEABLE
Definition: lws-callbacks.h:425
@ LWS_CALLBACK_WSI_TX_CREDIT_GET
Definition: lws-callbacks.h:121
@ LWS_CALLBACK_CLOSED_HTTP
Definition: lws-callbacks.h:254
@ LWS_CALLBACK_CONNECTING
Definition: lws-callbacks.h:829
@ LWS_CALLBACK_LOCK_POLL
Definition: lws-callbacks.h:657
@ LWS_CALLBACK_PROCESS_HTML
Definition: lws-callbacks.h:313
@ LWS_CALLBACK_RAW_PROXY_SRV_RX
Definition: lws-callbacks.h:732
@ LWS_CALLBACK_CLIENT_WRITEABLE
Definition: lws-callbacks.h:563
@ LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER
Definition: lws-callbacks.h:537
@ LWS_CALLBACK_USER
Definition: lws-callbacks.h:893
@ LWS_CALLBACK_OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY
Definition: lws-callbacks.h:163
@ LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH
Definition: lws-callbacks.h:522
@ LWS_CALLBACK_HTTP_PMO
Definition: lws-callbacks.h:719
@ LWS_CALLBACK_HTTP_FILE_COMPLETION
Definition: lws-callbacks.h:248
@ LWS_CALLBACK_CHILD_CLOSING
Definition: lws-callbacks.h:824
@ LWS_CALLBACK_CHANGE_MODE_POLL_FD
Definition: lws-callbacks.h:648
@ LWS_CALLBACK_RAW_CONNECTED
Definition: lws-callbacks.h:777
@ LWS_CALLBACK_RECEIVE_CLIENT_HTTP
Definition: lws-callbacks.h:371
@ LWS_CALLBACK_ADD_POLL_FD
Definition: lws-callbacks.h:624
@ LWS_CALLBACK_EVENT_WAIT_CANCELLED
Definition: lws-callbacks.h:817
@ LWS_CALLBACK_ADD_HEADERS
Definition: lws-callbacks.h:270
@ LWS_CALLBACK_CLIENT_RECEIVE
Definition: lws-callbacks.h:556
@ LWS_CALLBACK_WS_EXT_DEFAULTS
Definition: lws-callbacks.h:582
@ LWS_CALLBACK_SESSION_INFO
Definition: lws-callbacks.h:709
@ LWS_CALLBACK_WS_PEER_INITIATED_CLOSE
Definition: lws-callbacks.h:436
@ LWS_CALLBACK_CLOSED_CLIENT_HTTP
Definition: lws-callbacks.h:361
@ LWS_CALLBACK_HTTP_BODY
Definition: lws-callbacks.h:241
@ LWS_CALLBACK_RAW_WRITEABLE_FILE
Definition: lws-callbacks.h:796
@ LWS_CALLBACK_RAW_RX_FILE
Definition: lws-callbacks.h:790
@ LWS_CALLBACK_CGI_TERMINATED
Definition: lws-callbacks.h:683
@ LWS_CALLBACK_WSI_DESTROY
Definition: lws-callbacks.h:118
@ LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION
Definition: lws-callbacks.h:446
@ LWS_CALLBACK_RAW_WRITEABLE
Definition: lws-callbacks.h:771
@ LWS_CALLBACK_RAW_PROXY_CLI_ADOPT
Definition: lws-callbacks.h:747
@ LWS_CALLBACK_RAW_CLOSE_FILE
Definition: lws-callbacks.h:799
@ LWS_CALLBACK_PROTOCOL_INIT
Definition: lws-callbacks.h:105
@ LWS_CALLBACK_CGI_STDIN_COMPLETED
Definition: lws-callbacks.h:696
@ LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ
Definition: lws-callbacks.h:364
@ LWS_CALLBACK_CLIENT_CONNECTION_ERROR
Definition: lws-callbacks.h:477
@ LWS_CALLBACK_RAW_PROXY_CLI_WRITEABLE
Definition: lws-callbacks.h:741
@ LWS_CALLBACK_GET_THREAD_ID
Definition: lws-callbacks.h:618
@ LWS_CALLBACK_MQTT_UNSUBSCRIBE_TIMEOUT
Definition: lws-callbacks.h:885
@ LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS
Definition: lws-callbacks.h:129
@ LWS_CALLBACK_RAW_CLOSE
Definition: lws-callbacks.h:768
@ LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION
Definition: lws-callbacks.h:144
@ LWS_CALLBACK_HTTP
Definition: lws-callbacks.h:226
@ LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED
Definition: lws-callbacks.h:218
@ LWS_CALLBACK_CLIENT_HTTP_WRITEABLE
Definition: lws-callbacks.h:394
@ LWS_CALLBACK_GS_EVENT
Definition: lws-callbacks.h:715
@ LWS_CALLBACK_CLIENT_HTTP_REDIRECT
Definition: lws-callbacks.h:404
@ LWS_CALLBACK_CHECK_ACCESS_RIGHTS
Definition: lws-callbacks.h:306
@ LWS_CALLBACK_RAW_PROXY_SRV_ADOPT
Definition: lws-callbacks.h:751
@ LWS_CALLBACK_WSI_CREATE
Definition: lws-callbacks.h:115
@ LWS_CALLBACK_HTTP_WRITEABLE
Definition: lws-callbacks.h:251
Definition: lws-callbacks.h:78
Definition: lws-callbacks.h:88
Definition: lws-callbacks.h:38