2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
26 * $XConsortium: DbLoad.c /main/7 1996/08/28 14:38:07 rswiston $
28 * RESTRICTED CONFIDENTIAL INFORMATION:
30 * The information in this document is subject to special restrictions in a
31 * confidential disclosure agreement bertween HP, IBM, Sun, USL, SCO and
32 * Univel. Do not distribute this document outside HP, IBM, Sun, USL, SCO,
33 * or Univel wihtout Sun's specific written approval. This documment and all
34 * copies and derivative works thereof must be returned or destroyed at Sun's
37 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
43 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
44 * (c) Copyright 1993, 1994 International Business Machines Corp. *
45 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
46 * (c) Copyright 1993, 1994 Novell, Inc. *
50 #include <sys/types.h>
56 #if defined(sun) || defined(CSRG_BASED)
60 #endif /* sun || CSRD_BASED */
72 #include <sys/param.h> /* MAXPATHLEN, MAXHOSTNAMELEN */
74 #include <X11/Intrinsic.h>
75 #include <X11/StringDefs.h>
77 #include <Dt/Connect.h>
78 #include <Dt/FileUtil.h>
79 #include <Dt/DtNlUtils.h>
80 #include <Dt/Action.h>
81 #include <Dt/ActionDbP.h>
82 #include <Dt/ActionP.h>
83 #include <Dt/ActionFind.h>
84 #include <Dt/DbUtil.h>
85 #include <Dt/DtPStrings.h>
86 #include <Dt/Utility.h>
91 #include "myassertP.h"
92 #include "DtSvcLock.h"
94 extern void _DtDtsDCConverter(DtDtsDbField * fields,
97 Boolean rejectionStatus);
98 extern void _DtDtsDAConverter(DtDtsDbField * fields,
101 Boolean rejectionStatus);
103 extern void _DtDtsSeqReset(void);
104 extern int _DtDtsNextDCSeq(void);
105 extern int _DtDtsNextDASeq(void);
106 extern int _DtDtsMMUnLoad(void);
107 extern void _DtFreeActionDB(void);
109 char **_DtsDbListDb(void);
111 int use_in_memory_db = False;
114 _DtOAConverter(DtDtsDbField * fields,
117 Boolean rejectionStatus)
119 DtDtsDbDatabase *dc_db;
120 DtDtsDbDatabase *da_db;
121 DtDtsDbRecord *dc_rec;
122 DtDtsDbRecord *da_rec;
126 dc_db = _DtDtsDbGet(DtDTS_DC_NAME);
127 da_db = _DtDtsDbGet(DtDTS_DA_NAME);
128 if ( _DtDtsDbGetRecordByName(dc_db,
129 fields[0].fieldValue) ||
130 _DtDtsDbGetRecordByName(da_db,
131 fields[0].fieldValue))
133 _DtSvcProcessUnlock();
138 * Synthesize criteria record -- for this action
140 dc_rec = _DtDtsDbAddRecord(_DtDtsDbGet(DtDTS_DC_NAME));
141 dc_rec->recordName = XrmStringToQuark(fields[0].fieldValue);
142 dc_rec->seq = _DtDtsNextDCSeq();
143 dc_rec->pathId = (int)pathId;
144 fld = _DtDtsDbAddField(dc_rec);
145 fld->fieldName = XrmStringToQuark(DtDTS_NAME_PATTERN);
146 fld->fieldValue = strdup(fields[0].fieldValue);
147 fld = _DtDtsDbAddField(dc_rec);
148 fld->fieldName = XrmStringToQuark(DtDTS_MODE);
149 fld->fieldValue = strdup("fx");
150 fld = _DtDtsDbAddField(dc_rec);
151 fld->fieldName = XrmStringToQuark(DtDTS_DATA_ATTRIBUTES_NAME);
152 fld->fieldValue = strdup(fields[0].fieldValue);
154 * Mark the criteria record as synthetic.
156 fld = _DtDtsDbAddField(dc_rec);
157 fld->fieldName = XrmStringToQuark(DtDTS_DA_IS_SYNTHETIC);
158 fld->fieldValue = strdup("True");
161 * Synthesize attribute record -- for this action
163 da_rec = _DtDtsDbAddRecord(_DtDtsDbGet(DtDTS_DA_NAME));
164 da_rec->recordName = XrmStringToQuark(fields[0].fieldValue);
165 da_rec->seq = _DtDtsNextDASeq();
166 da_rec->pathId = (int)pathId;
167 fld = _DtDtsDbAddField(da_rec);
168 fld->fieldName = XrmStringToQuark(DtDTS_DA_ACTION_LIST);
169 fld->fieldValue = strdup(fields[0].fieldValue);
170 fld = _DtDtsDbAddField(da_rec);
171 fld->fieldName = XrmStringToQuark(DtDTS_DA_DATA_HOST);
172 fld->fieldValue = strdup(hostPrefix);
175 * Mark the attribute record as synthetic.
177 fld = _DtDtsDbAddField(da_rec);
178 fld->fieldName = XrmStringToQuark(DtDTS_DA_IS_SYNTHETIC);
179 fld->fieldValue = strdup("True");
181 fld = _DtDtsDbAddField(da_rec);
182 fld->fieldName = XrmStringToQuark(DtDTS_DA_IS_ACTION);
183 fld->fieldValue = strdup("True");
185 fld = _DtDtsDbAddField(da_rec);
186 fld->fieldName = XrmStringToQuark(DtDTS_DA_IS_TEXT);
187 fld->fieldValue = strdup("False");
190 * Use the action name as the default copy_to action
192 fld = _DtDtsDbAddField(da_rec);
193 fld->fieldName = XrmStringToQuark(DtDTS_DA_COPY_TO_ACTION);
194 fld->fieldValue = strdup(fields[0].fieldValue);
195 _DtSvcProcessUnlock();
199 /******************************************************************************
203 * Reads in the file types and action databases.
204 * From the Default DtDatabaseDirPaths.
206 *****************************************************************************/
208 void _DtDbLoad(DtDirPaths *dirs)
218 /* Load the requested database files */
219 dirs = _DtGetDatabaseDirPaths();
221 _DtFreeDatabaseDirPaths(dirs);
224 /******************************************************************************
228 * Reads in the file types and action databases.
229 * From the the given directory path. This function is not part of the
230 * public API but may be used internally to avoid repeated generation of
231 * the default databasedir path.
233 *****************************************************************************/
235 _DtDtsMMCreateDb(DtDirPaths *dirs, const char *CacheFile, int override)
237 DtDbRecordDesc recordDescriptions[3];
238 DtDbConverter criteriaConverters[2];
239 DtDbConverter attributesConverters[2];
240 DtDbConverter actionConverters[3];
241 static int beenCalled = 0;
247 use_in_memory_db = TRUE;
251 * Free up existing database.
261 * Initialize the databases
262 * -- this call will initializae the Object databases then
263 * add the action database.
265 (void) _DtDtsDbAddDatabase(_DtACTION_NAME);
269 myassert(dirs); /* register an assertion failure */
270 _DtSvcProcessUnlock();
274 /* Build up the record descriptions */
275 criteriaConverters[0] = (DtDbConverter) _DtDtsDCConverter;
276 criteriaConverters[1] = NULL;
277 recordDescriptions[0].recordKeyword = DtDTS_DC_NAME;
278 recordDescriptions[0].maxFields = _DtMAX_NUM_FIELDS;
279 recordDescriptions[0].converters = criteriaConverters;
281 /* Build up the ot record descriptions */
282 attributesConverters[0] = (DtDbConverter) _DtDtsDAConverter;
283 attributesConverters[1] = NULL;
284 recordDescriptions[1].recordKeyword = DtDTS_DA_NAME;
285 recordDescriptions[1].maxFields = _DtMAX_NUM_FIELDS;
286 recordDescriptions[1].converters = attributesConverters;
288 actionConverters[0] = (DtDbConverter) _DtActionConverter;
289 actionConverters[1] = (DtDbConverter) _DtOAConverter;
290 actionConverters[2] = NULL;
291 recordDescriptions[2].recordKeyword = _DtACTION_NAME;
292 recordDescriptions[2].maxFields = _ActDb_MAX_NUM_FIELDS;
293 recordDescriptions[2].converters = actionConverters;
296 _DtDbRead(dirs, ".dt", recordDescriptions, 3);
301 * we may eventually want to return a count of the new records.
302 * for now we return a non-zero value to register success.
305 if ((!_DtDtsMMCreateFile(dirs, CacheFile)) ||
306 (!_DtDtsMMapDB(CacheFile)))
308 _DtSvcProcessUnlock();
316 /* now that we have built the databases delete the tmp Db memory
317 used for it (Too, bad we can't delete the memory associcated
319 list = (char **)_DtsDbListDb();
320 for(i = 0; list[i]; i++)
322 _DtDtsDbDeleteDb(_DtDtsDbGet(list[i]));
326 use_in_memory_db = FALSE;
328 _DtSvcProcessUnlock();