|
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 // llmnrconf.cpp - LLMNR (linklocal multicast name resolver) configuration |
|
15 // file parser module |
|
16 // |
|
17 |
|
18 #ifdef LLMNR_ENABLED |
|
19 #include <f32file.h> // RFs |
|
20 #include <in_sock.h> // TInetAddr |
|
21 #include <es_ini.h> |
|
22 #include "dnd_ini.h" |
|
23 #include "engine.h" |
|
24 #include "llmnrresponder.h" // this |
|
25 #include "inet6log.h" |
|
26 |
|
27 CLlmnrConf::CLlmnrConf(CDndEngine &aControl) |
|
28 : iControl(aControl) |
|
29 { |
|
30 } |
|
31 |
|
32 CLlmnrConf::~CLlmnrConf() |
|
33 { |
|
34 delete iHostList; |
|
35 } |
|
36 |
|
37 void CLlmnrConf::ConstructL() |
|
38 { |
|
39 iLlmnrEntries = iControl.GetIniValue(DND_INI_LLMNR, LLMNR_INI_ENTRIES, 0, 0, KLlmnrMaxEnabled); |
|
40 iNotifyTime = iControl.GetIniValue(DND_INI_LLMNR, LLMNR_INI_NOTIFYTIME, KLlmnrIni_NotifyTime, 1, KMaxTInt); |
|
41 iRescans = iControl.GetIniValue(DND_INI_LLMNR, LLMNR_INI_RESCANS, KLlmnrIni_Rescans, 1, 255); |
|
42 iTTL = iControl.GetIniValue(DND_INI_LLMNR, LLMNR_INI_TTL, KLlmnrIni_Ttl, 1, KMaxTInt); |
|
43 } |
|
44 |
|
45 void CLlmnrConf::GetHostNamesL() |
|
46 { |
|
47 delete iHostList; |
|
48 iHostList = NULL; |
|
49 // Aways allocate the array "skeleton" to keep things simple. |
|
50 iHostList = new (ELeave) CArrayFixFlat<THostNameEntry>(iLlmnrEntries < 1 ? 1 : iLlmnrEntries); |
|
51 |
|
52 for (TUint i = 1; i <= iLlmnrEntries; ++i) |
|
53 { |
|
54 THostNameEntry entry; |
|
55 |
|
56 // Borrow he iName field of the entry |
|
57 entry.iName = LLMNR_INI_ENTRY; |
|
58 entry.iName.AppendNum(i); |
|
59 TPtrC entrystr; |
|
60 if(!iControl.FindVar(DND_INI_LLMNR, entry.iName, entrystr)) |
|
61 { |
|
62 // This log message should probably be logged in release also |
|
63 LOG(Log::Printf(_L("DND LMNR: %S is missing [%S] %S%d\r\n"), &DND_INI_DATA, &DND_INI_LLMNR, &LLMNR_INI_ENTRY, (TInt)i)); |
|
64 continue; |
|
65 } |
|
66 |
|
67 TLex wordLex(entrystr); |
|
68 |
|
69 // Get hostname |
|
70 wordLex.Mark(); |
|
71 while (!wordLex.Eos() && wordLex.Peek() != ',') |
|
72 wordLex.Inc(); |
|
73 |
|
74 TInt err = 0; |
|
75 for (;;) |
|
76 { |
|
77 const TInt N = wordLex.MarkedToken().Length(); |
|
78 if (N <= 0 || N > entry.iName.MaxLength()) |
|
79 { |
|
80 err = 1; |
|
81 break; // invalid hostname (either not given or too long) |
|
82 } |
|
83 entry.iName = wordLex.MarkedToken(); |
|
84 |
|
85 // By default, entry is valid for ... |
|
86 entry.iVersion = EIPany; // ...both IPv4 and IPv6 |
|
87 entry.iIfName.SetLength(0); // ...any interface |
|
88 if(wordLex.Eos()) |
|
89 break; |
|
90 |
|
91 // Get interface name |
|
92 wordLex.Inc(); |
|
93 if(wordLex.Peek() != ',') // not ",," after hostname |
|
94 { |
|
95 wordLex.Mark(); |
|
96 while (!wordLex.Eos() && wordLex.Peek() != ',') |
|
97 wordLex.Inc(); |
|
98 if (wordLex.MarkedToken().Length() > entry.iIfName.MaxLength()) |
|
99 { |
|
100 err = 2; |
|
101 break; |
|
102 } |
|
103 entry.iIfName = wordLex.MarkedToken(); |
|
104 } |
|
105 |
|
106 if(wordLex.Eos()) |
|
107 break; |
|
108 |
|
109 // Get ip-version |
|
110 wordLex.Inc(); |
|
111 if(wordLex.Eos()) // Eos after ',' |
|
112 break; |
|
113 |
|
114 TInt n; |
|
115 if((wordLex.Val(n) != KErrNone) || (n != 0 && n != 4 && n != 6)) |
|
116 err = 1; |
|
117 else |
|
118 entry.iVersion = (TIpVer)n; |
|
119 break; |
|
120 } |
|
121 if (err) |
|
122 { |
|
123 LOG(Log::Printf(_L("DND LMNR: %S has invalid [%S] %S%d= %S [ignored]\r\n"), &DND_INI_DATA, &DND_INI_LLMNR, &LLMNR_INI_ENTRY, (TInt)i, &entrystr)); |
|
124 } |
|
125 else |
|
126 iHostList->AppendL(entry); |
|
127 } |
|
128 } |
|
129 |
|
130 #endif |