preparing for release of 2.2.3a
[Samba.git] / source / libsmb / cliprint.c
blob57e2c049d8f2f35c1a27496dfc31785ff1c249bb
1 /*
2 Unix SMB/Netbios implementation.
3 Version 3.0
4 client print routines
5 Copyright (C) Andrew Tridgell 1994-1998
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #define NO_SYSLOG
24 #include "includes.h"
26 /*****************************************************************************
27 Convert a character pointer in a cli_call_api() response to a form we can use.
28 This function contains code to prevent core dumps if the server returns
29 invalid data.
30 *****************************************************************************/
31 static char *fix_char_ptr(unsigned int datap, unsigned int converter,
32 char *rdata, int rdrcnt)
34 if (datap == 0) { /* turn NULL pointers into zero length strings */
35 return "";
36 } else {
37 unsigned int offset = datap - converter;
39 if (offset >= rdrcnt) {
40 DEBUG(1,("bad char ptr: datap=%u, converter=%u rdrcnt=%d>",
41 datap, converter, rdrcnt));
42 return "<ERROR>";
43 } else {
44 return &rdata[offset];
50 /****************************************************************************
51 call fn() on each entry in a print queue
52 ****************************************************************************/
53 int cli_print_queue(struct cli_state *cli,
54 void (*fn)(struct print_job_info *))
56 char *rparam = NULL;
57 char *rdata = NULL;
58 char *p;
59 int rdrcnt, rprcnt;
60 pstring param;
61 int result_code=0;
62 int i = -1;
64 memset(param,'\0',sizeof(param));
66 p = param;
67 SSVAL(p,0,76); /* API function number 76 (DosPrintJobEnum) */
68 p += 2;
69 pstrcpy(p,"zWrLeh"); /* parameter description? */
70 p = skip_string(p,1);
71 pstrcpy(p,"WWzWWDDzz"); /* returned data format */
72 p = skip_string(p,1);
73 pstrcpy(p,cli->share); /* name of queue */
74 p = skip_string(p,1);
75 SSVAL(p,0,2); /* API function level 2, PRJINFO_2 data structure */
76 SSVAL(p,2,1000); /* size of bytes of returned data buffer */
77 p += 4;
78 pstrcpy(p,""); /* subformat */
79 p = skip_string(p,1);
81 DEBUG(4,("doing cli_print_queue for %s\n", cli->share));
83 if (cli_api(cli,
84 param, PTR_DIFF(p,param), 1024, /* Param, length, maxlen */
85 NULL, 0, CLI_BUFFER_SIZE, /* data, length, maxlen */
86 &rparam, &rprcnt, /* return params, length */
87 &rdata, &rdrcnt)) { /* return data, length */
88 int converter;
89 result_code = SVAL(rparam,0);
90 converter = SVAL(rparam,2); /* conversion factor */
92 if (result_code == 0) {
93 struct print_job_info job;
95 p = rdata;
97 for (i = 0; i < SVAL(rparam,4); ++i) {
98 job.id = SVAL(p,0);
99 job.priority = SVAL(p,2);
100 fstrcpy(job.user,
101 fix_char_ptr(SVAL(p,4), converter,
102 rdata, rdrcnt));
103 job.t = make_unix_date3(p + 12);
104 job.size = IVAL(p,16);
105 fstrcpy(job.name,fix_char_ptr(SVAL(p,24),
106 converter,
107 rdata, rdrcnt));
108 fn(&job);
109 p += 28;
114 /* If any parameters or data were returned, free the storage. */
115 SAFE_FREE(rparam);
116 SAFE_FREE(rdata);
118 return i;
121 /****************************************************************************
122 cancel a print job
123 ****************************************************************************/
124 int cli_printjob_del(struct cli_state *cli, int job)
126 char *rparam = NULL;
127 char *rdata = NULL;
128 char *p;
129 int rdrcnt,rprcnt, ret = -1;
130 pstring param;
132 memset(param,'\0',sizeof(param));
134 p = param;
135 SSVAL(p,0,81); /* DosPrintJobDel() */
136 p += 2;
137 pstrcpy(p,"W");
138 p = skip_string(p,1);
139 pstrcpy(p,"");
140 p = skip_string(p,1);
141 SSVAL(p,0,job);
142 p += 2;
144 if (cli_api(cli,
145 param, PTR_DIFF(p,param), 1024, /* Param, length, maxlen */
146 NULL, 0, CLI_BUFFER_SIZE, /* data, length, maxlen */
147 &rparam, &rprcnt, /* return params, length */
148 &rdata, &rdrcnt)) { /* return data, length */
149 ret = SVAL(rparam,0);
152 SAFE_FREE(rparam);
153 SAFE_FREE(rdata);
155 return ret;