1 /* 2 Copyright (C) 2016-2021, Dirk Krause 3 SPDX-License-Identifier: BSD-3-Clause 4 */ 5 6 /* 7 WARNING: This file was generated by the dkct program (see 8 http://dktools.sourceforge.net/ for details). 9 Changes you make here will be lost if dkct is run again! 10 You should modify the original source and run dkct on it. 11 Original source: printqd.ctr 12 */ 13 14 #ifndef PRINTQD_H_INCLUDED 15 /** Avoid multiple inclusions. */ 16 #define PRINTQD_H_INCLUDED 1 17 18 19 /* CORRECT NEXT LINE AFTER REPLACING PRINTQD */ 20 21 /** @file printqd.h Definitions for printqd. 22 */ 23 24 #ifndef DK4CONF_H_INCLUDED 25 #include "dk4conf.h" 26 #endif 27 28 #ifndef DK4TYPES_H_INCLUDED 29 #include <libdk4base/dk4types.h> 30 #endif 31 32 #ifndef DK4STO_H_INCLUDED 33 #include <libdk4c/dk4sto.h> 34 #endif 35 36 #ifndef DK4SOCK_H_INCLUDED 37 #include <libdk4sock/dk4sock.h> 38 #endif 39 40 41 42 /** Limit for one user or group. 43 */ 44 typedef struct { 45 char *name; /**< User or group name */ 46 dk4_um_t limit; /**< Page limit. */ 47 } pqd_limit_t; 48 49 50 51 52 /** Printer class (may contain multiple printers). 53 */ 54 typedef struct { 55 char *name; /**< Class name. */ 56 dk4_sto_t *s_u; /**< User limits storage. */ 57 dk4_sto_it_t *i_u; /**< User limits storage iterator. */ 58 dk4_sto_t *s_g; /**< Group limits storage. */ 59 dk4_sto_it_t *i_g; /**< Group limits storage iterator. */ 60 dk4_um_t dl; /**< Default limit. */ 61 int da; /**< Deny action: 1=hold, 0=remove. */ 62 int hdl; /**< Flag: Have default limit. */ 63 } pqd_class_t; 64 65 66 67 /** Printer. 68 */ 69 typedef struct { 70 char *name; /**< Printer name. */ 71 pqd_class_t *cl; /**< Printer class. */ 72 } pqd_printer_t; 73 /* 74 In service the class is not NULL. 75 If no class is configured for a printer, the program complains 76 and exits. 77 */ 78 79 80 81 /** Printer alias. 82 */ 83 typedef struct { 84 char *name; /**< Alias name. */ 85 pqd_printer_t *pr; /**< The real printer. */ 86 } pqd_printer_alias_t; 87 88 89 90 /** Printqd configuration. 91 */ 92 typedef struct { 93 char *sname; /**< UNIX domain socket file name. */ 94 char *dname; /**< Database name (including type). */ 95 char *lname; /**< Log file name. */ 96 dk4_sto_t *s_c; /**< Storage for classes. */ 97 dk4_sto_it_t *i_c; /**< Iterator for class storage. */ 98 dk4_sto_t *s_p; /**< Storage for printers. */ 99 dk4_sto_it_t *i_p; /**< Iterator for printers storage. */ 100 dk4_sto_t *s_a; /**< Storage for aliases. */ 101 dk4_sto_it_t *i_a; /**< Iterator for aliases storage. */ 102 dk4_sto_t *s_ai; /**< Storage for peers allowed info rq. */ 103 dk4_sto_it_t *i_ai; /**< Iterator for info peers storage. */ 104 dk4_sto_t *s_ad; /**< Storage for peers allowed data rq. */ 105 dk4_sto_it_t *i_ad; /**< Iterator for data peers storage. */ 106 dk4_sto_t *s_aa; /**< Storage for peers allowed admin rq. */ 107 dk4_sto_it_t *i_aa; /**< Iterator for admin peers storage. */ 108 size_t m_loc; /**< Maximum number of local connections. */ 109 size_t m_tcp; /**< Maximum number of TCP connections. */ 110 uid_t uid; /**< Run as specified user. */ 111 uid_t suid; /**< Local socket owner UID. */ 112 gid_t gid; /**< Run as specified group. */ 113 gid_t sgid; /**< Local socket owner GID. */ 114 int slbl; /**< Backlog for local socket. */ 115 int snbl; /**< Backlog for network socket. */ 116 int iglo; /**< Flag: Globally allow info requests. */ 117 int dglo; /**< Flag: Globally allow data requests. */ 118 int aglo; /**< Flag: Globally allow admin requests. */ 119 int linf; /**< Flag: Log info requests. */ 120 int ldb; /**< Flag: Log database modifications. */ 121 unsigned short ptcp; /**< TCP port (info, data, admin), host repr. */ 122 unsigned short pudp; /**< UDP port (info only), host represent. */ 123 } pqd_conf_t; 124 125 126 127 /** Connection record for local socket. 128 */ 129 typedef struct { 130 dk4_socket_t sock; /**< Socket. */ 131 } pqd_l_conn_t; 132 133 134 135 /** Connection record for network socket. 136 */ 137 typedef struct { 138 dk4_sockaddr_storage_t raddr; /**< Remote address. */ 139 dk4_socket_t sock; /**< Socket. */ 140 int pqdpl; /**< Printqd protocol level. */ 141 } pqd_n_conn_t; 142 143 144 145 /** One request to process. 146 */ 147 typedef struct { 148 void *connptr; /**< Connection record for socket. */ 149 dk4_sto_t *sto; /**< Container for conn records. */ 150 struct sockaddr *soa; /**< Remote address, only UDP. */ 151 size_t *pnconn; /**< Addr of variable, NULL for UDP. */ 152 char *cmdptr; /**< Start of command. */ 153 char *argptr; /**< Command arguments. */ 154 size_t szsoa; /**< Size of rem address, only UDP. */ 155 dk4_socket_t sock; /**< Socket to use for response. */ 156 int protlev; /**< Protocol level. */ 157 int action; /**< Action to take. */ 158 int logthis; /**< Flag: Log request and response. */ 159 } pqd_rq_t; 160 161 162 163 /** Data for one user in a class. 164 */ 165 typedef struct { 166 dk4_um_t limit; /**< Limit (maximum page number). */ 167 dk4_um_t used; /**< Number of pages used within limit. */ 168 dk4_um_t account; /**< Remaining pages personal print account. */ 169 int da; /**< Deny action: 0=remove, 1=hold. */ 170 } pqd_account_t; 171 172 173 174 /** Information from one LPRng accounting line. 175 */ 176 typedef struct { 177 char *username; /**< User name. */ 178 char *queuename; /**< Print queue name. */ 179 char *jobtitle; /**< Print job title. */ 180 char *pagecount; /**< Pagecount reported in line. */ 181 } lprng_info_t; 182 183 184 185 186 /** Printqd protocol levels. 187 */ 188 enum { 189 PQD_PROTO_NONE = 0 , /**< No requests allowed. */ 190 PQD_PROTO_INFO = 1 , /**< Info requests only. */ 191 PQD_PROTO_DATA = 2 , /**< Info and data requests. */ 192 PQD_PROTO_ADMIN = 3 /**< Info, data and admin requests. */ 193 }; 194 195 196 197 /** Commands in the printqd protocol. 198 */ 199 enum { 200 PQD_CMD_NONE = -1 , /**< Illegal command. */ 201 PQD_CMD_JOBSTART = 0 , /**< Start of print job, response required. */ 202 PQD_CMD_JOBEND = 1 , /**< End of print job. */ 203 PQD_CMD_START = 2 , /**< Start of printing (ignored). */ 204 PQD_CMD_END = 3 , /**< End of printing (ignored). */ 205 PQD_CMD_FILESTART = 4 , /**< Start of file printing (pc). */ 206 PQD_CMD_FILEEND = 5 , /**< End of file printing (pc). */ 207 PQD_CMD_INFO = 6 , /**< Information, response required. */ 208 PQD_CMD_ACCT_CHECK = 7 , /**< Check permission, response required. */ 209 PQD_CMD_ACCT_START = 8 , /**< Start of file printing (pc). */ 210 PQD_CMD_ACCT_END = 9 , /**< End of file printing (pc). */ 211 PQD_CMD_ACCT_CHARGE = 10 , /**< Summary for file printing (pc). */ 212 PQD_CMD_CONTROL = 11 /**< Control request. */ 213 }; 214 215 216 217 218 #endif 219