xref: /titanic_44/usr/src/lib/print/libprint/common/llib-lprint (revision c1ecd8b9404ee0d96d93f02e82c441b9bb149a3d)
1355b4669Sjacobs/*
2355b4669Sjacobs * CDDL HEADER START
3355b4669Sjacobs *
4355b4669Sjacobs * The contents of this file are subject to the terms of the
5355b4669Sjacobs * Common Development and Distribution License (the "License").
6355b4669Sjacobs * You may not use this file except in compliance with the License.
7355b4669Sjacobs *
8355b4669Sjacobs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9355b4669Sjacobs * or http://www.opensolaris.org/os/licensing.
10355b4669Sjacobs * See the License for the specific language governing permissions
11355b4669Sjacobs * and limitations under the License.
12355b4669Sjacobs *
13355b4669Sjacobs * When distributing Covered Code, include this CDDL HEADER in each
14355b4669Sjacobs * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15355b4669Sjacobs * If applicable, add the following below this CDDL HEADER, with the
16355b4669Sjacobs * fields enclosed by brackets "[]" replaced with your own identifying
17355b4669Sjacobs * information: Portions Copyright [yyyy] [name of copyright owner]
18355b4669Sjacobs *
19355b4669Sjacobs * CDDL HEADER END
20355b4669Sjacobs */
21355b4669Sjacobs/*
22*c1ecd8b9Sjacobs * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23355b4669Sjacobs * Use is subject to license terms.
24355b4669Sjacobs */
25355b4669Sjacobs
26355b4669Sjacobs/* LINTLIBRARY */
27355b4669Sjacobs/* PROTOLIB1 */
28355b4669Sjacobs
29355b4669Sjacobs#pragma ident	"%Z%%M%	%I%	%E% SMI"
30355b4669Sjacobs
31355b4669Sjacobs#include <arpa/inet.h>
32355b4669Sjacobs#include <dirent.h>
33355b4669Sjacobs#include <dlfcn.h>
34355b4669Sjacobs#include <errno.h>
35355b4669Sjacobs#include <fcntl.h>
36355b4669Sjacobs#include <libintl.h>
37355b4669Sjacobs#include <netdb.h>
38355b4669Sjacobs#include <netinet/in.h>
39355b4669Sjacobs#include <pwd.h>
40355b4669Sjacobs#include <rpc/rpc.h>
41355b4669Sjacobs#include <rpcsvc/yp_prot.h>
42355b4669Sjacobs#include <rpcsvc/ypclnt.h>
43355b4669Sjacobs#include <signal.h>
44355b4669Sjacobs#include <stdarg.h>
45355b4669Sjacobs#include <stdio.h>
46355b4669Sjacobs#include <stdlib.h>
47355b4669Sjacobs#include <string.h>
48355b4669Sjacobs#include <sys/mman.h>
49355b4669Sjacobs#include <sys/socket.h>
50355b4669Sjacobs#include <sys/stat.h>
51355b4669Sjacobs#include <sys/systeminfo.h>
52355b4669Sjacobs#include <sys/types.h>
53355b4669Sjacobs#include <syslog.h>
54355b4669Sjacobs#include <unistd.h>
55355b4669Sjacobs
56355b4669Sjacobsvoid **list_append(void **, void *);
57355b4669Sjacobsvoid **list_append_unique(void **, void *, int (*)(void *, void*));
58355b4669Sjacobsvoid **list_concatenate(void **, void **);
59355b4669Sjacobsvoid * list_locate(void **, int (*)(void *, void *), void *);
60355b4669Sjacobsint list_iterate(void **, int (*)(void *, __va_list), ...);
61355b4669Sjacobs
62355b4669Sjacobsvoid	*dynamic_function(const char *, const char *);
63355b4669Sjacobs
64355b4669Sjacobsstruct ns_bsd_addr {
65355b4669Sjacobs	char	*server;	/* server name */
66355b4669Sjacobs	char	*printer;	/* printer name or NULL */
67355b4669Sjacobs	char	*extension;	/* RFC-1179 conformance */
68355b4669Sjacobs	char  *pname;		/* Local printer name */
69355b4669Sjacobs};
70355b4669Sjacobstypedef struct ns_bsd_addr ns_bsd_addr_t;
71355b4669Sjacobs
72355b4669Sjacobs/* Key/Value pair structure */
73355b4669Sjacobsstruct ns_kvp {
74355b4669Sjacobs	char *key;		/* key */
75355b4669Sjacobs	char *value;		/* value string */
76355b4669Sjacobs};
77355b4669Sjacobstypedef struct ns_kvp ns_kvp_t;
78355b4669Sjacobs
79355b4669Sjacobs/* Printer Object structure */
80355b4669Sjacobsstruct ns_printer {
81355b4669Sjacobs	char		*name;			/* primary name of printer */
82355b4669Sjacobs	char		**aliases;		/* aliases for printer */
83355b4669Sjacobs	char		*source;		/* name service derived from */
84355b4669Sjacobs	ns_kvp_t	**attributes;		/* key/value pairs. */
85355b4669Sjacobs};
86355b4669Sjacobstypedef struct ns_printer ns_printer_t;
87355b4669Sjacobs
88355b4669Sjacobs/* functions to get/put printer objects */
89355b4669Sjacobsns_printer_t *ns_printer_create(char *, char **, char *, ns_kvp_t **);
90355b4669Sjacobsns_printer_t *ns_printer_get_name(const char *, const char *);
91355b4669Sjacobsns_printer_t **ns_printer_get_list(const char *);
92355b4669Sjacobsint	ns_printer_put(const ns_printer_t *);
93355b4669Sjacobsvoid	ns_printer_destroy(ns_printer_t *);
94355b4669Sjacobs
95355b4669Sjacobs/* functions to manipulate key/value pairs */
96355b4669Sjacobsvoid	*ns_get_value(const char *, const ns_printer_t *);
97355b4669Sjacobschar	*ns_get_value_string(const char *, const ns_printer_t *);
98355b4669Sjacobsint	ns_set_value(const char *, const void *, ns_printer_t *);
99355b4669Sjacobsint	ns_set_value_from_string(const char *, const char *,
100355b4669Sjacobs						ns_printer_t *);
101355b4669Sjacobsns_kvp_t	*ns_kvp_create(const char *, const char *);
102355b4669Sjacobs
103355b4669Sjacobs/* for BSD bindings only */
104355b4669Sjacobsns_bsd_addr_t *ns_bsd_addr_get_default(void);
105355b4669Sjacobsns_bsd_addr_t *ns_bsd_addr_get_name(char *name);
106355b4669Sjacobsns_bsd_addr_t **ns_bsd_addr_get_all(int);
107355b4669Sjacobsns_bsd_addr_t **ns_bsd_addr_get_list(int);
108355b4669Sjacobs
109355b4669Sjacobs/* others */
110355b4669Sjacobsns_printer_t *posix_name(const char *);
111355b4669Sjacobsint ns_printer_match_name(ns_printer_t *, const char *);
112355b4669Sjacobschar *ns_printer_name_list(const ns_printer_t *);
113355b4669Sjacobschar *value_to_string(const char *, void *);
114355b4669Sjacobsvoid *string_to_value(const char *, char *);
115355b4669Sjacobs
116355b4669Sjacobs
117355b4669Sjacobsns_printer_t *_cvt_pconf_entry_to_printer(char *, char *);
118355b4669Sjacobschar *_cvt_printer_to_pconf_entry(ns_printer_t *);
119355b4669Sjacobs
120355b4669Sjacobsns_printer_t *_cvt_user_string_to_printer(char *, char *);
121355b4669Sjacobschar *_cvt_printer_to_user_string(ns_printer_t *);
122355b4669Sjacobs
123355b4669Sjacobs
124355b4669Sjacobsns_printer_t *_file_get_name(const char *, const char *,
125355b4669Sjacobs    ns_printer_t *(*)(char *, char *), char *);
126355b4669Sjacobs
127355b4669Sjacobsns_printer_t **_file_get_list(const char *,
128355b4669Sjacobs    ns_printer_t *(*)(char *, char *), char *);
129355b4669Sjacobs
130355b4669Sjacobsint _file_put_printer(const char *, const ns_printer_t *,
131355b4669Sjacobs    ns_printer_t *(*)(char *, char *), char *, char *(*)(ns_printer_t *));
132355b4669Sjacobs
133355b4669Sjacobs
134355b4669Sjacobsns_printer_t *_nis_get_name(const char *, const char *,
135355b4669Sjacobs    ns_printer_t *(*)(char *, char *), char *);
136355b4669Sjacobs
137355b4669Sjacobsns_printer_t **_nis_get_list(const char *,
138355b4669Sjacobs    ns_printer_t *(*)(char *, char *), char *);
139355b4669Sjacobs
140355b4669Sjacobsint _nis_put_printer(const char *, const ns_printer_t *,
141355b4669Sjacobs    ns_printer_t *(*)(char *, char *), char *, char *(*)(ns_printer_t *));
142