1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3
* The contents of this file are subject to the Netscape Public
4
* License Version 1.1 (the "License"); you may not use this file
5
* except in compliance with the License. You may obtain a copy of
6
* the License at http://www.mozilla.org/NPL/
8
* Software distributed under the License is distributed on an "AS
9
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10
* implied. See the License for the specific language governing
11
* rights and limitations under the License.
13
* The Original Code is Mozilla Communicator client code,
14
* released March 31, 1998.
16
* The Initial Developer of the Original Code is Netscape Communications
17
* Corporation. Portions created by Netscape are
18
* Copyright (C) 1998 Netscape Communications Corporation. All
22
* Daniel Veditz <dveditz@netscape.com>
29
typedef void (*nr_RegPackCallbackFunc) (void *userData, int32 bytes, int32 totalBytes);
33
typedef uint32 REGENUM;
36
typedef struct _reginfo
38
uint16 size; /* must be initialized to sizeof(REGINFO) */
44
#define REGERR_FAIL (1)
45
#define REGERR_NOMORE (2)
46
#define REGERR_NOFIND (3)
47
#define REGERR_BADREAD (4)
48
#define REGERR_BADLOCN (5)
49
#define REGERR_PARAM (6)
50
#define REGERR_BADMAGIC (7)
51
#define REGERR_BADCHECK (8)
52
#define REGERR_NOFILE (9)
53
#define REGERR_MEMORY (10)
54
#define REGERR_BUFTOOSMALL (11)
55
#define REGERR_NAMETOOLONG (12)
56
#define REGERR_REGVERSION (13)
57
#define REGERR_DELETED (14)
58
#define REGERR_BADTYPE (15)
59
#define REGERR_NOPATH (16)
60
#define REGERR_BADNAME (17)
61
#define REGERR_READONLY (18)
62
#define REGERR_BADUTF8 (19)
65
/* Total path length */
66
#define MAXREGPATHLEN (2048)
67
/* Name on the path (including null terminator) */
68
#define MAXREGNAMELEN (512)
69
/* Value of an entry */
70
#define MAXREGVALUELEN (0x7FFF)
73
#define ROOTKEY_USERS (0x01)
74
#define ROOTKEY_COMMON (0x02)
75
#define ROOTKEY_CURRENT_USER (0x03)
76
#define ROOTKEY_PRIVATE (0x04)
78
/* enumeration styles */
79
#define REGENUM_NORMAL (0x00)
80
#define REGENUM_CHILDREN REGENUM_NORMAL
81
#define REGENUM_DESCEND (0x01)
82
#define REGENUM_DEPTH_FIRST (0x02)
84
/* entry data types */
85
#define REGTYPE_ENTRY (0x0010)
86
#define REGTYPE_ENTRY_STRING_UTF (REGTYPE_ENTRY + 1)
87
#define REGTYPE_ENTRY_INT32_ARRAY (REGTYPE_ENTRY + 2)
88
#define REGTYPE_ENTRY_BYTES (REGTYPE_ENTRY + 3)
89
#define REGTYPE_ENTRY_FILE (REGTYPE_ENTRY + 4)
91
#define REG_DELETE_LIST_KEY "Mozilla/XPInstall/Delete List"
92
#define REG_REPLACE_LIST_KEY "Mozilla/XPInstall/Replace List"
93
#define REG_UNINSTALL_DIR "Mozilla/XPInstall/Uninstall/"
94
#define REG_REPLACE_SRCFILE "ReplacementFile"
95
#define REG_REPLACE_DESTFILE "DestinationFile"
97
#define UNINSTALL_NAV_STR "_"
100
#define UNIX_GLOBAL_FLAG "MOZILLA_SHARED_REGISTRY"
102
/* Platform-dependent declspec for library interface */
105
#if defined (STANDALONE_REGISTRY)
106
#define VR_INTERFACE(type) __declspec(dllexport) type __cdecl
108
#define VR_INTERFACE(type) __declspec(dllexport) type __stdcall
112
#define VR_INTERFACE(type) type _far _pascal _export
115
#define VR_INTERFACE(__x) __declspec(export) __x
117
#define VR_INTERFACE(type) type
124
/* ---------------------------------------------------------------------
125
* Registry API -- General
126
* ---------------------------------------------------------------------
130
/* ---------------------------------------------------------------------
131
* NR_RegSetBufferSize - Sets the file buffer size
134
* hReg - handle to opened registry
135
* bufsize - size of the new buffer
138
* ---------------------------------------------------------------------
139
* returns the size of the buffer or -1 for err
141
VR_INTERFACE(int) NR_RegSetBufferSize(
142
HREG hReg, /* handle to opened registry */
147
/* ---------------------------------------------------------------------
148
* NR_RegOpen - Open a netscape XP registry
151
* filename - registry file to open. NULL or "" opens the standard
153
* hReg - OUT: handle to opened registry
156
* ---------------------------------------------------------------------
158
VR_INTERFACE(REGERR) NR_RegOpen(
159
const char *filename, /* reg. file to open (NULL == standard registry) */
160
HREG *hReg /* OUT: handle to opened registry */
164
/* ---------------------------------------------------------------------
165
* NR_RegClose - Close a netscape XP registry
168
* hReg - handle of open registry to be closed.
170
* After calling this routine the handle is no longer valid
171
* ---------------------------------------------------------------------
173
VR_INTERFACE(REGERR) NR_RegClose(
174
HREG hReg /* handle of open registry to close */
178
/* ---------------------------------------------------------------------
179
* NR_RegFlush - Manually flush data in a netscape XP registry
182
* hReg - handle of open registry to be flushed.
184
* ---------------------------------------------------------------------
186
VR_INTERFACE(REGERR) NR_RegFlush(
187
HREG hReg /* handle of open registry to flush */
191
/* ---------------------------------------------------------------------
192
* NR_RegIsWritable - Check read/write status of open registry
195
* hReg - handle of open registry to query
197
* REGERR_OK if writable, REGERR_READONLY if not, possibly
198
* other errors for an invalid hReg
199
* ---------------------------------------------------------------------
201
VR_INTERFACE(REGERR) NR_RegIsWritable(
202
HREG hReg /* handle of open registry to query */
205
VR_INTERFACE(REGERR) NR_RegPack(
206
HREG hReg, /* handle of open registry to pack */
208
nr_RegPackCallbackFunc fn
212
/* ---------------------------------------------------------------------
213
* NR_RegSetUsername - Set the current username
215
* If the current user profile name is not set then trying to use
216
* HKEY_CURRENT_USER will result in an error.
219
* name - name of the current user
222
* ---------------------------------------------------------------------
224
VR_INTERFACE(REGERR) NR_RegSetUsername(
225
const char *name /* name of current user */
229
/* ---------------------------------------------------------------------
230
* NR_RegGetUniqueName
232
* Returns a unique name that can be used for anonymous key/value names
235
* hReg - handle of open registry
236
* outbuf - where to put the string
237
* buflen - how big the buffer is
238
* ---------------------------------------------------------------------
240
VR_INTERFACE(REGERR) NR_RegGetUniqueName(
241
HREG hReg, /* handle of open registry */
242
char* outbuf, /* buffer to hold key name */
243
uint32 buflen /* size of buffer */
247
/* ---------------------------------------------------------------------
248
* DO NOT USE -- Will be removed
249
* ---------------------------------------------------------------------
251
VR_INTERFACE(REGERR) NR_RegGetUsername(
252
char **name /* on return, an alloc'ed copy of the current user name */
260
/* ---------------------------------------------------------------------
261
* Registry API -- Key Management functions
262
* ---------------------------------------------------------------------
265
/* ---------------------------------------------------------------------
266
* NR_RegAddKey - Add a key node to the registry
268
* Can also be used to find an existing node for convenience.
271
* hReg - handle of open registry
272
* key - registry key obtained from NR_RegGetKey(),
273
* or one of the standard top-level keys
274
* path - relative path of key to be added. Intermediate
275
* nodes will be added if necessary.
276
* newkey - If not null returns RKEY of new or found node
277
* ---------------------------------------------------------------------
279
VR_INTERFACE(REGERR) NR_RegAddKey(
280
HREG hReg, /* handle of open registry */
281
RKEY key, /* root key */
282
char *path, /* relative path of subkey to add */
283
RKEY *newKey /* if not null returns newly created key */
287
/* ---------------------------------------------------------------------
288
* NR_RegAddKeyRaw - Add a key node to the registry
290
* This routine is different from NR_RegAddKey() in that it takes
291
* a keyname rather than a path.
294
* hReg - handle of open registry
295
* key - registry key obtained from NR_RegGetKey(),
296
* or one of the standard top-level keys
297
* keyname - name of key to be added. No parsing of this
299
* newkey - if not null the RKEY of the new key is returned
300
* ---------------------------------------------------------------------
302
VR_INTERFACE(REGERR) NR_RegAddKeyRaw(
303
HREG hReg, /* handle of open registry */
304
RKEY key, /* root key */
305
char *keyname, /* name of key to add */
306
RKEY *newKey /* if not null returns newly created key */
310
/* ---------------------------------------------------------------------
311
* NR_RegDeleteKey - Delete the specified key
313
* Note that delete simply orphans blocks and makes no attempt
314
* to reclaim space in the file. Use NR_RegPack()
316
* Cannot be used to delete keys with child keys
319
* hReg - handle of open registry
320
* key - starting node RKEY, typically one of the standard ones.
321
* path - relative path of key to delete
322
* ---------------------------------------------------------------------
324
VR_INTERFACE(REGERR) NR_RegDeleteKey(
325
HREG hReg, /* handle of open registry */
326
RKEY key, /* root key */
327
char *path /* relative path of subkey to delete */
331
/* ---------------------------------------------------------------------
332
* NR_RegDeleteKeyRaw - Delete the specified raw key
334
* Note that delete simply orphans blocks and makes no attempt
335
* to reclaim space in the file. Use NR_RegPack()
338
* hReg - handle of open registry
339
* key - RKEY or parent to the raw key you wish to delete
340
* keyname - name of child key to delete
341
* ---------------------------------------------------------------------
343
VR_INTERFACE(REGERR) NR_RegDeleteKeyRaw(
344
HREG hReg, /* handle of open registry */
345
RKEY key, /* root key */
346
char *keyname /* name subkey to delete */
350
/* ---------------------------------------------------------------------
351
* NR_RegGetKey - Get the RKEY value of a node from its path
354
* hReg - handle of open registry
355
* key - starting node RKEY, typically one of the standard ones.
356
* path - relative path of key to find. (a blank path just gives you
357
* the starting key--useful for verification, VersionRegistry)
358
* result - if successful the RKEY of the specified sub-key
359
* ---------------------------------------------------------------------
361
VR_INTERFACE(REGERR) NR_RegGetKey(
362
HREG hReg, /* handle of open registry */
363
RKEY key, /* root key */
364
const char *path, /* relative path of subkey to find */
365
RKEY *result /* returns RKEY of specified sub-key */
369
/* ---------------------------------------------------------------------
370
* NR_RegGetKeyRaw - Get the RKEY value of a node from its keyname
373
* hReg - handle of open registry
374
* key - starting node RKEY, typically one of the standard ones.
375
* keyname - keyname of key to find. (a blank keyname just gives you
376
* the starting key--useful for verification, VersionRegistry)
377
* result - if successful the RKEY of the specified sub-key
378
* ---------------------------------------------------------------------
380
VR_INTERFACE(REGERR) NR_RegGetKeyRaw(
381
HREG hReg, /* handle of open registry */
382
RKEY key, /* root key */
383
char *keyname, /* name of key to get */
384
RKEY *result /* returns RKEY of specified sub-key */
388
/* ---------------------------------------------------------------------
389
* NR_RegEnumSubkeys - Enumerate the subkey names for the specified key
391
* Returns REGERR_NOMORE at end of enumeration.
394
* hReg - handle of open registry
395
* key - RKEY of key to enumerate--obtain with NR_RegGetKey()
396
* eState - enumerations state, must contain NULL to start
397
* buffer - location to store subkey names. Once an enumeration
398
* is started user must not modify contents since values
399
* are built using the previous contents.
400
* bufsize - size of buffer for names
401
* style - 0 returns direct child keys only, REGENUM_DESCEND
402
* returns entire sub-tree
403
* ---------------------------------------------------------------------
405
VR_INTERFACE(REGERR) NR_RegEnumSubkeys(
406
HREG hReg, /* handle of open registry */
407
RKEY key, /* containing key */
408
REGENUM *state, /* enum state, must be NULL to start */
409
char *buffer, /* buffer for entry names */
410
uint32 bufsize, /* size of buffer */
411
uint32 style /* 0: children only; REGENUM_DESCEND: sub-tree */
416
/* ---------------------------------------------------------------------
417
* Registry API -- Entry Management functions
418
* ---------------------------------------------------------------------
422
/* ---------------------------------------------------------------------
423
* NR_RegGetEntryInfo - Get some basic info about the entry data
426
* hReg - handle of open registry
427
* key - RKEY of key that contains entry--obtain with NR_RegGetKey()
428
* name - name of entry
429
* info - return: Entry info object
430
* ---------------------------------------------------------------------
432
VR_INTERFACE(REGERR) NR_RegGetEntryInfo(
433
HREG hReg, /* handle of open registry */
434
RKEY key, /* containing key */
435
char *name, /* entry name */
436
REGINFO *info /* returned entry info */
440
/* ---------------------------------------------------------------------
441
* NR_RegGetEntryString - Get the UTF string value associated with the
442
* named entry of the specified key.
445
* hReg - handle of open registry
446
* key - RKEY of key that contains entry--obtain with NR_RegGetKey()
447
* name - name of entry
448
* buffer - destination for string
449
* bufsize - size of buffer
450
* ---------------------------------------------------------------------
452
VR_INTERFACE(REGERR) NR_RegGetEntryString(
453
HREG hReg, /* handle of open registry */
454
RKEY key, /* containing key */
455
char *name, /* entry name */
456
char *buffer, /* buffer to hold value (UTF String) */
457
uint32 bufsize /* length of buffer */
460
/* ---------------------------------------------------------------------
461
* NR_RegGetEntry - Get the value data associated with the
462
* named entry of the specified key.
465
* hReg - handle of open registry
466
* key - RKEY of key that contains entry--obtain with NR_RegGetKey()
467
* name - name of entry
468
* buffer - destination for data
469
* size - in: size of buffer
470
* out: size of actual data (incl. \0 term. for strings)
471
* ---------------------------------------------------------------------
473
VR_INTERFACE(REGERR) NR_RegGetEntry(
474
HREG hReg, /* handle of open registry */
475
RKEY key, /* containing key */
476
char *name, /* entry name */
477
void *buffer, /* buffer to hold value */
478
uint32 *size /* in:length of buffer */
479
); /* out: data length, >>includes<< null terminator*/
482
/* ---------------------------------------------------------------------
483
* NR_RegSetEntryString - Store a UTF-8 string value associated with the
484
* named entry of the specified key. Used for
485
* both creation and update.
488
* hReg - handle of open registry
489
* key - RKEY of key that contains entry--obtain with NR_RegGetKey()
490
* name - name of entry
491
* buffer - UTF-8 String to store
492
* ---------------------------------------------------------------------
494
VR_INTERFACE(REGERR) NR_RegSetEntryString(
495
HREG hReg, /* handle of open registry */
496
RKEY key, /* containing key */
497
char *name, /* entry name */
498
char *buffer /* UTF String value */
502
/* ---------------------------------------------------------------------
503
* NR_RegSetEntry - Store value data associated with the named entry
504
* of the specified key. Used for both creation and update.
507
* hReg - handle of open registry
508
* key - RKEY of key that contains entry--obtain with NR_RegGetKey()
509
* name - name of entry
510
* type - type of data to be stored
511
* buffer - data to store
512
* size - length of data to store in bytes
513
* ---------------------------------------------------------------------
515
VR_INTERFACE(REGERR) NR_RegSetEntry(
516
HREG hReg, /* handle of open registry */
517
RKEY key, /* containing key */
518
char *name, /* entry name */
519
uint16 type, /* type of value data */
520
void *buffer, /* data buffer */
521
uint32 size /* data length in bytes; incl. null term for strings */
525
/* ---------------------------------------------------------------------
526
* NR_RegDeleteEntry - Delete the named entry
529
* hReg - handle of open registry
530
* key - RKEY of key that contains entry--obtain with NR_RegGetKey()
531
* name - name of entry
532
* ---------------------------------------------------------------------
534
VR_INTERFACE(REGERR) NR_RegDeleteEntry(
535
HREG hReg, /* handle of open registry */
536
RKEY key, /* containing key */
537
char *name /* value name */
541
/* ---------------------------------------------------------------------
542
* NR_RegEnumEntries - Enumerate the entry names for the specified key
544
* Returns REGERR_NOMORE at end of enumeration.
547
* hReg - handle of open registry
548
* key - RKEY of key that contains entry--obtain with NR_RegGetKey()
549
* eState - enumerations state, must contain NULL to start
550
* buffer - location to store entry names
551
* bufsize - size of buffer for names
552
* ---------------------------------------------------------------------
554
VR_INTERFACE(REGERR) NR_RegEnumEntries(
555
HREG hReg, /* handle of open registry */
556
RKEY key, /* containing key */
557
REGENUM *state, /* enum state, must be NULL to start */
558
char *buffer, /* buffer for entry names */
559
uint32 bufsize, /* size of buffer */
560
REGINFO *info /* optional; returns info about entry */
564
VR_INTERFACE(void) NR_ShutdownRegistry(void);
565
VR_INTERFACE(REGERR) NR_StartupRegistry(void);
570
#endif /* _NSREG_H_ */