TDE core libraries
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.

ksslx509map.cc 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* This file is part of the KDE project
  2. *
  3. * Copyright (C) 2000 George Staikos <staikos@kde.org>
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Library General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Library General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Library General Public License
  16. * along with this library; see the file COPYING.LIB. If not, write to
  17. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18. * Boston, MA 02110-1301, USA.
  19. */
  20. #include "ksslx509map.h"
  21. #include <tqstringlist.h>
  22. #include <tqregexp.h>
  23. KSSLX509Map::KSSLX509Map(const TQString& name) {
  24. parse(name);
  25. }
  26. KSSLX509Map::~KSSLX509Map() {
  27. }
  28. void KSSLX509Map::setValue(const TQString& key, const TQString& value) {
  29. m_pairs.replace(key, value);
  30. }
  31. TQString KSSLX509Map::getValue(const TQString& key) const {
  32. if (!m_pairs.contains(key)) {
  33. return TQString::null;
  34. }
  35. return m_pairs[key];
  36. }
  37. static TQStringList tokenizeBy(const TQString& str, const TQRegExp& tok, bool keepEmpties = false) {
  38. TQStringList tokens;
  39. unsigned int head, tail;
  40. const char *chstr = str.ascii();
  41. unsigned int length = str.length();
  42. if (length < 1) {
  43. return tokens;
  44. }
  45. if (length == 1) {
  46. tokens.append(str);
  47. return tokens;
  48. }
  49. for(head = 0, tail = 0; tail < length-1; head = tail+1) {
  50. TQString thisline;
  51. tail = str.find(tok, head);
  52. if (tail > length) // last token - none at end
  53. tail = length;
  54. if (tail-head > 0 || keepEmpties) { // it has to be at least 1 long!
  55. thisline = &(chstr[head]);
  56. thisline.truncate(tail-head);
  57. tokens.append(thisline);
  58. }
  59. }
  60. return tokens;
  61. }
  62. void KSSLX509Map::parse(const TQString& name) {
  63. TQStringList vl = tokenizeBy(name, TQRegExp("/[A-Za-z]+="), false);
  64. m_pairs.clear();
  65. for (TQStringList::Iterator j = vl.begin(); j != vl.end(); ++j) {
  66. TQStringList apair = tokenizeBy(*j, TQRegExp("="), false);
  67. if (m_pairs.contains(apair[0])) {
  68. TQString oldValue = m_pairs[apair[0]];
  69. oldValue += "\n";
  70. oldValue += apair[1];
  71. m_pairs.replace(apair[0], oldValue);
  72. } else {
  73. m_pairs.insert(apair[0], apair[1]);
  74. }
  75. }
  76. }
  77. void KSSLX509Map::reset(const TQString& name) {
  78. parse(name);
  79. }