From 452eb38df0553886313c9b19a945385d853e19ab Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 28 Jun 2002 00:17:15 +0000 Subject: Proper merge of all the working printing stuff from APPLIANCE_HEAD. Now let's keep this in sync ! Jeremy. (This used to be commit 3603cd4947df2c10df604447dc542932cb9e5d5a) --- source3/printing/notify.c | 230 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 230 insertions(+) create mode 100644 source3/printing/notify.c (limited to 'source3/printing/notify.c') diff --git a/source3/printing/notify.c b/source3/printing/notify.c new file mode 100644 index 0000000000..5ba7faba59 --- /dev/null +++ b/source3/printing/notify.c @@ -0,0 +1,230 @@ +/* + Unix SMB/Netbios implementation. + Version 2.2 + printing backend routines + Copyright (C) Tim Potter, 2002 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "printing.h" + +/* + * Print notification routines + */ + +static void send_spoolss_notify2_msg(struct spoolss_notify_msg *msg) +{ + char *buf = NULL; + int buflen = 0, len; + TDB_CONTEXT *tdb; + + /* Let's not waste any time with this */ + + if (lp_disable_spoolss()) + return; + + /* Flatten data into a message */ + +again: + len = 0; + + /* Pack header */ + + len += tdb_pack(buf + len, buflen - len, "f", msg->printer); + + len += tdb_pack(buf + len, buflen - len, "ddddd", + msg->type, msg->field, msg->id, msg->len, msg->flags); + + /* Pack data */ + + if (msg->len == 0) + len += tdb_pack(buf + len, buflen - len, "dd", + msg->notify.value[0], msg->notify.value[1]); + else + len += tdb_pack(buf + len, buflen - len, "B", + msg->len, msg->notify.data); + + if (buflen != len) { + buf = Realloc(buf, len); + buflen = len; + goto again; + } + + /* Send message */ + + tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0); + + if (!tdb) { + DEBUG(3, ("Failed to open connections database in send_spoolss_notify2_msg\n")); + return; + } + + message_send_all(tdb, MSG_PRINTER_NOTIFY2, buf, + buflen, False, NULL); + + SAFE_FREE(buf); + tdb_close(tdb); +} + +static void send_notify_field_values(const char *printer_name, uint32 type, + uint32 field, uint32 id, uint32 value1, + uint32 value2, uint32 flags) +{ + struct spoolss_notify_msg msg; + + ZERO_STRUCT(msg); + + fstrcpy(msg.printer, printer_name); + msg.type = type; + msg.field = field; + msg.id = id; + msg.notify.value[0] = value1; + msg.notify.value[1] = value2; + msg.flags = flags; + + send_spoolss_notify2_msg(&msg); +} + +static void send_notify_field_buffer(const char *printer_name, uint32 type, + uint32 field, uint32 id, uint32 len, + char *buffer) +{ + struct spoolss_notify_msg msg; + + ZERO_STRUCT(msg); + + fstrcpy(msg.printer, printer_name); + msg.type = type; + msg.field = field; + msg.id = id; + msg.len = len; + msg.notify.data = buffer; + + send_spoolss_notify2_msg(&msg); +} + +/* Send a message that the printer status has changed */ + +void notify_printer_status_byname(char *printer_name, uint32 status) +{ + /* Printer status stored in value1 */ + + send_notify_field_values(printer_name, PRINTER_NOTIFY_TYPE, + PRINTER_NOTIFY_STATUS, 0, + status, 0, 0); +} + +void notify_printer_status(int snum, uint32 status) +{ + char *printer_name = PRINTERNAME(snum); + + if (printer_name) + notify_printer_status_byname(printer_name, status); +} + +void notify_job_status_byname(char *printer_name, uint32 jobid, uint32 status, + uint32 flags) +{ + /* Job id stored in id field, status in value1 */ + + send_notify_field_values(printer_name, JOB_NOTIFY_TYPE, + JOB_NOTIFY_STATUS, jobid, + status, 0, flags); +} + +void notify_job_status(int snum, uint32 jobid, uint32 status) +{ + char *printer_name = PRINTERNAME(snum); + + notify_job_status_byname(printer_name, jobid, status, 0); +} + +void notify_job_total_bytes(int snum, uint32 jobid, uint32 size) +{ + char *printer_name = PRINTERNAME(snum); + + /* Job id stored in id field, status in value1 */ + + send_notify_field_values(printer_name, JOB_NOTIFY_TYPE, + JOB_NOTIFY_TOTAL_BYTES, jobid, + size, 0, 0); +} + +void notify_job_total_pages(int snum, uint32 jobid, uint32 pages) +{ + char *printer_name = PRINTERNAME(snum); + + /* Job id stored in id field, status in value1 */ + + send_notify_field_values(printer_name, JOB_NOTIFY_TYPE, + JOB_NOTIFY_TOTAL_PAGES, jobid, + pages, 0, 0); +} + +void notify_job_username(int snum, uint32 jobid, char *name) +{ + char *printer_name = PRINTERNAME(snum); + + send_notify_field_buffer( + printer_name, JOB_NOTIFY_TYPE, JOB_NOTIFY_USER_NAME, + jobid, strlen(name) + 1, name); +} + +void notify_job_name(int snum, uint32 jobid, char *name) +{ + char *printer_name = PRINTERNAME(snum); + + send_notify_field_buffer( + printer_name, JOB_NOTIFY_TYPE, JOB_NOTIFY_DOCUMENT, + jobid, strlen(name) + 1, name); +} + +void notify_job_submitted(int snum, uint32 jobid, time_t submitted) +{ + char *printer_name = PRINTERNAME(snum); + + send_notify_field_buffer( + printer_name, JOB_NOTIFY_TYPE, JOB_NOTIFY_SUBMITTED, + jobid, sizeof(submitted), (char *)&submitted); +} + +void notify_printer_delete(char *printer_name) +{ +} + +void notify_printer_add(char *printer_name) +{ +} + +void notify_printer_driver(int num, char *driver_name) +{ +} + +void notify_printer_comment(int num, char *comment) +{ +} + +void notify_printer_sharename(int num, char *share_name) +{ +} + +void notify_printer_port(int num, char *port_name) +{ +} + +void notify_printer_location(int num, char *location) +{ +} -- cgit From 25148a148c1bec680924909722d59d0d47c795ae Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 11 Jul 2002 00:06:29 +0000 Subject: *Experimental* new large-scaling printer code. Splits printing.tdb into a separate tdb per printer, but only keeps (currently one) tdb open at a time (although this is easily changed by changing a #define). Needs scalability testing with large numbers of printers now.... Jeremy. (This used to be commit b0909cfa14fc7ef29d2b98b56d52723570da782a) --- source3/printing/notify.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source3/printing/notify.c') diff --git a/source3/printing/notify.c b/source3/printing/notify.c index 5ba7faba59..21e28d0ca7 100644 --- a/source3/printing/notify.c +++ b/source3/printing/notify.c @@ -118,7 +118,7 @@ static void send_notify_field_buffer(const char *printer_name, uint32 type, /* Send a message that the printer status has changed */ -void notify_printer_status_byname(char *printer_name, uint32 status) +void notify_printer_status_byname(const char *printer_name, uint32 status) { /* Printer status stored in value1 */ @@ -129,13 +129,13 @@ void notify_printer_status_byname(char *printer_name, uint32 status) void notify_printer_status(int snum, uint32 status) { - char *printer_name = PRINTERNAME(snum); + const char *printer_name = PRINTERNAME(snum); if (printer_name) notify_printer_status_byname(printer_name, status); } -void notify_job_status_byname(char *printer_name, uint32 jobid, uint32 status, +void notify_job_status_byname(const char *printer_name, uint32 jobid, uint32 status, uint32 flags) { /* Job id stored in id field, status in value1 */ @@ -147,14 +147,14 @@ void notify_job_status_byname(char *printer_name, uint32 jobid, uint32 status, void notify_job_status(int snum, uint32 jobid, uint32 status) { - char *printer_name = PRINTERNAME(snum); + const char *printer_name = PRINTERNAME(snum); notify_job_status_byname(printer_name, jobid, status, 0); } void notify_job_total_bytes(int snum, uint32 jobid, uint32 size) { - char *printer_name = PRINTERNAME(snum); + const char *printer_name = PRINTERNAME(snum); /* Job id stored in id field, status in value1 */ @@ -165,7 +165,7 @@ void notify_job_total_bytes(int snum, uint32 jobid, uint32 size) void notify_job_total_pages(int snum, uint32 jobid, uint32 pages) { - char *printer_name = PRINTERNAME(snum); + const char *printer_name = PRINTERNAME(snum); /* Job id stored in id field, status in value1 */ @@ -176,7 +176,7 @@ void notify_job_total_pages(int snum, uint32 jobid, uint32 pages) void notify_job_username(int snum, uint32 jobid, char *name) { - char *printer_name = PRINTERNAME(snum); + const char *printer_name = PRINTERNAME(snum); send_notify_field_buffer( printer_name, JOB_NOTIFY_TYPE, JOB_NOTIFY_USER_NAME, @@ -185,7 +185,7 @@ void notify_job_username(int snum, uint32 jobid, char *name) void notify_job_name(int snum, uint32 jobid, char *name) { - char *printer_name = PRINTERNAME(snum); + const char *printer_name = PRINTERNAME(snum); send_notify_field_buffer( printer_name, JOB_NOTIFY_TYPE, JOB_NOTIFY_DOCUMENT, @@ -194,7 +194,7 @@ void notify_job_name(int snum, uint32 jobid, char *name) void notify_job_submitted(int snum, uint32 jobid, time_t submitted) { - char *printer_name = PRINTERNAME(snum); + const char *printer_name = PRINTERNAME(snum); send_notify_field_buffer( printer_name, JOB_NOTIFY_TYPE, JOB_NOTIFY_SUBMITTED, -- cgit