16#include <config-libkleo.h> 
   19#include "libkleo_debug.h" 
   27#define strcasecmp _stricmp 
   30class Kleo::DN::Private
 
   37    Private(
const Private &other)
 
   38        : attributes(other.attributes)
 
   39        , reorderedAttributes(other.reorderedAttributes)
 
   51        if (--mRefCount <= 0) {
 
   64    DN::Attribute::List attributes;
 
   65    DN::Attribute::List reorderedAttributes;
 
   81#define digitp(p) (*(p) >= '0' && *(p) <= '9') 
   82#define hexdigitp(a) (digitp(a) || (*(a) >= 'A' && *(a) <= 'F') || (*(a) >= 'a' && *(a) <= 'f')) 
   83#define xtoi_1(p) (*(p) <= '9' ? (*(p) - '0') : *(p) <= 'F' ? (*(p) - 'A' + 10) : (*(p) - 'a' + 10)) 
   84#define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p) + 1)) 
   86static char *trim_trailing_spaces(
char *
string)
 
   91    for (mark = 
nullptr, p = 
string; *p; p++) {
 
  110static const unsigned char *parse_dn_part(DnPair *array, 
const unsigned char *
string)
 
  112    const unsigned char *s;
 
  113    const unsigned char *s1;
 
  118    for (s = 
string + 1; *s && *s != 
'='; s++) {
 
  128    p = (
char *)malloc(n + 1);
 
  130    memcpy(p, 
string, n);
 
  132    trim_trailing_spaces((
char *)p);
 
  134    if (
const char *name = Kleo::attributeNameForOID(p)) {
 
  141    if (*
string == 
'#') {
 
  144        for (s = 
string; hexdigitp(s); s++)
 
  151        array->value = p = (
char *)malloc(n + 1);
 
  153        for (s1 = 
string; n; s1 += 2, n--) {
 
  159        for (n = 0, s = 
string; *s; s++) {
 
  163                if (*s == 
',' || *s == 
'=' || *s == 
'+' || *s == 
'<' || *s == 
'>' || *s == 
'#' || *s == 
';' || *s == 
'\\' || *s == 
'\"' || *s == 
' ') {
 
  165                } 
else if (hexdigitp(s) && hexdigitp(s + 1)) {
 
  171            } 
else if (*s == 
'\"') {
 
  173            } 
else if (*s == 
',' || *s == 
'=' || *s == 
'+' || *s == 
'<' || *s == 
'>' || *s == 
'#' || *s == 
';') {
 
  180        array->value = p = (
char *)malloc(n + 1);
 
  182        for (s = 
string; n; s++, n--) {
 
  204QT_WARNING_DISABLE_DEPRECATED
 
  205static Kleo::DN::Attribute::List parse_dn(
const unsigned char *
string)
 
  210        QT_WARNING_DISABLE_DEPRECATED
 
  216    QT_WARNING_DISABLE_DEPRECATED
 
  220        while (*
string == 
' ') {
 
  227        DnPair pair = {
nullptr, 
nullptr};
 
  228        string = parse_dn_part(&pair, 
string);
 
  232        if (pair.key && pair.value) {
 
  234            QT_WARNING_DISABLE_DEPRECATED
 
  241        while (*
string == 
' ') {
 
  244        if (*
string && *
string != 
',' && *
string != 
';' && *
string != 
'+') {
 
  255    QT_WARNING_DISABLE_DEPRECATED
 
  261QT_WARNING_DISABLE_DEPRECATED
 
  265    return parse_dn((
const unsigned char *)dn.
toUtf8().
data());
 
  271    for (
int i = 0, end = s.
length(); i != end; ++i) {
 
  272        const QChar ch = s[i];
 
  292QT_WARNING_DISABLE_DEPRECATED
 
  298    for (
const auto &attribute : dn) {
 
  299        if (!attribute.name().isEmpty() && !attribute.value().isEmpty()) {
 
  300            result.push_back(attribute.name().trimmed() + 
QLatin1Char(
'=') + dn_escape(attribute.value().trimmed()));
 
  307QT_WARNING_DISABLE_DEPRECATED
 
  311    return listAttributes(dn).join(sep);
 
  315QT_WARNING_DISABLE_DEPRECATED
 
  316static Kleo::DN::Attribute::List reorder_dn(
const Kleo::DN::Attribute::List &dn)
 
  319    const QStringList &attrOrder = Kleo::DNAttributes::order();
 
  322    QT_WARNING_DISABLE_DEPRECATED
 
  323    Kleo::DN::Attribute::List unknownEntries;
 
  324    Kleo::DN::Attribute::List result;
 
  326    unknownEntries.reserve(dn.
size());
 
  331    QT_WARNING_DISABLE_DEPRECATED
 
  332    for (Kleo::DN::const_iterator it = dn.
begin(); it != dn.
end(); ++it) {
 
  334        if (!attrOrder.contains((*it).name())) {
 
  335            unknownEntries.push_back(*it);
 
  343            std::copy(unknownEntries.begin(), unknownEntries.end(), std::back_inserter(result));
 
  344            unknownEntries.clear(); 
 
  347            QT_WARNING_DISABLE_DEPRECATED
 
  348            for (Kleo::DN::const_iterator dnit = dn.
begin(); dnit != dn.
end(); ++dnit) {
 
  350                if ((*dnit).name() == *oit) {
 
  372Kleo::DN::DN(
const QString &dn)
 
  376    d->attributes = parse_dn(dn);
 
  379Kleo::DN::DN(
const char *utf8DN)
 
  384        d->attributes = parse_dn((
const unsigned char *)utf8DN);
 
  388Kleo::DN::DN(
const DN &other)
 
  404QT_WARNING_DISABLE_DEPRECATED
 
  405const Kleo::DN &Kleo::DN::operator=(
const DN &that)
 
  408    if (this->d == that.d) {
 
  429    if (d->reorderedAttributes.empty()) {
 
  430        d->reorderedAttributes = reorder_dn(d->attributes);
 
  432    return serialise(d->reorderedAttributes, QStringLiteral(
","));
 
 
  441    if (d->reorderedAttributes.empty()) {
 
  442        d->reorderedAttributes = reorder_dn(d->attributes);
 
  444    return listAttributes(d->reorderedAttributes);
 
 
  449    return d ? serialise(d->attributes, QStringLiteral(
",")) : 
QString();
 
 
  454    return d ? serialise(d->attributes, sep) : 
QString();
 
 
  460    return dn_escape(value);
 
 
  463void Kleo::DN::detach()
 
  466        d = 
new Kleo::DN::Private();
 
  468    } 
else if (d->refCount() > 1) {
 
  469        Kleo::DN::Private *d_save = d;
 
  470        d = 
new Kleo::DN::Private(*d);
 
  476void Kleo::DN::append(
const Attribute &attr)
 
  479    d->attributes.push_back(attr);
 
  480    d->reorderedAttributes.clear();
 
  483QString Kleo::DN::operator[](
const QString &attr)
 const 
  488    const QString attrUpper = attr.
toUpper();
 
  489    for (QList<Attribute>::const_iterator it = d->attributes.constBegin(); it != d->attributes.constEnd(); ++it) {
 
  490        if ((*it).name() == attrUpper) {
 
  491            return (*it).value();
 
  498QT_WARNING_DISABLE_DEPRECATED
 
  499static QList<Kleo::DN::Attribute> empty;
 
  503QT_WARNING_DISABLE_DEPRECATED
 
  504Kleo::DN::const_iterator Kleo::DN::begin()
 const 
  507    return d ? d->attributes.constBegin() : empty.constBegin();
 
  511QT_WARNING_DISABLE_DEPRECATED
 
  512Kleo::DN::const_iterator Kleo::DN::end()
 const 
  515    return d ? d->attributes.constEnd() : empty.constEnd();
 
static QString escape(const QString &value)
 
QStringList prettyAttributes() const
Returns the non-empty attributes formatted as {NAME=value} and reordered according to the settings in...
 
void push_back(parameter_type value)
 
void reserve(qsizetype size)
 
qsizetype size() const const
 
QString fromUtf8(QByteArrayView str)
 
qsizetype length() const const
 
void reserve(qsizetype size)
 
QString toUpper() const const
 
QByteArray toUtf8() const const