00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include "cupsdconf.h"
00021
00022
#include <qfile.h>
00023
#include <qregexp.h>
00024
#include <klocale.h>
00025
#include <kdebug.h>
00026
#include <kconfig.h>
00027
00028
#include <stdlib.h>
00029
#include <cups/cups.h>
00030
#include <cups/ipp.h>
00031
#include <cups/language.h>
00032
00033
QString findDir(
const QStringList& list)
00034 {
00035
for (QStringList::ConstIterator it=list.begin(); it!=list.end(); ++it)
00036
if (QFile::exists(*it))
00037
return *it;
00038
00039
return list[0];
00040 }
00041
00042
void splitSizeSpec(
const QString& s,
int& sz,
int& suff)
00043 {
00044
int p = s.find(
QRegExp(
"\\D"));
00045 sz = s.mid(0, p).toInt();
00046
if (p != -1)
00047 {
00048
switch (s[p].latin1())
00049 {
00050
case 'k': suff = UNIT_KB;
break;
00051
default:
00052
case 'm': suff = UNIT_MB;
break;
00053
case 'g': suff = UNIT_GB;
break;
00054
case 't': suff = UNIT_TILE;
break;
00055 }
00056 }
00057
else
00058 suff = UNIT_MB;
00059 }
00060
00061 CupsdConf::CupsdConf()
00062 {
00063
00064 datadir_ = findDir(
QStringList(
"/usr/share/cups")
00065 <<
"/usr/local/share/cups"
00066 <<
"/opt/share/cups"
00067 <<
"/opt/local/share/cups");
00068 documentdir_ = findDir(
QStringList(datadir_+
"/doc")
00069 << datadir_.left(datadir_.length()-5)+
"/doc/cups");
00070
00071 requestdir_ = findDir(
QStringList(
"/var/spool/cups")
00072 <<
"/var/cups");
00073 serverbin_ = findDir(
QStringList(
"/usr/lib/cups")
00074 <<
"/usr/local/lib/cups"
00075 <<
"/opt/lib/cups"
00076 <<
"/opt/local/lib/cups");
00077 serverfiles_ = findDir(
QStringList(
"/etc/cups")
00078 <<
"/usr/local/etc/cups");
00079 tmpfiles_ = requestdir_+
"/tmp";
00080
00081
00082 servername_ = QString::null;
00083 serveradmin_ = QString::null;
00084 classification_ = CLASS_NONE;
00085 otherclassname_ = QString::null;
00086 classoverride_ =
false;
00087 charset_ =
"utf-8";
00088 language_ =
"en";
00089 printcap_ =
"/etc/printcap";
00090 printcapformat_ = PRINTCAP_BSD;
00091 remoteroot_ =
"remroot";
00092 systemgroup_ =
"sys";
00093 encryptcert_ = serverfiles_+
"/ssl/server.crt";
00094 encryptkey_ = serverfiles_+
"/ssl/server.key";
00095 hostnamelookup_ = HOSTNAME_OFF;
00096 keepalive_ =
true;
00097 keepalivetimeout_ = 60;
00098 maxclients_ = 100;
00099 maxrequestsize_ =
"0";
00100 clienttimeout_ = 300;
00101
00102
QString logdir = findDir(
QStringList(
"/var/log/cups")
00103 <<
"/var/spool/cups/log"
00104 <<
"/var/cups/log");
00105 accesslog_ = logdir+
"/access_log";
00106 errorlog_ = logdir+
"/error_log";
00107 pagelog_ = logdir+
"/page_log";
00108 maxlogsize_ =
"1m";
00109 loglevel_ = LOGLEVEL_INFO;
00110 keepjobhistory_ =
true;
00111 keepjobfiles_ =
false;
00112 autopurgejobs_ =
false;
00113 maxjobs_ = 0;
00114 maxjobsperprinter_ = 0;
00115 maxjobsperuser_ = 0;
00116 user_ =
"lp";
00117 group_ =
"sys";
00118 ripcache_ =
"8m";
00119 filterlimit_ = 0;
00120 browsing_ =
true;
00121 browseprotocols_ <<
"CUPS";
00122 browseport_ = ippPort();
00123 browseinterval_ = 30;
00124 browsetimeout_ = 300;
00125
00126 browseorder_ = ORDER_ALLOW_DENY;
00127 useimplicitclasses_ =
true;
00128 hideimplicitmembers_ =
true;
00129 useshortnames_ =
true;
00130 useanyclasses_ =
false;
00131
00132 loadAvailableResources();
00133 }
00134
00135 CupsdConf::~CupsdConf()
00136 {
00137 }
00138
00139
bool CupsdConf::loadFromFile(
const QString& filename)
00140 {
00141
QFile f(filename);
00142
if (!f.exists() || !f.open(IO_ReadOnly))
return false;
00143
else
00144 {
00145
QTextStream t(&f);
00146
QString line;
00147
bool done(
false), value(
true);
00148
while (!done && value)
00149 {
00150 line = t.readLine().simplifyWhiteSpace();
00151
if (line.isEmpty())
00152 {
00153
if (t.atEnd()) done =
true;
00154
else continue;
00155 }
00156
else if (line[0] ==
'#')
continue;
00157
else if (line.left(9).lower() ==
"<location")
00158 {
00159 CupsLocation *location =
new CupsLocation();
00160 locations_.append(location);
00161
if (!location->parseResource(line) || !parseLocation(location, t))
00162 value =
false;
00163
00164
for (resources_.first();resources_.current();resources_.next())
00165
if (resources_.current()->path_ == location->resourcename_)
00166 location->resource_ = resources_.current();
00167 }
00168
else value = parseOption(line);
00169 }
00170 f.close();
00171
return value;
00172 }
00173 }
00174
00175
bool CupsdConf::saveToFile(
const QString& filename)
00176 {
00177
QFile f(filename);
00178
if (!f.open(IO_WriteOnly))
00179
return false;
00180
else
00181 {
00182
QTextStream t(&f);
00183 t << comments_[
"header"] << endl;
00184 t <<
"# Server" << endl << endl;
00185
00186 t << comments_[
"servername"] << endl;
00187
if ( !servername_.isEmpty() )
00188 t <<
"ServerName " << servername_ << endl;
00189
00190 t << endl << comments_[
"serveradmin"] << endl;
00191
if ( !serveradmin_.isEmpty() )
00192 t <<
"ServerAdmin " << serveradmin_ << endl;
00193
00194 t << endl << comments_[
"classification"] << endl;
00195 t <<
"Classification ";
00196
switch (classification_)
00197 {
00198
default:
00199
case CLASS_NONE: t <<
"none";
break;
00200
case CLASS_CLASSIFIED: t <<
"classified";
break;
00201
case CLASS_CONFIDENTIAL: t <<
"confidential";
break;
00202
case CLASS_SECRET: t <<
"secret";
break;
00203
case CLASS_TOPSECRET: t <<
"topsecret";
break;
00204
case CLASS_UNCLASSIFIED: t <<
"unclassified";
break;
00205
case CLASS_OTHER: t << otherclassname_;
break;
00206 }
00207 t << endl;
00208
00209 t << endl << comments_[
"classifyoverride"] << endl;
00210
if (classification_ != CLASS_NONE) t <<
"ClassifyOverride " << (classoverride_ ?
"Yes" :
"No") << endl;
00211
00212 t << endl << comments_[
"defaultcharset"] << endl;
00213 t <<
"DefaultCharset " << charset_.upper() << endl;
00214
00215 t << endl << comments_[
"defaultlanguage"] << endl;
00216 t <<
"DefaultLanguage " << language_.lower() << endl;
00217
00218 t << endl << comments_[
"printcap"] << endl;
00219 t <<
"Printcap " << printcap_ << endl;
00220
00221 t << endl << comments_[
"printcapformat"] << endl;
00222 t <<
"PrintcapFormat " << (printcapformat_ == PRINTCAP_SOLARIS ?
"Solaris" :
"BSD") << endl;
00223
00224 t << endl <<
"# Security" << endl;
00225 t << endl << comments_[
"remoteroot"] << endl;
00226 t <<
"RemoteRoot " << remoteroot_ << endl;
00227
00228 t << endl << comments_[
"systemgroup"] << endl;
00229 t <<
"SystemGroup " << systemgroup_ << endl;
00230
00231 t << endl << comments_[
"servercertificate"] << endl;
00232 t <<
"ServerCertificate " << encryptcert_ << endl;
00233
00234 t << endl << comments_[
"serverkey"] << endl;
00235 t <<
"ServerKey " << encryptkey_ << endl;
00236
00237 t << endl << comments_[
"locations"] << endl;
00238
for (locations_.first(); locations_.current(); locations_.next())
00239 {
00240 CupsLocation *loc = locations_.current();
00241 t <<
"<Location " << loc->resourcename_ <<
">" << endl;
00242
if (loc->authtype_ != AUTHTYPE_NONE)
00243 {
00244 t <<
"AuthType ";
00245
switch (loc->authtype_)
00246 {
00247
case AUTHTYPE_BASIC: t <<
"Basic";
break;
00248
case AUTHTYPE_DIGEST: t <<
"Digest";
break;
00249 }
00250 t << endl;
00251 }
00252
if (loc->authclass_ != AUTHCLASS_ANONYMOUS)
00253 {
00254
switch (loc->authclass_)
00255 {
00256
case AUTHCLASS_USER:
00257
if (!loc->authname_.isEmpty())
00258 t <<
"Require user " << loc->authname_ << endl;
00259
else
00260 t <<
"AuthClass User" << endl;
00261
break;
00262
case AUTHCLASS_GROUP:
00263
if (!loc->authname_.isEmpty())
00264 t <<
"Require group " << loc->authname_ << endl;
00265
else
00266 t <<
"AuthClass Group" << endl;
00267
break;
00268
case AUTHCLASS_SYSTEM:
00269 t <<
"AuthClass System" << endl;
00270
break;
00271 }
00272 }
00273 t <<
"Encryption ";
00274
switch (loc->encryption_)
00275 {
00276
case ENCRYPT_ALWAYS: t <<
"Always";
break;
00277
case ENCRYPT_NEVER: t <<
"Never";
break;
00278
case ENCRYPT_REQUIRED: t <<
"Required";
break;
00279
default:
00280
case ENCRYPT_IFREQUESTED: t <<
"IfRequested";
break;
00281 }
00282 t << endl;
00283 t <<
"Satisfy " << (loc->satisfy_ == SATISFY_ALL ?
"All" :
"Any") << endl;
00284 t <<
"Order " << (loc->order_ == ORDER_ALLOW_DENY ?
"allow,deny" :
"deny,allow") << endl;
00285
for (QStringList::ConstIterator it=loc->addresses_.begin(); it!=loc->addresses_.end(); ++it)
00286 t << *it << endl;
00287 t <<
"</Location>" << endl;
00288 }
00289
00290 t << endl <<
"# Network" << endl;
00291 t << endl << comments_[
"hostnamelookups"] << endl;
00292 t <<
"HostnameLookups ";
00293
switch (hostnamelookup_)
00294 {
00295
default:
00296
case HOSTNAME_OFF: t <<
"Off";
break;
00297
case HOSTNAME_ON: t <<
"On";
break;
00298
case HOSTNAME_DOUBLE: t <<
"Double";
break;
00299 }
00300 t << endl;
00301
00302 t << endl << comments_[
"keepalive"] << endl;
00303 t <<
"KeepAlive " << (keepalive_ ?
"On" :
"Off") << endl;
00304
00305 t << endl << comments_[
"keepalivetimeout"] << endl;
00306 t <<
"KeepAliveTimeout " << keepalivetimeout_ << endl;
00307
00308 t << endl << comments_[
"maxclients"] << endl;
00309 t <<
"MaxClients " << maxclients_ << endl;
00310
00311 t << endl << comments_[
"maxrequestsize"] << endl;
00312 t <<
"MaxRequestSize " << maxrequestsize_ << endl;
00313
00314 t << endl << comments_[
"timeout"] << endl;
00315 t <<
"Timeout " << clienttimeout_ << endl;
00316
00317 t << endl << comments_[
"listen"] << endl;
00318
for (QStringList::ConstIterator it=listenaddresses_.begin(); it!=listenaddresses_.end(); ++it)
00319 t << *it << endl;
00320
00321 t << endl <<
"# Log" << endl;
00322 t << endl << comments_[
"accesslog"] << endl;
00323 t <<
"AccessLog " << accesslog_ << endl;
00324
00325 t << endl << comments_[
"errorlog"] << endl;
00326 t <<
"ErrorLog " << errorlog_ << endl;
00327
00328 t << endl << comments_[
"pagelog"] << endl;
00329 t <<
"PageLog " << pagelog_ << endl;
00330
00331 t << endl << comments_[
"maxlogsize"] << endl;
00332
00333 t <<
"MaxLogSize " << maxlogsize_ << endl;
00334
00335 t << endl << comments_[
"loglevel"] << endl;
00336 t <<
"LogLevel ";
00337
switch (loglevel_)
00338 {
00339
case LOGLEVEL_NONE: t <<
"none";
break;
00340
default:
00341
case LOGLEVEL_INFO: t <<
"info";
break;
00342
case LOGLEVEL_ERROR: t <<
"error";
break;
00343
case LOGLEVEL_WARN: t <<
"warn";
break;
00344
case LOGLEVEL_DEBUG: t <<
"debug";
break;
00345
case LOGLEVEL_DEBUG2: t <<
"debug2";
break;
00346 }
00347 t << endl;
00348
00349 t << endl <<
"# Jobs" << endl;
00350 t << endl << comments_[
"preservejobhistory"] << endl;
00351 t <<
"PreserveJobHistory " << (keepjobhistory_ ?
"On" :
"Off") << endl;
00352
00353 t << endl << comments_[
"preservejobfiles"] << endl;
00354
if (keepjobhistory_) t <<
"PreserveJobFiles " << (keepjobfiles_ ?
"On" :
"Off") << endl;
00355
00356 t << endl << comments_[
"autopurgejobs"] << endl;
00357
if (keepjobhistory_) t <<
"AutoPurgeJobs " << (autopurgejobs_ ?
"Yes" :
"No") << endl;
00358
00359 t << endl << comments_[
"maxjobs"] << endl;
00360 t <<
"MaxJobs " << maxjobs_ << endl;
00361
00362 t << endl << comments_[
"maxjobsperprinter"] << endl;
00363 t <<
"MaxJobsPerPrinter " << maxjobsperprinter_ << endl;
00364
00365 t << endl << comments_[
"maxjobsperuser"] << endl;
00366 t <<
"MaxJobsPerUser " << maxjobsperuser_ << endl;
00367
00368 t << endl <<
"# Filter" << endl;
00369 t << endl << comments_[
"user"] << endl;
00370 t <<
"User " << user_ << endl;
00371
00372 t << endl << comments_[
"group"] << endl;
00373 t <<
"Group " << group_ << endl;
00374
00375 t << endl << comments_[
"ripcache"] << endl;
00376 t <<
"RIPCache " << ripcache_ << endl;
00377
00378 t << endl << comments_[
"filterlimit"] << endl;
00379 t <<
"FilterLimit " << filterlimit_ << endl;
00380
00381 t << endl <<
"# Directories" << endl;
00382 t << endl << comments_[
"datadir"] << endl;
00383 t <<
"DataDir " << datadir_ << endl;
00384
00385 t << endl << comments_[
"documentroot"] << endl;
00386 t <<
"DocumentRoot " << documentdir_ << endl;
00387
00388 t << endl << comments_[
"fontpath"] << endl;
00389
for (QStringList::ConstIterator it=fontpath_.begin(); it!=fontpath_.end(); ++it)
00390 t <<
"FontPath " << *it << endl;
00391
00392 t << endl << comments_[
"requestroot"] << endl;
00393 t <<
"RequestRoot " << requestdir_ << endl;
00394
00395 t << endl << comments_[
"serverbin"] << endl;
00396 t <<
"ServerBin " << serverbin_ << endl;
00397
00398 t << endl << comments_[
"serverroot"] << endl;
00399 t <<
"ServerRoot " << serverfiles_ << endl;
00400
00401 t << endl << comments_[
"tempdir"] << endl;
00402 t <<
"TempDir " << tmpfiles_ << endl;
00403
00404 t << endl <<
"# Browsing" << endl;
00405 t << endl << comments_[
"browsing"] << endl;
00406 t <<
"Browsing " << (browsing_ ?
"On" :
"Off") << endl;
00407
00408 t << endl << comments_[
"browseprotocols"] << endl;
00409
if (browsing_)
00410 {
00411 t <<
"BrowseProtocols ";
00412
for (QStringList::ConstIterator it=browseprotocols_.begin(); it!=browseprotocols_.end(); ++it)
00413 t << (*it).upper() <<
" ";
00414 t << endl;
00415 }
00416
00417 t << endl << comments_[
"browseport"] << endl;
00418
if (browsing_) t <<
"BrowsePort " << browseport_ << endl;
00419
00420 t << endl << comments_[
"browseinterval"] << endl;
00421
if (browsing_) t <<
"BrowseInterval " << browseinterval_ << endl;
00422
00423 t << endl << comments_[
"browsetimeout"] << endl;
00424
if (browsing_) t <<
"BrowseTimeout " << browsetimeout_ << endl;
00425
00426 t << endl << comments_[
"browseaddress"] << endl;
00427
if (browsing_)
00428
for (QStringList::ConstIterator it=browseaddresses_.begin(); it!=browseaddresses_.end(); ++it)
00429
if ((*it).startsWith(
"Send"))
00430 t <<
"BrowseAddress " << (*it).mid(5) << endl;
00431
else
00432 t <<
"Browse" << (*it) << endl;
00433
00434 t << endl << comments_[
"browseorder"] << endl;
00435
if (browsing_) t <<
"BrowseOrder " << (browseorder_ == ORDER_ALLOW_DENY ?
"allow,deny" :
"deny,allow") << endl;
00436
00437 t << endl << comments_[
"implicitclasses"] << endl;
00438
if (browsing_) t <<
"ImplicitClasses " << (useimplicitclasses_ ?
"On" :
"Off") << endl;
00439
00440 t << endl << comments_[
"implicitanyclasses"] << endl;
00441
if (browsing_) t <<
"ImplicitAnyClasses " << (useanyclasses_ ?
"On" :
"Off") << endl;
00442
00443 t << endl << comments_[
"hideimplicitmembers"] << endl;
00444
if (browsing_) t <<
"HideImplicitMembers " << (hideimplicitmembers_ ?
"Yes" :
"No") << endl;
00445
00446 t << endl << comments_[
"browseshortnames"] << endl;
00447
if (browsing_) t <<
"BrowseShortNames " << (useshortnames_ ?
"Yes" :
"No") << endl;
00448
00449 t << endl <<
"# Unknown" << endl;
00450
for (
QValueList< QPair<QString,QString> >::ConstIterator it=unknown_.begin(); it!=unknown_.end(); ++it)
00451 t << (*it).first <<
" " << (*it).second << endl;
00452
00453
return true;
00454 }
00455 }
00456
00457
bool CupsdConf::parseLocation(CupsLocation *location,
QTextStream& file)
00458 {
00459
QString line;
00460
bool done(
false);
00461
bool value(
true);
00462
while (!done && value)
00463 {
00464 line = file.readLine().simplifyWhiteSpace();
00465
if (line.isEmpty())
00466 {
00467
if (file.atEnd())
00468 {
00469 value =
false;
00470 done =
true;
00471 }
00472
else continue;
00473 }
00474
else if (line[0] ==
'#')
continue;
00475
else if (line.lower() ==
"</location>") done =
true;
00476
else value = location->parseOption(line);
00477 }
00478
return value;
00479 }
00480
00481
bool CupsdConf::parseOption(
const QString& line)
00482 {
00483
int p(-1);
00484
QString keyword, value, l(line.simplifyWhiteSpace());
00485
00486
if ((p=l.find(
' ')) != -1)
00487 {
00488 keyword = l.left(p).lower();
00489 value = l.mid(p+1);
00490 }
00491
else
00492 {
00493 keyword = l.lower();
00494 }
00495
00496
00497
if (keyword ==
"accesslog") accesslog_ = value;
00498
else if (keyword ==
"autopurgejobs") autopurgejobs_ = (value.lower() ==
"yes");
00499
else if (keyword ==
"browseaddress") browseaddresses_.append(
"Send "+value);
00500
else if (keyword ==
"browseallow") browseaddresses_.append(
"Allow "+value);
00501
else if (keyword ==
"browsedeny") browseaddresses_.append(
"Deny "+value);
00502
else if (keyword ==
"browseinterval") browseinterval_ = value.toInt();
00503
else if (keyword ==
"browseorder") browseorder_ = (value.lower() ==
"deny,allow" ? ORDER_DENY_ALLOW : ORDER_ALLOW_DENY);
00504
else if (keyword ==
"browsepoll") browseaddresses_.append(
"Poll "+value);
00505
else if (keyword ==
"browseport") browseport_ = value.toInt();
00506
else if (keyword ==
"browseprotocols")
00507 {
00508 browseprotocols_.clear();
00509
QStringList prots = QStringList::split(
QRegExp(
"\\s"), value,
false);
00510
if (prots.find(
"all") != prots.end())
00511 browseprotocols_ <<
"CUPS" <<
"SLP";
00512
else
00513
for (QStringList::ConstIterator it=prots.begin(); it!=prots.end(); ++it)
00514 browseprotocols_ << (*it).upper();
00515 }
00516
else if (keyword ==
"browserelay") browseaddresses_.append(
"Relay "+value);
00517
else if (keyword ==
"browseshortnames") useshortnames_ = (value.lower() !=
"no");
00518
else if (keyword ==
"browsetimeout") browsetimeout_ = value.toInt();
00519
else if (keyword ==
"browsing") browsing_ = (value.lower() !=
"off");
00520
else if (keyword ==
"classification")
00521 {
00522
QString cl = value.lower();
00523
if (cl ==
"none") classification_ = CLASS_NONE;
00524
else if (cl ==
"classified") classification_ = CLASS_CLASSIFIED;
00525
else if (cl ==
"confidential") classification_ = CLASS_CONFIDENTIAL;
00526
else if (cl ==
"secret") classification_ = CLASS_SECRET;
00527
else if (cl ==
"topsecret") classification_ = CLASS_TOPSECRET;
00528
else if (cl ==
"unclassified") classification_ = CLASS_UNCLASSIFIED;
00529
else
00530 {
00531 classification_ = CLASS_OTHER;
00532 otherclassname_ = cl;
00533 }
00534 }
00535
else if (keyword ==
"classifyoverride") classoverride_ = (value.lower() ==
"yes");
00536
else if (keyword ==
"datadir") datadir_ = value;
00537
else if (keyword ==
"defaultcharset") charset_ = value;
00538
else if (keyword ==
"defaultlanguage") language_ = value;
00539
else if (keyword ==
"documentroot") documentdir_ = value;
00540
else if (keyword ==
"errorlog") errorlog_ = value;
00541
else if (keyword ==
"filterlimit") filterlimit_ = value.toInt();
00542
else if (keyword ==
"fontpath") fontpath_ += QStringList::split(
':', value,
false);
00543
else if (keyword ==
"group") group_ = value;
00544
else if (keyword ==
"hideimplicitmembers") hideimplicitmembers_ = (value.lower() !=
"no");
00545
else if (keyword ==
"hostnamelookups")
00546 {
00547
QString h = value.lower();
00548
if (h ==
"on") hostnamelookup_ = HOSTNAME_ON;
00549
else if (h ==
"double") hostnamelookup_ = HOSTNAME_DOUBLE;
00550
else hostnamelookup_ = HOSTNAME_OFF;
00551 }
00552
else if (keyword ==
"implicitclasses") useimplicitclasses_ = (value.lower() !=
"off");
00553
else if (keyword ==
"implicitanyclasses") useanyclasses_ = (value.lower() ==
"on");
00554
else if (keyword ==
"keepalive") keepalive_ = (value.lower() !=
"off");
00555
else if (keyword ==
"keepalivetimeout") keepalivetimeout_ = value.toInt();
00556
else if (keyword ==
"listen") listenaddresses_.append(
"Listen "+value);
00557
else if (keyword ==
"loglevel")
00558 {
00559
QString ll = value.lower();
00560
if (ll ==
"none") loglevel_ = LOGLEVEL_NONE;
00561
else if (ll ==
"error") loglevel_ = LOGLEVEL_ERROR;
00562
else if (ll ==
"warn") loglevel_ = LOGLEVEL_WARN;
00563
else if (ll ==
"info") loglevel_ = LOGLEVEL_INFO;
00564
else if (ll ==
"debug") loglevel_ = LOGLEVEL_DEBUG;
00565
else if (ll ==
"debug2") loglevel_ = LOGLEVEL_DEBUG2;
00566 }
00567
else if (keyword ==
"maxclients") maxclients_ = value.toInt();
00568
else if (keyword ==
"maxjobs") maxjobs_ = value.toInt();
00569
else if (keyword ==
"maxjobsperprinter") maxjobsperprinter_ = value.toInt();
00570
else if (keyword ==
"maxjobsperuser") maxjobsperuser_ = value.toInt();
00571
else if (keyword ==
"maxrequestsize") maxrequestsize_ = value;
00572
else if (keyword ==
"maxlogsize") maxlogsize_ = value;
00573
00574
00575
00576
00577
00578
else if (keyword ==
"pagelog") pagelog_ = value;
00579
else if (keyword ==
"port") listenaddresses_.append(
"Listen *:"+value);
00580
else if (keyword ==
"preservejobhistory") keepjobhistory_ = (value !=
"off");
00581
else if (keyword ==
"preservejobfiles") keepjobfiles_ = (value ==
"on");
00582
else if (keyword ==
"printcap") printcap_ = value;
00583
else if (keyword ==
"printcapformat") printcapformat_ = (value.lower() ==
"solaris" ? PRINTCAP_SOLARIS : PRINTCAP_BSD);
00584
else if (keyword ==
"requestroot") requestdir_ = value;
00585
else if (keyword ==
"remoteroot") remoteroot_ = value;
00586
else if (keyword ==
"ripcache") ripcache_ = value;
00587
else if (keyword ==
"serveradmin") serveradmin_ = value;
00588
else if (keyword ==
"serverbin") serverbin_ = value;
00589
else if (keyword ==
"servercertificate") encryptcert_ = value;
00590
else if (keyword ==
"serverkey") encryptkey_ = value;
00591
else if (keyword ==
"servername") servername_ = value;
00592
else if (keyword ==
"serverroot") serverfiles_ = value;
00593
else if (keyword ==
"ssllisten") listenaddresses_.append(
"SSLListen "+value);
00594
else if (keyword ==
"sslport") listenaddresses_.append(
"SSLListen *:"+value);
00595
else if (keyword ==
"systemgroup") systemgroup_ = value;
00596
else if (keyword ==
"tempdir") tmpfiles_ = value;
00597
else if (keyword ==
"timeout") clienttimeout_ = value.toInt();
00598
else if (keyword ==
"user") user_ = value;
00599
else
00600 {
00601
00602 unknown_ << QPair<QString,QString>(keyword, value);
00603 }
00604
return true;
00605 }
00606
00607
bool CupsdConf::loadAvailableResources()
00608 {
00609 KConfig conf(
"kdeprintrc");
00610 conf.setGroup(
"CUPS");
00611
QString host = conf.readEntry(
"Host",cupsServer());
00612
int port = conf.readNumEntry(
"Port",ippPort());
00613 http_t *http_ = httpConnect(host.local8Bit(),port);
00614
00615 resources_.clear();
00616
00617 resources_.append(
new CupsResource(
"/"));
00618 resources_.append(
new CupsResource(
"/admin"));
00619 resources_.append(
new CupsResource(
"/printers"));
00620 resources_.append(
new CupsResource(
"/classes"));
00621 resources_.append(
new CupsResource(
"/jobs"));
00622
00623
if (!http_)
00624
return false;
00625
00626
00627 ipp_t *request_ = ippNew();
00628 cups_lang_t* lang = cupsLangDefault();
00629 ippAddString(request_, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
"attributes-charset", NULL, cupsLangEncoding(lang));
00630 ippAddString(request_, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
"attributes-natural-language", NULL, lang->language);
00631 request_->request.op.operation_id = CUPS_GET_PRINTERS;
00632 request_ = cupsDoRequest(http_, request_,
"/printers/");
00633
if (request_)
00634 {
00635
QString name;
00636
int type(0);
00637 ipp_attribute_t *attr = request_->attrs;
00638
while (attr)
00639 {
00640
00641
if (!attr->name)
00642 {
00643
if (!(type & CUPS_PRINTER_REMOTE) && !(type & CUPS_PRINTER_IMPLICIT) && !name.isEmpty())
00644 resources_.append(
new CupsResource(
"/printers/"+name));
00645 name =
"";
00646 type = 0;
00647 }
00648
else if (strcmp(attr->name,
"printer-name") == 0) name = attr->values[0].string.text;
00649
else if (strcmp(attr->name,
"printer-type") == 0) type = attr->values[0].integer;
00650 attr = attr->next;
00651 }
00652
if (!(type & CUPS_PRINTER_REMOTE) && !(type & CUPS_PRINTER_IMPLICIT) && !name.isEmpty())
00653 resources_.append(
new CupsResource(
"/printers/"+name));
00654 ippDelete(request_);
00655 }
00656
00657 request_ = ippNew();
00658 ippAddString(request_, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
"attributes-charset", NULL, cupsLangEncoding(lang));
00659 ippAddString(request_, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
"attributes-natural-language", NULL, lang->language);
00660 request_->request.op.operation_id = CUPS_GET_CLASSES;
00661 request_ = cupsDoRequest(http_, request_,
"/classes/");
00662
if (request_)
00663 {
00664
QString name;
00665
int type(0);
00666 ipp_attribute_t *attr = request_->attrs;
00667
while (attr)
00668 {
00669
00670
if (!attr->name)
00671 {
00672
if (!(type & CUPS_PRINTER_REMOTE) && !name.isEmpty())
00673 resources_.append(
new CupsResource(
"/classes/"+name));
00674 name =
"";
00675 type = 0;
00676 }
00677
else if (strcmp(attr->name,
"printer-name") == 0) name = attr->values[0].string.text;
00678
else if (strcmp(attr->name,
"printer-type") == 0) type = attr->values[0].integer;
00679 attr = attr->next;
00680 }
00681
if (!(type & CUPS_PRINTER_REMOTE) && !name.isEmpty())
00682 resources_.append(
new CupsResource(
"/classes/"+name));
00683 ippDelete(request_);
00684 }
00685 httpClose(http_);
00686
return true;
00687 }
00688
00689
00690
00691 CupsLocation::CupsLocation()
00692 {
00693 resource_ = 0;
00694 resourcename_ =
"";
00695 authtype_ = AUTHTYPE_NONE;
00696 authclass_ = AUTHCLASS_ANONYMOUS;
00697 authname_ = QString::null;
00698 encryption_ = ENCRYPT_IFREQUESTED;
00699 satisfy_ = SATISFY_ALL;
00700 order_ = ORDER_ALLOW_DENY;
00701
00702 }
00703
00704 CupsLocation::CupsLocation(
const CupsLocation& loc)
00705 : resource_(loc.resource_),
00706 resourcename_(loc.resourcename_),
00707 authtype_(loc.authtype_),
00708 authclass_(loc.authclass_),
00709 authname_(loc.authname_),
00710 encryption_(loc.encryption_),
00711 satisfy_(loc.satisfy_),
00712 order_(loc.order_),
00713 addresses_(loc.addresses_)
00714 {
00715 }
00716
00717
bool CupsLocation::parseResource(
const QString& line)
00718 {
00719
QString str = line.simplifyWhiteSpace();
00720
int p1 = line.find(
' '), p2 = line.find(
'>');
00721
if (p1 != -1 && p2 != -1)
00722 {
00723 resourcename_ = str.mid(p1+1,p2-p1-1);
00724
return true;
00725 }
00726
else return false;
00727 }
00728
00729
bool CupsLocation::parseOption(
const QString& line)
00730 {
00731
int p(-1);
00732
QString keyword, value, l(line.simplifyWhiteSpace());
00733
00734
if ((p=l.find(
' ')) != -1)
00735 {
00736 keyword = l.left(p).lower();
00737 value = l.mid(p+1);
00738 }
00739
else
00740 {
00741 keyword = l.lower();
00742 }
00743
00744
if (keyword ==
"authtype")
00745 {
00746
QString a = value.lower();
00747
if (a ==
"basic") authtype_ = AUTHTYPE_BASIC;
00748
else if (a ==
"digest") authtype_ = AUTHTYPE_DIGEST;
00749
else authtype_ = AUTHTYPE_NONE;
00750 }
00751
else if (keyword ==
"authclass")
00752 {
00753
QString a = value.lower();
00754
if (a ==
"user") authclass_ = AUTHCLASS_USER;
00755
else if (a ==
"system") authclass_ = AUTHCLASS_SYSTEM;
00756
else if (a ==
"group") authclass_ = AUTHCLASS_GROUP;
00757
else authclass_ = AUTHCLASS_ANONYMOUS;
00758 }
00759
else if (keyword ==
"authgroupname") authname_ = value;
00760
else if (keyword ==
"require")
00761 {
00762
int p = value.find(
' ');
00763
if (p != -1)
00764 {
00765 authname_ = value.mid(p+1);
00766
QString cl = value.left(p).lower();
00767
if (cl ==
"user")
00768 authclass_ = AUTHCLASS_USER;
00769
else if (cl ==
"group")
00770 authclass_ = AUTHCLASS_GROUP;
00771 }
00772 }
00773
else if (keyword ==
"allow") addresses_.append(
"Allow "+value);
00774
else if (keyword ==
"deny") addresses_.append(
"Deny "+value);
00775
else if (keyword ==
"order") order_ = (value.lower() ==
"deny,allow" ? ORDER_DENY_ALLOW : ORDER_ALLOW_DENY);
00776
else if (keyword ==
"encryption")
00777 {
00778
QString e = value.lower();
00779
if (e ==
"always") encryption_ = ENCRYPT_ALWAYS;
00780
else if (e ==
"never") encryption_ = ENCRYPT_NEVER;
00781
else if (e ==
"required") encryption_ = ENCRYPT_REQUIRED;
00782
else encryption_ = ENCRYPT_IFREQUESTED;
00783 }
00784
else if (keyword ==
"satisfy") satisfy_ = (value.lower() ==
"any" ? SATISFY_ANY : SATISFY_ALL);
00785
else return false;
00786
return true;
00787 }
00788
00789
00790
00791 CupsResource::CupsResource()
00792 {
00793 type_ = RESOURCE_GLOBAL;
00794 }
00795
00796 CupsResource::CupsResource(
const QString& path)
00797 {
00798 setPath(path);
00799 }
00800
00801
void CupsResource::setPath(
const QString& path)
00802 {
00803 path_ = path;
00804 type_ = typeFromPath(path_);
00805 text_ = pathToText(path_);
00806 }
00807
00808
int CupsResource::typeFromText(
const QString& text)
00809 {
00810
if (text == i18n(
"Base",
"Root") || text == i18n(
"All printers") || text == i18n(
"All classes") || text == i18n(
"Print jobs"))
return RESOURCE_GLOBAL;
00811
else if (text == i18n(
"Administration"))
return RESOURCE_ADMIN;
00812
else if (text.find(i18n(
"Class")) == 0)
return RESOURCE_CLASS;
00813
else if (text.find(i18n(
"Printer")) == 0)
return RESOURCE_PRINTER;
00814
else return RESOURCE_PRINTER;
00815 }
00816
00817
int CupsResource::typeFromPath(
const QString& path)
00818 {
00819
if (path ==
"/admin")
return RESOURCE_ADMIN;
00820
else if (path ==
"/printers" || path ==
"/classes" || path ==
"/" || path ==
"/jobs")
return RESOURCE_GLOBAL;
00821
else if (path.left(9) ==
"/printers")
return RESOURCE_PRINTER;
00822
else if (path.left(8) ==
"/classes")
return RESOURCE_CLASS;
00823
else return RESOURCE_GLOBAL;
00824 }
00825
00826
QString CupsResource::textToPath(
const QString& text)
00827 {
00828
QString path(
"/");
00829
if (text == i18n(
"Administration")) path =
"/admin";
00830
else if (text == i18n(
"All printers")) path =
"/printers";
00831
else if (text == i18n(
"All classes")) path =
"/classes";
00832
else if (text == i18n(
"Print jobs")) path =
"/jobs";
00833
else if (text == i18n(
"Base",
"Root")) path =
"/";
00834
else if (text.find(i18n(
"Printer")) == 0)
00835 {
00836 path =
"/printers/";
00837 path.append(text.right(text.length()-i18n(
"Printer").length()-1));
00838 }
00839
else if (text.find(i18n(
"Class")) == 0)
00840 {
00841 path =
"/classes/";
00842 path.append(text.right(text.length()-i18n(
"Class").length()-1));
00843 }
00844
return path;
00845 }
00846
00847
QString CupsResource::pathToText(
const QString& path)
00848 {
00849
QString text(i18n(
"Base",
"Root"));
00850
if (path ==
"/admin") text = i18n(
"Administration");
00851
else if (path ==
"/printers") text = i18n(
"All printers");
00852
else if (path ==
"/classes") text = i18n(
"All classes");
00853
else if (path ==
"/") text = i18n(
"Root");
00854
else if (path ==
"/jobs") text = i18n(
"Print jobs");
00855
else if (path.find(
"/printers/") == 0)
00856 {
00857 text = i18n(
"Printer");
00858 text.append(
" ");
00859 text.append(path.right(path.length()-10));
00860 }
00861
else if (path.find(
"/classes/") == 0)
00862 {
00863 text = i18n(
"Class");
00864 text.append(
" ");
00865 text.append(path.right(path.length()-9));
00866 }
00867
return text;
00868 }
00869
00870
QString CupsResource::typeToIconName(
int type)
00871 {
00872
switch (type)
00873 {
00874
case RESOURCE_ADMIN:
00875
case RESOURCE_GLOBAL:
00876
return QString(
"folder");
00877
case RESOURCE_PRINTER:
00878
return QString(
"kdeprint_printer");
00879
case RESOURCE_CLASS:
00880
return QString(
"kdeprint_printer_class");
00881 }
00882
return QString(
"folder");
00883 }