2 * Copyright 2010-2011 self.disconnect
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #if !defined(_MOD_WEBSOCKET_H_)
18 #define _MOD_WEBSOCKET_H_
22 #if defined(__cplusplus)
28 #define EXPORT __declspec(dllexport)
29 #define CALLBACK __stdcall
35 #define MESSAGE_TYPE_INVALID -1
36 #define MESSAGE_TYPE_TEXT 0
37 #define MESSAGE_TYPE_BINARY 128
38 #define MESSAGE_TYPE_CLOSE 255
39 #define MESSAGE_TYPE_PING 256
40 #define MESSAGE_TYPE_PONG 257
42 struct _WebSocketServer;
44 typedef struct request_rec *(CALLBACK * WS_Request)
45 (const struct _WebSocketServer *server);
47 typedef const char *(CALLBACK * WS_Header_Get)
48 (const struct _WebSocketServer *server,
51 typedef void (CALLBACK * WS_Header_Set)
52 (const struct _WebSocketServer *server,
56 typedef size_t (CALLBACK * WS_Protocol_Count)
57 (const struct _WebSocketServer *server);
59 typedef const char *(CALLBACK * WS_Protocol_Index)
60 (const struct _WebSocketServer *server,
63 typedef void (CALLBACK * WS_Protocol_Set)
64 (const struct _WebSocketServer *server,
65 const char *protocol);
67 typedef size_t (CALLBACK * WS_Send)
68 (const struct _WebSocketServer *server,
70 const unsigned char *buffer,
71 const size_t buffer_size);
73 typedef void (CALLBACK * WS_Close)
74 (const struct _WebSocketServer *server);
76 #define WEBSOCKET_SERVER_VERSION_1 1
78 typedef struct _WebSocketServer
82 struct _WebSocketState *state;
84 WS_Header_Get header_get;
85 WS_Header_Set header_set;
86 WS_Protocol_Count protocol_count;
87 WS_Protocol_Index protocol_index;
88 WS_Protocol_Set protocol_set;
93 struct _WebSocketPlugin;
95 typedef struct _WebSocketPlugin *(CALLBACK * WS_Init)
97 typedef void (CALLBACK * WS_Destroy)
98 (struct _WebSocketPlugin *plugin);
100 typedef void *(CALLBACK * WS_OnConnect)
101 (const WebSocketServer *server); /* Returns plugin_private */
103 typedef size_t (CALLBACK * WS_OnMessage)
104 (void *plugin_private,
105 const WebSocketServer *server,
107 unsigned char *buffer,
108 const size_t buffer_size);
110 typedef void (CALLBACK * WS_OnDisconnect)
111 (void *plugin_private,
112 const WebSocketServer *server);
114 #define WEBSOCKET_PLUGIN_VERSION_0 0
116 typedef struct _WebSocketPlugin
119 unsigned int version;
121 WS_OnConnect on_connect;
122 WS_OnMessage on_message;
123 WS_OnDisconnect on_disconnect;
126 #if defined(__cplusplus)
130 #endif /* _MOD_WEBSOCKET_H_ */