98 |
98 |
99 QList<KeyData> QCrmlParser::parseRepository() |
99 QList<KeyData> QCrmlParser::parseRepository() |
100 { |
100 { |
101 QList<KeyData> rv; |
101 QList<KeyData> rv; |
102 QStringList mandatoryAttributes; |
102 QStringList mandatoryAttributes; |
103 mandatoryAttributes << "uidValue"; |
103 mandatoryAttributes << QLatin1String("uidValue"); |
104 setError(NoError, ""); |
104 setError(NoError, QString()); |
105 if (!checkMandatoryAttributes(mandatoryAttributes)) |
105 if (!checkMandatoryAttributes(mandatoryAttributes)) |
106 return rv; |
106 return rv; |
107 |
107 |
108 bool ok; |
108 bool ok; |
109 quint32 uidValue = uidStringToUInt32(attributes().value("uidValue").toString(), &ok); |
109 quint32 uidValue = |
|
110 uidStringToUInt32(attributes().value(QLatin1String("uidValue")).toString(), &ok); |
110 if (!ok) { |
111 if (!ok) { |
111 setError(ParseError, QObject::tr("repository element has invalid uidValue on line %1") |
112 setError(ParseError, QObject::tr("repository element has invalid uidValue on line %1") |
112 .arg(QString::number(lineNumber()))); |
113 .arg(QString::number(lineNumber()))); |
113 return rv; |
114 return rv; |
114 } |
115 } |
115 |
116 |
116 QString targetStr = attributes().value("target").toString(); |
117 QString targetStr = attributes().value(QLatin1String("target")).toString(); |
117 if (targetStr.isEmpty() || targetStr == "CRepository") { |
118 if (targetStr.isEmpty() || targetStr == QLatin1String("CRepository")) { |
118 m_target = KeyData::CRepository; |
119 m_target = KeyData::CRepository; |
119 } else if (targetStr == "RProperty") { |
120 } else if (targetStr == QLatin1String("RProperty")) { |
120 m_target = KeyData::RProperty; |
121 m_target = KeyData::RProperty; |
121 } else { |
122 } else { |
122 setError(ParseError, QObject::tr("repository element has unrecognised target attribute " |
123 setError(ParseError, QObject::tr("repository element has unrecognised target attribute " |
123 "on line %1, attribute must be CRepository, RProperty or " |
124 "on line %1, attribute must be CRepository, RProperty or " |
124 "be left undefined").arg(QString::number(lineNumber()))); |
125 "be left undefined").arg(QString::number(lineNumber()))); |
164 |
165 |
165 QList<KeyData> QCrmlParser::parseKey(quint32 repoUid) |
166 QList<KeyData> QCrmlParser::parseKey(quint32 repoUid) |
166 { |
167 { |
167 QList<KeyData> rv; |
168 QList<KeyData> rv; |
168 QStringList mandatoryAttributes; |
169 QStringList mandatoryAttributes; |
169 mandatoryAttributes << "int"; |
170 mandatoryAttributes << QLatin1String("int"); |
170 if (!checkMandatoryAttributes(mandatoryAttributes)) |
171 if (!checkMandatoryAttributes(mandatoryAttributes)) |
171 return rv; |
172 return rv; |
172 |
173 |
173 QXmlStreamAttributes attribs = attributes(); |
174 QXmlStreamAttributes attribs = attributes(); |
174 QString keyIntStr = attribs.value("int").toString(); |
175 QString keyIntStr = attribs.value(QLatin1String("int")).toString(); |
175 bool ok =false; |
176 bool ok =false; |
176 quint32 keyInt = uidStringToUInt32(keyIntStr, &ok); |
177 quint32 keyInt = uidStringToUInt32(keyIntStr, &ok); |
177 if (!ok) { |
178 if (!ok) { |
178 setError(ParseError,QObject::tr("key element has invalid int attribute on line %1"). |
179 setError(ParseError,QObject::tr("key element has invalid int attribute on line %1"). |
179 arg(QString::number(lineNumber()))); |
180 arg(QString::number(lineNumber()))); |
180 return rv; |
181 return rv; |
181 } |
182 } |
182 |
183 |
183 if (attribs.value("ref").isNull()) { |
184 if (attribs.value(QLatin1String("ref")).isNull()) { |
184 //no ref attribute so this must be |
185 //no ref attribute so this must be |
185 //a bitmask key |
186 //a bitmask key |
186 while (!atEnd()) { |
187 while (!atEnd()) { |
187 readNext(); |
188 readNext(); |
188 if (QXmlStreamReader::error() != QXmlStreamReader::NoError) { |
189 if (QXmlStreamReader::error() != QXmlStreamReader::NoError) { |
249 QList<KeyData> rv; |
250 QList<KeyData> rv; |
250 |
251 |
251 //if keyRange has no ref attribute it must |
252 //if keyRange has no ref attribute it must |
252 //only be used for creating access control |
253 //only be used for creating access control |
253 //policies which we do not need to worry about |
254 //policies which we do not need to worry about |
254 if (attributes().value("ref").isNull()) |
255 if (attributes().value(QLatin1String("ref")).isNull()) |
255 return rv; |
256 return rv; |
256 |
257 |
257 QStringList mandatoryAttributes; |
258 QStringList mandatoryAttributes; |
258 mandatoryAttributes << "firstInt" << "lastInt"; |
259 mandatoryAttributes << QLatin1String("firstInt") << QLatin1String("lastInt"); |
259 if (!checkMandatoryAttributes(mandatoryAttributes)) |
260 if (!checkMandatoryAttributes(mandatoryAttributes)) |
260 return rv; |
261 return rv; |
261 |
262 |
262 bool ok = false; |
263 bool ok = false; |
263 QString pathPrefix; |
264 QString pathPrefix; |
264 pathPrefix = attributes().value("ref").toString(); |
265 pathPrefix = attributes().value(QLatin1String("ref")).toString(); |
265 if (!pathPrefix.startsWith("/")) |
266 if (!pathPrefix.startsWith(QLatin1Char('/'))) |
266 pathPrefix.prepend("/"); |
267 pathPrefix.prepend(QLatin1Char('/')); |
267 |
268 |
268 if (!attributes().value("countInt").isNull()) { |
269 if (!attributes().value(QLatin1String("countInt")).isNull()) { |
269 quint32 countInt = uidStringToUInt32(attributes().value("countInt").toString(), &ok); |
270 quint32 countInt = |
|
271 uidStringToUInt32(attributes().value(QLatin1String("countInt")).toString(), &ok); |
270 if (!ok) { |
272 if (!ok) { |
271 setError(ParseError, QObject::tr("keyRange element has invalid countInt attribute on line %1") |
273 setError(ParseError, QObject::tr("keyRange element has invalid countInt attribute on line %1") |
272 .arg(QString::number(lineNumber()))); |
274 .arg(QString::number(lineNumber()))); |
273 rv.clear(); |
275 rv.clear(); |
274 return rv; |
276 return rv; |
275 } |
277 } |
276 |
278 |
277 rv.append(KeyData(pathPrefix,(quint64)countInt + (((quint64)repoUid) << 32), m_target)); |
279 rv.append(KeyData(pathPrefix,(quint64)countInt + (((quint64)repoUid) << 32), m_target)); |
278 } |
280 } |
279 |
281 |
280 if (!pathPrefix.endsWith("/")) |
282 if (!pathPrefix.endsWith(QLatin1Char('/'))) |
281 pathPrefix.append("/"); |
283 pathPrefix.append(QLatin1Char('/')); |
282 |
284 |
283 quint32 firstInt = uidStringToUInt32(attributes().value("firstInt").toString(), &ok); |
285 quint32 firstInt = |
|
286 uidStringToUInt32(attributes().value(QLatin1String("firstInt")).toString(), &ok); |
284 if (!ok) { |
287 if (!ok) { |
285 setError(ParseError, QObject::tr("keyRange element has invalid firstInt attribute on line %1") |
288 setError(ParseError, QObject::tr("keyRange element has invalid firstInt attribute on line %1") |
286 .arg(QString::number(lineNumber()))); |
289 .arg(QString::number(lineNumber()))); |
287 rv.clear(); |
290 rv.clear(); |
288 return rv; |
291 return rv; |
289 } |
292 } |
290 |
293 |
291 quint32 lastInt = uidStringToUInt32(attributes().value("lastInt").toString(),&ok); |
294 quint32 lastInt = |
|
295 uidStringToUInt32(attributes().value(QLatin1String("lastInt")).toString(),&ok); |
292 if (!ok) { |
296 if (!ok) { |
293 setError(ParseError, QObject::tr("keyRange element has invalid lastInt attribute on line %1") |
297 setError(ParseError, QObject::tr("keyRange element has invalid lastInt attribute on line %1") |
294 .arg(QString::number(lineNumber()))); |
298 .arg(QString::number(lineNumber()))); |
295 rv.clear(); |
299 rv.clear(); |
296 return rv; |
300 return rv; |
297 } |
301 } |
298 |
302 |
299 quint32 maxNum =0; |
303 quint32 maxNum =0; |
300 quint32 indexBits = 0; |
304 quint32 indexBits = 0; |
301 quint32 firstIndex = 0; |
305 quint32 firstIndex = 0; |
302 if (attributes().value("indexBits").isNull()) { |
306 if (attributes().value(QLatin1String("indexBits")).isNull()) { |
303 //keyRange doesn't map to sequence setting |
307 //keyRange doesn't map to sequence setting |
304 |
308 |
305 maxNum = lastInt - firstInt + 1; |
309 maxNum = lastInt - firstInt + 1; |
306 for (quint32 i=0; i < maxNum; i++) { |
310 for (quint32 i=0; i < maxNum; i++) { |
307 rv.append(KeyData(pathPrefix + QString::number(i), |
311 rv.append(KeyData(pathPrefix + QString::number(i), |
323 if (isStartElement()) |
327 if (isStartElement()) |
324 parseUnknownElement(); |
328 parseUnknownElement(); |
325 } |
329 } |
326 } else { |
330 } else { |
327 //keyRanges does map to sequence setting |
331 //keyRanges does map to sequence setting |
328 indexBits = uidStringToUInt32(attributes().value("indexBits").toString(), &ok); |
332 indexBits = |
|
333 uidStringToUInt32(attributes().value(QLatin1String("indexBits")).toString(), &ok); |
329 if (!ok) { |
334 if (!ok) { |
330 setError(ParseError, QObject::tr("keyRange elment has invalid indexBits attribute on line %1") |
335 setError(ParseError, QObject::tr("keyRange elment has invalid indexBits attribute on line %1") |
331 .arg(QString::number(lineNumber()))); |
336 .arg(QString::number(lineNumber()))); |
332 rv.clear(); |
337 rv.clear(); |
333 return rv; |
338 return rv; |
334 } |
339 } |
335 |
340 |
336 if (!attributes().value("firstIndex").isNull()) { |
341 if (!attributes().value(QLatin1String("firstIndex")).isNull()) { |
337 QString firstIndexStr = attributes().value("firstIndex").toString(); |
342 QString firstIndexStr = attributes().value(QLatin1String("firstIndex")).toString(); |
338 firstIndex = firstIndexStr.toUInt(&ok, 10); |
343 firstIndex = firstIndexStr.toUInt(&ok, 10); |
339 if (!ok) { |
344 if (!ok) { |
340 setError(ParseError, QObject::tr("keyRange element has invalid firstIndex attribute on line %1") |
345 setError(ParseError, QObject::tr("keyRange element has invalid firstIndex attribute on line %1") |
341 .arg(QString::number(lineNumber()))); |
346 .arg(QString::number(lineNumber()))); |
342 rv.clear(); |
347 rv.clear(); |
406 |
411 |
407 QList<KeyData> QCrmlParser::parseBit(quint32 repoUid, quint32 keyInt) |
412 QList<KeyData> QCrmlParser::parseBit(quint32 repoUid, quint32 keyInt) |
408 { |
413 { |
409 QList <KeyData> rv; |
414 QList <KeyData> rv; |
410 QStringList mandatoryAttributes; |
415 QStringList mandatoryAttributes; |
411 mandatoryAttributes << "ref"; |
416 mandatoryAttributes << QLatin1String("ref"); |
412 if (!checkMandatoryAttributes(mandatoryAttributes)) { |
417 if (!checkMandatoryAttributes(mandatoryAttributes)) { |
413 rv.clear(); |
418 rv.clear(); |
414 return rv; |
419 return rv; |
415 } |
420 } |
416 |
421 |
417 QString keyPath = attributes().value("ref").toString(); |
422 QString keyPath = attributes().value(QLatin1String("ref")).toString(); |
418 if (!keyPath.startsWith("/")) |
423 if (!keyPath.startsWith(QLatin1Char('/'))) |
419 keyPath.prepend("/"); |
424 keyPath.prepend(QLatin1Char('/')); |
420 |
425 |
421 int bitIndex = 0; |
426 int bitIndex = 0; |
422 while(!atEnd()) { |
427 while(!atEnd()) { |
423 readNext(); |
428 readNext(); |
424 if (QXmlStreamReader::error() != QXmlStreamReader::NoError) { |
429 if (QXmlStreamReader::error() != QXmlStreamReader::NoError) { |