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

tdeprint

  • tdeprint
  • cups
  • cupsdconf2
cupsdconf.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 <config.h>
21 #include "cupsdconf.h"
22 
23 #include <tqfile.h>
24 #include <tqregexp.h>
25 #include <tdelocale.h>
26 #include <kdebug.h>
27 #include <tdeconfig.h>
28 
29 #include <stdlib.h>
30 #include <cups/cups.h>
31 #include <cups/ipp.h>
32 #include <cups/language.h>
33 
34 TQString findDir(const TQStringList& list)
35 {
36  for (TQStringList::ConstIterator it=list.begin(); it!=list.end(); ++it)
37  if (TQFile::exists(*it))
38  return *it;
39  // if nothing found, just use the first as default value
40  return list[0];
41 }
42 
43 void splitSizeSpec(const TQString& s, int& sz, int& suff)
44 {
45  int p = s.find(TQRegExp("\\D"));
46  sz = s.mid(0, p).toInt();
47  if (p != -1)
48  {
49  switch (s[p].latin1())
50  {
51  case 'k': suff = UNIT_KB; break;
52  default:
53  case 'm': suff = UNIT_MB; break;
54  case 'g': suff = UNIT_GB; break;
55  case 't': suff = UNIT_TILE; break;
56  }
57  }
58  else
59  suff = UNIT_MB;
60 }
61 
62 CupsdConf::CupsdConf()
63 {
64  // start by trying to find CUPS directories (useful later)
65  datadir_ = findDir(TQStringList("/usr/share/cups")
66  << "/usr/local/share/cups"
67  << "/opt/share/cups"
68  << "/opt/local/share/cups");
69  documentdir_ = findDir(TQStringList(datadir_+"/doc-root")
70  << datadir_.left(datadir_.length()-5)+"/doc/cups");
71  //fontpath_ << (datadir_+"/fonts");
72  requestdir_ = findDir(TQStringList("/var/spool/cups")
73  << "/var/cups");
74  serverbin_ = findDir(TQStringList()
75  << "/usr/" SYSTEM_LIBDIR "/cups"
76  << "/usr/lib/cups"
77  << "/usr/local/" SYSTEM_LIBDIR "/cups"
78  << "/usr/local/lib/cups"
79  << "/opt/" SYSTEM_LIBDIR "/cups"
80  << "/opt/lib/cups"
81  << "/opt/local/" SYSTEM_LIBDIR "/cups"
82  << "/opt/local/lib/cups");
83  serverfiles_ = findDir(TQStringList("/etc/cups")
84  << "/usr/local/etc/cups");
85  tmpfiles_ = requestdir_+"/tmp";
86 
87  // other options
88  servername_ = TQString::null;
89  serveradmin_ = TQString::null;
90  classification_ = CLASS_NONE;
91  otherclassname_ = TQString::null;
92  classoverride_ = false;
93  charset_ = "utf-8";
94  language_ = "en";
95  printcap_ = "/etc/printcap";
96  printcapformat_ = PRINTCAP_BSD;
97  remoteroot_ = "remroot";
98  systemgroup_ = "lpadmin";
99  encryptcert_ = serverfiles_+"/ssl/server.crt";
100  encryptkey_ = serverfiles_+"/ssl/server.key";
101  hostnamelookup_ = HOSTNAME_OFF;
102  keepalive_ = true;
103  keepalivetimeout_ = 60;
104  maxclients_ = 100;
105  maxrequestsize_ = "0";
106  clienttimeout_ = 300;
107  // listenaddresses_
108  TQString logdir = findDir(TQStringList("/var/log/cups")
109  << "/var/spool/cups/log"
110  << "/var/cups/log");
111  accesslog_ = logdir+"/access_log";
112  errorlog_ = logdir+"/error_log";
113  pagelog_ = logdir+"/page_log";
114  maxlogsize_ = "1m";
115  loglevel_ = LOGLEVEL_INFO;
116  keepjobhistory_ = true;
117  keepjobfiles_ = false;
118  autopurgejobs_ = false;
119  maxjobs_ = 0;
120  maxjobsperprinter_ = 0;
121  maxjobsperuser_ = 0;
122  user_ = "lp";
123  group_ = "lpadmin";
124  ripcache_ = "8m";
125  filterlimit_ = 0;
126  browsing_ = true;
127  browseprotocols_ << "CUPS";
128  browseport_ = ippPort();
129  browseinterval_ = 30;
130  browsetimeout_ = 300;
131  // browseaddresses_
132  browseorder_ = ORDER_ALLOW_DENY;
133  useimplicitclasses_ = true;
134  hideimplicitmembers_ = true;
135  useshortnames_ = true;
136  useanyclasses_ = false;
137 
138  loadAvailableResources();
139 }
140 
141 CupsdConf::~CupsdConf()
142 {
143 }
144 
145 bool CupsdConf::loadFromFile(const TQString& filename)
146 {
147  TQFile f(filename);
148  if (!f.exists() || !f.open(IO_ReadOnly)) return false;
149  else
150  {
151  TQTextStream t(&f);
152  TQString line;
153  bool done(false), value(true);
154  while (!done && value)
155  {
156  line = t.readLine().simplifyWhiteSpace();
157  if (line.isEmpty())
158  {
159  if (t.atEnd()) done = true;
160  else continue;
161  }
162  else if (line[0] == '#') continue;
163  else if (line.left(9).lower() == "<location")
164  {
165  CupsLocation *location = new CupsLocation();
166  locations_.append(location);
167  if (!location->parseResource(line) || !parseLocation(location, t))
168  value = false;
169  // search corresponding resource
170  for (resources_.first();resources_.current();resources_.next())
171  if (resources_.current()->path_ == location->resourcename_)
172  location->resource_ = resources_.current();
173  }
174  else value = parseOption(line);
175  }
176  f.close();
177  return value;
178  }
179 }
180 
181 bool CupsdConf::saveToFile(const TQString& filename)
182 {
183  TQFile f(filename);
184  if (!f.open(IO_WriteOnly))
185  return false;
186  else
187  {
188  TQTextStream t(&f);
189  t << comments_["header"] << endl;
190  t << "# Server" << endl << endl;
191 
192  t << comments_["servername"] << endl;
193  if ( !servername_.isEmpty() )
194  t << "ServerName " << servername_ << endl;
195 
196  t << endl << comments_["serveradmin"] << endl;
197  if ( !serveradmin_.isEmpty() )
198  t << "ServerAdmin " << serveradmin_ << endl;
199 
200  t << endl << comments_["classification"] << endl;
201  t << "Classification ";
202  switch (classification_)
203  {
204  default:
205  case CLASS_NONE: t << "none"; break;
206  case CLASS_CLASSIFIED: t << "classified"; break;
207  case CLASS_CONFIDENTIAL: t << "confidential"; break;
208  case CLASS_SECRET: t << "secret"; break;
209  case CLASS_TOPSECRET: t << "topsecret"; break;
210  case CLASS_UNCLASSIFIED: t << "unclassified"; break;
211  case CLASS_OTHER: t << otherclassname_; break;
212  }
213  t << endl;
214 
215  t << endl << comments_["classifyoverride"] << endl;
216  if (classification_ != CLASS_NONE) t << "ClassifyOverride " << (classoverride_ ? "Yes" : "No") << endl;
217 
218  t << endl << comments_["defaultcharset"] << endl;
219  t << "DefaultCharset " << charset_.upper() << endl;
220 
221  t << endl << comments_["defaultlanguage"] << endl;
222  t << "DefaultLanguage " << language_.lower() << endl;
223 
224  t << endl << comments_["printcap"] << endl;
225  t << "Printcap " << printcap_ << endl;
226 
227  t << endl << comments_["printcapformat"] << endl;
228  t << "PrintcapFormat " << (printcapformat_ == PRINTCAP_SOLARIS ? "Solaris" : "BSD") << endl;
229 
230  t << endl << "# Security" << endl;
231  t << endl << comments_["remoteroot"] << endl;
232  t << "RemoteRoot " << remoteroot_ << endl;
233 
234  t << endl << comments_["systemgroup"] << endl;
235  t << "SystemGroup " << systemgroup_ << endl;
236 
237  t << endl << comments_["servercertificate"] << endl;
238  t << "ServerCertificate " << encryptcert_ << endl;
239 
240  t << endl << comments_["serverkey"] << endl;
241  t << "ServerKey " << encryptkey_ << endl;
242 
243  t << endl << comments_["locations"] << endl;
244  for (locations_.first(); locations_.current(); locations_.next())
245  {
246  CupsLocation *loc = locations_.current();
247  t << "<Location " << loc->resourcename_ << ">" << endl;
248  if (loc->authtype_ != AUTHTYPE_NONE)
249  {
250  t << "AuthType ";
251  switch (loc->authtype_)
252  {
253  case AUTHTYPE_BASIC: t << "Basic"; break;
254  case AUTHTYPE_DIGEST: t << "Digest"; break;
255  }
256  t << endl;
257  }
258  if (loc->authclass_ != AUTHCLASS_ANONYMOUS)
259  {
260  switch (loc->authclass_)
261  {
262  case AUTHCLASS_USER:
263  if (!loc->authname_.isEmpty())
264  t << "Require user " << loc->authname_ << endl;
265  else
266  t << "AuthClass User" << endl;
267  break;
268  case AUTHCLASS_GROUP:
269  if (!loc->authname_.isEmpty())
270  t << "Require group " << loc->authname_ << endl;
271  else
272  t << "AuthClass Group" << endl;
273  break;
274  case AUTHCLASS_SYSTEM:
275  t << "AuthClass System" << endl;
276  break;
277  }
278  }
279  t << "Encryption ";
280  switch (loc->encryption_)
281  {
282  case ENCRYPT_ALWAYS: t << "Always"; break;
283  case ENCRYPT_NEVER: t << "Never"; break;
284  case ENCRYPT_REQUIRED: t << "Required"; break;
285  default:
286  case ENCRYPT_IFREQUESTED: t << "IfRequested"; break;
287  }
288  t << endl;
289  t << "Satisfy " << (loc->satisfy_ == SATISFY_ALL ? "All" : "Any") << endl;
290  t << "Order " << (loc->order_ == ORDER_ALLOW_DENY ? "allow,deny" : "deny,allow") << endl;
291  for (TQStringList::ConstIterator it=loc->addresses_.begin(); it!=loc->addresses_.end(); ++it)
292  t << *it << endl;
293  t << "</Location>" << endl;
294  }
295 
296  t << endl << "# Network" << endl;
297  t << endl << comments_["hostnamelookups"] << endl;
298  t << "HostnameLookups ";
299  switch (hostnamelookup_)
300  {
301  default:
302  case HOSTNAME_OFF: t << "Off"; break;
303  case HOSTNAME_ON: t << "On"; break;
304  case HOSTNAME_DOUBLE: t << "Double"; break;
305  }
306  t << endl;
307 
308  t << endl << comments_["keepalive"] << endl;
309  t << "KeepAlive " << (keepalive_ ? "On" : "Off") << endl;
310 
311  t << endl << comments_["keepalivetimeout"] << endl;
312  t << "KeepAliveTimeout " << keepalivetimeout_ << endl;
313 
314  t << endl << comments_["maxclients"] << endl;
315  t << "MaxClients " << maxclients_ << endl;
316 
317  t << endl << comments_["maxrequestsize"] << endl;
318  t << "MaxRequestSize " << maxrequestsize_ << endl;
319 
320  t << endl << comments_["timeout"] << endl;
321  t << "Timeout " << clienttimeout_ << endl;
322 
323  t << endl << comments_["listen"] << endl;
324  for (TQStringList::ConstIterator it=listenaddresses_.begin(); it!=listenaddresses_.end(); ++it)
325  t << *it << endl;
326 
327  t << endl << "# Log" << endl;
328  t << endl << comments_["accesslog"] << endl;
329  t << "AccessLog " << accesslog_ << endl;
330 
331  t << endl << comments_["errorlog"] << endl;
332  t << "ErrorLog " << errorlog_ << endl;
333 
334  t << endl << comments_["pagelog"] << endl;
335  t << "PageLog " << pagelog_ << endl;
336 
337  t << endl << comments_["maxlogsize"] << endl;
338  //t << "MaxLogSize " << maxlogsize_ << "m" << endl;
339  t << "MaxLogSize " << maxlogsize_ << endl;
340 
341  t << endl << comments_["loglevel"] << endl;
342  t << "LogLevel ";
343  switch (loglevel_)
344  {
345  case LOGLEVEL_NONE: t << "none"; break;
346  default:
347  case LOGLEVEL_INFO: t << "info"; break;
348  case LOGLEVEL_ERROR: t << "error"; break;
349  case LOGLEVEL_WARN: t << "warn"; break;
350  case LOGLEVEL_DEBUG: t << "debug"; break;
351  case LOGLEVEL_DEBUG2: t << "debug2"; break;
352  }
353  t << endl;
354 
355  t << endl << "# Jobs" << endl;
356  t << endl << comments_["preservejobhistory"] << endl;
357  t << "PreserveJobHistory " << (keepjobhistory_ ? "On" : "Off") << endl;
358 
359  t << endl << comments_["preservejobfiles"] << endl;
360  if (keepjobhistory_) t << "PreserveJobFiles " << (keepjobfiles_ ? "On" : "Off") << endl;
361 
362  t << endl << comments_["autopurgejobs"] << endl;
363  if (keepjobhistory_) t << "AutoPurgeJobs " << (autopurgejobs_ ? "Yes" : "No") << endl;
364 
365  t << endl << comments_["maxjobs"] << endl;
366  t << "MaxJobs " << maxjobs_ << endl;
367 
368  t << endl << comments_["maxjobsperprinter"] << endl;
369  t << "MaxJobsPerPrinter " << maxjobsperprinter_ << endl;
370 
371  t << endl << comments_["maxjobsperuser"] << endl;
372  t << "MaxJobsPerUser " << maxjobsperuser_ << endl;
373 
374  t << endl << "# Filter" << endl;
375  t << endl << comments_["user"] << endl;
376  t << "User " << user_ << endl;
377 
378  t << endl << comments_["group"] << endl;
379  t << "Group " << group_ << endl;
380 
381  t << endl << comments_["ripcache"] << endl;
382  t << "RIPCache " << ripcache_ << endl;
383 
384  t << endl << comments_["filterlimit"] << endl;
385  t << "FilterLimit " << filterlimit_ << endl;
386 
387  t << endl << "# Directories" << endl;
388  t << endl << comments_["datadir"] << endl;
389  t << "DataDir " << datadir_ << endl;
390 
391  t << endl << comments_["documentroot"] << endl;
392  t << "DocumentRoot " << documentdir_ << endl;
393 
394  t << endl << comments_["fontpath"] << endl;
395  for (TQStringList::ConstIterator it=fontpath_.begin(); it!=fontpath_.end(); ++it)
396  t << "FontPath " << *it << endl;
397 
398  t << endl << comments_["requestroot"] << endl;
399  t << "RequestRoot " << requestdir_ << endl;
400 
401  t << endl << comments_["serverbin"] << endl;
402  t << "ServerBin " << serverbin_ << endl;
403 
404  t << endl << comments_["serverroot"] << endl;
405  t << "ServerRoot " << serverfiles_ << endl;
406 
407  t << endl << comments_["tempdir"] << endl;
408  t << "TempDir " << tmpfiles_ << endl;
409 
410  t << endl << "# Browsing" << endl;
411  t << endl << comments_["browsing"] << endl;
412  t << "Browsing " << (browsing_ ? "On" : "Off") << endl;
413 
414  t << endl << comments_["browseprotocols"] << endl;
415  if (browsing_)
416  {
417  t << "BrowseProtocols ";
418  for (TQStringList::ConstIterator it=browseprotocols_.begin(); it!=browseprotocols_.end(); ++it)
419  t << (*it).upper() << " ";
420  t << endl;
421  }
422 
423  t << endl << comments_["browseport"] << endl;
424  if (browsing_) t << "BrowsePort " << browseport_ << endl;
425 
426  t << endl << comments_["browseinterval"] << endl;
427  if (browsing_) t << "BrowseInterval " << browseinterval_ << endl;
428 
429  t << endl << comments_["browsetimeout"] << endl;
430  if (browsing_) t << "BrowseTimeout " << browsetimeout_ << endl;
431 
432  t << endl << comments_["browseaddress"] << endl;
433  if (browsing_)
434  for (TQStringList::ConstIterator it=browseaddresses_.begin(); it!=browseaddresses_.end(); ++it)
435  if ((*it).startsWith("Send"))
436  t << "BrowseAddress " << (*it).mid(5) << endl;
437  else
438  t << "Browse" << (*it) << endl;
439 
440  t << endl << comments_["browseorder"] << endl;
441  if (browsing_) t << "BrowseOrder " << (browseorder_ == ORDER_ALLOW_DENY ? "allow,deny" : "deny,allow") << endl;
442 
443  t << endl << comments_["implicitclasses"] << endl;
444  if (browsing_) t << "ImplicitClasses " << (useimplicitclasses_ ? "On" : "Off") << endl;
445 
446  t << endl << comments_["implicitanyclasses"] << endl;
447  if (browsing_) t << "ImplicitAnyClasses " << (useanyclasses_ ? "On" : "Off") << endl;
448 
449  t << endl << comments_["hideimplicitmembers"] << endl;
450  if (browsing_) t << "HideImplicitMembers " << (hideimplicitmembers_ ? "Yes" : "No") << endl;
451 
452  t << endl << comments_["browseshortnames"] << endl;
453  if (browsing_) t << "BrowseShortNames " << (useshortnames_ ? "Yes" : "No") << endl;
454 
455  t << endl << "# Unknown" << endl;
456  for (TQValueList< TQPair<TQString,TQString> >::ConstIterator it=unknown_.begin(); it!=unknown_.end(); ++it)
457  t << (*it).first << " " << (*it).second << endl;
458 
459  return true;
460  }
461 }
462 
463 bool CupsdConf::parseLocation(CupsLocation *location, TQTextStream& file)
464 {
465  TQString line;
466  bool done(false);
467  bool value(true);
468  while (!done && value)
469  {
470  line = file.readLine().simplifyWhiteSpace();
471  if (line.isEmpty())
472  {
473  if (file.atEnd())
474  {
475  value = false;
476  done = true;
477  }
478  else continue;
479  }
480  else if (line[0] == '#') continue;
481  else if (line.lower() == "</location>") done = true;
482  else value = location->parseOption(line);
483  }
484  return value;
485 }
486 
487 bool CupsdConf::parseOption(const TQString& line)
488 {
489  int p(-1);
490  TQString keyword, value, l(line.simplifyWhiteSpace());
491 
492  if ((p=l.find(' ')) != -1)
493  {
494  keyword = l.left(p).lower();
495  value = l.mid(p+1);
496  }
497  else
498  {
499  keyword = l.lower();
500  }
501 
502  //kdDebug() << "cupsd.conf keyword=" << keyword << endl;
503  if (keyword == "accesslog") accesslog_ = value;
504  else if (keyword == "autopurgejobs") autopurgejobs_ = (value.lower() == "yes");
505  else if (keyword == "browseaddress") browseaddresses_.append("Send "+value);
506  else if (keyword == "browseallow") browseaddresses_.append("Allow "+value);
507  else if (keyword == "browsedeny") browseaddresses_.append("Deny "+value);
508  else if (keyword == "browseinterval") browseinterval_ = value.toInt();
509  else if (keyword == "browseorder") browseorder_ = (value.lower() == "deny,allow" ? ORDER_DENY_ALLOW : ORDER_ALLOW_DENY);
510  else if (keyword == "browsepoll") browseaddresses_.append("Poll "+value);
511  else if (keyword == "browseport") browseport_ = value.toInt();
512  else if (keyword == "browseprotocols")
513  {
514  browseprotocols_.clear();
515  TQStringList prots = TQStringList::split(TQRegExp("\\s"), value, false);
516  if (prots.find("all") != prots.end())
517  browseprotocols_ << "CUPS" << "SLP";
518  else
519  for (TQStringList::ConstIterator it=prots.begin(); it!=prots.end(); ++it)
520  browseprotocols_ << (*it).upper();
521  }
522  else if (keyword == "browserelay") browseaddresses_.append("Relay "+value);
523  else if (keyword == "browseshortnames") useshortnames_ = (value.lower() != "no");
524  else if (keyword == "browsetimeout") browsetimeout_ = value.toInt();
525  else if (keyword == "browsing") browsing_ = (value.lower() != "off");
526  else if (keyword == "classification")
527  {
528  TQString cl = value.lower();
529  if (cl == "none") classification_ = CLASS_NONE;
530  else if (cl == "classified") classification_ = CLASS_CLASSIFIED;
531  else if (cl == "confidential") classification_ = CLASS_CONFIDENTIAL;
532  else if (cl == "secret") classification_ = CLASS_SECRET;
533  else if (cl == "topsecret") classification_ = CLASS_TOPSECRET;
534  else if (cl == "unclassified") classification_ = CLASS_UNCLASSIFIED;
535  else
536  {
537  classification_ = CLASS_OTHER;
538  otherclassname_ = cl;
539  }
540  }
541  else if (keyword == "classifyoverride") classoverride_ = (value.lower() == "yes");
542  else if (keyword == "datadir") datadir_ = value;
543  else if (keyword == "defaultcharset") charset_ = value;
544  else if (keyword == "defaultlanguage") language_ = value;
545  else if (keyword == "documentroot") documentdir_ = value;
546  else if (keyword == "errorlog") errorlog_ = value;
547  else if (keyword == "filterlimit") filterlimit_ = value.toInt();
548  else if (keyword == "fontpath") fontpath_ += TQStringList::split(':', value, false);
549  else if (keyword == "group") group_ = value;
550  else if (keyword == "hideimplicitmembers") hideimplicitmembers_ = (value.lower() != "no");
551  else if (keyword == "hostnamelookups")
552  {
553  TQString h = value.lower();
554  if (h == "on") hostnamelookup_ = HOSTNAME_ON;
555  else if (h == "double") hostnamelookup_ = HOSTNAME_DOUBLE;
556  else hostnamelookup_ = HOSTNAME_OFF;
557  }
558  else if (keyword == "implicitclasses") useimplicitclasses_ = (value.lower() != "off");
559  else if (keyword == "implicitanyclasses") useanyclasses_ = (value.lower() == "on");
560  else if (keyword == "keepalive") keepalive_ = (value.lower() != "off");
561  else if (keyword == "keepalivetimeout") keepalivetimeout_ = value.toInt();
562  else if (keyword == "listen") listenaddresses_.append("Listen "+value);
563  else if (keyword == "loglevel")
564  {
565  TQString ll = value.lower();
566  if (ll == "none") loglevel_ = LOGLEVEL_NONE;
567  else if (ll == "error") loglevel_ = LOGLEVEL_ERROR;
568  else if (ll == "warn") loglevel_ = LOGLEVEL_WARN;
569  else if (ll == "info") loglevel_ = LOGLEVEL_INFO;
570  else if (ll == "debug") loglevel_ = LOGLEVEL_DEBUG;
571  else if (ll == "debug2") loglevel_ = LOGLEVEL_DEBUG2;
572  }
573  else if (keyword == "maxclients") maxclients_ = value.toInt();
574  else if (keyword == "maxjobs") maxjobs_ = value.toInt();
575  else if (keyword == "maxjobsperprinter") maxjobsperprinter_ = value.toInt();
576  else if (keyword == "maxjobsperuser") maxjobsperuser_ = value.toInt();
577  else if (keyword == "maxrequestsize") maxrequestsize_ = value;
578  else if (keyword == "maxlogsize") maxlogsize_ = value;
579  /*{
580  // FIXME: support for suffixes
581  int suffix;
582  splitSizeSpec( value, maxlogsize_, suffix );
583  }*/
584  else if (keyword == "pagelog") pagelog_ = value;
585  else if (keyword == "port") listenaddresses_.append("Listen *:"+value);
586  else if (keyword == "preservejobhistory") keepjobhistory_ = (value != "off");
587  else if (keyword == "preservejobfiles") keepjobfiles_ = (value == "on");
588  else if (keyword == "printcap") printcap_ = value;
589  else if (keyword == "printcapformat") printcapformat_ = (value.lower() == "solaris" ? PRINTCAP_SOLARIS : PRINTCAP_BSD);
590  else if (keyword == "requestroot") requestdir_ = value;
591  else if (keyword == "remoteroot") remoteroot_ = value;
592  else if (keyword == "ripcache") ripcache_ = value;
593  else if (keyword == "serveradmin") serveradmin_ = value;
594  else if (keyword == "serverbin") serverbin_ = value;
595  else if (keyword == "servercertificate") encryptcert_ = value;
596  else if (keyword == "serverkey") encryptkey_ = value;
597  else if (keyword == "servername") servername_ = value;
598  else if (keyword == "serverroot") serverfiles_ = value;
599  else if (keyword == "ssllisten") listenaddresses_.append("SSLListen "+value);
600  else if (keyword == "sslport") listenaddresses_.append("SSLListen *:"+value);
601  else if (keyword == "systemgroup") systemgroup_ = value;
602  else if (keyword == "tempdir") tmpfiles_ = value;
603  else if (keyword == "timeout") clienttimeout_ = value.toInt();
604  else if (keyword == "user") user_ = value;
605  else
606  {
607  // unrecognized option
608  unknown_ << TQPair<TQString,TQString>(keyword, value);
609  }
610  return true;
611 }
612 
613 bool CupsdConf::loadAvailableResources()
614 {
615  TDEConfig conf("tdeprintrc");
616  conf.setGroup("CUPS");
617  TQString host = conf.readEntry("Host",cupsServer());
618  int port = conf.readNumEntry("Port",ippPort());
619  http_t *http_ = httpConnect2(
620  host.local8Bit(), port, NULL, AF_UNSPEC,
621  HTTP_ENCRYPTION_IF_REQUESTED, 1, 30000, NULL);
622 
623  resources_.clear();
624  // standard resources
625  resources_.append(new CupsResource("/"));
626  resources_.append(new CupsResource("/admin"));
627  resources_.append(new CupsResource("/printers"));
628  resources_.append(new CupsResource("/classes"));
629  resources_.append(new CupsResource("/jobs"));
630 
631  if (!http_)
632  return false;
633 
634  // printer resources
635  ipp_t *request_ = ippNew();
636  cups_lang_t* lang = cupsLangDefault();
637  ippAddString(request_, IPP_TAG_OPERATION, IPP_TAG_CHARSET, "attributes-charset", NULL, cupsLangEncoding(lang));
638  ippAddString(request_, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, lang->language);
639  ippSetOperation(request_, CUPS_GET_PRINTERS);
640  request_ = cupsDoRequest(http_, request_, "/printers/");
641  if (request_)
642  {
643  TQString name;
644  int type(0);
645  ipp_attribute_t *attr = ippFirstAttribute(request_);
646  while (attr)
647  {
648  // check new printer (keep only local non-implicit printers)
649  if (!ippGetName(attr))
650  {
651  if (!(type & CUPS_PRINTER_REMOTE) && !(type & CUPS_PRINTER_IMPLICIT) && !name.isEmpty())
652  resources_.append(new CupsResource("/printers/"+name));
653  name = "";
654  type = 0;
655  }
656  else if (strcmp(ippGetName(attr), "printer-name") == 0) name = ippGetString(attr, 0, NULL);
657  else if (strcmp(ippGetName(attr), "printer-type") == 0) type = ippGetInteger(attr, 0);
658  attr = ippNextAttribute(request_);
659  }
660  if (!(type & CUPS_PRINTER_REMOTE) && !(type & CUPS_PRINTER_IMPLICIT) && !name.isEmpty())
661  resources_.append(new CupsResource("/printers/"+name));
662  ippDelete(request_);
663  }
664  // class resources
665  request_ = ippNew();
666  ippAddString(request_, IPP_TAG_OPERATION, IPP_TAG_CHARSET, "attributes-charset", NULL, cupsLangEncoding(lang));
667  ippAddString(request_, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, lang->language);
668  ippSetOperation(request_, CUPS_GET_CLASSES);
669  request_ = cupsDoRequest(http_, request_, "/classes/");
670  if (request_)
671  {
672  TQString name;
673  int type(0);
674  ipp_attribute_t *attr = ippFirstAttribute(request_);
675  while (attr)
676  {
677  // check new class (keep only local classes)
678  if (!ippGetName(attr))
679  {
680  if (!(type & CUPS_PRINTER_REMOTE) && !name.isEmpty())
681  resources_.append(new CupsResource("/classes/"+name));
682  name = "";
683  type = 0;
684  }
685  else if (strcmp(ippGetName(attr), "printer-name") == 0) name = ippGetString(attr, 0, NULL);
686  else if (strcmp(ippGetName(attr), "printer-type") == 0) type = ippGetInteger(attr, 0);
687  attr = ippNextAttribute(request_);
688  }
689  if (!(type & CUPS_PRINTER_REMOTE) && !name.isEmpty())
690  resources_.append(new CupsResource("/classes/"+name));
691  ippDelete(request_);
692  }
693  httpClose(http_);
694  return true;
695 }
696 
697 //------------------------------------------------------------------------------------------------
698 
699 CupsLocation::CupsLocation()
700 {
701  resource_ = 0;
702  resourcename_ = "";
703  authtype_ = AUTHTYPE_NONE;
704  authclass_ = AUTHCLASS_ANONYMOUS;
705  authname_ = TQString::null;
706  encryption_ = ENCRYPT_IFREQUESTED;
707  satisfy_ = SATISFY_ALL;
708  order_ = ORDER_ALLOW_DENY;
709  // addresses_
710 }
711 
712 CupsLocation::CupsLocation(const CupsLocation& loc)
713 : resource_(loc.resource_),
714  resourcename_(loc.resourcename_),
715  authtype_(loc.authtype_),
716  authclass_(loc.authclass_),
717  authname_(loc.authname_),
718  encryption_(loc.encryption_),
719  satisfy_(loc.satisfy_),
720  order_(loc.order_),
721  addresses_(loc.addresses_)
722 {
723 }
724 
725 bool CupsLocation::parseResource(const TQString& line)
726 {
727  TQString str = line.simplifyWhiteSpace();
728  int p1 = line.find(' '), p2 = line.find('>');
729  if (p1 != -1 && p2 != -1)
730  {
731  resourcename_ = str.mid(p1+1,p2-p1-1);
732  return true;
733  }
734  else return false;
735 }
736 
737 bool CupsLocation::parseOption(const TQString& line)
738 {
739  int p(-1);
740  TQString keyword, value, l(line.simplifyWhiteSpace());
741 
742  if ((p=l.find(' ')) != -1)
743  {
744  keyword = l.left(p).lower();
745  value = l.mid(p+1);
746  }
747  else
748  {
749  keyword = l.lower();
750  }
751 
752  if (keyword == "authtype")
753  {
754  TQString a = value.lower();
755  if (a == "basic") authtype_ = AUTHTYPE_BASIC;
756  else if (a == "digest") authtype_ = AUTHTYPE_DIGEST;
757  else authtype_ = AUTHTYPE_NONE;
758  }
759  else if (keyword == "authclass")
760  {
761  TQString a = value.lower();
762  if (a == "user") authclass_ = AUTHCLASS_USER;
763  else if (a == "system") authclass_ = AUTHCLASS_SYSTEM;
764  else if (a == "group") authclass_ = AUTHCLASS_GROUP;
765  else authclass_ = AUTHCLASS_ANONYMOUS;
766  }
767  else if (keyword == "authgroupname") authname_ = value;
768  else if (keyword == "require")
769  {
770  int p = value.find(' ');
771  if (p != -1)
772  {
773  authname_ = value.mid(p+1);
774  TQString cl = value.left(p).lower();
775  if (cl == "user")
776  authclass_ = AUTHCLASS_USER;
777  else if (cl == "group")
778  authclass_ = AUTHCLASS_GROUP;
779  }
780  }
781  else if (keyword == "allow") addresses_.append("Allow "+value);
782  else if (keyword == "deny") addresses_.append("Deny "+value);
783  else if (keyword == "order") order_ = (value.lower() == "deny,allow" ? ORDER_DENY_ALLOW : ORDER_ALLOW_DENY);
784  else if (keyword == "encryption")
785  {
786  TQString e = value.lower();
787  if (e == "always") encryption_ = ENCRYPT_ALWAYS;
788  else if (e == "never") encryption_ = ENCRYPT_NEVER;
789  else if (e == "required") encryption_ = ENCRYPT_REQUIRED;
790  else encryption_ = ENCRYPT_IFREQUESTED;
791  }
792  else if (keyword == "satisfy") satisfy_ = (value.lower() == "any" ? SATISFY_ANY : SATISFY_ALL);
793  else return false;
794  return true;
795 }
796 
797 //------------------------------------------------------------------------------------------------
798 
799 CupsResource::CupsResource()
800 {
801  type_ = RESOURCE_GLOBAL;
802 }
803 
804 CupsResource::CupsResource(const TQString& path)
805 {
806  setPath(path);
807 }
808 
809 void CupsResource::setPath(const TQString& path)
810 {
811  path_ = path;
812  type_ = typeFromPath(path_);
813  text_ = pathToText(path_);
814 }
815 
816 int CupsResource::typeFromText(const TQString& text)
817 {
818  if (text == i18n("Base", "Root") || text == i18n("All printers") || text == i18n("All classes") || text == i18n("Print jobs")) return RESOURCE_GLOBAL;
819  else if (text == i18n("Administration")) return RESOURCE_ADMIN;
820  else if (text.find(i18n("Class")) == 0) return RESOURCE_CLASS;
821  else if (text.find(i18n("Printer")) == 0) return RESOURCE_PRINTER;
822  else return RESOURCE_PRINTER;
823 }
824 
825 int CupsResource::typeFromPath(const TQString& path)
826 {
827  if (path == "/admin") return RESOURCE_ADMIN;
828  else if (path == "/printers" || path == "/classes" || path == "/" || path == "/jobs") return RESOURCE_GLOBAL;
829  else if (path.left(9) == "/printers") return RESOURCE_PRINTER;
830  else if (path.left(8) == "/classes") return RESOURCE_CLASS;
831  else return RESOURCE_GLOBAL;
832 }
833 
834 TQString CupsResource::textToPath(const TQString& text)
835 {
836  TQString path("/");
837  if (text == i18n("Administration")) path = "/admin";
838  else if (text == i18n("All printers")) path = "/printers";
839  else if (text == i18n("All classes")) path = "/classes";
840  else if (text == i18n("Print jobs")) path = "/jobs";
841  else if (text == i18n("Base", "Root")) path = "/";
842  else if (text.find(i18n("Printer")) == 0)
843  {
844  path = "/printers/";
845  path.append(text.right(text.length()-i18n("Printer").length()-1));
846  }
847  else if (text.find(i18n("Class")) == 0)
848  {
849  path = "/classes/";
850  path.append(text.right(text.length()-i18n("Class").length()-1));
851  }
852  return path;
853 }
854 
855 TQString CupsResource::pathToText(const TQString& path)
856 {
857  TQString text(i18n("Base", "Root"));
858  if (path == "/admin") text = i18n("Administration");
859  else if (path == "/printers") text = i18n("All printers");
860  else if (path == "/classes") text = i18n("All classes");
861  else if (path == "/") text = i18n("Root");
862  else if (path == "/jobs") text = i18n("Print jobs");
863  else if (path.find("/printers/") == 0)
864  {
865  text = i18n("Printer");
866  text.append(" ");
867  text.append(path.right(path.length()-10));
868  }
869  else if (path.find("/classes/") == 0)
870  {
871  text = i18n("Class");
872  text.append(" ");
873  text.append(path.right(path.length()-9));
874  }
875  return text;
876 }
877 
878 TQString CupsResource::typeToIconName(int type)
879 {
880  switch (type)
881  {
882  case RESOURCE_ADMIN:
883  case RESOURCE_GLOBAL:
884  return TQString("folder");
885  case RESOURCE_PRINTER:
886  return TQString("tdeprint_printer");
887  case RESOURCE_CLASS:
888  return TQString("tdeprint_printer_class");
889  }
890  return TQString("folder");
891 }

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.8.17
This website is maintained by Timothy Pearson.