• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kio

ksslx509map.cc

Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
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)           // last token - none at end
00069             tail = length;
00070 
00071         if (tail-head > 0 || keepEmpties) {    // it has to be at least 1 long!
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 

kio

Skip menu "kio"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal