1 /*
2 * Motif
3 *
4 * Copyright (c) 1987-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 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27
28 #ifdef REV_INFO
29 #ifndef lint
30 static char rcsid[] = "$XConsortium: MrmItopw.c /main/13 1996/11/13 13:59:22 drk $"
31 #endif
32 #endif
33
34
35 /*
36 *++
37 * FACILITY:
38 *
39 * UIL Resource Manager (URM): IDB facility
40 *
41 * ABSTRACT:
42 *
43 * This module contains the publicly accessible top-level
44 * IDB write routines.
45 *
46 *--
47 */
48
49
50 /*
51 *
52 * INCLUDE FILES
53 *
54 */
55
56 #include <Mrm/MrmAppl.h>
57 #include <Mrm/Mrm.h>
58 #include <Mrm/IDB.h>
59
60
61 /*
62 *
63 * TABLE OF CONTENTS
64 *
65 * UrmIdbOpenFileWrite Open a file for write access
66 *
67 * UrmIdbPutIndexedResource Put indexed resource to file
68 *
69 * UrmIdbPutRIDResource Put resource id'ed resource in file
70 *
71 */
72
73 /*
74 *++
75 *
76 * PROCEDURE DESCRIPTION:
77 *
78 * IdbOpenFileWrite creates a new IDB database file, with null index
79 * structures. This call creates the file and initializes the file
80 * header.
81 *
82 * FORMAL PARAMETERS:
83 *
84 * name A system-dependent string specifying the IDB
85 * file to be opened.
86 * os_ext An operating-system specific structure which
87 * supports using specific file system features
88 * creator Identifies the database creator (application)
89 * creator_version Creator version
90 * module Identifies the UIL module
91 * module_version Module version
92 * file_id_return returns the IDB file id
93 * fname_return returns the name of the file actually opened
94 * (via strcpy). Should be at least 256 chars.
95 *
96 * IMPLICIT INPUTS:
97 *
98 * IMPLICIT OUTPUTS:
99 *
100 * FUNCTION VALUE:
101 *
102 * MrmSUCCESS operation succeeded
103 * MrmFAILURE operation failed, no further reason
104 *
105 * SIDE EFFECTS:
106 *
107 * 1. Acquires memory for the file descriptor
108 *
109 *--
110 */
111
112 Cardinal
113 UrmIdbOpenFileWrite (String name ,
114 MrmOsOpenParamPtr os_ext ,
115 String creator ,
116 String creator_version ,
117 String module ,
118 String module_version ,
119 IDBFile *file_id_return ,
120 char *fname_return )
121 {
122
123 /*
124 * Local variables
125 */
126 Cardinal result ; /* function results */
127 IDBLowLevelFilePtr fileid ; /* low-level id for file */
128 IDBFile filedesc ; /* new file descriptor */
129 int ndx ; /* loop index */
130
131 /*
132 * An OS extension block must be present for Unix, and by default
133 * specifies that existing files are over-written.
134 */
135 MrmOsOpenParam osext ; /* to delete file on open */
136
137 osext.version = MrmOsOpenParamVersion ;
138 osext.nam_flg.clobber_flg = TRUE ;
139 if ( os_ext == NULL ) os_ext = &osext ;
140
141
142 /*
143 * Attempt to open the file. For now, pay no attention to temporary naming
144 * issues.
145 */
146 result =
147 Idb__FU_OpenFile(name, URMWriteAccess, os_ext, &fileid, fname_return);
148 if ( result != MrmCREATE_NEW ) return result ;
149
150 /*
151 * File successfully opened. Acquire a file descriptor and initialize it.
152 */
153 filedesc = (IDBFile) XtMalloc (sizeof(IDBOpenFile)) ;
154 filedesc->validation = IDBOpenFileValid ;
155 filedesc->access = URMWriteAccess ;
156 filedesc->lowlevel_id = fileid ;
157 filedesc->last_record = 0 ;
158 filedesc->last_data_record = 0 ;
159 filedesc->get_count = 0 ;
160 filedesc->put_count = 0 ;
161 filedesc->byte_swapped = FALSE ;
162 filedesc->in_memory = FALSE ;
163 filedesc->uid_buffer = NULL ;
164 for ( ndx=IDBrtMin ; ndx<=IDBrtMax ; ndx++ )
165 filedesc->rt_counts[ndx] = 0 ;
166
167 /*
168 * Make sure all variables are initialized that aren't initialized elsewhere
169 */
170 filedesc->index_root = 0;
171 filedesc->timer = 0;
172 filedesc->class_ctable = (UidCompressionTablePtr)NULL;
173 filedesc->resource_ctable = (UidCompressionTablePtr)NULL;
174 filedesc->user1 = 0;
175 filedesc->user2 = 0;
176
177 for ( ndx=0 ; ndx<=IDBhsVersion ; ndx++ )
178 {
179 filedesc->db_version[ndx] = 0 ;
180 filedesc->creator_version[ndx] = 0 ;
181 filedesc->module_version[ndx] = 0 ;
182 };
183 for ( ndx=0 ; ndx<=IDBhsCreator ; ndx++ )
184 filedesc->creator[ndx] = 0 ;
185 for ( ndx=0 ; ndx<=IDBhsDate ; ndx++ )
186 filedesc->creation_date[ndx] = 0 ;
187 for ( ndx=0 ; ndx<=IDBhsModule ; ndx++ )
188 filedesc->module[ndx] = 0 ;
189
190 /*
191 * Write a new file header for this file
192 */
193 result = Idb__HDR_InitHeader (filedesc, creator, creator_version,
194 module, module_version) ;
195 if ( result != MrmSUCCESS )
196 {
197 UrmIdbCloseFile (filedesc, TRUE) ;
198 return result ;
199 }
200
201 /*
202 * File successfully opened
203 */
204 *file_id_return = filedesc ;
205 return MrmSUCCESS ;
206
207 }
208
209
210
211 /*
212 *++
213 *
214 * PROCEDURE DESCRIPTION:
215 *
216 * IdbPutIndexedResource creates a resource record holding the
217 * group, type, and resource data in the resource context, and saves it
218 * under the given index. The group and type must not be null, and the
219 * index must not be currently entered in the database index. The
220 * resource record is marked public or private depending on the value
221 * of the access parameter.
222 *
223 * FORMAL PARAMETERS:
224 *
225 * file_id The IDB file id returned by IdbOpenFile
226 * index case-sensitive index for the new entry, must
227 * not match any existing entry
228 * context_id URM resource context containing data block
229 * for entry
230 *
231 * IMPLICIT INPUTS:
232 *
233 * IMPLICIT OUTPUTS:
234 *
235 * FUNCTION VALUE:
236 *
237 * MrmSUCCESS operation succeeded
238 * MrmEXISTS operation failed, index already exists
239 * MrmNUL_GROUP operation failed, null group parameter
240 * MrmNUL_TYPE operation failed, null type parameter
241 * MrmFAILURE operation failed, no further reason
242 *
243 * SIDE EFFECTS:
244 *
245 *--
246 */
247
248 Cardinal
UrmIdbPutIndexedResource(IDBFile file_id,String index,URMResourceContextPtr context_id)249 UrmIdbPutIndexedResource (IDBFile file_id,
250 String index,
251 URMResourceContextPtr context_id)
252
253 {
254 /*
255 * Local variables
256 */
257 Cardinal result ; /* function results */
258 IDBRecordBufferPtr bufptr ; /* not used */
259 MrmCount recno ; /* not used */
260 IDBDataHandle data_entry ; /* return new data entry */
261 MrmCode group ; /* the entry's group code */
262
263
264 if ( (result=Idb__FIL_Valid(file_id)) != MrmSUCCESS ) return result ;
265
266 /*
267 * Validity check on group and type, and make sure entry doesn't
268 * currently exist.
269 */
270 if ( UrmRCGroup(context_id) == URMgNul ) return MrmNUL_GROUP ;
271 if ( UrmRCType(context_id) == URMtNul) return MrmNUL_TYPE ;
272 result = Idb__INX_FindIndex (file_id, index, &bufptr, &recno) ;
273 if ( result == MrmSUCCESS) return MrmEXISTS ;
274
275 /*
276 * Create the data entry for this item
277 */
278 result = Idb__DB_PutDataEntry (file_id, context_id, &data_entry) ;
279 if ( result != MrmSUCCESS ) return result ;
280
281 /*
282 * Enter the data entry under the index
283 */
284 result = Idb__INX_EnterItem (file_id, index, data_entry) ;
285 if ( result != MrmSUCCESS ) return result ;
286 file_id->num_indexed++ ;
287
288 group = UrmRCGroup (context_id) ;
289 if ( group>=URMgMin && group<=URMgMax )
290 file_id->group_counts[group]++ ;
291
292 /*
293 * item successfully entered
294 */
295 return MrmSUCCESS ;
296
297 }
298
299
300
301 /*
302 *++
303 *
304 * PROCEDURE DESCRIPTION:
305 *
306 * IdbPutRIDResource creates a resource record holding the group, type,
307 * and resource data, and saves under the given resource id. The group
308 * and type must not be null, and the resource must currently have no
309 * resource record associated with it. Access is always URMaPrivate
310 * regardless of the data context access field.
311 *
312 * FORMAL PARAMETERS:
313 *
314 * file_id The IDB file id returned by IdbOpenFile
315 * resource_id resource id for the new entry, should
316 * currently have no existing resource record
317 * context_id URM resource context holding data block.
318 *
319 * IMPLICIT INPUTS:
320 *
321 * IMPLICIT OUTPUTS:
322 *
323 * FUNCTION VALUE:
324 *
325 * MrmSUCCESS operation succeeded
326 * MrmEXISTS operation failed, index already exists
327 * MrmNUL_GROUP operation failed, null group parameter
328 * MrmNUL_TYPE operation failed, null type parameter
329 * MrmFAILURE operation failed, no further reason
330 *
331 * SIDE EFFECTS:
332 *
333 *--
334 */
335
336 Cardinal
UrmIdbPutRIDResource(IDBFile file_id,MrmResource_id resource_id,URMResourceContextPtr context_id)337 UrmIdbPutRIDResource (IDBFile file_id ,
338 MrmResource_id resource_id ,
339 URMResourceContextPtr context_id )
340 {
341 /*
342 * Local variables
343 */
344 Cardinal result ; /* function results */
345 IDBDataHandle data_entry ; /* new data entry */
346 MrmCode group ; /* the entry's group code */
347
348
349 if ( (result=Idb__FIL_Valid(file_id)) != MrmSUCCESS ) return result ;
350
351 /*
352 * Validity check on group and type, and make sure entry doesn't
353 * currently exist.
354 */
355 if ( UrmRCGroup(context_id) == URMgNul ) return MrmNUL_GROUP ;
356 if ( UrmRCType(context_id) == URMtNul) return MrmNUL_TYPE ;
357 result = Idb__RID_ReturnItem (file_id, resource_id, FALSE, &data_entry) ;
358 if ( result == MrmSUCCESS) return MrmEXISTS ;
359
360 /*
361 * Create the data entry for this item
362 */
363 result = Idb__DB_PutDataEntry (file_id, context_id, &data_entry) ;
364 if ( result != MrmSUCCESS ) return result ;
365
366 /*
367 * Enter the data entry under the resource id
368 */
369 result = Idb__RID_EnterItem (file_id, resource_id, data_entry) ;
370 if ( result != MrmSUCCESS ) return result ;
371 file_id->num_RID++ ;
372
373 group = UrmRCGroup (context_id) ;
374 if ( group>=URMgMin && group<=URMgMax )
375 file_id->group_counts[group]++ ;
376
377 /*
378 * item successfully entered
379 */
380 return MrmSUCCESS ;
381
382 }
383
384
385