• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 WEBSOCKET_CONSTANT_H
17 #define WEBSOCKET_CONSTANT_H
18 
19 #include <map>
20 #include <string>
21 
22 constexpr const char *WEBSOCKET_PROXY_EXCLUSIONS_SEPARATOR = ",";
23 constexpr const int32_t ERR_OK = 0;
24 constexpr const size_t MAP_TUPLE_SIZE = 2;
25 constexpr const uint32_t MAX_LIMIT = 100 * 1024 * 1024;
26 
27 namespace OHOS::NetStack::NetWebSocket {
28 enum WebSocketErrorCode {
29     WEBSOCKET_CONNECT_FAILED = -1,
30     WEBSOCKET_PERMISSION_DENIED_CODE = 201,
31     WEBSOCKET_PARSE_ERROR_CODE = 401,
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_NOT_ALLOWED_HOST = 2302998,
37     WEBSOCKET_UNKNOWN_OTHER_ERROR = 2302999
38 };
39 
40 static const std::map<int32_t, std::string> WEBSOCKET_ERR_MAP = {
41     {WEBSOCKET_CONNECT_FAILED, "Websocket connect failed"},
42     {WEBSOCKET_PERMISSION_DENIED_CODE, "Permission denied"},
43     {WEBSOCKET_PARSE_ERROR_CODE, "Parameter error"},
44     {WEBSOCKET_ERROR_CODE_URL_ERROR, "Websocket url error"},
45     {WEBSOCKET_ERROR_CODE_FILE_NOT_EXIST, "Websocket file not exist"},
46     {WEBSOCKET_ERROR_CODE_CONNECT_AlREADY_EXIST, "Websocket connection exist"},
47     {WEBSOCKET_NOT_ALLOWED_HOST, "It is not allowed to access this domain"},
48     {WEBSOCKET_UNKNOWN_OTHER_ERROR, "Websocket Unknown Other Error"}};
49 
50 enum class WebsocketProxyType {
51     NOT_USE,
52     USE_SYSTEM,
53     USE_SPECIFIED,
54 };
55 
56 enum {
57     CLOSE_REASON_NORMAL_CLOSE [[maybe_unused]] = 1000,
58     CLOSE_REASON_SERVER_CLOSED [[maybe_unused]] = 1001,
59     CLOSE_REASON_PROTOCOL_ERROR [[maybe_unused]] = 1002,
60     CLOSE_REASON_UNSUPPORT_DATA_TYPE [[maybe_unused]] = 1003,
61     CLOSE_REASON_RESERVED1 [[maybe_unused]],
62     CLOSE_REASON_RESERVED2 [[maybe_unused]],
63     CLOSE_REASON_RESERVED3 [[maybe_unused]],
64     CLOSE_REASON_RESERVED4 [[maybe_unused]],
65     CLOSE_REASON_RESERVED5 [[maybe_unused]],
66     CLOSE_REASON_RESERVED6 [[maybe_unused]],
67     CLOSE_REASON_RESERVED7 [[maybe_unused]],
68     CLOSE_REASON_RESERVED8 [[maybe_unused]],
69     CLOSE_REASON_RESERVED9 [[maybe_unused]],
70     CLOSE_REASON_RESERVED10 [[maybe_unused]],
71     CLOSE_REASON_RESERVED11 [[maybe_unused]],
72     CLOSE_REASON_RESERVED12 [[maybe_unused]],
73 };
74 
75 enum OnOffType {
76     EVENT_OPEN = 1,
77     EVENT_MESSAGE = 2,
78     EVENT_CLOSE = 3,
79     EVENT_ERROR = 4,
80     EVENT_DATA_END = 5,
81     EVENT_HEADER_RECEIVE = 6
82 };
83 
84 enum ReceiveResponseType {
85     MAP = 0,
86     ARRAY_STRING = 1,
87     UNDEFINED = 2
88 };
89 
90 enum MessageResponseType {
91     STRING = 0,
92     ARRAY_BUFFER = 1
93 };
94 }
95 #endif