You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.5 KiB
104 lines
2.5 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
*
|
||
|
* Copyright (C) 2000 George Staikos <staikos@kde.org>
|
||
|
*
|
||
|
* This library is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU Library General Public
|
||
|
* License as published by the Free Software Foundation; either
|
||
|
* version 2 of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* This library is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* Library General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Library General Public License
|
||
|
* along with this library; see the file COPYING.LIB. If not, write to
|
||
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include "ksslx509map.h"
|
||
15 years ago
|
#include <tqstringlist.h>
|
||
|
#include <tqregexp.h>
|
||
15 years ago
|
|
||
15 years ago
|
KSSLX509Map::KSSLX509Map(const TQString& name) {
|
||
15 years ago
|
parse(name);
|
||
|
}
|
||
|
|
||
|
|
||
|
KSSLX509Map::~KSSLX509Map() {
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void KSSLX509Map::setValue(const TQString& key, const TQString& value) {
|
||
14 years ago
|
m_pairs.replace(key, value);
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQString KSSLX509Map::getValue(const TQString& key) const {
|
||
14 years ago
|
if (!m_pairs.contains(key)) {
|
||
15 years ago
|
return TQString::null;
|
||
15 years ago
|
}
|
||
|
|
||
|
return m_pairs[key];
|
||
|
}
|
||
|
|
||
15 years ago
|
static TQStringList tokenizeBy(const TQString& str, const TQRegExp& tok, bool keepEmpties = false) {
|
||
|
TQStringList tokens;
|
||
15 years ago
|
unsigned int head, tail;
|
||
|
const char *chstr = str.ascii();
|
||
|
unsigned int length = str.length();
|
||
|
|
||
|
if (length < 1) {
|
||
|
return tokens;
|
||
|
}
|
||
|
|
||
|
if (length == 1) {
|
||
|
tokens.append(str);
|
||
|
return tokens;
|
||
|
}
|
||
|
|
||
|
for(head = 0, tail = 0; tail < length-1; head = tail+1) {
|
||
15 years ago
|
TQString thisline;
|
||
15 years ago
|
|
||
14 years ago
|
tail = str.find(tok, head);
|
||
15 years ago
|
|
||
|
if (tail > length) // last token - none at end
|
||
|
tail = length;
|
||
|
|
||
|
if (tail-head > 0 || keepEmpties) { // it has to be at least 1 long!
|
||
|
thisline = &(chstr[head]);
|
||
|
thisline.truncate(tail-head);
|
||
|
tokens.append(thisline);
|
||
|
}
|
||
|
}
|
||
|
return tokens;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void KSSLX509Map::parse(const TQString& name) {
|
||
|
TQStringList vl = tokenizeBy(name, TQRegExp("/[A-Za-z]+="), false);
|
||
15 years ago
|
|
||
|
m_pairs.clear();
|
||
|
|
||
15 years ago
|
for (TQStringList::Iterator j = vl.begin(); j != vl.end(); ++j) {
|
||
|
TQStringList apair = tokenizeBy(*j, TQRegExp("="), false);
|
||
14 years ago
|
if (m_pairs.contains(apair[0])) {
|
||
15 years ago
|
TQString oldValue = m_pairs[apair[0]];
|
||
15 years ago
|
oldValue += "\n";
|
||
|
oldValue += apair[1];
|
||
14 years ago
|
m_pairs.replace(apair[0], oldValue);
|
||
15 years ago
|
} else {
|
||
|
m_pairs.insert(apair[0], apair[1]);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
void KSSLX509Map::reset(const TQString& name) {
|
||
15 years ago
|
parse(name);
|
||
|
}
|
||
|
|