Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

url.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2011 Mark Cavage, Inc. All rights reserved.
  2. var querystring = require('querystring');
  3. var url = require('url');
  4. var util = require('util');
  5. var dn = require('./dn');
  6. var filter = require('./filters/index');
  7. module.exports = {
  8. parse: function (urlStr, parseDN) {
  9. var u = url.parse(urlStr);
  10. if (!u.protocol || !(u.protocol === 'ldap:' || u.protocol === 'ldaps:'))
  11. throw new TypeError(urlStr + ' is an invalid LDAP url (protocol)');
  12. u.secure = (u.protocol === 'ldaps:');
  13. if (!u.hostname)
  14. u.hostname = 'localhost';
  15. if (!u.port) {
  16. u.port = (u.secure ? 636 : 389);
  17. } else {
  18. u.port = parseInt(u.port, 10);
  19. }
  20. if (u.pathname) {
  21. u.pathname = querystring.unescape(u.pathname.substr(1));
  22. u.DN = parseDN ? dn.parse(u.pathname) : u.pathname;
  23. }
  24. if (u.search) {
  25. u.attributes = [];
  26. var tmp = u.search.substr(1).split('?');
  27. if (tmp && tmp.length) {
  28. if (tmp[0]) {
  29. tmp[0].split(',').forEach(function (a) {
  30. u.attributes.push(querystring.unescape(a.trim()));
  31. });
  32. }
  33. }
  34. if (tmp[1]) {
  35. if (tmp[1] !== 'base' && tmp[1] !== 'one' && tmp[1] !== 'sub')
  36. throw new TypeError(urlStr + ' is an invalid LDAP url (scope)');
  37. u.scope = tmp[1];
  38. }
  39. if (tmp[2]) {
  40. u.filter = querystring.unescape(tmp[2]);
  41. }
  42. if (tmp[3]) {
  43. u.extensions = querystring.unescape(tmp[3]);
  44. }
  45. if (!u.scope)
  46. u.scope = 'base';
  47. if (!u.filter)
  48. u.filter = filter.parseString('(objectclass=*)');
  49. else
  50. u.filter = filter.parseString(u.filter);
  51. }
  52. return u;
  53. }
  54. };