|
1 /** @file |
|
2 * Copyright (c) 2005-2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Base class for HTTP servers. Includes HTTP specific |
|
15 * functionality and represent the highest layer of the HTTP stack. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef C_CUPNPHTTPSERVER_H |
|
21 #define C_CUPNPHTTPSERVER_H |
|
22 |
|
23 // INCLUDES |
|
24 |
|
25 #include <f32file.h> |
|
26 #include "upnptcpserver.h" |
|
27 #include "upnphttpserverobserver.h" |
|
28 #include "upnphttpmessage.h" |
|
29 |
|
30 // FORWARD DECLARATIONS |
|
31 class CUpnpHttpFileAccess; |
|
32 class CUpnpHttpSession; |
|
33 class CUpnpHttpMessage; |
|
34 class MUpnpHttpServerTransactionCreator; |
|
35 |
|
36 // CLASS DECLARATION |
|
37 |
|
38 /** |
|
39 * Base class for HTTP servers. Includes HTTP specific functionality and represents |
|
40 * the highest layer of the HTTP stack. |
|
41 * Http Server derives from CUpnpTcpServer and adds HTTP related features as sending |
|
42 * HTTP messages, queueing messages, forwarding received messages and error codes |
|
43 * to observer layer etc. |
|
44 * @lib DLNAWebServer.lib |
|
45 * @since Series60 2.6 |
|
46 */ |
|
47 NONSHARABLE_CLASS (CUpnpHttpServer) : public CUpnpTcpServer |
|
48 { |
|
49 public: // Constructor and destructor |
|
50 |
|
51 /** |
|
52 * Constructor function. |
|
53 * @since Series60 2.6 |
|
54 * @param aObserver Pointer to this HttpServer observer for callback |
|
55 * functions. |
|
56 * @param aSocketServ Pointer to Socket server. |
|
57 * @param aActiveIap IAP to use with connection. |
|
58 * @param aHandle the thread log handle |
|
59 * @return A new CUpnpHttpServer instance. |
|
60 **/ |
|
61 static CUpnpHttpServer* NewL( MUpnpHttpServerObserver* aObserver, |
|
62 RSocketServ* aSocketServ, |
|
63 TInt aActiveIap ); |
|
64 |
|
65 |
|
66 /** |
|
67 * Virtual Destructor function. |
|
68 * @since Series60 2.6 |
|
69 **/ |
|
70 virtual ~CUpnpHttpServer(); |
|
71 |
|
72 public: // New funtions |
|
73 |
|
74 /** |
|
75 * Starts the HttpServer. |
|
76 * @since Series60 5.0 |
|
77 * @param aPort HTTP make attempt to start on that port |
|
78 **/ |
|
79 void StartL( const TInt aPort ); |
|
80 |
|
81 /** |
|
82 * Stops the HttpServer. |
|
83 * @since Series60 2.6 |
|
84 **/ |
|
85 void Stop(); |
|
86 |
|
87 /** |
|
88 * Forwards message to the upper layer. |
|
89 * @since Series60 2.6 |
|
90 * @param aMsg Pointer to message. |
|
91 **/ |
|
92 void ToReceiveStackD( CUpnpHttpMessage* aMsg ); |
|
93 |
|
94 /** |
|
95 * Sends the message. |
|
96 * @since Series60 2.6 |
|
97 * @param aMessage Pointer to message. |
|
98 * @return Errorcode. |
|
99 **/ |
|
100 TInt SendMessageL( CUpnpHttpMessage* aMessage ); |
|
101 |
|
102 /** |
|
103 * Returns Server's description string. |
|
104 * @since Series60 2.6 |
|
105 * @return Server's description string |
|
106 **/ |
|
107 TDesC8& ServerDescription(); |
|
108 |
|
109 /** |
|
110 * This function sets handle to transaction creator interface. |
|
111 * @since Series60 5.0 |
|
112 * @param aTransactionCreator pointer to object implementing MUpnpHttpServerTransactionCreator |
|
113 * interface. |
|
114 **/ |
|
115 void SetTransactionCreator( MUpnpHttpServerTransactionCreator* aTransactionCreator ); |
|
116 |
|
117 /** |
|
118 * Gets httpFilter |
|
119 */ |
|
120 MUpnpHttpServerTransactionCreator* TransactionCreator(); |
|
121 |
|
122 /** |
|
123 * This method returns the file session handle. |
|
124 * @since Series60 2.6 |
|
125 */ |
|
126 RFs& FileSession(); |
|
127 |
|
128 /** |
|
129 * This method returns the connection handle. |
|
130 * @since Series60 2.6 |
|
131 */ |
|
132 RConnection& ConnectionL(); |
|
133 |
|
134 |
|
135 /****IPFIltering*****/ |
|
136 IMPORT_C void StartIPFilteringL(); |
|
137 IMPORT_C void StopIPFiltering(); |
|
138 /*************************/ |
|
139 |
|
140 public: // From MUpnpMessageObserver |
|
141 |
|
142 /** |
|
143 * Callback for timer in aMessage. This gets called when timer expires and message |
|
144 * is tried to be sent again. |
|
145 * @since Series60 2.6 |
|
146 * @param aMessage Message to be sent. |
|
147 **/ |
|
148 void MessageExpiredL( CUpnpHttpMessage* aMessage ); |
|
149 |
|
150 private: // From CUpnpTcpServer |
|
151 |
|
152 /** |
|
153 * Accept the incoming connection from listening socket, creates a session |
|
154 * and start new listening socket. |
|
155 * @since Series60 2.6 |
|
156 * @param aSocket Socket that has received a new connection. |
|
157 * @return Pointer to a new incoming session. |
|
158 **/ |
|
159 CUpnpTcpSession* ConnectionAcceptedL( RSocket aSocket ); |
|
160 |
|
161 private: // New functions |
|
162 |
|
163 /** |
|
164 * Function that is used for sending messages. |
|
165 * Function first tries to find if message should be sent using existing |
|
166 * session - it means that the message is response for request. If |
|
167 * session is not found then the new one is created and the message is sent |
|
168 * as a request. |
|
169 * @since Series60 2.6 |
|
170 * @param aMessage Message to be sent. |
|
171 * @return If everything is ok, returns session id for that session. Else contains |
|
172 * error code (if value < KErrNone). |
|
173 */ |
|
174 TInt TrapSendMessageL( CUpnpHttpMessage* aMessage ); |
|
175 |
|
176 /** |
|
177 * Returns session |
|
178 * @since Series60 3.2 |
|
179 * @param aSessionId |
|
180 * @return pointer to CUpnpHttpSession |
|
181 **/ |
|
182 CUpnpHttpSession* GetSession( TInt aSessionId ); |
|
183 |
|
184 /** |
|
185 * Increments the counter of redirecting and check if no. of redirections is not above the limit |
|
186 * @since Series60 3.2 |
|
187 * @param aSessionId |
|
188 * @return ETrue - if the counter hasnt exceeded the maximum after incrementating it |
|
189 **/ |
|
190 TBool NewRedirection( TInt aSessionId ); |
|
191 |
|
192 private: // Constructors |
|
193 |
|
194 /** |
|
195 * First phase constructor |
|
196 * @since Series60 2.6 |
|
197 * @param aObserver handle to observer. |
|
198 * @param aSocketServ server socket used for accepting connestions. |
|
199 * @param aActiveIap number of IAP that should be used for connection. |
|
200 * @param aHandle the thread log handle |
|
201 **/ |
|
202 CUpnpHttpServer( MUpnpHttpServerObserver* aObserver, |
|
203 MUpnpHttpServerTransactionCreator* aCreator, |
|
204 RSocketServ* aSocketServ, |
|
205 TInt aActiveIap ); |
|
206 |
|
207 /** |
|
208 * By default Symbian 2nd phase constructor is private. |
|
209 * @since Series60 2.6 |
|
210 */ |
|
211 void ConstructL(); |
|
212 |
|
213 private: // Data |
|
214 |
|
215 // Pointer to this server's observer, not owned. |
|
216 MUpnpHttpServerObserver* iObserver; |
|
217 |
|
218 // Handle to a file server session. |
|
219 RFs iFs; |
|
220 |
|
221 // Bufer containing server's descriptions string used |
|
222 // for filling HTTP Server header value. Owned |
|
223 HBufC8* iServerDescription; |
|
224 }; |
|
225 |
|
226 #endif // C_CUPNPHTTPSERVER_H |
|
227 |
|
228 // End Of File |