32#include <cups/language.h> 
   34TQString findDir(
const TQStringList& list)
 
   36    for (TQStringList::ConstIterator it=list.begin(); it!=list.end(); ++it)
 
   37        if (TQFile::exists(*it))
 
   43void splitSizeSpec(
const TQString& s, 
int& sz, 
int& suff)
 
   45    int p = s.find(TQRegExp(
"\\D"));
 
   46    sz = s.mid(0, p).toInt();
 
   49        switch (s[p].latin1())
 
   51            case 'k': suff = UNIT_KB; 
break;
 
   53            case 'm': suff = UNIT_MB; 
break;
 
   54            case 'g': suff = UNIT_GB; 
break;
 
   55            case 't': suff = UNIT_TILE; 
break;
 
   65    datadir_ = findDir(TQStringList(
"/usr/share/cups")
 
   66            << 
"/usr/local/share/cups" 
   68            << 
"/opt/local/share/cups");
 
   69    documentdir_ = findDir(TQStringList(datadir_+
"/doc-root")
 
   70            << datadir_.left(datadir_.length()-5)+
"/doc/cups");
 
   72    requestdir_ = findDir(TQStringList(
"/var/spool/cups")
 
   74    serverbin_ = findDir(TQStringList()
 
   75            << 
"/usr/" SYSTEM_LIBDIR 
"/cups" 
   77            << 
"/usr/local/" SYSTEM_LIBDIR 
"/cups" 
   78            << 
"/usr/local/lib/cups" 
   79            << 
"/opt/" SYSTEM_LIBDIR 
"/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";
 
   88    servername_ = TQString::null;
 
   89    serveradmin_ = TQString::null;
 
   90    classification_ = CLASS_NONE;
 
   91    otherclassname_ = TQString::null;
 
   92    classoverride_ = 
false;
 
   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;
 
  103    keepalivetimeout_ = 60;
 
  105    maxrequestsize_ = 
"0";
 
  106    clienttimeout_ = 300;
 
  108    TQString    logdir = findDir(TQStringList(
"/var/log/cups")
 
  109            << 
"/var/spool/cups/log" 
  111    accesslog_ = logdir+
"/access_log";
 
  112    errorlog_ = logdir+
"/error_log";
 
  113    pagelog_ = logdir+
"/page_log";
 
  115    loglevel_ = LOGLEVEL_INFO;
 
  116    keepjobhistory_ = 
true;
 
  117    keepjobfiles_ = 
false;
 
  118    autopurgejobs_ = 
false;
 
  120    maxjobsperprinter_ = 0;
 
  127    browseprotocols_ << 
"CUPS";
 
  128    browseport_ = ippPort();
 
  129    browseinterval_ = 30;
 
  130    browsetimeout_ = 300;
 
  132    browseorder_ = ORDER_ALLOW_DENY;
 
  133    useimplicitclasses_ = 
true;
 
  134    hideimplicitmembers_ = 
true;
 
  135    useshortnames_ = 
true;
 
  136    useanyclasses_ = 
false;
 
  138    loadAvailableResources();
 
  141CupsdConf::~CupsdConf()
 
  145bool CupsdConf::loadFromFile(
const TQString& filename)
 
  148    if (!f.exists() || !f.open(IO_ReadOnly)) 
return false;
 
  153        bool    done(
false), value(
true);
 
  154        while (!done && value)
 
  156            line = t.readLine().simplifyWhiteSpace();
 
  159                if (t.atEnd()) done = 
true;
 
  162            else if (line[0] == 
'#') 
continue;
 
  163            else if (line.left(9).lower() == 
"<location")
 
  165                CupsLocation    *location = 
new CupsLocation();
 
  166                locations_.append(location);
 
  167                if (!location->parseResource(line) || !parseLocation(location, t))
 
  170                for (resources_.first();resources_.current();resources_.next())
 
  171                    if (resources_.current()->path_ == location->resourcename_)
 
  172                        location->resource_ = resources_.current();
 
  174            else value = parseOption(line);
 
  181bool CupsdConf::saveToFile(
const TQString& filename)
 
  184    if (!f.open(IO_WriteOnly))
 
  189        t << comments_[
"header"] << endl;
 
  190        t << 
"# Server" << endl << endl;
 
  192        t << comments_[
"servername"] << endl;
 
  193        if ( !servername_.isEmpty() )
 
  194            t << 
"ServerName " << servername_ << endl;
 
  196        t << endl << comments_[
"serveradmin"] << endl;
 
  197        if ( !serveradmin_.isEmpty() )
 
  198            t << 
"ServerAdmin " << serveradmin_ << endl;
 
  200        t << endl << comments_[
"classification"] << endl;
 
  201        t << 
"Classification ";
 
  202        switch (classification_)
 
  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;
 
  215        t << endl << comments_[
"classifyoverride"] << endl;
 
  216        if (classification_ != CLASS_NONE) t << 
"ClassifyOverride " << (classoverride_ ? 
"Yes" : 
"No") << endl;
 
  218        t << endl << comments_[
"defaultcharset"] << endl;
 
  219        t << 
"DefaultCharset " << charset_.upper() << endl;
 
  221        t << endl << comments_[
"defaultlanguage"] << endl;
 
  222        t << 
"DefaultLanguage " << language_.lower() << endl;
 
  224        t << endl << comments_[
"printcap"] << endl;
 
  225        t << 
"Printcap " << printcap_ << endl;
 
  227        t << endl << comments_[
"printcapformat"] << endl;
 
  228        t << 
"PrintcapFormat " << (printcapformat_ == PRINTCAP_SOLARIS ? 
"Solaris" : 
"BSD") << endl;
 
  230        t << endl << 
"# Security" << endl;
 
  231        t << endl << comments_[
"remoteroot"] << endl;
 
  232        t << 
"RemoteRoot " << remoteroot_ << endl;
 
  234        t << endl << comments_[
"systemgroup"] << endl;
 
  235        t << 
"SystemGroup " << systemgroup_ << endl;
 
  237        t << endl << comments_[
"servercertificate"] << endl;
 
  238        t << 
"ServerCertificate " << encryptcert_ << endl;
 
  240        t << endl << comments_[
"serverkey"] << endl;
 
  241        t << 
"ServerKey " << encryptkey_ << endl;
 
  243        t << endl << comments_[
"locations"] << endl;
 
  244        for (locations_.first(); locations_.current(); locations_.next())
 
  246            CupsLocation *loc = locations_.current();
 
  247            t << 
"<Location " << loc->resourcename_ << 
">" << endl;
 
  248            if (loc->authtype_ != AUTHTYPE_NONE)
 
  251                switch (loc->authtype_)
 
  253                    case AUTHTYPE_BASIC: t << 
"Basic"; 
break;
 
  254                    case AUTHTYPE_DIGEST: t << 
"Digest"; 
break;
 
  258            if (loc->authclass_ != AUTHCLASS_ANONYMOUS)
 
  260                switch (loc->authclass_)
 
  263                        if (!loc->authname_.isEmpty())
 
  264                            t << 
"Require user " << loc->authname_ << endl;
 
  266                            t << 
"AuthClass User" << endl;
 
  268                    case AUTHCLASS_GROUP:
 
  269                        if (!loc->authname_.isEmpty())
 
  270                            t << 
"Require group " << loc->authname_ << endl;
 
  272                            t << 
"AuthClass Group" << endl;
 
  274                    case AUTHCLASS_SYSTEM:
 
  275                        t << 
"AuthClass System" << endl;
 
  280            switch (loc->encryption_)
 
  282                case ENCRYPT_ALWAYS: t << 
"Always"; 
break;
 
  283                case ENCRYPT_NEVER: t << 
"Never"; 
break;
 
  284                case ENCRYPT_REQUIRED: t << 
"Required"; 
break;
 
  286                case ENCRYPT_IFREQUESTED: t << 
"IfRequested"; 
break;
 
  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)
 
  293            t << 
"</Location>" << endl;
 
  296        t << endl << 
"# Network" << endl;
 
  297        t << endl << comments_[
"hostnamelookups"] << endl;
 
  298        t << 
"HostnameLookups ";
 
  299        switch (hostnamelookup_)
 
  302            case HOSTNAME_OFF: t << 
"Off"; 
break;
 
  303            case HOSTNAME_ON: t << 
"On"; 
break;
 
  304            case HOSTNAME_DOUBLE: t << 
"Double"; 
break;
 
  308        t << endl << comments_[
"keepalive"] << endl;
 
  309        t << 
"KeepAlive " << (keepalive_ ? 
"On" : 
"Off") << endl;
 
  311        t << endl << comments_[
"keepalivetimeout"] << endl;
 
  312        t << 
"KeepAliveTimeout " << keepalivetimeout_ << endl;
 
  314        t << endl << comments_[
"maxclients"] << endl;
 
  315        t << 
"MaxClients " << maxclients_ << endl;
 
  317        t << endl << comments_[
"maxrequestsize"] << endl;
 
  318        t << 
"MaxRequestSize " << maxrequestsize_ << endl;
 
  320        t << endl << comments_[
"timeout"] << endl;
 
  321        t << 
"Timeout " << clienttimeout_ << endl;
 
  323        t << endl << comments_[
"listen"] << endl;
 
  324        for (TQStringList::ConstIterator it=listenaddresses_.begin(); it!=listenaddresses_.end(); ++it)
 
  327        t << endl << 
"# Log" << endl;
 
  328        t << endl << comments_[
"accesslog"] << endl;
 
  329        t << 
"AccessLog " << accesslog_ << endl;
 
  331        t << endl << comments_[
"errorlog"] << endl;
 
  332        t << 
"ErrorLog " << errorlog_ << endl;
 
  334        t << endl << comments_[
"pagelog"] << endl;
 
  335        t << 
"PageLog " << pagelog_ << endl;
 
  337        t << endl << comments_[
"maxlogsize"] << endl;
 
  339        t << 
"MaxLogSize " << maxlogsize_ << endl;
 
  341        t << endl << comments_[
"loglevel"] << endl;
 
  345            case LOGLEVEL_NONE: t << 
"none"; 
break;
 
  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;
 
  355        t << endl << 
"# Jobs" << endl;
 
  356        t << endl << comments_[
"preservejobhistory"] << endl;
 
  357        t << 
"PreserveJobHistory " << (keepjobhistory_ ? 
"On" : 
"Off") << endl;
 
  359        t << endl << comments_[
"preservejobfiles"] << endl;
 
  360        if (keepjobhistory_) t << 
"PreserveJobFiles " << (keepjobfiles_ ? 
"On" : 
"Off") << endl;
 
  362        t << endl << comments_[
"autopurgejobs"] << endl;
 
  363        if (keepjobhistory_) t << 
"AutoPurgeJobs " << (autopurgejobs_ ? 
"Yes" : 
"No") << endl;
 
  365        t << endl << comments_[
"maxjobs"] << endl;
 
  366        t << 
"MaxJobs " << maxjobs_ << endl;
 
  368        t << endl << comments_[
"maxjobsperprinter"] << endl;
 
  369        t << 
"MaxJobsPerPrinter " << maxjobsperprinter_ << endl;
 
  371        t << endl << comments_[
"maxjobsperuser"] << endl;
 
  372        t << 
"MaxJobsPerUser " << maxjobsperuser_ << endl;
 
  374        t << endl << 
"# Filter" << endl;
 
  375        t << endl << comments_[
"user"] << endl;
 
  376        t << 
"User " << user_ << endl;
 
  378        t << endl << comments_[
"group"] << endl;
 
  379        t << 
"Group " << group_ << endl;
 
  381        t << endl << comments_[
"ripcache"] << endl;
 
  382        t << 
"RIPCache " << ripcache_ << endl;
 
  384        t << endl << comments_[
"filterlimit"] << endl;
 
  385        t << 
"FilterLimit " << filterlimit_ << endl;
 
  387        t << endl << 
"# Directories" << endl;
 
  388        t << endl << comments_[
"datadir"] << endl;
 
  389        t << 
"DataDir " << datadir_ << endl;
 
  391        t << endl << comments_[
"documentroot"] << endl;
 
  392        t << 
"DocumentRoot " << documentdir_ << endl;
 
  394        t << endl << comments_[
"fontpath"] << endl;
 
  395        for (TQStringList::ConstIterator it=fontpath_.begin(); it!=fontpath_.end(); ++it)
 
  396            t << 
"FontPath " << *it << endl;
 
  398        t << endl << comments_[
"requestroot"] << endl;
 
  399        t << 
"RequestRoot " << requestdir_ << endl;
 
  401        t << endl << comments_[
"serverbin"] << endl;
 
  402        t << 
"ServerBin " << serverbin_ << endl;
 
  404        t << endl << comments_[
"serverroot"] << endl;
 
  405        t << 
"ServerRoot " << serverfiles_ << endl;
 
  407        t << endl << comments_[
"tempdir"] << endl;
 
  408        t << 
"TempDir " << tmpfiles_ << endl;
 
  410        t << endl << 
"# Browsing" << endl;
 
  411        t << endl << comments_[
"browsing"] << endl;
 
  412        t << 
"Browsing " << (browsing_ ? 
"On" : 
"Off") << endl;
 
  414        t << endl << comments_[
"browseprotocols"] << endl;
 
  417            t << 
"BrowseProtocols ";
 
  418            for (TQStringList::ConstIterator it=browseprotocols_.begin(); it!=browseprotocols_.end(); ++it)
 
  419                t << (*it).upper() << 
" ";
 
  423        t << endl << comments_[
"browseport"] << endl;
 
  424        if (browsing_) t << 
"BrowsePort " << browseport_ << endl;
 
  426        t << endl << comments_[
"browseinterval"] << endl;
 
  427        if (browsing_) t << 
"BrowseInterval " << browseinterval_ << endl;
 
  429        t << endl << comments_[
"browsetimeout"] << endl;
 
  430        if (browsing_) t << 
"BrowseTimeout " << browsetimeout_ << endl;
 
  432        t << endl << comments_[
"browseaddress"] << endl;
 
  434            for (TQStringList::ConstIterator it=browseaddresses_.begin(); it!=browseaddresses_.end(); ++it)
 
  435                if ((*it).startsWith(
"Send"))
 
  436                    t << 
"BrowseAddress " << (*it).mid(5) << endl;
 
  438                    t << 
"Browse" << (*it) << endl;
 
  440        t << endl << comments_[
"browseorder"] << endl;
 
  441        if (browsing_) t << 
"BrowseOrder " << (browseorder_ == ORDER_ALLOW_DENY ? 
"allow,deny" : 
"deny,allow") << endl;
 
  443        t << endl << comments_[
"implicitclasses"] << endl;
 
  444        if (browsing_) t << 
"ImplicitClasses " << (useimplicitclasses_ ? 
"On" : 
"Off") << endl;
 
  446        t << endl << comments_[
"implicitanyclasses"] << endl;
 
  447        if (browsing_) t << 
"ImplicitAnyClasses " << (useanyclasses_ ? 
"On" : 
"Off") << endl;
 
  449        t << endl << comments_[
"hideimplicitmembers"] << endl;
 
  450        if (browsing_) t << 
"HideImplicitMembers " << (hideimplicitmembers_ ? 
"Yes" : 
"No") << endl;
 
  452        t << endl << comments_[
"browseshortnames"] << endl;
 
  453        if (browsing_) t << 
"BrowseShortNames " << (useshortnames_ ? 
"Yes" : 
"No") << endl;
 
  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;
 
  463bool CupsdConf::parseLocation(CupsLocation *location, TQTextStream& file)
 
  468    while (!done && value)
 
  470        line = file.readLine().simplifyWhiteSpace();
 
  480        else if (line[0] == 
'#') 
continue;
 
  481        else if (line.lower() == 
"</location>") done = 
true;
 
  482        else value = location->parseOption(line);
 
  487bool CupsdConf::parseOption(
const TQString& line)
 
  490    TQString keyword, value, l(line.simplifyWhiteSpace());
 
  492    if ((p=l.find(
' ')) != -1)
 
  494        keyword = l.left(p).lower();
 
  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")
 
  514        browseprotocols_.clear();
 
  515        TQStringList prots = TQStringList::split(TQRegExp(
"\\s"), value, 
false);
 
  516        if (prots.find(
"all") != prots.end())
 
  517            browseprotocols_ << 
"CUPS" << 
"SLP";
 
  519            for (TQStringList::ConstIterator it=prots.begin(); it!=prots.end(); ++it)
 
  520                browseprotocols_ << (*it).upper();
 
  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")
 
  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;
 
  537            classification_ = CLASS_OTHER;
 
  538            otherclassname_ = cl;
 
  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")
 
  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;
 
  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")
 
  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;
 
  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;
 
  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;
 
  608        unknown_ << TQPair<TQString,TQString>(keyword, value);
 
  613bool CupsdConf::loadAvailableResources()
 
  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_ = httpConnect(host.local8Bit(),port);
 
  623    resources_.append(
new CupsResource(
"/"));
 
  624    resources_.append(
new CupsResource(
"/admin"));
 
  625    resources_.append(
new CupsResource(
"/printers"));
 
  626    resources_.append(
new CupsResource(
"/classes"));
 
  627    resources_.append(
new CupsResource(
"/jobs"));
 
  633    ipp_t   *request_ = ippNew();
 
  634    cups_lang_t*    lang = cupsLangDefault();
 
  635    ippAddString(request_, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 
"attributes-charset", NULL, cupsLangEncoding(lang));
 
  636    ippAddString(request_, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, 
"attributes-natural-language", NULL, lang->language);
 
  638    ippSetOperation(request_, CUPS_GET_PRINTERS);
 
  640    request_->request.op.operation_id = CUPS_GET_PRINTERS;
 
  642    request_ = cupsDoRequest(http_, request_, 
"/printers/");
 
  648        ipp_attribute_t *attr = ippFirstAttribute(request_);
 
  650        ipp_attribute_t *attr = request_->attrs;
 
  656            if (!ippGetName(attr))
 
  661                if (!(type & CUPS_PRINTER_REMOTE) && !(type & CUPS_PRINTER_IMPLICIT) && !name.isEmpty())
 
  662                    resources_.append(
new CupsResource(
"/printers/"+name));
 
  667            else if (strcmp(ippGetName(attr), 
"printer-name") == 0) name = ippGetString(attr, 0, NULL);
 
  668            else if (strcmp(ippGetName(attr), 
"printer-type") == 0) type = ippGetInteger(attr, 0);
 
  669            attr = ippNextAttribute(request_);
 
  671            else if (strcmp(attr->name, 
"printer-name") == 0) name = attr->values[0].string.text;
 
  672            else if (strcmp(attr->name, 
"printer-type") == 0) type = attr->values[0].integer;
 
  676        if (!(type & CUPS_PRINTER_REMOTE) && !(type & CUPS_PRINTER_IMPLICIT) && !name.isEmpty())
 
  677            resources_.append(
new CupsResource(
"/printers/"+name));
 
  682    ippAddString(request_, IPP_TAG_OPERATION, IPP_TAG_CHARSET, 
"attributes-charset", NULL, cupsLangEncoding(lang));
 
  683    ippAddString(request_, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, 
"attributes-natural-language", NULL, lang->language);
 
  685    ippSetOperation(request_, CUPS_GET_CLASSES);
 
  687    request_->request.op.operation_id = CUPS_GET_CLASSES;
 
  689    request_ = cupsDoRequest(http_, request_, 
"/classes/");
 
  695        ipp_attribute_t *attr = ippFirstAttribute(request_);
 
  697        ipp_attribute_t *attr = request_->attrs;
 
  703            if (!ippGetName(attr))
 
  708                if (!(type & CUPS_PRINTER_REMOTE) && !name.isEmpty())
 
  709                    resources_.append(
new CupsResource(
"/classes/"+name));
 
  714            else if (strcmp(ippGetName(attr), 
"printer-name") == 0) name = ippGetString(attr, 0, NULL);
 
  715            else if (strcmp(ippGetName(attr), 
"printer-type") == 0) type = ippGetInteger(attr, 0);
 
  716            attr = ippNextAttribute(request_);
 
  718            else if (strcmp(attr->name, 
"printer-name") == 0) name = attr->values[0].string.text;
 
  719            else if (strcmp(attr->name, 
"printer-type") == 0) type = attr->values[0].integer;
 
  723        if (!(type & CUPS_PRINTER_REMOTE) && !name.isEmpty())
 
  724            resources_.append(
new CupsResource(
"/classes/"+name));
 
  733CupsLocation::CupsLocation()
 
  737    authtype_ = AUTHTYPE_NONE;
 
  738    authclass_ = AUTHCLASS_ANONYMOUS;
 
  739    authname_ = TQString::null;
 
  740    encryption_ = ENCRYPT_IFREQUESTED;
 
  741    satisfy_ = SATISFY_ALL;
 
  742    order_ = ORDER_ALLOW_DENY;
 
  746CupsLocation::CupsLocation(
const CupsLocation& loc)
 
  747: resource_(loc.resource_),
 
  748  resourcename_(loc.resourcename_),
 
  749  authtype_(loc.authtype_),
 
  750  authclass_(loc.authclass_),
 
  751  authname_(loc.authname_),
 
  752  encryption_(loc.encryption_),
 
  753  satisfy_(loc.satisfy_),
 
  755  addresses_(loc.addresses_)
 
  759bool CupsLocation::parseResource(
const TQString& line)
 
  761    TQString    str = line.simplifyWhiteSpace();
 
  762    int p1 = line.find(
' '), p2 = line.find(
'>');
 
  763    if (p1 != -1 && p2 != -1)
 
  765        resourcename_ = str.mid(p1+1,p2-p1-1);
 
  771bool CupsLocation::parseOption(
const TQString& line)
 
  774    TQString keyword, value, l(line.simplifyWhiteSpace());
 
  776    if ((p=l.find(
' ')) != -1)
 
  778        keyword = l.left(p).lower();
 
  786    if (keyword == 
"authtype")
 
  788        TQString a = value.lower();
 
  789        if (a == 
"basic") authtype_ = AUTHTYPE_BASIC;
 
  790        else if (a == 
"digest") authtype_ = AUTHTYPE_DIGEST;
 
  791        else authtype_ = AUTHTYPE_NONE;
 
  793    else if (keyword == 
"authclass")
 
  795        TQString a = value.lower();
 
  796        if (a == 
"user") authclass_ = AUTHCLASS_USER;
 
  797        else if (a == 
"system") authclass_ = AUTHCLASS_SYSTEM;
 
  798        else if (a == 
"group") authclass_ = AUTHCLASS_GROUP;
 
  799        else authclass_ = AUTHCLASS_ANONYMOUS;
 
  801    else if (keyword == 
"authgroupname") authname_ = value;
 
  802    else if (keyword == 
"require")
 
  804        int p = value.find(
' ');
 
  807            authname_ = value.mid(p+1);
 
  808            TQString cl = value.left(p).lower();
 
  810                authclass_ = AUTHCLASS_USER;
 
  811            else if (cl == 
"group")
 
  812                authclass_ = AUTHCLASS_GROUP;
 
  815    else if (keyword == 
"allow") addresses_.append(
"Allow "+value);
 
  816    else if (keyword == 
"deny") addresses_.append(
"Deny "+value);
 
  817    else if (keyword == 
"order") order_ = (value.lower() == 
"deny,allow" ? ORDER_DENY_ALLOW : ORDER_ALLOW_DENY);
 
  818    else if (keyword == 
"encryption")
 
  820        TQString e = value.lower();
 
  821        if (e == 
"always") encryption_ = ENCRYPT_ALWAYS;
 
  822        else if (e == 
"never") encryption_ = ENCRYPT_NEVER;
 
  823        else if (e == 
"required") encryption_ = ENCRYPT_REQUIRED;
 
  824        else encryption_ = ENCRYPT_IFREQUESTED;
 
  826    else if (keyword == 
"satisfy") satisfy_ = (value.lower() == 
"any" ? SATISFY_ANY : SATISFY_ALL);
 
  833CupsResource::CupsResource()
 
  835    type_ = RESOURCE_GLOBAL;
 
  838CupsResource::CupsResource(
const TQString& path)
 
  843void CupsResource::setPath(
const TQString& path)
 
  846    type_ = typeFromPath(path_);
 
  847    text_ = pathToText(path_);
 
  850int CupsResource::typeFromText(
const TQString& text)
 
  852    if (text == i18n(
"Base", 
"Root") || text == i18n(
"All printers") || text == i18n(
"All classes") || text == i18n(
"Print jobs")) 
return RESOURCE_GLOBAL;
 
  853    else if (text == i18n(
"Administration")) 
return RESOURCE_ADMIN;
 
  854    else if (text.find(i18n(
"Class")) == 0) 
return RESOURCE_CLASS;
 
  855    else if (text.find(i18n(
"Printer")) == 0) 
return RESOURCE_PRINTER;
 
  856    else return RESOURCE_PRINTER;
 
  859int CupsResource::typeFromPath(
const TQString& path)
 
  861    if (path == 
"/admin") 
return RESOURCE_ADMIN;
 
  862    else if (path == 
"/printers" || path == 
"/classes" || path == 
"/" || path == 
"/jobs") 
return RESOURCE_GLOBAL;
 
  863    else if (path.left(9) == 
"/printers") 
return RESOURCE_PRINTER;
 
  864    else if (path.left(8) == 
"/classes") 
return RESOURCE_CLASS;
 
  865    else return RESOURCE_GLOBAL;
 
  868TQString CupsResource::textToPath(
const TQString& text)
 
  871    if (text == i18n(
"Administration")) path = 
"/admin";
 
  872    else if (text == i18n(
"All printers")) path = 
"/printers";
 
  873    else if (text == i18n(
"All classes")) path = 
"/classes";
 
  874    else if (text == i18n(
"Print jobs")) path = 
"/jobs";
 
  875    else if (text == i18n(
"Base", 
"Root")) path = 
"/";
 
  876    else if (text.find(i18n(
"Printer")) == 0)
 
  879        path.append(text.right(text.length()-i18n(
"Printer").length()-1));
 
  881    else if (text.find(i18n(
"Class")) == 0)
 
  884        path.append(text.right(text.length()-i18n(
"Class").length()-1));
 
  889TQString CupsResource::pathToText(
const TQString& path)
 
  891    TQString    text(i18n(
"Base", 
"Root"));
 
  892    if (path == 
"/admin") text = i18n(
"Administration");
 
  893    else if (path == 
"/printers") text = i18n(
"All printers");
 
  894    else if (path == 
"/classes") text = i18n(
"All classes");
 
  895    else if (path == 
"/") text = i18n(
"Root");
 
  896    else if (path == 
"/jobs") text = i18n(
"Print jobs");
 
  897    else if (path.find(
"/printers/") == 0)
 
  899        text = i18n(
"Printer");
 
  901        text.append(path.right(path.length()-10));
 
  903    else if (path.find(
"/classes/") == 0)
 
  905        text = i18n(
"Class");
 
  907        text.append(path.right(path.length()-9));
 
  912TQString CupsResource::typeToIconName(
int type)
 
  917       case RESOURCE_GLOBAL:
 
  918        return TQString(
"folder");
 
  919       case RESOURCE_PRINTER:
 
  920        return TQString(
"tdeprint_printer");
 
  922        return TQString(
"tdeprint_printer_class");
 
  924    return TQString(
"folder");