Bug 1714510 - Implement nsILDAPService in JS. r=darktrojan

Differential Revision: https://phabricator.services.mozilla.com/D117110

--HG--
extra : amend_source : ab864f5a9a8fa70fa060da19f765df8af38d34b3
This commit is contained in:
Ping Chen 2021-06-08 13:25:46 +03:00
Родитель 07a04c6aed
Коммит e6eeac1c6d
3 изменённых файлов: 72 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,66 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const EXPORTED_SYMBOLS = ["LDAPService"];
/**
* @implements {nsILDAPService}
*/
class LDAPService {
QueryInterface = ChromeUtils.generateQI(["nsILDAPService"]);
createFilter(maxSize, pattern, prefix, suffix, attr, value) {
let words = value.split(" ");
// Get the Mth to Nth words.
function getMtoN(m, n) {
n = n || m;
return words.slice(m - 1, n).join(" ");
}
let filter = prefix;
pattern.replaceAll("%a", attr);
while (pattern) {
let index = pattern.indexOf("%v");
if (index == -1) {
filter += pattern;
pattern = "";
} else {
filter += pattern.slice(0, index);
// Get the three characters after %v.
let [c1, c2, c3] = pattern.slice(index + 2, index + 5);
if (c1 >= "1" && c1 <= "9") {
if (c2 == "$") {
// %v$: means the last word
filter += getMtoN(words.length);
pattern = pattern.slice(index + 3);
} else if (c2 == "-") {
if (c3 >= "1" && c3 <= "9") {
// %vM-N: means from the Mth to the Nth word
filter += getMtoN(c1, c3);
pattern = pattern.slice(index + 5);
} else {
// %vN-: means from the Nth to the last word
filter += getMtoN(c1, words.length);
pattern = pattern.slice(index + 4);
}
} else {
// %vN: means the Nth word
filter += getMtoN(c1);
pattern = pattern.slice(index + 3);
}
} else {
// %v: means the entire search value
filter += value;
pattern = pattern.slice(index + 2);
}
}
}
filter += suffix;
return filter.length > maxSize ? "" : filter;
}
}
LDAPService.prototype.classID = Components.ID(
"{e8b59b32-f83f-4d5f-8eb5-e3c1e5de0d47}"
);

Просмотреть файл

@ -8,4 +8,5 @@ EXTRA_JS_MODULES += [
"LDAPConnection.jsm",
"LDAPMessage.jsm",
"LDAPOperation.jsm",
"LDAPService.jsm",
]

Просмотреть файл

@ -48,6 +48,11 @@ var ldapJSModules = [
"{dbe204e8-ae09-11eb-b4c8-a7e4b3e6e82e}",
"@mozilla.org/addressbook/ldap-replication-service;1",
],
[
"LDAPService",
"{e8b59b32-f83f-4d5f-8eb5-e3c1e5de0d47}",
"@mozilla.org/network/ldap-service;1",
],
];
LDAPModuleLoader.prototype = {