1 /* |
1 /* |
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of the License "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
8 * |
8 * |
9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: |
14 * Description: |
15 * EAP method validator: username |
15 * EAP method username format validator |
16 * |
16 * |
17 */ |
17 */ |
18 |
18 |
19 /* |
19 /* |
20 * %version: 7 % |
20 * %version: 11 % |
21 */ |
21 */ |
22 |
22 |
|
23 // System includes |
23 #include <HbEditorInterface> |
24 #include <HbEditorInterface> |
24 #include <HbLineEdit> |
25 #include <HbLineEdit> |
25 |
26 |
|
27 // User includes |
26 #include "eapqtvalidatorusername.h" |
28 #include "eapqtvalidatorusername.h" |
27 #include "eapqtconfiginterface_p.h" |
29 #include "eapqtconfiginterface_p.h" |
28 |
30 |
29 EapQtValidatorUsername::EapQtValidatorUsername(EapQtExpandedEapType type) : |
31 /*! |
|
32 * \class EapQtValidatorUsername |
|
33 * \brief EAP method username format validator |
|
34 */ |
|
35 |
|
36 // External function prototypes |
|
37 |
|
38 // Local constants |
|
39 |
|
40 // ======== LOCAL FUNCTIONS ======== |
|
41 |
|
42 // ======== MEMBER FUNCTIONS ======== |
|
43 |
|
44 EapQtValidatorUsername::EapQtValidatorUsername(const EapQtExpandedEapType& type) : |
30 mEapType(type) |
45 mEapType(type) |
31 { |
46 { |
32 } |
47 } |
33 |
48 |
34 EapQtValidatorUsername::~EapQtValidatorUsername() |
49 EapQtValidatorUsername::~EapQtValidatorUsername() |
35 { |
50 { |
36 } |
51 } |
37 |
52 |
38 EapQtValidator::Status EapQtValidatorUsername::validate(QVariant value) |
53 EapQtValidator::Status EapQtValidatorUsername::validate(const QVariant& value) |
39 { |
54 { |
|
55 qDebug("EapQtValidatorUsername::validate()"); |
|
56 |
40 Status status(StatusOk); |
57 Status status(StatusOk); |
41 |
58 |
42 switch (mEapType.type()) { |
59 switch (mEapType.type()) { |
43 case EapQtExpandedEapType::TypeEapAka: |
60 case EapQtExpandedEapType::TypeEapAka: |
44 case EapQtExpandedEapType::TypeEapFast: |
61 case EapQtExpandedEapType::TypeEapFast: |
47 case EapQtExpandedEapType::TypeEapSim: |
64 case EapQtExpandedEapType::TypeEapSim: |
48 case EapQtExpandedEapType::TypeEapTls: |
65 case EapQtExpandedEapType::TypeEapTls: |
49 case EapQtExpandedEapType::TypeEapTtls: |
66 case EapQtExpandedEapType::TypeEapTtls: |
50 case EapQtExpandedEapType::TypeLeap: |
67 case EapQtExpandedEapType::TypeLeap: |
51 case EapQtExpandedEapType::TypePeap: |
68 case EapQtExpandedEapType::TypePeap: |
|
69 case EapQtExpandedEapType::TypePap: |
|
70 case EapQtExpandedEapType::TypePlainMschapv2: |
52 status = validateGeneral(value); |
71 status = validateGeneral(value); |
53 break; |
72 break; |
54 default: |
73 default: |
55 // for methods that do not have a realm |
74 // for methods that do not have a realm |
56 status = StatusInvalid; |
75 status = StatusInvalid; |
|
76 break; |
57 } |
77 } |
58 |
78 |
59 return status; |
79 return status; |
60 } |
80 } |
61 |
81 |
62 EapQtValidator::Status EapQtValidatorUsername::validateGeneral(QVariant value) |
82 EapQtValidator::Status EapQtValidatorUsername::validateGeneral(const QVariant& value) |
63 { |
83 { |
64 Status status(StatusOk); |
84 Status status(StatusOk); |
65 QString str = value.toString(); |
85 QString str = value.toString(); |
66 |
86 |
67 // input must be of correct type |
87 // input must be of correct type |
68 if (value.type() != QVariant::String) { |
88 if (value.type() != QVariant::String) { |
69 status = StatusInvalid; |
89 status = StatusInvalid; |
70 } |
90 } |
|
91 else if (str.length() <= 0 && !isEmptyAllowed()) { |
|
92 status = StatusTooShort; |
|
93 } |
71 // zero length username is ok |
94 // zero length username is ok |
72 else if (str.length() > EapQtConfigInterfacePrivate::StringMaxLength) { |
95 else if (str.length() > EapQtConfigInterfacePrivate::StringMaxLength) { |
73 status = StatusTooLong; |
96 status = StatusTooLong; |
74 } |
97 } |
75 else if (!validateCharacters(str)) { |
98 else if (!validateCharacters(str)) { |
79 qDebug("EapQtValidatorUsername::validateGeneral - return status: %d", status); |
102 qDebug("EapQtValidatorUsername::validateGeneral - return status: %d", status); |
80 |
103 |
81 return status; |
104 return status; |
82 } |
105 } |
83 |
106 |
84 bool EapQtValidatorUsername::validateCharacters(QString& str) |
107 bool EapQtValidatorUsername::isEmptyAllowed() |
85 { |
108 { |
|
109 qDebug("EapQtValidatorUsername::isEmptyAllowed()"); |
|
110 |
|
111 bool ret(true); |
|
112 |
|
113 switch (mEapType.type()) { |
|
114 case EapQtExpandedEapType::TypeEapGtc: |
|
115 case EapQtExpandedEapType::TypeEapMschapv2: |
|
116 case EapQtExpandedEapType::TypeLeap: |
|
117 case EapQtExpandedEapType::TypePap: |
|
118 case EapQtExpandedEapType::TypePlainMschapv2: |
|
119 ret = false; |
|
120 break; |
|
121 default: |
|
122 // other methods can have empty username |
|
123 break; |
|
124 } |
|
125 |
|
126 return ret; |
|
127 } |
|
128 |
|
129 bool EapQtValidatorUsername::validateCharacters(const QString& str) |
|
130 { |
|
131 qDebug("EapQtValidatorUsername::validateCharacters()"); |
|
132 |
86 bool ret(true); |
133 bool ret(true); |
87 |
134 |
88 switch (mEapType.type()) { |
135 switch (mEapType.type()) { |
89 case EapQtExpandedEapType::TypeEapAka: |
136 case EapQtExpandedEapType::TypeEapAka: |
90 case EapQtExpandedEapType::TypeEapFast: |
137 case EapQtExpandedEapType::TypeEapFast: |
119 case EapQtExpandedEapType::TypeEapSim: |
168 case EapQtExpandedEapType::TypeEapSim: |
120 case EapQtExpandedEapType::TypeEapTls: |
169 case EapQtExpandedEapType::TypeEapTls: |
121 case EapQtExpandedEapType::TypeEapTtls: |
170 case EapQtExpandedEapType::TypeEapTtls: |
122 case EapQtExpandedEapType::TypeLeap: |
171 case EapQtExpandedEapType::TypeLeap: |
123 case EapQtExpandedEapType::TypePeap: |
172 case EapQtExpandedEapType::TypePeap: |
|
173 case EapQtExpandedEapType::TypePap: |
|
174 case EapQtExpandedEapType::TypePlainMschapv2: |
124 updateEditorGeneral(edit); |
175 updateEditorGeneral(edit); |
125 // falls through on purpose |
176 // falls through on purpose |
126 default: |
177 default: |
127 // no realm for other types |
178 // no editor preferences for other types |
128 break; |
179 break; |
129 } |
180 } |
130 } |
181 } |
131 |
182 |
132 void EapQtValidatorUsername::updateEditorGeneral(HbLineEdit *edit) |
183 void EapQtValidatorUsername::updateEditorGeneral(HbLineEdit* const edit) |
133 { |
184 { |
134 qDebug("EapQtValidatorUsername::updateEditorGeneral()"); |
185 qDebug("EapQtValidatorUsername::updateEditorGeneral()"); |
135 |
186 |
136 Q_ASSERT(edit); |
187 Q_ASSERT(edit); |
137 |
188 |