Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit 1376e59

Browse files
committed
Remove special attribute formatting for objectGUID
- Conclude #218 - Clean up exports in index.js
1 parent 3ca7e6d commit 1376e59

File tree

3 files changed

+5
-128
lines changed

3 files changed

+5
-128
lines changed

README.md

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -36,70 +36,15 @@ server.listen(1389, function() {
3636
});
3737
```
3838

39-
To run that, assuming you've got the [OpenLDAP](http://www.openldap.org/) client
40-
on your system:
39+
To run that, assuming you've got the [OpenLDAP](http://www.openldap.org/)
40+
client on your system:
4141

4242
ldapsearch -H ldap://localhost:1389 -x -b dc=example objectclass=*
4343

4444
## Installation
4545

4646
npm install ldapjs
4747

48-
## Formatting objectGUID attribute value
49-
50-
```javascript
51-
var ldap = require('ldapjs');
52-
53-
ldap.Attribute.settings.guid_format = ldap.GUID_FORMAT_B;
54-
55-
var client = ldap.createClient({
56-
url: 'ldap://127.0.0.1/CN=test,OU=Development,DC=Home'
57-
});
58-
59-
var opts = {
60-
filter: '(objectclass=user)',
61-
scope: 'sub',
62-
attributes: ['objectGUID']
63-
};
64-
65-
client.bind('username', 'password', function (err) {
66-
client.search('CN=test,OU=Development,DC=Home', opts, function (err, search) {
67-
search.on('searchEntry', function (entry) {
68-
var user = entry.object;
69-
console.log(user.objectGUID);
70-
});
71-
});
72-
});
73-
```
74-
75-
_Note: for the sake of simplicity all checks and error handling was removed from the sample above._
76-
77-
The console output may be similar to the following (depending on the amount of users in the directory):
78-
79-
{a7667bb1-4aee-48ce-9d9d-a1193550deba}
80-
{8d642ac8-14c6-4f27-ac5-94d39833da88}
81-
82-
Available formatting modes:
83-
84-
GUID_FORMAT_N
85-
N specifier, 32 digits:
86-
00000000000000000000000000000000
87-
GUID_FORMAT_D
88-
D specifier, 32 digits separated by hypens:
89-
00000000-0000-0000-0000-000000000000
90-
GUID_FORMAT_B
91-
B specifier, 32 digits separated by hyphens, enclosed in braces:
92-
{00000000-0000-0000-0000-000000000000}
93-
GUID_FORMAT_P
94-
P speficier, 32 digits separated by hyphens, enclosed in parentheses:
95-
(00000000-0000-0000-0000-000000000000)
96-
GUID_FORMAT_X
97-
X speficier, four hexadecimal values enclosed in braces,
98-
where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces:
99-
{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}
100-
101-
GUID formatting is unobtrusive by default. You should explicitly define formatting mode in order to enable it.
102-
10348
## License
10449

10550
MIT.

lib/attribute.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ var asn1 = require('asn1');
66

77
var Protocol = require('./protocol');
88

9-
var settings = {};
10-
// specifies Guid display format, not defined (and unobstrusive) by default
11-
settings.guid_format = '';
129

1310
///--- API
1411

@@ -39,19 +36,6 @@ function Attribute(options) {
3936
}
4037
});
4138

42-
// processing of objectGUID attribute value
43-
if (/objectGUID$/.test(self.type)) {
44-
// check whether custom display format was defined
45-
if (settings && settings.guid_format && settings.guid_format.length > 0) {
46-
// ensure objectGUID value is present within buffers
47-
var _buffers = self._vals;
48-
if (_buffers && _buffers.length > 0 && Buffer.isBuffer(_buffers[0])) {
49-
// return formatted value as per settings
50-
return formatGuid(settings.guid_format, _buffers[0]);
51-
}
52-
}
53-
}
54-
5539
return _vals;
5640
});
5741

@@ -81,7 +65,6 @@ function Attribute(options) {
8165

8266
}
8367
module.exports = Attribute;
84-
module.exports.settings = settings;
8568

8669
Attribute.prototype.addValue = function (val) {
8770
if (Buffer.isBuffer(val)) {
@@ -186,14 +169,3 @@ Attribute.isAttribute = function (attr) {
186169
Attribute.prototype.toString = function () {
187170
return JSON.stringify(this.json);
188171
};
189-
190-
191-
function formatGuid(format, data) {
192-
for (var i = 0; i < data.length; i++) {
193-
var re = new RegExp('\\{' + i + '\\}', 'g');
194-
// Leading 0 is needed if value of data[i] is less than 16 (of 10 as hex).
195-
var dataStr = data[i].toString(16);
196-
format = format.replace(re, data[i] >= 16 ? dataStr : '0' + dataStr);
197-
}
198-
return format;
199-
}

lib/index.js

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,10 @@ var filters = require('./filters');
1717
var messages = require('./messages');
1818
var url = require('./url');
1919

20-
// Guid formatting
21-
22-
// N specifier, 32 digits:
23-
// 00000000000000000000000000000000
24-
/* JSSTYLED */
25-
var GUID_FORMAT_N = '{3}{2}{1}{0}{5}{4}{7}{6}{8}{9}{10}{11}{12}{13}{14}{15}';
26-
27-
// D specifier, 32 digits separated by hypens:
28-
// 00000000-0000-0000-0000-000000000000
29-
/* JSSTYLED */
30-
var GUID_FORMAT_D = '{3}{2}{1}{0}-{5}{4}-{7}{6}-{8}{9}-{10}{11}{12}{13}{14}{15}';
31-
32-
// B specifier, 32 digits separated by hyphens, enclosed in braces:
33-
// {00000000-0000-0000-0000-000000000000}
34-
/* JSSTYLED */
35-
var GUID_FORMAT_B = '{{3}{2}{1}{0}-{5}{4}-{7}{6}-{8}{9}-{10}{11}{12}{13}{14}{15}}';
36-
37-
// P specifier, 32 digits separated by hyphens, enclosed in parentheses:
38-
// (00000000-0000-0000-0000-000000000000)
39-
/* JSSTYLED */
40-
var GUID_FORMAT_P = '({3}{2}{1}{0}-{5}{4}-{7}{6}-{8}{9}-{10}{11}{12}{13}{14}{15})';
41-
42-
// X specifier, Four hexadecimal values enclosed in braces,
43-
// where the fourth value is a subset of eight hexadecimal values that is also
44-
// enclosed in braces:
45-
// {0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}
46-
/* JSSTYLED */
47-
var GUID_FORMAT_X = '{0x{3}{2}{1}{0},0x{5}{4},0x{7}{6},{0x{8},0x{9},0x{10},0x{11},0x{12},0x{13},0x{14},0x{15}}}';
48-
49-
5020

5121
///--- API
5222

5323
module.exports = {
54-
5524
createClient: client.createClient,
5625

5726
Server: Server,
@@ -76,31 +45,22 @@ module.exports = {
7645
Attribute: Attribute,
7746
Change: Change,
7847

48+
dn: dn,
7949
DN: dn.DN,
80-
PersistentSearchCache: persistentSearch.PersistentSearchCache,
8150
RDN: dn.RDN,
82-
8351
parseDN: dn.parse,
84-
dn: dn,
8552

8653
persistentSearch: persistentSearch,
54+
PersistentSearchCache: persistentSearch.PersistentSearchCache,
8755

8856
filters: filters,
8957
parseFilter: filters.parseString,
9058

91-
parseURL: url.parse,
92-
9359
url: url,
94-
95-
GUID_FORMAT_N: GUID_FORMAT_N,
96-
GUID_FORMAT_D: GUID_FORMAT_D,
97-
GUID_FORMAT_B: GUID_FORMAT_B,
98-
GUID_FORMAT_P: GUID_FORMAT_P,
99-
GUID_FORMAT_X: GUID_FORMAT_X
60+
parseURL: url.parse
10061
};
10162

10263

103-
10464
///--- Export all the childrenz
10565

10666
var k;

0 commit comments

Comments
 (0)