Do not re-prototype strdup()
[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 librararies 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(USL) || defined(sco) || defined(__uxp__)
55 #include <dirent.h>
56 #else
57 #include <sys/dir.h>
58 #endif                          /* sun || USL */
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 #if !defined(linux)
77 extern char     *strdup(const char *);
78 #endif
79
80 static int      cur_dc_count = 0;
81 static int      cur_da_count = 0;
82 #define _DtFT_NUM_FIELDS        20
83
84 int
85 _DtDtsNextDCSeq()
86 {
87         int nextDCSeq;
88
89         _DtSvcProcessLock();
90         nextDCSeq = ++cur_dc_count;
91         _DtSvcProcessUnlock();
92
93         return(nextDCSeq);
94 }
95
96 int
97 _DtDtsNextDASeq()
98 {
99         int nextDASeq;
100
101         _DtSvcProcessLock();
102         nextDASeq = ++cur_da_count;
103         _DtSvcProcessUnlock();
104
105         return(nextDASeq);
106 }
107
108 void
109 _DtDtsSeqReset()
110 {
111         _DtSvcProcessLock();
112         cur_dc_count = 0;
113         cur_da_count = 0;
114         _DtSvcProcessUnlock();
115 }
116 void
117 _DtDtsDCConverter(DtDtsDbField * fields,
118                DtDbPathId pathId,
119                char *hostPrefix,
120                Boolean rejectionStatus)
121 {
122         DtDtsDbDatabase *db;
123         DtDtsDbRecord  *rec;
124         DtDtsDbField   *fld;
125         int             i = 0;
126
127         _DtSvcProcessLock();   
128         db = _DtDtsDbGet(DtDTS_DC_NAME);
129         while (fields[i].fieldName && fields[i].fieldValue)
130         {
131                 if (i == 0)
132                 {
133                         if(rec=_DtDtsDbGetRecordByName(db,fields[i].fieldValue))
134                         {
135                                 char *value = _DtDtsDbGetFieldByName(rec,DtDTS_DA_IS_SYNTHETIC);
136                                 /*
137                                  * Check if the record is SYNTHETIC --
138                                  * if so then replace it with this real
139                                  * definition -- otherwise return.
140                                  */
141                                 if (value && !strcmp(value,"True") )
142                                 {
143                                         /* free up the current record */
144                                         _DtDtsDbDeleteRecord(rec,db);
145                                 }
146                                 else
147                                 {
148                                         _DtSvcProcessUnlock();
149                                         return;
150                                 }
151                         }
152                         rec = _DtDtsDbAddRecord(db);
153                         rec->recordName = XrmStringToQuark(fields[i].fieldValue);
154                         rec->seq = _DtDtsNextDCSeq();
155                         rec->pathId = (int)pathId;
156                 }
157                 else
158                 {
159                         fld = _DtDtsDbAddField(rec);
160                         fld->fieldName = fields[i].fieldName;
161                         fld->fieldValue = strdup(fields[i].fieldValue);
162                 }
163                 i++;
164         }
165         _DtSvcProcessUnlock();
166 }
167
168 void
169 _DtDtsDAConverter(DtDtsDbField * fields,
170                DtDbPathId pathId,
171                char *hostPrefix,
172                Boolean rejectionStatus)
173 {
174         DtDtsDbDatabase *db;
175         DtDtsDbRecord  *rec;
176         DtDtsDbField   *fld;
177         int             i = 0;
178
179         _DtSvcProcessLock();    
180         db = _DtDtsDbGet(DtDTS_DA_NAME);
181
182         while (fields[i].fieldName && fields[i].fieldValue)
183         {
184                 if (i == 0)
185                 {
186                         if(rec = _DtDtsDbGetRecordByName(db, fields[i].fieldValue))
187                         {
188                                 char *value = _DtDtsDbGetFieldByName(rec,DtDTS_DA_IS_SYNTHETIC);
189                                 /*
190                                  * Check if the record is SYNTHETIC --
191                                  * if so then replace it with this real
192                                  * definition -- otherwise return.
193                                  */
194                                 if (value && !strcmp(value,"True") )
195                                 {
196                                         /* free up the current record */
197                                         _DtDtsDbDeleteRecord(rec,db);
198                                 }
199                                 else
200                                 {
201                                         _DtSvcProcessUnlock();
202                                         return;
203                                 }
204                         }
205                         rec = _DtDtsDbAddRecord(db);
206                         rec->recordName = XrmStringToQuark(fields[i].fieldValue);
207                         rec->seq = _DtDtsNextDASeq();
208                         fld = _DtDtsDbAddField(rec);
209                         fld->fieldName = XrmStringToQuark(DtDTS_DA_DATA_HOST);
210                         fld->fieldValue = hostPrefix?strdup(hostPrefix):(char *) 0;
211                         rec->pathId = (int)pathId;
212                 }
213                 else
214                 {
215                         fld = _DtDtsDbAddField(rec);
216                         fld->fieldName = fields[i].fieldName;
217                         fld->fieldValue = strdup(fields[i].fieldValue);
218                 }
219                 i++;
220         }
221         _DtSvcProcessUnlock();
222 }
223
224
225 /******************************************************************************
226  *
227  * DtDtsLoadDataTypes -
228  *
229  *   Reads in the file types and action databases.
230  *
231  *   Also initializes the variable DtMaxFileTypes to the number
232  *   of entries in the file types database.
233  *
234  * MODIFIED:
235  *
236  *   DtMaxFtFileTypes
237  *   DtMaxFileTypes - set to the number of real filetypes 
238  *       ( Holdovers from previous filetypes stuff -- still used by
239  *         some clients. i.e. dtfile )
240  *
241  *****************************************************************************/
242
243 void
244 DtDtsLoadDataTypes(void)
245 {
246         /* with new mmap database this function is not needed to 
247          * load the database. Just to initialize it.
248          */
249
250         _DtDtsMMUnLoad();
251 }