]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/request.c
Merge changes from CUPS 1.4svn-r7961.
[thirdparty/cups.git] / cups / request.c
1 /*
2 * "$Id: request.c 7946 2008-09-16 23:27:54Z mike $"
3 *
4 * IPP utilities for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 2007-2008 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products.
8 *
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
14 *
15 * This file is subject to the Apple OS-Developed Software exception.
16 *
17 * Contents:
18 *
19 * cupsDoFileRequest() - Do an IPP request with a file.
20 * cupsDoIORequest() - Do an IPP request with file descriptors.
21 * cupsDoRequest() - Do an IPP request.
22 * cupsGetResponse() - Get a response to an IPP request.
23 * cupsReadResponseData() - Read additional data after the IPP response.
24 * cupsSendRequest() - Send an IPP request.
25 * cupsWriteRequestData() - Write additional data after an IPP request.
26 * _cupsSetError() - Set the last IPP status code and status-message.
27 * _cupsSetHTTPError() - Set the last error using the HTTP status.
28 */
29
30 /*
31 * Include necessary headers...
32 */
33
34 #include "globals.h"
35 #include "debug.h"
36 #include <stdlib.h>
37 #include <errno.h>
38 #include <fcntl.h>
39 #include <sys/stat.h>
40 #if defined(WIN32) || defined(__EMX__)
41 # include <io.h>
42 #else
43 # include <unistd.h>
44 #endif /* WIN32 || __EMX__ */
45 #ifndef O_BINARY
46 # define O_BINARY 0
47 #endif /* O_BINARY */
48
49
50 /*
51 * 'cupsDoFileRequest()' - Do an IPP request with a file.
52 *
53 * This function sends the IPP request to the specified server, retrying
54 * and authenticating as necessary. The request is freed with @link ippDelete@
55 * after receiving a valid IPP response.
56 */
57
58 ipp_t * /* O - Response data */
59 cupsDoFileRequest(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
60 ipp_t *request, /* I - IPP request */
61 const char *resource, /* I - HTTP resource for POST */
62 const char *filename) /* I - File to send or @code NULL@ for none */
63 {
64 ipp_t *response; /* IPP response data */
65 int infile; /* Input file */
66
67
68 DEBUG_printf(("cupsDoFileRequest(http=%p, request=%p(%s), resource=\"%s\", "
69 "filename=\"%s\")\n", http, request,
70 request ? ippOpString(request->request.op.operation_id) : "?",
71 resource ? resource : "(null)",
72 filename ? filename : "(null)"));
73
74 if (filename)
75 {
76 if ((infile = open(filename, O_RDONLY | O_BINARY)) < 0)
77 {
78 /*
79 * Can't get file information!
80 */
81
82 _cupsSetError(errno == ENOENT ? IPP_NOT_FOUND : IPP_NOT_AUTHORIZED,
83 NULL, 0);
84
85 ippDelete(request);
86
87 return (NULL);
88 }
89 }
90 else
91 infile = -1;
92
93 response = cupsDoIORequest(http, request, resource, infile, -1);
94
95 if (infile >= 0)
96 close(infile);
97
98 return (response);
99 }
100
101
102 /*
103 * 'cupsDoIORequest()' - Do an IPP request with file descriptors.
104 *
105 * This function sends the IPP request to the specified server, retrying
106 * and authenticating as necessary. The request is freed with ippDelete()
107 * after receiving a valid IPP response.
108 *
109 * If "infile" is a valid file descriptor, cupsDoIORequest() copies
110 * all of the data from the file after the IPP request message.
111 *
112 * If "outfile" is a valid file descriptor, cupsDoIORequest() copies
113 * all of the data after the IPP response message to the file.
114 *
115 * @since CUPS 1.3@
116 */
117
118 ipp_t * /* O - Response data */
119 cupsDoIORequest(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
120 ipp_t *request, /* I - IPP request */
121 const char *resource, /* I - HTTP resource for POST */
122 int infile, /* I - File to read from or -1 for none */
123 int outfile) /* I - File to write to or -1 for none */
124 {
125 ipp_t *response = NULL; /* IPP response data */
126 size_t length = 0; /* Content-Length value */
127 http_status_t status; /* Status of HTTP request */
128 struct stat fileinfo; /* File information */
129 int bytes; /* Number of bytes read/written */
130 char buffer[32768]; /* Output buffer */
131
132
133 DEBUG_printf(("cupsDoIORequest(http=%p, request=%p(%s), resource=\"%s\", "
134 "infile=%d, outfile=%d)\n", http, request,
135 request ? ippOpString(request->request.op.operation_id) : "?",
136 resource ? resource : "(null)", infile, outfile));
137
138 /*
139 * Range check input...
140 */
141
142 if (!request || !resource)
143 {
144 ippDelete(request);
145
146 _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
147
148 return (NULL);
149 }
150
151 /*
152 * Get the default connection as needed...
153 */
154
155 if (!http)
156 if ((http = _cupsConnect()) == NULL)
157 return (NULL);
158
159 /*
160 * See if we have a file to send...
161 */
162
163 if (infile >= 0)
164 {
165 if (fstat(infile, &fileinfo))
166 {
167 /*
168 * Can't get file information!
169 */
170
171 _cupsSetError(errno == EBADF ? IPP_NOT_FOUND : IPP_NOT_AUTHORIZED,
172 NULL, 0);
173
174 ippDelete(request);
175
176 return (NULL);
177 }
178
179 #ifdef WIN32
180 if (fileinfo.st_mode & _S_IFDIR)
181 #else
182 if (S_ISDIR(fileinfo.st_mode))
183 #endif /* WIN32 */
184 {
185 /*
186 * Can't send a directory...
187 */
188
189 ippDelete(request);
190
191 _cupsSetError(IPP_NOT_POSSIBLE, strerror(EISDIR), 0);
192
193 return (NULL);
194 }
195
196 #ifndef WIN32
197 if (!S_ISREG(fileinfo.st_mode))
198 length = 0; /* Chunk when piping */
199 else
200 #endif /* !WIN32 */
201 length = ippLength(request) + fileinfo.st_size;
202 }
203 else
204 length = ippLength(request);
205
206 /*
207 * Loop until we can send the request without authorization problems.
208 */
209
210 while (response == NULL)
211 {
212 DEBUG_puts("cupsDoIORequest: setup...");
213
214 /*
215 * Send the request...
216 */
217
218 status = cupsSendRequest(http, request, resource, length);
219
220 DEBUG_printf(("cupsDoIORequest: status=%d\n", status));
221
222 if (status == HTTP_CONTINUE && request->state == IPP_DATA && infile >= 0)
223 {
224 DEBUG_puts("cupsDoIORequest: file write...");
225
226 /*
227 * Send the file with the request...
228 */
229
230 #ifndef WIN32
231 if (S_ISREG(fileinfo.st_mode))
232 #endif /* WIN32 */
233 lseek(infile, 0, SEEK_SET);
234
235 while ((bytes = (int)read(infile, buffer, sizeof(buffer))) > 0)
236 {
237 if (httpCheck(http))
238 {
239 if ((status = httpUpdate(http)) != HTTP_CONTINUE)
240 break;
241 }
242
243 if (httpWrite2(http, buffer, bytes) < bytes)
244 break;
245 }
246 }
247
248 /*
249 * Get the server's response...
250 */
251
252 if (status == HTTP_CONTINUE || status == HTTP_OK)
253 {
254 response = cupsGetResponse(http, resource);
255 status = http->status;
256 }
257
258 if (status == HTTP_FORBIDDEN || status == HTTP_ERROR ||
259 status == HTTP_SERVICE_UNAVAILABLE)
260 {
261 _cupsSetHTTPError(status);
262 break;
263 }
264
265 if (response)
266 {
267 if (outfile >= 0)
268 {
269 /*
270 * Write trailing data to file...
271 */
272
273 while ((bytes = (int)httpRead2(http, buffer, sizeof(buffer))) > 0)
274 if (write(outfile, buffer, bytes) < bytes)
275 break;
276 }
277 else
278 {
279 /*
280 * Flush any remaining data...
281 */
282
283 httpFlush(http);
284 }
285 }
286 }
287
288 /*
289 * Delete the original request and return the response...
290 */
291
292 ippDelete(request);
293
294 return (response);
295 }
296
297
298 /*
299 * 'cupsDoRequest()' - Do an IPP request.
300 *
301 * This function sends the IPP request to the specified server, retrying
302 * and authenticating as necessary. The request is freed with ippDelete()
303 * after receiving a valid IPP response.
304 */
305
306 ipp_t * /* O - Response data */
307 cupsDoRequest(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
308 ipp_t *request, /* I - IPP request */
309 const char *resource) /* I - HTTP resource for POST */
310 {
311 DEBUG_printf(("cupsDoRequest(http=%p, request=%p(%s), resource=\"%s\")\n",
312 http, request,
313 request ? ippOpString(request->request.op.operation_id) : "?",
314 resource ? resource : "(null)"));
315
316 return (cupsDoIORequest(http, request, resource, -1, -1));
317 }
318
319
320 /*
321 * 'cupsGetResponse()' - Get a response to an IPP request.
322 *
323 * Use this function to get the response for an IPP request sent using
324 * cupsSendDocument() or cupsSendRequest(). For requests that return
325 * additional data, use httpRead() after getting a successful response.
326 *
327 * @since CUPS 1.4@
328 */
329
330 ipp_t * /* O - Response or @code NULL@ on HTTP error */
331 cupsGetResponse(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
332 const char *resource) /* I - HTTP resource for POST */
333 {
334 http_status_t status; /* HTTP status */
335 ipp_state_t state; /* IPP read state */
336 ipp_t *response = NULL; /* IPP response */
337
338
339 DEBUG_printf(("cupsGetReponse(http=%p, resource=\"%s\")\n", http,
340 resource ? resource : "(null)"));
341
342 /*
343 * Connect to the default server as needed...
344 */
345
346 if (!http)
347 http = _cupsConnect();
348
349 if (!http || (http->state != HTTP_POST_RECV && http->state != HTTP_POST_SEND))
350 return (NULL);
351
352 /*
353 * Check for an unfinished chunked request...
354 */
355
356 if (http->data_encoding == HTTP_ENCODE_CHUNKED)
357 {
358 /*
359 * Send a 0-length chunk to finish off the request...
360 */
361
362 DEBUG_puts("cupsGetResponse: Finishing chunked POST...");
363
364 if (httpWrite2(http, "", 0) < 0)
365 return (NULL);
366 }
367
368 /*
369 * Wait for a response from the server...
370 */
371
372 DEBUG_printf(("cupsGetResponse: Update loop, http->status=%d...\n",
373 http->status));
374
375 status = http->status;
376 while (status == HTTP_CONTINUE)
377 status = httpUpdate(http);
378
379 DEBUG_printf(("cupsGetResponse: status=%d\n", status));
380
381 if (status == HTTP_OK)
382 {
383 /*
384 * Get the IPP response...
385 */
386
387 response = ippNew();
388
389 while ((state = ippRead(http, response)) != IPP_DATA)
390 if (state == IPP_ERROR)
391 break;
392
393 if (state == IPP_ERROR)
394 {
395 /*
396 * Delete the response...
397 */
398
399 DEBUG_puts("cupsGetResponse: IPP read error!");
400
401 ippDelete(response);
402 response = NULL;
403
404 _cupsSetError(IPP_SERVICE_UNAVAILABLE, NULL, 0);
405 }
406 }
407 else if (status != HTTP_ERROR)
408 {
409 /*
410 * Flush any error message...
411 */
412
413 httpFlush(http);
414
415 /*
416 * Then handle encryption and authentication...
417 */
418
419 if (status == HTTP_UNAUTHORIZED)
420 {
421 /*
422 * See if we can do authentication...
423 */
424
425 int auth_result;
426
427 DEBUG_puts("cupsGetResponse: Need authorization...");
428
429 if ((auth_result = cupsDoAuthentication(http, "POST", resource)) == 0)
430 httpReconnect(http);
431 else if (auth_result < 0)
432 http->status = status = HTTP_FORBIDDEN;
433 }
434
435 #ifdef HAVE_SSL
436 else if (status == HTTP_UPGRADE_REQUIRED)
437 {
438 /*
439 * Force a reconnect with encryption...
440 */
441
442 DEBUG_puts("cupsGetResponse: Need encryption...");
443
444 if (!httpReconnect(http))
445 httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
446 }
447 #endif /* HAVE_SSL */
448 }
449
450 if (response)
451 {
452 ipp_attribute_t *attr; /* status-message attribute */
453
454
455 attr = ippFindAttribute(response, "status-message", IPP_TAG_TEXT);
456
457 DEBUG_printf(("cupsGetResponse: status-code=%s, status-message=\"%s\"\n",
458 ippErrorString(response->request.status.status_code),
459 attr ? attr->values[0].string.text : ""));
460
461 _cupsSetError(response->request.status.status_code,
462 attr ? attr->values[0].string.text :
463 ippErrorString(response->request.status.status_code), 0);
464 }
465 else if (status != HTTP_OK)
466 _cupsSetHTTPError(status);
467
468 return (response);
469 }
470
471
472 /*
473 * 'cupsReadResponseData()' - Read additional data after the IPP response.
474 *
475 * This function is used after cupsGetResponse() to read the PPD or document
476 * files for CUPS_GET_PPD and CUPS_GET_DOCUMENT requests, respectively.
477 *
478 * @since CUPS 1.4@
479 */
480
481 ssize_t /* O - Bytes read, 0 on EOF, -1 on error */
482 cupsReadResponseData(
483 http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
484 char *buffer, /* I - Buffer to use */
485 size_t length) /* I - Number of bytes to read */
486 {
487 /*
488 * Get the default connection as needed...
489 */
490
491 DEBUG_printf(("cupsReadResponseData(http=%p, buffer=%p, "
492 "length=" CUPS_LLFMT ")\n", http, buffer, CUPS_LLCAST length));
493
494 if (!http)
495 {
496 _cups_globals_t *cg = _cupsGlobals();
497 /* Pointer to library globals */
498
499 if ((http = cg->http) == NULL)
500 {
501 _cupsSetError(IPP_INTERNAL_ERROR, _("No active connection"), 1);
502 return (-1);
503 }
504 }
505
506 /*
507 * Then read from the HTTP connection...
508 */
509
510 return (httpRead2(http, buffer, length));
511 }
512
513
514 /*
515 * 'cupsSendRequest()' - Send an IPP request.
516 *
517 * Use httpWrite() to write any additional data (document, PPD file, etc.)
518 * for the request, cupsGetResponse() to get the IPP response, and httpRead()
519 * to read any additional data following the response. Only one request can be
520 * sent/queued at a time.
521 *
522 * Unlike cupsDoFileRequest(), cupsDoIORequest(), and cupsDoRequest(), the
523 * request is not freed.
524 *
525 * @since CUPS 1.4@
526 */
527
528 http_status_t /* O - Initial HTTP status */
529 cupsSendRequest(http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
530 ipp_t *request, /* I - IPP request */
531 const char *resource, /* I - Resource path */
532 size_t length) /* I - Length of data to follow or @code CUPS_LENGTH_VARIABLE@ */
533 {
534 http_status_t status; /* Status of HTTP request */
535 int got_status; /* Did we get the status? */
536 ipp_state_t state; /* State of IPP processing */
537 http_status_t expect; /* Expect: header to use */
538
539
540 DEBUG_printf(("cupsSendRequest(http=%p, request=%p(%s), resource=\"%s\", "
541 "length=" CUPS_LLFMT ")\n", http, request,
542 request ? ippOpString(request->request.op.operation_id) : "?",
543 resource ? resource : "(null)", CUPS_LLCAST length));
544
545 /*
546 * Range check input...
547 */
548
549 if (!request || !resource)
550 {
551 _cupsSetError(IPP_INTERNAL_ERROR, strerror(EINVAL), 0);
552
553 return (HTTP_ERROR);
554 }
555
556 /*
557 * Get the default connection as needed...
558 */
559
560 if (!http)
561 if ((http = _cupsConnect()) == NULL)
562 return (HTTP_SERVICE_UNAVAILABLE);
563
564 #ifdef HAVE_SSL
565 /*
566 * See if we have an auth-info attribute and are communicating over
567 * a non-local link. If so, encrypt the link so that we can pass
568 * the authentication information securely...
569 */
570
571 if (ippFindAttribute(request, "auth-info", IPP_TAG_TEXT) &&
572 !httpAddrLocalhost(http->hostaddr) && !http->tls &&
573 httpEncryption(http, HTTP_ENCRYPT_REQUIRED))
574 {
575 _cupsSetError(IPP_SERVICE_UNAVAILABLE, NULL, 0);
576 return (HTTP_SERVICE_UNAVAILABLE);
577 }
578 #endif /* HAVE_SSL */
579
580 /*
581 * Reconnect if the last response had a "Connection: close"...
582 */
583
584 if (!strcasecmp(http->fields[HTTP_FIELD_CONNECTION], "close"))
585 if (httpReconnect(http))
586 {
587 _cupsSetError(IPP_SERVICE_UNAVAILABLE, NULL, 0);
588 return (HTTP_SERVICE_UNAVAILABLE);
589 }
590
591 /*
592 * Loop until we can send the request without authorization problems.
593 */
594
595 expect = HTTP_CONTINUE;
596
597 for (;;)
598 {
599 DEBUG_puts("cupsSendRequest: Setup...");
600
601 /*
602 * Setup the HTTP variables needed...
603 */
604
605 httpClearFields(http);
606 httpSetLength(http, length);
607 httpSetField(http, HTTP_FIELD_CONTENT_TYPE, "application/ipp");
608 httpSetField(http, HTTP_FIELD_AUTHORIZATION, http->authstring);
609 httpSetExpect(http, expect);
610
611 DEBUG_printf(("cupsSendRequest: authstring=\"%s\"\n", http->authstring));
612
613 /*
614 * Try the request...
615 */
616
617 DEBUG_puts("cupsSendRequest: Sending HTTP POST...");
618
619 if (httpPost(http, resource))
620 {
621 if (httpReconnect(http))
622 {
623 _cupsSetError(IPP_SERVICE_UNAVAILABLE, NULL, 0);
624 return (HTTP_SERVICE_UNAVAILABLE);
625 }
626 else
627 continue;
628 }
629
630 /*
631 * Send the IPP data...
632 */
633
634 DEBUG_puts("cupsSendRequest: Writing IPP request...");
635
636 request->state = IPP_IDLE;
637 status = HTTP_CONTINUE;
638 got_status = 0;
639
640 while ((state = ippWrite(http, request)) != IPP_DATA)
641 if (state == IPP_ERROR)
642 break;
643 else if (httpCheck(http))
644 {
645 got_status = 1;
646
647 if ((status = httpUpdate(http)) != HTTP_CONTINUE)
648 break;
649 }
650
651 /*
652 * Wait up to 1 second to get the 100-continue response as needed...
653 */
654
655 if (!got_status && expect == HTTP_CONTINUE)
656 {
657 DEBUG_puts("cupsSendRequest: Waiting for 100-continue...");
658
659 if (httpWait(http, 1000))
660 status = httpUpdate(http);
661 else
662 status = HTTP_EXPECTATION_FAILED;
663 }
664 else if (httpCheck(http))
665 status = httpUpdate(http);
666
667 DEBUG_printf(("cupsSendRequest: status=%d\n", status));
668
669 /*
670 * Process the current HTTP status...
671 */
672
673 switch (status)
674 {
675 case HTTP_ERROR :
676 case HTTP_CONTINUE :
677 case HTTP_OK :
678 return (status);
679
680 case HTTP_UNAUTHORIZED :
681 if (!cupsDoAuthentication(http, "POST", resource))
682 if (httpReconnect(http))
683 {
684 _cupsSetError(IPP_SERVICE_UNAVAILABLE, NULL, 0);
685 return (HTTP_SERVICE_UNAVAILABLE);
686 }
687
688 return (status);
689
690 #ifdef HAVE_SSL
691 case HTTP_UPGRADE_REQUIRED :
692 /*
693 * Flush any error message, reconnect, and then upgrade with
694 * encryption...
695 */
696
697 if (httpReconnect(http))
698 {
699 _cupsSetError(IPP_SERVICE_UNAVAILABLE, NULL, 0);
700 return (HTTP_SERVICE_UNAVAILABLE);
701 }
702
703 httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
704
705 return (status);
706 #endif /* HAVE_SSL */
707
708 case HTTP_EXPECTATION_FAILED :
709 /*
710 * Don't try using the Expect: header the next time around...
711 */
712
713 expect = (http_status_t)0;
714 break;
715
716 default :
717 /*
718 * Some other error...
719 */
720
721 return (status);
722 }
723 }
724 }
725
726
727 /*
728 * 'cupsWriteRequestData()' - Write additional data after an IPP request.
729 *
730 * This function is used after @link cupsSendRequest@ to provide a PPD and
731 * after @link cupsStartDocument@ to provide a document file.
732 *
733 * @since CUPS 1.4@
734 */
735
736 http_status_t /* O - @code HTTP_CONTINUE@ if OK or HTTP status on error */
737 cupsWriteRequestData(
738 http_t *http, /* I - Connection to server or @code CUPS_HTTP_DEFAULT@ */
739 const char *buffer, /* I - Bytes to write */
740 size_t length) /* I - Number of bytes to write */
741 {
742 /*
743 * Get the default connection as needed...
744 */
745
746 DEBUG_printf(("cupsWriteRequestData(http=%p, buffer=%p, "
747 "length=" CUPS_LLFMT ")\n", http, buffer, CUPS_LLCAST length));
748
749 if (!http)
750 {
751 _cups_globals_t *cg = _cupsGlobals();
752 /* Pointer to library globals */
753
754 if ((http = cg->http) == NULL)
755 {
756 _cupsSetError(IPP_INTERNAL_ERROR, _("No active connection"), 1);
757 return (HTTP_ERROR);
758 }
759 }
760
761 /*
762 * Then write to the HTTP connection...
763 */
764
765 if (httpWrite2(http, buffer, length) < 0)
766 return (HTTP_ERROR);
767
768 /*
769 * Finally, check if we have any pending data from the server...
770 */
771
772 if (httpCheck(http))
773 return (httpUpdate(http));
774 else
775 return (HTTP_CONTINUE);
776 }
777
778
779 /*
780 * '_cupsSetError()' - Set the last IPP status code and status-message.
781 */
782
783 void
784 _cupsSetError(ipp_status_t status, /* I - IPP status code */
785 const char *message, /* I - status-message value */
786 int localize) /* I - Localize the message? */
787 {
788 _cups_globals_t *cg; /* Global data */
789
790
791 if (!message && errno)
792 {
793 message = strerror(errno);
794 localize = 0;
795 }
796
797 cg = _cupsGlobals();
798 cg->last_error = status;
799
800 if (cg->last_status_message)
801 {
802 _cupsStrFree(cg->last_status_message);
803
804 cg->last_status_message = NULL;
805 }
806
807 if (message)
808 {
809 if (localize)
810 {
811 /*
812 * Get the message catalog...
813 */
814
815 if (!cg->lang_default)
816 cg->lang_default = cupsLangDefault();
817
818 cg->last_status_message = _cupsStrAlloc(_cupsLangString(cg->lang_default,
819 message));
820 }
821 else
822 cg->last_status_message = _cupsStrAlloc(message);
823 }
824
825 DEBUG_printf(("_cupsSetError: last_error=%s, last_status_message=\"%s\"\n",
826 ippErrorString(cg->last_error),
827 cg->last_status_message ? cg->last_status_message : ""));
828 }
829
830
831 /*
832 * '_cupsSetHTTPError()' - Set the last error using the HTTP status.
833 */
834
835 void
836 _cupsSetHTTPError(http_status_t status) /* I - HTTP status code */
837 {
838 switch (status)
839 {
840 case HTTP_NOT_FOUND :
841 _cupsSetError(IPP_NOT_FOUND, httpStatus(status), 0);
842 break;
843
844 case HTTP_UNAUTHORIZED :
845 _cupsSetError(IPP_NOT_AUTHORIZED, httpStatus(status), 0);
846 break;
847
848 case HTTP_FORBIDDEN :
849 _cupsSetError(IPP_FORBIDDEN, httpStatus(status), 0);
850 break;
851
852 case HTTP_BAD_REQUEST :
853 _cupsSetError(IPP_BAD_REQUEST, httpStatus(status), 0);
854 break;
855
856 case HTTP_REQUEST_TOO_LARGE :
857 _cupsSetError(IPP_REQUEST_VALUE, httpStatus(status), 0);
858 break;
859
860 case HTTP_NOT_IMPLEMENTED :
861 _cupsSetError(IPP_OPERATION_NOT_SUPPORTED, httpStatus(status), 0);
862 break;
863
864 case HTTP_NOT_SUPPORTED :
865 _cupsSetError(IPP_VERSION_NOT_SUPPORTED, httpStatus(status), 0);
866 break;
867
868 default :
869 DEBUG_printf(("HTTP error %d mapped to IPP_SERVICE_UNAVAILABLE!\n",
870 status));
871 _cupsSetError(IPP_SERVICE_UNAVAILABLE, httpStatus(status), 0);
872 break;
873 }
874 }
875
876
877 /*
878 * End of "$Id: request.c 7946 2008-09-16 23:27:54Z mike $".
879 */