|
1 /** @file |
|
2 * Copyright (c) 2009 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: CUpnpHttpServerTransactionDescription implementation. |
|
15 * |
|
16 */ |
|
17 #include <uri8.h> |
|
18 #include "upnphttpservertransactiondescription.h" |
|
19 #include "upnphttpservertransactionhandler.h" |
|
20 #include "upnperrors.h" |
|
21 #include "upnphttpmessage.h" |
|
22 #include "upnpstring.h" |
|
23 |
|
24 |
|
25 // --------------------------------------------------------------------------- |
|
26 // CUpnpHttpServerTransactionDescription::NewL |
|
27 // |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 CUpnpHttpServerTransactionDescription* CUpnpHttpServerTransactionDescription::NewL( |
|
31 CUpnpHttpServerTransactionHandler& aClientContext, const TInetAddr& aSender, |
|
32 const TDesC8& aUri ) |
|
33 { |
|
34 CUpnpHttpServerTransactionDescription* self = |
|
35 new (ELeave) CUpnpHttpServerTransactionDescription( aClientContext ); |
|
36 CleanupStack::PushL( self ); |
|
37 self->ConstructL( aSender, aUri ); |
|
38 CleanupStack::Pop( self ); |
|
39 return self; |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // CUpnpHttpServerTransactionDescription::CUpnpHttpServerTransactionDescription |
|
44 // |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 CUpnpHttpServerTransactionDescription::CUpnpHttpServerTransactionDescription( |
|
48 CUpnpHttpServerTransactionHandler& aClientContext ) |
|
49 : iClientContext( aClientContext ) |
|
50 { |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // CUpnpHttpServerTransactionDescription::ConstructL |
|
55 // |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 void CUpnpHttpServerTransactionDescription::ConstructL( |
|
59 const TInetAddr& aSender, const TDesC8& aUri ) |
|
60 { |
|
61 iSender = aSender; |
|
62 iSenderUri = aUri.AllocL(); |
|
63 iDecodedUri.CreateL( aUri ); |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // CUpnpHttpServerTransactionDescription::~CUpnpHttpServerTransactionDescription |
|
68 // |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 CUpnpHttpServerTransactionDescription::~CUpnpHttpServerTransactionDescription() |
|
72 { |
|
73 delete iSenderUri; |
|
74 iDecodedUri.Close(); |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // CUpnpHttpServerTransactionDescription::OnCallbackL |
|
79 // |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 void CUpnpHttpServerTransactionDescription::OnCallbackL( TUpnpHttpServerEvent aEvent ) |
|
83 { |
|
84 TRAPD( err, DoCallbackL(aEvent) ); |
|
85 if ( err ) |
|
86 { |
|
87 SetHttpCode( err ); |
|
88 } |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // CUpnpHttpServerTransactionDescription::OnCallbackL |
|
93 // |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 void CUpnpHttpServerTransactionDescription::DoCallbackL( TUpnpHttpServerEvent aEvent ) |
|
97 { |
|
98 switch ( aEvent ) |
|
99 { |
|
100 case EOnRequestStart: |
|
101 { |
|
102 TInt error = DecodeUri(); |
|
103 if ( error ) |
|
104 { |
|
105 SetHttpCode( error ); |
|
106 } |
|
107 else |
|
108 { |
|
109 RFile file; |
|
110 TInt error = iClientContext.GetFileL( file, *iSenderUri, iSender ); |
|
111 if ( error ) |
|
112 { |
|
113 SetHttpCode( error ); |
|
114 } |
|
115 else |
|
116 { |
|
117 SetDataSourceL( file ); |
|
118 } |
|
119 } |
|
120 } |
|
121 break; |
|
122 case EOnComplete: |
|
123 break; |
|
124 case EOnResponseStart: |
|
125 break; |
|
126 default: |
|
127 break; |
|
128 } |
|
129 } |
|
130 |
|
131 |
|
132 TInt CUpnpHttpServerTransactionDescription::DecodeUri( ) |
|
133 { |
|
134 TInt error = KErrNone; |
|
135 UpnpString::ReplaceHttpCharacters( iDecodedUri ); |
|
136 TUriParser8 up; |
|
137 TInt parseError = up.Parse( iDecodedUri ); |
|
138 if ( parseError ) |
|
139 { |
|
140 error = -EHttpBadRequest; |
|
141 } |
|
142 return error; |
|
143 } |
|
144 |
|
145 |