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>
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);
107 char **_DtsDbListDb(void);
109 int use_in_memory_db = False;
112 _DtOAConverter(DtDtsDbField * fields,
115 Boolean rejectionStatus)
117 DtDtsDbDatabase *dc_db;
118 DtDtsDbDatabase *da_db;
119 DtDtsDbRecord *dc_rec;
120 DtDtsDbRecord *da_rec;
124 dc_db = _DtDtsDbGet(DtDTS_DC_NAME);
125 da_db = _DtDtsDbGet(DtDTS_DA_NAME);
126 if ( _DtDtsDbGetRecordByName(dc_db,
127 fields[0].fieldValue) ||
128 _DtDtsDbGetRecordByName(da_db,
129 fields[0].fieldValue))
131 _DtSvcProcessUnlock();
136 * Synthesize criteria record -- for this action
138 dc_rec = _DtDtsDbAddRecord(_DtDtsDbGet(DtDTS_DC_NAME));
139 dc_rec->recordName = XrmStringToQuark(fields[0].fieldValue);
140 dc_rec->seq = _DtDtsNextDCSeq();
141 dc_rec->pathId = (int)pathId;
142 fld = _DtDtsDbAddField(dc_rec);
143 fld->fieldName = XrmStringToQuark(DtDTS_NAME_PATTERN);
144 fld->fieldValue = strdup(fields[0].fieldValue);
145 fld = _DtDtsDbAddField(dc_rec);
146 fld->fieldName = XrmStringToQuark(DtDTS_MODE);
147 fld->fieldValue = strdup("fx");
148 fld = _DtDtsDbAddField(dc_rec);
149 fld->fieldName = XrmStringToQuark(DtDTS_DATA_ATTRIBUTES_NAME);
150 fld->fieldValue = strdup(fields[0].fieldValue);
152 * Mark the criteria record as synthetic.
154 fld = _DtDtsDbAddField(dc_rec);
155 fld->fieldName = XrmStringToQuark(DtDTS_DA_IS_SYNTHETIC);
156 fld->fieldValue = strdup("True");
159 * Synthesize attribute record -- for this action
161 da_rec = _DtDtsDbAddRecord(_DtDtsDbGet(DtDTS_DA_NAME));
162 da_rec->recordName = XrmStringToQuark(fields[0].fieldValue);
163 da_rec->seq = _DtDtsNextDASeq();
164 da_rec->pathId = (int)pathId;
165 fld = _DtDtsDbAddField(da_rec);
166 fld->fieldName = XrmStringToQuark(DtDTS_DA_ACTION_LIST);
167 fld->fieldValue = strdup(fields[0].fieldValue);
168 fld = _DtDtsDbAddField(da_rec);
169 fld->fieldName = XrmStringToQuark(DtDTS_DA_DATA_HOST);
170 fld->fieldValue = strdup(hostPrefix);
173 * Mark the attribute record as synthetic.
175 fld = _DtDtsDbAddField(da_rec);
176 fld->fieldName = XrmStringToQuark(DtDTS_DA_IS_SYNTHETIC);
177 fld->fieldValue = strdup("True");
179 fld = _DtDtsDbAddField(da_rec);
180 fld->fieldName = XrmStringToQuark(DtDTS_DA_IS_ACTION);
181 fld->fieldValue = strdup("True");
183 fld = _DtDtsDbAddField(da_rec);
184 fld->fieldName = XrmStringToQuark(DtDTS_DA_IS_TEXT);
185 fld->fieldValue = strdup("False");
188 * Use the action name as the default copy_to action
190 fld = _DtDtsDbAddField(da_rec);
191 fld->fieldName = XrmStringToQuark(DtDTS_DA_COPY_TO_ACTION);
192 fld->fieldValue = strdup(fields[0].fieldValue);
193 _DtSvcProcessUnlock();
197 /******************************************************************************
201 * Reads in the file types and action databases.
202 * From the Default DtDatabaseDirPaths.
204 *****************************************************************************/
206 void _DtDbLoad(DtDirPaths *dirs)
216 /* Load the requested database files */
217 dirs = _DtGetDatabaseDirPaths();
219 _DtFreeDatabaseDirPaths(dirs);
222 /******************************************************************************
226 * Reads in the file types and action databases.
227 * From the the given directory path. This function is not part of the
228 * public API but may be used internally to avoid repeated generation of
229 * the default databasedir path.
231 *****************************************************************************/
233 _DtDtsMMCreateDb(DtDirPaths *dirs, const char *CacheFile, int override)
235 DtDbRecordDesc recordDescriptions[3];
236 DtDbConverter criteriaConverters[2];
237 DtDbConverter attributesConverters[2];
238 DtDbConverter actionConverters[3];
239 static int beenCalled = 0;
245 use_in_memory_db = TRUE;
249 * Free up existing database.
259 * Initialize the databases
260 * -- this call will initializae the Object databases then
261 * add the action database.
263 (void) _DtDtsDbAddDatabase(_DtACTION_NAME);
267 myassert(dirs); /* register an assertion failure */
268 _DtSvcProcessUnlock();
272 /* Build up the record descriptions */
273 criteriaConverters[0] = (DtDbConverter) _DtDtsDCConverter;
274 criteriaConverters[1] = NULL;
275 recordDescriptions[0].recordKeyword = DtDTS_DC_NAME;
276 recordDescriptions[0].maxFields = _DtMAX_NUM_FIELDS;
277 recordDescriptions[0].converters = criteriaConverters;
279 /* Build up the ot record descriptions */
280 attributesConverters[0] = (DtDbConverter) _DtDtsDAConverter;
281 attributesConverters[1] = NULL;
282 recordDescriptions[1].recordKeyword = DtDTS_DA_NAME;
283 recordDescriptions[1].maxFields = _DtMAX_NUM_FIELDS;
284 recordDescriptions[1].converters = attributesConverters;
286 actionConverters[0] = (DtDbConverter) _DtActionConverter;
287 actionConverters[1] = (DtDbConverter) _DtOAConverter;
288 actionConverters[2] = NULL;
289 recordDescriptions[2].recordKeyword = _DtACTION_NAME;
290 recordDescriptions[2].maxFields = _ActDb_MAX_NUM_FIELDS;
291 recordDescriptions[2].converters = actionConverters;
294 _DtDbRead(dirs, ".dt", recordDescriptions, 3);
299 * we may eventually want to return a count of the new records.
300 * for now we return a non-zero value to register success.
303 if ((!_DtDtsMMCreateFile(dirs, CacheFile)) ||
304 (!_DtDtsMMapDB(CacheFile)))
306 _DtSvcProcessUnlock();
314 /* now that we have built the databases delete the tmp Db memory
315 used for it (Too, bad we can't delete the memory associcated
317 list = (char **)_DtsDbListDb();
318 for(i = 0; list[i]; i++)
320 _DtDtsDbDeleteDb(_DtDtsDbGet(list[i]));
324 use_in_memory_db = FALSE;
326 _DtSvcProcessUnlock();