summaryrefslogtreecommitdiff
path: root/source3/printing/notify.c
blob: 1b2b7805e581d9fdb947f263636538af74d75c92 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/* 
   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 = conn_tdb_ctx();

	if (!tdb) {
		DEBUG(3, ("Failed to open connections database in send_spoolss_notify2_msg\n"));
		goto done;
	}
	
	message_send_all(tdb, MSG_PRINTER_NOTIFY2, buf, buflen, False, NULL);

done:
	SAFE_FREE(buf);
}

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(const 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)
{
	const char *printer_name = PRINTERNAME(snum);

	if (printer_name)
		notify_printer_status_byname(printer_name, 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 */

	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)
{
	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)
{
	const 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)
{
	const 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)
{
	const 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)
{
	const 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)
{
	const 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)
{
}