1/*
2 * "$Id: client.h 11742 2014-03-26 21:14:15Z msweet $"
3 *
4 * Client definitions for the CUPS scheduler.
5 *
6 * Copyright 2007-2014 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
8 *
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file.  If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
14 */
15
16#ifdef HAVE_AUTHORIZATION_H
17#  include <Security/Authorization.h>
18#endif /* HAVE_AUTHORIZATION_H */
19
20
21/*
22 * HTTP client structure...
23 */
24
25struct cupsd_client_s
26{
27  int			number;		/* Connection number */
28  http_t		*http;		/* HTTP client connection */
29  ipp_t			*request,	/* IPP request information */
30			*response;	/* IPP response information */
31  cupsd_location_t	*best;		/* Best match for AAA */
32  struct timeval	start;		/* Request start time */
33  http_state_t		operation;	/* Request operation */
34  off_t			bytes;		/* Bytes transferred for this request */
35  int			type;		/* AuthType for username */
36  char			username[HTTP_MAX_VALUE],
37					/* Username from Authorization: line */
38			password[HTTP_MAX_VALUE],
39					/* Password from Authorization: line */
40			uri[HTTP_MAX_URI],
41					/* Localized URL/URI for GET/PUT */
42			*filename,	/* Filename of output file */
43			*command,	/* Command to run */
44			*options,	/* Options for command */
45			*query_string;	/* QUERY_STRING environment variable */
46  int			file;		/* Input/output file */
47  int			file_ready;	/* Input ready on file/pipe? */
48  int			pipe_pid;	/* Pipe process ID (or 0 if not a pipe) */
49  http_status_t		pipe_status;	/* HTTP status from pipe process */
50  int			sent_header,	/* Non-zero if sent HTTP header */
51			got_fields,	/* Non-zero if all fields seen */
52			header_used;	/* Number of header bytes used */
53  char			header[2048];	/* Header from CGI program */
54  cups_lang_t		*language;	/* Language to use */
55#ifdef HAVE_SSL
56  int			auto_ssl;	/* Automatic test for SSL/TLS */
57#endif /* HAVE_SSL */
58  http_addr_t		clientaddr;	/* Client's server address */
59  char			clientname[256];/* Client's server name for connection */
60  int			clientport;	/* Client's server port for connection */
61  char			servername[256];/* Server name for connection */
62  int			serverport;	/* Server port for connection */
63#ifdef HAVE_GSSAPI
64  int			have_gss;	/* Have GSS credentials? */
65  uid_t			gss_uid;	/* User ID for local prints */
66#endif /* HAVE_GSSAPI */
67#ifdef HAVE_AUTHORIZATION_H
68  AuthorizationRef	authref;	/* Authorization ref */
69#endif /* HAVE_AUTHORIZATION_H */
70};
71
72#define HTTP(con) ((con)->http)
73
74
75/*
76 * HTTP listener structure...
77 */
78
79typedef struct
80{
81  int			fd;		/* File descriptor for this server */
82  http_addr_t		address;	/* Bind address of socket */
83  http_encryption_t	encryption;	/* To encrypt or not to encrypt... */
84#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD)
85  int			on_demand;	/* Is this a socket from launchd/systemd? */
86#endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */
87} cupsd_listener_t;
88
89
90/*
91 * Globals...
92 */
93
94VAR int			LastClientNumber VALUE(0),
95					/* Last client connection number */
96			ListenBackLog	VALUE(SOMAXCONN),
97					/* Max backlog of pending connections */
98			LocalPort	VALUE(631),
99					/* Local port to use */
100			RemotePort	VALUE(0);
101					/* Remote port to use */
102VAR http_encryption_t	LocalEncryption	VALUE(HTTP_ENCRYPT_IF_REQUESTED);
103					/* Local port encryption to use */
104VAR cups_array_t	*Listeners	VALUE(NULL);
105					/* Listening sockets */
106VAR time_t		ListeningPaused	VALUE(0);
107					/* Time when listening was paused */
108VAR cups_array_t	*Clients	VALUE(NULL),
109					/* HTTP clients */
110			*ActiveClients	VALUE(NULL);
111					/* Active HTTP clients */
112VAR char		*ServerHeader	VALUE(NULL);
113					/* Server header in requests */
114VAR int			CGIPipes[2]	VALUE2(-1,-1);
115					/* Pipes for CGI error/debug output */
116VAR cupsd_statbuf_t	*CGIStatusBuffer VALUE(NULL);
117					/* Status buffer for pipes */
118
119
120/*
121 * Prototypes...
122 */
123
124extern void	cupsdAcceptClient(cupsd_listener_t *lis);
125extern void	cupsdCloseAllClients(void);
126extern int	cupsdCloseClient(cupsd_client_t *con);
127extern void	cupsdDeleteAllListeners(void);
128extern void	cupsdPauseListening(void);
129extern int	cupsdProcessIPPRequest(cupsd_client_t *con);
130extern void	cupsdReadClient(cupsd_client_t *con);
131extern void	cupsdResumeListening(void);
132extern int	cupsdSendCommand(cupsd_client_t *con, char *command,
133		                 char *options, int root);
134extern int	cupsdSendError(cupsd_client_t *con, http_status_t code,
135		               int auth_type);
136extern int	cupsdSendHeader(cupsd_client_t *con, http_status_t code,
137		                char *type, int auth_type);
138extern void	cupsdShutdownClient(cupsd_client_t *con);
139extern void	cupsdStartListening(void);
140extern void	cupsdStopListening(void);
141extern void	cupsdUpdateCGI(void);
142extern void	cupsdWriteClient(cupsd_client_t *con);
143
144#ifdef HAVE_SSL
145extern int	cupsdEndTLS(cupsd_client_t *con);
146extern int	cupsdStartTLS(cupsd_client_t *con);
147#endif /* HAVE_SSL */
148
149
150/*
151 * End of "$Id: client.h 11742 2014-03-26 21:14:15Z msweet $".
152 */
153