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