2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FIo_ChannelWebAppStub.h
20 * @brief This is the header file for the _ChannelWebAppStub class.
22 * This file contains the declarations of _ChannelWebAppStub.
25 #ifndef _FIO_INTERNAL_CHANNEL_WEBAPP_STUB_H_
26 #define _FIO_INTERNAL_CHANNEL_WEBAPP_STUB_H_
32 #include <libsoup/soup.h>
34 #include <FOspConfig.h>
35 #include <FBaseObject.h>
36 #include <FBaseString.h>
37 #include <FBaseResult.h>
38 #include <FBaseColArrayList.h>
39 #include <FBaseColHashMap.h>
40 #include <FAppTypes.h>
41 #include <FIo_ChannelService.h>
43 namespace Tizen { namespace Base { namespace Runtime
45 class _EventDispatcher;
48 namespace Tizen { namespace Io
58 class _IIpcServerEventListener;
59 class _ChannelServiceStub;
62 * @class _ChannelWebAppStub
63 * @brief This class provides methods to handle web-application request messages.
67 class _OSP_EXPORT_ _ChannelWebAppStub
68 : public Tizen::Base::Object
72 * This is the default constructor for this class.
75 _ChannelWebAppStub(void);
78 * This is the destructor for this class.
81 virtual ~_ChannelWebAppStub(void);
83 result Construct(void);
85 void SetChannelService(_ChannelService& service);
87 static bool SendResponse(int clientId, const Tizen::Base::Collection::ArrayList& args);
90 _ChannelWebAppStub(const _ChannelWebAppStub& rhs);
92 _ChannelWebAppStub& operator =(const _ChannelWebAppStub& rhs);
94 static gboolean OnConnectionRequest(GIOChannel* source, GIOCondition condition, gpointer data);
96 static gboolean OnReadMessage(GIOChannel* source, GIOCondition condition, gpointer data);
98 gboolean HandleReceivedMessage(GIOChannel* source, GIOCondition condition, gpointer data);
100 static std::string CreateResponseHeader(int appSocket, SoupMessageHeaders *header, const std::string& response);
102 static WebSocketType VerifyHttpHeaderType(std::string header, int headerLength);
103 static std::string MakeHybi00Response(uint32_t first, uint32_t second, unsigned char* third);
104 static std::string MakeHybi10Response(std::string& secureAccept);
106 static bool AppendChallengeNumber(uint32_t number, unsigned char *response);
107 static unsigned int ExtractChallengeNumber(const char* keyString);
108 static char* EncodeBase64(unsigned char *string, int len);
111 // struct _ClientInfo;
113 // struct _ChannelInfo
115 // _ChannelInfo(void);
116 // ~_ChannelInfo(void);
118 // struct _ClientInfo* pClientInfo;
119 // GIOChannel* pGIOChannel;
120 // GSource* pGSource;
121 // bool destroySource;
124 // struct _ClientInfo
126 // _ClientInfo(void);
127 // ~_ClientInfo(void);
129 // int clientId; // the client id
130 // _ChannelWebAppStub* pChannelStub; // the pointer to an _ChannelWebAppStub
131 // //GIOChannel* pReverseChannel; // the channel for sending reverse message
132 // std::vector <struct _ChannelInfo*> channels; // the set of channels associated with a client
133 // //Tizen::Base::String appId;
134 // //Tizen::Base::String appExecutableName;
145 _ClientInfo* pClientInfo;
147 Tizen::App::AppId destAppId;
149 GIOChannel* pGIOChannel;
155 : public Tizen::Base::Object
161 Tizen::App::AppId srcAppId;
164 Tizen::Base::String key; // key = srcAppId + srcAppExecName
165 _ChannelWebAppStub* pChannelStub;
166 std::vector <struct _ChannelInfo*> channels; /**< the set of channels associated with a client */
169 class _WebSocketMessage
172 _WebSocketMessage(void);
173 ~_WebSocketMessage(void);
180 unsigned int opcode : 4;
181 unsigned int rsv3 : 1;
182 unsigned int rsv2 : 1;
183 unsigned int rsv1 : 1;
184 unsigned int fin : 1;
185 unsigned int payloadLen : 7;
186 unsigned int masked : 1;
191 int ParseHeader(uint8_t* header, int messageLen);
192 int ParsePayload(uint8_t* payload, int messageLen);
193 void ConsoleMessage() const;
194 static size_t CreateMessage(std::string& payload, std::string& message);
197 uint8_t m_payloadOffset;
198 uint8_t m_maskingKey[4];
199 uint64_t m_payloadLen;
204 _WebSocketMessage(_WebSocketMessage& webSocketMessage);
206 _WebSocketMessage& operator =(const _WebSocketMessage& webSocketMessage);
210 _ChannelService* __pChannelService;
212 GMainContext* __pGMainContext;
213 GSource* __pServerGSource;
214 GSource* __pClientGSource;
216 Tizen::Base::Collection::HashMap* __pClients;
218 }; // _ChannelWebAppStub
222 #endif // _FIO_INTERNAL_CHANNEL_WEBAPP_STUB_H_