|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Name : SIPRequestUtility.cpp |
|
15 // Part of : TransactionUser |
|
16 // Version : SIP/4.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "siperr.h" |
|
22 #include "SipAssert.h" |
|
23 #include "siprequest.h" |
|
24 #include "uricontainer.h" |
|
25 #include "siprouteheader.h" |
|
26 #include "sipsupportedheader.h" |
|
27 #include "sipaddress.h" |
|
28 #include "sipmaxforwardsheader.h" |
|
29 #include "sipstrings.h" |
|
30 #include "sipstrconsts.h" |
|
31 |
|
32 #include "SIPRequestUtility.h" |
|
33 #include "RouteSet.h" |
|
34 |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // SIPRequestUtility::CheckOutgoingRequestL |
|
38 // Request-URI can be present if the request is sent by Refresh subsystem. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 void SIPRequestUtility::CheckOutgoingRequestL(CSIPRequest& aReq) |
|
42 { |
|
43 __SIP_ASSERT_LEAVE(aReq.Method().DesC().Length() > 0, |
|
44 KErrSIPMalformedMessage); |
|
45 __SIP_ASSERT_LEAVE(aReq.To() != NULL, KErrSIPMalformedMessage); |
|
46 __SIP_ASSERT_LEAVE(aReq.From() != NULL, KErrSIPMalformedMessage); |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // SIPRequestUtility::SetRequestUriL |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 void SIPRequestUtility::SetRequestUriL(CSIPRequest& aReq, |
|
54 const CURIContainer& aUri) |
|
55 { |
|
56 CURIContainer* reqUri = CURIContainer::NewLC(aUri); |
|
57 aReq.SetRequestURIL(reqUri); |
|
58 CleanupStack::Pop(reqUri); |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // SIPRequestUtility::FillRouteAndRequestUriL |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 void |
|
66 SIPRequestUtility::FillRouteAndRequestUriL(CSIPRequest& aReq, |
|
67 const CRouteSet& aRouteSet, |
|
68 const CURIContainer& aRemoteTarget) |
|
69 { |
|
70 aReq.DeleteHeaders(SIPStrings::StringF(SipStrConsts::ERouteHeader)); |
|
71 |
|
72 if (aRouteSet.IsEmpty()) |
|
73 { |
|
74 SetRequestUriL(aReq, aRemoteTarget); |
|
75 } |
|
76 else |
|
77 { |
|
78 if (aRouteSet.IsLrParamInTopRoute()) |
|
79 { |
|
80 SetRequestUriL(aReq, aRemoteTarget); |
|
81 aRouteSet.CopyToRequestL(aReq); |
|
82 } |
|
83 else |
|
84 { |
|
85 //Put first URI in route set to Request-URI. Add rest of the route |
|
86 //set as Route headers. Add remote target as the last route header. |
|
87 SetRequestUriL(aReq, *aRouteSet.TopUri()); |
|
88 aRouteSet.CopyToRequestL(aReq, 1); |
|
89 |
|
90 if (!aRouteSet.IsInSet(aRemoteTarget)) |
|
91 { |
|
92 CSIPRouteHeader* route = CreateRouteHeaderLC(aRemoteTarget); |
|
93 aReq.AddHeaderL(route); |
|
94 CleanupStack::Pop(route); |
|
95 } |
|
96 } |
|
97 } |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // SIPRequestUtility::CreateRouteHeaderLC |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 CSIPRouteHeader* |
|
105 SIPRequestUtility::CreateRouteHeaderLC(const CURIContainer& aUri) |
|
106 { |
|
107 HBufC8* uri = aUri.ToTextL(); |
|
108 CleanupStack::PushL(uri); |
|
109 CSIPAddress* addr = CSIPAddress::DecodeL(*uri); |
|
110 CleanupStack::PopAndDestroy(uri); |
|
111 CleanupStack::PushL(addr); |
|
112 CSIPRouteHeader* route = CSIPRouteHeader::NewL(addr); |
|
113 CleanupStack::Pop(addr); |
|
114 CleanupStack::PushL(route); |
|
115 return route; |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // SIPRequestUtility::FillNewMaxForwardsL |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 void SIPRequestUtility::FillNewMaxForwardsL(CSIPRequest& aReq) |
|
123 { |
|
124 CSIPMaxForwardsHeader* maxForw = |
|
125 new (ELeave) CSIPMaxForwardsHeader(EMaxForwardsValue); |
|
126 CleanupStack::PushL(maxForw); |
|
127 aReq.AddHeaderL(maxForw); |
|
128 CleanupStack::Pop(maxForw); |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // SIPRequestUtility::FillSupportedSecAgreeL |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 void SIPRequestUtility::FillSupportedSecAgreeL(CSIPRequest& aReq) |
|
136 { |
|
137 CSIPSupportedHeader* supported = CSIPSupportedHeader::NewLC( |
|
138 SIPStrings::StringF(SipStrConsts::ESecAgreeTag)); |
|
139 aReq.AddHeaderL(supported); |
|
140 CleanupStack::Pop(supported); |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // SIPRequestUtility::CleanupRouteHeaders |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 void SIPRequestUtility::CleanupRouteHeaders(TAny* aRouteHeaders) |
|
148 { |
|
149 __SIP_ASSERT_RETURN(aRouteHeaders, KErrArgument); |
|
150 |
|
151 reinterpret_cast<RPointerArray<CSIPHeaderBase>*> |
|
152 (aRouteHeaders)->ResetAndDestroy(); |
|
153 } |