Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added some extra keywords for schema parsing.

  • Loading branch information...
commit 021701325c787c7394d7b9a76cd7ba7cfd44e788 1 parent 86ef054
Jeremy Childs authored

Showing 1 changed file with 39 additions and 33 deletions. Show diff stats Hide diff stats

  1. +39 33 schema.js
72 schema.js
@@ -2,23 +2,23 @@ var attributes = {};
2 2 var objectclasses = {};
3 3
4 4 var re_main = /(?:[^\(]*\( *)(.+)(?: \))/;
5   -var re_tokenize = /[\w\.-:]+|'(?:\\'|[^'])+'/g;
  5 +var re_tokenize = /[\w\.\-:\{\}]+|'(?:\\'|[^'])+'/g;
6 6 var re_quotedstring = /(?:')([^'\\]*(?:\\.[^'\\]*)*)/;
7 7 var is_oid = /[0-9\.]+/;
8   -var is_keyword = /(NAME|DESC|X-ORDERED|EQUALITY|OBSOLETE|SUP|ABSTRACT|STRUCTURAL|AUXILIARY|MUST|MAY|SINGLE-VALUE|NO-USER-MODIFICATION|SYNTAX|ORDERING|SUBSTR|COLLECTIVE)/;
  8 +var is_keyword = /(NAME|DESC|X\-ORDERED|USAGE|EQUALITY|OBSOLETE|SUP|ABSTRACT|STRUCTURAL|AUXILIARY|MUST|MAY|SINGLE\-VALUE|NO\-USER\-MODIFICATION|SYNTAX|ORDERING|SUBSTR|COLLECTIVE|X\-ORDERED\-VALUES)/;
9 9
10   -function parse(result, entry) {
  10 +function parseSchema(entry) {
  11 + var self = this;
11 12 var x;
12 13 var keyword;
13   -
14 14 try {
15 15 var items = entry.match(re_main)[1].match(re_tokenize);
16 16 items.forEach(function(item) {
17 17 if ((x = item.match(is_keyword)) && x[0]) {
18 18 keyword = x[0].toLowerCase().replace(/-/, '');
19   - result[keyword] = true;
  19 + self[keyword] = true;
20 20 } else if ((x = item.match(is_oid)) && !keyword) {
21   - result.oid = item;
  21 + self.oid = item;
22 22 } else {
23 23 // we're a value.. let's clean it up.
24 24 if (item[0] == '\'') {
@@ -27,20 +27,20 @@ function parse(result, entry) {
27 27 item = item.split(/ /);
28 28 }
29 29
30   - switch(typeof result[keyword]) {
  30 + switch(typeof self[keyword]) {
31 31 case 'boolean':
32   - result[keyword] = item;
  32 + self[keyword] = item;
33 33 break;
34 34 case 'string':
35   - result[keyword] = [ result[keyword] ];
  35 + self[keyword] = [ self[keyword] ];
36 36 // nobreak - fall through
37 37 case 'object':
38   - result[keyword].push(item);
  38 + self[keyword].push(item);
39 39 break;
40 40 case 'undefined':
41 41 break;
42 42 default:
43   - result[keyword] = item;
  43 + self[keyword] = item;
44 44 break;
45 45 }
46 46 }
@@ -49,50 +49,56 @@ function parse(result, entry) {
49 49 } catch (e) {
50 50 console.log(e);
51 51 }
52   - if (result.name && typeof result.name != 'object') {
53   - result.name = [ result.name ];
54   - }
55   - if (result.may && typeof result.may != 'object') {
56   - result.may = [ result.may ];
57   - }
58   - if (result.must && typeof result.must != 'object') {
59   - result.must = [ result.must ];
60   - }
61 52
62 53 return;
63 54 }
64 55
65 56 function ObjectClass(str) {
66   - var must = {};
67   - var may = {};
  57 + this.attributes = {};
  58 + this.parse(str);
  59 +
  60 + if (!this.must) {
  61 + this.must = [];
  62 + } else if (typeof this.must != 'object') {
  63 + this.must = [ this.must ];
  64 + }
  65 + if (!this.may) {
  66 + this.may = [];
  67 + } else if (typeof this.may != 'object') {
  68 + this.may = [ this.may ];
  69 + }
  70 + if (!this.name) {
  71 + this.name = [];
  72 + } else if (typeof this.name != 'object') {
  73 + this.name = [ this.name ];
  74 + }
68 75
69   - parse(this, str);
70   -
71 76 for (var i in this.must) {
72 77 var attrname = this.must[i];
73 78 if (attributes[attrname]) {
74   - must[attrname] = attributes[attrname];
  79 + this.attributes[attrname] = attributes[attrname];
75 80 }
76 81 }
77 82 for (var i in this.may) {
78 83 var attrname = this.may[i];
79 84 if (attributes[attrname]) {
80   - may[attrname] = attributes[attrname];
  85 + this.attributes[attrname] = attributes[attrname];
81 86 }
82 87 }
83   -
84   - this.muststr = this.must; // used for looping - so we know what name this oc uses for a given attr
85   - this.maystr = this.may;
86   - this.must = must;
87   - this.may = may;
88   -
89 88 return this;
90 89 }
  90 +ObjectClass.prototype.parse = parseSchema;
91 91
92 92 function Attribute(str) {
93   - parse(this, str);
  93 + this.parse(str);
  94 + if (!this.name) {
  95 + this.name = [];
  96 + } else if (typeof this.name != 'object') {
  97 + this.name = [ this.name ];
  98 + }
94 99 return this;
95 100 }
  101 +Attribute.prototype.parse = parseSchema;
96 102
97 103 module.exports = function(ldap, opt) {
98 104 // dummy for init_attr;

0 comments on commit 0217013

Please sign in to comment.
Something went wrong with that request. Please try again.