o Correct quirks entry for a MP3 player
[dragonfly.git] / lib / libncp / ncpl_queue.c
blob983f37b800d2557d3dda6f8b0ac62d4fb410b057
1 /*
2 * Copyright (c) 1999, Boris Popov
3 * All rights reserved.
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. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Boris Popov.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
32 * $FreeBSD: src/lib/libncp/ncpl_queue.c,v 1.2 1999/10/31 03:39:03 bp Exp $
33 * $DragonFly: src/lib/libncp/ncpl_queue.c,v 1.3 2007/11/25 01:28:23 swildner Exp $
35 * NetWare queue interface
38 #include <sys/types.h>
39 #include <errno.h>
40 #include <stdio.h>
41 #include <string.h>
42 #include <netncp/ncp_lib.h>
44 int
45 ncp_create_queue_job_and_file(NWCONN_HANDLE connid, u_int32_t queue_id,
46 struct queue_job *job)
48 int error;
49 DECLARE_RQ;
51 ncp_init_request_s(conn, 121);
52 ncp_add_dword_hl(conn, queue_id);
53 ncp_add_mem(conn, &(job->j), sizeof(job->j));
55 if ((error = ncp_request(connid, 23, conn)) != 0)
56 return error;
57 memcpy(&(job->j), ncp_reply_data(conn, 0), 78);
58 ConvertToNWfromDWORD(job->j.JobFileHandle, &job->file_handle);
59 return 0;
62 int
63 ncp_close_file_and_start_job(NWCONN_HANDLE connid, u_int32_t queue_id,
64 struct queue_job *job)
66 int error;
67 DECLARE_RQ;
69 ncp_init_request_s(conn, 127);
70 ncp_add_dword_hl(conn, queue_id);
71 ncp_add_dword_lh(conn, job->j.JobNumber);
72 error = ncp_request(connid, 23, conn);
73 return error;
76 int
77 ncp_attach_to_queue(NWCONN_HANDLE connid, u_int32_t queue_id) {
78 int error;
79 DECLARE_RQ;
81 ncp_init_request_s(conn, 111);
82 ncp_add_dword_hl(conn, queue_id);
83 error = ncp_request(connid, 23, conn);
84 return error;
87 int
88 ncp_detach_from_queue(NWCONN_HANDLE connid, u_int32_t queue_id) {
89 int error;
90 DECLARE_RQ;
92 ncp_init_request_s(conn, 112);
93 ncp_add_dword_hl(conn, queue_id);
94 error= ncp_request(connid, 23, conn);
95 return error;
98 int
99 ncp_service_queue_job(NWCONN_HANDLE connid, u_int32_t queue_id,
100 u_int16_t job_type, struct queue_job *job)
102 int error;
103 DECLARE_RQ;
105 ncp_init_request_s(conn, 124);
106 ncp_add_dword_hl(conn, queue_id);
107 ncp_add_word_hl(conn, job_type);
108 if ((error = ncp_request(connid, 23, conn)) != 0) {
109 return error;
111 memcpy(&(job->j), ncp_reply_data(conn, 0), 78);
112 ConvertToNWfromDWORD(job->j.JobFileHandle, &job->file_handle);
113 return error;
117 ncp_finish_servicing_job(NWCONN_HANDLE connid, u_int32_t queue_id,
118 u_int32_t job_number, u_int32_t charge_info)
120 int error;
121 DECLARE_RQ;
123 ncp_init_request_s(conn, 131);
124 ncp_add_dword_hl(conn, queue_id);
125 ncp_add_dword_lh(conn, job_number);
126 ncp_add_dword_hl(conn, charge_info);
128 error = ncp_request(connid, 23, conn);
129 return error;
133 ncp_abort_servicing_job(NWCONN_HANDLE connid, u_int32_t queue_id,
134 u_int32_t job_number)
136 int error;
137 DECLARE_RQ;
139 ncp_init_request_s(conn, 132);
140 ncp_add_dword_hl(conn, queue_id);
141 ncp_add_dword_lh(conn, job_number);
142 error = ncp_request(connid, 23, conn);
143 return error;
147 ncp_get_queue_length(NWCONN_HANDLE connid, u_int32_t queue_id,
148 u_int32_t *queue_length)
150 int error;
151 DECLARE_RQ;
153 ncp_init_request_s(conn, 125);
154 ncp_add_dword_hl(conn, queue_id);
156 if ((error = ncp_request(connid, 23, conn)) != 0)
157 return error;
158 if (conn->rpsize < 12) {
159 ncp_printf("ncp_reply_size %d < 12\n", conn->rpsize);
160 return EINVAL;
162 if (ncp_reply_dword_hl(conn,0) != queue_id) {
163 printf("Ouch! Server didn't reply with same queue id in ncp_get_queue_length!\n");
164 return EINVAL;
166 *queue_length = ncp_reply_dword_lh(conn,8);
167 return error;
170 int
171 ncp_get_queue_job_ids(NWCONN_HANDLE connid, u_int32_t queue_id,
172 u_int32_t queue_section, u_int32_t *length1, u_int32_t *length2,
173 u_int32_t ids[])
175 int error;
176 DECLARE_RQ;
178 ncp_init_request_s(conn,129);
179 ncp_add_dword_hl(conn, queue_id);
180 ncp_add_dword_lh(conn, queue_section);
182 if ((error = ncp_request(connid, 23, conn)) != 0)
183 return error;
184 if (conn->rpsize < 8) {
185 ncp_printf("ncp_reply_size %d < 8\n", conn->rpsize);
186 return EINVAL;
188 *length2 = ncp_reply_dword_lh(conn,4);
189 if (conn->rpsize < 8 + 4*(*length2)) {
190 ncp_printf("ncp_reply_size %d < %d\n", conn->rpsize, 8+4*(*length2));
191 return EINVAL;
193 if (ids) {
194 int count = min(*length1, *length2)*sizeof(u_int32_t);
195 int pos;
197 for (pos=0; pos<count; pos+=sizeof(u_int32_t)) {
198 *ids++ = ncp_reply_dword_lh(conn, 8+pos);
201 *length1 = ncp_reply_dword_lh(conn,0);
202 return error;
206 ncp_get_queue_job_info(NWCONN_HANDLE connid, u_int32_t queue_id,
207 u_int32_t job_id, struct nw_queue_job_entry *jobdata)
209 int error;
210 DECLARE_RQ;
212 ncp_init_request_s(conn,122);
213 ncp_add_dword_hl(conn, queue_id);
214 ncp_add_dword_lh(conn, job_id);
216 if ((error = ncp_request(connid, 23, conn)) != 0)
217 return error;
219 if (conn->rpsize < sizeof(struct nw_queue_job_entry)) {
220 ncp_printf("ncp_reply_size %d < %d\n", conn->rpsize,sizeof(struct nw_queue_job_entry));
221 return EINVAL;
223 memcpy(jobdata,ncp_reply_data(conn,0), sizeof(struct nw_queue_job_entry));
224 return error;