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 <qstringlist.h>
00023
#include <qregexp.h>
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.
replace(key, value);
00037 }
00038
00039
00040 QString KSSLX509Map::getValue(
const QString& key)
const {
00041
if (!m_pairs.
contains(key)) {
00042
return QString::null;
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
const char *chstr = str.
ascii();
00052
unsigned int length = str.
length();
00053
00054
if (length < 1) {
00055
return tokens;
00056 }
00057
00058
if (length == 1) {
00059 tokens.append(str);
00060
return tokens;
00061 }
00062
00063
for(head = 0, tail = 0; tail < length-1; head = tail+1) {
00064
QString thisline;
00065
00066 tail = str.
find(tok, head);
00067
00068
if (tail > length)
00069 tail = length;
00070
00071
if (tail-head > 0 || keepEmpties) {
00072 thisline = &(chstr[head]);
00073 thisline.
truncate(tail-head);
00074 tokens.append(thisline);
00075 }
00076 }
00077
return tokens;
00078 }
00079
00080
00081
void KSSLX509Map::parse(
const QString& name) {
00082
QStringList vl = tokenizeBy(name,
QRegExp(
"/[A-Za-z]+="),
false);
00083
00084 m_pairs.
clear();
00085
00086
for (QStringList::Iterator j = vl.begin(); j != vl.end(); ++j) {
00087
QStringList apair = tokenizeBy(*j,
QRegExp(
"="),
false);
00088
if (m_pairs.
contains(apair[0])) {
00089
QString oldValue = m_pairs[apair[0]];
00090 oldValue +=
"\n";
00091 oldValue += apair[1];
00092 m_pairs.
replace(apair[0], oldValue);
00093 }
else {
00094 m_pairs.
insert(apair[0], apair[1]);
00095 }
00096 }
00097 }
00098
00099
00100 void KSSLX509Map::reset(
const QString& name) {
00101 parse(name);
00102 }
00103