|
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 : CSIPRegistrar.cpp |
|
15 // Part of : Registration |
|
16 // Version : SIP/4.0 |
|
17 // |
|
18 |
|
19 |
|
20 |
|
21 #include "CSIPRegistrar.h" |
|
22 #include "CSIPRegistrarStore.h" |
|
23 #include "TSIPRegistrationUtility.h" |
|
24 #include "uricontainer.h" |
|
25 #include "siprequest.h" |
|
26 #include "sipcallidheader.h" |
|
27 #include "sipcseqheader.h" |
|
28 #include "sipstrings.h" |
|
29 #include "sipstrconsts.h" |
|
30 |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CSIPRegistrar::NewLC |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CSIPRegistrar* CSIPRegistrar::NewLC(const CURIContainer& aRegistrar, |
|
37 const TDesC8& aCallId, |
|
38 TUint aCSeqNumber, |
|
39 const TRegistrationId aRegistrationId, |
|
40 CSIPRegistrarStore& aRegistrarStore) |
|
41 { |
|
42 CSIPRegistrar* self = |
|
43 new (ELeave) CSIPRegistrar(aCSeqNumber, aRegistrarStore); |
|
44 CleanupStack::PushL(self); |
|
45 self->ConstructL(aRegistrar, aCallId, aRegistrationId); |
|
46 return self; |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CSIPRegistrar::CSIPRegistrar |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 CSIPRegistrar::CSIPRegistrar(TUint aCSeqNumber, |
|
54 CSIPRegistrarStore& aRegistrarStore) |
|
55 : iCSeqNumber (aCSeqNumber), |
|
56 iRegistrarStore (aRegistrarStore) |
|
57 { |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CSIPRegistrar::ConstructL |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 void CSIPRegistrar::ConstructL(const CURIContainer& aRegistrar, |
|
65 const TDesC8& aCallId, |
|
66 const TRegistrationId aRegistrationId) |
|
67 { |
|
68 iRegistrar = CURIContainer::NewL(aRegistrar); |
|
69 iCallId = aCallId.AllocL(); |
|
70 User::LeaveIfError(iRegistrationIds.Append(aRegistrationId)); |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CSIPRegistrar::~CSIPRegistrar |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 CSIPRegistrar::~CSIPRegistrar() |
|
78 { |
|
79 delete iCallId; |
|
80 delete iRegistrar; |
|
81 iRegistrationIds.Reset(); |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CSIPRegistrar::Registrar |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 const CURIContainer& CSIPRegistrar::Registrar() const |
|
89 { |
|
90 return *iRegistrar; |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CSIPRegistrar::IncreaseCSeqNumber |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 void CSIPRegistrar::IncreaseCSeqNumber() |
|
98 { |
|
99 iCSeqNumber++; |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CSIPRegistrar::FillCallIdAndCSeqL |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 void CSIPRegistrar::FillCallIdAndCSeqL(CSIPRequest& aSIPRequest) |
|
107 { |
|
108 CSIPCallIDHeader* callId = CSIPCallIDHeader::DecodeL(*iCallId); |
|
109 CleanupStack::PushL(callId); |
|
110 // fill in callid header, and add it to request |
|
111 CSIPCallIDHeader* oldCallId = aSIPRequest.CallID(); |
|
112 if (oldCallId) |
|
113 { |
|
114 aSIPRequest.ReplaceHeaderL(oldCallId, callId); |
|
115 } |
|
116 else // there are callId header in request |
|
117 { |
|
118 aSIPRequest.AddHeaderL(callId); |
|
119 } |
|
120 CleanupStack::Pop(callId); |
|
121 |
|
122 // increase the CSeqNumber by one |
|
123 IncreaseCSeqNumber(); |
|
124 |
|
125 CSIPCSeqHeader* oldCSeqHeader = aSIPRequest.CSeq(); |
|
126 if (oldCSeqHeader) |
|
127 { |
|
128 oldCSeqHeader->SetSeq(iCSeqNumber); |
|
129 } |
|
130 else |
|
131 { |
|
132 // create a CSIPCSeqHeader header, and add it to request |
|
133 CSIPCSeqHeader* cseqHeader = CSIPCSeqHeader::NewLC( |
|
134 iCSeqNumber, SIPStrings::StringF(SipStrConsts::ERegister)); |
|
135 aSIPRequest.AddHeaderL(cseqHeader); |
|
136 CleanupStack::Pop(cseqHeader); |
|
137 } |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CSIPRegistrar::AddRegistrationIdL |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 void CSIPRegistrar::AddRegistrationIdL(const TRegistrationId aRegistrationId) |
|
145 { |
|
146 User::LeaveIfError(iRegistrationIds.Append(aRegistrationId)); |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CSIPRegistrar::BindingRemoved |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 TBool CSIPRegistrar::BindingRemoved(const TRegistrationId aRegistrationId) |
|
154 { |
|
155 TInt idFound = FindRegistrationId(aRegistrationId); |
|
156 |
|
157 // there is no registration binding relate to this registrar, |
|
158 // remove the registrar |
|
159 if (idFound != KErrNotFound) |
|
160 { |
|
161 if (iRegistrationIds.Count() == 1) |
|
162 { |
|
163 // if registration is added to delete mgr succeed, |
|
164 // remove registration id |
|
165 TInt res = iRegistrarStore.RemoveRegistrar(this); |
|
166 if (res == KErrNone) |
|
167 { |
|
168 iRegistrationIds.Remove(idFound); |
|
169 return ETrue; |
|
170 } |
|
171 else |
|
172 { |
|
173 return EFalse; |
|
174 } |
|
175 } |
|
176 else |
|
177 { |
|
178 iRegistrationIds.Remove(idFound); |
|
179 return ETrue; |
|
180 } |
|
181 } |
|
182 |
|
183 return EFalse; |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // CSIPRegistrar::FindRegistrationId |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 TInt CSIPRegistrar::FindRegistrationId (const TRegistrationId aRegistrationId) |
|
191 { |
|
192 TInt idFound = KErrNotFound; |
|
193 |
|
194 for (TInt i=iRegistrationIds.Count()-1; (i>=0 && idFound==KErrNotFound); i--) |
|
195 { |
|
196 if (iRegistrationIds[i] == aRegistrationId) |
|
197 { |
|
198 return i; |
|
199 } |
|
200 } |
|
201 return idFound; |
|
202 } |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // CSIPRegistrar::CSeqNumber |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 TUint CSIPRegistrar::CSeqNumber() const |
|
209 { |
|
210 return iCSeqNumber; |
|
211 } |
|
212 |
|
213 |