|
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 : CSIPCallIDHeader.cpp |
|
15 // Part of : SIP Codec |
|
16 // Version : SIP/4.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "sipcallidheader.h" |
|
22 #include "sipcodecerr.h" |
|
23 #include "SIPSyntaxCheck.h" |
|
24 #include "sipcodecutils.h" |
|
25 #include "sipstrings.h" |
|
26 #include "sipstrconsts.h" |
|
27 #include "_sipcodecdefs.h" |
|
28 |
|
29 |
|
30 // ---------------------------------------------------------------------------- |
|
31 // CSIPCallIDHeader::DecodeL |
|
32 // ---------------------------------------------------------------------------- |
|
33 // |
|
34 EXPORT_C CSIPCallIDHeader* CSIPCallIDHeader::DecodeL (const TDesC8& aValue) |
|
35 { |
|
36 TLex8 lex(aValue); |
|
37 lex.SkipSpace(); |
|
38 TPtrC8 value(lex.Remainder()); |
|
39 __ASSERT_ALWAYS(value.Length() > 0, User::Leave(KErrSipCodecCallIdHeader)); |
|
40 |
|
41 CSIPCallIDHeader* self = new(ELeave)CSIPCallIDHeader; |
|
42 CleanupStack::PushL(self); |
|
43 self->ParseL (value); |
|
44 self->iCallID = value.AllocL(); |
|
45 CleanupStack::Pop(self); |
|
46 return self; |
|
47 } |
|
48 |
|
49 // ---------------------------------------------------------------------------- |
|
50 // CSIPCallIDHeader::CSIPCallIDHeader |
|
51 // ---------------------------------------------------------------------------- |
|
52 // |
|
53 CSIPCallIDHeader::CSIPCallIDHeader() |
|
54 { |
|
55 } |
|
56 |
|
57 // ---------------------------------------------------------------------------- |
|
58 // CSIPCallIDHeader::~CSIPCallIDHeader |
|
59 // ---------------------------------------------------------------------------- |
|
60 // |
|
61 EXPORT_C CSIPCallIDHeader::~CSIPCallIDHeader() |
|
62 { |
|
63 delete iCallID; |
|
64 } |
|
65 |
|
66 // ---------------------------------------------------------------------------- |
|
67 // CSIPCallIDHeader::CloneL |
|
68 // From CSIPHeaderBase: |
|
69 // ---------------------------------------------------------------------------- |
|
70 // |
|
71 EXPORT_C CSIPHeaderBase* CSIPCallIDHeader::CloneL () const |
|
72 { |
|
73 CSIPCallIDHeader* clone = new(ELeave)CSIPCallIDHeader; |
|
74 CleanupStack::PushL(clone); |
|
75 clone->iCallID = iCallID->AllocL(); |
|
76 CleanupStack::Pop(clone); |
|
77 return clone; |
|
78 } |
|
79 |
|
80 // ---------------------------------------------------------------------------- |
|
81 // CSIPCallIDHeader::operator== |
|
82 // ---------------------------------------------------------------------------- |
|
83 // |
|
84 EXPORT_C TBool |
|
85 CSIPCallIDHeader::operator==(const CSIPCallIDHeader& aCallIDHeader) |
|
86 { |
|
87 return (iCallID->Compare(*(aCallIDHeader.iCallID)) == 0); |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CSIPCSeqHeader::InternalizeValueL |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 EXPORT_C CSIPHeaderBase* |
|
95 CSIPCallIDHeader::InternalizeValueL (RReadStream& aReadStream) |
|
96 { |
|
97 CSIPCallIDHeader* self = new(ELeave)CSIPCallIDHeader; |
|
98 CleanupStack::PushL(self); |
|
99 self->iCallID = SIPCodecUtils::ReadDescFromStreamL(aReadStream); |
|
100 CleanupStack::Pop(self); |
|
101 return self; |
|
102 } |
|
103 |
|
104 // ---------------------------------------------------------------------------- |
|
105 // CSIPCallIDHeader::Name |
|
106 // From CSIPHeaderBase: |
|
107 // ---------------------------------------------------------------------------- |
|
108 // |
|
109 EXPORT_C RStringF CSIPCallIDHeader::Name() const |
|
110 { |
|
111 return SIPStrings::StringF(SipStrConsts::ECallIDHeader); |
|
112 } |
|
113 |
|
114 // ---------------------------------------------------------------------------- |
|
115 // CSIPCallIDHeader::HasCompactName |
|
116 // From CSIPHeaderBase: |
|
117 // ---------------------------------------------------------------------------- |
|
118 // |
|
119 TBool CSIPCallIDHeader::HasCompactName () const |
|
120 { |
|
121 return ETrue; |
|
122 } |
|
123 |
|
124 // ---------------------------------------------------------------------------- |
|
125 // CSIPCallIDHeader::CompactName |
|
126 // From CSIPHeaderBase: |
|
127 // ---------------------------------------------------------------------------- |
|
128 // |
|
129 RStringF CSIPCallIDHeader::CompactName () const |
|
130 { |
|
131 return SIPStrings::StringF(SipStrConsts::ECallIDHeaderCompact); |
|
132 } |
|
133 |
|
134 // ---------------------------------------------------------------------------- |
|
135 // CSIPCallIDHeader::ToTextValueL |
|
136 // From CSIPHeaderBase: |
|
137 // ---------------------------------------------------------------------------- |
|
138 // |
|
139 EXPORT_C HBufC8* CSIPCallIDHeader::ToTextValueL () const |
|
140 { |
|
141 return iCallID->AllocL(); |
|
142 } |
|
143 |
|
144 // ---------------------------------------------------------------------------- |
|
145 // CSIPCallIDHeader::PreferredPlaceInMessage |
|
146 // From CSIPHeaderBase: |
|
147 // ---------------------------------------------------------------------------- |
|
148 // |
|
149 CSIPHeaderBase::TPreferredPlace |
|
150 CSIPCallIDHeader::PreferredPlaceInMessage () const |
|
151 { |
|
152 return CSIPHeaderBase::EMiddle; |
|
153 } |
|
154 |
|
155 // ---------------------------------------------------------------------------- |
|
156 // CSIPCallIDHeader::BaseDecodeL |
|
157 // ---------------------------------------------------------------------------- |
|
158 // |
|
159 RPointerArray<CSIPHeaderBase> |
|
160 CSIPCallIDHeader::BaseDecodeL (const TDesC8& aValue) |
|
161 { |
|
162 CSIPCallIDHeader* header = DecodeL(aValue); |
|
163 CleanupStack::PushL(header); |
|
164 RPointerArray<CSIPHeaderBase> headers; |
|
165 User::LeaveIfError (headers.Append(header)); |
|
166 CleanupStack::Pop(header); |
|
167 return headers; |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CSIPCSeqHeader::ExternalizeValueL |
|
172 // From CSIPHeaderBase: |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 void CSIPCallIDHeader::ExternalizeValueL (RWriteStream& aWriteStream) const |
|
176 { |
|
177 aWriteStream.WriteUint32L(iCallID->Length()); |
|
178 aWriteStream.WriteL(*iCallID); |
|
179 } |
|
180 |
|
181 // ---------------------------------------------------------------------------- |
|
182 // CSIPCallIDHeader::ParseL |
|
183 // ---------------------------------------------------------------------------- |
|
184 // |
|
185 void CSIPCallIDHeader::ParseL (const TDesC8& aValue) |
|
186 { |
|
187 __ASSERT_ALWAYS (aValue.Length() > 0, |
|
188 User::Leave(KErrSipCodecCallIdHeader)); |
|
189 |
|
190 TLex8 lex(aValue); |
|
191 TPtrC8 value(lex.NextToken()); |
|
192 lex.SkipSpace(); |
|
193 if (lex.Remainder().Length() > 0) |
|
194 { |
|
195 User::Leave(KErrSipCodecCallIdHeader); |
|
196 } |
|
197 |
|
198 TInt atPos = value.Locate('@'); |
|
199 if (atPos == 0 || atPos == value.Length()-1) |
|
200 { |
|
201 User::Leave(KErrSipCodecCallIdHeader); |
|
202 } |
|
203 |
|
204 if (atPos < 0) // word |
|
205 { |
|
206 if (!SIPSyntaxCheck::Word(value)) |
|
207 { |
|
208 User::Leave(KErrSipCodecCallIdHeader); |
|
209 } |
|
210 } |
|
211 else // word@word |
|
212 { |
|
213 if (!SIPSyntaxCheck::Word(value.Left(atPos))) |
|
214 { |
|
215 User::Leave(KErrSipCodecCallIdHeader); |
|
216 } |
|
217 if (!SIPSyntaxCheck::Word(value.Mid(atPos+1))) |
|
218 { |
|
219 User::Leave(KErrSipCodecCallIdHeader); |
|
220 } |
|
221 } |
|
222 } |