kio Library API Documentation

ksslx509map.cc

00001 /* This file is part of the KDE project
00002  *
00003  * Copyright (C) 2000 George Staikos <staikos@kde.org>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public License
00016  * along with this library; see the file COPYING.LIB.  If not, write to
00017  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018  * Boston, MA 02111-1307, USA.
00019  */
00020 
00021 #include "ksslx509map.h"
00022 #include <qvaluelist.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)) return QString::null;
00042   return m_pairs[key];
00043 }
00044 
00045 static QValueList<QString> tokenizeBy(const QString& str, const QRegExp& tok, bool keepEmpties = false) {
00046 QValueList<QString> tokens;
00047 unsigned int head, tail;
00048 const char *chstr = str.ascii();
00049 unsigned int length = str.length();
00050  
00051   if (length < 1) return tokens;
00052  
00053   if (length == 1) {
00054     tokens.append(str);
00055     return tokens;
00056   }
00057  
00058   for(head = 0, tail = 0; tail < length-1; head = tail+1) {
00059     QString thisline;
00060  
00061     tail = str.find(tok, head);
00062  
00063     if (tail > length)           // last token - none at end
00064       tail = length;
00065  
00066     if (tail-head > 0 || keepEmpties) {    // it has to be at least 1 long!
00067       thisline = &(chstr[head]);
00068       thisline.truncate(tail-head);
00069       tokens.append(thisline);
00070     }
00071   }
00072 return tokens;
00073 }
00074 
00075 
00076 void KSSLX509Map::parse(const QString& name) {
00077 QValueList<QString> vl = tokenizeBy(name, QRegExp("/[A-Za-z]+="), false);
00078 
00079   m_pairs.clear();
00080 
00081   for (QValueListIterator<QString> j = vl.begin();
00082                                    j != vl.end();
00083                                    ++j) {
00084     QValueList<QString> apair = tokenizeBy(*j, QRegExp("="), false);
00085     if (m_pairs.contains(apair[0])) {
00086       QString oldValue = m_pairs[apair[0]];
00087       oldValue += "\n";
00088       oldValue += apair[1];
00089       m_pairs.replace(apair[0], oldValue);
00090     } else m_pairs.insert(apair[0], apair[1]);
00091   }
00092   
00093 }
00094 
00095 
00096 void KSSLX509Map::reset(const QString& name) {
00097   parse(name);
00098 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:21:32 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001