DtSvc/DtUtil1: fix implicit function declarations
[oweals/cde.git] / cde / lib / DtSvc / DtUtil1 / DtsInit.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /*
24  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
25  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
26  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
27  * (c) Copyright 1993, 1994 Novell, Inc.                                *
28  */
29 /*
30  * +SNOTICE
31  * 
32  * $XConsortium: DtsInit.c /main/5 1996/08/28 16:08:50 rswiston $
33  * 
34  * RESTRICTED CONFIDENTIAL INFORMATION:
35  * 
36  * The information in this document is subject to special restrictions in a
37  * confidential disclosure agreement bertween HP, IBM, Sun, USL, SCO and
38  * Univel.  Do not distribute this document outside HP, IBM, Sun, USL, SCO,
39  * or Univel wihtout Sun's specific written approval.  This documment and all
40  * copies and derivative works thereof must be returned or destroyed at Sun's
41  * request.
42  * 
43  * Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
44  * 
45  * +ENOTICE
46  */
47 #include <stdio.h>
48 #include <sys/types.h>
49
50 #ifdef __hpux
51 #include <ndir.h>
52 #else
53
54 #if defined(sun) || defined(CSRG_BASED)
55 #include <dirent.h>
56 #else
57 #include <sys/dir.h>
58 #endif                          /* sun || CSRG_BASED */
59
60 #endif                          /* __hpux */
61
62 #include <ctype.h>
63 #include <string.h>
64
65 #ifdef NLS16
66 #include <limits.h>
67 #endif
68
69 #include <sys/stat.h>
70 #include <sys/param.h>          /* MAXPATHLEN, MAXHOSTNAMELEN */
71 #include <Dt/DbReader.h>
72 #include <Dt/DtsDb.h>
73 #include <Dt/Dts.h>
74 #include "DtSvcLock.h"
75
76 extern int _DtDtsMMUnLoad(void);
77
78 static int      cur_dc_count = 0;
79 static int      cur_da_count = 0;
80 #define _DtFT_NUM_FIELDS        20
81
82 int
83 _DtDtsNextDCSeq(void)
84 {
85         int nextDCSeq;
86
87         _DtSvcProcessLock();
88         nextDCSeq = ++cur_dc_count;
89         _DtSvcProcessUnlock();
90
91         return(nextDCSeq);
92 }
93
94 int
95 _DtDtsNextDASeq(void)
96 {
97         int nextDASeq;
98
99         _DtSvcProcessLock();
100         nextDASeq = ++cur_da_count;
101         _DtSvcProcessUnlock();
102
103         return(nextDASeq);
104 }
105
106 void
107 _DtDtsSeqReset(void)
108 {
109         _DtSvcProcessLock();
110         cur_dc_count = 0;
111         cur_da_count = 0;
112         _DtSvcProcessUnlock();
113 }
114 void
115 _DtDtsDCConverter(DtDtsDbField * fields,
116                DtDbPathId pathId,
117                char *hostPrefix,
118                Boolean rejectionStatus)
119 {
120         DtDtsDbDatabase *db;
121         DtDtsDbRecord  *rec;
122         DtDtsDbField   *fld;
123         int             i = 0;
124
125         _DtSvcProcessLock();   
126         db = _DtDtsDbGet(DtDTS_DC_NAME);
127         while (fields[i].fieldName && fields[i].fieldValue)
128         {
129                 if (i == 0)
130                 {
131                         if(rec=_DtDtsDbGetRecordByName(db,fields[i].fieldValue))
132                         {
133                                 char *value = _DtDtsDbGetFieldByName(rec,DtDTS_DA_IS_SYNTHETIC);
134                                 /*
135                                  * Check if the record is SYNTHETIC --
136                                  * if so then replace it with this real
137                                  * definition -- otherwise return.
138                                  */
139                                 if (value && !strcmp(value,"True") )
140                                 {
141                                         /* free up the current record */
142                                         _DtDtsDbDeleteRecord(rec,db);
143                                 }
144                                 else
145                                 {
146                                         _DtSvcProcessUnlock();
147                                         return;
148                                 }
149                         }
150                         rec = _DtDtsDbAddRecord(db);
151                         rec->recordName = XrmStringToQuark(fields[i].fieldValue);
152                         rec->seq = _DtDtsNextDCSeq();
153                         rec->pathId = (int)pathId;
154                 }
155                 else
156                 {
157                         fld = _DtDtsDbAddField(rec);
158                         fld->fieldName = fields[i].fieldName;
159                         fld->fieldValue = strdup(fields[i].fieldValue);
160                 }
161                 i++;
162         }
163         _DtSvcProcessUnlock();
164 }
165
166 void
167 _DtDtsDAConverter(DtDtsDbField * fields,
168                DtDbPathId pathId,
169                char *hostPrefix,
170                Boolean rejectionStatus)
171 {
172         DtDtsDbDatabase *db;
173         DtDtsDbRecord  *rec;
174         DtDtsDbField   *fld;
175         int             i = 0;
176
177         _DtSvcProcessLock();    
178         db = _DtDtsDbGet(DtDTS_DA_NAME);
179
180         while (fields[i].fieldName && fields[i].fieldValue)
181         {
182                 if (i == 0)
183                 {
184                         if(rec = _DtDtsDbGetRecordByName(db, fields[i].fieldValue))
185                         {
186                                 char *value = _DtDtsDbGetFieldByName(rec,DtDTS_DA_IS_SYNTHETIC);
187                                 /*
188                                  * Check if the record is SYNTHETIC --
189                                  * if so then replace it with this real
190                                  * definition -- otherwise return.
191                                  */
192                                 if (value && !strcmp(value,"True") )
193                                 {
194                                         /* free up the current record */
195                                         _DtDtsDbDeleteRecord(rec,db);
196                                 }
197                                 else
198                                 {
199                                         _DtSvcProcessUnlock();
200                                         return;
201                                 }
202                         }
203                         rec = _DtDtsDbAddRecord(db);
204                         rec->recordName = XrmStringToQuark(fields[i].fieldValue);
205                         rec->seq = _DtDtsNextDASeq();
206                         fld = _DtDtsDbAddField(rec);
207                         fld->fieldName = XrmStringToQuark(DtDTS_DA_DATA_HOST);
208                         fld->fieldValue = hostPrefix?strdup(hostPrefix):(char *) 0;
209                         rec->pathId = (int)pathId;
210                 }
211                 else
212                 {
213                         fld = _DtDtsDbAddField(rec);
214                         fld->fieldName = fields[i].fieldName;
215                         fld->fieldValue = strdup(fields[i].fieldValue);
216                 }
217                 i++;
218         }
219         _DtSvcProcessUnlock();
220 }
221
222
223 /******************************************************************************
224  *
225  * DtDtsLoadDataTypes -
226  *
227  *   Reads in the file types and action databases.
228  *
229  *   Also initializes the variable DtMaxFileTypes to the number
230  *   of entries in the file types database.
231  *
232  * MODIFIED:
233  *
234  *   DtMaxFtFileTypes
235  *   DtMaxFileTypes - set to the number of real filetypes 
236  *       ( Holdovers from previous filetypes stuff -- still used by
237  *         some clients. i.e. dtfile )
238  *
239  *****************************************************************************/
240
241 void
242 DtDtsLoadDataTypes(void)
243 {
244         /* with new mmap database this function is not needed to 
245          * load the database. Just to initialize it.
246          */
247
248         _DtDtsMMUnLoad();
249 }