21 #include "cupsdconf.h"
30 #include <cups/cups.h>
32 #include <cups/language.h>
34 TQString findDir(
const TQStringList& list)
36 for (TQStringList::ConstIterator it=list.begin(); it!=list.end(); ++it)
37 if (TQFile::exists(*it))
43 void splitSizeSpec(
const TQString& s,
int& sz,
int& suff)
45 int p = s.find(TQRegExp(
"\\D"));
46 sz = s.mid(0, p).toInt();
49 switch (s[p].latin1())
51 case 'k': suff = UNIT_KB;
break;
53 case 'm': suff = UNIT_MB;
break;
54 case 'g': suff = UNIT_GB;
break;
55 case 't': suff = UNIT_TILE;
break;
62 CupsdConf::CupsdConf()
65 datadir_ = findDir(TQStringList(
"/usr/share/cups")
66 <<
"/usr/local/share/cups"
68 <<
"/opt/local/share/cups");
69 documentdir_ = findDir(TQStringList(datadir_+
"/doc-root")
70 << datadir_.left(datadir_.length()-5)+
"/doc/cups");
72 requestdir_ = findDir(TQStringList(
"/var/spool/cups")
74 serverbin_ = findDir(TQStringList(
"/usr/lib" KDELIBSUFF
"/cups")
75 <<
"/usr/local/lib" KDELIBSUFF
"/cups"
76 <<
"/opt/lib" KDELIBSUFF
"/cups"
77 <<
"/opt/local/lib" KDELIBSUFF
"/cups");
78 serverfiles_ = findDir(TQStringList(
"/etc/cups")
79 <<
"/usr/local/etc/cups");
80 tmpfiles_ = requestdir_+
"/tmp";
83 servername_ = TQString::null;
84 serveradmin_ = TQString::null;
85 classification_ = CLASS_NONE;
86 otherclassname_ = TQString::null;
87 classoverride_ =
false;
90 printcap_ =
"/etc/printcap";
91 printcapformat_ = PRINTCAP_BSD;
92 remoteroot_ =
"remroot";
93 systemgroup_ =
"lpadmin";
94 encryptcert_ = serverfiles_+
"/ssl/server.crt";
95 encryptkey_ = serverfiles_+
"/ssl/server.key";
96 hostnamelookup_ = HOSTNAME_OFF;
98 keepalivetimeout_ = 60;
100 maxrequestsize_ =
"0";
101 clienttimeout_ = 300;
103 TQString logdir = findDir(TQStringList(
"/var/log/cups")
104 <<
"/var/spool/cups/log"
106 accesslog_ = logdir+
"/access_log";
107 errorlog_ = logdir+
"/error_log";
108 pagelog_ = logdir+
"/page_log";
110 loglevel_ = LOGLEVEL_INFO;
111 keepjobhistory_ =
true;
112 keepjobfiles_ =
false;
113 autopurgejobs_ =
false;
115 maxjobsperprinter_ = 0;
122 browseprotocols_ <<
"CUPS";
123 browseport_ = ippPort();
124 browseinterval_ = 30;
125 browsetimeout_ = 300;
127 browseorder_ = ORDER_ALLOW_DENY;
128 useimplicitclasses_ =
true;
129 hideimplicitmembers_ =
true;
130 useshortnames_ =
true;
131 useanyclasses_ =
false;
133 loadAvailableResources();
136 CupsdConf::~CupsdConf()
140 bool CupsdConf::loadFromFile(
const TQString& filename)
143 if (!f.exists() || !f.open(IO_ReadOnly))
return false;
148 bool done(
false), value(
true);
149 while (!done && value)
151 line = t.readLine().simplifyWhiteSpace();
154 if (t.atEnd()) done =
true;
157 else if (line[0] ==
'#')
continue;
158 else if (line.left(9).lower() ==
"<location")
160 CupsLocation *location =
new CupsLocation();
161 locations_.append(location);
162 if (!location->parseResource(line) || !parseLocation(location, t))
165 for (resources_.first();resources_.current();resources_.next())
166 if (resources_.current()->path_ == location->resourcename_)
167 location->resource_ = resources_.current();
169 else value = parseOption(line);
176 bool CupsdConf::saveToFile(
const TQString& filename)
179 if (!f.open(IO_WriteOnly))
184 t << comments_[
"header"] << endl;
185 t <<
"# Server" << endl << endl;
187 t << comments_[
"servername"] << endl;
188 if ( !servername_.isEmpty() )
189 t <<
"ServerName " << servername_ << endl;
191 t << endl << comments_[
"serveradmin"] << endl;
192 if ( !serveradmin_.isEmpty() )
193 t <<
"ServerAdmin " << serveradmin_ << endl;
195 t << endl << comments_[
"classification"] << endl;
196 t <<
"Classification ";
197 switch (classification_)
200 case CLASS_NONE: t <<
"none";
break;
201 case CLASS_CLASSIFIED: t <<
"classified";
break;
202 case CLASS_CONFIDENTIAL: t <<
"confidential";
break;
203 case CLASS_SECRET: t <<
"secret";
break;
204 case CLASS_TOPSECRET: t <<
"topsecret";
break;
205 case CLASS_UNCLASSIFIED: t <<
"unclassified";
break;
206 case CLASS_OTHER: t << otherclassname_;
break;
210 t << endl << comments_[
"classifyoverride"] << endl;
211 if (classification_ != CLASS_NONE) t <<
"ClassifyOverride " << (classoverride_ ?
"Yes" :
"No") << endl;
213 t << endl << comments_[
"defaultcharset"] << endl;
214 t <<
"DefaultCharset " << charset_.upper() << endl;
216 t << endl << comments_[
"defaultlanguage"] << endl;
217 t <<
"DefaultLanguage " << language_.lower() << endl;
219 t << endl << comments_[
"printcap"] << endl;
220 t <<
"Printcap " << printcap_ << endl;
222 t << endl << comments_[
"printcapformat"] << endl;
223 t <<
"PrintcapFormat " << (printcapformat_ == PRINTCAP_SOLARIS ?
"Solaris" :
"BSD") << endl;
225 t << endl <<
"# Security" << endl;
226 t << endl << comments_[
"remoteroot"] << endl;
227 t <<
"RemoteRoot " << remoteroot_ << endl;
229 t << endl << comments_[
"systemgroup"] << endl;
230 t <<
"SystemGroup " << systemgroup_ << endl;
232 t << endl << comments_[
"servercertificate"] << endl;
233 t <<
"ServerCertificate " << encryptcert_ << endl;
235 t << endl << comments_[
"serverkey"] << endl;
236 t <<
"ServerKey " << encryptkey_ << endl;
238 t << endl << comments_[
"locations"] << endl;
239 for (locations_.first(); locations_.current(); locations_.next())
241 CupsLocation *loc = locations_.current();
242 t <<
"<Location " << loc->resourcename_ <<
">" << endl;
243 if (loc->authtype_ != AUTHTYPE_NONE)
246 switch (loc->authtype_)
248 case AUTHTYPE_BASIC: t <<
"Basic";
break;
249 case AUTHTYPE_DIGEST: t <<
"Digest";
break;
253 if (loc->authclass_ != AUTHCLASS_ANONYMOUS)
255 switch (loc->authclass_)
258 if (!loc->authname_.isEmpty())
259 t <<
"Require user " << loc->authname_ << endl;
261 t <<
"AuthClass User" << endl;
263 case AUTHCLASS_GROUP:
264 if (!loc->authname_.isEmpty())
265 t <<
"Require group " << loc->authname_ << endl;
267 t <<
"AuthClass Group" << endl;
269 case AUTHCLASS_SYSTEM:
270 t <<
"AuthClass System" << endl;
275 switch (loc->encryption_)
277 case ENCRYPT_ALWAYS: t <<
"Always";
break;
278 case ENCRYPT_NEVER: t <<
"Never";
break;
279 case ENCRYPT_REQUIRED: t <<
"Required";
break;
281 case ENCRYPT_IFREQUESTED: t <<
"IfRequested";
break;
284 t <<
"Satisfy " << (loc->satisfy_ == SATISFY_ALL ?
"All" :
"Any") << endl;
285 t <<
"Order " << (loc->order_ == ORDER_ALLOW_DENY ?
"allow,deny" :
"deny,allow") << endl;
286 for (TQStringList::ConstIterator it=loc->addresses_.begin(); it!=loc->addresses_.end(); ++it)
288 t <<
"</Location>" << endl;
291 t << endl <<
"# Network" << endl;
292 t << endl << comments_[
"hostnamelookups"] << endl;
293 t <<
"HostnameLookups ";
294 switch (hostnamelookup_)
297 case HOSTNAME_OFF: t <<
"Off";
break;
298 case HOSTNAME_ON: t <<
"On";
break;
299 case HOSTNAME_DOUBLE: t <<
"Double";
break;
303 t << endl << comments_[
"keepalive"] << endl;
304 t <<
"KeepAlive " << (keepalive_ ?
"On" :
"Off") << endl;
306 t << endl << comments_[
"keepalivetimeout"] << endl;
307 t <<
"KeepAliveTimeout " << keepalivetimeout_ << endl;
309 t << endl << comments_[
"maxclients"] << endl;
310 t <<
"MaxClients " << maxclients_ << endl;
312 t << endl << comments_[
"maxrequestsize"] << endl;
313 t <<
"MaxRequestSize " << maxrequestsize_ << endl;
315 t << endl << comments_[
"timeout"] << endl;
316 t <<
"Timeout " << clienttimeout_ << endl;
318 t << endl << comments_[
"listen"] << endl;
319 for (TQStringList::ConstIterator it=listenaddresses_.begin(); it!=listenaddresses_.end(); ++it)
322 t << endl <<
"# Log" << endl;
323 t << endl << comments_[
"accesslog"] << endl;
324 t <<
"AccessLog " << accesslog_ << endl;
326 t << endl << comments_[
"errorlog"] << endl;
327 t <<
"ErrorLog " << errorlog_ << endl;
329 t << endl << comments_[
"pagelog"] << endl;
330 t <<
"PageLog " << pagelog_ << endl;
332 t << endl << comments_[
"maxlogsize"] << endl;
334 t <<
"MaxLogSize " << maxlogsize_ << endl;
336 t << endl << comments_[
"loglevel"] << endl;
340 case LOGLEVEL_NONE: t <<
"none";
break;
342 case LOGLEVEL_INFO: t <<
"info";
break;
343 case LOGLEVEL_ERROR: t <<
"error";
break;
344 case LOGLEVEL_WARN: t <<
"warn";
break;
345 case LOGLEVEL_DEBUG: t <<
"debug";
break;
346 case LOGLEVEL_DEBUG2: t <<
"debug2";
break;
350 t << endl <<
"# Jobs" << endl;
351 t << endl << comments_[
"preservejobhistory"] << endl;
352 t <<
"PreserveJobHistory " << (keepjobhistory_ ?
"On" :
"Off") << endl;
354 t << endl << comments_[
"preservejobfiles"] << endl;
355 if (keepjobhistory_) t <<
"PreserveJobFiles " << (keepjobfiles_ ?
"On" :
"Off") << endl;
357 t << endl << comments_[
"autopurgejobs"] << endl;
358 if (keepjobhistory_) t <<
"AutoPurgeJobs " << (autopurgejobs_ ?
"Yes" :
"No") << endl;
360 t << endl << comments_[
"maxjobs"] << endl;
361 t <<
"MaxJobs " << maxjobs_ << endl;
363 t << endl << comments_[
"maxjobsperprinter"] << endl;
364 t <<
"MaxJobsPerPrinter " << maxjobsperprinter_ << endl;
366 t << endl << comments_[
"maxjobsperuser"] << endl;
367 t <<
"MaxJobsPerUser " << maxjobsperuser_ << endl;
369 t << endl <<
"# Filter" << endl;
370 t << endl << comments_[
"user"] << endl;
371 t <<
"User " << user_ << endl;
373 t << endl << comments_[
"group"] << endl;
374 t <<
"Group " << group_ << endl;
376 t << endl << comments_[
"ripcache"] << endl;
377 t <<
"RIPCache " << ripcache_ << endl;
379 t << endl << comments_[
"filterlimit"] << endl;
380 t <<
"FilterLimit " << filterlimit_ << endl;
382 t << endl <<
"# Directories" << endl;
383 t << endl << comments_[
"datadir"] << endl;
384 t <<
"DataDir " << datadir_ << endl;
386 t << endl << comments_[
"documentroot"] << endl;
387 t <<
"DocumentRoot " << documentdir_ << endl;
389 t << endl << comments_[
"fontpath"] << endl;
390 for (TQStringList::ConstIterator it=fontpath_.begin(); it!=fontpath_.end(); ++it)
391 t <<
"FontPath " << *it << endl;
393 t << endl << comments_[
"requestroot"] << endl;
394 t <<
"RequestRoot " << requestdir_ << endl;
396 t << endl << comments_[
"serverbin"] << endl;
397 t <<
"ServerBin " << serverbin_ << endl;
399 t << endl << comments_[
"serverroot"] << endl;
400 t <<
"ServerRoot " << serverfiles_ << endl;
402 t << endl << comments_[
"tempdir"] << endl;
403 t <<
"TempDir " << tmpfiles_ << endl;
405 t << endl <<
"# Browsing" << endl;
406 t << endl << comments_[
"browsing"] << endl;
407 t <<
"Browsing " << (browsing_ ?
"On" :
"Off") << endl;
409 t << endl << comments_[
"browseprotocols"] << endl;
412 t <<
"BrowseProtocols ";
413 for (TQStringList::ConstIterator it=browseprotocols_.begin(); it!=browseprotocols_.end(); ++it)
414 t << (*it).upper() <<
" ";
418 t << endl << comments_[
"browseport"] << endl;
419 if (browsing_) t <<
"BrowsePort " << browseport_ << endl;
421 t << endl << comments_[
"browseinterval"] << endl;
422 if (browsing_) t <<
"BrowseInterval " << browseinterval_ << endl;
424 t << endl << comments_[
"browsetimeout"] << endl;
425 if (browsing_) t <<
"BrowseTimeout " << browsetimeout_ << endl;
427 t << endl << comments_[
"browseaddress"] << endl;
429 for (TQStringList::ConstIterator it=browseaddresses_.begin(); it!=browseaddresses_.end(); ++it)
430 if ((*it).startsWith(
"Send"))
431 t <<
"BrowseAddress " << (*it).mid(5) << endl;
433 t <<
"Browse" << (*it) << endl;
435 t << endl << comments_[
"browseorder"] << endl;
436 if (browsing_) t <<
"BrowseOrder " << (browseorder_ == ORDER_ALLOW_DENY ?
"allow,deny" :
"deny,allow") << endl;
438 t << endl << comments_[
"implicitclasses"] << endl;
439 if (browsing_) t <<
"ImplicitClasses " << (useimplicitclasses_ ?
"On" :
"Off") << endl;
441 t << endl << comments_[
"implicitanyclasses"] << endl;
442 if (browsing_) t <<
"ImplicitAnyClasses " << (useanyclasses_ ?
"On" :
"Off") << endl;
444 t << endl << comments_[
"hideimplicitmembers"] << endl;
445 if (browsing_) t <<
"HideImplicitMembers " << (hideimplicitmembers_ ?
"Yes" :
"No") << endl;
447 t << endl << comments_[
"browseshortnames"] << endl;
448 if (browsing_) t <<
"BrowseShortNames " << (useshortnames_ ?
"Yes" :
"No") << endl;
450 t << endl <<
"# Unknown" << endl;
451 for (TQValueList< TQPair<TQString,TQString> >::ConstIterator it=unknown_.begin(); it!=unknown_.end(); ++it)
452 t << (*it).first <<
" " << (*it).second << endl;
458 bool CupsdConf::parseLocation(CupsLocation *location, TQTextStream& file)
463 while (!done && value)
465 line = file.readLine().simplifyWhiteSpace();
475 else if (line[0] ==
'#')
continue;
476 else if (line.lower() ==
"</location>") done =
true;
477 else value = location->parseOption(line);
482 bool CupsdConf::parseOption(
const TQString& line)
485 TQString keyword, value, l(line.simplifyWhiteSpace());
487 if ((p=l.find(
' ')) != -1)
489 keyword = l.left(p).lower();
498 if (keyword ==
"accesslog") accesslog_ = value;
499 else if (keyword ==
"autopurgejobs") autopurgejobs_ = (value.lower() ==
"yes");
500 else if (keyword ==
"browseaddress") browseaddresses_.append(
"Send "+value);
501 else if (keyword ==
"browseallow") browseaddresses_.append(
"Allow "+value);
502 else if (keyword ==
"browsedeny") browseaddresses_.append(
"Deny "+value);
503 else if (keyword ==
"browseinterval") browseinterval_ = value.toInt();
504 else if (keyword ==
"browseorder") browseorder_ = (value.lower() ==
"deny,allow" ? ORDER_DENY_ALLOW : ORDER_ALLOW_DENY);
505 else if (keyword ==
"browsepoll") browseaddresses_.append(
"Poll "+value);
506 else if (keyword ==
"browseport") browseport_ = value.toInt();
507 else if (keyword ==
"browseprotocols")
509 browseprotocols_.clear();
510 TQStringList prots = TQStringList::split(TQRegExp(
"\\s"), value,
false);
511 if (prots.find(
"all") != prots.end())
512 browseprotocols_ <<
"CUPS" <<
"SLP";
514 for (TQStringList::ConstIterator it=prots.begin(); it!=prots.end(); ++it)
515 browseprotocols_ << (*it).upper();
517 else if (keyword ==
"browserelay") browseaddresses_.append(
"Relay "+value);
518 else if (keyword ==
"browseshortnames") useshortnames_ = (value.lower() !=
"no");
519 else if (keyword ==
"browsetimeout") browsetimeout_ = value.toInt();
520 else if (keyword ==
"browsing") browsing_ = (value.lower() !=
"off");
521 else if (keyword ==
"classification")
523 TQString cl = value.lower();
524 if (cl ==
"none") classification_ = CLASS_NONE;
525 else if (cl ==
"classified") classification_ = CLASS_CLASSIFIED;
526 else if (cl ==
"confidential") classification_ = CLASS_CONFIDENTIAL;
527 else if (cl ==
"secret") classification_ = CLASS_SECRET;
528 else if (cl ==
"topsecret") classification_ = CLASS_TOPSECRET;
529 else if (cl ==
"unclassified") classification_ = CLASS_UNCLASSIFIED;
532 classification_ = CLASS_OTHER;
533 otherclassname_ = cl;
536 else if (keyword ==
"classifyoverride") classoverride_ = (value.lower() ==
"yes");
537 else if (keyword ==
"datadir") datadir_ = value;
538 else if (keyword ==
"defaultcharset") charset_ = value;
539 else if (keyword ==
"defaultlanguage") language_ = value;
540 else if (keyword ==
"documentroot") documentdir_ = value;
541 else if (keyword ==
"errorlog") errorlog_ = value;
542 else if (keyword ==
"filterlimit") filterlimit_ = value.toInt();
543 else if (keyword ==
"fontpath") fontpath_ += TQStringList::split(
':', value,
false);
544 else if (keyword ==
"group") group_ = value;
545 else if (keyword ==
"hideimplicitmembers") hideimplicitmembers_ = (value.lower() !=
"no");
546 else if (keyword ==
"hostnamelookups")
548 TQString h = value.lower();
549 if (h ==
"on") hostnamelookup_ = HOSTNAME_ON;
550 else if (h ==
"double") hostnamelookup_ = HOSTNAME_DOUBLE;
551 else hostnamelookup_ = HOSTNAME_OFF;
553 else if (keyword ==
"implicitclasses") useimplicitclasses_ = (value.lower() !=
"off");
554 else if (keyword ==
"implicitanyclasses") useanyclasses_ = (value.lower() ==
"on");
555 else if (keyword ==
"keepalive") keepalive_ = (value.lower() !=
"off");
556 else if (keyword ==
"keepalivetimeout") keepalivetimeout_ = value.toInt();
557 else if (keyword ==
"listen") listenaddresses_.append(
"Listen "+value);
558 else if (keyword ==
"loglevel")
560 TQString ll = value.lower();
561 if (ll ==
"none") loglevel_ = LOGLEVEL_NONE;
562 else if (ll ==
"error") loglevel_ = LOGLEVEL_ERROR;
563 else if (ll ==
"warn") loglevel_ = LOGLEVEL_WARN;
564 else if (ll ==
"info") loglevel_ = LOGLEVEL_INFO;
565 else if (ll ==
"debug") loglevel_ = LOGLEVEL_DEBUG;
566 else if (ll ==
"debug2") loglevel_ = LOGLEVEL_DEBUG2;
568 else if (keyword ==
"maxclients") maxclients_ = value.toInt();
569 else if (keyword ==
"maxjobs") maxjobs_ = value.toInt();
570 else if (keyword ==
"maxjobsperprinter") maxjobsperprinter_ = value.toInt();
571 else if (keyword ==
"maxjobsperuser") maxjobsperuser_ = value.toInt();
572 else if (keyword ==
"maxrequestsize") maxrequestsize_ = value;
573 else if (keyword ==
"maxlogsize") maxlogsize_ = value;
579 else if (keyword ==
"pagelog") pagelog_ = value;
580 else if (keyword ==
"port") listenaddresses_.append(
"Listen *:"+value);
581 else if (keyword ==
"preservejobhistory") keepjobhistory_ = (value !=
"off");
582 else if (keyword ==
"preservejobfiles") keepjobfiles_ = (value ==
"on");
583 else if (keyword ==
"printcap") printcap_ = value;
584 else if (keyword ==
"printcapformat") printcapformat_ = (value.lower() ==
"solaris" ? PRINTCAP_SOLARIS : PRINTCAP_BSD);
585 else if (keyword ==
"requestroot") requestdir_ = value;
586 else if (keyword ==
"remoteroot") remoteroot_ = value;
587 else if (keyword ==
"ripcache") ripcache_ = value;
588 else if (keyword ==
"serveradmin") serveradmin_ = value;
589 else if (keyword ==
"serverbin") serverbin_ = value;
590 else if (keyword ==
"servercertificate") encryptcert_ = value;
591 else if (keyword ==
"serverkey") encryptkey_ = value;
592 else if (keyword ==
"servername") servername_ = value;
593 else if (keyword ==
"serverroot") serverfiles_ = value;
594 else if (keyword ==
"ssllisten") listenaddresses_.append(
"SSLListen "+value);
595 else if (keyword ==
"sslport") listenaddresses_.append(
"SSLListen *:"+value);
596 else if (keyword ==
"systemgroup") systemgroup_ = value;
597 else if (keyword ==
"tempdir") tmpfiles_ = value;
598 else if (keyword ==
"timeout") clienttimeout_ = value.toInt();
599 else if (keyword ==
"user") user_ = value;
603 unknown_ << TQPair<TQString,TQString>(keyword, value);
608 bool CupsdConf::loadAvailableResources()
610 KConfig conf(
"kdeprintrc");
611 conf.setGroup(
"CUPS");
612 TQString host = conf.readEntry(
"Host",cupsServer());
613 int port = conf.readNumEntry(
"Port",ippPort());
614 http_t *http_ = httpConnect(host.local8Bit(),port);
618 resources_.append(
new CupsResource(
"/"));
619 resources_.append(
new CupsResource(
"/admin"));
620 resources_.append(
new CupsResource(
"/printers"));
621 resources_.append(
new CupsResource(
"/classes"));
622 resources_.append(
new CupsResource(
"/jobs"));
628 ipp_t *request_ = ippNew();
629 cups_lang_t* lang = cupsLangDefault();
630 ippAddString(request_, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
"attributes-charset", NULL, cupsLangEncoding(lang));
631 ippAddString(request_, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
"attributes-natural-language", NULL, lang->language);
633 ippSetOperation(request_, CUPS_GET_PRINTERS);
634 #else // HAVE_CUPS_1_6
635 request_->request.op.operation_id = CUPS_GET_PRINTERS;
636 #endif // HAVE_CUPS_1_6
637 request_ = cupsDoRequest(http_, request_,
"/printers/");
643 ipp_attribute_t *attr = ippFirstAttribute(request_);
644 #else // HAVE_CUPS_1_6
645 ipp_attribute_t *attr = request_->attrs;
646 #endif // HAVE_CUPS_1_6
651 if (!ippGetName(attr))
652 #else // HAVE_CUPS_1_6
654 #endif // HAVE_CUPS_1_6
656 if (!(type & CUPS_PRINTER_REMOTE) && !(type & CUPS_PRINTER_IMPLICIT) && !name.isEmpty())
657 resources_.append(
new CupsResource(
"/printers/"+name));
662 else if (strcmp(ippGetName(attr),
"printer-name") == 0) name = ippGetString(attr, 0, NULL);
663 else if (strcmp(ippGetName(attr),
"printer-type") == 0) type = ippGetInteger(attr, 0);
664 attr = ippNextAttribute(request_);
665 #else // HAVE_CUPS_1_6
666 else if (strcmp(attr->name,
"printer-name") == 0) name = attr->values[0].string.text;
667 else if (strcmp(attr->name,
"printer-type") == 0) type = attr->values[0].integer;
669 #endif // HAVE_CUPS_1_6
671 if (!(type & CUPS_PRINTER_REMOTE) && !(type & CUPS_PRINTER_IMPLICIT) && !name.isEmpty())
672 resources_.append(
new CupsResource(
"/printers/"+name));
677 ippAddString(request_, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
"attributes-charset", NULL, cupsLangEncoding(lang));
678 ippAddString(request_, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
"attributes-natural-language", NULL, lang->language);
680 ippSetOperation(request_, CUPS_GET_CLASSES);
681 #else // HAVE_CUPS_1_6
682 request_->request.op.operation_id = CUPS_GET_CLASSES;
683 #endif // HAVE_CUPS_1_6
684 request_ = cupsDoRequest(http_, request_,
"/classes/");
690 ipp_attribute_t *attr = ippFirstAttribute(request_);
691 #else // HAVE_CUPS_1_6
692 ipp_attribute_t *attr = request_->attrs;
693 #endif // HAVE_CUPS_1_6
698 if (!ippGetName(attr))
699 #else // HAVE_CUPS_1_6
701 #endif // HAVE_CUPS_1_6
703 if (!(type & CUPS_PRINTER_REMOTE) && !name.isEmpty())
704 resources_.append(
new CupsResource(
"/classes/"+name));
709 else if (strcmp(ippGetName(attr),
"printer-name") == 0) name = ippGetString(attr, 0, NULL);
710 else if (strcmp(ippGetName(attr),
"printer-type") == 0) type = ippGetInteger(attr, 0);
711 attr = ippNextAttribute(request_);
712 #else // HAVE_CUPS_1_6
713 else if (strcmp(attr->name,
"printer-name") == 0) name = attr->values[0].string.text;
714 else if (strcmp(attr->name,
"printer-type") == 0) type = attr->values[0].integer;
716 #endif // HAVE_CUPS_1_6
718 if (!(type & CUPS_PRINTER_REMOTE) && !name.isEmpty())
719 resources_.append(
new CupsResource(
"/classes/"+name));
728 CupsLocation::CupsLocation()
732 authtype_ = AUTHTYPE_NONE;
733 authclass_ = AUTHCLASS_ANONYMOUS;
734 authname_ = TQString::null;
735 encryption_ = ENCRYPT_IFREQUESTED;
736 satisfy_ = SATISFY_ALL;
737 order_ = ORDER_ALLOW_DENY;
741 CupsLocation::CupsLocation(
const CupsLocation& loc)
742 : resource_(loc.resource_),
743 resourcename_(loc.resourcename_),
744 authtype_(loc.authtype_),
745 authclass_(loc.authclass_),
746 authname_(loc.authname_),
747 encryption_(loc.encryption_),
748 satisfy_(loc.satisfy_),
750 addresses_(loc.addresses_)
754 bool CupsLocation::parseResource(
const TQString& line)
756 TQString str = line.simplifyWhiteSpace();
757 int p1 = line.find(
' '), p2 = line.find(
'>');
758 if (p1 != -1 && p2 != -1)
760 resourcename_ = str.mid(p1+1,p2-p1-1);
766 bool CupsLocation::parseOption(
const TQString& line)
769 TQString keyword, value, l(line.simplifyWhiteSpace());
771 if ((p=l.find(
' ')) != -1)
773 keyword = l.left(p).lower();
781 if (keyword ==
"authtype")
783 TQString a = value.lower();
784 if (a ==
"basic") authtype_ = AUTHTYPE_BASIC;
785 else if (a ==
"digest") authtype_ = AUTHTYPE_DIGEST;
786 else authtype_ = AUTHTYPE_NONE;
788 else if (keyword ==
"authclass")
790 TQString a = value.lower();
791 if (a ==
"user") authclass_ = AUTHCLASS_USER;
792 else if (a ==
"system") authclass_ = AUTHCLASS_SYSTEM;
793 else if (a ==
"group") authclass_ = AUTHCLASS_GROUP;
794 else authclass_ = AUTHCLASS_ANONYMOUS;
796 else if (keyword ==
"authgroupname") authname_ = value;
797 else if (keyword ==
"require")
799 int p = value.find(
' ');
802 authname_ = value.mid(p+1);
803 TQString cl = value.left(p).lower();
805 authclass_ = AUTHCLASS_USER;
806 else if (cl ==
"group")
807 authclass_ = AUTHCLASS_GROUP;
810 else if (keyword ==
"allow") addresses_.append(
"Allow "+value);
811 else if (keyword ==
"deny") addresses_.append(
"Deny "+value);
812 else if (keyword ==
"order") order_ = (value.lower() ==
"deny,allow" ? ORDER_DENY_ALLOW : ORDER_ALLOW_DENY);
813 else if (keyword ==
"encryption")
815 TQString e = value.lower();
816 if (e ==
"always") encryption_ = ENCRYPT_ALWAYS;
817 else if (e ==
"never") encryption_ = ENCRYPT_NEVER;
818 else if (e ==
"required") encryption_ = ENCRYPT_REQUIRED;
819 else encryption_ = ENCRYPT_IFREQUESTED;
821 else if (keyword ==
"satisfy") satisfy_ = (value.lower() ==
"any" ? SATISFY_ANY : SATISFY_ALL);
828 CupsResource::CupsResource()
830 type_ = RESOURCE_GLOBAL;
833 CupsResource::CupsResource(
const TQString& path)
838 void CupsResource::setPath(
const TQString& path)
841 type_ = typeFromPath(path_);
842 text_ = pathToText(path_);
845 int CupsResource::typeFromText(
const TQString& text)
847 if (text == i18n(
"Base",
"Root") || text == i18n(
"All printers") || text == i18n(
"All classes") || text == i18n(
"Print jobs"))
return RESOURCE_GLOBAL;
848 else if (text == i18n(
"Administration"))
return RESOURCE_ADMIN;
849 else if (text.find(i18n(
"Class")) == 0)
return RESOURCE_CLASS;
850 else if (text.find(i18n(
"Printer")) == 0)
return RESOURCE_PRINTER;
851 else return RESOURCE_PRINTER;
854 int CupsResource::typeFromPath(
const TQString& path)
856 if (path ==
"/admin")
return RESOURCE_ADMIN;
857 else if (path ==
"/printers" || path ==
"/classes" || path ==
"/" || path ==
"/jobs")
return RESOURCE_GLOBAL;
858 else if (path.left(9) ==
"/printers")
return RESOURCE_PRINTER;
859 else if (path.left(8) ==
"/classes")
return RESOURCE_CLASS;
860 else return RESOURCE_GLOBAL;
863 TQString CupsResource::textToPath(
const TQString& text)
866 if (text == i18n(
"Administration")) path =
"/admin";
867 else if (text == i18n(
"All printers")) path =
"/printers";
868 else if (text == i18n(
"All classes")) path =
"/classes";
869 else if (text == i18n(
"Print jobs")) path =
"/jobs";
870 else if (text == i18n(
"Base",
"Root")) path =
"/";
871 else if (text.find(i18n(
"Printer")) == 0)
874 path.append(text.right(text.length()-i18n(
"Printer").length()-1));
876 else if (text.find(i18n(
"Class")) == 0)
879 path.append(text.right(text.length()-i18n(
"Class").length()-1));
884 TQString CupsResource::pathToText(
const TQString& path)
886 TQString text(i18n(
"Base",
"Root"));
887 if (path ==
"/admin") text = i18n(
"Administration");
888 else if (path ==
"/printers") text = i18n(
"All printers");
889 else if (path ==
"/classes") text = i18n(
"All classes");
890 else if (path ==
"/") text = i18n(
"Root");
891 else if (path ==
"/jobs") text = i18n(
"Print jobs");
892 else if (path.find(
"/printers/") == 0)
894 text = i18n(
"Printer");
896 text.append(path.right(path.length()-10));
898 else if (path.find(
"/classes/") == 0)
900 text = i18n(
"Class");
902 text.append(path.right(path.length()-9));
907 TQString CupsResource::typeToIconName(
int type)
912 case RESOURCE_GLOBAL:
913 return TQString(
"folder");
914 case RESOURCE_PRINTER:
915 return TQString(
"kdeprint_printer");
917 return TQString(
"kdeprint_printer_class");
919 return TQString(
"folder");