|
1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "cdnsresourcedata.h" |
|
20 #include "crdtypeptr.h" |
|
21 #include "crdtypea.h" |
|
22 #include "crdtypesrv.h" |
|
23 #include "crdtypetxt.h" |
|
24 |
|
25 |
|
26 CDnsResourceData::CDnsResourceData():CDnsSection() |
|
27 { |
|
28 } |
|
29 |
|
30 EXPORT_C CDnsResourceData::~CDnsResourceData() |
|
31 { |
|
32 } |
|
33 |
|
34 |
|
35 EXPORT_C TBool CDnsResourceData::IsFlushBitSet()const |
|
36 { |
|
37 if(iClass & KFlushBit) |
|
38 return ETrue; |
|
39 else |
|
40 return EFalse; |
|
41 } |
|
42 |
|
43 EXPORT_C void CDnsResourceData::SetFlushBit(TBool aFlushBit) |
|
44 { |
|
45 if(aFlushBit) |
|
46 iClass |= KFlushBit; |
|
47 else |
|
48 iClass &= ~KFlushBit; |
|
49 } |
|
50 |
|
51 EXPORT_C TUint16 CDnsResourceData::RdLength()const |
|
52 { |
|
53 return iRdLength; |
|
54 } |
|
55 |
|
56 EXPORT_C void CDnsResourceData::SetRdLength(TUint16 aRdLength) |
|
57 { |
|
58 iRdLength = aRdLength; |
|
59 } |
|
60 |
|
61 EXPORT_C TUint32 CDnsResourceData::Ttl()const |
|
62 { |
|
63 return iTtl; |
|
64 } |
|
65 |
|
66 EXPORT_C void CDnsResourceData::SetTtl(TUint32 aTtl) |
|
67 { |
|
68 iTtl = aTtl; |
|
69 } |
|
70 |
|
71 |
|
72 //Creates a new copy of this object. Leaves if a memory allocation fails |
|
73 EXPORT_C CDnsResourceData* CDnsResourceData::CloneL()const |
|
74 { |
|
75 CDnsResourceData* recordData = NULL; |
|
76 |
|
77 switch(Type()) |
|
78 { |
|
79 case EDnsType_A: // A record |
|
80 { |
|
81 const CRdTypeA* addrRecord = static_cast<const CRdTypeA*>(this); |
|
82 CRdTypeA* rrAddrRecord = CRdTypeA::NewL(); |
|
83 CleanupStack::PushL(rrAddrRecord); |
|
84 |
|
85 rrAddrRecord->SetNameL(addrRecord->Name()); |
|
86 rrAddrRecord->SetType(addrRecord->Type()); |
|
87 rrAddrRecord->SetClass(addrRecord->Class()); |
|
88 rrAddrRecord->SetTtl(addrRecord->Ttl()); |
|
89 rrAddrRecord->SetRdLength(addrRecord->RdLength()); |
|
90 rrAddrRecord->SetAddr(addrRecord->Address()); |
|
91 |
|
92 CleanupStack::Pop(rrAddrRecord); |
|
93 recordData = rrAddrRecord; |
|
94 } |
|
95 break; |
|
96 |
|
97 case EDnsType_PTR: // ptr record |
|
98 { |
|
99 const CRdTypePtr* ptrRecord = static_cast<const CRdTypePtr*>(this); |
|
100 CRdTypePtr* rrPtrRecord = CRdTypePtr::NewL(); |
|
101 CleanupStack::PushL(rrPtrRecord); |
|
102 |
|
103 rrPtrRecord->SetNameL(ptrRecord->Name()); |
|
104 rrPtrRecord->SetType(ptrRecord->Type()); |
|
105 rrPtrRecord->SetClass(ptrRecord->Class()); |
|
106 rrPtrRecord->SetTtl(ptrRecord->Ttl()); |
|
107 rrPtrRecord->SetRdLength(ptrRecord->RdLength()); |
|
108 rrPtrRecord->SetDomainNameL(ptrRecord->DomainName()); |
|
109 |
|
110 CleanupStack::Pop(rrPtrRecord); |
|
111 recordData = rrPtrRecord; |
|
112 } |
|
113 break; |
|
114 |
|
115 case EDnsType_SRV: // srv record |
|
116 { |
|
117 const CRdTypeSrv* srvRecord = static_cast<const CRdTypeSrv*>(this); |
|
118 CRdTypeSrv* rrSrvRecord = CRdTypeSrv::NewL(); |
|
119 CleanupStack::PushL(rrSrvRecord); |
|
120 |
|
121 rrSrvRecord->SetNameL(srvRecord->Name()); |
|
122 rrSrvRecord->SetClass(srvRecord->Class()); |
|
123 rrSrvRecord->SetType(srvRecord->Type()); |
|
124 rrSrvRecord->SetTtl(srvRecord->Ttl()); |
|
125 rrSrvRecord->SetRdLength(srvRecord->RdLength()); |
|
126 rrSrvRecord->SetPriority(srvRecord->Priority()); |
|
127 rrSrvRecord->SetWeight(srvRecord->Weight()); |
|
128 rrSrvRecord->SetPort(srvRecord->Port()); |
|
129 rrSrvRecord->SetTargetL(srvRecord->Target()); |
|
130 |
|
131 CleanupStack::Pop(rrSrvRecord); |
|
132 recordData = rrSrvRecord; |
|
133 } |
|
134 break; |
|
135 |
|
136 case EDnsType_TXT: // Txt record |
|
137 { |
|
138 const CRdTypeTxt* txtRecord = static_cast<const CRdTypeTxt*>(this); |
|
139 CRdTypeTxt* rrTxtRecord = CRdTypeTxt::NewL(); |
|
140 CleanupStack::PushL(rrTxtRecord); |
|
141 |
|
142 rrTxtRecord->SetNameL(txtRecord->Name()); |
|
143 rrTxtRecord->SetType(txtRecord->Type()); |
|
144 rrTxtRecord->SetClass(txtRecord->Class()); |
|
145 rrTxtRecord->SetTtl(txtRecord->Ttl()); |
|
146 rrTxtRecord->SetRdLength(txtRecord->RdLength()); |
|
147 |
|
148 const RArray<RBuf8>& txtList = txtRecord->Text(); |
|
149 TInt count = txtList.Count(); |
|
150 for(TInt j=0; j<count; j++) |
|
151 { |
|
152 RBuf8 txtBuf; |
|
153 txtBuf.CreateL(txtList[j]); |
|
154 rrTxtRecord->AppendTextDataL(txtBuf); |
|
155 } |
|
156 CleanupStack::Pop(rrTxtRecord); |
|
157 recordData = rrTxtRecord; |
|
158 } |
|
159 break; |
|
160 } |
|
161 return recordData; |
|
162 } |
|
163 |
|
164 TUint16 CDnsResourceData::Size()const |
|
165 { |
|
166 return 0; |
|
167 } |
|
168 |
|
169 |