Blame lib/Mrm/MrmItop.c

Packit b099d7
/* 
Packit b099d7
 * Motif
Packit b099d7
 *
Packit b099d7
 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are free software; you can
Packit b099d7
 * redistribute them and/or modify them under the terms of the GNU
Packit b099d7
 * Lesser General Public License as published by the Free Software
Packit b099d7
 * Foundation; either version 2 of the License, or (at your option)
Packit b099d7
 * any later version.
Packit b099d7
 *
Packit b099d7
 * These libraries and programs are distributed in the hope that
Packit b099d7
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
Packit b099d7
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
Packit b099d7
 * PURPOSE. See the GNU Lesser General Public License for more
Packit b099d7
 * details.
Packit b099d7
 *
Packit b099d7
 * You should have received a copy of the GNU Lesser General Public
Packit b099d7
 * License along with these librararies and programs; if not, write
Packit b099d7
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
Packit b099d7
 * Floor, Boston, MA 02110-1301 USA
Packit b099d7
 */ 
Packit b099d7
/* 
Packit b099d7
 * HISTORY
Packit b099d7
 */ 
Packit b099d7
#ifdef HAVE_CONFIG_H
Packit b099d7
#include <config.h>
Packit b099d7
#endif
Packit b099d7
Packit b099d7
Packit b099d7
#ifdef REV_INFO
Packit b099d7
#ifndef lint
Packit b099d7
static char rcsid[] = "$XConsortium: MrmItop.c /main/15 1996/11/13 13:58:55 drk $"
Packit b099d7
#endif
Packit b099d7
#endif
Packit b099d7
Packit b099d7
/* (c) Copyright 1989, 1990, DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASS. */
Packit b099d7
Packit b099d7
Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *  FACILITY:
Packit b099d7
 *
Packit b099d7
 *      UIL Resource Manager (URM): IDB facility
Packit b099d7
 *
Packit b099d7
 *  ABSTRACT:
Packit b099d7
 *
Packit b099d7
 *      This module contains the publicly accessible top-level
Packit b099d7
 *	IDB read & common (to read and write operations) routines.
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
Packit b099d7
/*
Packit b099d7
 *
Packit b099d7
 *  INCLUDE FILES
Packit b099d7
 *
Packit b099d7
 */
Packit b099d7
Packit b099d7
#include <Mrm/MrmAppl.h>
Packit b099d7
#include <Mrm/Mrm.h>
Packit b099d7
#include <Mrm/IDB.h>
Packit b099d7
Packit b099d7
Packit b099d7
/*
Packit b099d7
 *
Packit b099d7
 *  TABLE OF CONTENTS
Packit b099d7
 *
Packit b099d7
 *	UrmIdbOpenFileRead		Open a file for read access
Packit b099d7
 *
Packit b099d7
 *	UrmIdbOpenBuffer		Open a file contained in a buffer
Packit b099d7
 *
Packit b099d7
 *	UrmIdbCloseFile			Close an open file
Packit b099d7
 *
Packit b099d7
 *	UrmIdbGetIndexedResource	Get indexed resource from file
Packit b099d7
 *
Packit b099d7
 *	UrmIdbFindIndexedResource	Find indexed resource(s) in file
Packit b099d7
 *
Packit b099d7
 *	UrmIdbGetRIDResource		Get resource id'ed resource from file
Packit b099d7
 *
Packit b099d7
 *	UrmIdbGetResourceId		Get next resource id in file
Packit b099d7
 *
Packit b099d7
 *	Idb__FIL_Valid			Validate file id
Packit b099d7
 */
Packit b099d7
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  PROCEDURE DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	IdbOpenFile opens the requested IDB database file, and returns a
Packit b099d7
 *	handle or id which is used in all subsequent IDB operations.
Packit b099d7
 *	IdbOpenFile initializes the file's index structures and sets up
Packit b099d7
 *	any buffers it needs. The database file is opened for read access only.
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	name		A system-dependent string specifying the IDB file
Packit b099d7
 *			to be opened.
Packit b099d7
 *	os_ext		An operating-system specific structure which
Packit b099d7
 *			supports using specific file system features
Packit b099d7
 *	file_id_return	returns the IDB file id used in all other IDB routines
