|
1 // Copyright (c) 2004-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 : SIPCodecUtils.cpp |
|
15 // Part of : SIP Codec |
|
16 // Version : SIP/4.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "sipcodecutils.h" |
|
22 #include "siprouteheader.h" |
|
23 #include "siprecordrouteheader.h" |
|
24 #include "sipaddress.h" |
|
25 #include "SIPSyntaxCheck.h" |
|
26 #include "sipstrings.h" |
|
27 #include "_sipcodecdefs.h" |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // SIPCodecUtils::SIPCodecUtils |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 SIPCodecUtils::SIPCodecUtils() |
|
34 { |
|
35 } |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // SIPCodecUtils::CreateRouteHeaderLC |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 EXPORT_C CSIPRouteHeader* |
|
42 SIPCodecUtils::CreateRouteHeaderLC(const CSIPRouteHeaderBase& aHeader) |
|
43 { |
|
44 CSIPRouteHeader* header = CSIPRouteHeader::NewL(aHeader); |
|
45 CleanupStack::PushL(header); |
|
46 return header; |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // SIPCodecUtils::CopyRecordRouteHeaderLC |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 EXPORT_C CSIPRecordRouteHeader* |
|
54 SIPCodecUtils::CreateRecordRouteHeaderLC(const CSIPRouteHeaderBase& aHeader) |
|
55 { |
|
56 CSIPRecordRouteHeader* header = CSIPRecordRouteHeader::NewL(aHeader); |
|
57 CleanupStack::PushL(header); |
|
58 return header; |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // SIPCodecUtils::CreateSIPAddressLC |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 EXPORT_C CSIPAddress* SIPCodecUtils::CreateSIPAddressLC(CURIContainer* aURI) |
|
66 { |
|
67 return CSIPAddress::NewLC(aURI); |
|
68 } |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // SIPCodecUtils::CheckAndCreateTokenL |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 RStringF |
|
75 SIPCodecUtils::CheckAndCreateTokenL(const TDesC8& aToken, TInt aLeaveCode) |
|
76 { |
|
77 HBufC8* tmp = aToken.AllocLC(); |
|
78 tmp->Des().Trim(); |
|
79 if (!SIPSyntaxCheck::Token(*tmp)) |
|
80 { |
|
81 User::Leave(aLeaveCode); |
|
82 } |
|
83 RStringF tmpString = SIPStrings::Pool().OpenFStringL(*tmp); |
|
84 CleanupStack::PopAndDestroy(tmp); |
|
85 return tmpString; |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // SIPCodecUtils::ValueWithoutQuotes |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 TInt SIPCodecUtils::ValueWithoutQuotes( |
|
93 const TDesC8& aValue, |
|
94 TPtrC8& aWithoutQuotes) |
|
95 { |
|
96 if (aValue.Length() > 0) |
|
97 { |
|
98 TLex8 lex(aValue); |
|
99 lex.SkipSpace(); |
|
100 if (lex.Get() == '"') |
|
101 { |
|
102 // Remove first quote |
|
103 TPtrC8 remainder(aValue.Mid(1)); |
|
104 // Ensure that ending quote exists. |
|
105 if(remainder.LocateReverse('"') != (remainder.Length()-1)) |
|
106 { |
|
107 return KErrArgument; |
|
108 } |
|
109 aWithoutQuotes.Set(remainder.Left(remainder.Length()-1)); |
|
110 } |
|
111 else |
|
112 { |
|
113 return KErrArgument; |
|
114 } |
|
115 } |
|
116 return KErrNone; |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // SIPCodecUtils::CheckAndSetValueL |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 void SIPCodecUtils::CheckAndSetValueL(HBufC8*& aBuffer, |
|
124 const TDesC8& aValue, |
|
125 TInt aErr) |
|
126 { |
|
127 HBufC8* tmp = aValue.AllocLC(); |
|
128 tmp->Des().Trim(); |
|
129 if (!SIPSyntaxCheck::Token(*tmp)) |
|
130 { |
|
131 User::Leave(aErr); |
|
132 } |
|
133 CleanupStack::Pop(tmp); |
|
134 delete aBuffer; |
|
135 aBuffer = tmp; |
|
136 } |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // SIPCodecUtils::ReadDescFromStreamL |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 HBufC8* SIPCodecUtils::ReadDescFromStreamL(RReadStream& aReadStream) |
|
143 { |
|
144 TUint32 valueLength = aReadStream.ReadUint32L(); |
|
145 HBufC8* buf = HBufC8::NewLC(valueLength); |
|
146 if(valueLength > 0) |
|
147 { |
|
148 TPtr8 value(buf->Des()); |
|
149 aReadStream.ReadL(value,valueLength); |
|
150 } |
|
151 CleanupStack::Pop(buf); |
|
152 return buf; |
|
153 } |