1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

Fixup the sending of printer change messages from job changes.

Jeremy.
(This used to be commit 28d4e7a3e2)
This commit is contained in:
Jeremy Allison 2002-02-26 03:12:09 +00:00
parent 2f8452fd49
commit 2ff9390245
3 changed files with 45 additions and 28 deletions

View File

@ -246,16 +246,6 @@ static int traverse_fn_delete(TDB_CONTEXT *t, TDB_DATA key, TDB_DATA data, void
return 0;
}
/**
* Send PRINTER NOTIFY to all processes.
**/
void broadcast_printer_notify(const char *printer_name)
{
/* include NUL */
message_send_all(conn_tdb_ctx(), MSG_PRINTER_NOTIFY, printer_name,
strlen(printer_name) + 1, False, NULL);
}
/****************************************************************************
check if the print queue has been updated recently enough
****************************************************************************/
@ -320,6 +310,20 @@ static void set_updating_pid(fstring printer_name, BOOL delete)
tdb_store(tdb, key, data, TDB_REPLACE);
}
/****************************************************************************
Send a message saying the queue changed.
****************************************************************************/
static void send_queue_message(const char *printer_name, uint32 high, uint32 low)
{
char msg[8 + sizeof(fstring)];
SIVAL(msg,0,low);
SIVAL(msg,4,high);
fstrcpy(&msg[8], printer_name);
message_send_all(conn_tdb_ctx(), MSG_PRINTER_NOTIFY, msg, 8 + strlen(printer_name) + 1, False, NULL);
}
/****************************************************************************
update the internal database from the system print queue for a queue in the background
****************************************************************************/
@ -452,7 +456,7 @@ static void print_queue_update_background(int snum)
if( qcount != get_queue_status(snum, &old_status)) {
DEBUG(10,("print_queue_update: queue status change %d jobs -> %d jobs for printer %s\n",
old_status.qcount, qcount, printer_name ));
broadcast_printer_notify(printer_name);
send_queue_message(printer_name, 0, PRINTER_CHANGE_JOB);
}
/* store the new queue status structure */
@ -696,7 +700,7 @@ BOOL print_job_delete(struct current_user *user, int jobid, WERROR *errcode)
printer_name = PRINTERNAME(snum);
broadcast_printer_notify(printer_name);
send_queue_message(printer_name, 0, PRINTER_CHANGE_JOB);
return !print_job_exists(jobid);
}
@ -739,7 +743,7 @@ BOOL print_job_pause(struct current_user *user, int jobid, WERROR *errcode)
printer_name = PRINTERNAME(snum);
broadcast_printer_notify(printer_name);
send_queue_message(printer_name, 0, PRINTER_CHANGE_JOB);
/* how do we tell if this succeeded? */
@ -782,7 +786,7 @@ BOOL print_job_resume(struct current_user *user, int jobid, WERROR *errcode)
printer_name = PRINTERNAME(snum);
broadcast_printer_notify(printer_name);
send_queue_message(printer_name, 0, PRINTER_CHANGE_JOB);
return True;
}
@ -1282,7 +1286,7 @@ BOOL print_queue_pause(struct current_user *user, int snum, WERROR *errcode)
printer_name = PRINTERNAME(snum);
broadcast_printer_notify(printer_name);
send_queue_message(printer_name, 0, PRINTER_CHANGE_JOB);
return True;
}
@ -1314,7 +1318,7 @@ BOOL print_queue_resume(struct current_user *user, int snum, WERROR *errcode)
printer_name = PRINTERNAME(snum);
broadcast_printer_notify(printer_name);
send_queue_message(printer_name, 0, PRINTER_CHANGE_JOB);
return True;
}
@ -1350,7 +1354,7 @@ BOOL print_queue_purge(struct current_user *user, int snum, WERROR *errcode)
printer_name = PRINTERNAME(snum);
broadcast_printer_notify(printer_name);
send_queue_message(printer_name, 0, PRINTER_CHANGE_JOB);
return True;
}

View File

@ -566,33 +566,39 @@ static void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size
{
Printer_entry *find_printer;
WERROR status;
fstring printer_name;
char msg[8];
char *buf_ptr = (char *)buf;
uint32 low, high;
if (len != sizeof(msg)) {
if (len < sizeof(msg) + 2) {
DEBUG(2,("srv_spoolss_receive_message: got incorrect message size (%u)!\n", (unsigned int)len));
return;
}
memcpy(msg, buf, len);
memcpy(msg, buf_ptr, sizeof(msg));
low = IVAL(msg,0);
high = IVAL(msg,4);
fstrcpy(printer_name, buf_ptr + sizeof(msg));
DEBUG(10,("srv_spoolss_receive_message: Got message printer change low=0x%x high=0x%x\n", (unsigned int)low,
(unsigned int)high ));
find_printer = printers_list;
DEBUG(10,("srv_spoolss_receive_message: Got message printer change name [%s] low=0x%x high=0x%x\n",
printer_name, (unsigned int)low, (unsigned int)high ));
/* Iterate the printer list */
for(; find_printer; find_printer = find_printer->next) {
for(find_printer = printers_list; find_printer; find_printer = find_printer->next) {
/*
* If the entry has a connected client we send the message.
*/
if (find_printer->notify.client_connected==True) {
DEBUG(10,("srv_spoolss_receive_message: printerserver [%s]\n", find_printer->dev.printerservername ));
if (*printer_name && !strequal(printer_name, find_printer->dev.handlename)) {
DEBUG(10,("srv_spoolss_receive_message: ignoring message sent to %s [%s]\n",
printer_name, find_printer->dev.handlename ));
continue;
}
if (cli_spoolss_reply_rrpcn(&cli, &find_printer->notify.client_hnd, low, high, &status))
DEBUG(10,("srv_spoolss_receive_message: cli_spoolss_reply_rrpcn status = 0x%x\n",
(unsigned int)W_ERROR_V(status)));
@ -608,8 +614,9 @@ static void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size
static BOOL srv_spoolss_sendnotify(uint32 high, uint32 low)
{
char msg[8];
char msg[10];
ZERO_STRUCT(msg);
SIVAL(msg,0,low);
SIVAL(msg,4,high);
DEBUG(10,("srv_spoolss_sendnotify: printer change low=0x%x high=0x%x\n", low, high));

View File

@ -334,8 +334,14 @@ static BOOL do_command(char *dest, char *msg_name, int iparams, char **params)
fprintf(stderr, "printer-notify needs a printer name\n");
return (False);
}
retval = send_message(dest, MSG_PRINTER_NOTIFY, params[0],
strlen(params[0]) + 1, False);
{
char msg[8 + sizeof(fstring)];
SIVAL(msg,0,PRINTER_CHANGE_ALL);
SIVAL(msg,4,0);
fstrcpy(&msg[8], params[0]);
retval = send_message(dest, MSG_PRINTER_NOTIFY, msg, 8 + strlen(params[0]) + 1, False);
}
break;
case MSG_SMB_FORCE_TDIS: