]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/gateway/websocket_plugin.h
LP#1824184: Change potentially slow log statements to subroutines
[OpenSRF.git] / src / gateway / websocket_plugin.h
1 /*
2  * Copyright 2010-2011 self.disconnect
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #if !defined(_MOD_WEBSOCKET_H_)
18 #define _MOD_WEBSOCKET_H_
19
20 #include <stdlib.h>
21
22 #if defined(__cplusplus)
23 extern "C"
24 {
25 #endif
26
27 #if defined(_WIN32)
28 #define EXPORT __declspec(dllexport)
29 #define CALLBACK __stdcall
30 #else
31 #define EXPORT
32 #define CALLBACK
33 #endif
34
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
41
42     struct _WebSocketServer;
43
44     typedef struct request_rec *(CALLBACK * WS_Request)
45                                 (const struct _WebSocketServer *server);
46
47     typedef const char *(CALLBACK * WS_Header_Get)
48                         (const struct _WebSocketServer *server,
49                          const char *key);
50
51     typedef void (CALLBACK * WS_Header_Set)
52                  (const struct _WebSocketServer *server,
53                   const char *key,
54                   const char *value);
55
56     typedef size_t (CALLBACK * WS_Protocol_Count)
57                    (const struct _WebSocketServer *server);
58
59     typedef const char *(CALLBACK * WS_Protocol_Index)
60                         (const struct _WebSocketServer *server,
61                          const size_t index);
62
63     typedef void (CALLBACK * WS_Protocol_Set)
64                  (const struct _WebSocketServer *server,
65                   const char *protocol);
66
67     typedef size_t (CALLBACK * WS_Send)
68                    (const struct _WebSocketServer *server,
69                     const int type,
70                     const unsigned char *buffer,
71                     const size_t buffer_size);
72
73     typedef void (CALLBACK * WS_Close)
74                  (const struct _WebSocketServer *server);
75
76 #define WEBSOCKET_SERVER_VERSION_1 1
77
78     typedef struct _WebSocketServer
79     {
80         unsigned int size;
81         unsigned int version;
82         struct _WebSocketState *state;
83         WS_Request request;
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;
89         WS_Send send;
90         WS_Close close;
91     } WebSocketServer;
92
93     struct _WebSocketPlugin;
94
95     typedef struct _WebSocketPlugin *(CALLBACK * WS_Init)
96                                      ();
97     typedef void (CALLBACK * WS_Destroy)
98                  (struct _WebSocketPlugin *plugin);
99
100     typedef void *(CALLBACK * WS_OnConnect)
101                   (const WebSocketServer *server); /* Returns plugin_private */
102
103     typedef size_t (CALLBACK * WS_OnMessage)
104                    (void *plugin_private,
105                     const WebSocketServer *server,
106                     const int type,
107                     unsigned char *buffer,
108                     const size_t buffer_size);
109
110     typedef void (CALLBACK * WS_OnDisconnect)
111                  (void *plugin_private,
112                   const WebSocketServer *server);
113
114 #define WEBSOCKET_PLUGIN_VERSION_0 0
115
116   typedef struct _WebSocketPlugin
117   {
118       unsigned int size;
119       unsigned int version;
120       WS_Destroy destroy;
121       WS_OnConnect on_connect;
122       WS_OnMessage on_message;
123       WS_OnDisconnect on_disconnect;
124   } WebSocketPlugin;
125
126 #if defined(__cplusplus)
127 }
128 #endif
129
130 #endif                          /* _MOD_WEBSOCKET_H_ */