2 * Support code for Novell iPrint using the Common UNIX Printing
3 * System ("CUPS") libraries
5 * Copyright 1999-2003 by Michael R Sweet.
6 * Portions Copyright 2005 by Joel J. Smith.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
24 #include "printing/pcap.h"
27 #include <cups/cups.h>
28 #include <cups/language.h>
30 #define OPERATION_NOVELL_LIST_PRINTERS 0x401A
31 #define OPERATION_NOVELL_MGMT 0x401C
32 #define NOVELL_SERVER_SYSNAME "sysname="
33 #define NOVELL_SERVER_SYSNAME_NETWARE "NetWare IA32"
34 #define NOVELL_SERVER_VERSION_STRING "iprintserverversion="
35 #define NOVELL_SERVER_VERSION_OES_SP1 33554432
38 * 'iprint_passwd_cb()' - The iPrint password callback...
41 static const char * /* O - Password or NULL */
42 iprint_passwd_cb(const char *prompt
) /* I - Prompt */
45 * Always return NULL to indicate that no password is available...
51 static const char *iprint_server(void)
53 if ((lp_iprint_server() != NULL
) && (strlen(lp_iprint_server()) > 0)) {
54 DEBUG(10, ("iprint server explicitly set to %s\n",
56 return lp_iprint_server();
59 DEBUG(10, ("iprint server left to default %s\n", cupsServer()));
64 * Pass in an already connected http_t*
65 * Returns the server version if one can be found, multiplied by
66 * -1 for all NetWare versions. Returns 0 if a server version
67 * cannot be determined
70 static int iprint_get_server_version(http_t
*http
, char* serviceUri
)
72 ipp_t
*request
= NULL
, /* IPP Request */
73 *response
= NULL
; /* IPP Response */
74 ipp_attribute_t
*attr
; /* Current attribute */
75 cups_lang_t
*language
= NULL
; /* Default language */
76 char *ver
; /* server version pointer */
77 char *vertmp
; /* server version tmp pointer */
78 int serverVersion
= 0; /* server version */
79 char *os
; /* server os */
80 int osFlag
= 0; /* 0 for NetWare, 1 for anything else */
81 char *temp
; /* pointer for string manipulation */
84 * Build an OPERATION_NOVELL_MGMT("get-server-version") request,
85 * which requires the following attributes:
88 * attributes-natural-language
95 request
->request
.op
.operation_id
= (ipp_op_t
)OPERATION_NOVELL_MGMT
;
96 request
->request
.op
.request_id
= 1;
98 language
= cupsLangDefault();
100 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
101 "attributes-charset", NULL
, "utf-8");
103 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
104 "attributes-natural-language", NULL
, language
->language
);
106 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
107 "service-uri", NULL
, serviceUri
);
109 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
110 "operation-name", NULL
, "get-server-version");
113 * Do the request and get back a response...
116 if (((response
= cupsDoRequest(http
, request
, "/ipp/")) == NULL
) ||
117 (response
->request
.status
.status_code
>= IPP_OK_CONFLICT
))
120 if (((attr
= ippFindAttribute(response
, "server-version",
121 IPP_TAG_STRING
)) != NULL
)) {
122 if ((ver
= strstr(attr
->values
[0].string
.text
,
123 NOVELL_SERVER_VERSION_STRING
)) != NULL
) {
124 ver
+= strlen(NOVELL_SERVER_VERSION_STRING
);
126 * Strangely, libcups stores a IPP_TAG_STRING (octet
127 * string) as a null-terminated string with no length
128 * even though it could be binary data with nulls in
129 * it. Luckily, in this case the value is not binary.
131 serverVersion
= strtol(ver
, &vertmp
, 10);
133 /* Check for not found, overflow or negative version */
134 if ((ver
== vertmp
) || (serverVersion
< 0))
138 if ((os
= strstr(attr
->values
[0].string
.text
,
139 NOVELL_SERVER_SYSNAME
)) != NULL
) {
140 os
+= strlen(NOVELL_SERVER_SYSNAME
);
141 if ((temp
= strchr(os
,'<')) != NULL
)
143 if (strcmp(os
,NOVELL_SERVER_SYSNAME_NETWARE
))
144 osFlag
= 1; /* 1 for non-NetWare systems */
153 cupsLangFree(language
);
158 return serverVersion
;
162 static int iprint_cache_add_printer(http_t
*http
,
166 ipp_t
*request
= NULL
, /* IPP Request */
167 *response
= NULL
; /* IPP Response */
168 ipp_attribute_t
*attr
; /* Current attribute */
169 cups_lang_t
*language
= NULL
; /* Default language */
170 char *name
, /* printer-name attribute */
171 *info
, /* printer-info attribute */
172 smb_enabled
, /* smb-enabled attribute */
173 secure
; /* security-enabled attrib. */
175 char *httpPath
; /* path portion of the printer-uri */
177 static const char *pattrs
[] = /* Requested printer attributes */
187 request
->request
.op
.operation_id
= IPP_GET_PRINTER_ATTRIBUTES
;
188 request
->request
.op
.request_id
= reqId
;
190 language
= cupsLangDefault();
192 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
193 "attributes-charset", NULL
, "utf-8");
195 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
196 "attributes-natural-language", NULL
, language
->language
);
198 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, url
);
200 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
201 "requested-attributes",
202 (sizeof(pattrs
) / sizeof(pattrs
[0])),
206 * Do the request and get back a response...
209 if ((httpPath
= strstr(url
,"://")) == NULL
||
210 (httpPath
= strchr(httpPath
+3,'/')) == NULL
)
217 if ((response
= cupsDoRequest(http
, request
, httpPath
)) == NULL
) {
218 ipp_status_t lastErr
= cupsLastError();
221 * Ignore printers that cannot be queried without credentials
223 if (lastErr
== IPP_FORBIDDEN
||
224 lastErr
== IPP_NOT_AUTHENTICATED
||
225 lastErr
== IPP_NOT_AUTHORIZED
)
228 DEBUG(0,("Unable to get printer list - %s\n",
229 ippErrorString(lastErr
)));
233 for (attr
= response
->attrs
; attr
!= NULL
;) {
235 * Skip leading attributes until we hit a printer...
238 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
245 * Pull the needed attributes from this printer...
253 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
) {
254 if (strcmp(attr
->name
, "printer-name") == 0 &&
255 attr
->value_tag
== IPP_TAG_NAME
)
256 name
= attr
->values
[0].string
.text
;
258 if (strcmp(attr
->name
, "printer-info") == 0 &&
259 (attr
->value_tag
== IPP_TAG_TEXT
||
260 attr
->value_tag
== IPP_TAG_TEXTLANG
))
261 info
= attr
->values
[0].string
.text
;
264 * If the smb-enabled attribute is present and the
265 * value is set to 0, don't show the printer.
266 * If the attribute is not present, assume that the
267 * printer should show up
269 if (!strcmp(attr
->name
, "smb-enabled") &&
270 ((attr
->value_tag
== IPP_TAG_INTEGER
&&
271 !attr
->values
[0].integer
) ||
272 (attr
->value_tag
== IPP_TAG_BOOLEAN
&&
273 !attr
->values
[0].boolean
)))
277 * If the security-enabled attribute is present and the
278 * value is set to 1, don't show the printer.
279 * If the attribute is not present, assume that the
280 * printer should show up
282 if (!strcmp(attr
->name
, "security-enabled") &&
283 ((attr
->value_tag
== IPP_TAG_INTEGER
&&
284 attr
->values
[0].integer
) ||
285 (attr
->value_tag
== IPP_TAG_BOOLEAN
&&
286 attr
->values
[0].boolean
)))
293 * See if we have everything needed...
294 * Make sure the printer is not a secure printer
295 * and make sure smb printing hasn't been explicitly
296 * disabled for the printer
299 if (name
!= NULL
&& !secure
&& smb_enabled
)
300 pcap_cache_add(name
, info
);
309 bool iprint_cache_reload(void)
311 http_t
*http
= NULL
; /* HTTP connection to server */
312 ipp_t
*request
= NULL
, /* IPP Request */
313 *response
= NULL
; /* IPP Response */
314 ipp_attribute_t
*attr
; /* Current attribute */
315 cups_lang_t
*language
= NULL
; /* Default language */
319 DEBUG(5, ("reloading iprint printcap cache\n"));
322 * Make sure we don't ask for passwords...
325 cupsSetPasswordCB(iprint_passwd_cb
);
328 * Try to connect to the server...
331 if ((http
= httpConnect(iprint_server(), ippPort())) == NULL
) {
332 DEBUG(0,("Unable to connect to iPrint server %s - %s\n",
333 iprint_server(), strerror(errno
)));
338 * Build a OPERATION_NOVELL_LIST_PRINTERS request, which requires the following attributes:
341 * attributes-natural-language
346 request
->request
.op
.operation_id
=
347 (ipp_op_t
)OPERATION_NOVELL_LIST_PRINTERS
;
348 request
->request
.op
.request_id
= 1;
350 language
= cupsLangDefault();
352 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
353 "attributes-charset", NULL
, "utf-8");
355 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
356 "attributes-natural-language", NULL
, language
->language
);
358 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
359 "ipp-server", NULL
, "ippSrvr");
362 * Do the request and get back a response...
365 if ((response
= cupsDoRequest(http
, request
, "/ipp")) == NULL
) {
366 DEBUG(0,("Unable to get printer list - %s\n",
367 ippErrorString(cupsLastError())));
371 for (attr
= response
->attrs
; attr
!= NULL
;) {
373 * Skip leading attributes until we hit a printer...
376 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
383 * Pull the needed attributes from this printer...
386 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
388 if (strcmp(attr
->name
, "printer-name") == 0 &&
389 (attr
->value_tag
== IPP_TAG_URI
||
390 attr
->value_tag
== IPP_TAG_NAME
||
391 attr
->value_tag
== IPP_TAG_TEXT
||
392 attr
->value_tag
== IPP_TAG_NAMELANG
||
393 attr
->value_tag
== IPP_TAG_TEXTLANG
))
395 for (i
= 0; i
<attr
->num_values
; i
++)
397 char *url
= attr
->values
[i
].string
.text
;
398 if (!url
|| !strlen(url
))
400 iprint_cache_add_printer(http
, i
+2, url
);
414 cupsLangFree(language
);
424 * 'iprint_job_delete()' - Delete a job.
427 static int iprint_job_delete(const char *sharename
, const char *lprm_command
, struct printjob
*pjob
)
429 int ret
= 1; /* Return value */
430 http_t
*http
= NULL
; /* HTTP connection to server */
431 ipp_t
*request
= NULL
, /* IPP Request */
432 *response
= NULL
; /* IPP Response */
433 cups_lang_t
*language
= NULL
; /* Default language */
434 char uri
[HTTP_MAX_URI
]; /* printer-uri attribute */
435 char httpPath
[HTTP_MAX_URI
]; /* path portion of the printer-uri */
438 DEBUG(5,("iprint_job_delete(%s, %p (%d))\n", sharename
, pjob
, pjob
->sysjob
));
441 * Make sure we don't ask for passwords...
444 cupsSetPasswordCB(iprint_passwd_cb
);
447 * Try to connect to the server...
450 if ((http
= httpConnect(iprint_server(), ippPort())) == NULL
) {
451 DEBUG(0,("Unable to connect to iPrint server %s - %s\n",
452 iprint_server(), strerror(errno
)));
457 * Build an IPP_CANCEL_JOB request, which uses the following
461 * attributes-natural-language
464 * requesting-user-name
469 request
->request
.op
.operation_id
= IPP_CANCEL_JOB
;
470 request
->request
.op
.request_id
= 1;
472 language
= cupsLangDefault();
474 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
475 "attributes-charset", NULL
, "utf-8");
477 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
478 "attributes-natural-language", NULL
, language
->language
);
480 slprintf(uri
, sizeof(uri
) - 1, "ipp://%s/ipp/%s", iprint_server(), sharename
);
482 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, uri
);
484 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "job-id", pjob
->sysjob
);
486 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
490 * Do the request and get back a response...
493 slprintf(httpPath
, sizeof(httpPath
) - 1, "/ipp/%s", sharename
);
495 if ((response
= cupsDoRequest(http
, request
, httpPath
)) != NULL
) {
496 if (response
->request
.status
.status_code
>= IPP_OK_CONFLICT
) {
497 DEBUG(0,("Unable to cancel job %d - %s\n", pjob
->sysjob
,
498 ippErrorString(cupsLastError())));
503 DEBUG(0,("Unable to cancel job %d - %s\n", pjob
->sysjob
,
504 ippErrorString(cupsLastError())));
512 cupsLangFree(language
);
522 * 'iprint_job_pause()' - Pause a job.
525 static int iprint_job_pause(int snum
, struct printjob
*pjob
)
527 int ret
= 1; /* Return value */
528 http_t
*http
= NULL
; /* HTTP connection to server */
529 ipp_t
*request
= NULL
, /* IPP Request */
530 *response
= NULL
; /* IPP Response */
531 cups_lang_t
*language
= NULL
; /* Default language */
532 char uri
[HTTP_MAX_URI
]; /* printer-uri attribute */
533 char httpPath
[HTTP_MAX_URI
]; /* path portion of the printer-uri */
536 DEBUG(5,("iprint_job_pause(%d, %p (%d))\n", snum
, pjob
, pjob
->sysjob
));
539 * Make sure we don't ask for passwords...
542 cupsSetPasswordCB(iprint_passwd_cb
);
545 * Try to connect to the server...
548 if ((http
= httpConnect(iprint_server(), ippPort())) == NULL
) {
549 DEBUG(0,("Unable to connect to iPrint server %s - %s\n",
550 iprint_server(), strerror(errno
)));
555 * Build an IPP_HOLD_JOB request, which requires the following
559 * attributes-natural-language
562 * requesting-user-name
567 request
->request
.op
.operation_id
= IPP_HOLD_JOB
;
568 request
->request
.op
.request_id
= 1;
570 language
= cupsLangDefault();
572 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
573 "attributes-charset", NULL
, "utf-8");
575 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
576 "attributes-natural-language", NULL
, language
->language
);
578 slprintf(uri
, sizeof(uri
) - 1, "ipp://%s/ipp/%s", iprint_server(),
579 lp_printername(snum
));
581 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, uri
);
583 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "job-id", pjob
->sysjob
);
585 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
589 * Do the request and get back a response...
592 slprintf(httpPath
, sizeof(httpPath
) - 1, "/ipp/%s",
593 lp_printername(snum
));
595 if ((response
= cupsDoRequest(http
, request
, httpPath
)) != NULL
) {
596 if (response
->request
.status
.status_code
>= IPP_OK_CONFLICT
) {
597 DEBUG(0,("Unable to hold job %d - %s\n", pjob
->sysjob
,
598 ippErrorString(cupsLastError())));
603 DEBUG(0,("Unable to hold job %d - %s\n", pjob
->sysjob
,
604 ippErrorString(cupsLastError())));
612 cupsLangFree(language
);
622 * 'iprint_job_resume()' - Resume a paused job.
625 static int iprint_job_resume(int snum
, struct printjob
*pjob
)
627 int ret
= 1; /* Return value */
628 http_t
*http
= NULL
; /* HTTP connection to server */
629 ipp_t
*request
= NULL
, /* IPP Request */
630 *response
= NULL
; /* IPP Response */
631 cups_lang_t
*language
= NULL
; /* Default language */
632 char uri
[HTTP_MAX_URI
]; /* printer-uri attribute */
633 char httpPath
[HTTP_MAX_URI
]; /* path portion of the printer-uri */
636 DEBUG(5,("iprint_job_resume(%d, %p (%d))\n", snum
, pjob
, pjob
->sysjob
));
639 * Make sure we don't ask for passwords...
642 cupsSetPasswordCB(iprint_passwd_cb
);
645 * Try to connect to the server...
648 if ((http
= httpConnect(iprint_server(), ippPort())) == NULL
) {
649 DEBUG(0,("Unable to connect to iPrint server %s - %s\n",
650 iprint_server(), strerror(errno
)));
655 * Build an IPP_RELEASE_JOB request, which requires the following
659 * attributes-natural-language
662 * requesting-user-name
667 request
->request
.op
.operation_id
= IPP_RELEASE_JOB
;
668 request
->request
.op
.request_id
= 1;
670 language
= cupsLangDefault();
672 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
673 "attributes-charset", NULL
, "utf-8");
675 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
676 "attributes-natural-language", NULL
, language
->language
);
678 slprintf(uri
, sizeof(uri
) - 1, "ipp://%s/ipp/%s", iprint_server(),
679 lp_printername(snum
));
681 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, uri
);
683 ippAddInteger(request
, IPP_TAG_OPERATION
, IPP_TAG_INTEGER
, "job-id", pjob
->sysjob
);
685 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
689 * Do the request and get back a response...
692 slprintf(httpPath
, sizeof(httpPath
) - 1, "/ipp/%s",
693 lp_printername(snum
));
695 if ((response
= cupsDoRequest(http
, request
, httpPath
)) != NULL
) {
696 if (response
->request
.status
.status_code
>= IPP_OK_CONFLICT
) {
697 DEBUG(0,("Unable to release job %d - %s\n", pjob
->sysjob
,
698 ippErrorString(cupsLastError())));
703 DEBUG(0,("Unable to release job %d - %s\n", pjob
->sysjob
,
704 ippErrorString(cupsLastError())));
712 cupsLangFree(language
);
722 * 'iprint_job_submit()' - Submit a job for printing.
725 static int iprint_job_submit(int snum
, struct printjob
*pjob
)
727 int ret
= 1; /* Return value */
728 http_t
*http
= NULL
; /* HTTP connection to server */
729 ipp_t
*request
= NULL
, /* IPP Request */
730 *response
= NULL
; /* IPP Response */
731 ipp_attribute_t
*attr
; /* Current attribute */
732 cups_lang_t
*language
= NULL
; /* Default language */
733 char uri
[HTTP_MAX_URI
]; /* printer-uri attribute */
734 const char *clientname
= NULL
; /* hostname of client for job-originating-host attribute */
735 char addr
[INET6_ADDRSTRLEN
];
737 DEBUG(5,("iprint_job_submit(%d, %p (%d))\n", snum
, pjob
, pjob
->sysjob
));
740 * Make sure we don't ask for passwords...
743 cupsSetPasswordCB(iprint_passwd_cb
);
746 * Try to connect to the server...
749 if ((http
= httpConnect(iprint_server(), ippPort())) == NULL
) {
750 DEBUG(0,("Unable to connect to iPrint server %s - %s\n",
751 iprint_server(), strerror(errno
)));
756 * Build an IPP_PRINT_JOB request, which requires the following
760 * attributes-natural-language
762 * requesting-user-name
768 request
->request
.op
.operation_id
= IPP_PRINT_JOB
;
769 request
->request
.op
.request_id
= 1;
771 language
= cupsLangDefault();
773 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
774 "attributes-charset", NULL
, "utf-8");
776 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
777 "attributes-natural-language", NULL
, language
->language
);
779 slprintf(uri
, sizeof(uri
) - 1, "ipp://%s/ipp/%s", iprint_server(),
780 lp_printername(snum
));
782 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
783 "printer-uri", NULL
, uri
);
785 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
788 clientname
= client_name(get_client_fd());
789 if (strcmp(clientname
, "UNKNOWN") == 0) {
790 clientname
= client_addr(get_client_fd(),addr
,sizeof(addr
));
793 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
794 "job-originating-host-name", NULL
,
797 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "job-name", NULL
,
801 * Do the request and get back a response...
804 slprintf(uri
, sizeof(uri
) - 1, "/ipp/%s", lp_printername(snum
));
806 if ((response
= cupsDoFileRequest(http
, request
, uri
, pjob
->filename
)) != NULL
) {
807 if (response
->request
.status
.status_code
>= IPP_OK_CONFLICT
) {
808 DEBUG(0,("Unable to print file to %s - %s\n",
809 lp_printername(snum
),
810 ippErrorString(cupsLastError())));
815 DEBUG(0,("Unable to print file to `%s' - %s\n",
816 lp_printername(snum
),
817 ippErrorString(cupsLastError())));
821 unlink(pjob
->filename
);
822 /* else print_job_end will do it for us */
826 attr
= ippFindAttribute(response
, "job-id", IPP_TAG_INTEGER
);
827 if (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_JOB
)
829 pjob
->sysjob
= attr
->values
[0].integer
;
838 cupsLangFree(language
);
847 * 'iprint_queue_get()' - Get all the jobs in the print queue.
850 static int iprint_queue_get(const char *sharename
,
851 enum printing_types printing_type
,
853 print_queue_struct
**q
,
854 print_status_struct
*status
)
857 http_t
*http
= NULL
; /* HTTP connection to server */
858 ipp_t
*request
= NULL
, /* IPP Request */
859 *response
= NULL
; /* IPP Response */
860 ipp_attribute_t
*attr
= NULL
; /* Current attribute */
861 cups_lang_t
*language
= NULL
; /* Default language */
862 char uri
[HTTP_MAX_URI
]; /* printer-uri attribute */
863 char serviceUri
[HTTP_MAX_URI
]; /* service-uri attribute */
864 char httpPath
[HTTP_MAX_URI
]; /* path portion of the uri */
865 int jobUseUnixTime
= 0; /* Whether job times should
866 * be assumed to be Unix time */
867 int qcount
= 0, /* Number of active queue entries */
868 qalloc
= 0; /* Number of queue entries allocated */
869 print_queue_struct
*queue
= NULL
, /* Queue entries */
870 *temp
; /* Temporary pointer for queue */
871 const char *user_name
, /* job-originating-user-name attribute */
872 *job_name
; /* job-name attribute */
873 int job_id
; /* job-id attribute */
874 int job_k_octets
; /* job-k-octets attribute */
875 time_t job_time
; /* time-at-creation attribute */
876 time_t printer_current_time
= 0; /* printer's current time */
877 time_t printer_up_time
= 0; /* printer's uptime */
878 ipp_jstate_t job_status
; /* job-status attribute */
879 int job_priority
; /* job-priority attribute */
880 static const char *jattrs
[] = /* Requested job attributes */
885 "job-originating-user-name",
890 static const char *pattrs
[] = /* Requested printer attributes */
893 "printer-state-message",
894 "printer-current-time",
900 /* HACK ALERT!!! The porblem with support the 'printer name'
901 option is that we key the tdb off the sharename. So we will
902 overload the lpq_command string to pass in the printername
903 (which is basically what we do for non-cups printers ... using
904 the lpq_command to get the queue listing). */
906 fstrcpy( printername
, lpq_command
);
908 DEBUG(5,("iprint_queue_get(%s, %p, %p)\n", printername
, q
, status
));
911 * Make sure we don't ask for passwords...
914 cupsSetPasswordCB(iprint_passwd_cb
);
917 * Try to connect to the server...
920 if ((http
= httpConnect(iprint_server(), ippPort())) == NULL
) {
921 DEBUG(0,("Unable to connect to iPrint server %s - %s\n",
922 iprint_server(), strerror(errno
)));
927 * Generate the printer URI and the service URI that goes with it...
930 slprintf(uri
, sizeof(uri
) - 1, "ipp://%s/ipp/%s", iprint_server(), printername
);
931 slprintf(serviceUri
, sizeof(serviceUri
) - 1, "ipp://%s/ipp/", iprint_server());
934 * For Linux iPrint servers from OES SP1 on, the iPrint server
935 * uses Unix time for job start times unless it detects the iPrint
936 * client in an http User-Agent header. (This was done to accomodate
937 * CUPS broken behavior. According to RFC 2911, section 4.3.14, job
938 * start times are supposed to be relative to how long the printer has
939 * been up.) Since libcups doesn't allow us to set that header before
940 * the request is sent, this ugly hack allows us to detect the server
941 * version and decide how to interpret the job time.
943 if (iprint_get_server_version(http
, serviceUri
) >=
944 NOVELL_SERVER_VERSION_OES_SP1
)
949 request
->request
.op
.operation_id
= IPP_GET_PRINTER_ATTRIBUTES
;
950 request
->request
.op
.request_id
= 2;
952 language
= cupsLangDefault();
954 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
955 "attributes-charset", NULL
, "utf-8");
957 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
958 "attributes-natural-language", NULL
, language
->language
);
960 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
961 "printer-uri", NULL
, uri
);
963 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
964 "requested-attributes",
965 (sizeof(pattrs
) / sizeof(pattrs
[0])),
969 * Do the request and get back a response...
972 slprintf(httpPath
, sizeof(httpPath
) - 1, "/ipp/%s", printername
);
974 if ((response
= cupsDoRequest(http
, request
, httpPath
)) == NULL
) {
975 DEBUG(0,("Unable to get printer status for %s - %s\n", printername
,
976 ippErrorString(cupsLastError())));
981 if (response
->request
.status
.status_code
>= IPP_OK_CONFLICT
) {
982 DEBUG(0,("Unable to get printer status for %s - %s\n", printername
,
983 ippErrorString(response
->request
.status
.status_code
)));
989 * Get the current printer status and convert it to the SAMBA values.
992 if ((attr
= ippFindAttribute(response
, "printer-state", IPP_TAG_ENUM
)) != NULL
) {
993 if (attr
->values
[0].integer
== IPP_PRINTER_STOPPED
)
994 status
->status
= LPSTAT_STOPPED
;
996 status
->status
= LPSTAT_OK
;
999 if ((attr
= ippFindAttribute(response
, "printer-state-message",
1000 IPP_TAG_TEXT
)) != NULL
)
1001 fstrcpy(status
->message
, attr
->values
[0].string
.text
);
1003 if ((attr
= ippFindAttribute(response
, "printer-current-time",
1004 IPP_TAG_DATE
)) != NULL
)
1005 printer_current_time
= ippDateToTime(attr
->values
[0].date
);
1007 if ((attr
= ippFindAttribute(response
, "printer-up-time",
1008 IPP_TAG_INTEGER
)) != NULL
)
1009 printer_up_time
= attr
->values
[0].integer
;
1011 ippDelete(response
);
1015 * Build an IPP_GET_JOBS request, which requires the following
1018 * attributes-charset
1019 * attributes-natural-language
1020 * requested-attributes
1026 request
->request
.op
.operation_id
= IPP_GET_JOBS
;
1027 request
->request
.op
.request_id
= 3;
1029 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
1030 "attributes-charset", NULL
, "utf-8");
1032 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
1033 "attributes-natural-language", NULL
, language
->language
);
1035 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1036 "printer-uri", NULL
, uri
);
1038 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1039 "requested-attributes",
1040 (sizeof(jattrs
) / sizeof(jattrs
[0])),
1044 * Do the request and get back a response...
1047 slprintf(httpPath
, sizeof(httpPath
) - 1, "/ipp/%s", printername
);
1049 if ((response
= cupsDoRequest(http
, request
, httpPath
)) == NULL
) {
1050 DEBUG(0,("Unable to get jobs for %s - %s\n", uri
,
1051 ippErrorString(cupsLastError())));
1055 if (response
->request
.status
.status_code
>= IPP_OK_CONFLICT
) {
1056 DEBUG(0,("Unable to get jobs for %s - %s\n", uri
,
1057 ippErrorString(response
->request
.status
.status_code
)));
1062 * Process the jobs...
1069 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
) {
1071 * Skip leading attributes until we hit a job...
1074 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_JOB
)
1081 * Allocate memory as needed...
1083 if (qcount
>= qalloc
) {
1086 queue
= SMB_REALLOC_ARRAY(queue
, print_queue_struct
, qalloc
);
1088 if (queue
== NULL
) {
1089 DEBUG(0,("iprint_queue_get: Not enough memory!"));
1095 temp
= queue
+ qcount
;
1096 memset(temp
, 0, sizeof(print_queue_struct
));
1099 * Pull the needed attributes from this job...
1104 job_status
= IPP_JOB_PENDING
;
1110 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_JOB
) {
1111 if (attr
->name
== NULL
) {
1116 if (strcmp(attr
->name
, "job-id") == 0 &&
1117 attr
->value_tag
== IPP_TAG_INTEGER
)
1118 job_id
= attr
->values
[0].integer
;
1120 if (strcmp(attr
->name
, "job-k-octets") == 0 &&
1121 attr
->value_tag
== IPP_TAG_INTEGER
)
1122 job_k_octets
= attr
->values
[0].integer
;
1124 if (strcmp(attr
->name
, "job-priority") == 0 &&
1125 attr
->value_tag
== IPP_TAG_INTEGER
)
1126 job_priority
= attr
->values
[0].integer
;
1128 if (strcmp(attr
->name
, "job-state") == 0 &&
1129 attr
->value_tag
== IPP_TAG_ENUM
)
1130 job_status
= (ipp_jstate_t
)(attr
->values
[0].integer
);
1132 if (strcmp(attr
->name
, "time-at-creation") == 0 &&
1133 attr
->value_tag
== IPP_TAG_INTEGER
)
1136 * If jobs times are in Unix time, the accuracy of the job
1137 * start time depends upon the iPrint server's time being
1138 * set correctly. Otherwise, the accuracy depends upon
1139 * the Samba server's time being set correctly
1143 job_time
= attr
->values
[0].integer
;
1145 job_time
= time(NULL
) - printer_up_time
+ attr
->values
[0].integer
;
1148 if (strcmp(attr
->name
, "job-name") == 0 &&
1149 (attr
->value_tag
== IPP_TAG_NAMELANG
||
1150 attr
->value_tag
== IPP_TAG_NAME
))
1151 job_name
= attr
->values
[0].string
.text
;
1153 if (strcmp(attr
->name
, "job-originating-user-name") == 0 &&
1154 (attr
->value_tag
== IPP_TAG_NAMELANG
||
1155 attr
->value_tag
== IPP_TAG_NAME
))
1156 user_name
= attr
->values
[0].string
.text
;
1162 * See if we have everything needed...
1165 if (user_name
== NULL
|| job_name
== NULL
|| job_id
== 0) {
1173 temp
->size
= job_k_octets
* 1024;
1174 temp
->status
= job_status
== IPP_JOB_PENDING
? LPQ_QUEUED
:
1175 job_status
== IPP_JOB_STOPPED
? LPQ_PAUSED
:
1176 job_status
== IPP_JOB_HELD
? LPQ_PAUSED
:
1178 temp
->priority
= job_priority
;
1179 temp
->time
= job_time
;
1180 strncpy(temp
->fs_user
, user_name
, sizeof(temp
->fs_user
) - 1);
1181 strncpy(temp
->fs_file
, job_name
, sizeof(temp
->fs_file
) - 1);
1190 * Return the job queue...
1197 ippDelete(response
);
1200 cupsLangFree(language
);
1210 * 'iprint_queue_pause()' - Pause a print queue.
1213 static int iprint_queue_pause(int snum
)
1215 return(-1); /* Not supported without credentials */
1220 * 'iprint_queue_resume()' - Restart a print queue.
1223 static int iprint_queue_resume(int snum
)
1225 return(-1); /* Not supported without credentials */
1228 /*******************************************************************
1229 * iPrint printing interface definitions...
1230 ******************************************************************/
1232 struct printif iprint_printif
=
1237 iprint_queue_resume
,
1245 /* this keeps fussy compilers happy */
1246 void print_iprint_dummy(void);
1247 void print_iprint_dummy(void) {}
1248 #endif /* HAVE_IPRINT */