46 #include <QStringList>
57 #include <kconfiggroup.h>
59 class Kleo::DN::Private {
61 Private() : mRefCount( 0 ) {}
62 Private(
const Private & other )
63 : attributes( other.attributes ),
64 reorderedAttributes( other.reorderedAttributes ),
75 if ( --mRefCount <= 0 ) {
82 int refCount()
const {
return mRefCount; }
84 DN::Attribute::List attributes;
85 DN::Attribute::List reorderedAttributes;
99 #define digitp(p) (*(p) >= '0' && *(p) <= '9')
100 #define hexdigitp(a) (digitp (a) \
101 || (*(a) >= 'A' && *(a) <= 'F') \
102 || (*(a) >= 'a' && *(a) <= 'f'))
103 #define xtoi_1(p) (*(p) <= '9'? (*(p)- '0'): \
104 *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10))
105 #define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1))
112 for( mark = NULL, p =
string; *p; p++ ) {
113 if( isspace( *p ) ) {
129 static const unsigned char *
132 const unsigned char *s, *s1;
137 for (s =
string+1; *s && *s !=
'='; s++)
144 p = (
char*)malloc (n+1);
147 memcpy (p,
string, n);
151 for (
unsigned int i = 0 ; i <
numOidMaps ; ++i )
152 if ( !strcasecmp ((
char*)p,
oidmap[i].
oid) ) {
169 array->value = p = (
char*)malloc (n+1);
172 for (s1=
string; n; s1 += 2, n--)
178 for (n=0, s=
string; *s; s++)
183 if (*s ==
',' || *s ==
'=' || *s ==
'+'
184 || *s ==
'<' || *s ==
'>' || *s ==
'#' || *s ==
';'
185 || *s ==
'\\' || *s ==
'\"' || *s ==
' ')
197 else if (*s ==
',' || *s ==
'=' || *s ==
'+'
198 || *s ==
'<' || *s ==
'>' || *s ==
'#' || *s ==
';' )
204 array->value = p = (
char*)malloc (n+1);
207 for (s=
string; n; s++, n--)
232 static Kleo::DN::Attribute::List
240 while (*
string ==
' ')
245 DnPair pair = { 0, 0 };
249 if ( pair.key && pair.value )
255 while (*
string ==
' ')
257 if (*
string && *
string !=
',' && *
string !=
';' && *
string !=
'+')
275 for (
unsigned int i = 0, end = s.
length() ; i != end ; ++i ) {
276 const QChar ch = s[i];
298 if ( !(*it).name().isEmpty() && !(*it).value().isEmpty() )
300 return result.
join( sep );
303 static Kleo::DN::Attribute::List
307 Kleo::DN::Attribute::List unknownEntries;
308 Kleo::DN::Attribute::List result;
309 unknownEntries.
reserve( dn.size() );
310 result.reserve( dn.size() );
313 for ( Kleo::DN::const_iterator it = dn.begin(); it != dn.end(); ++it )
314 if ( !attrOrder.
contains( (*it).name() ) )
315 unknownEntries.push_back( *it );
321 std::copy( unknownEntries.begin(), unknownEntries.end(),
322 std::back_inserter( result ) );
323 unknownEntries.clear();
325 for ( Kleo::DN::const_iterator dnit = dn.begin() ; dnit != dn.end() ; ++dnit )
326 if ( (*dnit).name() == *oit )
327 result.push_back( *dnit );
354 d->attributes =
parse_dn( (
const unsigned char*)utf8DN );
368 if ( this->d == that.d )
384 if ( d->reorderedAttributes.empty() )
385 d->reorderedAttributes =
reorder_dn( d->attributes );
402 void Kleo::DN::detach() {
404 d =
new Kleo::DN::Private();
406 }
else if ( d->refCount() > 1 ) {
407 Kleo::DN::Private * d_save = d;
408 d =
new Kleo::DN::Private( *d );
416 d->attributes.push_back( attr );
417 d->reorderedAttributes.clear();
425 it != d->attributes.constEnd() ; ++it )
426 if ( (*it).name() == attrUpper )
427 return (*it).value();
434 return d ? d->attributes.constBegin() : empty.
constBegin() ;
438 return d ? d->attributes.constEnd() : empty.
constEnd() ;
446 bool operator()(
const char * s1,
const char * s2 )
const {
447 return qstrcmp( s1, s2 ) < 0 ;
453 "CN",
"L",
"_X_",
"OU",
"O",
"C"
457 #define MAKE_PAIR(x,y) std::pair<const char*,const char*>( x, y )
458 MAKE_PAIR(
"CN", I18N_NOOP(
"Common name") ),
460 MAKE_PAIR(
"GN", I18N_NOOP(
"Given name") ),
463 MAKE_PAIR(
"OU", I18N_NOOP(
"Organizational unit") ),
464 MAKE_PAIR(
"O", I18N_NOOP(
"Organization") ),
465 MAKE_PAIR(
"PC", I18N_NOOP(
"Postal code") ),
466 MAKE_PAIR(
"C", I18N_NOOP(
"Country code") ),
467 MAKE_PAIR(
"SP", I18N_NOOP(
"State or province") ),
468 MAKE_PAIR(
"DC", I18N_NOOP(
"Domain component") ),
469 MAKE_PAIR(
"BC", I18N_NOOP(
"Business category") ),
470 MAKE_PAIR(
"EMAIL", I18N_NOOP(
"Email address") ),
471 MAKE_PAIR(
"MAIL", I18N_NOOP(
"Mail address") ),
472 MAKE_PAIR(
"MOBILE", I18N_NOOP(
"Mobile phone number") ),
473 MAKE_PAIR(
"TEL", I18N_NOOP(
"Telephone number") ),
474 MAKE_PAIR(
"FAX", I18N_NOOP(
"Fax number") ),
475 MAKE_PAIR(
"STREET", I18N_NOOP(
"Street address") ),
476 MAKE_PAIR(
"UID", I18N_NOOP(
"Unique ID") )
481 class Kleo::DNAttributeMapper::Private {
484 std::map<const char*,const char*,ltstr>
map;
488 Kleo::DNAttributeMapper::Private::Private()
489 :
map( attributeLabels, attributeLabels + numAttributeLabels ) {}
491 Kleo::DNAttributeMapper::DNAttributeMapper() {
493 const KConfigGroup config( KGlobal::config(),
"DN" );
494 d->attributeOrder = config.readEntry(
"AttributeOrder" ,
QStringList() );
495 if ( d->attributeOrder.empty() )
496 std::copy( defaultOrder, defaultOrder +
sizeof defaultOrder /
sizeof *defaultOrder,
497 std::back_inserter( d->attributeOrder ) );
501 Kleo::DNAttributeMapper::~DNAttributeMapper() {
515 const std::map<const char*,const char*,ltstr>::const_iterator it
517 if ( it == d->map.end() )
519 return i18n( it->second );
524 for ( std::map<const char*,const char*,ltstr>::const_iterator it = d->map.begin() ; it != d->map.end() ; ++it )
530 return d->attributeOrder;
534 d->attributeOrder = order;
536 std::copy( defaultOrder, defaultOrder +
sizeof defaultOrder /
sizeof *defaultOrder,
537 std::back_inserter( d->attributeOrder ) );
538 KConfigGroup config( KGlobal::config(),
"DN" );
539 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)
const_iterator constEnd() const
bool contains(const QString &str, Qt::CaseSensitivity cs) const
static const unsigned int numAttributeLabels
QString join(const QString &separator) const
QString map(const char *token, int subtoken)
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
void append(const Attribute &attr)
static const unsigned char * parse_dn_part(DnPair *array, const unsigned char *string)
static const char * defaultOrder[]
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 struct @4 oidmap[]
static QString serialise(const QVector< Kleo::DN::Attribute > &dn, const QString &sep)
void push_back(const T &value)
int find(QChar c, int i, bool cs) const
DNAttributeOrderConfigWidget * configWidget(QWidget *parent=0) const
static QString dn_escape(const QString &s)
const_iterator begin() const
std::pair< const char *, const char * > attributeLabels[]
static const DNAttributeMapper * instance()
Attribute(const QString &name=QString(), const QString &value=QString())
const DN & operator=(const DN &other)
QByteArray toUtf8() const