1/*
2 This file is part of libkldap.
3 Copyright (c) 2004-2006 Szombathelyi György <gyurco@freemail.hu>
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
21#ifndef KLDAP_BER_H
22#define KLDAP_BER_H
23
24#include <QtCore/QByteArray>
25
26#include "kldap_export.h"
27
28namespace KLDAP {
29
30 /**
31 * This class allows encoding and decoding Qt structures using Basic
32 * Encoding Rules.
33 */
34class KLDAP_EXPORT Ber
35{
36 public:
37 /**
38 * Constructs a Ber object.
39 */
40 Ber();
41 /**
42 * Constructs a Ber object from the value.
43 */
44 explicit Ber( const QByteArray &value );
45 /**
46 * Destroys the Ber object.
47 */
48 virtual ~Ber();
49
50 Ber( const Ber &that );
51 Ber &operator=( const Ber &that );
52
53 /**
54 * Returns the Ber object as a flat QByteArray.
55 */
56 QByteArray flatten() const;
57
58 /**
59 * Appends the data with the specified format to the Ber object.
60 * This function works like printf, except that it's appending the
61 * parameters, not replacing them. The allowed format characters and
62 * the expected parameter types are:
63 * <ul>
64 * <li>
65 * b Boolean. An int parameter should be supplied.
66 * A boolean element is output.
67 * </li>
68 * <li>
69 * e Enumeration. An int parameter should be supplied.
70 * An enumeration element is output.
71 * </li>
72 * <li>
73 * i Integer. An int parameter should be supplied.
74 * An integer element is output.
75 * </li>
76 * <li>
77 * B Bitstring. A pointer to a QByteArray which contains the
78 * bitstring is supplied, followed by the number of bits in the
79 * bitstring. A bitstring element is output.
80 * </li>
81 * <li>
82 * n Null. No parameter is required. A null element is output.
83 * </li>
84 * <li>
85 * O,o,s Octet string. A QByteArray * is supplied.
86 * An octet string element is output.
87 * Due to versatility of Qt's QByteArray, these three format
88 * strings are all accepts the same parameter, but using the 's'
89 * format the string will be encoded only to the first zero
90 * character (a null terminated string)!
91 * </li>
92 * <li>
93 * t Tag. An int specifying the tag to give the next element
94 * is provided. This works across calls.
95 * </li>
96 * <li>
97 * v,V Several octet strings. A QList<QByteArray>* is supplied.
98 * Note that a construct like ’{v}’ is required to get an actual
99 * SEQUENCE OF octet strings. Also note that the 'v' format recognizes
100 * the QByteArray only to the first zero character, so it's not
101 * appropriate for binary data, just only for null terminated strings!
102 * </li>
103 * <li>
104 * { Begin sequence. No parameter is required.
105 * </li>
106 * <li>
107 * } End sequence. No parameter is required.
108 * </li>
109 * <li>
110 * [ Begin set. No parameter is required.
111 * </li>
112 * <li>
113 * ] End set. No parameter is required.
114 * </li>
115 * </ul>
116 */
117 int printf( const QString &format, ... );
118 int scanf( const QString &format, ... );
119 unsigned int peekTag( int &size );
120 unsigned int skipTag( int &size );
121
122 private:
123 class BerPrivate;
124 BerPrivate *const d;
125};
126
127}
128#endif
129