]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - lib/libncp/ncpl_queue.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / lib / libncp / ncpl_queue.c
1 /*
2  * Copyright (c) 1999, Boris Popov
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the author nor the names of any co-contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * NetWare queue interface
30  */
31
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
34
35 #include <sys/types.h>
36 #include <errno.h>
37 #include <stdio.h>
38 #include <string.h>
39 #include <netncp/ncp_lib.h>
40
41 int
42 ncp_create_queue_job_and_file(NWCONN_HANDLE connid, u_int32_t queue_id, 
43         struct queue_job *job)
44 {
45         int error;
46         DECLARE_RQ;
47
48         ncp_init_request_s(conn, 121);
49         ncp_add_dword_hl(conn, queue_id);
50         ncp_add_mem(conn, &(job->j), sizeof(job->j));
51
52         if ((error = ncp_request(connid, 23, conn)) != 0)
53                 return error;
54         memcpy(&(job->j), ncp_reply_data(conn, 0), 78);
55         ConvertToNWfromDWORD(job->j.JobFileHandle, &job->file_handle);
56         return 0;
57 }
58
59 int
60 ncp_close_file_and_start_job(NWCONN_HANDLE connid, u_int32_t queue_id,
61         struct queue_job *job)
62 {
63         int error;
64         DECLARE_RQ;
65
66         ncp_init_request_s(conn, 127);
67         ncp_add_dword_hl(conn, queue_id);
68         ncp_add_dword_lh(conn, job->j.JobNumber);
69         error = ncp_request(connid, 23, conn);
70         return error;
71 }
72
73 int
74 ncp_attach_to_queue(NWCONN_HANDLE connid, u_int32_t queue_id) {
75         int error;
76         DECLARE_RQ;
77
78         ncp_init_request_s(conn, 111);
79         ncp_add_dword_hl(conn, queue_id);
80         error = ncp_request(connid, 23, conn);
81         return error;
82 }
83
84 int
85 ncp_detach_from_queue(NWCONN_HANDLE connid, u_int32_t queue_id) {
86         int error;
87         DECLARE_RQ;
88
89         ncp_init_request_s(conn, 112);
90         ncp_add_dword_hl(conn, queue_id);
91         error= ncp_request(connid, 23, conn);
92         return error;
93 }
94
95 int
96 ncp_service_queue_job(NWCONN_HANDLE connid, u_int32_t queue_id,
97         u_int16_t job_type, struct queue_job *job)
98 {
99         int error;
100         DECLARE_RQ;
101
102         ncp_init_request_s(conn, 124);
103         ncp_add_dword_hl(conn, queue_id);
104         ncp_add_word_hl(conn, job_type);
105         if ((error = ncp_request(connid, 23, conn)) != 0) {
106                 return error;
107         }
108         memcpy(&(job->j), ncp_reply_data(conn, 0), 78);
109         ConvertToNWfromDWORD(job->j.JobFileHandle, &job->file_handle);
110         return error;
111 }
112
113 int
114 ncp_finish_servicing_job(NWCONN_HANDLE connid, u_int32_t queue_id,
115         u_int32_t job_number, u_int32_t charge_info)
116 {
117         int error;
118         DECLARE_RQ;
119
120         ncp_init_request_s(conn, 131);
121         ncp_add_dword_hl(conn, queue_id);
122         ncp_add_dword_lh(conn, job_number);
123         ncp_add_dword_hl(conn, charge_info);
124
125         error = ncp_request(connid, 23, conn);
126         return error;
127 }
128
129 int
130 ncp_abort_servicing_job(NWCONN_HANDLE connid, u_int32_t queue_id,
131         u_int32_t job_number)
132 {
133         int error;
134         DECLARE_RQ;
135
136         ncp_init_request_s(conn, 132);
137         ncp_add_dword_hl(conn, queue_id);
138         ncp_add_dword_lh(conn, job_number);
139         error = ncp_request(connid, 23, conn);
140         return error;
141 }
142
143 int
144 ncp_get_queue_length(NWCONN_HANDLE connid, u_int32_t queue_id,
145         u_int32_t *queue_length)
146 {
147         int error;
148         DECLARE_RQ;
149
150         ncp_init_request_s(conn, 125);
151         ncp_add_dword_hl(conn, queue_id);
152
153         if ((error = ncp_request(connid, 23, conn)) != 0) 
154                 return error;
155         if (conn->rpsize < 12) {
156                 ncp_printf("ncp_reply_size %d < 12\n", conn->rpsize);
157                 return EINVAL;
158         }
159         if (ncp_reply_dword_hl(conn,0) != queue_id) {
160                 printf("Ouch! Server didn't reply with same queue id in ncp_get_queue_length!\n");
161                 return EINVAL;
162         }
163         *queue_length = ncp_reply_dword_lh(conn,8);
164         return error;
165 }
166
167 int 
168 ncp_get_queue_job_ids(NWCONN_HANDLE connid, u_int32_t queue_id,
169         u_int32_t queue_section, u_int32_t *length1, u_int32_t *length2,
170         u_int32_t ids[])
171 {
172         int error;
173         DECLARE_RQ;
174
175         ncp_init_request_s(conn,129);
176         ncp_add_dword_hl(conn, queue_id);
177         ncp_add_dword_lh(conn, queue_section);
178         
179         if ((error = ncp_request(connid, 23, conn)) != 0)
180                 return error;
181         if (conn->rpsize < 8) {
182                 ncp_printf("ncp_reply_size %d < 8\n", conn->rpsize);
183                 return EINVAL;
184         }
185         *length2 = ncp_reply_dword_lh(conn,4);
186         if (conn->rpsize < 8 + 4*(*length2)) {
187                 ncp_printf("ncp_reply_size %d < %d\n", conn->rpsize, 8+4*(*length2));
188                 return EINVAL;
189         }
190         if (ids) {
191                 int count = min(*length1, *length2)*sizeof(u_int32_t);
192                 int pos;
193
194                 for (pos=0; pos<count; pos+=sizeof(u_int32_t)) {
195                         *ids++ = ncp_reply_dword_lh(conn, 8+pos);
196                 }
197         }
198         *length1 = ncp_reply_dword_lh(conn,0);
199         return error;
200 }
201
202 int
203 ncp_get_queue_job_info(NWCONN_HANDLE connid, u_int32_t queue_id,
204         u_int32_t job_id, struct nw_queue_job_entry *jobdata)
205 {
206         int error;
207         DECLARE_RQ;
208
209         ncp_init_request_s(conn,122);
210         ncp_add_dword_hl(conn, queue_id);
211         ncp_add_dword_lh(conn, job_id);
212
213         if ((error = ncp_request(connid, 23, conn)) != 0)
214                 return error;
215
216         if (conn->rpsize < sizeof(struct nw_queue_job_entry)) {
217                 ncp_printf("ncp_reply_size %d < %d\n", conn->rpsize,sizeof(struct nw_queue_job_entry));
218                 return EINVAL;
219         }    
220         memcpy(jobdata,ncp_reply_data(conn,0), sizeof(struct nw_queue_job_entry));
221         return error;
222 }