Packit b099d7
 *	fname_return	returns the name of the file actually opened
Packit b099d7
 *			(via strcpy). Should be at least 256 chars.
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *	MrmSUCCESS	operation succeeded
Packit b099d7
 *	MrmNOT_FOUND	existing file not found
Packit b099d7
 *	MrmFAILURE	operation failed, no further reason
Packit b099d7
 *
Packit b099d7
 *  SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *      1. Acquires memory for the file descriptor.
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
Cardinal 
Packit b099d7
UrmIdbOpenFileRead (String			name,
Packit b099d7
		    MrmOsOpenParamPtr		os_ext,
Packit b099d7
		    IDBFile			*file_id_return,
Packit b099d7
		    char			*fname_return)
Packit b099d7
{
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   *  Local variables
Packit b099d7
   */
Packit b099d7
  Cardinal		result ;	/* function results */
Packit b099d7
  IDBLowLevelFilePtr	fileid ;	/* low-level id for file */
Packit b099d7
  IDBFile		filedesc ;	/* new file descriptor */
Packit b099d7
  int			ndx ;		/* loop index */
Packit b099d7
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Attempt to open the file.
Packit b099d7
   */
Packit b099d7
  result = Idb__FU_OpenFile
Packit b099d7
    (name, URMReadAccess, os_ext,  &fileid, fname_return) ;
Packit b099d7
  if ( result != MrmSUCCESS ) return result ;
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * File successfully opened. Acquire a file descriptor and initialize it.
Packit b099d7
   */
Packit b099d7
  filedesc = (IDBFile) XtMalloc (sizeof(IDBOpenFile)) ;
Packit b099d7
  if ( filedesc == NULL )
Packit b099d7
    {
Packit b099d7
      Idb__FU_CloseFile (fileid, FALSE);
Packit b099d7
      return MrmFAILURE ;
Packit b099d7
    }
Packit b099d7
Packit b099d7
  filedesc->validation = IDBOpenFileValid ;
Packit b099d7
  filedesc->access = URMReadAccess ;
Packit b099d7
  filedesc->lowlevel_id = fileid ;
Packit b099d7
  filedesc->last_record = 0 ;
Packit b099d7
  filedesc->last_data_record = 0 ;
Packit b099d7
  filedesc->get_count = 0 ;
Packit b099d7
  filedesc->put_count = 0 ;
Packit b099d7
  filedesc->class_ctable = NULL;
Packit b099d7
  filedesc->resource_ctable = NULL;
Packit b099d7
  filedesc->byte_swapped = FALSE ;
Packit b099d7
  filedesc->in_memory = FALSE ;
Packit b099d7
  filedesc->uid_buffer = NULL ;
Packit b099d7
  for ( ndx=IDBrtMin ; ndx<=IDBrtMax ; ndx++ )
Packit b099d7
    filedesc->rt_counts[ndx] = 0 ;
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Read the file header record info into the file descriptor
Packit b099d7
   */
Packit b099d7
  result = Idb__HDR_GetHeader (filedesc) ;
Packit b099d7
  if ( result != MrmSUCCESS )
Packit b099d7
    {
Packit b099d7
      UrmIdbCloseFile (filedesc, TRUE) ;
Packit b099d7
      return result ;
Packit b099d7
    }
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * File successfully opened
Packit b099d7
   */
Packit b099d7
  *file_id_return = filedesc ;
Packit b099d7
  return MrmSUCCESS ;
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  PROCEDURE DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *     	This is a simplified version of UrmIdbOpenFile which opens
Packit b099d7
 * 	a buffer contained in memory.  
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	uid_buffer	the buffer containing the uid file
Packit b099d7
 *	file_id_return	returns the IDB file id used in all other IDB routines
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *	MrmSUCCESS	operation succeeded
Packit b099d7
 *	MrmNOT_FOUND	existing file not found
Packit b099d7
 *	MrmFAILURE	operation failed, no further reason
Packit b099d7
 *
Packit b099d7
 *  SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *      1. Acquires memory for the file descriptor.
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
Cardinal 
Packit b099d7
UrmIdbOpenBuffer (unsigned char 		*uid_buffer,
Packit b099d7
		  IDBFile			*file_id_return)
Packit b099d7
{
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   *  Local variables
Packit b099d7
   */
Packit b099d7
  Cardinal		result ;	/* function results */
Packit b099d7
  IDBFile		filedesc ;	/* new file descriptor */
Packit b099d7
  int			ndx ;		/* loop index */
Packit b099d7
Packit b099d7
Packit b099d7
  filedesc = (IDBFile) XtMalloc (sizeof(IDBOpenFile)) ;
Packit b099d7
  if ( filedesc == NULL ) return MrmFAILURE ;
Packit b099d7
Packit b099d7
  filedesc->validation = IDBOpenFileValid ;
Packit b099d7
  filedesc->access = URMReadAccess ;
Packit b099d7
  filedesc->lowlevel_id = NULL ;
Packit b099d7
  filedesc->last_record = 0 ;
Packit b099d7
  filedesc->last_data_record = 0 ;
Packit b099d7
  filedesc->get_count = 0 ;
Packit b099d7
  filedesc->put_count = 0 ;
Packit b099d7
  filedesc->class_ctable = NULL;
Packit b099d7
  filedesc->resource_ctable = NULL;
Packit b099d7
  filedesc->byte_swapped = FALSE ;
Packit b099d7
  filedesc->in_memory = TRUE ;
Packit b099d7
  filedesc->uid_buffer = uid_buffer ;
Packit b099d7
  for ( ndx=IDBrtMin ; ndx<=IDBrtMax ; ndx++ )
Packit b099d7
    filedesc->rt_counts[ndx] = 0 ;
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Read the file header record info into the file descriptor
Packit b099d7
   */
Packit b099d7
  result = Idb__HDR_GetHeader (filedesc) ;
Packit b099d7
  if ( result != MrmSUCCESS ) return result ;
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Buffer ready
Packit b099d7
   */
Packit b099d7
  *file_id_return = filedesc ;
Packit b099d7
  return MrmSUCCESS ;
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  PROCEDURE DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	If the file was opened for read access, then UrmIdbCloseFile simply
Packit b099d7
 *	closes it. If it was opened for write acccess, then UrmIdbCloseFile
Packit b099d7
 *	uses keep_new_file to determine its behavior. If keep_new_file is
Packit b099d7
 *	true, then the file's index structures are updated, the file is
Packit b099d7
 *	closed, and it becomes the newest version of the database file.
Packit b099d7
 *	If keep_new_file is false, then the working copy of the file is closed
Packit b099d7
 *	and deleted, retaining the previous version of the file as the latest
Packit b099d7
 *	version. In all cases, UrmIdbCloseFile frees all memory structures
Packit b099d7
 *	associated with the file.
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	file_id			The IDB file id returned by IdbOpenFile
Packit b099d7
 *	keep_new_file		true if database is to be permanently updated;
Packit b099d7
 *				false to quit without changing the database
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *	MrmSUCCESS	operation succeeded
Packit b099d7
 *	MrmFAILURE	operation failed
Packit b099d7
 *
Packit b099d7
 *  SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
/*ARGSUSED*/
Packit b099d7
Cardinal 
Packit b099d7
UrmIdbCloseFile (IDBFile		file_id,
Packit b099d7
		 Boolean		keep_new_file)	  /* unused */
Packit b099d7
{
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   *  Local variables
Packit b099d7
   */
Packit b099d7
  Cardinal	result ;		/* function results */
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Local macros
Packit b099d7
   */
Packit b099d7
#define	_error_close()					\
Packit b099d7
  {							\
Packit b099d7
    Idb__FU_CloseFile(file_id->lowlevel_id,TRUE) ;	\
Packit b099d7
    file_id->validation = 0 ;				\
Packit b099d7
    XtFree((char*)file_id) ;				\
Packit b099d7
    return MrmFAILURE ;					\
Packit b099d7
  }
Packit b099d7
Packit b099d7
  if ( (result=Idb__FIL_Valid(file_id)) != MrmSUCCESS ) return result ;
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * We are serious about closing this file so deallocate the class and resource
Packit b099d7
   * tables before we do anything else.
Packit b099d7
   */
Packit b099d7
Packit b099d7
  if (file_id->class_ctable != NULL)
Packit b099d7
    XtFree ((char*)file_id->class_ctable);
Packit b099d7
  if (file_id->resource_ctable != NULL)
Packit b099d7
    XtFree ((char*)file_id->resource_ctable);
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * If the file was opened for write, update its header
Packit b099d7
   */
Packit b099d7
  if ( file_id->access == URMWriteAccess )
Packit b099d7
    {
Packit b099d7
      result = Idb__HDR_PutHeader ( file_id ) ;
Packit b099d7
      if ( result != MrmSUCCESS ) _error_close () ;
Packit b099d7
    }
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Decommit the file's buffers
Packit b099d7
   */
Packit b099d7
  result = Idb__BM_DecommitAll (file_id) ;
Packit b099d7
  if ( result != MrmSUCCESS ) _error_close () ;
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Close the file and deallocate the file descriptor
Packit b099d7
   */
Packit b099d7
  result = Idb__FU_CloseFile (file_id->lowlevel_id, FALSE) ;
Packit b099d7
  file_id->validation = 0 ;
Packit b099d7
  XtFree ((char*)file_id) ;
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * File successfully closed
Packit b099d7
   */
Packit b099d7
  return MrmSUCCESS ;
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  PROCEDURE DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	IdbGetIndexedResource attempts to retrieve a resource record with
Packit b099d7
 *	a matching index. The entry's group and type must match the filters
Packit b099d7
 *	when these are not null (RMCcNull and RMCtNull respectively). If a
Packit b099d7
 *	matching entry is found, its resource group, type, access, and data
Packit b099d7
 *	block are returned in the resource context. The resource context
Packit b099d7
 *	memory buffer will be reallocated as required to hold the data block.
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	file_id		The IDB file id returned by IdbOpenFile
Packit b099d7
 *	index		case-sensitive index for the entry to match
Packit b099d7
 *	group_filter	if not null, entry found must match this group
Packit b099d7
 *	type_filter	if not null, entry found must match this type
Packit b099d7
 *	context_id	URM resource context to receieve data block
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *	MrmSUCCESS	operation succeeded
Packit b099d7
 *	MrmNOT_FOUND	entry not found
Packit b099d7
 *	MrmWRONG_GROUP	entry didn't match group filter
Packit b099d7
 *	MrmWRONG_TYPE	entry didn't match type filter
Packit b099d7
 *	MrmFAILURE	operation failed, no further reason
Packit b099d7
 *
Packit b099d7
 *  SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
Cardinal 
Packit b099d7
UrmIdbGetIndexedResource (IDBFile			file_id,
Packit b099d7
			  String			index,
Packit b099d7
			  MrmGroup			group_filter,
Packit b099d7
			  MrmType			type_filter,
Packit b099d7
			  URMResourceContextPtr		context_id)
Packit b099d7
{
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   *  Local variables
Packit b099d7
   */
Packit b099d7
  Cardinal		result ;	/* function results */
Packit b099d7
  IDBDataHandle		data_entry ;	/* return new data entry */
Packit b099d7
  MrmCode		group ;		/* data entry's group */
Packit b099d7
  MrmCode		type ;		/* data entry's type */
Packit b099d7
Packit b099d7
Packit b099d7
  if ( (result=Idb__FIL_Valid(file_id)) != MrmSUCCESS ) return result ;
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Attempt to find the item.
Packit b099d7
   */
Packit b099d7
  result = Idb__INX_ReturnItem (file_id, index, &data_entry) ;
Packit b099d7
  if ( result != MrmSUCCESS ) return result ;
Packit b099d7
  result = Idb__DB_GetDataEntry (file_id, data_entry, context_id) ;
Packit b099d7
  if ( result != MrmSUCCESS ) return result ;
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Check group and type against filters.
Packit b099d7
   */
Packit b099d7
  group = UrmRCGroup (context_id) ;
Packit b099d7
  type = UrmRCType (context_id) ;
Packit b099d7
  if ( (group_filter!=URMgNul) && (group_filter!=group) )
Packit b099d7
    return MrmWRONG_GROUP ;
Packit b099d7
  if ( (type_filter!=URMtNul) && (type_filter!=type) )
Packit b099d7
    return MrmWRONG_TYPE ;
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Item successfuly retrieved
Packit b099d7
   */
Packit b099d7
  return MrmSUCCESS ;
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  PROCEDURE DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	IdbFindIndexedResource locates and lists all resources in the
Packit b099d7
 *	database which match the given filters. The entries in the
Packit b099d7
 *	index list will be in alphabetical order. The index strings must
Packit b099d7
 *	be deallocated by the caller using UrmFreePlistContents. This
Packit b099d7
 *	routine returns MrmSUCCESS even if no entries (0 entries) are found.
Packit b099d7
 *	Failure returns are used only for internal and other errors.
Packit b099d7
 *
Packit b099d7
 *	The number of entries in index_list is not reset to 0 when
Packit b099d7
 *	the search begins; its state is as the caller gives it.
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	file_id		The IDB file id returned by IdbOpenFile
Packit b099d7
 *	group_filter	if not null, entries found must match this group
Packit b099d7
 *	type_filter	if not null, entries found must match this type
Packit b099d7
 *	index_list	A pointer list in which to return index
Packit b099d7
 *			strings for matches. The required strings
Packit b099d7
 *			are automatically allocated.
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *	MrmSUCCESS	operation succeeded
Packit b099d7
 *	MrmFAILURE	operation failed, no further reason
Packit b099d7
 *
Packit b099d7
 *  SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
Cardinal 
Packit b099d7
UrmIdbFindIndexedResource (IDBFile		file_id,
Packit b099d7
			   MrmGroup		group_filter,
Packit b099d7
			   MrmType		type_filter,
Packit b099d7
			   URMPointerListPtr	index_list)
Packit b099d7
{
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   *  Local variables
Packit b099d7
   */
Packit b099d7
  Cardinal		result ;	/* function results */
Packit b099d7
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Validate file id, then initiate search with the root node. Return
Packit b099d7
   * immediately if there are no indexed resources.
Packit b099d7
   */
Packit b099d7
  if ( (result=Idb__FIL_Valid(file_id)) != MrmSUCCESS ) return result ;
Packit b099d7
Packit b099d7
  if ( file_id->num_indexed <= 0 ) return MrmSUCCESS ;
Packit b099d7
  return Idb__INX_FindResources (file_id, file_id->index_root,
Packit b099d7
				 group_filter, type_filter, index_list) ;
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  PROCEDURE DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	IdbGetRIDResource attempts to retrieve a resource record with a
Packit b099d7
 *	matching resource id. If there is a resource record associated with
Packit b099d7
 *	the resource id, it is returned - the resource group, type, and data
Packit b099d7
 *	block are set in the resource context. The memory buffer in the
Packit b099d7
 *	resource context is reallocated automatically as require to hold the
Packit b099d7
 *	data block.
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	file_id		The IDB file id returned by IdbOpenFile
Packit b099d7
 *	resource_id	resource id matching entry
Packit b099d7
 *	group_filter	if not null, entries found must match this group
Packit b099d7
 *	type_filter    	if not null, entries found must match this type
Packit b099d7
 *	context_id	to return data block
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *	MrmSUCCESS	operation succeeded
Packit b099d7
 *	MrmNOT_FOUND	entry not found
Packit b099d7
 *	MrmWRONG_GROUP	entry didn't match group filter
Packit b099d7
 *	MrmWRONG_TYPE	entry didn't match type filter
Packit b099d7
 *	MrmFAILURE	operation failed, no further reason
Packit b099d7
 *
Packit b099d7
 *  SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
Cardinal 
Packit b099d7
UrmIdbGetRIDResource (IDBFile			file_id,
Packit b099d7
		      MrmResource_id		resource_id,
Packit b099d7
		      MrmGroup			group_filter,
Packit b099d7
		      MrmType			type_filter,
Packit b099d7
		      URMResourceContextPtr	context_id)
Packit b099d7
{
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   *  Local variables
Packit b099d7
   */
Packit b099d7
  Cardinal		result ;	/* function results */
Packit b099d7
  IDBDataHandle		data_entry ;	/* return new data entry */
Packit b099d7
  MrmCode		group ;		/* data entry's group */
Packit b099d7
  MrmCode		type ;		/* data entry's type */
Packit b099d7
Packit b099d7
Packit b099d7
  if ( (result=Idb__FIL_Valid(file_id)) != MrmSUCCESS ) return result ;
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Attempt to find the item.
Packit b099d7
   */
Packit b099d7
  result = Idb__RID_ReturnItem (file_id, resource_id, TRUE, &data_entry) ;
Packit b099d7
  if ( result != MrmSUCCESS ) return result ;
Packit b099d7
  result = Idb__DB_GetDataEntry (file_id, data_entry, context_id) ;
Packit b099d7
  if ( result != MrmSUCCESS ) return result ;
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Check group and type against filters.
Packit b099d7
   */
Packit b099d7
  group = UrmRCGroup (context_id) ;
Packit b099d7
  type = UrmRCType (context_id) ;
Packit b099d7
  if ( (group_filter!=URMgNul) && (group_filter!=group) )
Packit b099d7
    return MrmWRONG_GROUP ;
Packit b099d7
  if ( (type_filter!=URMtNul) && (type_filter!=type) )
Packit b099d7
    return MrmWRONG_TYPE ;
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   * Item successfuly retrieved
Packit b099d7
   */
Packit b099d7
  return MrmSUCCESS ;
Packit b099d7
Packit b099d7
}
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  PROCEDURE DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	IdbGetResourceId returns the next available resource id in the file
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	file_id			The IDB file id returned by IdbOpenFile
Packit b099d7
 *	resource_id_return	To return new resource id
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *	MrmSUCCESS	operation succeeded
Packit b099d7
 *	MrmFAILURE	operation failed, no further reason given
Packit b099d7
 *
Packit b099d7
 *  SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
Cardinal 
Packit b099d7
UrmIdbGetResourceId (IDBFile			file_id,
Packit b099d7
		     MrmResource_id		*resource_id_return)
Packit b099d7
{
Packit b099d7
Packit b099d7
  /*
Packit b099d7
   *  Local variables
Packit b099d7
   */
Packit b099d7
  Cardinal	result ;		/* function results */
Packit b099d7
  IDBResource resource_id;
Packit b099d7
Packit b099d7
  if ( (result=Idb__FIL_Valid((IDBFile)file_id)) != MrmSUCCESS ) return result ;
Packit b099d7
  result = Idb__RID_NextRID ((IDBFile)file_id, 
Packit b099d7
                             &resource_id) ;
Packit b099d7
  *resource_id_return = resource_id;
Packit b099d7
  return result ;
Packit b099d7
Packit b099d7
}
Packit b099d7
Packit b099d7
Packit b099d7

Packit b099d7
/*
Packit b099d7
 *++
Packit b099d7
 *
Packit b099d7
 *  PROCEDURE DESCRIPTION:
Packit b099d7
 *
Packit b099d7
 *	This routine performs a validity check on a (supposed) IDB file
Packit b099d7
 *	pointer. It should probably signal errors, but currently just
Packit b099d7
 *	returns a code.
Packit b099d7
 *
Packit b099d7
 *  FORMAL PARAMETERS:
Packit b099d7
 *
Packit b099d7
 *	file_id		Supposed pointer to file descriptor to validate
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT INPUTS:
Packit b099d7
 *
Packit b099d7
 *  IMPLICIT OUTPUTS:
Packit b099d7
 *
Packit b099d7
 *  FUNCTION VALUE:
Packit b099d7
 *
Packit b099d7
 *	MrmSUCCESS	operation succeeded
Packit b099d7
 *	MrmFAILURE	some other failure
Packit b099d7
 *
Packit b099d7
 *  SIDE EFFECTS:
Packit b099d7
 *
Packit b099d7
 *--
Packit b099d7
 */
Packit b099d7
Packit b099d7
Cardinal 
Packit b099d7
Idb__FIL_Valid (IDBFile		file_id)
Packit b099d7
{
Packit b099d7
Packit b099d7
  if ( file_id == NULL ) return MrmFAILURE ;
Packit b099d7
  if ( file_id->validation != IDBOpenFileValid ) return MrmFAILURE ;
Packit b099d7
  return MrmSUCCESS ;
Packit b099d7
Packit b099d7
}
Packit b099d7