No part of this publication may be
reproduced, stored in a retrieval
system, or transmitted, in any form
or by any means, mechanical,
electronic, photocopying, recording,
or otherwise, without prior written
permission of Apple Computer, Inc.,
except to make a backup copy of any
documentation provided on
CD-ROM.
The Apple logo is a trademark of
Apple Computer, Inc.
Use of the “keyboard” Apple logo
(Option-Shift-K) for commercial
purposes without the prior written
consent of Apple may constitute
trademark infringement and unfair
competition in violation of federal
and state laws.
No licenses, express or implied, are
granted with respect to any of the
technology described in this book.
Apple retains all intellectual
property rights associated with the
technology described in this book.
This book is intended to assist
application developers to develop
applications only for Apple-labeled
or Apple-licensed computers.
Every effort has been made to ensure
that the information in this manual is
accurate. Apple is not responsible for
typographical errors.
Apple Computer, Inc.
1 Infinite Loop
Cupertino, CA 95014
408-996-1010
Apple, the Apple logo, and
Macintosh are trademarks of Apple
Computer, Inc., registered in the
United States and other countries.
Adobe, Acrobat, and PostScript are
trademarks of Adobe Systems
Incorporated or its subsidiaries and
may be registered in certain
jurisdictions.
Helvetica and Palatino are registered
trademarks of Linotype-Hell AG
and/or its subsidiaries.
ITC Zapf Dingbats is a registered
trademark of International Typeface
Corporation.
Simultaneously published in the
United States and Canada.
Even though Apple has reviewed this
manual, APPLE MAKES NO
WARRANTY OR REPRESENTATION,
EITHER EXPRESS OR IMPLIED, WITH
RESPECT TO THIS MANUAL, ITS
QUALITY, ACCURACY,
MERCHANTABILITY, OR FITNESS
FOR A PARTICULAR PURPOSE. AS A
RESULT, THIS MANUAL IS SOLD “AS
IS,” AND YOU, THE PURCHASER, ARE
ASSUMING THE ENTIRE RISK AS TO
ITS QUALITY AND ACCURACY.
IN NO EVENT WILL APPLE BE LIABLE
FOR DIRECT, INDIRECT, SPECIAL,
INCIDENTAL, OR CONSEQUENTIAL
DAMAGES RESULTING FROM ANY
DEFECT OR INACCURACY IN THIS
MANUAL, even if advised of the
possibility of such damages.
THE WARRANTY AND REMEDIES
SET FORTH ABOVE ARE EXCLUSIVE
AND IN LIEU OF ALL OTHERS, ORAL
OR WRITTEN, EXPRESS OR IMPLIED.
No Apple dealer, agent, or employee is
authorized to make any modification,
extension, or addition to this warranty.
Some states do not allow the exclusion or
limitation of implied warranties or
liability for incidental or consequential
damages, so the above limitation or
exclusion may not apply to you. This
warranty gives you specific legal rights,
and you may also have other rights
which vary from state to state.
Contents
Figures, Tables, and Listings7
Preface
Chapter 1
Chapter 2
About This Manual
Conventions Used in This Manual9
For More Information10
TCP/IP Constants and Other Data Types160
Apple Remote Access Constants and Other Data Types163
Modem Constants and Other Data Types170
AppleTalk Constants and Other Data Types172
Infrared Constants and Other Data Types173
Network configuration prior to Network Setup12
Network Setup in Mac OS 8.5 through the present13
Future Network Setup architecture14
Structure of the Network Setup Library15
Sample organization of the default area18
Reading and writing the default area20
Opening the database for reading26
Opening the database for writing27
Closing the database after reading28
Closing the database after writing29
Finding all entities of a particular class and type31
Printing the user-visible name for an entity33
Reading a fixed-size preference35
Reading the DHCP lease info preference in a TCP/IP network
connection entity36
Reading the user-visible name preference37
Calling OTCfgGetPrefsSize to read a variable-size preference38
Writing a preference39
Printing an entity’s table of contents40
Finding the active set entity44
Finding the active entity of a given class and type46
Finding the active TCP/IP entity47
Packing and unpacking the kOTCfgTCPInterfacesPref
preference50
Encrypting the user’s password54
11
25
7
8
PREFACE
▲
About This Manual
This manual describes Network Setup, which is a programming interface that
allows you to manipulate the contents of the Network Setup database. The
Network Setup database contains settings for all of the network protocols
installed on the system. Using Network Setup, you can programmatically
modify any network setting that the user can see in the various networking
control panels.
Conventions Used in This Manual0
The Courier font is used to indicate text that you type or see displayed. This
manual includes special text elements to highlight important or supplemental
information:
Note
Text set off in this manner presents sidelights or interesting
points of information.
IMPORTANT
Text set off in this manner—with the word Important—
presents important information or instructions.
WARNING
Text set off in this manner—with the word Warning—
indicates potentially serious problems.
◆
▲
▲
9
PREFACE
For More Information0
The following sources provide additional information that may be of interest to
developers who use the Network Setup programming interface:
Network Setup is a system service that allows you to manipulate network
configurations. You can use Network Setup to read, create, modify, and delete
network configurations. Any option that is accessible to the user through the
network control panels provided by Apple is also available to you through the
Network Setup programming interface.
This chapter describes the overall Network Setup architecture and introduces
the terminology needed to understand how to use Network Setup. It assumes
that you are familiar with the existing network control panels provided by
Apple (for example, the TCP/IP control panel) from a user's perspective,
especially the configurations window used to select, duplicate, and rename
network configurations.
Network Setup Architecture1
Prior to the introduction of Network Setup, each network protocol stack used
its own private mechanism to store preferences and make those preferences
active. Network preferences were stored as resources in files in the Preferences
folder. Figure 1-1 shows the overall network configuration architecture prior to
the introduction of Network Setup.
Network Setup Architecture
11
CHAPTER 1
About Network Setup
Figure 1-1
Control panels
Private interface
Private
preferences files
Network configuration prior to Network Setup
TCP/IP
TCP/IP
protocol
stack
TCP/IP preferences
AppleTalk
AppleTalk preferences
AppleTalk
protocol
stack
Remote Access,
Modem,
Dial Assist,
Infrared, ...
The architecture shown in Figure 1-1 had a number of drawbacks:
■
There was a control panel for each protocol type, leading to an unnecessary
proliferation of control panels.
■
There was no programming interface for changing network settings. With the
explosion of interest in networking prompted by the rise of the Internet, this
proved to be a problem. Internet setup programs, whether provided by
Apple or by third parties, were required to reverse engineer the network
preferences file format. After changing the files “underneath” the protocol
stacks, these programs had to force the protocol stack to read the new
preferences through a variety of unsupported means.
12
The dependence of third-party applications on the preferences file format
■
and private interfaces to the protocol stack made it difficult for Apple to ship
modern network features, such as TCP/IP multihoming, and to support the
multiple users feature in Mac OS 9.
■
Resource files are susceptible to corruption when the system crashes.
Network Setup was designed to eliminate these problems by giving developers,
both inside and outside of Apple, a programming interface to modify network
preferences without relying on internal implementation details of the individual
protocol stacks.
Network Setup is being introduced in two stages. The architecture of the first
stage (Mac OS 8.5 to the present day) is shown in Figure 1-2.
Network Setup Architecture
CHAPTER 1
About Network Setup
Figure 1-2
Legacy
control
panels
Legacy
protocol
stacks
Legacy
preferences
files
Network Setup in Mac OS 8.5 through the present
Network
Setup
scripting
TCP/IP
TCP/IP
TCP/IP
TCP/IP
TCP/IP
TCP/IP
Protocol
Protocol
Protocol
Stack
Stack
Stack
Network Setup library
Network Setup database
Third-party
application
Network Setup
aware applications
Public interface
The following key points are to be taken from Figure 1-2:
■
The Network Setup library provides a standard programming interface for
manipulating network configurations stored in the Network Setup database.
The database is designed to store network preferences reliably even if the
system crashes while preferences are being modified.
■
The Network Setup library provides automatic synchronization between the
database and legacy preference files. Synchronization allows existing
software with dependencies on the format of those files (such as third-party
Internet setup software, Apple control panels, and protocol stacks) to
continue working in the new environment.
Third-party developers are encouraged to migrate to the Network Setup
■
programming interface, but in so doing, their existing applications in the
field will not break.
Network Setup scripting is a bridge between the Network Setup
■
programming interface and AppleScript. It allows script developers to
manipulate network configurations through a standard AppleScript object
model interface.
The primary disadvantage of the current Network Setup architecture is that the
synchronization between the legacy preferences files and the Network Setup
database is a time consuming operation. Consequently, Apple intends to
Network Setup Architecture
13
CHAPTER 1
About Network Setup
remove support for legacy preferences files as soon as possible. Figure 1-3
shows the future Network Setup architecture.
Figure 1-3
Updated
protocol
stacks
Future Network Setup architecture
Network
control
panel
TCP/IP
TCP/IP
TCP/IP
Protocol
Protocol
Protocol
Stack
Stack
Stack
Network Setup library
Network Setup database
Network
Setup
scripting
Third-party
application
Network Setup
aware applications
Public interface
In the future Network Setup architecture, all developers, applications that
manipulate network preferences will be required to use the Network Setup
programming interface. If you have an application that manipulates legacy
preferences files directly, to guarantee future compatibility you must update it
to use the Network Setup programming interface.
Inside the Network Setup Library1
Figure 1-4 shows the structure of the Network Setup library itself and its
relationship to the applications that call it. This structure is mostly irrelevant to
programmers who call the programming interface — Network Setup acts like a
“black box”—- but it helps to explain how Network Setup works.
14
Inside the Network Setup Library
CHAPTER 1
About Network Setup
Figure 1-4
Network Setup
aware applications
Network Setup
extension
Structure of the Network Setup Library
High-level framework
Mid-level database (OTCfg)
Low-level database (Cfg)
Synchronization
Legacy
module
As shown in Figure 1-4, the Network Setup library is divided into four key
components:
The low-level database, which is an internal component of the Network
■
Setup Extension file. The low-level database contains the core database
manipulation engine. It knows nothing about networking — it just moves
bits around. The low-level database is not visible to developers except insofar
as its prefix (“Cfg”) is used by some Network Setup identifiers.
■
The mid-level database, which is the actual programming interface exported
to developers. Its routine names start with “OTCfg”. The mid-level database
passes most requests directly to the low-level database, which actually
executes the request and manipulates the database. The mid-level database
also interfaces with the legacy synchronization module.
■
The legacy synchronization module, which in combination with the
mid-level database, ensures that the database is synchronized with the legacy
preferences files. This module will be removed in a future version of
Network Setup. See “Legacy Synchronization Algorithm” (page 22) for more
information about legacy file synchronization.
Most users of the Network Setup programming interface use a high-level
■
framework to assist them in their task. Apple software uses an
Apple-internal C++ framework for this. This framework is statically linked
into software like the Network Setup Scripting application. Third-party
developers commonly use the MoreNetworkSetup framework, available as
sample code.
Inside the Network Setup Library
15
CHAPTER 1
About Network Setup
Network Setup Database Fundamentals1
This section describes the fundamental structure of and operations on the
Network Setup database.
Database Structure1
The Network Setup database consists of multiple areas. There are two types of
areas:
named areas
the preference modification process. The system currently uses a single named
area, known as the
store all network preferences. While it is possible to create and manipulate other
named areas within the database, doing so does not affect any network settings.
Areas are identified by a unique
store preferences, while temporary areas are used as part of
default area
(sometimes referred to as the
area ID
.
current area
) to
Each area contains a number of
entity reference.
■
An entity reference uniquely identifies an entity. The entity
entities
having the following properties:
reference contains an area ID, which identifies the area in which the entity
resides.
entity name.
■
■
entity class
A user-visible name for the entity that need not be unique.
and
type.
These values, both of type
, determine the type
OSType
of data contained within an entity. There are three entity classes:
■
network connection entity.
A network connection entity contains
information about a single instance of a network protocol on a port.
Typically there is one active network connection entity per protocol stack,
but on a multihomed computer there can be more. The entity type for an
network connection entity indicates the network protocol of the
connection.
■
global protocol entity.
A global protocol entity contains configuration for
a protocol stack on a computer. There is only one active global protocol
entity for each protocol stack. The entity type for a global protocol entity
indicates the network protocol whose configuration it contains.
■
set entity.
A set entity groups global protocol and network connection
entities into a set. The set entity contains entity references to each entity in
the set. An area can contain multiple set entities, but there is one and only
16
Network Setup Database Fundamentals
CHAPTER 1
About Network Setup
one
active set entity
. The entities referenced by the active set entity
comprise the active network preferences. All set entities have the same
type.
■
icon.
An entity can include a reference to a custom icon. The custom icon is
not currently used, but may be used by future system software to display a
visual representation of the entity.
Within each entity there are zero or more
preference type
(an
). A preference is the atomic unit of data in the
OSType
preferences
, distinguished by a
database. When you read or write data, you do so one preference at a time.
Typically the data for a preference is protocol-dependent. Its format is
determined by the entity class and type and by the preference type itself. To
read or write a preference meaningfully, you must know the format of the
preference data. The reference section of this document describes the format of
every preference used by the Apple protocol stacks. In most cases, this
description includes a C structure that mirrors the structure of the preference
itself.
Note
For most preferences, the data format is the same as for the
equivalent resource in the legacy preference files. If you are
familiar with the legacy file format, you should be able to
easily understand the preference data format. See “Legacy
Issues” (page 21) for more information on how Network
Setup synchronizes the database with the legacy
preferences files.
Database Structure Example1
Figure 1-5 shows an example of how the Network Setup database might be
structured on a particular computer.
Network Setup Database Fundamentals
17
CHAPTER 1
About Network Setup
Figure 1-5
Default area
AppleTalk global protocol entity
'opts' preference
'opts' preference
...
...
TCP/IP global protocol entity
'opts' preference
'opts' preference
...
...
"LocalTalk for Printer" AppleTalk network protocol entity
general AppleTalk preference
user-visible name of this port
general AppleTalk preference
user-visible name of this port
DNS configuration
user-visible name of this port
DNS configuration
user-visible name of this port
Active
Active
18
Network Setup Database Fundamentals
CHAPTER 1
About Network Setup
For simplicity, this example assumes a computer with two places of operation,
home and work, and two protocol stacks, TCP/IP and AppleTalk. Thus, there
are four network connection entities:
■
“AirPort,” a TCP/IP network connection entity that configures a TCP/IP
interface to use an AirPort card to access an AirPort Base Station at home.
“LocalTalk for Printer,” an AppleTalk network connection entity that
■
configures an AppleTalk interface to use LocalTalk over the Printer port, to
talk to a LocalTalk printer at home.
“Work/DHCP,” a TCP/IP network connection entity which configures a
■
TCP/IP interface to use DHCP over the Ethernet port.
“Company Ethernet,” an AppleTalk network connection entity that
■
configures an AppleTalk interface to use the Ethernet port in a zone that only
exists on the “Work” network.
The area also has two global protocol entities, one for TCP/IP and one for
AppleTalk. These settings do not need to change between home and work, so
there is only one of each.
Finally, the area has two set entities:
“Home,” which references the two global protocol entities and the two home
■
network connection entities: “AirPort” for TCP/IP and “LocalTalk for
Printer” for AppleTalk.
“Work,” which references the two global protocol entities but also references
■
two network connection entities: “Work/DHCP” for TCP/IP and “Company
Ethernet” for AppleTalk.
The “Work” set entity is marked as active, so the network connection entities
that it references are active. When the user moves from work to home, a
program (such as the Location Manager) can simply mark the “Work” entity as
inactive and the “Home” entity as active and the network configuration will
switch accordingly.
Database Operations1
Before reading or writing preferences, an application must open the database.
The first step is to create a
calling application to the Network Setup library and is passed to subsequent
calls that access the database. After creating the database reference, the process
diverges for readers and writers. When an application opens the default area for
Network Setup Database Fundamentals
database reference
. This reference identifies the
19
CHAPTER 1
About Network Setup
reading, it reads the area directly. Network Setup simply notes that the area is
open for synchronization purposes (see the section “Preference Coherency”
(page 21)). For writing, the process is somewhat different.
When an application opens an area for writing, Network Setup creates a
temporary area that is an exact duplicate of the default area. It then returns the
temporary area ID to the application. The application can now change the
temporary area without affecting running network services. When the
application is done making changes, it commits the changes to the database.
Committing changes is an atomic process that overwrites the default area with
the contents of the temporary area and causes the protocol stacks to reconfigure
themselves for the new configuration.
Alternatively, the writing application can choose to abort the modifications, in
response to which Network Setup discards the temporary area and the system
continues to use the configuration in the default area.
Figure 1-6 shows this process diagrammatically.
Figure 1-6
Reading
Default area
Default area
being read
Default area
Reading and writing the default area
Open for reading
Close for reading
Writing
Default area
Open for write
abort
Temporary area
being written
Commit
Updated default area
Multiple applications can open the Network Setup database for reading, but
only one application at a time can open the database for writing.When an
application commits changes to the default area, Network Setup notifies each
application that has opened the database for reading that a change has
occurred, as explained in the next section, “Preference Coherency.”
20
Network Setup Database Fundamentals
CHAPTER 1
About Network Setup
Preference Coherency1
When an application commits changes to the default area, it is important that
applications that are reading the database be informed of those changes. For
example, an application might be displaying the DHCP client ID preference. If
another application changes this preference in the database, it is important that
the original application update its display.
Prior to Network Setup 1.0.2, the mechanism by which readers learned of
changes was somewhat primitive. When a writing application committed its
changes, Network Setup tagged each reading application’s database reference
with an error. Any subsequent calls using that database connection failed with
an error (kCfgErrDatabaseChanged). The reading application responded by
closing its database reference and opening the database again. It then read the
new preferences.
Network Setup 1.0.2 introduces a new, notifier-based mechanism for learning
about preference changes. The reading application attaches a notifier to the
database reference. When changes are committed to the database, Network
Setup calls each installed notifier to inform the reading application that a
change has occurred. The reading application should respond by re-reading any
preferences it has cached.
Legacy Issues1
As described in the section “Network Setup Architecture” (page 11), current
versions of Network Setup automatically synchronize the legacy preferences
files with the database. This synchronization mechanism is transparent to
applications calling Network Setup, but there are two issues that you should be
aware of:
■ Legacy synchronization is slow. Depending on the speed of the computer
and the number of entities, a full synchronization can take seconds. You
should do all that you can to avoid synchronizations. The best way to avoid
synchronizations is to adopt Network Setup and avoid modifying the legacy
preferences files directly.
■ Legacy preferences files do not support multihoming.
Legacy Issues
21
CHAPTER 1
About Network Setup
Given that legacy synchronization is slow and that legacy preferences files do
not support multihoming, future system software will not support legacy
synchronization.
Legacy Synchronization Algorithm1
Network Setup synchronizes the database and the legacy preferences files at the
following times:
■ When the database is opened. Network Setup checks the modification dates
of each legacy preferences file against modification dates stored in the
database. If the dates are different, Network Setup assumes that some
application has changed one or more legacy preferences files and imports
preferences from the modified files.
■ When changes are committed to the database. Network Setup determines
whether the committed changes affect a legacy preferences file. If they do,
Network Setup exports the database to the legacy preferences file and
records the modification date of the legacy preferences file in the database.
The legacy import mechanism makes good use of the structure of the legacy
preferences files. Most preferences files are resource files having the following
attributes:
■ A resource having a well known resource type ('cnam').
■ All resources with a resource ID of a 'cnam' resource belong to that
configuration. The contents of these resources are the preferences for that
configuration.
■ There is one fixed resource whose type is 'ccfg' and whose ID is 1 that
contains the resource ID of the active configuration.
■ Any resources with IDs other than those used for configurations are global
preferences.
When importing a legacy preferences file, Network Setup creates an entity for
each 'cnam' resource and, for each resource with the same ID as the 'cnam'
resource, creates a preference in the entity whose preference type is the resource
ID and whose data is the resource data. If the 'ccfg' resource indicates that the
configuration is active, Network Setup places the entity in the active set.
The legacy export process is similar to the legacy import mechanism. For each
network connection entity of a particular type, Network Setup creates a
resource with a unique ID in the legacy file. Then, for each preference in the
22Legacy Issues
'cnam'
CHAPTER 1
About Network Setup
entity, it creates a resource containing the preference data with the resource type
matching the preference type and the resource ID the same as the 'cnam'
resource.
Network Setup uses a number of private preferences to ensure a reliable round
trip conversion between legacy preferences files and the database. The
preference types are described in “Common Preference Types” (page 106), but
your application should not depend on their presence, their content, or their
semantics.
If you find undocumented preferences (such as a preference of type 'vers') in a
global protocol entity, do not be concerned. Network Setup itself does not
actually look at the data as it imports from and exports to legacy preferences
files.
Network Setup Version History1
Table 1-1 summarizes the different versions of Network Setup, their features,
and their release vehicles.
Table 1-1Network Setup versions
VersionMac OS versionNew features
1.0Mac OS 8.5
1.0.1Not released
OTCfgGetAreaName
1.0.2Mac OS 8.6OTCfgInstallNotifier,
OTCfgRemoveNotifier
1.1Not releasedOTCfgEncrypt,
OTCfgDecrypt
1.1.1Mac OS 9.0
There is no easy way to determine the version of Network Setup installed on a
system. The best way to test for the presence of a specific Network Setup API
enhancement is to weak link to its symbol, as described in TN 1083, “Weak
Linking to a Code Fragment Manager-based Shared Library.”
Network Setup Version History23
CHAPTER 1
About Network Setup
24Network Setup Version History
CHAPTER 2
Figure 2-0
Listing 2-0
Table 2-0
Using Network Setup2
This chapter explains how to use the Network Setup programming interface to
read and write network preferences. It assumes that you are familiar with basic
Network Setup concepts. If not, you should read Chapter 1, “About Network
Setup,”for important background material. This chapter concentrates on
practical examples of coding with Network Setup.
Opening and Closing the Network Setup Database2
This section explains how your application should open the Network Setup
database for reading and writing and then discusses how to close the database
and, in the case where the database has been opened for writing, either
committing or discarding your modifications.
Opening the Database for Reading2
The MyOpenDatabaseForReading routine shown in Listing 2-1 shows how to open
the default (or current) area in the Network Setup database for reading. It starts
by calling OTCfgOpenDatabase, which returns a database reference (of type
CfgDatabaseRef) that identifies your application’s connection to the database. It
then calls OTCfgGetCurrentArea, which returns an area identifier (of type
CfgAreaID) that identifies the default area. Finally, it opens the default area for
reading by calling OTCfgOpenArea.
The MyOpenDatabaseForReading routine returns both the database reference
(dbRef) and the default area identifier (readArea). You must know these values
in order to read preferences and eventually close the database.
err = OTCfgOpenDatabase(dbRef);
if (err == noErr) {
err = OTCfgGetCurrentArea(*dbRef, readArea);
if (err == noErr) {
err = OTCfgOpenArea(*dbRef, *readArea);
}
if (err != noErr) {
(void) OTCfgCloseDatabase(dbRef);
}
}
if (err != noErr) {
*dbRef = nil;
*readArea = kInvalidCfgAreaID;
}
return err;
}
Opening the Database for Writing2
The MyOpenDatabaseForWriting routine shown in Listing 2-2 shows how to open
the default (or current) area in the Network Setup database for writing. The
approach is similar to that used for opening the database for reading except that
instead of calling OTCfgOpenArea to open the area for reading, the routine calls
OTCfgBeginAreaModifications to open the area for writing.
The OTCfgBeginAreaModifications function returns another area identifier that
references a writable temporary area. The MyOpenDatabaseForWriting routine
returns both the original default area identifier and the writable temporary area
identifier. You must keep both of these area identifiers because you need them
both in order to close the database. You can only make changes to the writable
26Opening and Closing the Network Setup Database
CHAPTER 2
Using Network Setup
area, but you can read from both the original area and the writable area to
access, respectively, the currently active network settings and your proposed
changes to the network settings.
The MyCloseDatabaseAfterReading routine shown in Listing 2-3 shows how to
close the database after you are done reading from it. The routine simply calls
OTCfgCloseArea to close the read area and then calls OTCfgCloseDatabase to close
the database itself. This code discards error results from both of these routines
because if the database fails to close there isn’t anything your application can do
to force it to close, but it does log any errors with the standard C assert macro
so that you can detect this sort of error during testing.
The MyCloseDatabaseAfterWriting routine shown in Listing 2-4 shows how to
close the database after you have finished making changes. The first three
routine parameters (the database reference, the read area identifier, and the
write area identifier) were obtained when the database was opened the
database for writing. The fourth parameter, commit, indicates whether the
changes are to be committed to the database or discarded.
If commit is true, the routine calls OTCfgCommitAreaModifications, which
overwrites the current settings in the read area with the new settings in the
write area and notifies the network protocol stacks that their preferences have
changed so that they can reconfigure themselves.
28Opening and Closing the Network Setup Database
CHAPTER 2
Using Network Setup
If commit is false, the routine calls OTCfgAbortAreaModifications to discard the
changes made in the writable temporary area. The read area is not changed, and
the network protocol stacks continue unaffected.
In contrast to MyCloseDatabaseAfterReading shown in Listing 2-3,
MyCloseDatabaseAfterWriting does not always throw away error results. If
OTCfgCommitAreaModifications returns an error, the
MyCloseDatabaseAfterWriting routine aborts. Your application may respond to
this by calling the same routine again, this time with commit set to false.
Once you have a reference to the database and an area identifier for the default
area, the next step is to look for appropriate entities within that area. Regardless
of what you want to do to an entity, you must first obtain a reference to it. An
entity reference is an opaque data structure that Network Setup uses to
uniquely identify each entity within an area.
Typically there are two ways to get the entity reference for an entity within an
area.
■ You can list all of the entities of a particular class and type and display that
list to the user. For example, you might want to list all of the TCP/IP
network connection entities so that the user can choose the one to make
active. The section “Listing All Entities” (page 30) explains how to do this.
■ You can find the currently active entity of a particular class and type. This is
useful when you want to read the current network settings. The section
“Finding an Active Entity” (page 34) explains how to do this.
You can also create, duplicate, rename, and delete entities. These tasks are easy
to do and are not explained in detail in this chapter. See “Network Setup
Reference” (page 57) for information about OTCfgCreateEntity (page 76),
OTCfgDuplicateEntity (page 78), OTCfgSetEntityName (page 81), and
OTCfgDeleteEntity (page 78).
Listing All Entities2
Listing 2-5 shows the routine MyGetEntitiesList, which generates a list of all of
the entities within an area of the database. The routine’s database reference and
area identifier parameters are obtained by opening the database, as explained in
“Opening the Database for Reading” (page 25). The entityClass and entityType
parameters specify the entities to list. Some common scenarios include:
■ Getting all entities of a specific class and type. Set the entityClass and
entityType parameters to that class and type. For example, to find all TCP/IP
network connection entities, supply a class of kOTCfgClassNetworkConnection
and a type of kOTCfgTypeTCPv4. See “Entity Classes and Types” (page 104) for
a list of the defined classes and types.
30Working with Entities
CHAPTER 2
Using Network Setup
■ Getting all entities. Set entityClass and entityType to the wildcard values
kCfgClassAnyEntity and kCfgTypeAnyEntity, respectively.
The entityRefs and entityInfos parameters are handles containing an array of
elements of type CfgEntityRef and CfgEntityInfo, respectively. You must create
these handles before calling MyGetEntitiesList. You can set entityInfos to NULL
if you’re not interested in the information returned in that handle. The
MyGetEntitiesList routine resizes the handles appropriately to hold
information about each of the entities that it finds.
The MyGetEntitiesList routine calls two key Network Setup functions:
OTCfgGetEntitiesCount to count the number of entities of the specified class and
type and OTCfgGetEntitiesList to get the actual entity information. The rest of
the MyGetEntitiesList routine is just memory management.
Listing 2-5Finding all entities of a particular class and type
The next routine, shown in Listing 2-6, opens the database for reading, gets the
entity references for all of the TCP/IP network connection entities in the default
area (using the
MyGetEntitiesList routine in Listing 2-5), and prints their
user-visible names. This routine calls a routine, MyGetEntityUserVisibleName,
which hasn’t been documented yet. It is shown in Listing 2-9 in the section
“Reading and Writing Preferences” (page 34).
Listing 2-6Printing the user-visible name for an entity
Currently, only one entity can be active for any given network connection type.
This is not a restriction of Network Setup itself, but a limitation in the network
protocol stacks. When you look for an active entity for a particular network
protocol, you should be aware that, in the future, there may be more than one.
Because of the complexity of this algorithm and because its implementation
relies on concepts that haven’t been discussed yet, the steps and sample code
for finding an active entity are shown in “Working with Sets” (page 42), later in
this chapter.
Reading and Writing Preferences2
Once you have an entity reference, reading and writing preferences in the entity
is a straightforward exercise. The basic steps are to open the entity, read and
34Reading and Writing Preferences
CHAPTER 2
Using Network Setup
write the desired preferences, and close the entity. This section describes this
process for reading variable-length and fixed-size preferences and for writing
preferences.
Reading Fixed-size Preferences2
Many Network Setup preferences are of a fixed size. Reading a fixed size
preference is easy because you simply read it into the C structure that
corresponds to the preference. The code in Listing 2-7 shows a simple wrapper
routine you can use to read a fixed size preference from an entity within the
database. The prefType parameter controls the preference that is read. The
preference data is put in the buffer described by buffer and bufferSize.
The sample shown in Listing 2-7, which opens and closes
the entity before reading each preference, is implemented
in an inefficient manner for the sake of clarity. If you are
reading multiple preferences, it is more efficient to open the
entity once. Then read the preferences by calling
OTCfgGetPrefs or OTCfgSetPrefs multiple times and close
the entity when you’re done. ◆
A noteworthy point about reading preferences is that the OTCfgOpenPrefs
function does not take an area parameter. This is because the CfgEntityRef itself
implicitly includes the area. The significant of this point is demonstrated in the
section “Working with Sets” (page 42).
You can use the MyReadFixedSizePref routine shown in Listing 2-7 to read
specific preferences within an entity. For example, Listing 2-8 shows how to
read the DHCP lease information from a TCP/IP network connection entity.
The routine calls MyReadFixedSizePref, passing it the appropriate preference
type (kOTCfgTCPDHCPLeaseInfoPref), a pointer to the corresponding C structure,
and the size of the structure.
Listing 2-8Reading the DHCP lease info preference in a TCP/IP network
You can derive the C structure for a specific preference type
by removing the “k” from the front of the name and the
“Pref” from the end. For example, the C structure for
kOTCfgTCPDHCPLeaseInfoPref is OTCfgTCPDHCPLeaseInfo. The
preference type constants and preference structures for all
of the Apple-defined preferences are provided in Chapter 4,
“Network Setup Protocol Structures and Data Types.” ▲
Reading Variable-size Preferences2
The MyReadFixedSizePref routine shown in Listing 2-7 also works with variable
size preferences that have a known maximum size that internally includes the
size of the preference. The user-visible name preference
kOTCfgUserVisibleNamePref), which contains a packed Pascal string, is an
(
example. The maximum length of a Pascal string is 256 bytes, and the first byte
denotes the length of the actual string data. Listing 2-9 shows how to use
MyReadFixedSizePref to read this type of variable size preference.
Listing 2-9Reading the user-visible name preference
If the variable size preference you want to read does not have a known
maximum size and does not store its size internally, you need to know how big
a buffer to allocate before you call
Reading and Writing Preferences37
OTCfgGetPrefs. You can get this information
CHAPTER 2
Using Network Setup
by calling OTCfgGetPrefsSize before you read the preference, as shown in
Listing 2-10.
Listing 2-10Calling OTCfgGetPrefsSize to read a variable-size preference
}
err2 = OTCfgClosePrefs(accessID);
if (err == noErr) {
err = err2;
}
38Reading and Writing Preferences
CHAPTER 2
Using Network Setup
}
return err;
}
Writing Preferences2
Listing 2-11 shows the routine MyWritePref, which demonstrates the basic
mechanism for writing preferences. Writing a preference is similar to reading a
preference, with the following exceptions:
■ When you open the entity, open the entity for writing by passing true in the
writer parameter of OTCfgOpenPrefs.
■ The entity that is opened must be in a writable temporary area. Attempting
to open for writing an entity in a read-only area will result in an error.
Note
You don’t need provide the area identifier when you call
OTCfgOpenPrefs because an entity “knows” the area to
err2 = OTCfgClosePrefs(accessID);
if (err == noErr) {
err = err2;
}
}
return err;
}
Note
The sample shown in Listing 2-11, which opens and closes
the entity for each preference written, is implemented in an
inefficient manner for the sake of clarity. If you are writing
multiple preferences, it is more efficient to open the entity,
write your preferences by calling OTCfgSetPrefs multiple
times, and close the entity when you’re done. ◆
Iterating the Preferences in an Entity2
Network Setup provides functions for iterating all of the preferences in an
entity. You will rarely need to do this, but the code in Listing 2-12 gives an
example. The code first calls OTCfgGetPrefsTOCCount (TOC stands for “Table of
Contents”) to get a count of the number of preferences in the entity and then
calls OTCfgGetPrefsTOC to get an array of CfgPrefsHeader structures. Each
structure represents a preference in the entity, with fields for the preference’s
type and size.
Listing 2-12Printing an entity’s table of contents
The Network Setup database uses set entities to store collections of other entity
references. When network entities are grouped into sets, they can be activated
and deactivated as a group. All of the network entities in all of the sets reside in
a single area, so there are no limits on the way entities can be grouped. For
example, a single network connection entity can be referenced by multiple sets.
IMPORTANT
Sets contain entity references — not the entities
themselves. ▲
Figure 2-1 shows the relationship between set entities, network connection
entities, and global protocol entities.
■ Each set entity contains a preference, kOTCfgSetsStructPref, that has a flag
that determines whether the set is active.
■ At all times, there must be one and only one active set.
■ Each set entity contains a preference, kOTCfgSetsVectorPref, that includes, as
elements of an unbounded array, the entity references of all entities in the set.
■ For legacy synchronization to work correctly, each set entity must contain
one and only one entity of each type of network connection and global
protocol entity. This restriction will be relaxed in future versions of Mac OS.
When you make changes to a set entity, you must follow these rules:
■ If you mark a set as active, you must deactivate the previously active set.
■ When you add an entity to a set entity, you must remove the first entity in
the array of the same class and type as the entity you are adding. If there is
more than one entity of the same class and type, you can safely leave the
other entities in the set entity because you are running on a system that
supports multihoming.
■ When you delete an entity, you must delete its reference from all set entities,
whether they are active or not.
■ You must not delete the last remaining entity of a particular class and type
from a set entity.
■ Do not add a set entity reference to another set entity. Network Setup does
not support nested set entities.
Finding the Active Set Entity2
The basic algorithm for finding the active entity of a particular class and type is:
1. Get a list of all set entities.
2. Search the list for the active set entity.
3. Get the contents of that set entity. (The contents of a set entity is a list of
entity references.)
4. Search the set’s entity references for the entity reference having the
appropriate class and type.
Working with Sets43
CHAPTER 2
Using Network Setup
The MyFindActiveSet routine in Listing 2-13 implements the first two steps. It
starts by getting a list of all of the set entities by calling the MyGetEntitiesList
routine (Listing 2-5). Then MyFindActiveSet iterates through all of the set
entities, reading the kOTCfgSetsStructPref preference of each set entity. That
preference maps to the CfgSetsStruct structure, which contains an fFlags
member. One bit of the fFlags member, kOTCfgSetsFlagActiveMask, indicates
whether this set entity is the active set entity. If it is, the routine breaks out of
the loop and returns the set’s entity reference to the caller.
The remaining two steps for finding the set entity of a particular class and type
are implemented by the MyFindFirstActiveEntity routine, shown in Listing
2-14. It calls MyFindActiveSet (Listing 2-13) to find the entity reference of the
active set entity. The MyFindFirstActiveEntity routine then reads the
kOTCfgSetsVectorPref preference out of the active set entity. This preference is a
count field followed by an unbounded array of CfgSetsElement structures, each
of which represents an entity in the set. Because of its variable size,
MyFindFirstActiveEntity reads the preference by calling
MyReadVariableSizePref (Listing 2-10). Once it has the array of information
about entities contained in the set, MyFindFirstActiveEntity iterates over that
array looking for the first element whose class and type matches the required
class and type specified by the caller. When it finds the correct entity in the set,
MyFindFirstActiveEntity breaks out of the loop and returns the found entity
reference to the caller.
Working with Sets45
CHAPTER 2
Using Network Setup
Listing 2-14Finding the active entity of a given class and type
The code in Listing 2-15 pulls together the process of finding an active set entity
by finding the active TCP/IP set entity. It opens the database, calls
MyFindFirstActiveEntity (Listing 2-14) with kOTCfgClassNetworkConnection and
kOTCfgTypeTCPv4 as parameters, calls MyGetEntityUserVisibleName (Listing 2-9)
to get and print the entity’s user visible name, and calls
MyCloseDatabaseAfterReading (Listing 2-3) to close the database.
printf("User-visible name of active TCP/IP entity = "%#s"\n",
userVisibleName);
}
MyCloseDatabaseAfterReading(dbRef, readArea);
}
if (err != noErr) {
printf("Failed with error %ld.\n", err);
}
}
Areas and Sets2
When working with sets you need to be very careful about area identifiers.
There are three key points to remember:
■ The area identifier is embedded in the entity reference.
■ All modifications to the database are done in a temporary area.
■ The temporary area is destroyed when changes are committed to the
database.
So, the area identifier that is embedded in the entity reference in a set is an area
identifier for an area that no longer exists. This can cause your software to fail.
For example, consider the following sequence:
1. Start with a database whose default area identifier is 1370.
2. A program opens the database for writing, which creates a temporary area
whose identifier is 6288.
3. The program adds an entity reference to the active set entity in the temporary
area. Because the added entity reference describes an entity in the temporary
area, its area identifier is 6288.
4. The writing program commits its changes to the database, overwriting area
1370 with the content of area 6288. The active set entity in area 1370 now
contains an entity reference whose area identifier is 6288.
5. Your program opens the database for reading. It then opens the active set
entity and reads the entity references contained therein. When it tries to use
one of those entities, the program fails because the entity’s area identifier is
6288, not 1370.
48Working with Sets
CHAPTER 2
Using Network Setup
The solution to this problem is very simple: assume that all entity references in
a set refer to entities that are in the same area as the set. This has two practical
consequences.
■ When comparing two entity references that might have come from a set
entity, always pass kOTCfgIgnoreArea when calling OTCfgIsSameEntityRef. The
OTCfgIsSameEntityRef function will then compare the entities as if they were
in the same area.
■ When opening an entity whose reference you have obtained from a set,
always call OTCfgChangeEntityArea to reset its area identifier to that of the
area in which you are working.
Listing 2-14 demonstrates this technique.
Protocol-specific Topics2
This section contains hints and tips for working with the Network Setup
preferences of certain protocol stacks provided by Apple.
TCP/IP Notes2
A TCP/IP network connection entity has a class of
kOTCfgClassNetworkConnection and a type of kOTCfgTypeTCPv4. The entity must
contain the following preferences:
■ kOTCfgTCPInterfacesPref, which contains the core TCP/IP configuration
information. For details, see the discussion below and
(page 114), and OTCfgTCPInterfacesPackedPart (page 114).
■ kOTCfgTCPDeviceTypePref, which contains data needed by the current TCP/IP
control panel. For details, see OTCfgTCPDeviceTypePref in the section “TCP/IP
Constants and Other Data Types” (page 160).
■ kOTCfgTCPRoutersListPref, which contains the list of configured routers. For
details, see OTCfgTCPRoutersList (page 119).
■ kOTCfgTCPSearchListPref, which contains the strings which make up the
implicit search path for DNS. For details, see OTCfgTCPSearchList (page 120).
Protocol-specific Topics49
CHAPTER 2
Using Network Setup
■ kOTCfgTCPDNSServersListPref, which contains the list of configured DNS
servers. For details, see OTCfgTCPDNSServersList (page 116).
■ kOTCfgTCPSearchDomainsPref, which contains the list of additional domains to
be searched. For details, see OTCfgTCPSearchDomains (page 120).
■ kOTCfgTCPUnloadAttrPref, which specifies how TCP/IP loads and unloads.
For details, see OTCfgTCPUnloadAttr (page 121).
■ kOTCfgTCPLocksPref, which is used by the TCP/IP control panel to remember
which preferences are locked. For details, see OTCfgTCPLocks (page 116).
The only complex preference in a TCP/IP network connection entity is the
kOTCfgTCPInterfacesPref preference. The data for this preference is packed in
an unusual way that makes the preference tricky to access from C. To help solve
this problem, Network Setup declares two sets of C structures for this
preference.
■ OTCfgTCPInterfacesPacked and OTCfgTCPInterfacesPackedPart help you
access the preference in its packed format.
■ OTCfgTCPInterfacesUnpacked is an unpacked form of the preference that you
can use internally within your code. When you read the preference, you can
unpack it into this structure. You can then manipulate the unpacked
structure and only pack it again when you write it.
Listing 2-16 provides sample code that unpacks and packs a
kOTCfgTCPInterfacesPref preference.
Listing 2-16Packing and unpacking the kOTCfgTCPInterfacesPref preference
// Start the cursor at the beginning of the packed preference.
50Protocol-specific Topics
CHAPTER 2
Using Network Setup
cursor = (UInt8 *) packedPref;
// For each field in the unpacked pref, copy the field to the
// packed preference cursor and advance the cursor appropriately.
if (unpackedPref->fCount != 1) goto prefDataErr;
*((UInt16 *) cursor) = unpackedPref->fCount;
cursor += sizeof(UInt16);
// Now calculate the packed preference size by taking the difference
// between the final cursor position and the initial cursor position.
*packedPrefSize = (cursor - ((UInt8 *) packedPref));
// The following code accesses a long off a word.
// Network Setup is PowerPC only, and the emulated PowerPC processor handles these
// misaligned accesses.
unpackedPref->fIPAddress = *((InetHost *) cursor);
cursor += sizeof(InetHost);
unpackedPref->fSubnetMask = *((InetHost *) cursor);
cursor += sizeof(InetHost);
// fAppleTalkZone is a Str32. A longer string in the 'iitf' preference causes an
A Remote Access network connection entity has a class of
kOTCfgClassNetworkConnection and a type of kOTCfgTypeModem. The entity
typically contains the following preferences:
■ kOTCfgModemGeneralPrefs, which contains the core modem preferences. For
details, see OTCfgModemGeneral (page 141).
■ kOTCfgModemLocksPref, which is used by the Modem control panel to
remember which preferences are locked. For details, see OTCfgModemLocks
(page 143).
When creating the kOTCfgModemGeneralPrefs preference, you have to supply the
name of a serial port that is visible to Open Transport. For information about
building a list of Open Transport serial ports and their user-visible names, see
54Protocol-specific Topics
encodedPassword,
sizeof(Str255));
CHAPTER 2
Using Network Setup
DTS Technote 1119 Serial Port Apocrypha available at
http://developer.apple.com/technotes/tn/tn1119.html.
Notes for Third Parties2
This section contains miscellaneous hints and tips for third-party developers
who want to use Network Setup to store their own preferences.
Storing Third-party Preferences in Apple Entities2
It is reasonable for third-party developers to store custom preferences inside
Apple Computer’s protocol entities. For example, a TCP/IP virtual private
network (VPN) implementation might store per-connection preferences inside
Apple Computer’s TCP/IP network connection entity. This is perfectly legal —
in fact it is encouraged — but you need to follow one important rule: The
preference type for your preference must be registered as a unique creator code
with DTS at
types will prevent two different developers from using the same preference
type for conflicting preferences.
If you're writing a third-party protocol stack, you can use the Network Setup
database to store your preferences in much the same way as the Apple protocol
stacks do. There are a few important things to remember.
■ It is recommended that you use the existing classes,
kOTCfgClassNetworkConnection and kOTCfgClassGlobalSettings, for your
global protocol and network connection entities.
■ You should register a unique creator code with DTS at
http://developer.apple.com/dev/cftype and use it as the type for your
entities. This will ensure that your work does not conflict with Apple
Computer or other developers.
Your protocol stack configurator should call OTCfgInstallNotifier (page 94) to
install a Network Setup notifier to watch for changes to its preferences by your
control panel or by third-party software.
Notes for Third Parties55
CHAPTER 2
Using Network Setup
56Notes for Third Parties
CHAPTER 3
Figure 3-0
Listing 3-0
Table 3-0
Network Setup Reference3
This chapter describes the functions, structures, and data types for calling
Network Setup. For protocol-specific preferences, see Chapter 4, “Network
Setup Protocol Structures and Data Types.”
Network Setup Functions3
The Network Setup functions are described in these sections:
■ “Opening and Closing the Network Setup Database” (page 57)
■ “Managing Areas” (page 59)
■ “Managing Entities” (page 72)
■ “Managing Preferences” (page 83)
■ “Preference Utilities” (page 92)
■ “Installing and Removing a Notification Callback” (page 94)
Opening and Closing the Network Setup Database3
Before attempting to call the Network Setup functions, you must open the
Network Setup database. Be sure to close the database when you are done. The
functions are:
■ OTCfgOpenDatabase (page 58) opens the Network Setup database.
■ OTCfgCloseDatabase (page 58) closes the Network Setup database.
On input, a pointer to a value of type CfgDatabaseRef (page 98).
On output, dbRef is a reference to the opened database that is
passed as a parameter to other Network Setup functions.
function result A value of noErr if the database was opened. For a list of other
possible result codes, see “Result Codes” (page 110).
DISCUSSION
The OTCfgOpenDatabase function opens a session with the Network Setup
database. Your application must call OTCfgOpenDatabase successfully before it
can call any other Network Setup function.
function result A value of noErr if the database was closed. For a list of other
A pointer to value of type CfgDatabaseRef (page 98) that
represents the database session you want to close.
possible result codes, see “Result Codes” (page 110).
DISCUSSION
The OTCfgCloseDatabase function closes the database session represented by
dbRef.
58Network Setup Functions
CHAPTER 3
Network Setup Reference
Note
Closing a database session automatically removes any
notification callback that has been installed for the session
represented by dbRef. ◆
Managing Areas3
The following functions manage areas in the Network Setup database:
■ OTCfgGetCurrentArea (page 60) obtains the default area in the database.
■ OTCfgSetCurrentArea (page 61) sets the default area in the database.
■ OTCfgOpenArea (page 61) opens an area in the database.
■ OTCfgCloseArea (page 62) closes an area in the database.
■ OTCfgBeginAreaModifications (page 63) creates a temporary area for
modifying the database.
■ OTCfgCommitAreaModifications (page 64) commits changes made in a
temporary area to the database.
■ OTCfgAbortAreaModifications (page 65) discards a temporary area and all
modifications made to it.
■ OTCfgIsSameAreaID (page 65) determines whether two area IDs are the same.
■ OTCfgGetAreaName (page 66) gets the name of an area in the database.
■ OTCfgSetAreaName (page 67) sets the name of an area in the database.
■ OTCfgGetAreasCount (page 68) obtains the number of areas in the database.
■ OTCfgGetAreasList (page 68) obtains the area IDs and area names in the
database.
■ OTCfgCreateArea (page 70) creates a new area in the database.
■ OTCfgDuplicateArea (page 71) copies the contents of an area to another area.
■ OTCfgDeleteArea (page 72) deletes an area in the database.
Network Setup Functions59
CHAPTER 3
Network Setup Reference
IMPORTANT
Areas other than the default area (also known as the
current area) do not affect any network setting, so many of
the area manipulation functions described in this section
are not commonly used. You rarely need to call
On input, a value of type CfgDatabaseRef (page 98) that
represents a database session previously opened by calling
OTCfgOpenDatabase (page 58).
areaIDOn input, a value of type CfgAreaID (page 98) containing the
areaID that identifies the area that is to be made active. If the
area does not exist, OTCfgSetCurrentArea returns
kCfgErrAreaNotFound.
function result A value of noErr indicates that OTCfgSetCurrentArea returned
successfully. For a list of other possible result codes, see “Result
Codes” (page 110).
The OTCfgSetCurrentArea function makes the area ID specified by the areaID
parameter the default area. The default area is sometimes referred to as the
current area.
WARNING
Do not change the default area. If you want to modify
settings, make changes to the entities within the default
area. ▲
OTCfgOpenArea3
Opens an area in the Network Setup database for reading.
OSStatus OTCfgOpenArea (CfgDatabaseRef dbRef,
CfgAreaID areaID);
Network Setup Functions61
CHAPTER 3
Network Setup Reference
dbRefOn input, a value of type CfgDatabaseRef (page 98) that
represents a database session previously opened by calling
OTCfgOpenDatabase (page 58).
areaIDOn input, a value of type CfgAreaID (page 98) that identifies the
area that is to be opened. If the area specified by areaID does not
exist, OTCfgOpenArea returns kCfgErrAreaNotFound.
function result A value of noErr indicates that OTCfgOpenArea returned
successfully. For a list of other possible result codes, see “Result
Codes” (page 110).
DISCUSSION
The OTCfgOpenArea function opens the specified area in the Network Setup
database for reading.
OTCfgCloseArea3
Closes an area in the Network Setup database.
OSStatus OTCfgCloseArea (CfgDatabaseRef dbRef,
dbRef
On input, a value of type CfgDatabaseRef (page 98) that
represents a database session previously opened by calling
OTCfgOpenDatabase (page 58).
areaIDOn input, a value of type CfgAreaID (page 98) that identifies the
area that is to be closed. If the area specified by areaID does not
exist, OTCfgCloseArea returns kCfgErrAreaNotFound.
function result A value of noErr indicates that OTCfgCloseArea returned
successfully. For a list of other possible result codes, see “Result
Codes” (page 110).
DISCUSSION
The OTCfgCloseArea function closes an area in the database that was previously
opened for reading by calling OTCfgOpenArea (page 61).
On input, a value of type CfgDatabaseRef (page 98) that
represents a database session previously opened by calling
OTCfgOpenDatabase (page 58).
readAreaIDOn input, a value of type CfgAreaID (page 98) obtained by
calling OTCfgGetCurrentArea (page 60). If the area specified by
readAreaID does not exist, OTCfgBeginAreaModifications returns
kCfgErrAreaNotFound.
writeAreaIDOn input, a pointer to a value of type CfgAreaID (page 98). On
output, writeAreaID points to a new area ID that your
application should use to modify, delete, enumerate, or read
data in the area.
function result A value of noErr indicates that OTCfgBeginAreaModifications
returned successfully. For a list of other possible result codes,
see “Result Codes” (page 110).
The OTCfgBeginAreaModifications function creates a temporary area and returns
in the writeAreaID parameter an area ID for it. The area ID for the temporary
area can be passed as a parameter to subsequent calls for creating or modifying
entities in the temporary area.
If you need to read the area’s original, unmodified data, you can continue using
readAreaID to do so.
IMPORTANT
Only one program can open an area of writing at any one
time. If another program has already opened the area for
writing, OTCfgBeginAreaModifications returns
kCfgErrConfigLocked. ▲
Network Setup Functions63
CHAPTER 3
Network Setup Reference
Call OTCfgCommitAreaModifications (page 64) to write the temporary area to the
area identified by writeAreaID, dispose of the temporary area, and close the area
represented by writeAreaID, or call OTCfgAbortAreaModifications (page 65) to
close the area represented by readAreaID and discard the temporary area.
OTCfgCommitAreaModifications3
Closes an area for writing and commits modifications.
function result A value of noErr indicates that OTCfgCommitAreaModifications
returned successfully. For a list of other possible result codes,
see “Result Codes” (page 110).
The OTCfgCommitAreaModifications function writes the temporary area
represented by writeAreaID to the area represented by readAreaID and closes the
write area.
Readers of the area represented by readAreaID are informed that the database
has been modified.
64Network Setup Functions
CHAPTER 3
Network Setup Reference
OTCfgAbortAreaModifications3
Closes an area for writing without committing modifications.
On input, a value of type CfgDatabaseRef (page 98) that
represents a database session previously opened by calling
OTCfgOpenDatabase (page 58).
readAreaIDOn input, a value of type CfgAreaID (page 98) that identifies an
area that has been opened for writing. If readAreaID does not
exist or you have not called OTCfgBeginAreaModifications
(page 63) for the area represented by readAreaID,
function result A value of noErr indicates that OTCfgAbortAreaModifications
returned successfully. For a list of other possible result codes,
see “Result Codes” (page 110).
DISCUSSION
The OTCfgAbortAreaModifications function closes an area that was opened for
writing without writing the modifications to the area presented by readAreaID.
OTCfgIsSameAreaID3
Compares two area IDs.
Boolean OTCfgIsSameAreaID (CfgAreaID areaID1,
CfgAreaID areaID2);
areaID1
On input, a value of type CfgAreaID (page 98) representing one
of the area IDs that is to be compared.
areaID2On input, a value of type CfgAreaID (page 98) representing the
other area ID that is to be compared.
Network Setup Functions65
CHAPTER 3
Network Setup Reference
function result A Boolean value that is TRUE if the area IDs are the same and
FALSE if the area IDs are different.
DISCUSSION
The OTCfgIsSameAreaID function determines whether two area IDs represent to
the same area.
OTCfgGetAreaName3
Obtains the user-visible name of an area.
OSStatus OTCfgGetAreaName (CfgDatabaseRef dbRef,
CfgAreaID areaID,
Str255 areaName);
DISCUSSION
dbRef
On input, a value of type CfgDatabaseRef (page 98) that
represents a database session previously opened by calling
OTCfgOpenDatabase (page 58).
areaIDOn input, a value of type CfgAreaID (page 98) that identifies the
area whose name is to be obtained. If the area specified by
areaID does not exist, OTCfgGetAreaName returns
kCfgErrAreaNotFound.
areaNameOn input, a value of type Str255. On output, areaName contains
the user-visible name of the area specified by areaID.
function result A value of noErr indicates that OTCfgGetAreaName returned
successfully. For a list of other possible result codes, see “Result
Codes” (page 110).
The OTCfgGetAreaName function gets the user-visible name of the specified area.
Note
The OTCfgGetAreaName function is available in Network
Setup version 1.0.1 and later. ◆
On input, a value of type CfgDatabaseRef (page 98) that
represents a database session previously opened by calling
OTCfgOpenDatabase (page 58).
itemCountOn input, a pointer to a value of type ItemCount that specifies
the number of areas for which information is requested. Call
OTCfgGetAreasCount (page 68) to determine the number of areas
68Network Setup Functions
CHAPTER 3
Network Setup Reference
that are available. On output, itemCount points to the number of
areas for which information was actually returned, which may
be less that expected if areas were deleted between calling
OTCfgGetAreasCount (page 68) and calling OTCfgGetAreasList.
areaIDOn input, an array of elements of type CfgAreaID (page 98) that
is large enough to hold the number of area IDs specified by
itemCount. On output, each array element contains an area ID. If
you don’t want to get area IDs, set areaID to NULL.
areaNameOn input, an array of elements of type Str255 that is large
enough to hold the number of area names specified by
itemCount. On output, each array element contains an area
name. The area name in the first element corresponds to the area
ID in the first element of the array specified by areaID, and so
on. If you don’t want to get area names, set areaName to NULL.
function result A value of noErr indicates that OTCfgGetAreasList returned
successfully. For a list of other possible result codes, see “Result
Codes” (page 110).
DISCUSSION
The OTCfgGetAreasList function obtains the IDs and names of areas in the
database and stores this information in two arrays: one containing area IDs and
the other containing area names. Each area ID and area name pair identifies an
area in the database.
When you allocate the arrays for the areaID and areaName parameters, be sure to
allocate enough elements to hold the number of areas returned by
OTCfgGetAreasCount (page 68). The actual number of items returned in each
array may be lower than the number returned by OTCfgGetAreasCount (page 68)
if areas have been deleted in the meantime.
Network Setup Functions69
CHAPTER 3
Network Setup Reference
OTCfgCreateArea3
Creates an area in the Network Setup database.
OSStatus OTCfgCreateArea (CfgDatabaseRef dbRef,
ConstStr255Param areaName,
CfgAreaID* areaID);
DISCUSSION
dbRef
On input, a value of type CfgDatabaseRef (page 98) that
represents a database session previously opened by calling
OTCfgOpenDatabase (page 58).
areaNameOn input, a value of type ConstStr255Param that specifies the
user-visible name of the area to create. If an area of the name
specified by areaName already exists, OTCfgCreateArea returns
kCfgErrAreaAlreadyExists.
areaIDOn input, a pointer to a value of type CfgAreaID (page 98). On
output, areaID contains the ID of the area that was created.
function result A value of noErr indicates that OTCfgCreateArea returned
successfully. For a list of other possible result codes, see “Result
Codes” (page 110).
The OTCfgCreateArea function creates an area of the specified name in the
database.
IMPORTANT
The OTCfgCreateArea function has almost no purpose in the
version of Network Setup described by this document. ◆
On input, a value of type CfgDatabaseRef (page 98) that
represents a database session previously opened by calling
OTCfgOpenDatabase (page 58).
areaIDOn input, a value of type CfgAreaID (page 98) that identifies the
area that is to be searched. If the area specified by areaID does
not exist, OTCfgGetEntitiesCount returns the error
kCfgErrAreaNotFound.
entityClassOn input, a value of type CfgEntityClass that specifies the class
that is to be matched. To specify all classes, set entityClass to
kCfgClassAnyEntity. For a list of possible classes, see “Entity
Classes and Types” (page 104).
entityTypeOn input, a value of type CfgEntityType that specifies the type
that is to be matched. To specify all types, set entityType to
kCfgTypeAnyEntity. For a list of possible types, see “Entity
Classes and Types” (page 104).
Network Setup Functions73
CHAPTER 3
Network Setup Reference
itemCountOn input, a pointer to a value of type ItemCount. On output,
itemCount contains the number of entities that matched the
specified class and type.
function result A value of noErr indicates that OTCfgGetEntitiesCount returned
successfully. For a list of other possible result codes, see “Result
Codes” (page 110).
DISCUSSION
The OTCfgGetEntitiesCount function obtains the number of entities of the
specified class and type in the specified area. With the number of entities, you
can call OTCfgGetEntitiesList (page 74) to get the list of entities in the area.
entityTypeOn input, a value of type CfgEntityType that specifies the type
that is to be matched. To specify all types, set entityType to
kCfgTypeAnyEntity. For a list of possible types, see “Entity
Classes and Types” (page 104).
itemCountOn input, a pointer to a value of type ItemCount that specifies
the number of entities to list. Call OTCfgGetEntitiesCount
(page 73) to get the current number of entities in the area
represented by areaID. On output, itemCount points to the
number of entities for which information was actually obtained.
entityRefOn input, an array of elements of type CfgEntityRef (page 99)
that is large enough to hold the number of entity references
specified by itemCount, or NULL if you do not want to receive
entity references. If not NULL on input, each element of the
entityRef array corresponds to an element of the entityInfo
array on output.
entityInfoOn input, an array of CfgEntityInfo (page 99) structures that is
large enough to hold the number of CfgEntityInfo structures
specified by itemCount, or NULL if you do not want to receive
CfgEntityInfo structures.
DISCUSSION
function result A value of noErr indicates that OTCfgGetEntitiesList returned
successfully. For a list of other possible result codes, see “Result
Codes” (page 110).
The OTCfgGetEntitiesList function obtains an array of entity references, each of
which represents an entity in the specified area, and an array of entity
information structures, each of which contains information about its respective
entity. The information includes the entity’s class, type, user-visible name, and
icon.
You can use the entity reference to call other Network Setup functions, such as
On input, a pointer to a value of type CfgEntityRef (page 99) for
one of the entity references that is to be compared.
entityRef2On input, a pointer to a value of type CfgEntityRef (page 99) for
the second entity reference that is to be compared.
ignoreAreaOn input, a Boolean value. If ignoreArea is kCfgIgnoreArea,
OTCfgIsSameEntityRef ignores the area ID when comparing
entityRef1 and entityRef2. If ignoreArea is kCfgDontIgnoreArea,
OTCfgIsSameEntityRef does not ignore the area ID when
comparing entityRef1 and entityRef2.
function result TRUE if the entity references represent the same entity; FALSE if
the entity references represent different entities.
DISCUSSION
The OTCfgIsSameEntityRef function determines whether two entity references
represent the same area. For a discussion of the circumstances in which calling
OTCfgIsSameEntityRef is particularly useful, see “Areas and Sets” (page 48).
dbRefOn input, a value of type CfgDatabaseRef (page 98) that
represents a database session previously opened by calling
OTCfgOpenDatabase (page 58).
areaIDOn input, a value of type CfgAreaID (page 98) that identifies the
area in which the entity is to be created. If the area specified by
areaID is not writable, OTCfgCreateEntity returns the error
kCfgErrLocked. If the area specified by areaID does not exist,
OTCfgCreateEntity returns the error kCfgErrAreaNotFound.
entityInfoOn input, a pointer to a CfgEntityInfo (page 99) structure that
specifies the class, type, user-visible name, and icon for the
entity that is to be created. If an entity of the specified name
already exists, OTCfgCreateEntity returns the error
kCfgErrEntityAlreadyExists.
entityRefOn input, a pointer to a value of type CfgEntityRef (page 99).
On output, entityRef points to an entity reference for the
created reference.
function result A value of noErr indicates that OTCfgCreateEntity returned
successfully. For a list of other possible result codes, see “Result
Codes” (page 110).
DISCUSSION
The OTCfgCreateEntity function creates an entity in the area specified by areaID
with the class, type, user-visible name, and icon specified by the entityInfo
parameter.
The area represented by areaID must have been opened by calling
OTCfgBeginAreaModifications (page 63).
The OTCfgCreateEntity function returns a reference to the created entity that can
be passed as a parameter to other Network Setup functions, such as
OTCfgOpenPrefs (page 84).
Network Setup Functions77
CHAPTER 3
Network Setup Reference
OTCfgDeleteEntity3
Deletes the specified entity.
OSStatus OTCfgDeleteEntity (CfgDatabaseRef dbRef,
const CfgEntityRef* entityRef);
dbRef
On input, a value of type CfgDatabaseRef (page 98) that
represents a database session previously opened by calling
OTCfgOpenDatabase (page 58).
entityRefOn input, a pointer to a value of type CfgEntityRef (page 99)
representing the entity that is to be deleted. If entityRef
represents an entity that does not reside in an area that is open
for writing, OTCfgDeleteEntity returns the error
kCfgErrAreaNotOpen or kCfgErrLocked. If the entity represented
by entityRef does not exist, OTCfgDeleteEntry returns the error
kCfgErrEntityNotFound.
function result A value of noErr indicates that OTCfgDeleteEntity returned
successfully. For a list of other possible result codes, see “Result
Codes” (page 110).
DISCUSSION
The OTCfgDeleteEntity function deletes the specified entity.
OTCfgDuplicateEntity3
Copies the contents of one entity to another entity.
entityRefOn input, a pointer to a value of type CfgEntityRef (page 99)
that identifies the entity reference that is to be duplicated. If the
entity represented by entityRef does not exist,
OTCfgDuplicateEntry returns the error kCfgErrEntityNotFound.
newEntityRef On input, a pointer to a value of type CfgEntityRef (page 99)
that identifies the entity that is to be overwritten by the contents
of entityRef. If entityRef represents an entity that does not
reside in an area that is open for writing, OTCfgDuplicateEntity
returns the error kCfgErrAreaNotOpen or kCfgErrLocked.
function result A value of noErr indicates that OTCfgDuplicateEntity returned
successfully. For a list of other possible result codes, see “Result
Codes” (page 110).
The OTCfgDuplicateEntity function copies the contents of the entity specified by
entityRef to the entity specified by newEntityRef. Any data stored in
newEntityRef before OTCfgDuplicateEntity is called is overwritten by the
contents of entityRef when OTCfgDuplicateEntity returns.
entityRefOn input, a pointer to a value of type CfgEntityRef (page 99)
entityNameOn input, a value of type Str255. On output, entityName contains
Network Setup Functions79
On input, a value of type CfgDatabaseRef (page 98) that
represents a database session previously opened by calling
OTCfgOpenDatabase (page 58).
that identifies the entity whose name is to be obtained. To obtain
the reference for an entity, call OTCfgGetEntitiesList (page 74).
the user-visible name of the entity represented by entityRef.
CHAPTER 3
Network Setup Reference
function result A value of noErr indicates that OTCfgGetEntityLogicalName
returned successfully. For a list of other possible result codes,
see “Result Codes” (page 110).
DISCUSSION
The OTCfgGetEntityLogicalName function obtains the user-visible name of the
entity represented by entityRef.
Note
The OTCfgGetEntityLogicalName function is available in
Network Setup 1.2 and later. If
OTCfgGetEntityLogicalName is not available, you can get
the user-visible name of an entity by calling OTCfgGetPrefs
(page 86) and specifying kOTCfgUserVisibleNamePref as the
preference to get. ◆
On input, a pointer to a value of type CfgEntityRef (page 99)
that identifies the entity whose name is to be obtained. To obtain
the reference for an entity, call OTCfgGetEntitiesList (page 74).
entityNameOn input, a value of type Str255. On output, entityName contains
the name of the entity represented by entityRef.
function result None.
DISCUSSION
The OTCfgGetEntityName function obtains the name of the entity represented by
entityRef.
80Network Setup Functions
Str255 entityName);
CHAPTER 3
▲
Network Setup Reference
WARNING
The OTCfgGetEntityName function does not return the
user-visible name of the entity. Instead, OTCfgGetEntityName
returns an internal name in entityName. To get the
user-visible name, call OTCfgGetPrefs (page 86) passing
kOTCfgUserVisibleNamePref in the prefsType parameter or
call OTCfgGetEntityLogicalName (page 79) if that function is
available. ▲
On input, a value of type CfgDatabaseRef (page 98) that
represents a database session previously opened by calling
OTCfgOpenDatabase (page 58).
entityRefOn input, a pointer to a value of type CfgEntityRef (page 99)
that represents the entity whose name is to be set. To obtain the
entity reference for an entity, call OTCfgGetEntitiesList
(page 74). If entityRef does not refer to a valid entity,
OTCfgSetEntityName returns the error kCfgEntityNotFoundErr.
entityNameOn input, a value of type ConstStr255Param that specifies the
new user-visible name for the entity.
newEntityRef On input, a pointer to a value of type CfgEntityRef (page 99).
On output, newEntityRef points to a new entity reference that
represents the renamed entity. Your application should use
newEntityRef for future references to the renamed entity.
function result A value of noErr indicates that OTCfgSetEntityName returned
successfully. For a list of other possible result codes, see “Result
Codes” (page 110).
Network Setup Functions81
CHAPTER 3
Network Setup Reference
DISCUSSION
The OTCfgSetEntityName function sets the user-visible name of the specified
entity and returns a new entity reference for the renamed entity.
On input, a pointer to a value of type CfgEntityRef (page 99)
that identifies the entity reference whose area is to be obtained.
To obtain the entity reference for an entity, call
OTCfgGetEntitiesList (page 74).
areaIDOn input, a pointer to a value of type CfgAreaID (page 98). On
output, areaID points to the area ID of the entity represented by
entityRef.
function result None.
DISCUSSION
The OTCfgGetEntityArea function obtains the area ID of the entity represented
by entityRef.
entityRefOn input, a pointer to a value of type CfgEntityRef (page 99)
that represents the entity reference whose area is to be changed.
To obtain the entity reference for an entity, call
OTCfgGetEntitiesList (page 74) or use the entity reference
returned by a Network Setup function that creates an entity.
newAreaIDOn input, a value of type CfgAreaID (page 98) that specifies the
new area ID for the specified entity.
function result None.
DISCUSSION
The OTCfgChangeEntityArea function changes the area ID of the specified entity.
This function does not actually move the entity. Instead, it changes the entity
reference to point to the same entity in the area specified by newAreaID.
Managing Preferences3
Use the following functions to manage preferences, which are stored in an
entity:
■ OTCfgOpenPrefs (page 84) opens an entity so that its preferences can be
accessed.
■ OTCfgClosePrefs (page 85) closes an entity.
■ OTCfgGetPrefsSize (page 85) gets the size of a preference.
■ OTCfgGetPrefs (page 86) gets the value of a preference.
■ OTCfgSetPrefs (page 87) sets the value of a preference.
■ OTCfgGetPrefsTOCCount (page 88) gets the number of preferences in an entity.
■ OTCfgGetPrefsTOC (page 89) gets a list of a preferences in an entity.
■ OTCfgGetDefault (page 90) gets the default value for a preference.
■ OTCfgDeletePrefs (page 90) deletes a preference from an entity.
■ OTCfgGetTemplate (page 91) gets a preference’s template.
Network Setup Functions83
CHAPTER 3
Network Setup Reference
OTCfgOpenPrefs3
Opens an entity so that its preferences can be accessed.
On input, a value of type CfgDatabaseRef (page 98) that
represents a database session previously opened by calling
OTCfgOpenDatabase (page 58).
entityRefOn input, a pointer to a value of type CfgEntityRef (page 99)
that represents the entity whose preferences are to be read or
written. If the entity does not exist, OTCfgOpenPrefs returns the
error kCfgErrEntityNotFound.
writerOn input, a Boolean value. If writer is TRUE, the entity
represented by entityRef must be in an area that was opened by
calling OTCfgBeginAreaModifications (page 63); otherwise,
OTCfgOpenPrefs returns the error kCfgErrLocked. If writer is
FALSE, the entity represented by entityRef must be in an open
area [opened by calling OTCfgBeginAreaModifications (page 63)
or OTCfgOpenArea (page 61)]; otherwise, OTCfgOpenPrefs returns
the error kCfgErrAreaNotOpen.
accessIDOn input, a pointer to a value of type CfgEntityAccessID
(page 100). On output, use accessID in subsequent calls to get
and set preferences.
function result A value of noErr indicates that OTCfgOpenPrefs returned
successfully. For a list of other possible result codes, see “Result
Codes” (page 110).
DISCUSSION
The OTCfgOpenPrefs function opens the specified entity so that your application
can get or set the value of the preferences the entity contains.
If the value of the writer parameter is TRUE, you can set preferences as well as
get preferences; otherwise, you can only get preferences.
On input, a value of type CfgEntityAccessID (page 100),
obtained by previously calling OTCfgOpenPrefs (page 84), that
identifies the entity that is to be closed.
function result A value of noErr indicates that OTCfgClosePrefs returned
successfully. For a list of other possible result codes, see “Result
Codes” (page 110).
DISCUSSION
The OTCfgClosePrefs function closes the specified entity.
On input, a value of type CfgEntityAccessID (page 100),
obtained by previously calling OTCfgOpenPrefs (page 84), that
identifies the entity containing the preference whose size is to be
obtained.
prefsTypeOn input, a value of type prefsType that identifies the type of
the preference whose size is to be obtained.
lengthOn input, a pointer to a value of type ByteCount. On output,
length contains the size in bytes of the preference specified by
prefsType.
Network Setup Functions85
CHAPTER 3
Network Setup Reference
function result A value of noErr indicates that OTCfgGetPrefsSize returned
successfully. For a list of other possible result codes, see “Result
Codes” (page 110).
DISCUSSION
The OTCfgGetPrefsSize function gets the size in bytes of the preference specified
by prefsType in the entity represented by accessID.
For variable-length preferences, you should call OTCfgGetPrefsSize to get the
size of a preference before it calls OTCfgGetPrefs (page 86) to get the value of
that preference.
On input, a value of type CfgEntityAccessID (page 100),
obtained by previously calling OTCfgOpenPrefs (page 84), that
identifies the entity containing the preference whose value is to
be obtained.
prefsTypeOn input, a value of type OSType that identifies the preference
whose value is to be obtained. See“Protocol Constants and
Other Data Types” (page 159) for protocol-specific preferences.
dataOn input, a pointer to the buffer into which the value of the
preference is to be placed. On output, data contains the value of
the preference specified by prefsType.
lengthOn input, a value of type ByteCount that is the size in bytes of
the buffer pointed to by data.
function result A value of noErr indicates that OTCfgGetPrefs returned
successfully. For a list of other possible result codes, see “Result
Codes” (page 110).
86Network Setup Functions
CHAPTER 3
Network Setup Reference
DISCUSSION
The OTCfgGetPrefs function gets the value of the preference specified by
prefsType in the entity represented by accessID and stores it in data.
Before calling OTCfgGetPrefs, you may call OTCfgGetPrefsSize (page 85) to
obtain the size of the entity so that you can allocate a data parameter of the
appropriate size.
If the data parameter is too small to hold the value, OTCfgGetPrefs stores as
much of the value in data as possible and returns the error
On input, a value of type CfgEntityAccessID (page 100),
obtained by previously calling OTCfgOpenPrefs (page 84). The
entity in which the preference represented by accessID resides
must itself reside in an area that has been opened for writing by
calling OTCfgBeginAreaModifications (page 63).
prefsTypeOn input, a value of type OSType that identifies the preference to
set. If a preference of the type specified by prefsType already
exists OTCfgSetPrefs overwrites the value of the preference.
Otherwise, OTCfgSetPrefs creates the new preference.
dataOn input, a pointer to the data that is to be set.
lengthOn input, a value of type ByteCount that contains the length in
bytes of the data in data.
function result A value of noErr indicates that OTCfgSetPrefs returned
successfully. For a list of other possible result codes, see “Result
Codes” (page 110).
Network Setup Functions87
CHAPTER 3
Network Setup Reference
DISCUSSION
The OTCfgSetPrefs function sets the preference represented by prefsType to the
value specified by data.
The accessID parameter must have been created by calling OTCfgOpenPrefs
(page 84) with the writer parameter set to TRUE; otherwise, OTCfgSetPrefs
returns the error kCfgErrLocked.
On input, a value of type CfgEntityAccessID (page 100),
obtained by previously calling OTCfgOpenPrefs (page 84) that
identifies the entity whose preferences are to be counted.
itemCountOn input, a pointer to a value of type ItemCount. On output,
itemCount contains the number of preferences in the entity
represented by accessID.
function result A value of noErr indicates that OTCfgGetPrefsTOCCount returned
successfully. For a list of other possible result codes, see “Result
Codes” (page 110).
The OTCfgGetPrefsTOCCount function gets the number of preferences in the entity
represented by accessID.
You should call OTCfgPrefsTOCCount to find out how many preferences are
present before calling OTCfgGetPrefsTOC (page 89).
On input, a value of type CfgEntityAccessID (page 100),
obtained by previously calling OTCfgOpenPrefs (page 84) that
identifies the entity whose preferences are to be obtained.
itemCountOn input, a pointer to a value of type ItemCount that specifies
the requested number of preferences. On output, itemCount
contains the number of preferences that were obtained.
prefsTOCOn input, an array of CfgPrefsHeader (page 100) structures. The
prefsTOC parameter must have enough CfgPrefsHeader
structures to store all of the preferences in the entity.
function result A value of noErr indicates that OTCfgGetPrefsTOC returned
successfully. For a list of other possible result codes, see “Result
Codes” (page 110).
The OTCfgGetPrefsTOC function obtains information about the specified number
preferences in the entity represented by accessID and stores them in the
prefsTOC array.
Before you call OTCfgPrefsTOC, you must should find out how many preferences
are available by calling OTCfgGetPrefsTOCCount (page 88).
WARNING
Early versions of Network Setup do not determine whether
there is enough space in prefsTOC (as specified on input by
itemCount) and can write beyond the end of the array. You
should always call OTCfgGetPrefsTOCCount before calling
OTCfgGetPrefsTOC. When you call OTCfgGetPrefsTOC, set
itemCount to the value returned by OTCfgGetPrefsTOCCount
in the
itemCount parameter. ▲
Network Setup Functions89
CHAPTER 3
Network Setup Reference
OTCfgGetDefault3
Returns a handle containing the default value for a preference.
Handle OTCfgGetDefault (OSType entityType,
OSType entityClass,
OSType prefsType);
DISCUSSION
entityType
On input, a value of type OSType that identifies the entity type of
the default preference that is to be obtained. For possible values,
see “Entity Classes and Types” (page 104).
entityClassOn input, a value of type OSType that identifies the entity class of
the default preference that is to be obtained. For possible values,
see “Entity Classes and Types” (page 104).
prefsTypeOn input, a value of type OSType that identifies the preference
whose default value is to be obtained.
function result A handle or NULL if no preference of the specified entity type,
class, and preference type exists, or if there is not enough
memory to obtain the handle.
The OTCfgGetDefault function returns a handle containing the default value for
a preference of the specified entity, class, and preference type.
Note
You are responsible for disposing of the handle that
OTCfgGetDefault obtains by calling the Memory Manager
entityTypeOn input, a value of type CfgEntityType that specifies the type of
prefsTypeOn input, a value of type OSType that specifies the preference
Network Setup Functions91
On input, a value of type CfgEntityClass that specifies the class
of the preference whose default value is to be obtained.
the preference whose default value is to be obtained.
type of the preference whose default value is to be obtained.
DISCUSSION
CHAPTER 3
Network Setup Reference
dataOn input, a pointer to the buffer into which the default value is
to be placed. On output, data points to the default value. If the
buffer is too small to hold the default value, OTCfgGetTemplate
returns as much data as possible and returns the error
kCFGErrDataTruncated. If you want to get the size of the default
value but not the default value itself, set data to NULL.
dataSizeOn input, a pointer to a value of type ByteCount. On output,
dataSize points to the number of bytes in the buffer pointed to
by data. On input, if data is NULL, on output, dataSize points to
the size in bytes of the default value for the specified preference.
function result A value of noErr indicates that OTCfgGetTemplate returned
successfully. For a list of other possible result codes, see “Result
Codes” (page 110).
The OTCfgGetTemplate function gets the default value for the preference
identified by the entityClass, entityType, and prefsType parameters and stores
it in the buffer described by data and dataSize.
IMPORTANT
The OTCfgGetTemplate function is available in Network
Setup version 1.2 and later. It returns the same data that
OTCfgGetDefault (page 90) returns, but the parameters have
been changed to be consistent with the parameters of other
Network Setup functions. If you rely on Network Setup 1.2
or later, call OTCfgGetTemplate. If you need to work with
earlier versions of Network Setup, you can safely continue
to call OTCfgGetDefault. ▲
Preference Utilities3
Use the following functions to encrypt and decrypt preferences:
■ OTCfgDecrypt (page 93) decrypts data.
■ OTCfgEncrypt (page 93) encrypts data.
92Network Setup Functions
CHAPTER 3
Network Setup Reference
OTCfgEncrypt3
Encrypts data.
SInt16 OTCCfgEncrypt (const UInt8 *key.
UInt8 *data,
SInt16 dataLen);
key
On input, a pointer to a Pascal string containing the encryption
key. For Remote Access password, the encryption key is a user
name.
dataOn input, a pointer to an array of bytes that contains data that is
to be encrypted. Usually, the data is a password. On output,
data contains the encrypted password.
dataLenOn input, a value of type SInt16 that specifies the number of
bytes in the data array.
function result The length of the encrypted data.
DISCUSSION
The OTCfgEncrypt function encrypts the contents of the data parameter using the
key specified by the key parameter. For sample code, see Listing 2-17 in Chapter
2, “Using Network Setup.”
Note
The OTCCfgEncrypt function is available in Network Setup
version 1.1 and later. ◆
OTCfgDecrypt3
Decrypts data.
SInt16 OTCCfgDecrypt (const UInt8 *key.
UInt8 *data,
SInt16 dataLen);
Network Setup Functions93
DISCUSSION
CHAPTER 3
Network Setup Reference
keyOn input, a pointer to a Pascal string containing the encryption
key. Usually the encryption key is a user name.
dataOn input, a pointer to an array of bytes containing data that was
previously encrypted by OTCfgEncrypt (page 93). On output,
data contains the decrypted data.
dataLenOn input, a value of type SInt16 that specifies the length of data.
function result The length in bytes of the decrypted data.
The OTCfgDecrypt function decrypts the contents of the data parameter using
the key specified by the key parameter.
Note
The OTCCfgDecrypt function is available in Network Setup
version 1.1 and later. ◆
Installing and Removing a Notification Callback3
You can use the following functions to install and remove a notification
callback:
■ OTCfgInstallNotifier (page 94) installs a notification callback.
■ OTCfgRemoveNotifier (page 96) removes a notification callback.
dbRefOn input, a value of type CfgDatabaseRef (page 98) that
represents a database session previously opened by calling
OTCfgOpenDatabase (page 58).
theClassOn input, a value of type CfgEntityClass that specifies the class
for which the notification callback is to be called. For possible
values, see the constants described in “Entity Classes and
Types” (page 104). Constants that define wildcards are valid.
theTypeOn input, a value of type CfgEntityType that specifies the type
for which the notification callback is to be called. For possible
values, see the constants described in “Entity Classes and
Types” (page 104). Constants that define wildcards are valid.
notifierOn input, a value of type OTNotifyProcPtr that points to the
notification callback that is to be installed.
contextPtrOn input, a pointer to an arbitrary data type that is passed to the
notification callback when it is called.
function result A value of noErr indicates that OTCfgInstallNotifier returned
successfully. For a list of other possible result codes, see “Result
Codes” (page 110)
DISCUSSION
The OTCfgInstallNotifier function installs a notification callback that is called
when changes to preferences of the specified class and type occur. Calling
OTCfgInstallNotifier when you have already installed a notification callback
causes the current notification callback to be replaced by the new notification
callback.
Note
The OTCfgInstallNotifier function is available in Network
Setup version 1.0.2 and later. ◆
To remove an installed notification callback, call OTCfgRemoveNotifier (page 96).
Notification callbacks are removed automatically when the database session
represented by dbRef is closed.
A pointer to the untyped value that was specified when you
called OTCfgInstallNotifier (page 94) to install the notification
callback routine.
codeA value of type OTEventCode.Your notification callback routine
should ignore callbacks when this is any value other than
kCfgDatabaseChanged.
resultA notification-dependent value of type OSStatus. When the
value of code is kCfgDatabaseChanged, the value of result is
kCfgErrDatabaseChanged.
cookieReserved.
DISCUSSION
Your notification callback routine is called at system task time (but not
necessarily in the context of your application) when a change occurs to the
database. When your notification callback routine is called, you should reread
any preferences that were previously read.
Network Setup Structures and Data Types3
This section describes structures used by the Network Setup functions. The
structures and data types are
■ CfgDatabaseRef (page 98), which refers to an open database session.
■ CfgAreaID (page 98), which identifies an area.
■ CfgEntityRef (page 99), which refers to an open entity.
Network Setup Structures and Data Types97
CHAPTER 3
Network Setup Reference
■ CfgEntityInfo (page 99), which contains information about the entities in an
area.
■ CfgEntityAccessID (page 100), which identifies an open preference within an
entity.
■ CfgPrefsHeader (page 100), which is used to return information about the
preferences within an entity.
■ CfgSetsStruct (page 101), which stores information about a set entity.
■ CfgSetsElement (page 103), which represents an element in a CfgSetsVector
(page 103) structure.
■ CfgSetsVector (page 103), which stores references to a set of entities.
CfgDatabaseRef3
A value of type CfgDatabaseRef refers to an open session with the Network
Setup database.
A pointer to an opaque value that identifies the open
session.
Call OTCfgOpenDatabase (page 58) to open the database and obtain a value of
type CfgDatabaseRef. Network Setup requires a value of type CfgDatabaseRef to
open an area, make changes in an area, list and create entities in an area, and to
open an entity.
A CfgDatabaseRef whose value is NULL is never a valid database reference.
CfgAreaID3
A value of type CfgAreaID identifies an area.
typedef UInt32 CfgAreaID;
CfgAreaID
98Network Setup Structures and Data Types
An unsigned 32-bit value that uniquely identifies an area.
CHAPTER 3
Network Setup Reference
Network Setup uses a value of type CfgAreaID to identify the area in which an
entity resides. For example, a value of type CfgAreaID is a member of the
CfgEntityRef (page 99) structure. Use the constant kInvalidCfgAreaID (page 109)
to determine whether an area ID is valid.
CfgEntityRef3
A CfgEntityRef structure refers to a specific entity.
For example, OTCfgCreateEntity (page 76) returns a CfgEntityRef structure to
refer to the newly created entity, and OTCfgGetEntitiesList (page 74) returns a
CfgEntityRef for each entity in an area.
CfgEntityInfo3
The CfgEntityInfo structure stores various attributes of an entity.