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 const char *server = lp_iprint_server(talloc_tos());
55 if ((lp_iprint_server(server) != NULL) && (strlen(server) > 0)) {
56 DEBUG(10, ("iprint server explicitly set to %s\n",
61 DEBUG(10, ("iprint server left to default %s\n", cupsServer()));
66 * Pass in an already connected http_t*
67 * Returns the server version if one can be found, multiplied by
68 * -1 for all NetWare versions. Returns 0 if a server version
69 * cannot be determined
72 static int iprint_get_server_version(http_t *http, char* serviceUri)
74 ipp_t *request = NULL, /* IPP Request */
75 *response = NULL; /* IPP Response */
76 ipp_attribute_t *attr; /* Current attribute */
77 cups_lang_t *language = NULL; /* Default language */
78 char *ver; /* server version pointer */
79 char *vertmp; /* server version tmp pointer */
80 int serverVersion = 0; /* server version */
81 char *os; /* server os */
82 int osFlag = 0; /* 0 for NetWare, 1 for anything else */
83 char *temp; /* pointer for string manipulation */
86 * Build an OPERATION_NOVELL_MGMT("get-server-version") request,
87 * which requires the following attributes:
90 * attributes-natural-language
97 request->request.op.operation_id = (ipp_op_t)OPERATION_NOVELL_MGMT;
98 request->request.op.request_id = 1;
100 language = cupsLangDefault();
102 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
103 "attributes-charset", NULL, "utf-8");
105 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
106 "attributes-natural-language", NULL, language->language);
108 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
109 "service-uri", NULL, serviceUri);
111 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
112 "operation-name", NULL, "get-server-version");
115 * Do the request and get back a response...
118 if (((response = cupsDoRequest(http, request, "/ipp/")) == NULL) ||
119 (response->request.status.status_code >= IPP_OK_CONFLICT))
122 if (((attr = ippFindAttribute(response, "server-version",
123 IPP_TAG_STRING)) != NULL)) {
124 if ((ver = strstr(attr->values[0].string.text,
125 NOVELL_SERVER_VERSION_STRING)) != NULL) {
126 ver += strlen(NOVELL_SERVER_VERSION_STRING);
128 * Strangely, libcups stores a IPP_TAG_STRING (octet
129 * string) as a null-terminated string with no length
130 * even though it could be binary data with nulls in
131 * it. Luckily, in this case the value is not binary.
133 serverVersion = strtol(ver, &vertmp, 10);
135 /* Check for not found, overflow or negative version */
136 if ((ver == vertmp) || (serverVersion < 0))
140 if ((os = strstr(attr->values[0].string.text,
141 NOVELL_SERVER_SYSNAME)) != NULL) {
142 os += strlen(NOVELL_SERVER_SYSNAME);
143 if ((temp = strchr(os,'<')) != NULL)
145 if (strcmp(os,NOVELL_SERVER_SYSNAME_NETWARE))
146 osFlag = 1; /* 1 for non-NetWare systems */
155 cupsLangFree(language);
160 return serverVersion;
164 static int iprint_cache_add_printer(http_t *http,
168 ipp_t *request = NULL, /* IPP Request */
169 *response = NULL; /* IPP Response */
170 ipp_attribute_t *attr; /* Current attribute */
171 cups_lang_t *language = NULL; /* Default language */
172 char *name, /* printer-name attribute */
173 *info, /* printer-info attribute */
174 smb_enabled, /* smb-enabled attribute */
175 secure; /* security-enabled attrib. */
177 char *httpPath; /* path portion of the printer-uri */
179 static const char *pattrs[] = /* Requested printer attributes */
189 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
190 request->request.op.request_id = reqId;
192 language = cupsLangDefault();
194 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
195 "attributes-charset", NULL, "utf-8");
197 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
198 "attributes-natural-language", NULL, language->language);
200 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, url);
202 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
203 "requested-attributes",
204 (sizeof(pattrs) / sizeof(pattrs[0])),
208 * Do the request and get back a response...
211 if ((httpPath = strstr(url,"://")) == NULL ||
212 (httpPath = strchr(httpPath+3,'/')) == NULL)
219 if ((response = cupsDoRequest(http, request, httpPath)) == NULL) {
220 ipp_status_t lastErr = cupsLastError();
223 * Ignore printers that cannot be queried without credentials
225 if (lastErr == IPP_FORBIDDEN ||
226 lastErr == IPP_NOT_AUTHENTICATED ||
227 lastErr == IPP_NOT_AUTHORIZED)
230 DEBUG(0,("Unable to get printer list - %s\n",
231 ippErrorString(lastErr)));
235 for (attr = response->attrs; attr != NULL;) {
237 * Skip leading attributes until we hit a printer...
240 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
247 * Pull the needed attributes from this printer...
255 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) {
256 if (strcmp(attr->name, "printer-name") == 0 &&
257 attr->value_tag == IPP_TAG_NAME)
258 name = attr->values[0].string.text;
260 if (strcmp(attr->name, "printer-info") == 0 &&
261 (attr->value_tag == IPP_TAG_TEXT ||
262 attr->value_tag == IPP_TAG_TEXTLANG))
263 info = attr->values[0].string.text;
266 * If the smb-enabled attribute is present and the
267 * value is set to 0, don't show the printer.
268 * If the attribute is not present, assume that the
269 * printer should show up
271 if (!strcmp(attr->name, "smb-enabled") &&
272 ((attr->value_tag == IPP_TAG_INTEGER &&
273 !attr->values[0].integer) ||
274 (attr->value_tag == IPP_TAG_BOOLEAN &&
275 !attr->values[0].boolean)))
279 * If the security-enabled attribute is present and the
280 * value is set to 1, don't show the printer.
281 * If the attribute is not present, assume that the
282 * printer should show up
284 if (!strcmp(attr->name, "security-enabled") &&
285 ((attr->value_tag == IPP_TAG_INTEGER &&
286 attr->values[0].integer) ||
287 (attr->value_tag == IPP_TAG_BOOLEAN &&
288 attr->values[0].boolean)))
295 * See if we have everything needed...
296 * Make sure the printer is not a secure printer
297 * and make sure smb printing hasn't been explicitly
298 * disabled for the printer
301 if (name != NULL && !secure && smb_enabled)
302 pcap_cache_add(name, info, NULL);
311 bool iprint_cache_reload(void)
313 http_t *http = NULL; /* HTTP connection to server */
314 ipp_t *request = NULL, /* IPP Request */
315 *response = NULL; /* IPP Response */
316 ipp_attribute_t *attr; /* Current attribute */
317 cups_lang_t *language = NULL; /* Default language */
321 DEBUG(5, ("reloading iprint printcap cache\n"));
324 * Make sure we don't ask for passwords...
327 cupsSetPasswordCB(iprint_passwd_cb);
330 * Try to connect to the server...
333 if ((http = httpConnect(iprint_server(), ippPort())) == NULL) {
334 DEBUG(0,("Unable to connect to iPrint server %s - %s\n",
335 iprint_server(), strerror(errno)));
340 * Build a OPERATION_NOVELL_LIST_PRINTERS request, which requires the following attributes:
343 * attributes-natural-language
348 request->request.op.operation_id =
349 (ipp_op_t)OPERATION_NOVELL_LIST_PRINTERS;
350 request->request.op.request_id = 1;
352 language = cupsLangDefault();
354 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
355 "attributes-charset", NULL, "utf-8");
357 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
358 "attributes-natural-language", NULL, language->language);
360 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
361 "ipp-server", NULL, "ippSrvr");
364 * Do the request and get back a response...
367 if ((response = cupsDoRequest(http, request, "/ipp")) == NULL) {
368 DEBUG(0,("Unable to get printer list - %s\n",
369 ippErrorString(cupsLastError())));
373 for (attr = response->attrs; attr != NULL;) {
375 * Skip leading attributes until we hit a printer...
378 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
385 * Pull the needed attributes from this printer...
388 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
390 if (strcmp(attr->name, "printer-name") == 0 &&
391 (attr->value_tag == IPP_TAG_URI ||
392 attr->value_tag == IPP_TAG_NAME ||
393 attr->value_tag == IPP_TAG_TEXT ||
394 attr->value_tag == IPP_TAG_NAMELANG ||
395 attr->value_tag == IPP_TAG_TEXTLANG))
397 for (i = 0; i<attr->num_values; i++)
399 char *url = attr->values[i].string.text;
400 if (!url || !strlen(url))
402 iprint_cache_add_printer(http, i+2, url);
416 cupsLangFree(language);
426 * 'iprint_job_delete()' - Delete a job.
429 static int iprint_job_delete(const char *sharename, const char *lprm_command, struct printjob *pjob)
431 int ret = 1; /* Return value */
432 http_t *http = NULL; /* HTTP connection to server */
433 ipp_t *request = NULL, /* IPP Request */
434 *response = NULL; /* IPP Response */
435 cups_lang_t *language = NULL; /* Default language */
436 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
437 char httpPath[HTTP_MAX_URI]; /* path portion of the printer-uri */
440 DEBUG(5,("iprint_job_delete(%s, %p (%d))\n", sharename, pjob, pjob->sysjob));
443 * Make sure we don't ask for passwords...
446 cupsSetPasswordCB(iprint_passwd_cb);
449 * Try to connect to the server...
452 if ((http = httpConnect(iprint_server(), ippPort())) == NULL) {
453 DEBUG(0,("Unable to connect to iPrint server %s - %s\n",
454 iprint_server(), strerror(errno)));
459 * Build an IPP_CANCEL_JOB request, which uses the following
463 * attributes-natural-language
466 * requesting-user-name
471 request->request.op.operation_id = IPP_CANCEL_JOB;
472 request->request.op.request_id = 1;
474 language = cupsLangDefault();
476 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
477 "attributes-charset", NULL, "utf-8");
479 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
480 "attributes-natural-language", NULL, language->language);
482 slprintf(uri, sizeof(uri) - 1, "ipp://%s/ipp/%s", iprint_server(), sharename);
484 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
486 ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", pjob->sysjob);
488 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
492 * Do the request and get back a response...
495 slprintf(httpPath, sizeof(httpPath) - 1, "/ipp/%s", sharename);
497 if ((response = cupsDoRequest(http, request, httpPath)) != NULL) {
498 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
499 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
500 ippErrorString(cupsLastError())));
505 DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob,
506 ippErrorString(cupsLastError())));
514 cupsLangFree(language);
524 * 'iprint_job_pause()' - Pause a job.
527 static int iprint_job_pause(int snum, struct printjob *pjob)
529 int ret = 1; /* Return value */
530 http_t *http = NULL; /* HTTP connection to server */
531 ipp_t *request = NULL, /* IPP Request */
532 *response = NULL; /* IPP Response */
533 cups_lang_t *language = NULL; /* Default language */
534 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
535 char httpPath[HTTP_MAX_URI]; /* path portion of the printer-uri */
538 DEBUG(5,("iprint_job_pause(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
541 * Make sure we don't ask for passwords...
544 cupsSetPasswordCB(iprint_passwd_cb);
547 * Try to connect to the server...
550 if ((http = httpConnect(iprint_server(), ippPort())) == NULL) {
551 DEBUG(0,("Unable to connect to iPrint server %s - %s\n",
552 iprint_server(), strerror(errno)));
557 * Build an IPP_HOLD_JOB request, which requires the following
561 * attributes-natural-language
564 * requesting-user-name
569 request->request.op.operation_id = IPP_HOLD_JOB;
570 request->request.op.request_id = 1;
572 language = cupsLangDefault();
574 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
575 "attributes-charset", NULL, "utf-8");
577 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
578 "attributes-natural-language", NULL, language->language);
580 slprintf(uri, sizeof(uri) - 1, "ipp://%s/ipp/%s", iprint_server(),
581 lp_printername(talloc_tos(), snum));
583 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
585 ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", pjob->sysjob);
587 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
591 * Do the request and get back a response...
594 slprintf(httpPath, sizeof(httpPath) - 1, "/ipp/%s",
595 lp_printername(talloc_tos(), snum));
597 if ((response = cupsDoRequest(http, request, httpPath)) != NULL) {
598 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
599 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
600 ippErrorString(cupsLastError())));
605 DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob,
606 ippErrorString(cupsLastError())));
614 cupsLangFree(language);
624 * 'iprint_job_resume()' - Resume a paused job.
627 static int iprint_job_resume(int snum, struct printjob *pjob)
629 int ret = 1; /* Return value */
630 http_t *http = NULL; /* HTTP connection to server */
631 ipp_t *request = NULL, /* IPP Request */
632 *response = NULL; /* IPP Response */
633 cups_lang_t *language = NULL; /* Default language */
634 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
635 char httpPath[HTTP_MAX_URI]; /* path portion of the printer-uri */
638 DEBUG(5,("iprint_job_resume(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
641 * Make sure we don't ask for passwords...
644 cupsSetPasswordCB(iprint_passwd_cb);
647 * Try to connect to the server...
650 if ((http = httpConnect(iprint_server(), ippPort())) == NULL) {
651 DEBUG(0,("Unable to connect to iPrint server %s - %s\n",
652 iprint_server(), strerror(errno)));
657 * Build an IPP_RELEASE_JOB request, which requires the following
661 * attributes-natural-language
664 * requesting-user-name
669 request->request.op.operation_id = IPP_RELEASE_JOB;
670 request->request.op.request_id = 1;
672 language = cupsLangDefault();
674 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
675 "attributes-charset", NULL, "utf-8");
677 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
678 "attributes-natural-language", NULL, language->language);
680 slprintf(uri, sizeof(uri) - 1, "ipp://%s/ipp/%s", iprint_server(),
681 lp_printername(talloc_tos(), snum));
683 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
685 ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "job-id", pjob->sysjob);
687 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
691 * Do the request and get back a response...
694 slprintf(httpPath, sizeof(httpPath) - 1, "/ipp/%s",
695 lp_printername(talloc_tos(), snum));
697 if ((response = cupsDoRequest(http, request, httpPath)) != NULL) {
698 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
699 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
700 ippErrorString(cupsLastError())));
705 DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob,
706 ippErrorString(cupsLastError())));
714 cupsLangFree(language);
724 * 'iprint_job_submit()' - Submit a job for printing.
727 static int iprint_job_submit(int snum, struct printjob *pjob,
728 enum printing_types printing_type,
731 int ret = 1; /* Return value */
732 http_t *http = NULL; /* HTTP connection to server */
733 ipp_t *request = NULL, /* IPP Request */
734 *response = NULL; /* IPP Response */
735 ipp_attribute_t *attr; /* Current attribute */
736 cups_lang_t *language = NULL; /* Default language */
737 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
739 DEBUG(5,("iprint_job_submit(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
742 * Make sure we don't ask for passwords...
745 cupsSetPasswordCB(iprint_passwd_cb);
748 * Try to connect to the server...
751 if ((http = httpConnect(iprint_server(), ippPort())) == NULL) {
752 DEBUG(0,("Unable to connect to iPrint server %s - %s\n",
753 iprint_server(), strerror(errno)));
758 * Build an IPP_PRINT_JOB request, which requires the following
762 * attributes-natural-language
764 * requesting-user-name
770 request->request.op.operation_id = IPP_PRINT_JOB;
771 request->request.op.request_id = 1;
773 language = cupsLangDefault();
775 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
776 "attributes-charset", NULL, "utf-8");
778 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
779 "attributes-natural-language", NULL, language->language);
781 slprintf(uri, sizeof(uri) - 1, "ipp://%s/ipp/%s", iprint_server(),
782 lp_printername(talloc_tos(), snum));
784 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
785 "printer-uri", NULL, uri);
787 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
790 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
791 "job-originating-host-name", NULL,
792 pjob->clientmachine);
794 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
798 * Do the request and get back a response...
801 slprintf(uri, sizeof(uri) - 1, "/ipp/%s", lp_printername(talloc_tos(), snum));
803 if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) {
804 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
805 DEBUG(0,("Unable to print file to %s - %s\n",
806 lp_printername(talloc_tos(), snum),
807 ippErrorString(cupsLastError())));
812 DEBUG(0,("Unable to print file to `%s' - %s\n",
813 lp_printername(talloc_tos(), snum),
814 ippErrorString(cupsLastError())));
818 unlink(pjob->filename);
819 /* else print_job_end will do it for us */
823 attr = ippFindAttribute(response, "job-id", IPP_TAG_INTEGER);
824 if (attr != NULL && attr->group_tag == IPP_TAG_JOB)
826 pjob->sysjob = attr->values[0].integer;
835 cupsLangFree(language);
844 * 'iprint_queue_get()' - Get all the jobs in the print queue.
847 static int iprint_queue_get(const char *sharename,
848 enum printing_types printing_type,
850 print_queue_struct **q,
851 print_status_struct *status)
854 http_t *http = NULL; /* HTTP connection to server */
855 ipp_t *request = NULL, /* IPP Request */
856 *response = NULL; /* IPP Response */
857 ipp_attribute_t *attr = NULL; /* Current attribute */
858 cups_lang_t *language = NULL; /* Default language */
859 char uri[HTTP_MAX_URI]; /* printer-uri attribute */
860 char serviceUri[HTTP_MAX_URI]; /* service-uri attribute */
861 char httpPath[HTTP_MAX_URI]; /* path portion of the uri */
862 int jobUseUnixTime = 0; /* Whether job times should
863 * be assumed to be Unix time */
864 int qcount = 0, /* Number of active queue entries */
865 qalloc = 0; /* Number of queue entries allocated */
866 print_queue_struct *queue = NULL, /* Queue entries */
867 *temp; /* Temporary pointer for queue */
868 const char *user_name, /* job-originating-user-name attribute */
869 *job_name; /* job-name attribute */
870 int job_id; /* job-id attribute */
871 int job_k_octets; /* job-k-octets attribute */
872 time_t job_time; /* time-at-creation attribute */
873 time_t printer_up_time = 0; /* printer's uptime */
874 ipp_jstate_t job_status; /* job-status attribute */
875 int job_priority; /* job-priority attribute */
876 static const char *jattrs[] = /* Requested job attributes */
881 "job-originating-user-name",
886 static const char *pattrs[] = /* Requested printer attributes */
889 "printer-state-message",
890 "printer-current-time",
896 /* HACK ALERT!!! The porblem with support the 'printer name'
897 option is that we key the tdb off the sharename. So we will
898 overload the lpq_command string to pass in the printername
899 (which is basically what we do for non-cups printers ... using
900 the lpq_command to get the queue listing). */
902 fstrcpy( printername, lpq_command );
904 DEBUG(5,("iprint_queue_get(%s, %p, %p)\n", printername, q, status));
907 * Make sure we don't ask for passwords...
910 cupsSetPasswordCB(iprint_passwd_cb);
913 * Try to connect to the server...
916 if ((http = httpConnect(iprint_server(), ippPort())) == NULL) {
917 DEBUG(0,("Unable to connect to iPrint server %s - %s\n",
918 iprint_server(), strerror(errno)));
923 * Generate the printer URI and the service URI that goes with it...
926 slprintf(uri, sizeof(uri) - 1, "ipp://%s/ipp/%s", iprint_server(), printername);
927 slprintf(serviceUri, sizeof(serviceUri) - 1, "ipp://%s/ipp/", iprint_server());
930 * For Linux iPrint servers from OES SP1 on, the iPrint server
931 * uses Unix time for job start times unless it detects the iPrint
932 * client in an http User-Agent header. (This was done to accomodate
933 * CUPS broken behavior. According to RFC 2911, section 4.3.14, job
934 * start times are supposed to be relative to how long the printer has
935 * been up.) Since libcups doesn't allow us to set that header before
936 * the request is sent, this ugly hack allows us to detect the server
937 * version and decide how to interpret the job time.
939 if (iprint_get_server_version(http, serviceUri) >=
940 NOVELL_SERVER_VERSION_OES_SP1)
945 request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES;
946 request->request.op.request_id = 2;
948 language = cupsLangDefault();
950 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
951 "attributes-charset", NULL, "utf-8");
953 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
954 "attributes-natural-language", NULL, language->language);
956 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
957 "printer-uri", NULL, uri);
959 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
960 "requested-attributes",
961 (sizeof(pattrs) / sizeof(pattrs[0])),
965 * Do the request and get back a response...
968 slprintf(httpPath, sizeof(httpPath) - 1, "/ipp/%s", printername);
970 if ((response = cupsDoRequest(http, request, httpPath)) == NULL) {
971 DEBUG(0,("Unable to get printer status for %s - %s\n", printername,
972 ippErrorString(cupsLastError())));
977 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
978 DEBUG(0,("Unable to get printer status for %s - %s\n", printername,
979 ippErrorString(response->request.status.status_code)));
985 * Get the current printer status and convert it to the SAMBA values.
988 if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL) {
989 if (attr->values[0].integer == IPP_PRINTER_STOPPED)
990 status->status = LPSTAT_STOPPED;
992 status->status = LPSTAT_OK;
995 if ((attr = ippFindAttribute(response, "printer-state-message",
996 IPP_TAG_TEXT)) != NULL)
997 fstrcpy(status->message, attr->values[0].string.text);
999 if ((attr = ippFindAttribute(response, "printer-up-time",
1000 IPP_TAG_INTEGER)) != NULL)
1001 printer_up_time = attr->values[0].integer;
1003 ippDelete(response);
1007 * Build an IPP_GET_JOBS request, which requires the following
1010 * attributes-charset
1011 * attributes-natural-language
1012 * requested-attributes
1018 request->request.op.operation_id = IPP_GET_JOBS;
1019 request->request.op.request_id = 3;
1021 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
1022 "attributes-charset", NULL, "utf-8");
1024 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
1025 "attributes-natural-language", NULL, language->language);
1027 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
1028 "printer-uri", NULL, uri);
1030 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
1031 "requested-attributes",
1032 (sizeof(jattrs) / sizeof(jattrs[0])),
1036 * Do the request and get back a response...
1039 slprintf(httpPath, sizeof(httpPath) - 1, "/ipp/%s", printername);
1041 if ((response = cupsDoRequest(http, request, httpPath)) == NULL) {
1042 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
1043 ippErrorString(cupsLastError())));
1047 if (response->request.status.status_code >= IPP_OK_CONFLICT) {
1048 DEBUG(0,("Unable to get jobs for %s - %s\n", uri,
1049 ippErrorString(response->request.status.status_code)));
1054 * Process the jobs...
1061 for (attr = response->attrs; attr != NULL; attr = attr->next) {
1063 * Skip leading attributes until we hit a job...
1066 while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
1073 * Allocate memory as needed...
1075 if (qcount >= qalloc) {
1078 queue = SMB_REALLOC_ARRAY(queue, print_queue_struct, qalloc);
1080 if (queue == NULL) {
1081 DEBUG(0,("iprint_queue_get: Not enough memory!"));
1087 temp = queue + qcount;
1088 memset(temp, 0, sizeof(print_queue_struct));
1091 * Pull the needed attributes from this job...
1096 job_status = IPP_JOB_PENDING;
1102 while (attr != NULL && attr->group_tag == IPP_TAG_JOB) {
1103 if (attr->name == NULL) {
1108 if (strcmp(attr->name, "job-id") == 0 &&
1109 attr->value_tag == IPP_TAG_INTEGER)
1110 job_id = attr->values[0].integer;
1112 if (strcmp(attr->name, "job-k-octets") == 0 &&
1113 attr->value_tag == IPP_TAG_INTEGER)
1114 job_k_octets = attr->values[0].integer;
1116 if (strcmp(attr->name, "job-priority") == 0 &&
1117 attr->value_tag == IPP_TAG_INTEGER)
1118 job_priority = attr->values[0].integer;
1120 if (strcmp(attr->name, "job-state") == 0 &&
1121 attr->value_tag == IPP_TAG_ENUM)
1122 job_status = (ipp_jstate_t)(attr->values[0].integer);
1124 if (strcmp(attr->name, "time-at-creation") == 0 &&
1125 attr->value_tag == IPP_TAG_INTEGER)
1128 * If jobs times are in Unix time, the accuracy of the job
1129 * start time depends upon the iPrint server's time being
1130 * set correctly. Otherwise, the accuracy depends upon
1131 * the Samba server's time being set correctly
1135 job_time = attr->values[0].integer;
1137 job_time = time(NULL) - printer_up_time + attr->values[0].integer;
1140 if (strcmp(attr->name, "job-name") == 0 &&
1141 (attr->value_tag == IPP_TAG_NAMELANG ||
1142 attr->value_tag == IPP_TAG_NAME))
1143 job_name = attr->values[0].string.text;
1145 if (strcmp(attr->name, "job-originating-user-name") == 0 &&
1146 (attr->value_tag == IPP_TAG_NAMELANG ||
1147 attr->value_tag == IPP_TAG_NAME))
1148 user_name = attr->values[0].string.text;
1154 * See if we have everything needed...
1157 if (user_name == NULL || job_name == NULL || job_id == 0) {
1164 temp->sysjob = job_id;
1165 temp->size = job_k_octets * 1024;
1166 temp->status = job_status == IPP_JOB_PENDING ? LPQ_QUEUED :
1167 job_status == IPP_JOB_STOPPED ? LPQ_PAUSED :
1168 job_status == IPP_JOB_HELD ? LPQ_PAUSED :
1170 temp->priority = job_priority;
1171 temp->time = job_time;
1172 strncpy(temp->fs_user, user_name, sizeof(temp->fs_user) - 1);
1173 strncpy(temp->fs_file, job_name, sizeof(temp->fs_file) - 1);
1182 * Return the job queue...
1189 ippDelete(response);
1192 cupsLangFree(language);
1202 * 'iprint_queue_pause()' - Pause a print queue.
1205 static int iprint_queue_pause(int snum)
1207 return(-1); /* Not supported without credentials */
1212 * 'iprint_queue_resume()' - Restart a print queue.
1215 static int iprint_queue_resume(int snum)
1217 return(-1); /* Not supported without credentials */
1220 /*******************************************************************
1221 * iPrint printing interface definitions...
1222 ******************************************************************/
1224 struct printif iprint_printif =
1229 iprint_queue_resume,
1237 /* this keeps fussy compilers happy */
1238 void print_iprint_dummy(void);
1239 void print_iprint_dummy(void) {}
1240 #endif /* HAVE_IPRINT */