xref: /titanic_50/usr/src/lib/print/libprint/common/llib-lprint (revision 2df1fe9ca32bb227b9158c67f5c00b54c20b10fd)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26/* LINTLIBRARY */
27/* PROTOLIB1 */
28
29#pragma ident	"%Z%%M%	%I%	%E% SMI"
30
31#include <arpa/inet.h>
32#include <dirent.h>
33#include <dlfcn.h>
34#include <errno.h>
35#include <fcntl.h>
36#include <libintl.h>
37#include <netdb.h>
38#include <netinet/in.h>
39#include <pwd.h>
40#include <rpc/rpc.h>
41#include <rpcsvc/yp_prot.h>
42#include <rpcsvc/ypclnt.h>
43#include <signal.h>
44#include <stdarg.h>
45#include <stdio.h>
46#include <stdlib.h>
47#include <string.h>
48#include <sys/mman.h>
49#include <sys/socket.h>
50#include <sys/stat.h>
51#include <sys/systeminfo.h>
52#include <sys/types.h>
53#include <syslog.h>
54#include <unistd.h>
55
56typedef struct _jobfile jobfile_t;
57typedef struct _job job_t;
58
59struct _jobfile {
60	char	*jf_spl_path;	/* df file */
61	char	*jf_src_path;	/* source file */
62	char	*jf_name;		/* title/name */
63	char	*jf_data;	/* ptr to mmapped file */
64	long	jf_size;		/* size of data */
65	char	jf_mmapped;	/* is this mmapped or malloced */
66};
67
68struct _job {
69	int	job_id;
70	char	*job_printer;
71	char	*job_server;
72	char	*job_user;
73	char	*job_host;
74	char	*job_spool_dir;
75	jobfile_t *job_cf;
76	char 	job_df_next;
77	jobfile_t **job_df_list;
78};
79
80int	job_store(job_t *job);
81void	job_free(job_t *job);
82void	job_destroy(job_t *job);
83job_t	*job_create(char *printer, char *server, char *spool);
84job_t	*job_retrieve(char *xfer_file, char *spool);
85job_t	**job_list_append(job_t **list, char *printer, char *spool);
86#ifndef SUNOS_4
87int	vjob_match_attribute(char *attribute, __va_list ap);
88int	vjob_cancel(job_t *job, __va_list ap);
89#endif
90
91
92void **list_append(void **, void *);
93void **list_append_unique(void **, void *, int (*)(void *, void*));
94void **list_concatenate(void **, void **);
95void * list_locate(void **, int (*)(void *, void *), void *);
96int list_iterate(void **, int (*)(void *, __va_list), ...);
97
98char * get_user_name(void);
99int	check_client_spool(char *printer);
100int	get_lock(char *name, int write_pid);
101uid_t	get_user_id(void);
102char	*strcdup(char *, char);
103char	*strndup(char *, int);
104char	**strsplit(char *, char *);
105int	file_size(char *);
106int	copy_file(char *src, char *dst);
107int	map_in_file(const char *name, char **buf);
108int	write_buffer(char *name, char *buf, int len);
109void	start_daemon(int do_fork);
110int	kill_process(char *file);
111void	*dynamic_function(const char *, const char *);
112
113int	net_open(char *host, int timeout);
114int	net_close(int nd);
115int	net_read(int nd, char *buf, int len);
116int	net_write(int nd, char *buf, int len);
117int	net_printf(int nd, char *fmt, ...);
118char	*net_gets(char *buf, int size, int nd);
119int	net_send_message(int nd, char *fmt, ...);
120int	net_response(int nd);
121int	net_send_file(int nd, char *name, char *data, int data_len,
122				int type);
123
124
125struct ns_bsd_addr {
126	char	*server;	/* server name */
127	char	*printer;	/* printer name or NULL */
128	char	*extension;	/* RFC-1179 conformance */
129	char  *pname;		/* Local printer name */
130};
131typedef struct ns_bsd_addr ns_bsd_addr_t;
132
133/* Key/Value pair structure */
134struct ns_kvp {
135	char *key;		/* key */
136	char *value;		/* value string */
137};
138typedef struct ns_kvp ns_kvp_t;
139
140/* Printer Object structure */
141struct ns_printer {
142	char		*name;			/* primary name of printer */
143	char		**aliases;		/* aliases for printer */
144	char		*source;		/* name service derived from */
145	ns_kvp_t	**attributes;		/* key/value pairs. */
146};
147typedef struct ns_printer ns_printer_t;
148
149/* functions to get/put printer objects */
150ns_printer_t *ns_printer_create(char *, char **, char *, ns_kvp_t **);
151ns_printer_t *ns_printer_get_name(const char *, const char *);
152ns_printer_t **ns_printer_get_list(const char *);
153int	ns_printer_put(const ns_printer_t *);
154void	ns_printer_destroy(ns_printer_t *);
155
156/* functions to manipulate key/value pairs */
157void	*ns_get_value(const char *, const ns_printer_t *);
158char	*ns_get_value_string(const char *, const ns_printer_t *);
159int	ns_set_value(const char *, const void *, ns_printer_t *);
160int	ns_set_value_from_string(const char *, const char *,
161						ns_printer_t *);
162ns_kvp_t	*ns_kvp_create(const char *, const char *);
163
164/* for BSD bindings only */
165ns_bsd_addr_t *ns_bsd_addr_get_default(void);
166ns_bsd_addr_t *ns_bsd_addr_get_name(char *name);
167ns_bsd_addr_t **ns_bsd_addr_get_all(int);
168ns_bsd_addr_t **ns_bsd_addr_get_list(int);
169
170/* others */
171ns_printer_t *posix_name(const char *);
172int ns_printer_match_name(ns_printer_t *, const char *);
173char *ns_printer_name_list(const ns_printer_t *);
174char *value_to_string(const char *, void *);
175void *string_to_value(const char *, char *);
176
177
178ns_printer_t *_cvt_pconf_entry_to_printer(char *, char *);
179char *_cvt_printer_to_pconf_entry(ns_printer_t *);
180
181ns_printer_t *_cvt_user_string_to_printer(char *, char *);
182char *_cvt_printer_to_user_string(ns_printer_t *);
183
184
185ns_printer_t *_file_get_name(const char *, const char *,
186    ns_printer_t *(*)(char *, char *), char *);
187
188ns_printer_t **_file_get_list(const char *,
189    ns_printer_t *(*)(char *, char *), char *);
190
191int _file_put_printer(const char *, const ns_printer_t *,
192    ns_printer_t *(*)(char *, char *), char *, char *(*)(ns_printer_t *));
193
194
195ns_printer_t *_nis_get_name(const char *, const char *,
196    ns_printer_t *(*)(char *, char *), char *);
197
198ns_printer_t **_nis_get_list(const char *,
199    ns_printer_t *(*)(char *, char *), char *);
200
201int _nis_put_printer(const char *, const ns_printer_t *,
202    ns_printer_t *(*)(char *, char *), char *, char *(*)(ns_printer_t *));
203