|
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 |
|
19 #include <centralrepository.h> |
|
20 #include <unsafprotocolscrkeys.h> |
|
21 #include "CTcSIPContext.h" |
|
22 #include "TCmdSetSTUNServer.h" |
|
23 #include "SIPConstants.h" |
|
24 |
|
25 |
|
26 /** |
|
27 * INPUT: |
|
28 * Headers: - |
|
29 * Parameters: KParamDomainName, KParamSTUNServerDomain, |
|
30 * KParamSTUNServerPort |
|
31 * IDs: - |
|
32 * |
|
33 * OUTPUT: |
|
34 * Parameters: - |
|
35 * IDs: - |
|
36 * |
|
37 * If at least one of the parameters KParamSTUNServerDomain and |
|
38 * KParamSTUNServerPort is specified, they are written to repository. |
|
39 * If neither is specified, the configured values are removed from the |
|
40 * repository. |
|
41 */ |
|
42 void TCmdSetSTUNServer::ExecuteL() |
|
43 { |
|
44 TPtrC8 sipAOR = ExtractTextL( KParamDomainName, ETrue ); |
|
45 TPtrC8 server = ExtractTextL( KParamSTUNServerDomain, EFalse ); |
|
46 //UDP and TLS both use the same port |
|
47 TInt port = ExtractIntegerL( KParamSTUNServerPort, KErrNotFound, EFalse ); |
|
48 TBool writeToRepository = ( server != KNullDesC8 || port > 0 ); |
|
49 |
|
50 CRepository* repository = CRepository::NewLC( KCRUidUNSAFProtocols ); |
|
51 TUint32 key( 0 ); |
|
52 TInt status = FindDomainKeyL( *repository, sipAOR, key ); |
|
53 __ASSERT_ALWAYS( status == KErrNone || status == KErrNotFound, |
|
54 User::Leave( status ) ); |
|
55 |
|
56 User::LeaveIfError( |
|
57 repository->StartTransaction( |
|
58 CRepository::EConcurrentReadWriteTransaction ) ); |
|
59 repository->CleanupCancelTransactionPushL(); |
|
60 |
|
61 if ( writeToRepository ) |
|
62 { |
|
63 if ( status == KErrNotFound ) |
|
64 { |
|
65 key = CreateNewKeyL( *repository, |
|
66 KUNSAFProtocolsDomainMask, |
|
67 KUNSAFProtocolsDomainTableMask ); |
|
68 WriteL( *repository, KUNSAFProtocolsDomainMask | key, sipAOR ); |
|
69 } |
|
70 WriteL( *repository, KUNSAFProtocolsSTUNServerMask | key, server ); |
|
71 WriteL( *repository, KUNSAFProtocolsSTUNServerPortMask | key, port ); |
|
72 } |
|
73 else |
|
74 { |
|
75 if ( status == KErrNone ) |
|
76 { |
|
77 RemoveParameterL( *repository, |
|
78 KUNSAFProtocolsSTUNServerMask | key ); |
|
79 RemoveParameterL( *repository, |
|
80 KUNSAFProtocolsSTUNServerPortMask | key ); |
|
81 } |
|
82 } |
|
83 |
|
84 TUint32 dummy( 0 ); |
|
85 User::LeaveIfError( repository->CommitTransaction( dummy ) ); |
|
86 CleanupStack::Pop( 1 ); // transaction |
|
87 |
|
88 CleanupStack::PopAndDestroy( repository ); |
|
89 } |
|
90 |
|
91 TBool TCmdSetSTUNServer::Match( const TTcIdentifier& aId ) |
|
92 { |
|
93 return TTcSIPCommandBase::Match( aId, _L8("SetSTUNServer") ); |
|
94 } |
|
95 |
|
96 TTcCommandBase* TCmdSetSTUNServer::CreateL( MTcTestContext& aContext ) |
|
97 { |
|
98 return new( ELeave ) TCmdSetSTUNServer( aContext ); |
|
99 } |