Libinfo-278.0.3.tar.gz
[apple/libinfo.git] / lookup.subproj / lu_utils.h
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24 /*
25 * Useful macros and other stuff for generic lookups
26 * Copyright (C) 1989 by NeXT, Inc.
27 */
28
29 #ifndef _LU_UTILS_H_
30 #define _LU_UTILS_H_
31
32 #include "DSlibinfoMIG_types.h"
33 #include "kvbuf.h"
34 #include <stdarg.h>
35
36 #define _li_data_key_alias 10010
37 #define _li_data_key_bootp 10020
38 #define _li_data_key_bootparams 10030
39 #define _li_data_key_fstab 10040
40 #define _li_data_key_group 10050
41 #define _li_data_key_host 10060
42 #define _li_data_key_netgroup 10070
43 #define _li_data_key_network 10080
44 #define _li_data_key_printer 10090
45 #define _li_data_key_protocol 10100
46 #define _li_data_key_rpc 10110
47 #define _li_data_key_service 10120
48 #define _li_data_key_user 10130
49
50 /*
51 * Return values for LI_L1_cache_check.
52 */
53 #define LI_L1_CACHE_OK 0
54 #define LI_L1_CACHE_STALE 1
55 #define LI_L1_CACHE_DISABLED 2
56 #define LI_L1_CACHE_FAILED 3
57
58 struct li_thread_info
59 {
60 void *li_entry;
61 size_t li_entry_size;
62 char *li_vm;
63 uint32_t li_vm_length;
64 uint32_t li_vm_cursor;
65 uint32_t li_flags;
66 };
67
68 extern mach_port_t _ds_port;
69 extern int _ds_running(void);
70
71 /*
72 * Thread-local data management
73 */
74 __private_extern__ void *LI_data_find_key(uint32_t key);
75 __private_extern__ void *LI_data_create_key(uint32_t key, size_t esize);
76 __private_extern__ void LI_data_set_key(uint32_t key, void *data);
77 __private_extern__ void *LI_data_get_key(uint32_t key);
78 __private_extern__ void LI_data_free_kvarray(struct li_thread_info *tdata);
79 __private_extern__ void LI_data_recycle(struct li_thread_info *tdata, void *entry, size_t entrysize);
80 __private_extern__ void *LI_ils_create(char *fmt, ...);
81 __private_extern__ int LI_ils_free(void *ils, size_t len);
82
83 kern_return_t _lookup_link(mach_port_t server, char *name, int *procno);
84 kern_return_t _lookup_one(mach_port_t server, int proc, char *indata, mach_msg_type_number_t indataCnt, char *outdata, mach_msg_type_number_t *outdataCnt);
85 kern_return_t _lookup_all(mach_port_t server, int proc, char *indata, mach_msg_type_number_t indataCnt, char **outdata, mach_msg_type_number_t *outdataCnt);
86 kern_return_t _lookup_ooall(mach_port_t server, int proc, char *indata, mach_msg_type_number_t indataCnt, char **outdata, mach_msg_type_number_t *outdataCnt);
87
88 /*
89 * Directory Service queries
90 */
91 kern_return_t LI_DSLookupGetProcedureNumber(const char *name, int *procno);
92
93 __private_extern__ kern_return_t LI_DSLookupQuery(int32_t proc, kvbuf_t *request, kvarray_t **reply);
94 __private_extern__ void *LI_getent(const char *procname, int *procnum, void *(*extract)(kvarray_t *), int tkey, size_t esize);
95 __private_extern__ void *LI_getone(const char *procname, int *procnum, void *(*extract)(kvarray_t *), const char *key, const char *val);
96
97 /*
98 * L1 cache
99 * Takes _li_data_key_xxx as an argument.
100 * Returns 0 is the cache is valid, non-zero if it is invalid.
101 */
102 __private_extern__ int LI_L1_cache_check(int tkey);
103
104 /*
105 * Async support
106 */
107 void LI_async_call_cancel(mach_port_t p, void **context);
108 kern_return_t LI_async_handle_reply(mach_msg_header_t *msg, kvarray_t **reply, void **callback, void **context);
109 kern_return_t LI_async_receive(mach_port_t p, kvarray_t **reply);
110 kern_return_t LI_async_send(mach_port_t *p, uint32_t proc, kvbuf_t *query);
111 kern_return_t LI_async_start(mach_port_t *p, uint32_t proc, kvbuf_t *query, void *callback, void *context);
112
113 /*
114 * kvbuf query support
115 */
116 __private_extern__ kvbuf_t *kvbuf_query(char *fmt, ...);
117 __private_extern__ kvbuf_t *kvbuf_query_key_int(const char *key, int32_t i);
118 __private_extern__ kvbuf_t *kvbuf_query_key_uint(const char *key, uint32_t u);
119 __private_extern__ kvbuf_t *kvbuf_query_key_val(const char *key, const char *val);
120
121 #endif /* ! _LU_UTILS_H_ */