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