• 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("/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";
81 
82  // other options
83  servername_ = TQString::null;
84  serveradmin_ = TQString::null;
85  classification_ = CLASS_NONE;
86  otherclassname_ = TQString::null;
87  classoverride_ = false;
88  charset_ = "utf-8";
89  language_ = "en";
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;
97  keepalive_ = true;
98  keepalivetimeout_ = 60;
99  maxclients_ = 100;
100  maxrequestsize_ = "0";
101  clienttimeout_ = 300;
102  // listenaddresses_
103  TQString logdir = findDir(TQStringList("/var/log/cups")
104  << "/var/spool/cups/log"
105  << "/var/cups/log");
106  accesslog_ = logdir+"/access_log";
107  errorlog_ = logdir+"/error_log";
108  pagelog_ = logdir+"/page_log";
109  maxlogsize_ = "1m";
110  loglevel_ = LOGLEVEL_INFO;
111  keepjobhistory_ = true;
112  keepjobfiles_ = false;
113  autopurgejobs_ = false;
114  maxjobs_ = 0;
115  maxjobsperprinter_ = 0;
116  maxjobsperuser_ = 0;
117  user_ = "lp";
118  group_ = "lpadmin";
119  ripcache_ = "8m";
120  filterlimit_ = 0;
121  browsing_ = true;
122  browseprotocols_ << "CUPS";
123  browseport_ = ippPort();
124  browseinterval_ = 30;
125  browsetimeout_ = 300;
126  // browseaddresses_
127  browseorder_ = ORDER_ALLOW_DENY;
128  useimplicitclasses_ = true;
129  hideimplicitmembers_ = true;
130  useshortnames_ = true;
131  useanyclasses_ = false;
132 
133  loadAvailableResources();
134 }
135 
136 CupsdConf::~CupsdConf()
137 {
138 }
139 
140 bool CupsdConf::loadFromFile(const TQString& filename)
141 {
142  TQFile f(filename);
143  if (!f.exists() || !f.open(IO_ReadOnly)) return false;
144  else
145  {
146  TQTextStream t(&f);
147  TQString line;
148  bool done(false), value(true);
149  while (!done && value)
150  {
151  line = t.readLine().simplifyWhiteSpace();
152  if (line.isEmpty())
153  {
154  if (t.atEnd()) done = true;
155  else continue;
156  }
157  else if (line[0] == '#') continue;
158  else if (line.left(9).lower() == "<location")
159  {
160  CupsLocation *location = new CupsLocation();
161  locations_.append(location);
162  if (!location->parseResource(line) || !parseLocation(location, t))
163  value = false;
164  // search corresponding resource
165  for (resources_.first();resources_.current();resources_.next())
166  if (resources_.current()->path_ == location->resourcename_)
167  location->resource_ = resources_.current();
168  }
169  else value = parseOption(line);
170  }
171  f.close();
172  return value;
173  }
174 }
175 
176 bool CupsdConf::saveToFile(const TQString& filename)
177 {
178  TQFile f(filename);
179  if (!f.open(IO_WriteOnly))
180  return false;
181  else
182  {
183  TQTextStream t(&f);
184  t << comments_["header"] << endl;
185  t << "# Server" << endl << endl;
186 
187  t << comments_["servername"] << endl;
188  if ( !servername_.isEmpty() )
189  t << "ServerName " << servername_ << endl;
190 
191  t << endl << comments_["serveradmin"] << endl;
192  if ( !serveradmin_.isEmpty() )
193  t << "ServerAdmin " << serveradmin_ << endl;
194 
195  t << endl << comments_["classification"] << endl;
196  t << "Classification ";
197  switch (classification_)
198  {
199  default:
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;
207  }
208  t << endl;
209 
210  t << endl << comments_["classifyoverride"] << endl;
211  if (classification_ != CLASS_NONE) t << "ClassifyOverride " << (classoverride_ ? "Yes" : "No") << endl;
212 
213  t << endl << comments_["defaultcharset"] << endl;
214  t << "DefaultCharset " << charset_.upper() << endl;
215 
216  t << endl << comments_["defaultlanguage"] << endl;
217  t << "DefaultLanguage " << language_.lower() << endl;
218 
219  t << endl << comments_["printcap"] << endl;
220  t << "Printcap " << printcap_ << endl;
221 
222  t << endl << comments_["printcapformat"] << endl;
223  t << "PrintcapFormat " << (printcapformat_ == PRINTCAP_SOLARIS ? "Solaris" : "BSD") << endl;
224 
225  t << endl << "# Security" << endl;
226  t << endl << comments_["remoteroot"] << endl;
227  t << "RemoteRoot " << remoteroot_ << endl;
228 
229  t << endl << comments_["systemgroup"] << endl;
230  t << "SystemGroup " << systemgroup_ << endl;
231 
232  t << endl << comments_["servercertificate"] << endl;
233  t << "ServerCertificate " << encryptcert_ << endl;
234 
235  t << endl << comments_["serverkey"] << endl;
236  t << "ServerKey " << encryptkey_ << endl;
237 
238  t << endl << comments_["locations"] << endl;
239  for (locations_.first(); locations_.current(); locations_.next())
240  {
241  CupsLocation *loc = locations_.current();
242  t << "<Location " << loc->resourcename_ << ">" << endl;
243  if (loc->authtype_ != AUTHTYPE_NONE)
244  {
245  t << "AuthType ";
246  switch (loc->authtype_)
247  {
248  case AUTHTYPE_BASIC: t << "Basic"; break;
249  case AUTHTYPE_DIGEST: t << "Digest"; break;
250  }
251  t << endl;
252  }
253  if (loc->authclass_ != AUTHCLASS_ANONYMOUS)
254  {
255  switch (loc->authclass_)
256  {
257  case AUTHCLASS_USER:
258  if (!loc->authname_.isEmpty())
259  t << "Require user " << loc->authname_ << endl;
260  else
261  t << "AuthClass User" << endl;
262  break;
263  case AUTHCLASS_GROUP:
264  if (!loc->authname_.isEmpty())
265  t << "Require group " << loc->authname_ << endl;
266  else
267  t << "AuthClass Group" << endl;
268  break;
269  case AUTHCLASS_SYSTEM:
270  t << "AuthClass System" << endl;
271  break;
272  }
273  }
274  t << "Encryption ";
275  switch (loc->encryption_)
276  {
277  case ENCRYPT_ALWAYS: t << "Always"; break;
278  case ENCRYPT_NEVER: t << "Never"; break;
279  case ENCRYPT_REQUIRED: t << "Required"; break;
280  default:
281  case ENCRYPT_IFREQUESTED: t << "IfRequested"; break;
282  }
283  t << endl;
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)
287  t << *it << endl;
288  t << "</Location>" << endl;
289  }
290 
291  t << endl << "# Network" << endl;
292  t << endl << comments_["hostnamelookups"] << endl;
293  t << "HostnameLookups ";
294  switch (hostnamelookup_)
295  {
296  default:
297  case HOSTNAME_OFF: t << "Off"; break;
298  case HOSTNAME_ON: t << "On"; break;
299  case HOSTNAME_DOUBLE: t << "Double"; break;
300  }
301  t << endl;
302 
303  t << endl << comments_["keepalive"] << endl;
304  t << "KeepAlive " << (keepalive_ ? "On" : "Off") << endl;
305 
306  t << endl << comments_["keepalivetimeout"] << endl;
307  t << "KeepAliveTimeout " << keepalivetimeout_ << endl;
308 
309  t << endl << comments_["maxclients"] << endl;
310  t << "MaxClients " << maxclients_ << endl;
311 
312  t << endl << comments_["maxrequestsize"] << endl;
313  t << "MaxRequestSize " << maxrequestsize_ << endl;
314 
315  t << endl << comments_["timeout"] << endl;
316  t << "Timeout " << clienttimeout_ << endl;
317 
318  t << endl << comments_["listen"] << endl;
319  for (TQStringList::ConstIterator it=listenaddresses_.begin(); it!=listenaddresses_.end(); ++it)
320  t << *it << endl;
321 
322  t << endl << "# Log" << endl;
323  t << endl << comments_["accesslog"] << endl;
324  t << "AccessLog " << accesslog_ << endl;
325 
326  t << endl << comments_["errorlog"] << endl;
327  t << "ErrorLog " << errorlog_ << endl;
328 
329  t << endl << comments_["pagelog"] << endl;
330  t << "PageLog " << pagelog_ << endl;
331 
332  t << endl << comments_["maxlogsize"] << endl;
333  //t << "MaxLogSize " << maxlogsize_ << "m" << endl;
334  t << "MaxLogSize " << maxlogsize_ << endl;
335 
336  t << endl << comments_["loglevel"] << endl;
337  t << "LogLevel ";
338  switch (loglevel_)
339  {
340  case LOGLEVEL_NONE: t << "none"; break;
341  default:
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;
347  }
348  t << endl;
349 
350  t << endl << "# Jobs" << endl;
351  t << endl << comments_["preservejobhistory"] << endl;
352  t << "PreserveJobHistory " << (keepjobhistory_ ? "On" : "Off") << endl;
353 
354  t << endl << comments_["preservejobfiles"] << endl;
355  if (keepjobhistory_) t << "PreserveJobFiles " << (keepjobfiles_ ? "On" : "Off") << endl;
356 
357  t << endl << comments_["autopurgejobs"] << endl;
358  if (keepjobhistory_) t << "AutoPurgeJobs " << (autopurgejobs_ ? "Yes" : "No") << endl;
359 
360  t << endl << comments_["maxjobs"] << endl;
361  t << "MaxJobs " << maxjobs_ << endl;
362 
363  t << endl << comments_["maxjobsperprinter"] << endl;
364  t << "MaxJobsPerPrinter " << maxjobsperprinter_ << endl;
365 
366  t << endl << comments_["maxjobsperuser"] << endl;
367  t << "MaxJobsPerUser " << maxjobsperuser_ << endl;
368 
369  t << endl << "# Filter" << endl;
370  t << endl << comments_["user"] << endl;
371  t << "User " << user_ << endl;
372 
373  t << endl << comments_["group"] << endl;
374  t << "Group " << group_ << endl;
375 
376  t << endl << comments_["ripcache"] << endl;
377  t << "RIPCache " << ripcache_ << endl;
378 
379  t << endl << comments_["filterlimit"] << endl;
380  t << "FilterLimit " << filterlimit_ << endl;
381 
382  t << endl << "# Directories" << endl;
383  t << endl << comments_["datadir"] << endl;
384  t << "DataDir " << datadir_ << endl;
385 
386  t << endl << comments_["documentroot"] << endl;
387  t << "DocumentRoot " << documentdir_ << endl;
388 
389  t << endl << comments_["fontpath"] << endl;
390  for (TQStringList::ConstIterator it=fontpath_.begin(); it!=fontpath_.end(); ++it)
391  t << "FontPath " << *it << endl;
392 
393  t << endl << comments_["requestroot"] << endl;
394  t << "RequestRoot " << requestdir_ << endl;
395 
396  t << endl << comments_["serverbin"] << endl;
397  t << "ServerBin " << serverbin_ << endl;
398 
399  t << endl << comments_["serverroot"] << endl;
400  t << "ServerRoot " << serverfiles_ << endl;
401 
402  t << endl << comments_["tempdir"] << endl;
403  t << "TempDir " << tmpfiles_ << endl;
404 
405  t << endl << "# Browsing" << endl;
406  t << endl << comments_["browsing"] << endl;
407  t << "Browsing " << (browsing_ ? "On" : "Off") << endl;
408 
409  t << endl << comments_["browseprotocols"] << endl;
410  if (browsing_)
411  {
412  t << "BrowseProtocols ";
413  for (TQStringList::ConstIterator it=browseprotocols_.begin(); it!=browseprotocols_.end(); ++it)
414  t << (*it).upper() << " ";
415  t << endl;
416  }
417 
418  t << endl << comments_["browseport"] << endl;
419  if (browsing_) t << "BrowsePort " << browseport_ << endl;
420 
421  t << endl << comments_["browseinterval"] << endl;
422  if (browsing_) t << "BrowseInterval " << browseinterval_ << endl;
423 
424  t << endl << comments_["browsetimeout"] << endl;
425  if (browsing_) t << "BrowseTimeout " << browsetimeout_ << endl;
426 
427  t << endl << comments_["browseaddress"] << endl;
428  if (browsing_)
429  for (TQStringList::ConstIterator it=browseaddresses_.begin(); it!=browseaddresses_.end(); ++it)
430  if ((*it).startsWith("Send"))
431  t << "BrowseAddress " << (*it).mid(5) << endl;
432  else
433  t << "Browse" << (*it) << endl;
434 
435  t << endl << comments_["browseorder"] << endl;
436  if (browsing_) t << "BrowseOrder " << (browseorder_ == ORDER_ALLOW_DENY ? "allow,deny" : "deny,allow") << endl;
437 
438  t << endl << comments_["implicitclasses"] << endl;
439  if (browsing_) t << "ImplicitClasses " << (useimplicitclasses_ ? "On" : "Off") << endl;
440 
441  t << endl << comments_["implicitanyclasses"] << endl;
442  if (browsing_) t << "ImplicitAnyClasses " << (useanyclasses_ ? "On" : "Off") << endl;
443 
444  t << endl << comments_["hideimplicitmembers"] << endl;
445  if (browsing_) t << "HideImplicitMembers " << (hideimplicitmembers_ ? "Yes" : "No") << endl;
446 
447  t << endl << comments_["browseshortnames"] << endl;
448  if (browsing_) t << "BrowseShortNames " << (useshortnames_ ? "Yes" : "No") << endl;
449 
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;
453 
454  return true;
455  }
456 }
457 
458 bool CupsdConf::parseLocation(CupsLocation *location, TQTextStream& file)
459 {
460  TQString line;
461  bool done(false);
462  bool value(true);
463  while (!done && value)
464  {
465  line = file.readLine().simplifyWhiteSpace();
466  if (line.isEmpty())
467  {
468  if (file.atEnd())
469  {
470  value = false;
471  done = true;
472  }
473  else continue;
474  }
475  else if (line[0] == '#') continue;
476  else if (line.lower() == "</location>") done = true;
477  else value = location->parseOption(line);
478  }
479  return value;
480 }
481 
482 bool CupsdConf::parseOption(const TQString& line)
483 {
484  int p(-1);
485  TQString keyword, value, l(line.simplifyWhiteSpace());
486 
487  if ((p=l.find(' ')) != -1)
488  {
489  keyword = l.left(p).lower();
490  value = l.mid(p+1);
491  }
492  else
493  {
494  keyword = l.lower();
495  }
496 
497  //kdDebug() << "cupsd.conf keyword=" << keyword << endl;
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")
508  {
509  browseprotocols_.clear();
510  TQStringList prots = TQStringList::split(TQRegExp("\\s"), value, false);
511  if (prots.find("all") != prots.end())
512  browseprotocols_ << "CUPS" << "SLP";
513  else
514  for (TQStringList::ConstIterator it=prots.begin(); it!=prots.end(); ++it)
515  browseprotocols_ << (*it).upper();
516  }
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")
522  {
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;
530  else
531  {
532  classification_ = CLASS_OTHER;
533  otherclassname_ = cl;
534  }
535  }
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")
547  {
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;
552  }
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")
559  {
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;
567  }
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;
574  /*{
575  // FIXME: support for suffixes
576  int suffix;
577  splitSizeSpec( value, maxlogsize_, suffix );
578  }*/
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;
600  else
601  {
602  // unrecognized option
603  unknown_ << TQPair<TQString,TQString>(keyword, value);
604  }
605  return true;
606 }
607 
608 bool CupsdConf::loadAvailableResources()
609 {
610  TDEConfig conf("tdeprintrc");
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);
615 
616  resources_.clear();
617  // standard resources
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"));
623 
624  if (!http_)
625  return false;
626 
627  // printer resources
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);
632 #ifdef HAVE_CUPS_1_6
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/");
638  if (request_)
639  {
640  TQString name;
641  int type(0);
642 #ifdef HAVE_CUPS_1_6
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
647  while (attr)
648  {
649  // check new printer (keep only local non-implicit printers)
650 #ifdef HAVE_CUPS_1_6
651  if (!ippGetName(attr))
652 #else // HAVE_CUPS_1_6
653  if (!attr->name)
654 #endif // HAVE_CUPS_1_6
655  {
656  if (!(type & CUPS_PRINTER_REMOTE) && !(type & CUPS_PRINTER_IMPLICIT) && !name.isEmpty())
657  resources_.append(new CupsResource("/printers/"+name));
658  name = "";
659  type = 0;
660  }
661 #ifdef HAVE_CUPS_1_6
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;
668  attr = attr->next;
669 #endif // HAVE_CUPS_1_6
670  }
671  if (!(type & CUPS_PRINTER_REMOTE) && !(type & CUPS_PRINTER_IMPLICIT) && !name.isEmpty())
672  resources_.append(new CupsResource("/printers/"+name));
673  ippDelete(request_);
674  }
675  // class resources
676  request_ = ippNew();
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);
679 #ifdef HAVE_CUPS_1_6
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/");
685  if (request_)
686  {
687  TQString name;
688  int type(0);
689 #ifdef HAVE_CUPS_1_6
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
694  while (attr)
695  {
696  // check new class (keep only local classes)
697 #ifdef HAVE_CUPS_1_6
698  if (!ippGetName(attr))
699 #else // HAVE_CUPS_1_6
700  if (!attr->name)
701 #endif // HAVE_CUPS_1_6
702  {
703  if (!(type & CUPS_PRINTER_REMOTE) && !name.isEmpty())
704  resources_.append(new CupsResource("/classes/"+name));
705  name = "";
706  type = 0;
707  }
708 #ifdef HAVE_CUPS_1_6
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;
715  attr = attr->next;
716 #endif // HAVE_CUPS_1_6
717  }
718  if (!(type & CUPS_PRINTER_REMOTE) && !name.isEmpty())
719  resources_.append(new CupsResource("/classes/"+name));
720  ippDelete(request_);
721  }
722  httpClose(http_);
723  return true;
724 }
725 
726 //------------------------------------------------------------------------------------------------
727 
728 CupsLocation::CupsLocation()
729 {
730  resource_ = 0;
731  resourcename_ = "";
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;
738  // addresses_
739 }
740 
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_),
749  order_(loc.order_),
750  addresses_(loc.addresses_)
751 {
752 }
753 
754 bool CupsLocation::parseResource(const TQString& line)
755 {
756  TQString str = line.simplifyWhiteSpace();
757  int p1 = line.find(' '), p2 = line.find('>');
758  if (p1 != -1 && p2 != -1)
759  {
760  resourcename_ = str.mid(p1+1,p2-p1-1);
761  return true;
762  }
763  else return false;
764 }
765 
766 bool CupsLocation::parseOption(const TQString& line)
767 {
768  int p(-1);
769  TQString keyword, value, l(line.simplifyWhiteSpace());
770 
771  if ((p=l.find(' ')) != -1)
772  {
773  keyword = l.left(p).lower();
774  value = l.mid(p+1);
775  }
776  else
777  {
778  keyword = l.lower();
779  }
780 
781  if (keyword == "authtype")
782  {
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;
787  }
788  else if (keyword == "authclass")
789  {
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;
795  }
796  else if (keyword == "authgroupname") authname_ = value;
797  else if (keyword == "require")
798  {
799  int p = value.find(' ');
800  if (p != -1)
801  {
802  authname_ = value.mid(p+1);
803  TQString cl = value.left(p).lower();
804  if (cl == "user")
805  authclass_ = AUTHCLASS_USER;
806  else if (cl == "group")
807  authclass_ = AUTHCLASS_GROUP;
808  }
809  }
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")
814  {
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;
820  }
821  else if (keyword == "satisfy") satisfy_ = (value.lower() == "any" ? SATISFY_ANY : SATISFY_ALL);
822  else return false;
823  return true;
824 }
825 
826 //------------------------------------------------------------------------------------------------
827 
828 CupsResource::CupsResource()
829 {
830  type_ = RESOURCE_GLOBAL;
831 }
832 
833 CupsResource::CupsResource(const TQString& path)
834 {
835  setPath(path);
836 }
837 
838 void CupsResource::setPath(const TQString& path)
839 {
840  path_ = path;
841  type_ = typeFromPath(path_);
842  text_ = pathToText(path_);
843 }
844 
845 int CupsResource::typeFromText(const TQString& text)
846 {
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;
852 }
853 
854 int CupsResource::typeFromPath(const TQString& path)
855 {
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;
861 }
862 
863 TQString CupsResource::textToPath(const TQString& text)
864 {
865  TQString path("/");
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)
872  {
873  path = "/printers/";
874  path.append(text.right(text.length()-i18n("Printer").length()-1));
875  }
876  else if (text.find(i18n("Class")) == 0)
877  {
878  path = "/classes/";
879  path.append(text.right(text.length()-i18n("Class").length()-1));
880  }
881  return path;
882 }
883 
884 TQString CupsResource::pathToText(const TQString& path)
885 {
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)
893  {
894  text = i18n("Printer");
895  text.append(" ");
896  text.append(path.right(path.length()-10));
897  }
898  else if (path.find("/classes/") == 0)
899  {
900  text = i18n("Class");
901  text.append(" ");
902  text.append(path.right(path.length()-9));
903  }
904  return text;
905 }
906 
907 TQString CupsResource::typeToIconName(int type)
908 {
909  switch (type)
910  {
911  case RESOURCE_ADMIN:
912  case RESOURCE_GLOBAL:
913  return TQString("folder");
914  case RESOURCE_PRINTER:
915  return TQString("tdeprint_printer");
916  case RESOURCE_CLASS:
917  return TQString("tdeprint_printer_class");
918  }
919  return TQString("folder");
920 }

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