Apple Network Setup manual Reading Variable-size Preferences

Models: Network Setup

1 184
Download 184 pages 5.56 Kb
Page 37
Image 37
Reading Variable-size Preferences

C H A P T E R 2

Using Network Setup

IMPORTANT

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 Preferences

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

static OSStatus MyGetEntityUserVisibleName(CfgDatabaseRef dbRef, const CfgEntityRef *entity, Str255 name)

{

OSStatus err;

assert(dbRef != nil); assert(entity != nil); assert(name != nil);

err = MyReadFixedSizePref(dbRef, entity, kOTCfgUserVisibleNamePref, name, sizeof(Str255));

return err;

}

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 OTCfgGetPrefs. You can get this information

Reading and Writing Preferences

37

Page 37
Image 37
Apple Network Setup manual Reading Variable-size Preferences, assertdbRef != nil assertentity != nil assertname != nil