|
1 /* |
|
2 * Copyright (c) 2004 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: Implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "CTcSIPConnectionContainer.h" |
|
19 #include "CTcSIPContext.h" |
|
20 #include "SIPConstants.h" |
|
21 #include "TCmdGetMessageAndCreateAssoc.h" |
|
22 #include "TTcSIPReceived.h" |
|
23 |
|
24 #include <sipclienttransaction.h> |
|
25 #include <sipcseqheader.h> |
|
26 #include <sipdialog.h> |
|
27 #include <sipfromheader.h> |
|
28 #include <sipinvitedialogassoc.h> |
|
29 #include <sipmessageelements.h> |
|
30 #include <siprefresh.h> |
|
31 #include <sipregistrationbinding.h> |
|
32 #include <sipresponseelements.h> |
|
33 #include <siprequestelements.h> |
|
34 #include <sipservertransaction.h> |
|
35 #include <sipsubscribedialogassoc.h> |
|
36 #include <siptoheader.h> |
|
37 |
|
38 /** |
|
39 * INPUT: |
|
40 * Headers: - |
|
41 * Parameters: Timeout* |
|
42 * IDs: ConnectionId* |
|
43 * |
|
44 * OUTPUT: |
|
45 * Parameters: StackErrorMsg*, IAPName*, EventType* |
|
46 * IDs: RequestId*, DialogId*, RegistrationId*, RefreshId* |
|
47 * Message: ReturnCode, Headers |
|
48 */ |
|
49 void TCmdGetMessageAndCreateAssoc::ExecuteL() |
|
50 { |
|
51 // -- Setup --------------------------------------------------------------- |
|
52 |
|
53 // Select connection; either default or user specified (and existing) |
|
54 CTcSIPConnectionContainer& conn = SelectConnectionL(); |
|
55 |
|
56 // -- Execution ----------------------------------------------------------- |
|
57 |
|
58 // Get an item off the receive queue (waits until timeout if none is present) |
|
59 TInt timeout = ExtractIntegerL( KParamTimeout, KDefaultReceiveTimeout, EFalse ); |
|
60 TTcSIPReceived item = conn.ReceivedItemL( timeout ); |
|
61 |
|
62 // -- Response creation --------------------------------------------------- |
|
63 |
|
64 // Get client transaction, if any |
|
65 const CSIPClientTransaction* transaction = item.iClientTransaction; |
|
66 const CSIPServerTransaction* serverTransaction = item.iServerTransaction; |
|
67 if( transaction ) |
|
68 { |
|
69 // Get SIP elements from transaction |
|
70 const CSIPResponseElements* resElements = transaction->ResponseElements(); |
|
71 // Check if SIP elements really exists |
|
72 if( resElements && ( |
|
73 resElements->FromHeader() != NULL || |
|
74 resElements->ToHeader() != NULL || |
|
75 resElements->CSeqHeader() != NULL ) ) |
|
76 { |
|
77 CTcNameValue* respCode = CTcNameValue::NewLC(); |
|
78 respCode->SetL( KResponseCode, resElements->StatusCode() ); |
|
79 |
|
80 // Create a new array for the response |
|
81 CTcArray* headers = CTcArray::NewLC(); |
|
82 headers->SetName( KResponseHeaders ); |
|
83 |
|
84 // Add From header to response array if it's present |
|
85 if( resElements->FromHeader() ) |
|
86 { |
|
87 headers->AddItemL( resElements->FromHeader()->ToTextLC()->Des() ); |
|
88 CleanupStack::PopAndDestroy(); |
|
89 } |
|
90 // Add To header to response array if it's present |
|
91 if( resElements->ToHeader() ) |
|
92 { |
|
93 headers->AddItemL( resElements->ToHeader()->ToTextLC()->Des() ); |
|
94 CleanupStack::PopAndDestroy(); |
|
95 } |
|
96 // Add CSeq header to response array if it's present |
|
97 if( resElements->CSeqHeader() ) |
|
98 { |
|
99 headers->AddItemL( resElements->CSeqHeader()->ToTextLC()->Des() ); |
|
100 CleanupStack::PopAndDestroy(); |
|
101 } |
|
102 // Add any user header from message elements to response array |
|
103 const CSIPMessageElements& elements = resElements->MessageElements(); |
|
104 const RPointerArray< CSIPHeaderBase >& userHeaders = elements.UserHeaders(); |
|
105 TInt count = userHeaders.Count(); |
|
106 for( TInt i = 0; i < count; i++ ) |
|
107 { |
|
108 headers->AddItemL( userHeaders[ i ]->ToTextLC()->Des() ); |
|
109 CleanupStack::PopAndDestroy(); |
|
110 } |
|
111 |
|
112 // Add parameters to return list |
|
113 // ReceivedMsg needs to be the first in the parameter list |
|
114 iContext.ReturnList().InsertParameterL( headers, KSIPMessageAtIndex ); |
|
115 iContext.ReturnList().InsertParameterL( respCode, KSIPMessageAtIndex ); |
|
116 |
|
117 CleanupStack::Pop( 2 ); // headers, respCode |
|
118 } |
|
119 |
|
120 AddIdResponseL( KTransactionId, transaction ); |
|
121 } |
|
122 else if( serverTransaction ) |
|
123 { |
|
124 // Get SIP elements from transaction |
|
125 const CSIPRequestElements* reqElements = serverTransaction->RequestElements(); |
|
126 // Check if SIP elements really exists |
|
127 if( reqElements && ( |
|
128 reqElements->FromHeader() != NULL || |
|
129 reqElements->ToHeader() != NULL ) ) |
|
130 { |
|
131 // not defined in requests, of course |
|
132 CTcNameValue* respCode = CTcNameValue::NewLC(); |
|
133 respCode->SetL( KResponseCode, 0 ); |
|
134 |
|
135 CTcNameValue* method = CTcNameValue::NewLC(); |
|
136 method->SetL( KParamMethod, reqElements->Method().DesC() ); |
|
137 |
|
138 // Create a new array for the response |
|
139 CTcArray* headers = CTcArray::NewLC(); |
|
140 headers->SetName( KResponseHeaders ); |
|
141 |
|
142 // Add From header to response array if it's present |
|
143 if( reqElements->FromHeader() ) |
|
144 { |
|
145 headers->AddItemL( reqElements->FromHeader()->ToTextLC()->Des() ); |
|
146 CleanupStack::PopAndDestroy(); |
|
147 } |
|
148 // Add To header to response array if it's present |
|
149 if( reqElements->ToHeader() ) |
|
150 { |
|
151 headers->AddItemL( reqElements->ToHeader()->ToTextLC()->Des() ); |
|
152 CleanupStack::PopAndDestroy(); |
|
153 } |
|
154 // Add any user header from message elements to response array |
|
155 const CSIPMessageElements& elements = reqElements->MessageElements(); |
|
156 const RPointerArray< CSIPHeaderBase >& userHeaders = elements.UserHeaders(); |
|
157 TInt count = userHeaders.Count(); |
|
158 for( TInt i = 0; i < count; i++ ) |
|
159 { |
|
160 headers->AddItemL( userHeaders[ i ]->ToTextLC()->Des() ); |
|
161 CleanupStack::PopAndDestroy(); |
|
162 } |
|
163 |
|
164 // Add parameters to return list |
|
165 // ReceivedMsg needs to be the first in the parameter list |
|
166 iContext.ReturnList().InsertParameterL( headers, KSIPMessageAtIndex ); |
|
167 iContext.ReturnList().InsertParameterL( method, KSIPMessageAtIndex ); |
|
168 iContext.ReturnList().InsertParameterL( respCode, KSIPMessageAtIndex ); |
|
169 |
|
170 CleanupStack::Pop( 3 ); |
|
171 } |
|
172 |
|
173 AddIdResponseL( KServerTransactionId, serverTransaction ); |
|
174 } |
|
175 if( item.iDialog ) |
|
176 { |
|
177 AddIdResponseL( KDialogId, item.iDialog ); |
|
178 } |
|
179 |
|
180 if( item.iInviteDialogAssoc ) |
|
181 { |
|
182 CSIPServerTransaction* newTransaction = |
|
183 const_cast< CSIPServerTransaction* >( item.iServerTransaction ); |
|
184 CSIPInviteDialogAssoc* inviteDialogAssocNew = |
|
185 CSIPInviteDialogAssoc::NewL( *(newTransaction) ); |
|
186 |
|
187 // Add invite dialog id to response |
|
188 item.iInviteDialogAssoc = inviteDialogAssocNew; |
|
189 AddIdResponseL( KInviteDialogId, item.iInviteDialogAssoc ); |
|
190 } |
|
191 else if( item.iSubscribeDialogAssoc ) |
|
192 { |
|
193 AddIdResponseL( KSubscribeDialogId, item.iSubscribeDialogAssoc ); |
|
194 } |
|
195 |
|
196 if( item.iRegistration ) |
|
197 { |
|
198 AddIdResponseL( KRegistrationId, item.iRegistration ); |
|
199 } |
|
200 else if( item.iRefresh ) |
|
201 { |
|
202 AddIdResponseL( KRefreshId, item.iRefresh ); |
|
203 } |
|
204 |
|
205 if( item.iIapId ) |
|
206 { |
|
207 AddTextResponseL( KParamIAPName, iContext.IAPNameL( item.iIapId ) ); |
|
208 } |
|
209 |
|
210 if ( item.iEvent ) |
|
211 { |
|
212 AddIntegerResponseL( KParamEventType, item.iEvent ); |
|
213 } |
|
214 |
|
215 if( item.iError != KErrNone ) |
|
216 { |
|
217 AddTextResponseL( KParamStackErrorMsg, iContext.SIPErrorToText( item.iError ) ); |
|
218 User::Leave( item.iError ); |
|
219 } |
|
220 } |
|
221 |
|
222 TBool TCmdGetMessageAndCreateAssoc::Match( const TTcIdentifier& aId ) |
|
223 { |
|
224 return TTcSIPCommandBase::Match( aId, _L8("GetMessageAndCreateAssoc") ); |
|
225 } |
|
226 |
|
227 TTcCommandBase* TCmdGetMessageAndCreateAssoc::CreateL( MTcTestContext& aContext ) |
|
228 { |
|
229 return new( ELeave ) TCmdGetMessageAndCreateAssoc( aContext ); |
|
230 } |
|
231 |