!import
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
8 *
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
13 *
14 * The Original Code is mozilla.org code.
15 *
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 2001
19 * the Initial Developer. All Rights Reserved.
20 *
21 * Contributor(s):
22 * Srilatha Moturi <srilatha@netscape.com>
23 * Mark Banner <mark@standard8.demon.co.uk>
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38
39 /* components defined in this file */
40
41 const NS_LDAPPREFSSERVICE_CONTRACTID =
42 "@mozilla.org/ldapprefs-service;1";
43 const NS_LDAPPREFSSERVICE_CID =
44 Components.ID("{667f6ab8-dbaf-49cb-be43-45ffa032b3de}");
45
46 /* interfaces used in this file */
47 const nsISupports = Components.interfaces.nsISupports;
48 const nsISupportsString = Components.interfaces.nsISupportsString;
49 const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
50 const nsILDAPPrefsService = Components.interfaces.nsILDAPPrefsService;
51
52 /* pref branches used in this file */
53 const prefRoot = "ldap_2.servers";
54 const parent = "ldap_2.servers.";
55
56 /* nsLDAPPrefs service */
nsLDAPPrefsService
57 function nsLDAPPrefsService() {}
58
59 nsLDAPPrefsService.prototype.QueryInterface =
QueryInterface
60 function (iid) {
61
62 if (iid.equals(nsISupports) ||
63 iid.equals(nsILDAPPrefsService))
64 return this;
65
66 Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;
67 return null;
68 }
69
70 nsLDAPPrefsService.prototype.getServerList =
getServerList
71 function (prefBranch, aCount) {
72 var prefCount = {value:0};
73
74 // get all the preferences with prefix ldap_2.servers
75 var directoriesList = prefBranch.getChildList(prefRoot, prefCount);
76
77 var childList = new Array();
78 var count = 0;
79 if (directoriesList) {
80 directoriesList.sort();
81 var prefixLen;
82 // lastDirectory contains the last entry that is added to the
83 // array childList.
84 var lastDirectory = "";
85
86 // only add toplevel prefnames to the list,
87 // i.e. add ldap_2.servers.<server-name>
88 // but not ldap_2.servers.<server-name>.foo
89 for(var i=0; i<prefCount.value; i++) {
90 // Assign the prefix ldap_2.servers.<server-name> to directoriesList
91 prefixLen = directoriesList[i].indexOf(".", parent.length);
92 if (prefixLen != -1) {
93 directoriesList[i] = directoriesList[i].substr(0, prefixLen);
94 if (directoriesList[i] != lastDirectory) {
95 // add the entry to childList
96 // only if it is not added yet
97 lastDirectory = directoriesList[i];
98 childList[count] = directoriesList[i];
99 count++;
100 }
101 }
102 }
103 }
104
105 if (!count)
106 // no preferences with the prefix ldap_2.servers
107 throw Components.results.NS_ERROR_FAILURE;
108
109 aCount.value = count;
110 return childList;
111 }
112
113 /* factory for nsLDAPPrefs service (nsLDAPPrefsService) */
114
115 var nsLDAPPrefsFactory = new Object();
116
117 nsLDAPPrefsFactory.createInstance =
118
anon:119:0
119 function (outer, iid) {
120 if (outer != null)
121 throw Components.results.NS_ERROR_NO_AGGREGATION;
122
123 if (!iid.equals(nsISupports) && !iid.equals(nsILDAPPrefsService))
124 throw Components.results.NS_ERROR_INVALID_ARG;
125
126 return new nsLDAPPrefsService();
127 }
128
129 var nsLDAPPrefsModule = new Object();
130 nsLDAPPrefsModule.registerSelf =
anon:131:0
131 function (compMgr, fileSpec, location, type)
132 {
133 compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
134
135 compMgr.registerFactoryLocation(NS_LDAPPREFSSERVICE_CID,
136 "nsLDAPPrefs Service",
137 NS_LDAPPREFSSERVICE_CONTRACTID,
138 fileSpec,
139 location,
140 type);
141 }
142
143 nsLDAPPrefsModule.unregisterSelf =
anon:144:0
144 function(compMgr, fileSpec, location)
145 {
146 compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
147 compMgr.unregisterFactoryLocation(NS_LDAPPREFSSERVICE_CID, fileSpec);
148 }
149
150 nsLDAPPrefsModule.getClassObject =
anon:151:0
151 function (compMgr, cid, iid) {
152 if (cid.equals(nsILDAPPrefsService))
153 return nsLDAPPrefsFactory;
154 throw Components.results.NS_ERROR_NO_INTERFACE;
155 }
156
157 nsLDAPPrefsModule.canUnload =
anon:158:0
158 function(compMgr)
159 {
160 return true;
161 }
162
163 /* entrypoint */
NSGetModule
164 function NSGetModule(compMgr, fileSpec) {
165 return nsLDAPPrefsModule;
166 }