• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeprint
 

tdeprint

  • tdeprint
  • cups
ipprequest.cpp
1/*
2 * This file is part of the KDE libraries
3 * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License version 2 as published by the Free Software Foundation.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 **/
19
20#include "ipprequest.h"
21#include "cupsinfos.h"
22
23#include <stdlib.h>
24#include <string>
25#include <cups/language.h>
26#include <kdebug.h>
27#include <tdeglobal.h>
28#include <tdelocale.h>
29#include <tqdatetime.h>
30#include <tqregexp.h>
31#include <cups/cups.h>
32
33#ifdef HAVE_CONFIG_H
34#include <config.h>
35#endif
36
37#ifdef HAVE_CUPS_NO_PWD_CACHE
38#include <tqcstring.h>
39static TQCString cups_authstring = "";
40#endif
41
42void dumpRequest(ipp_t *req, bool answer = false, const TQString& s = TQString::null)
43{
44 kdDebug(500) << "==========" << endl;
45 if (s.isEmpty())
46 kdDebug(500) << (answer ? "Answer" : "Request") << endl;
47 else
48 kdDebug(500) << s << endl;
49 kdDebug(500) << "==========" << endl;
50 if (!req)
51 {
52 kdDebug(500) << "Null request" << endl;
53 return;
54 }
55#ifdef HAVE_CUPS_1_6
56 kdDebug(500) << "State = 0x" << TQString::number(ippGetState(req), 16) << endl;
57 kdDebug(500) << "ID = 0x" << TQString::number(ippGetRequestId(req), 16) << endl;
58 if (answer)
59 {
60 kdDebug(500) << "Status = 0x" << TQString::number(ippGetStatusCode(req), 16) << endl;
61 kdDebug(500) << "Status message = " << ippErrorString(ippGetStatusCode(req)) << endl;
62 }
63 else
64 kdDebug(500) << "Operation = 0x" << TQString::number(ippGetOperation(req), 16) << endl;
65 int minorVersion;
66 int majorVersion = ippGetVersion(req, &minorVersion);
67 kdDebug(500) << "Version = " << (int)(majorVersion) << "." << (int)(minorVersion) << endl;
68 kdDebug(500) << endl;
69
70 ipp_attribute_t *attr = ippFirstAttribute(req);
71 while (attr)
72 {
73 TQString s = TQString::fromLatin1("%1 (0x%2) = ").arg(ippGetName(attr)).arg(ippGetValueTag(attr), 0, 16);
74 for (int i=0;i<ippGetCount(attr);i++)
75 {
76 switch (ippGetValueTag(attr))
77 {
78 case IPP_TAG_INTEGER:
79 case IPP_TAG_ENUM:
80 s += ("0x"+TQString::number(ippGetInteger(attr, i), 16));
81 break;
82 case IPP_TAG_BOOLEAN:
83 s += (ippGetBoolean(attr, i) ? "true" : "false");
84 break;
85 case IPP_TAG_STRING:
86 case IPP_TAG_TEXT:
87 case IPP_TAG_NAME:
88 case IPP_TAG_KEYWORD:
89 case IPP_TAG_URI:
90 case IPP_TAG_MIMETYPE:
91 case IPP_TAG_NAMELANG:
92 case IPP_TAG_TEXTLANG:
93 case IPP_TAG_CHARSET:
94 case IPP_TAG_LANGUAGE:
95 s += ippGetString(attr, i, NULL);
96 break;
97 default:
98 break;
99 }
100 if (i != (ippGetCount(attr)-1))
101 s += ", ";
102 }
103 kdDebug(500) << s << endl;
104 attr = ippNextAttribute(req);
105 }
106#else
107 kdDebug(500) << "State = 0x" << TQString::number(req->state, 16) << endl;
108 kdDebug(500) << "ID = 0x" << TQString::number(req->request.status.request_id, 16) << endl;
109 if (answer)
110 {
111 kdDebug(500) << "Status = 0x" << TQString::number(req->request.status.status_code, 16) << endl;
112 kdDebug(500) << "Status message = " << ippErrorString(req->request.status.status_code) << endl;
113 }
114 else
115 kdDebug(500) << "Operation = 0x" << TQString::number(req->request.op.operation_id, 16) << endl;
116 kdDebug(500) << "Version = " << (int)(req->request.status.version[0]) << "." << (int)(req->request.status.version[1]) << endl;
117 kdDebug(500) << endl;
118
119 ipp_attribute_t *attr = req->attrs;
120 while (attr)
121 {
122 TQString s = TQString::fromLatin1("%1 (0x%2) = ").arg(attr->name).arg(attr->value_tag, 0, 16);
123 for (int i=0;i<attr->num_values;i++)
124 {
125 switch (attr->value_tag)
126 {
127 case IPP_TAG_INTEGER:
128 case IPP_TAG_ENUM:
129 s += ("0x"+TQString::number(attr->values[i].integer, 16));
130 break;
131 case IPP_TAG_BOOLEAN:
132 s += (attr->values[i].boolean ? "true" : "false");
133 break;
134 case IPP_TAG_STRING:
135 case IPP_TAG_TEXT:
136 case IPP_TAG_NAME:
137 case IPP_TAG_KEYWORD:
138 case IPP_TAG_URI:
139 case IPP_TAG_MIMETYPE:
140 case IPP_TAG_NAMELANG:
141 case IPP_TAG_TEXTLANG:
142 case IPP_TAG_CHARSET:
143 case IPP_TAG_LANGUAGE:
144 s += attr->values[i].string.text;
145 break;
146 default:
147 break;
148 }
149 if (i != (attr->num_values-1))
150 s += ", ";
151 }
152 kdDebug(500) << s << endl;
153 attr = attr->next;
154 }
155#endif
156}
157
158TQString errorString(int status)
159{
160 TQString str;
161 switch (status)
162 {
163 case IPP_FORBIDDEN:
164 str = i18n("You don't have access to the requested resource.");
165 break;
166 case IPP_NOT_AUTHORIZED:
167 str = i18n("You are not authorized to access the requested resource.");
168 break;
169 case IPP_NOT_POSSIBLE:
170 str = i18n("The requested operation cannot be completed.");
171 break;
172 case IPP_SERVICE_UNAVAILABLE:
173 str = i18n("The requested service is currently unavailable.");
174 break;
175 case IPP_NOT_ACCEPTING:
176 str = i18n("The target printer is not accepting print jobs.");
177 break;
178 default:
179 str = TQString::fromLocal8Bit(ippErrorString((ipp_status_t)status));
180 break;
181 }
182 return str;
183}
184
185//*************************************************************************************
186
187IppRequest::IppRequest()
188{
189 request_ = 0;
190 port_ = -1;
191 host_ = TQString();
192 dump_ = 0;
193 init();
194}
195
196IppRequest::~IppRequest()
197{
198 ippDelete(request_);
199}
200
201void IppRequest::init()
202{
203 connect_ = true;
204
205 if (request_)
206 {
207 ippDelete(request_);
208 request_ = 0;
209 }
210 request_ = ippNew();
211 //kdDebug(500) << "tdeprint: IPP request, lang=" << TDEGlobal::locale()->language() << endl;
212 TQCString langstr = TDEGlobal::locale()->language().latin1();
213 cups_lang_t* lang = cupsLangGet(langstr.data());
214 // default charset to UTF-8 (ugly hack)
215 lang->encoding = CUPS_UTF8;
216 ippAddString(request_, IPP_TAG_OPERATION, IPP_TAG_CHARSET, "attributes-charset", NULL, cupsLangEncoding(lang));
217 ippAddString(request_, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, lang->language);
218 cupsLangFree(lang);
219}
220
221void IppRequest::addString_p(int group, int type, const TQString& name, const TQString& value)
222{
223 if (!name.isEmpty())
224 ippAddString(request_,(ipp_tag_t)group,(ipp_tag_t)type,name.latin1(),NULL,(value.isEmpty() ? "" : value.local8Bit().data()));
225}
226
227void IppRequest::addStringList_p(int group, int type, const TQString& name, const TQStringList& values)
228{
229 if (!name.isEmpty())
230 {
231 //> Values buffer and references offset prepare
232 const char *vlsRefs[values.count()];
233 std::string vlsBuf;
234 for(unsigned i_vl = 0; i_vl < values.count(); i_vl++)
235 {
236 vlsRefs[i_vl] = (const char*)vlsBuf.size();
237 vlsBuf += values[i_vl].local8Bit();
238 vlsBuf += (char)0;
239 }
240 //> References update to pointers
241 for(unsigned i_vl = 0; i_vl < values.count(); i_vl++)
242 vlsRefs[i_vl] = vlsBuf.data()+(intptr_t)vlsRefs[i_vl];
243 ippAddStrings(request_,(ipp_tag_t)group,(ipp_tag_t)type,name.latin1(),(int)(values.count()),NULL,(const char**)&vlsRefs);
244 }
245}
246
247void IppRequest::addInteger_p(int group, int type, const TQString& name, int value)
248{
249 if (!name.isEmpty()) ippAddInteger(request_,(ipp_tag_t)group,(ipp_tag_t)type,name.latin1(),value);
250}
251
252void IppRequest::addIntegerList_p(int group, int type, const TQString& name, const TQValueList<int>& values)
253{
254 if (!name.isEmpty())
255 {
256 ipp_attribute_t *attr = ippAddIntegers(request_,(ipp_tag_t)group,(ipp_tag_t)type,name.latin1(),(int)(values.count()),NULL);
257 int i(0);
258 for (TQValueList<int>::ConstIterator it=values.begin(); it != values.end(); ++it, i++)
259#ifdef HAVE_CUPS_1_6
260 ippSetInteger(request_, &attr, i, *it);
261#else
262 attr->values[i].integer = *it;
263#endif
264 }
265}
266
267void IppRequest::addBoolean(int group, const TQString& name, bool value)
268{
269 if (!name.isEmpty()) ippAddBoolean(request_,(ipp_tag_t)group,name.latin1(),(char)value);
270}
271
272void IppRequest::addBoolean(int group, const TQString& name, const TQValueList<bool>& values)
273{
274 if (!name.isEmpty())
275 {
276 ipp_attribute_t *attr = ippAddBooleans(request_,(ipp_tag_t)group,name.latin1(),(int)(values.count()),NULL);
277 int i(0);
278 for (TQValueList<bool>::ConstIterator it=values.begin(); it != values.end(); ++it, i++)
279#ifdef HAVE_CUPS_1_6
280 ippSetBoolean(request_, &attr, i, (char)(*it));
281#else
282 attr->values[i].boolean = (char)(*it);
283#endif
284 }
285}
286
287void IppRequest::setOperation(int op)
288{
289#ifdef HAVE_CUPS_1_6
290 ippSetOperation(request_, (ipp_op_t)op);
291 ippSetRequestId(request_, 1); // 0 is not RFC-compliant, should be at least 1
292#else
293 request_->request.op.operation_id = (ipp_op_t)op;
294 request_->request.op.request_id = 1; // 0 is not RFC-compliant, should be at least 1
295#endif
296}
297
298int IppRequest::status()
299{
300#ifdef HAVE_CUPS_1_6
301 return (request_ ? ippGetStatusCode(request_) : (connect_ ? cupsLastError() : -2));
302#else
303 return (request_ ? request_->request.status.status_code : (connect_ ? cupsLastError() : -2));
304#endif
305}
306
307TQString IppRequest::statusMessage()
308{
309 TQString msg;
310 switch (status())
311 {
312 case -2:
313 msg = i18n("Connection to CUPS server failed. Check that the CUPS server is correctly installed and running.");
314 break;
315 case -1:
316 msg = i18n("The IPP request failed for an unknown reason.");
317 break;
318 default:
319 msg = errorString(status());
320 break;
321 }
322 return msg;
323}
324
325bool IppRequest::integerValue_p(const TQString& name, int& value, int type)
326{
327 if (!request_ || name.isEmpty()) return false;
328 ipp_attribute_t *attr = ippFindAttribute(request_, name.latin1(), (ipp_tag_t)type);
329 if (attr)
330 {
331#ifdef HAVE_CUPS_1_6
332 value = ippGetInteger(attr, 0);
333#else
334 value = attr->values[0].integer;
335#endif
336 return true;
337 }
338 else return false;
339}
340
341bool IppRequest::stringValue_p(const TQString& name, TQString& value, int type)
342{
343 if (!request_ || name.isEmpty()) return false;
344 ipp_attribute_t *attr = ippFindAttribute(request_, name.latin1(), (ipp_tag_t)type);
345 if (attr)
346 {
347#ifdef HAVE_CUPS_1_6
348 value = TQString::fromLocal8Bit(ippGetString(attr, 0, NULL));
349#else
350 value = TQString::fromLocal8Bit(attr->values[0].string.text);
351#endif
352 return true;
353 }
354 else return false;
355}
356
357bool IppRequest::stringListValue_p(const TQString& name, TQStringList& values, int type)
358{
359 if (!request_ || name.isEmpty()) return false;
360 ipp_attribute_t *attr = ippFindAttribute(request_, name.latin1(), (ipp_tag_t)type);
361 values.clear();
362 if (attr)
363 {
364#ifdef HAVE_CUPS_1_6
365 for (int i=0;i<ippGetCount(attr);i++)
366 values.append(TQString::fromLocal8Bit(ippGetString(attr, i, NULL)));
367#else
368 for (int i=0;i<attr->num_values;i++)
369 values.append(TQString::fromLocal8Bit(attr->values[i].string.text));
370#endif
371 return true;
372 }
373 else return false;
374}
375
376bool IppRequest::boolean(const TQString& name, bool& value)
377{
378 if (!request_ || name.isEmpty()) return false;
379 ipp_attribute_t *attr = ippFindAttribute(request_, name.latin1(), IPP_TAG_BOOLEAN);
380 if (attr)
381 {
382#ifdef HAVE_CUPS_1_6
383 value = (bool)ippGetBoolean(attr, 0);
384#else
385 value = (bool)attr->values[0].boolean;
386#endif
387 return true;
388 }
389 else return false;
390}
391
392bool IppRequest::doFileRequest(const TQString& res, const TQString& filename)
393{
394 TQString myHost = host_;
395 int myPort = port_;
396 if (myHost.isEmpty()) myHost = CupsInfos::self()->host();
397 if (myPort <= 0) myPort = CupsInfos::self()->port();
398 http_t *HTTP = httpConnect(myHost.latin1(),myPort);
399
400 connect_ = (HTTP != NULL);
401
402 if (HTTP == NULL)
403 {
404 ippDelete(request_);
405 request_ = 0;
406 return false;
407 }
408
409#ifdef HAVE_CUPS_NO_PWD_CACHE
410#if CUPS_VERSION_MAJOR < 1 || (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR < 2)
411 strncpy( HTTP->authstring, cups_authstring.data(), HTTP_MAX_VALUE );
412#else
413 httpSetAuthString( HTTP, NULL, cups_authstring.data() );
414#endif
415#endif
416
417 if (dump_ > 0)
418 {
419 dumpRequest(request_, false, "Request to "+myHost+":"+TQString::number(myPort));
420 }
421
422 request_ = cupsDoFileRequest(HTTP, request_, (res.isEmpty() ? "/" : res.latin1()), (filename.isEmpty() ? NULL : filename.latin1()));
423#ifdef HAVE_CUPS_NO_PWD_CACHE
424#if CUPS_VERSION_MAJOR < 1 || (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR < 2)
425 cups_authstring = HTTP->authstring;
426#else
427 cups_authstring = httpGetAuthString( HTTP );
428#endif
429#endif
430 httpClose(HTTP);
431
432 if (dump_ > 1)
433 {
434 dumpRequest(request_, true);
435 }
436
437 /* No printers found */
438#ifdef HAVE_CUPS_1_6
439 if ( request_ && ippGetStatusCode(request_) == 0x406 )
440#else
441 if ( request_ && request_->request.status.status_code == 0x406 )
442#endif
443 return true;
444
445#ifdef HAVE_CUPS_1_6
446 if (!request_ || ippGetState(request_) == IPP_ERROR || (ippGetStatusCode(request_) & 0x0F00))
447#else
448 if (!request_ || request_->state == IPP_ERROR || (request_->request.status.status_code & 0x0F00))
449#endif
450 return false;
451
452
453 return true;
454}
455
456bool IppRequest::htmlReport(int group, TQTextStream& output)
457{
458 if (!request_) return false;
459 // start table
460 output << "<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">" << endl;
461 output << "<tr><th bgcolor=\"dark blue\"><font color=\"white\">" << i18n("Attribute") << "</font></th>" << endl;
462 output << "<th bgcolor=\"dark blue\"><font color=\"white\">" << i18n("Values") << "</font></th></tr>" << endl;
463 // go to the first attribute of the specified group
464#ifdef HAVE_CUPS_1_6
465 ipp_attribute_t *attr = ippFirstAttribute(request_);
466 while (attr && ippGetGroupTag(attr) != group)
467 attr = ippNextAttribute(request_);
468#else
469 ipp_attribute_t *attr = request_->attrs;
470 while (attr && attr->group_tag != group)
471 attr = attr->next;
472#endif
473 // print each attribute
474 const ipp_uchar_t *d;
475 TQCString dateStr;
476 TQDateTime dt;
477 bool bg(false);
478#ifdef HAVE_CUPS_1_6
479 while (attr && ippGetGroupTag(attr) == group)
480 {
481 output << " <tr bgcolor=\"" << (bg ? "#ffffd9" : "#ffffff") << "\">\n <td><b>" << ippGetName(attr) << "</b></td>\n <td>" << endl;
482 bg = !bg;
483 for (int i=0; i<ippGetCount(attr); i++)
484 {
485 switch (ippGetValueTag(attr))
486 {
487 case IPP_TAG_INTEGER:
488 if (ippGetName(attr) && strstr(ippGetName(attr), "time"))
489 {
490 dt.setTime_t((unsigned int)(ippGetInteger(attr, i)));
491 output << dt.toString();
492 }
493 else
494 output << ippGetInteger(attr, i);
495 break;
496 case IPP_TAG_ENUM:
497 output << "0x" << hex << ippGetInteger(attr, i) << dec;
498 break;
499 case IPP_TAG_BOOLEAN:
500 output << (ippGetBoolean(attr, i) ? i18n("True") : i18n("False"));
501 break;
502 case IPP_TAG_STRING:
503 case IPP_TAG_TEXTLANG:
504 case IPP_TAG_NAMELANG:
505 case IPP_TAG_TEXT:
506 case IPP_TAG_NAME:
507 case IPP_TAG_KEYWORD:
508 case IPP_TAG_URI:
509 case IPP_TAG_CHARSET:
510 case IPP_TAG_LANGUAGE:
511 case IPP_TAG_MIMETYPE:
512 output << ippGetString(attr, i, NULL);
513 break;
514 case IPP_TAG_RESOLUTION:
515 int xres;
516 int yres;
517 ipp_res_t units;
518 xres = ippGetResolution(attr, i, &yres, &units);
519 output << "( " << xres
520 << ", " << yres << " )";
521 break;
522 case IPP_TAG_RANGE:
523 int lowervalue;
524 int uppervalue;
525 lowervalue = ippGetRange(attr, i, &uppervalue);
526 output << "[ " << (lowervalue > 0 ? lowervalue : 1)
527 << ", " << (uppervalue > 0 ? uppervalue : 65535) << " ]";
528 break;
529 case IPP_TAG_DATE:
530 d = ippGetDate(attr, i);
531 dateStr.sprintf("%.4d-%.2d-%.2d, %.2d:%.2d:%.2d %c%.2d%.2d",
532 d[0]*256+d[1], d[2], d[3],
533 d[4], d[5], d[6],
534 d[8], d[9], d[10]);
535 output << dateStr;
536 break;
537 default:
538 continue;
539 }
540 if (i < ippGetCount(attr)-1)
541 output << "<br>";
542 }
543 output << "</td>\n </tr>" << endl;
544 attr = ippNextAttribute(request_);
545#else
546 while (attr && attr->group_tag == group)
547 {
548 output << " <tr bgcolor=\"" << (bg ? "#ffffd9" : "#ffffff") << "\">\n <td><b>" << attr->name << "</b></td>\n <td>" << endl;
549 bg = !bg;
550 for (int i=0; i<attr->num_values; i++)
551 {
552 switch (attr->value_tag)
553 {
554 case IPP_TAG_INTEGER:
555 if (attr->name && strstr(attr->name, "time"))
556 {
557 dt.setTime_t((unsigned int)(attr->values[i].integer));
558 output << dt.toString();
559 }
560 else
561 output << attr->values[i].integer;
562 break;
563 case IPP_TAG_ENUM:
564 output << "0x" << hex << attr->values[i].integer << dec;
565 break;
566 case IPP_TAG_BOOLEAN:
567 output << (attr->values[i].boolean ? i18n("True") : i18n("False"));
568 break;
569 case IPP_TAG_STRING:
570 case IPP_TAG_TEXTLANG:
571 case IPP_TAG_NAMELANG:
572 case IPP_TAG_TEXT:
573 case IPP_TAG_NAME:
574 case IPP_TAG_KEYWORD:
575 case IPP_TAG_URI:
576 case IPP_TAG_CHARSET:
577 case IPP_TAG_LANGUAGE:
578 case IPP_TAG_MIMETYPE:
579 output << attr->values[i].string.text;
580 break;
581 case IPP_TAG_RESOLUTION:
582 output << "( " << attr->values[i].resolution.xres
583 << ", " << attr->values[i].resolution.yres << " )";
584 break;
585 case IPP_TAG_RANGE:
586 output << "[ " << (attr->values[i].range.lower > 0 ? attr->values[i].range.lower : 1)
587 << ", " << (attr->values[i].range.upper > 0 ? attr->values[i].range.upper : 65535) << " ]";
588 break;
589 case IPP_TAG_DATE:
590 d = attr->values[i].date;
591 dateStr.sprintf("%.4d-%.2d-%.2d, %.2d:%.2d:%.2d %c%.2d%.2d",
592 d[0]*256+d[1], d[2], d[3],
593 d[4], d[5], d[6],
594 d[8], d[9], d[10]);
595 output << dateStr;
596 break;
597 default:
598 continue;
599 }
600 if (i < attr->num_values-1)
601 output << "<br>";
602 }
603 output << "</td>\n </tr>" << endl;
604 attr = attr->next;
605#endif
606 }
607 // end table
608 output << "</table>" << endl;
609
610 return true;
611}
612
613TQMap<TQString,TQString> IppRequest::toMap(int group)
614{
615 TQMap<TQString,TQString> opts;
616 if (request_)
617 {
618 ipp_attribute_t *attr = first();
619 while (attr)
620 {
621#ifdef HAVE_CUPS_1_6
622 if (group != -1 && ippGetGroupTag(attr) != group)
623 {
624 attr = ippNextAttribute(request_);
625 continue;
626 }
627 TQString value;
628 for (int i=0; i<ippGetCount(attr); i++)
629 {
630 switch (ippGetValueTag(attr))
631 {
632 case IPP_TAG_INTEGER:
633 case IPP_TAG_ENUM:
634 value.append(TQString::number(ippGetInteger(attr, i))).append(",");
635 break;
636 case IPP_TAG_BOOLEAN:
637 value.append((ippGetBoolean(attr, i) ? "true" : "false")).append(",");
638 break;
639 case IPP_TAG_RANGE:
640 int lowervalue;
641 int uppervalue;
642 lowervalue = ippGetRange(attr, i, &uppervalue);
643 if (lowervalue > 0)
644 value.append(TQString::number(lowervalue));
645 if (lowervalue != uppervalue)
646 {
647 value.append("-");
648 if (uppervalue > 0)
649 value.append(TQString::number(uppervalue));
650 }
651 value.append(",");
652 break;
653 case IPP_TAG_STRING:
654 case IPP_TAG_TEXT:
655 case IPP_TAG_NAME:
656 case IPP_TAG_KEYWORD:
657 case IPP_TAG_URI:
658 case IPP_TAG_MIMETYPE:
659 case IPP_TAG_NAMELANG:
660 case IPP_TAG_TEXTLANG:
661 case IPP_TAG_CHARSET:
662 case IPP_TAG_LANGUAGE:
663 value.append(TQString::fromLocal8Bit(ippGetString(attr, i, NULL))).append(",");
664 break;
665 default:
666 break;
667 }
668 }
669 if (!value.isEmpty())
670 value.truncate(value.length()-1);
671 opts[TQString::fromLocal8Bit(ippGetName(attr))] = value;
672 attr = ippNextAttribute(request_);
673#else
674 if (group != -1 && attr->group_tag != group)
675 {
676 attr = attr->next;
677 continue;
678 }
679 TQString value;
680 for (int i=0; i<attr->num_values; i++)
681 {
682 switch (attr->value_tag)
683 {
684 case IPP_TAG_INTEGER:
685 case IPP_TAG_ENUM:
686 value.append(TQString::number(attr->values[i].integer)).append(",");
687 break;
688 case IPP_TAG_BOOLEAN:
689 value.append((attr->values[i].boolean ? "true" : "false")).append(",");
690 break;
691 case IPP_TAG_RANGE:
692 if (attr->values[i].range.lower > 0)
693 value.append(TQString::number(attr->values[i].range.lower));
694 if (attr->values[i].range.lower != attr->values[i].range.upper)
695 {
696 value.append("-");
697 if (attr->values[i].range.upper > 0)
698 value.append(TQString::number(attr->values[i].range.upper));
699 }
700 value.append(",");
701 break;
702 case IPP_TAG_STRING:
703 case IPP_TAG_TEXT:
704 case IPP_TAG_NAME:
705 case IPP_TAG_KEYWORD:
706 case IPP_TAG_URI:
707 case IPP_TAG_MIMETYPE:
708 case IPP_TAG_NAMELANG:
709 case IPP_TAG_TEXTLANG:
710 case IPP_TAG_CHARSET:
711 case IPP_TAG_LANGUAGE:
712 value.append(TQString::fromLocal8Bit(attr->values[i].string.text)).append(",");
713 break;
714 default:
715 break;
716 }
717 }
718 if (!value.isEmpty())
719 value.truncate(value.length()-1);
720 opts[TQString::fromLocal8Bit(attr->name)] = value;
721 attr = attr->next;
722#endif
723 }
724 }
725 return opts;
726}
727
728void IppRequest::setMap(const TQMap<TQString,TQString>& opts)
729{
730 if (!request_)
731 return;
732
733 TQRegExp re("^\"|\"$");
734 cups_option_t *options = NULL;
735 int n = 0;
736 for (TQMap<TQString,TQString>::ConstIterator it=opts.begin(); it!=opts.end(); ++it)
737 {
738 if (it.key().startsWith("kde-") || it.key().startsWith("app-"))
739 continue;
740 TQString value = it.data().stripWhiteSpace(), lovalue;
741 value.replace(re, "");
742 lovalue = value.lower();
743
744 // handles specific cases: boolean, empty strings, or option that has that boolean
745 // keyword as value (to prevent them from conversion to real boolean)
746 if (value == "true" || value == "false")
747 addBoolean(IPP_TAG_JOB, it.key(), (value == "true"));
748 else if (value.isEmpty() || lovalue == "off" || lovalue == "on"
749 || lovalue == "yes" || lovalue == "no"
750 || lovalue == "true" || lovalue == "false")
751 addName(IPP_TAG_JOB, it.key(), value);
752 else
753 n = cupsAddOption(it.key().local8Bit(), value.local8Bit(), n, &options);
754 }
755 if (n > 0)
756 cupsEncodeOptions(request_, n, options);
757 cupsFreeOptions(n, options);
758
759 // find an remove that annoying "document-format" attribute
760#if CUPS_VERSION_MAJOR > 1 || (CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR >= 2)
761 ipp_attribute_t *attr = ippFindAttribute(request_, "document-format", IPP_TAG_NAME);
762 ippDeleteAttribute(request_, attr);
763#else
764 // (can't use IppDeleteAttribute as older cups doesn't have that)
765 ipp_attribute_t *attr = request_->attrs;
766 while (attr)
767 {
768 if (attr->next && strcmp(attr->next->name, "document-format") == 0)
769 {
770 ipp_attribute_t *attr2 = attr->next;
771 attr->next = attr2->next;
772 _ipp_free_attr(attr2);
773 break;
774 }
775 attr = attr->next;
776 }
777#endif
778}
779
780#ifdef HAVE_CUPS_1_6
781ipp_attribute_t* IppRequest::first()
782{ return (request_ ? ippFirstAttribute(request_) : NULL); }
783#else
784ipp_attribute_t* IppRequest::first()
785{ return (request_ ? request_->attrs : NULL); }
786#endif

tdeprint

Skip menu "tdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeprint

Skip menu "tdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.9.4
This website is maintained by Timothy Pearson.