1 /* 2 * Subscription definitions for the CUPS scheduler. 3 * 4 * Copyright © 2020-2024 by OpenPrinting. 5 * Copyright 2007-2010 by Apple Inc. 6 * Copyright 1997-2007 by Easy Software Products, all rights reserved. 7 * 8 * Licensed under Apache License v2.0. See the file "LICENSE" for more information. 9 */ 10 11 /* 12 * Event mask enumeration... 13 */ 14 15 typedef enum 16 { 17 /* Individual printer events... */ 18 CUPSD_EVENT_PRINTER_STATE = 0x0001, /* Sent after generic printer state change */ 19 CUPSD_EVENT_PRINTER_RESTARTED = 0x0002, 20 /* Sent after printer restarted */ 21 CUPSD_EVENT_PRINTER_SHUTDOWN = 0x0004,/* Sent after printer shutdown */ 22 CUPSD_EVENT_PRINTER_STOPPED = 0x0008, /* Sent after printer stopped */ 23 24 CUPSD_EVENT_PRINTER_CONFIG = 0x0010, /* Send after add/modify changes attrs */ 25 CUPSD_EVENT_PRINTER_FINISHINGS_CHANGED = 0x0020, 26 /* Sent after finishings-supported changed */ 27 CUPSD_EVENT_PRINTER_MEDIA_CHANGED = 0x0040, 28 /* Sent after media-supported changed */ 29 CUPSD_EVENT_PRINTER_ADDED = 0x0080, /* Sent after printer added */ 30 CUPSD_EVENT_PRINTER_DELETED = 0x0100, /* Sent after printer deleted */ 31 CUPSD_EVENT_PRINTER_MODIFIED = 0x0200,/* Sent after printer modified */ 32 CUPSD_EVENT_PRINTER_QUEUE_ORDER_CHANGED = 0x0400, 33 /* Sent when the order of jobs is changed */ 34 35 /* Convenience printer event groupings... */ 36 CUPSD_EVENT_PRINTER_STATE_CHANGED = 0x000f, 37 /* STATE + RESTARTED + SHUTDOWN + STOPPED */ 38 CUPSD_EVENT_PRINTER_CONFIG_CHANGED = 0x0070, 39 /* CONFIG + FINISHINGS_CHANGED + MEDIA_CHANGED */ 40 CUPSD_EVENT_PRINTER_CHANGED = 0x07ff, /* All of the above */ 41 42 /* Individual job events... */ 43 CUPSD_EVENT_JOB_STATE = 0x0800, /* Any state change */ 44 CUPSD_EVENT_JOB_CREATED = 0x1000, /* Send after job is created */ 45 CUPSD_EVENT_JOB_COMPLETED = 0x2000, /* Sent after job is completed */ 46 CUPSD_EVENT_JOB_STOPPED = 0x4000, /* Sent after job is stopped */ 47 CUPSD_EVENT_JOB_CONFIG_CHANGED = 0x8000, 48 /* Sent after set-job-attributes */ 49 CUPSD_EVENT_JOB_PROGRESS = 0x10000, /* Sent for each page */ 50 51 /* Convenience job event grouping... */ 52 CUPSD_EVENT_JOB_STATE_CHANGED = 0x7800, 53 /* STATE + CREATED + COMPLETED + STOPPED */ 54 55 /* Server events... */ 56 CUPSD_EVENT_SERVER_RESTARTED = 0x20000,/* Sent after server restarts */ 57 CUPSD_EVENT_SERVER_STARTED = 0x40000, /* Sent when server first starts */ 58 CUPSD_EVENT_SERVER_STOPPED = 0x80000, /* Sent when server is stopped */ 59 CUPSD_EVENT_SERVER_AUDIT = 0x100000, /* Security-related stuff */ 60 61 /* Everything and nothing... */ 62 CUPSD_EVENT_NONE = 0, /* Nothing */ 63 CUPSD_EVENT_ALL = 0x1fffff /* Everything */ 64 } cupsd_eventmask_t; 65 66 67 /* 68 * Notification support structures... 69 */ 70 71 typedef struct cupsd_event_s /**** Event structure ****/ 72 { 73 cupsd_eventmask_t event; /* Event */ 74 time_t time; /* Time of event */ 75 ipp_t *attrs; /* Notification message */ 76 cupsd_printer_t *dest; /* Associated printer, if any */ 77 cupsd_job_t *job; /* Associated job, if any */ 78 } cupsd_event_t; 79 80 typedef struct cupsd_subscription_s /**** Subscription structure ****/ 81 { 82 int id; /* subscription-id */ 83 unsigned mask; /* Event mask */ 84 char *owner; /* notify-subscriber-user-name */ 85 char *recipient; /* notify-recipient-uri, if applicable */ 86 unsigned char user_data[64]; /* notify-user-data */ 87 int user_data_len; /* Length of notify-user-data */ 88 int lease; /* notify-lease-duration */ 89 int interval; /* notify-time-interval */ 90 cupsd_printer_t *dest; /* notify-printer-uri, if any */ 91 cupsd_job_t *job; /* notify-job-id, if any */ 92 int pid; /* Process ID of notifier */ 93 int pipe; /* Pipe to notifier */ 94 int status; /* Exit status of notifier */ 95 time_t last; /* Time of last notification */ 96 time_t expire; /* Lease expiration time */ 97 int first_event_id, /* First event-id in cache */ 98 next_event_id; /* Next event-id to use */ 99 cups_array_t *events; /* Cached events */ 100 } cupsd_subscription_t; 101 102 103 /* 104 * Globals... 105 */ 106 107 VAR int MaxSubscriptions VALUE(100), 108 /* Overall subscription limit */ 109 MaxSubscriptionsPerJob VALUE(0), 110 /* Per-job subscription limit */ 111 MaxSubscriptionsPerPrinter VALUE(0), 112 /* Per-printer subscription limit */ 113 MaxSubscriptionsPerUser VALUE(0), 114 /* Per-user subscription limit */ 115 NextSubscriptionId VALUE(1), 116 /* Next subscription ID */ 117 DefaultLeaseDuration VALUE(86400), 118 /* Default notify-lease-duration */ 119 MaxLeaseDuration VALUE(0); 120 /* Maximum notify-lease-duration */ 121 VAR cups_array_t *Subscriptions VALUE(NULL); 122 /* Active subscriptions */ 123 124 VAR int MaxEvents VALUE(100); /* Maximum number of events */ 125 126 VAR unsigned LastEvent VALUE(0); /* Last event(s) processed */ 127 VAR int NotifierPipes[2] VALUE2(-1, -1); 128 /* Pipes for notifier error/debug output */ 129 VAR cupsd_statbuf_t *NotifierStatusBuffer VALUE(NULL); 130 /* Status buffer for pipes */ 131 132 133 /* 134 * Prototypes... 135 */ 136 137 extern void cupsdAddEvent(cupsd_eventmask_t event, cupsd_printer_t *dest, 138 cupsd_job_t *job, const char *text, ...); 139 extern cupsd_subscription_t * 140 cupsdAddSubscription(unsigned mask, cupsd_printer_t *dest, 141 cupsd_job_t *job, const char *uri, 142 int sub_id); 143 extern void cupsdDeleteAllSubscriptions(void); 144 extern void cupsdDeleteSubscription(cupsd_subscription_t *sub, int update); 145 extern const char * 146 cupsdEventName(cupsd_eventmask_t event); 147 extern cupsd_eventmask_t 148 cupsdEventValue(const char *name); 149 150 extern cupsd_subscription_t * 151 cupsdFindSubscription(int id); 152 extern void cupsdExpireSubscriptions(cupsd_printer_t *dest, 153 cupsd_job_t *job); 154 extern void cupsdLoadAllSubscriptions(void); 155 extern void cupsdSaveAllSubscriptions(void); 156 extern void cupsdStopAllNotifiers(void); 157