1 mike 1.1 /*
2 **==============================================================================
3 **
4 ** Open Management Infrastructure (OMI)
5 **
6 ** Copyright (c) Microsoft Corporation
7 **
8 ** Licensed under the Apache License, Version 2.0 (the "License"); you may not
9 ** use this file except in compliance with the License. You may obtain a copy
10 ** of the License at
11 **
12 ** http://www.apache.org/licenses/LICENSE-2.0
13 **
14 ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 ** MERCHANTABLITY OR NON-INFRINGEMENT.
18 **
19 ** See the Apache 2 License for the specific language governing permissions
20 ** and limitations under the License.
21 **
22 mike 1.1 **==============================================================================
23 */
24
25 #ifndef _omi_protocol_h
26 #define _omi_protocol_h
27
28 #include "config.h"
29 #include <string.h>
30 #include <common.h>
|
31 krisbash 1.4 #include <base/Strand.h>
|
32 mike 1.2 #include <sock/selector.h>
|
33 krisbash 1.4 #include <pal/thread.h>
34 #include <protocol/header.h>
|
35 mike 1.1
36 BEGIN_EXTERNC
37
|
38 krisbash 1.4 #define PROTOCOLSOCKET_STRANDAUX_POSTMSG 0
39 #define PROTOCOLSOCKET_STRANDAUX_READYTOFINISH 1
40 #define PROTOCOLSOCKET_STRANDAUX_CONNECTEVENT 2
|
41 mike 1.1
|
42 krisbash 1.4 typedef enum _Protocol_AuthState
43 {
44 /* authentication failed (intentionaly takes value '0')*/
45 PRT_AUTH_FAILED,
46
47 /* listener (server) waits for connect request */
48 PRT_AUTH_WAIT_CONNECTION_REQUEST,
49
50 /* listener (server) waits for second connect request with random data from file */
51 PRT_AUTH_WAIT_CONNECTION_REQUEST_WITH_FILE_DATA,
52
53 /* connector (client) waits for server's response */
54 PRT_AUTH_WAIT_CONNECTION_RESPONSE,
55
56 /* authentication completed */
57 PRT_AUTH_OK
58 }
59 Protocol_AuthState;
60
61 typedef enum _Protocol_Type
62 {
63 krisbash 1.4 PRT_TYPE_LISTENER,
64 PRT_TYPE_CONNECTOR,
65 PRT_TYPE_FROM_SOCKET
66 }
67 Protocol_Type;
68
69 /* Keeps data for file-based authentication */
70 typedef struct _Protocol_AuthData
71 {
72 char path[PAL_MAX_PATH_SIZE];
73 char authRandom[AUTH_RANDOM_DATA_SIZE];
74 }
75 Protocol_AuthData;
76
77 typedef struct _ProtocolBase
78 {
79 MI_Uint32 magic; //TODO: Evaluate if this is still needed after implementing multiplexer
80 Selector* selector;
81 Selector internal_selector;
82 MI_Boolean internal_selector_used;
83 Addr addr;
84 krisbash 1.4 OpenCallback callback; // Callback for new Interaction (when the connection is opened on listener/agent)
85 void* callbackData;
86 Protocol_Type type;
87 /* Indicates whether instance has to be upacked or stored as byte array */
88 MI_Boolean skipInstanceUnpack;
89 }
90 ProtocolBase;
91
92 typedef struct _ProtocolSocket
93 {
94 /* based member*/
95 Handler base;
96
97 Strand strand;
98
99 /* currently sending message */
100 Message* message;
101 size_t sentCurrentBlockBytes;
102 int sendingPageIndex; /* 0 for header otherwise 1-N page index */
103
104 /* receiving data */
105 krisbash 1.4 Batch * receivingBatch;
106 size_t receivedCurrentBlockBytes;
107 int receivingPageIndex; /* 0 for header otherwise 1-N page index */
108
109 /* send/recv buffers */
110 Header recv_buffer;
111 Header send_buffer;
112
113 /* Auth state */
114 Protocol_AuthState authState;
115 /* server side - auhtenticated user's ids */
116 AuthInfo authInfo;
117 Protocol_AuthData* authData;
118
119 /* Whether connection has been established */
120 MI_Boolean isConnected;
121 volatile ptrdiff_t connectEventSent;
122
123 volatile ptrdiff_t refCount; //used by socket listner for lifetimemanagement
124 MI_Boolean closeOtherScheduled;
125 }
126 krisbash 1.4 ProtocolSocket;
127
128 // Combined with a internal protocol base
129 // A connector (PRT_TYPE_CONNECTOR) or either side of an agent connection (PRT_TYPE_FROM_SOCKET)
130 typedef struct _ProtocolSocketAndBase
131 {
132 ProtocolSocket protocolSocket;
133 ProtocolBase internalProtocolBase;
134 }
135 ProtocolSocketAndBase;
136
137 MI_Result ProtocolBase_New_Listener(
138 _Out_ ProtocolBase** selfOut,
139 _In_opt_ Selector* selector, /*optional, maybe NULL*/
140 _In_ const char* locator,
141 _In_ OpenCallback callback,
142 _In_ void* callbackData);
|
143 mike 1.1
144 /*
145 Creates new protocol object (client side) and
146 connect it to the server.
147
148 Parameters:
149 self - [out] protocol object
150 selector - [opt] selector to use for socket monitoring
151 locator - server's address (typically domain socket file name)
152 callback - function that protocol calls to inform about new messsages
153 callbackData -
154 eventCallback - function that protocl calls to inform about socket states
155 connected/disconnected
156 user, password [opt] - credentials for explicit auth. If NULL,
157 implicit authentication is used
158
159 Returns:
160 'OK' if succefful, error otherwise
161 */
|
162 krisbash 1.4 MI_Result ProtocolSocketAndBase_New_Connector(
163 _Out_ ProtocolSocketAndBase** selfOut,
164 _In_opt_ Selector* selector, // optional, maybe NULL
165 _In_ const char* locator,
166 _In_ InteractionOpenParams* params,
167 _In_ const char* user,
168 _In_ const char* password );
169
170 MI_Result ProtocolSocketAndBase_New_AgentConnector(
171 _Out_ ProtocolSocketAndBase** selfOut,
172 _In_opt_ Selector* selector, // optional, maybe NULL
173 _In_ Sock s,
174 _In_ InteractionOpenParams* params );
175
176 MI_Result ProtocolSocketAndBase_New_Agent(
177 _Out_ ProtocolSocketAndBase** selfOut,
178 _In_opt_ Selector* selector, // optional, maybe NULL
179 _In_ Sock s,
180 _In_ OpenCallback callback,
181 _In_ void* callbackData); // used along with callback
182
183 krisbash 1.4 MI_Result ProtocolBase_Delete(
184 ProtocolBase* self);
185
186 // Call this once it is out of the selector run loop
187 MI_INLINE void ProtocolSocketAndBase_ReadyToFinish(
188 ProtocolSocketAndBase* self)
189 {
190 Strand_ScheduleAux( &self->protocolSocket.strand, PROTOCOLSOCKET_STRANDAUX_READYTOFINISH );
191 }
|
192 mike 1.1
193 MI_Result Protocol_Run(
|
194 krisbash 1.4 ProtocolBase* self,
|
195 mike 1.1 MI_Uint64 timeoutUsec);
196
197 END_EXTERNC
198
199 #endif /* _omi_protocol_h */
|