4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 /* $Id: lpd-cancel.c 155 2006-04-26 02:34:54Z ktou $ */
30 #define __EXTENSIONS__ /* for strtok_r() */
35 #include <papi_impl.h>
38 lpd_cancel_job(service_t
*svc
, int id
)
40 papi_status_t status
= PAPI_INTERNAL_ERROR
;
43 char buf
[128]; /* this should be overkill */
46 return (PAPI_BAD_ARGUMENT
);
48 snprintf(buf
, sizeof (buf
), "%d", id
);
52 if ((fd
= lpd_open(svc
, 'c', list
, 15)) < 0)
53 return (PAPI_INTERNAL_ERROR
);
55 memset(buf
, 0, sizeof (buf
));
56 if (fdgets(buf
, sizeof (buf
), fd
) != NULL
) {
58 status
= PAPI_NOT_FOUND
;
59 else if ((strstr(buf
, "permission denied") != NULL
) ||
60 (strstr(buf
, "not-authorized") != NULL
))
61 status
= PAPI_NOT_AUTHORIZED
;
62 else if ((strstr(buf
, "cancelled") != NULL
) ||
63 (strstr(buf
, "removed") != NULL
))
66 status
= PAPI_NOT_FOUND
;
74 lpd_purge_jobs(service_t
*svc
, job_t
***jobs
)
76 papi_status_t status
= PAPI_INTERNAL_ERROR
;
82 return (PAPI_BAD_ARGUMENT
);
84 if ((fd
= lpd_open(svc
, 'c', NULL
, 15)) < 0)
85 return (PAPI_INTERNAL_ERROR
);
87 queue
= queue_name_from_uri(svc
->uri
);
90 memset(buf
, 0, sizeof (buf
));
91 while (fdgets(buf
, sizeof (buf
), fd
) != NULL
) {
92 /* if we canceled it, add it to the list */
93 if ((strstr(buf
, "cancelled") != NULL
) ||
94 (strstr(buf
, "removed") != NULL
)) {
96 papi_attribute_t
**attributes
= NULL
;
97 char *ptr
, *iter
= NULL
;
100 ptr
= strtok_r(buf
, ":", &iter
);
101 papiAttributeListAddString(&attributes
, PAPI_ATTR_EXCL
,
104 papiAttributeListAddInteger(&attributes
, PAPI_ATTR_EXCL
,
106 papiAttributeListAddString(&attributes
, PAPI_ATTR_EXCL
,
107 "job-printer", queue
);
109 if ((job
= (job_t
*)calloc(1, (sizeof (*job
))))
111 job
->attributes
= attributes
;
112 list_append(jobs
, job
);
114 papiAttributeListFree(attributes
);
115 } else if (strstr(buf
, "permission denied") != NULL
)
116 status
= PAPI_NOT_AUTHORIZED
;