44 #include <KLocalizedString>
46 #include <QStringList>
56 #include <KConfigGroup>
57 #include <KSharedConfig>
59 class Kleo::DN::Private
62 Private() : mRefCount(0) {}
63 Private(
const Private &other)
64 : attributes(other.attributes),
65 reorderedAttributes(other.reorderedAttributes),
78 if (--mRefCount <= 0) {
91 DN::Attribute::List attributes;
92 DN::Attribute::List reorderedAttributes;
107 #define digitp(p) (*(p) >= '0' && *(p) <= '9')
108 #define hexdigitp(a) (digitp (a) \
109 || (*(a) >= 'A' && *(a) <= 'F') \
110 || (*(a) >= 'a' && *(a) <= 'f'))
111 #define xtoi_1(p) (*(p) <= '9'? (*(p)- '0'): \
112 *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10))
113 #define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1))
120 for (mark =
nullptr, p =
string; *p; p++) {
139 static const unsigned char *
142 const unsigned char *s, *s1;
147 for (s =
string + 1; *s && *s !=
'='; s++)
156 p = (
char *)malloc(n + 1);
158 memcpy(p,
string, n);
163 if (!strcasecmp((
char *)p,
oidmap[i].
oid)) {
171 if (*
string ==
'#') {
182 array->value = p = (
char *)malloc(n + 1);
184 for (s1 =
string; n; s1 += 2, n--) {
190 for (n = 0, s =
string; *s; s++) {
194 if (*s ==
',' || *s ==
'=' || *s ==
'+'
195 || *s ==
'<' || *s ==
'>' || *s ==
'#' || *s ==
';'
196 || *s ==
'\\' || *s ==
'\"' || *s ==
' ') {
204 }
else if (*s ==
'\"') {
206 }
else if (*s ==
',' || *s ==
'=' || *s ==
'+'
207 || *s ==
'<' || *s ==
'>' || *s ==
'#' || *s ==
';') {
214 array->value = p = (
char *)malloc(n + 1);
216 for (s =
string; n; s++, n--) {
237 static Kleo::DN::Attribute::List
246 while (*
string ==
' ') {
253 DnPair pair = {
nullptr,
nullptr };
258 if (pair.key && pair.value)
264 while (*
string ==
' ') {
267 if (*
string && *
string !=
',' && *
string !=
';' && *
string !=
'+') {
289 for (
int i = 0, end = s.
length(); i != end; ++i) {
290 const QChar ch = s[i];
314 if (!(*it).name().isEmpty() && !(*it).value().isEmpty()) {
317 return result.
join(sep);
320 static Kleo::DN::Attribute::List
325 Kleo::DN::Attribute::List unknownEntries;
326 Kleo::DN::Attribute::List result;
327 unknownEntries.
reserve(dn.size());
328 result.reserve(dn.size());
331 for (Kleo::DN::const_iterator it = dn.begin(); it != dn.end(); ++it)
332 if (!attrOrder.
contains((*it).name())) {
333 unknownEntries.push_back(*it);
340 std::copy(unknownEntries.begin(), unknownEntries.end(),
341 std::back_inserter(result));
342 unknownEntries.clear();
344 for (Kleo::DN::const_iterator dnit = dn.begin(); dnit != dn.end(); ++dnit)
345 if ((*dnit).name() == *oit) {
346 result.push_back(*dnit);
377 d->attributes =
parse_dn((
const unsigned char *)utf8DN);
398 if (this->d == that.d) {
419 if (d->reorderedAttributes.empty()) {
420 d->reorderedAttributes =
reorder_dn(d->attributes);
422 return serialise(d->reorderedAttributes, QStringLiteral(
","));
441 void Kleo::DN::detach()
444 d =
new Kleo::DN::Private();
446 }
else if (d->refCount() > 1) {
447 Kleo::DN::Private *d_save = d;
448 d =
new Kleo::DN::Private(*d);
457 d->attributes.push_back(attr);
458 d->reorderedAttributes.clear();
468 it != d->attributes.constEnd(); ++it)
469 if ((*it).name() == attrUpper) {
470 return (*it).value();
479 return d ? d->attributes.constBegin() : empty.
constBegin();
484 return d ? d->attributes.constEnd() : empty.
constEnd();
492 bool operator()(
const char *s1,
const char *s2)
const
494 return qstrcmp(s1, s2) < 0;
500 "CN",
"L",
"_X_",
"OU",
"O",
"C"
504 #define MAKE_PAIR(x,y) std::pair<const char*,const char*>( x, y )
505 MAKE_PAIR(
"CN", I18N_NOOP(
"Common name")),
507 MAKE_PAIR(
"GN", I18N_NOOP(
"Given name")),
510 MAKE_PAIR(
"OU", I18N_NOOP(
"Organizational unit")),
511 MAKE_PAIR(
"O", I18N_NOOP(
"Organization")),
512 MAKE_PAIR(
"PC", I18N_NOOP(
"Postal code")),
513 MAKE_PAIR(
"C", I18N_NOOP(
"Country code")),
514 MAKE_PAIR(
"SP", I18N_NOOP(
"State or province")),
515 MAKE_PAIR(
"DC", I18N_NOOP(
"Domain component")),
516 MAKE_PAIR(
"BC", I18N_NOOP(
"Business category")),
517 MAKE_PAIR(
"EMAIL", I18N_NOOP(
"Email address")),
518 MAKE_PAIR(
"MAIL", I18N_NOOP(
"Mail address")),
519 MAKE_PAIR(
"MOBILE", I18N_NOOP(
"Mobile phone number")),
520 MAKE_PAIR(
"TEL", I18N_NOOP(
"Telephone number")),
521 MAKE_PAIR(
"FAX", I18N_NOOP(
"Fax number")),
522 MAKE_PAIR(
"STREET", I18N_NOOP(
"Street address")),
528 class Kleo::DNAttributeMapper::Private
532 std::map<const char *, const char *, ltstr> map;
536 Kleo::DNAttributeMapper::Private::Private()
537 :
map(attributeLabels, attributeLabels + numAttributeLabels) {}
539 Kleo::DNAttributeMapper::DNAttributeMapper()
542 const KConfigGroup config(KSharedConfig::openConfig(),
"DN");
543 d->attributeOrder = config.readEntry(
"AttributeOrder",
QStringList());
544 if (d->attributeOrder.empty())
545 std::copy(defaultOrder, defaultOrder +
sizeof defaultOrder /
sizeof * defaultOrder,
546 std::back_inserter(d->attributeOrder));
550 Kleo::DNAttributeMapper::~DNAttributeMapper()
553 delete d; d =
nullptr;
568 const std::map<const char *, const char *, ltstr>::const_iterator it
570 if (it == d->map.end()) {
573 return i18n(it->second);
579 for (std::map<const char *, const char *, ltstr>::const_iterator it = d->map.begin(); it != d->map.end(); ++it) {
587 return d->attributeOrder;
592 d->attributeOrder = order;
594 std::copy(defaultOrder, defaultOrder +
sizeof defaultOrder /
sizeof * defaultOrder,
595 std::back_inserter(d->attributeOrder));
596 KConfigGroup config(KSharedConfig::openConfig(),
"DN");
597 config.writeEntry(
"AttributeOrder", order);
static char * trim_trailing_spaces(char *string)
static QVector< Kleo::DN::Attribute > empty
QString name2label(const QString &s) const
void setAttributeOrder(const QStringList &order)
static const unsigned int numOidMaps
void push_back(const T &value)
static const struct @2 oidmap[]
const_iterator constEnd() const
static const char *const defaultOrder[]
bool contains(const QString &str, Qt::CaseSensitivity cs) const
static const unsigned int numAttributeLabels
QString join(const QString &separator) const
const QStringList & attributeOrder() const
static QString escape(const QString &value)
static Kleo::DN::Attribute::List reorder_dn(const Kleo::DN::Attribute::List &dn)
QString fromUtf8(const char *str, int size)
QStringList names() const
const char * constData() const
void append(const Attribute &attr)
static const unsigned char * parse_dn_part(DnPair *array, const unsigned char *string)
QFuture< void > map(Sequence &sequence, MapFunction function)
QString operator[](const QString &attr) const
const_iterator constBegin() const
QByteArray toLatin1() const
static Kleo::DN::Attribute::List parse_dn(const unsigned char *string)
const_iterator end() const
static QString serialise(const QVector< Kleo::DN::Attribute > &dn, const QString &sep)
static std::pair< const char *, const char * > const attributeLabels[]
void push_back(const T &value)
int find(QChar c, int i, bool cs) const
static QString dn_escape(const QString &s)
const_iterator begin() const
static const DNAttributeMapper * instance()
Attribute(const QString &name=QString(), const QString &value=QString())
DNAttributeOrderConfigWidget * configWidget(QWidget *parent=nullptr) const
const DN & operator=(const DN &other)
QByteArray toUtf8() const