KIO
ksslx509map.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "ksslx509map.h"
00022 #include <QtCore/QStringList>
00023 #include <QtCore/QRegExp>
00024
00025 KSSLX509Map::KSSLX509Map(const QString& name) {
00026 parse(name);
00027 }
00028
00029
00030 KSSLX509Map::~KSSLX509Map() {
00031
00032 }
00033
00034
00035 void KSSLX509Map::setValue(const QString& key, const QString& value) {
00036 m_pairs.insert(key, value);
00037 }
00038
00039
00040 QString KSSLX509Map::getValue(const QString& key) const {
00041 if (!m_pairs.contains(key)) {
00042 return QString();
00043 }
00044
00045 return m_pairs[key];
00046 }
00047
00048 static QStringList tokenizeBy(const QString& str, const QRegExp& tok, bool keepEmpties = false) {
00049 QStringList tokens;
00050 unsigned int head, tail;
00051 QByteArray bastr = str.toAscii();
00052 const char *chstr = bastr.constData();
00053 unsigned int length = str.length();
00054
00055 if (length < 1) {
00056 return tokens;
00057 }
00058
00059 if (length == 1) {
00060 tokens.append(str);
00061 return tokens;
00062 }
00063
00064 for(head = 0, tail = 0; tail < length-1; head = tail+1) {
00065 QString thisline;
00066
00067 tail = str.indexOf(tok, head);
00068
00069 if (tail > length)
00070 tail = length;
00071
00072 if (tail-head > 0 || keepEmpties) {
00073 thisline = &(chstr[head]);
00074 thisline.truncate(tail-head);
00075 tokens.append(thisline);
00076 }
00077 }
00078 return tokens;
00079 }
00080
00081
00082 void KSSLX509Map::parse(const QString& name) {
00083 const QStringList vl = tokenizeBy(name, QRegExp("/[A-Za-z]+="), false);
00084
00085 m_pairs.clear();
00086
00087 for (QStringList::ConstIterator j = vl.begin(); j != vl.end(); ++j) {
00088 const QStringList apair = tokenizeBy(*j, QRegExp("="), false);
00089 if( apair.count() >0 ) {
00090 if (m_pairs.contains(apair[0])) {
00091 QString oldValue = m_pairs[apair[0]];
00092 oldValue += '\n';
00093 oldValue += (apair.count()>1) ? apair[1]:"";
00094 m_pairs.insert(apair[0], oldValue);
00095 } else {
00096 m_pairs.insert(apair[0], (apair.count()>1) ? apair[1]: "" );
00097 }
00098 }
00099 }
00100 }
00101
00102
00103 void KSSLX509Map::reset(const QString& name) {
00104 parse(name);
00105 }
00106