• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef COMMUNICATIONNETSTACK_CONSTANT_H
17 #define COMMUNICATIONNETSTACK_CONSTANT_H
18 
19 #include <map>
20 #include <string>
21 
22 namespace OHOS::NetStack::Websocket {
23 enum {
24     FUNCTION_PARAM_ZERO = 0,
25     FUNCTION_PARAM_ONE = 1,
26     FUNCTION_PARAM_TWO = 2,
27     FUNCTION_PARAM_THREE = 3,
28 };
29 
30 enum WebsocketErrorCode {
31     WEBSOCKET_CONNECT_FAILED = -1,
32     WEBSOCKET_ERROR_CODE_BASE = 2302000,
33     WEBSOCKET_ERROR_CODE_URL_ERROR = WEBSOCKET_ERROR_CODE_BASE + 1,
34     WEBSOCKET_ERROR_CODE_FILE_NOT_EXIST = WEBSOCKET_ERROR_CODE_BASE + 2,
35     WEBSOCKET_ERROR_CODE_CONNECT_AlREADY_EXIST = WEBSOCKET_ERROR_CODE_BASE + 3,
36     WEBSOCKET_ERROR_CODE_INVALID_NIC = WEBSOCKET_ERROR_CODE_BASE + 4,
37     WEBSOCKET_ERROR_CODE_INVALID_PORT = WEBSOCKET_ERROR_CODE_BASE + 5,
38     WEBSOCKET_ERROR_CODE_CONNECTION_NOT_EXIST = WEBSOCKET_ERROR_CODE_BASE + 6,
39     WEBSOCKET_NOT_ALLOWED_HOST = 2302998,
40     WEBSOCKET_UNKNOWN_OTHER_ERROR = 2302999
41 };
42 
43 static const std::map<int32_t, std::string> WEBSOCKET_ERR_MAP = {
44     {WEBSOCKET_CONNECT_FAILED, "Websocket connect failed"},
45     {WEBSOCKET_ERROR_CODE_URL_ERROR, "Websocket url error"},
46     {WEBSOCKET_ERROR_CODE_FILE_NOT_EXIST, "Websocket file not exist"},
47     {WEBSOCKET_ERROR_CODE_CONNECT_AlREADY_EXIST, "Websocket connection exist"},
48     {WEBSOCKET_ERROR_CODE_INVALID_NIC, "Can't listen to the given NIC"},
49     {WEBSOCKET_ERROR_CODE_INVALID_PORT, "Can't listen to the given Port"},
50     {WEBSOCKET_ERROR_CODE_CONNECTION_NOT_EXIST, "websocket connection does not exist"},
51     {WEBSOCKET_NOT_ALLOWED_HOST, "It is not allowed to access this domain"},
52     {WEBSOCKET_UNKNOWN_OTHER_ERROR, "Websocket Unknown Other Error"}};
53 
54 enum {
55     CLOSE_REASON_NORMAL_CLOSE [[maybe_unused]] = 1000,
56     CLOSE_REASON_SERVER_CLOSED [[maybe_unused]] = 1001,
57     CLOSE_REASON_PROTOCOL_ERROR [[maybe_unused]] = 1002,
58     CLOSE_REASON_UNSUPPORT_DATA_TYPE [[maybe_unused]] = 1003,
59     CLOSE_REASON_RESERVED1 [[maybe_unused]],
60     CLOSE_REASON_RESERVED2 [[maybe_unused]],
61     CLOSE_REASON_RESERVED3 [[maybe_unused]],
62     CLOSE_REASON_RESERVED4 [[maybe_unused]],
63     CLOSE_REASON_RESERVED5 [[maybe_unused]],
64     CLOSE_REASON_RESERVED6 [[maybe_unused]],
65     CLOSE_REASON_RESERVED7 [[maybe_unused]],
66     CLOSE_REASON_RESERVED8 [[maybe_unused]],
67     CLOSE_REASON_RESERVED9 [[maybe_unused]],
68     CLOSE_REASON_RESERVED10 [[maybe_unused]],
69     CLOSE_REASON_RESERVED11 [[maybe_unused]],
70     CLOSE_REASON_RESERVED12 [[maybe_unused]],
71 };
72 
73 enum class WebsocketProxyType {
74     NOT_USE,
75     USE_SYSTEM,
76     USE_SPECIFIED,
77 };
78 
79 class ContextKey final {
80 public:
81     static const char *HEADER;
82 
83     static const char *CAPATH;
84     static const char *CLIENT_CERT;
85     static const char *CERT_PATH;
86     static const char *KEY_PATH;
87     static const char *KEY_PASSWD;
88     static const char *KEY_SKIP_SERVER_CERT_VERIFY;
89 
90     static const char *PROXY;
91     static const char *PROTCOL;
92     static const char *USE_SYSTEM_PROXY;
93     static const char *NOT_USE_PROXY;
94 
95     static const char *WEBSOCKET_PROXY_HOST;
96     static const char *WEBSOCKET_PROXY_PORT;
97     static const char *WEBSOCKET_PROXY_EXCLUSION_LIST;
98     static const char *WEBSOCKET_PROXY_EXCLUSIONS_SEPARATOR;
99 
100     static const char *CODE;
101     static const char *REASON;
102 /* WebSocketConnection */
103     static const char *CLIENT_PORT;
104     static const char *CLIENT_IP;
105 
106 /* WebSocketServerConfig */
107     static const char *SERVER_PORT;
108     static const char *MAX_CLIENT_NUMBER;
109     static const char *MAX_CONNECTIONS_FOR_ONE_CLIENT;
110     static const char *SERVER_IP;
111     static const char *SERVER_CERT;
112     static const char *PROTOCOL;
113     static const char *PING_INTERVAL;
114     static const char *PONG_TIMEOUT;
115 };
116 
117 class EventName final {
118 public:
119     static const char *EVENT_OPEN;
120     static const char *EVENT_MESSAGE;
121     static const char *EVENT_CLOSE;
122     static const char *EVENT_ERROR;
123     static const char *EVENT_DATA_END;
124     static const char *EVENT_HEADER_RECEIVE;
125 
126 /* websocketServer */
127     static const char *EVENT_SERVER_ERROR;
128     static const char *EVENT_SERVER_CONNECT;
129     static const char *EVENT_SERVER_MESSAGE_RECEIVE;
130     static const char *EVENT_SERVER_CLOSE;
131 };
132 } // namespace OHOS::NetStack::Websocket
133 #endif /* COMMUNICATIONNETSTACK_CONSTANT_H */
134