]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Mirror 1.1.x changes.
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 29 Jan 2003 20:08:28 +0000 (20:08 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Wed, 29 Jan 2003 20:08:28 +0000 (20:08 +0000)
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/branches/branch-1.2@3282 7a7537e8-13f0-0310-91df-b6672ffda945

12 files changed:
CHANGES-1.1.txt
scheduler/classes.c
scheduler/conf.c
scheduler/conf.h
scheduler/cupsd.h
scheduler/dirsvc.c
scheduler/ipp.c
scheduler/job.c
scheduler/job.h
scheduler/main.c
scheduler/printers.c
scheduler/printers.h

index a6b9297752da5f44691aeb8628d18fb429bd6bb1..a2bc8419a418c7bd9821b5b8af9ed46355966142 100644 (file)
@@ -3,6 +3,9 @@ CHANGES-1.1.txt
 
 CHANGES IN CUPS V1.1.19
 
+       - Revamped how strings are stored in the scheduler,
+         providing a substantial improvement in memory usage
+         for systems with large numbers of printers.
        - The PostScript filter now supports binary PostScript
          files and files beginning with the PJL language escape
          sequence.
index f03fb82bb21aafe994127d53dcd780572085d1c4..6c9135040070db80833213365093b1c62148d909 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: classes.c,v 1.34.2.9 2003/01/24 18:00:54 mike Exp $"
+ * "$Id: classes.c,v 1.34.2.10 2003/01/29 20:08:20 mike Exp $"
  *
  *   Printer class routines for the Common UNIX Printing System (CUPS).
  *
@@ -65,12 +65,12 @@ AddClass(const char *name)  /* I - Name of class */
 
 #ifdef AF_INET6
     if (Listeners[0].address.addr.sa_family == AF_INET6)
-      snprintf(c->uri, sizeof(c->uri), "ipp://%s:%d/classes/%s", ServerName,
-               ntohs(Listeners[0].address.ipv6.sin6_port), name);
+      SetStringf(&c->uri, "ipp://%s:%d/classes/%s", ServerName,
+                 ntohs(Listeners[0].address.ipv6.sin6_port), name);
     else
 #endif /* AF_INET6 */
-    snprintf(c->uri, sizeof(c->uri), "ipp://%s:%d/classes/%s", ServerName,
-             ntohs(Listeners[0].address.ipv4.sin_port), name);
+    SetStringf(&c->uri, "ipp://%s:%d/classes/%s", ServerName,
+               ntohs(Listeners[0].address.ipv4.sin_port), name);
   }
 
   return (c);
@@ -444,16 +444,36 @@ LoadAllClasses(void)
     }
     
     else if (strcmp(name, "Info") == 0)
-      strlcpy(p->info, value, sizeof(p->info));
+      SetString(&p->info, value);
     else if (strcmp(name, "Location") == 0)
-      strlcpy(p->location, value, sizeof(p->location));
+      SetString(&p->location, value);
     else if (strcmp(name, "Printer") == 0)
     {
-      if ((temp = FindPrinter(value)) != NULL)
-        AddPrinterToClass(p, temp);
-      else
+      if ((temp = FindPrinter(value)) == NULL)
+      {
        LogMessage(L_WARN, "Unknown printer %s on line %d of classes.conf.",
                   value, linenum);
+
+       /*
+       * Add the missing remote printer...
+       */
+
+       temp = AddPrinter(value);
+       strcpy(temp->make_model, "Remote Printer on unknown");
+
+        temp->state       = IPP_PRINTER_STOPPED;
+       temp->type        |= CUPS_PRINTER_REMOTE;
+       temp->browse_time = 2147483647;
+
+       SetString(&temp->location, "Location Unknown");
+       SetString(&temp->info, "No Information Available");
+       temp->hostname[0] = '\0';
+
+       SetPrinterAttrs(temp);
+      }
+
+      if (temp)
+        AddPrinterToClass(p, temp);
     }
     else if (strcmp(name, "State") == 0)
     {
@@ -499,7 +519,7 @@ LoadAllClasses(void)
       if (*valueptr)
         *valueptr++ = '\0';
 
-      strlcpy(p->job_sheets[0], value, sizeof(p->job_sheets[0]));
+      SetString(&p->job_sheets[0], value);
 
       while (isspace(*valueptr))
         valueptr ++;
@@ -511,7 +531,7 @@ LoadAllClasses(void)
        if (*valueptr)
           *valueptr++ = '\0';
 
-       strlcpy(p->job_sheets[1], value, sizeof(p->job_sheets[1]));
+       SetString(&p->job_sheets[1], value);
       }
     }
     else if (strcmp(name, "AllowUser") == 0)
@@ -615,10 +635,10 @@ SaveAllClasses(void)
     else
       fprintf(fp, "<Class %s>\n", pclass->name);
 
-    if (pclass->info[0])
+    if (pclass->info)
       fprintf(fp, "Info %s\n", pclass->info);
 
-    if (pclass->location[0])
+    if (pclass->location)
       fprintf(fp, "Location %s\n", pclass->location);
 
     if (pclass->state == IPP_PRINTER_STOPPED)
@@ -653,5 +673,5 @@ SaveAllClasses(void)
 
 
 /*
- * End of "$Id: classes.c,v 1.34.2.9 2003/01/24 18:00:54 mike Exp $".
+ * End of "$Id: classes.c,v 1.34.2.10 2003/01/29 20:08:20 mike Exp $".
  */
index 7b06d0da6e4bb01e21730571c3c92d942e68c5f2..340a0acc1a9d13dbdcdbac7cc65198e47028b378 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: conf.c,v 1.77.2.23 2003/01/29 15:38:45 mike Exp $"
+ * "$Id: conf.c,v 1.77.2.24 2003/01/29 20:08:20 mike Exp $"
  *
  *   Configuration routines for the Common UNIX Printing System (CUPS).
  *
@@ -95,8 +95,7 @@ typedef struct
 {
   char *name;          /* Name of variable */
   void *ptr;           /* Pointer to variable */
-  int  type,           /* Type (int, string, address) */
-       size;           /* Size of string */
+  int  type;           /* Type (int, string, address) */
 } var_t;
 
 #define VAR_INTEGER    0
@@ -110,65 +109,66 @@ typedef struct
 
 static var_t   variables[] =
 {
-  { "AccessLog",       AccessLog,              VAR_STRING,     sizeof(AccessLog) },
-  { "AutoPurgeJobs",   &JobAutoPurge,          VAR_BOOLEAN,    0 },
-  { "BrowseInterval",  &BrowseInterval,        VAR_INTEGER,    0 },
-  { "BrowsePort",      &BrowsePort,            VAR_INTEGER,    0 },
-  { "BrowseShortNames",        &BrowseShortNames,      VAR_BOOLEAN,    0 },
-  { "BrowseTimeout",   &BrowseTimeout,         VAR_INTEGER,    0 },
-  { "Browsing",                &Browsing,              VAR_BOOLEAN,    0 },
-  { "Classification",  Classification,         VAR_STRING,     sizeof(Classification) },
-  { "ClassifyOverride",        &ClassifyOverride,      VAR_BOOLEAN,    0 },
-  { "ConfigFilePerm",  &ConfigFilePerm,        VAR_INTEGER,    0 },
-  { "DataDir",         DataDir,                VAR_STRING,     sizeof(DataDir) },
-  { "DefaultCharset",  DefaultCharset,         VAR_STRING,     sizeof(DefaultCharset) },
-  { "DefaultLanguage", DefaultLanguage,        VAR_STRING,     sizeof(DefaultLanguage) },
-  { "DocumentRoot",    DocumentRoot,           VAR_STRING,     sizeof(DocumentRoot) },
-  { "ErrorLog",                ErrorLog,               VAR_STRING,     sizeof(ErrorLog) },
-  { "FileDevice",      &FileDevice,            VAR_BOOLEAN,    0 },
-  { "FilterLimit",     &FilterLimit,           VAR_INTEGER,    0 },
-  { "FilterNice",      &FilterNice,            VAR_INTEGER,    0 },
-  { "FontPath",                FontPath,               VAR_STRING,     sizeof(FontPath) },
-  { "HideImplicitMembers", &HideImplicitMembers, VAR_BOOLEAN,  0 },
-  { "ImplicitClasses", &ImplicitClasses,       VAR_BOOLEAN,    0 },
-  { "ImplicitAnyClasses", &ImplicitAnyClasses, VAR_BOOLEAN,    0 },
-  { "KeepAliveTimeout",        &KeepAliveTimeout,      VAR_INTEGER,    0 },
-  { "KeepAlive",       &KeepAlive,             VAR_BOOLEAN,    0 },
-  { "LimitRequestBody",        &MaxRequestSize,        VAR_INTEGER,    0 },
-  { "ListenBackLog",   &ListenBackLog,         VAR_INTEGER,    0 },
-  { "LogFilePerm",     &LogFilePerm,           VAR_INTEGER,    0 },
-  { "MaxActiveJobs",   &MaxActiveJobs,         VAR_INTEGER,    0 },
-  { "MaxClients",      &MaxClients,            VAR_INTEGER,    0 },
-  { "MaxClientsPerHost",&MaxClientsPerHost,    VAR_INTEGER,    0 },
-  { "MaxCopies",       &MaxCopies,             VAR_INTEGER,    0 },
-  { "MaxJobs",         &MaxJobs,               VAR_INTEGER,    0 },
-  { "MaxJobsPerPrinter",&MaxJobsPerPrinter,    VAR_INTEGER,    0 },
-  { "MaxJobsPerUser",  &MaxJobsPerUser,        VAR_INTEGER,    0 },
-  { "MaxLogSize",      &MaxLogSize,            VAR_INTEGER,    0 },
-  { "MaxRequestSize",  &MaxRequestSize,        VAR_INTEGER,    0 },
-  { "PageLog",         PageLog,                VAR_STRING,     sizeof(PageLog) },
-  { "PreserveJobFiles",        &JobFiles,              VAR_BOOLEAN,    0 },
-  { "PreserveJobHistory", &JobHistory,         VAR_BOOLEAN,    0 },
-  { "Printcap",                Printcap,               VAR_STRING,     sizeof(Printcap) },
-  { "PrintcapGUI",     PrintcapGUI,            VAR_STRING,     sizeof(PrintcapGUI) },
-  { "RemoteRoot",      RemoteRoot,             VAR_STRING,     sizeof(RemoteRoot) },
-  { "RequestRoot",     RequestRoot,            VAR_STRING,     sizeof(RequestRoot) },
-  { "RIPCache",                RIPCache,               VAR_STRING,     sizeof(RIPCache) },
-  { "RunAsUser",       &RunAsUser,             VAR_BOOLEAN,    0 },
-  { "RootCertDuration", &RootCertDuration,     VAR_INTEGER,    0 },
-  { "ServerAdmin",     ServerAdmin,            VAR_STRING,     sizeof(ServerAdmin) },
-  { "ServerBin",       ServerBin,              VAR_STRING,     sizeof(ServerBin) },
+  { "AccessLog",               &AccessLog,             VAR_STRING },
+  { "AutoPurgeJobs",           &JobAutoPurge,          VAR_BOOLEAN },
+  { "BrowseInterval",          &BrowseInterval,        VAR_INTEGER },
+  { "BrowsePort",              &BrowsePort,            VAR_INTEGER },
+  { "BrowseShortNames",                &BrowseShortNames,      VAR_BOOLEAN },
+  { "BrowseTimeout",           &BrowseTimeout,         VAR_INTEGER },
+  { "Browsing",                        &Browsing,              VAR_BOOLEAN },
+  { "Classification",          &Classification,        VAR_STRING },
+  { "ClassifyOverride",                &ClassifyOverride,      VAR_BOOLEAN },
+  { "ConfigFilePerm",          &ConfigFilePerm,        VAR_INTEGER },
+  { "DataDir",                 &DataDir,               VAR_STRING },
+  { "DefaultCharset",          &DefaultCharset,        VAR_STRING },
+  { "DefaultLanguage",         &DefaultLanguage,       VAR_STRING },
+  { "DocumentRoot",            &DocumentRoot,          VAR_STRING },
+  { "ErrorLog",                        &ErrorLog,              VAR_STRING },
+  { "FileDevice",              &FileDevice,            VAR_BOOLEAN },
+  { "FilterLimit",             &FilterLimit,           VAR_INTEGER },
+  { "FilterNice",              &FilterNice,            VAR_INTEGER },
+  { "FontPath",                        &FontPath,              VAR_STRING },
+  { "HideImplicitMembers",     &HideImplicitMembers,   VAR_BOOLEAN },
+  { "ImplicitClasses",         &ImplicitClasses,       VAR_BOOLEAN },
+  { "ImplicitAnyClasses",      &ImplicitAnyClasses,    VAR_BOOLEAN },
+  { "KeepAliveTimeout",                &KeepAliveTimeout,      VAR_INTEGER },
+  { "KeepAlive",               &KeepAlive,             VAR_BOOLEAN },
+  { "LimitRequestBody",                &MaxRequestSize,        VAR_INTEGER },
+  { "ListenBackLog",           &ListenBackLog,         VAR_INTEGER },
+  { "LogFilePerm",             &LogFilePerm,           VAR_INTEGER },
+  { "MaxActiveJobs",           &MaxActiveJobs,         VAR_INTEGER },
+  { "MaxClients",              &MaxClients,            VAR_INTEGER },
+  { "MaxClientsPerHost",       &MaxClientsPerHost,     VAR_INTEGER },
+  { "MaxCopies",               &MaxCopies,             VAR_INTEGER },
+  { "MaxJobs",                 &MaxJobs,               VAR_INTEGER },
+  { "MaxJobsPerPrinter",       &MaxJobsPerPrinter,     VAR_INTEGER },
+  { "MaxJobsPerUser",          &MaxJobsPerUser,        VAR_INTEGER },
+  { "MaxLogSize",              &MaxLogSize,            VAR_INTEGER },
+  { "MaxRequestSize",          &MaxRequestSize,        VAR_INTEGER },
+  { "PageLog",                 &PageLog,               VAR_STRING },
+  { "PreserveJobFiles",                &JobFiles,              VAR_BOOLEAN },
+  { "PreserveJobHistory",      &JobHistory,            VAR_BOOLEAN },
+  { "Printcap",                        &Printcap,              VAR_STRING },
+  { "PrintcapGUI",             &PrintcapGUI,           VAR_STRING },
+  { "RemoteRoot",              &RemoteRoot,            VAR_STRING },
+  { "RequestRoot",             &RequestRoot,           VAR_STRING },
+  { "RIPCache",                        &RIPCache,              VAR_STRING },
+  { "RunAsUser",               &RunAsUser,             VAR_BOOLEAN },
+  { "RootCertDuration",                &RootCertDuration,      VAR_INTEGER },
+  { "ServerAdmin",             &ServerAdmin,           VAR_STRING },
+  { "ServerBin",               &ServerBin,             VAR_STRING },
 #ifdef HAVE_SSL
-  { "ServerCertificate",ServerCertificate,     VAR_STRING,     sizeof(ServerCertificate) },
-  { "ServerKey",       ServerKey,              VAR_STRING,     sizeof(ServerKey) },
+  { "ServerCertificate",       &ServerCertificate,     VAR_STRING },
+  { "ServerKey",               &ServerKey,             VAR_STRING },
 #endif /* HAVE_SSL */
-  { "ServerName",      ServerName,             VAR_STRING,     sizeof(ServerName) },
-  { "ServerRoot",      ServerRoot,             VAR_STRING,     sizeof(ServerRoot) },
-  { "TempDir",         TempDir,                VAR_STRING,     sizeof(TempDir) },
-  { "Timeout",         &Timeout,               VAR_INTEGER,    0 }
+  { "ServerName",              &ServerName,            VAR_STRING },
+  { "ServerRoot",              &ServerRoot,            VAR_STRING },
+  { "TempDir",                 &TempDir,               VAR_STRING },
+  { "Timeout",                 &Timeout,               VAR_INTEGER }
 };
 #define NUM_VARS       (sizeof(variables) / sizeof(variables[0]))
 
+
 static unsigned                ones[4] =
                        {
                          0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
@@ -199,20 +199,21 @@ static int        get_addr_and_mask(const char *value, unsigned *ip,
  * 'ReadConfiguration()' - Read the cupsd.conf file.
  */
 
-int                            /* O - 1 if file read successfully, 0 otherwise */
+int                                    /* O - 1 on success, 0 otherwise */
 ReadConfiguration(void)
 {
-  int          i;              /* Looping var */
-  FILE         *fp;            /* Configuration file */
-  int          status;         /* Return status */
-  char         directory[1024],/* Configuration directory */
-               *slash;         /* Directory separator */
+  int          i;                      /* Looping var */
+  FILE         *fp;                    /* Configuration file */
+  int          status;                 /* Return status */
+  char         temp[1024],             /* Temporary buffer */
+               *slash;                 /* Directory separator */
   char         type[MIME_MAX_SUPER + MIME_MAX_TYPE];
-                               /* MIME type name */
-  struct rlimit        limit;          /* Runtime limit */
-  char         *language;      /* Language string */
-  struct passwd        *user;          /* Default user */
-  struct group *group;         /* Default group */
+                                       /* MIME type name */
+  struct rlimit        limit;                  /* Runtime limit */
+  char         *language;              /* Language string */
+  struct passwd        *user;                  /* Default user */
+  struct group *group;                 /* Default group */
+  int          run_user;               /* User that will be running cupsd */
 
 
  /*
@@ -271,25 +272,28 @@ ReadConfiguration(void)
   * String options...
   */
 
-  gethostname(ServerName, sizeof(ServerName));
-  snprintf(ServerAdmin, sizeof(ServerAdmin), "root@%s", ServerName);
-  strcpy(ServerBin, CUPS_SERVERBIN);
-  strcpy(RequestRoot, CUPS_REQUESTS);
-  strcpy(DocumentRoot, CUPS_DOCROOT);
-  strcpy(DataDir, CUPS_DATADIR);
-  strcpy(AccessLog, CUPS_LOGDIR "/access_log");
-  strcpy(ErrorLog, CUPS_LOGDIR "/error_log");
-  strcpy(PageLog, CUPS_LOGDIR "/page_log");
-  strcpy(Printcap, "/etc/printcap");
-  strcpy(PrintcapGUI, "/usr/bin/glpoptions");
-  strcpy(FontPath, CUPS_FONTPATH);
-  strcpy(RemoteRoot, "remroot");
-
-  strcpy(ServerRoot, ConfigurationFile);
-  if ((slash = strrchr(ServerRoot, '/')) != NULL)
+  gethostname(temp, sizeof(temp));
+  SetString(&ServerName, temp);
+  SetStringf(&ServerAdmin, "root@%s", temp);
+  SetString(&ServerBin, CUPS_SERVERBIN);
+  SetString(&RequestRoot, CUPS_REQUESTS);
+  SetString(&DocumentRoot, CUPS_DOCROOT);
+  SetString(&DataDir, CUPS_DATADIR);
+  SetString(&AccessLog, CUPS_LOGDIR "/access_log");
+  SetString(&ErrorLog, CUPS_LOGDIR "/error_log");
+  SetString(&PageLog, CUPS_LOGDIR "/page_log");
+  SetString(&Printcap, "/etc/printcap");
+  SetString(&PrintcapGUI, "/usr/bin/glpoptions");
+  SetString(&FontPath, CUPS_FONTPATH);
+  SetString(&RemoteRoot, "remroot");
+
+  strlcpy(temp, ConfigurationFile, sizeof(temp));
+  if ((slash = strrchr(temp, '/')) != NULL)
     *slash = '\0';
 
-  Classification[0] = '\0';
+  SetString(&ServerRoot, temp);
+
+  ClearString(&Classification);
   ClassifyOverride  = 0;
 
 #ifdef HAVE_SSL
@@ -300,11 +304,11 @@ ReadConfiguration(void)
     ServerCertificatesArray = NULL;
   }
 
-  strcpy(ServerCertificate, "/var/root/Library/Keychains/CUPS");
+  SetString(&ServerCertificate, "/var/root/Library/Keychains/CUPS");
 
 #  else
-  strcpy(ServerCertificate, "ssl/server.crt");
-  strcpy(ServerKey, "ssl/server.key");
+  SetString(&ServerCertificate, "ssl/server.crt");
+  SetString(&ServerKey, "ssl/server.key");
 #  endif /* HAVE_CDSASSL */
 #endif /* HAVE_SSL */
 
@@ -313,16 +317,15 @@ ReadConfiguration(void)
   else if (strcmp(language, "C") == 0 || strcmp(language, "POSIX") == 0)
     language = "en";
 
-  strlcpy(DefaultLanguage, language, sizeof(DefaultLanguage));
+  SetString(&DefaultLanguage, language);
+  SetString(&DefaultCharset, DEFAULT_CHARSET);
 
-  strcpy(DefaultCharset, DEFAULT_CHARSET);
-
-  strcpy(RIPCache, "8m");
+  SetString(&RIPCache, "8m");
 
   if (getenv("TMPDIR") == NULL)
-    strcpy(TempDir, CUPS_REQUESTS "/tmp");
+    SetStringf(&TempDir, "TMPDIR=%s", CUPS_REQUESTS "/tmp");
   else
-    strlcpy(TempDir, getenv("TMPDIR"), sizeof(TempDir));
+    SetStringf(&TempDir, "TMPDIR=%s", getenv("TMPDIR"));
 
  /*
   * Find the default system group: "sys", "system", or "root"...
@@ -335,7 +338,7 @@ ReadConfiguration(void)
 
   if (group != NULL)
   {
-    strcpy(SystemGroups[0], CUPS_DEFAULT_GROUP);
+    SetString(&SystemGroups[0], CUPS_DEFAULT_GROUP);
     Group = group->gr_gid;
   }
   else
@@ -345,12 +348,12 @@ ReadConfiguration(void)
 
     if (group != NULL)
     {
-      strcpy(SystemGroups[0], group->gr_name);
+      SetString(&SystemGroups[0], group->gr_name);
       Group = 0;
     }
     else
     {
-      strcpy(SystemGroups[0], "unknown");
+      SetString(&SystemGroups[0], "unknown");
       Group = 0;
     }
   }
@@ -370,46 +373,48 @@ ReadConfiguration(void)
   * Numeric options...
   */
 
-  ConfigFilePerm    = 0600;
-  LogFilePerm       = 0644;
-
-  FileDevice        = FALSE;
-  FilterLevel       = 0;
-  FilterLimit       = 0;
-  FilterNice        = 0;
-  HostNameLookups   = FALSE;
-  ImplicitClasses   = TRUE;
-  KeepAlive         = TRUE;
-  KeepAliveTimeout  = DEFAULT_KEEPALIVE;
-  ListenBackLog     = SOMAXCONN;
-  LogLevel          = L_ERROR;
-  MaxClients        = 100;
-  MaxClientsPerHost = 0;
-  MaxLogSize        = 1024 * 1024;
-  MaxRequestSize    = 0;
-  RootCertDuration  = 300;
-  RunAsUser         = FALSE;
-  Timeout           = DEFAULT_TIMEOUT;
-
-  BrowseInterval    = DEFAULT_INTERVAL;
-  BrowsePort        = ippPort();
-  BrowseShortNames  = TRUE;
-  BrowseTimeout     = DEFAULT_TIMEOUT;
-  Browsing          = TRUE;
-  NumBrowsers       = 0;
-  NumPolled         = 0;
-
-  NumListeners      = 0;
-
-  JobHistory        = DEFAULT_HISTORY;
-  JobFiles          = DEFAULT_FILES;
-  JobAutoPurge      = 0;
-
-  MaxJobs           = 0;
-  MaxActiveJobs     = 0;
-  MaxJobsPerPrinter = 0;
-  MaxJobsPerUser    = 0;
-  MaxCopies         = 100;
+  ConfigFilePerm      = 0640;
+  LogFilePerm         = 0644;
+
+  FileDevice          = FALSE;
+  FilterLevel         = 0;
+  FilterLimit         = 0;
+  FilterNice          = 0;
+  HostNameLookups     = FALSE;
+  ImplicitClasses     = TRUE;
+  ImplicitAnyClasses  = FALSE;
+  HideImplicitMembers = TRUE;
+  KeepAlive           = TRUE;
+  KeepAliveTimeout    = DEFAULT_KEEPALIVE;
+  ListenBackLog       = SOMAXCONN;
+  LogLevel            = L_ERROR;
+  MaxClients          = 100;
+  MaxClientsPerHost   = 0;
+  MaxLogSize          = 1024 * 1024;
+  MaxRequestSize      = 0;
+  RootCertDuration    = 300;
+  RunAsUser           = FALSE;
+  Timeout             = DEFAULT_TIMEOUT;
+
+  BrowseInterval      = DEFAULT_INTERVAL;
+  BrowsePort          = ippPort();
+  BrowseProtocols     = BROWSE_CUPS;
+  BrowseShortNames    = TRUE;
+  BrowseTimeout       = DEFAULT_TIMEOUT;
+  Browsing            = TRUE;
+  NumBrowsers         = 0;
+  NumPolled           = 0;
+
+  NumListeners        = 0;
+
+  JobHistory          = DEFAULT_HISTORY;
+  JobFiles            = DEFAULT_FILES;
+  JobAutoPurge        = 0;
+  MaxJobs             = 0;
+  MaxActiveJobs       = 0;
+  MaxJobsPerPrinter   = 0;
+  MaxJobsPerUser      = 0;
+  MaxCopies           = 100;
 
  /*
   * Read the configuration file...
@@ -425,6 +430,11 @@ ReadConfiguration(void)
   if (!status)
     return (0);
 
+  if (RunAsUser)
+    run_user = User;
+  else
+    run_user = getuid();
+
  /*
   * Use the default system group if none was supplied in cupsd.conf...
   */
@@ -461,40 +471,25 @@ ReadConfiguration(void)
   */
 
   if (DocumentRoot[0] != '/')
-  {
-    snprintf(directory, sizeof(directory), "%s/%s", ServerRoot, DocumentRoot);
-    strlcpy(DocumentRoot, directory, sizeof(DocumentRoot));
-  }
+    SetStringf(&DocumentRoot, "%s/%s", ServerRoot, DocumentRoot);
 
   if (RequestRoot[0] != '/')
-  {
-    snprintf(directory, sizeof(directory), "%s/%s", ServerRoot, RequestRoot);
-    strlcpy(RequestRoot, directory, sizeof(RequestRoot));
-  }
+    SetStringf(&RequestRoot, "%s/%s", ServerRoot, RequestRoot);
 
   if (ServerBin[0] != '/')
-  {
-    snprintf(directory, sizeof(directory), "%s/%s", ServerRoot, ServerBin);
-    strlcpy(ServerBin, directory, sizeof(ServerBin));
-  }
+    SetStringf(&ServerBin, "%s/%s", ServerRoot, ServerBin);
 
 #ifdef HAVE_SSL
   if (ServerCertificate[0] != '/')
-  {
-    snprintf(directory, sizeof(directory), "%s/%s", ServerRoot, ServerCertificate);
-    strlcpy(ServerCertificate, directory, sizeof(ServerCertificate));
-  }
+    SetStringf(&ServerCertificate, "%s/%s", ServerRoot, ServerCertificate);
 
-  chown(ServerCertificate, User, Group);
+  chown(ServerCertificate, run_user, Group);
   chmod(ServerCertificate, ConfigFilePerm);
 
   if (ServerKey[0] != '/')
-  {
-    snprintf(directory, sizeof(directory), "%s/%s", ServerRoot, ServerKey);
-    strlcpy(ServerKey, directory, sizeof(ServerKey));
-  }
+    SetStringf(&ServerKey, "%s/%s", ServerRoot, ServerKey);
 
-  chown(ServerKey, User, Group);
+  chown(ServerKey, run_user, Group);
   chmod(ServerKey, ConfigFilePerm);
 #endif /* HAVE_SSL */
 
@@ -503,43 +498,43 @@ ReadConfiguration(void)
   * writable by the user and group in the cupsd.conf file...
   */
 
-  chown(ServerRoot, User, Group);
+  chown(ServerRoot, run_user, Group);
   chmod(ServerRoot, 0755);
 
-  snprintf(directory, sizeof(directory), "%s/certs", ServerRoot);
-  chown(directory, User, Group);
-  chmod(directory, 0711);
+  snprintf(temp, sizeof(temp), "%s/certs", ServerRoot);
+  chown(temp, run_user, Group);
+  chmod(temp, 0711);
 
-  snprintf(directory, sizeof(directory), "%s/ppd", ServerRoot);
-  chown(directory, User, Group);
-  chmod(directory, 0755);
+  snprintf(temp, sizeof(temp), "%s/ppd", ServerRoot);
+  chown(temp, User, Group);
+  chmod(temp, 0755);
 
-  snprintf(directory, sizeof(directory), "%s/ssl", ServerRoot);
-  chown(directory, User, Group);
-  chmod(directory, 0700);
+  snprintf(temp, sizeof(temp), "%s/ssl", ServerRoot);
+  chown(temp, run_user, Group);
+  chmod(temp, 0700);
 
-  snprintf(directory, sizeof(directory), "%s/cupsd.conf", ServerRoot);
-  chown(directory, User, Group);
-  chmod(directory, ConfigFilePerm);
+  snprintf(temp, sizeof(temp), "%s/cupsd.conf", ServerRoot);
+  chown(temp, run_user, Group);
+  chmod(temp, ConfigFilePerm);
 
-  snprintf(directory, sizeof(directory), "%s/classes.conf", ServerRoot);
-  chown(directory, User, Group);
-  chmod(directory, ConfigFilePerm);
+  snprintf(temp, sizeof(temp), "%s/classes.conf", ServerRoot);
+  chown(temp, run_user, Group);
+  chmod(temp, ConfigFilePerm);
 
-  snprintf(directory, sizeof(directory), "%s/printers.conf", ServerRoot);
-  chown(directory, User, Group);
-  chmod(directory, ConfigFilePerm);
+  snprintf(temp, sizeof(temp), "%s/printers.conf", ServerRoot);
+  chown(temp, run_user, Group);
+  chmod(temp, ConfigFilePerm);
 
-  snprintf(directory, sizeof(directory), "%s/passwd.md5", ServerRoot);
-  chown(directory, User, Group);
-  chmod(directory, 0600);
+  snprintf(temp, sizeof(temp), "%s/passwd.md5", ServerRoot);
+  chown(temp, User, Group);
+  chmod(temp, 0600);
 
  /*
   * Make sure the request and temporary directories have the right
   * permissions...
   */
 
-  chown(RequestRoot, User, Group);
+  chown(RequestRoot, run_user, Group);
   chmod(RequestRoot, 0700);
 
   if (strncmp(TempDir, RequestRoot, strlen(RequestRoot)) == 0)
@@ -549,8 +544,8 @@ ReadConfiguration(void)
     * is under the spool directory...
     */
 
-    chown(TempDir, User, Group);
-    chmod(TempDir, 01700);
+    chown(TempDir, run_user, Group);
+    chmod(TempDir, 01770);
   }
 
  /*
@@ -579,10 +574,10 @@ ReadConfiguration(void)
   if (MaxActiveJobs > (limit.rlim_max / 3))
     MaxActiveJobs = limit.rlim_max / 3;
 
-  if (strcasecmp(Classification, "none") == 0)
-    Classification[0] = '\0';
+  if (Classification && strcasecmp(Classification, "none") == 0)
+    ClearString(&Classification);
 
-  if (Classification[0])
+  if (Classification)
     LogMessage(L_INFO, "Security set to \"%s\"", Classification);
 
  /*
@@ -590,12 +585,7 @@ ReadConfiguration(void)
   */
 
   if (MaxClientsPerHost <= 0)
-  {
-    MaxClientsPerHost = MaxClients / 10;
-
-    if (MaxClientsPerHost < 4)
-      MaxClientsPerHost = 4;
-  }
+    MaxClientsPerHost = MaxClients;
 
   if (MaxClientsPerHost > MaxClients)
     MaxClientsPerHost = MaxClients;
@@ -607,10 +597,10 @@ ReadConfiguration(void)
   * Read the MIME type and conversion database...
   */
 
-  snprintf(directory, sizeof(directory), "%s/filter", ServerBin);
+  snprintf(temp, sizeof(temp), "%s/filter", ServerBin);
 
   MimeDatabase = mimeNew();
-  mimeMerge(MimeDatabase, ServerRoot, directory);
+  mimeMerge(MimeDatabase, ServerRoot, temp);
 
  /*
   * Create a list of MIME types for the document-format-supported
@@ -638,8 +628,8 @@ ReadConfiguration(void)
   * Load banners...
   */
 
-  snprintf(directory, sizeof(directory), "%s/banners", DataDir);
-  LoadBanners(directory);
+  snprintf(temp, sizeof(temp), "%s/banners", DataDir);
+  LoadBanners(temp);
 
  /*
   * Load printers and classes...
@@ -652,11 +642,11 @@ ReadConfiguration(void)
   * Load devices and PPDs...
   */
 
-  snprintf(directory, sizeof(directory), "%s/model", DataDir);
-  LoadPPDs(directory);
+  snprintf(temp, sizeof(temp), "%s/model", DataDir);
+  LoadPPDs(temp);
 
-  snprintf(directory, sizeof(directory), "%s/backend", ServerBin);
-  LoadDevices(directory);
+  snprintf(temp, sizeof(temp), "%s/backend", ServerBin);
+  LoadDevices(temp);
 
 #ifdef HAVE_CDSASSL
   ServerCertificatesArray = CDSAGetServerCerts();
@@ -1315,7 +1305,7 @@ read_configuration(FILE *fp)              /* I - File to read from */
       char *valueptr; /* Pointer into value */
 
 
-      for (i = 0; i < MAX_SYSTEM_GROUPS; i ++)
+      for (i = NumSystemGroups; i < MAX_SYSTEM_GROUPS; i ++)
       {
         for (valueptr = value; *valueptr; valueptr ++)
          if (isspace(*valueptr) || *valueptr == ',')
@@ -1324,7 +1314,7 @@ read_configuration(FILE *fp)              /* I - File to read from */
         if (*valueptr)
           *valueptr++ = '\0';
 
-        strlcpy(SystemGroups[i], value, sizeof(SystemGroups[0]));
+        SetString(SystemGroups + i, value);
 
         while (*value == ',' || isspace(*value))
          value ++;
@@ -1458,7 +1448,7 @@ read_configuration(FILE *fp)              /* I - File to read from */
            break;
 
        case VAR_STRING :
-           strlcpy((char *)var->ptr, value, var->size);
+           SetString((char **)var->ptr, value);
            break;
       }
     }
@@ -2191,5 +2181,5 @@ CDSAGetServerCerts(void)
 
 
 /*
- * End of "$Id: conf.c,v 1.77.2.23 2003/01/29 15:38:45 mike Exp $".
+ * End of "$Id: conf.c,v 1.77.2.24 2003/01/29 20:08:20 mike Exp $".
  */
index 25b9091fcb7a29f878c54b712345aa1f2437c6c3..afceb1fb5ed9b4a961a0da6cdd7ff6667757eca6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: conf.h,v 1.36.2.13 2003/01/24 19:19:46 mike Exp $"
+ * "$Id: conf.h,v 1.36.2.14 2003/01/29 20:08:21 mike Exp $"
  *
  *   Configuration file definitions for the Common UNIX Printing System (CUPS)
  *   scheduler.
  * Globals...
  */
 
-VAR char               ConfigurationFile[256]  VALUE(CUPS_SERVERROOT "/cupsd.conf"),
+VAR char               *ConfigurationFile      VALUE(NULL),
                                        /* Configuration file to use */
-                       ServerName[256]         VALUE(""),
+                       *ServerName             VALUE(NULL),
                                        /* FQDN for server */
-                       ServerAdmin[256]        VALUE(""),
+                       *ServerAdmin            VALUE(NULL),
                                        /* Administrator's email */
-                       ServerRoot[1024]        VALUE(CUPS_SERVERROOT),
+                       *ServerRoot             VALUE(NULL),
                                        /* Root directory for scheduler */
-                       ServerBin[1024]         VALUE(CUPS_SERVERBIN),
+                       *ServerBin              VALUE(NULL),
                                        /* Root directory for binaries */
-                       RequestRoot[1024]       VALUE(CUPS_REQUESTS),
+                       *RequestRoot            VALUE(NULL),
                                        /* Directory for request files */
-                       DocumentRoot[1024]      VALUE(CUPS_DOCROOT);
+                       *DocumentRoot           VALUE(NULL);
                                        /* Root directory for documents */
 VAR int                        NumSystemGroups         VALUE(0);
                                        /* Number of system group names */
-VAR char               SystemGroups[MAX_SYSTEM_GROUPS][32],
+VAR char               *SystemGroups[MAX_SYSTEM_GROUPS],
                                        /* System group names */
-                       AccessLog[1024]         VALUE(CUPS_LOGDIR "/access_log"),
+                       *AccessLog              VALUE(NULL),
                                        /* Access log filename */
-                       ErrorLog[1024]          VALUE(CUPS_LOGDIR "/error_log"),
+                       *ErrorLog               VALUE(NULL),
                                        /* Error log filename */
-                       PageLog[1024]           VALUE(CUPS_LOGDIR "/page_log"),
+                       *PageLog                VALUE(NULL),
                                        /* Page log filename */
-                       DataDir[1024]           VALUE(CUPS_DATADIR),
+                       *DataDir                VALUE(NULL),
                                        /* Data file directory */
-                       DefaultLanguage[32]     VALUE("C"),
+                       *DefaultLanguage        VALUE(NULL),
                                        /* Default language encoding */
-                       DefaultCharset[32]      VALUE(DEFAULT_CHARSET),
+                       *DefaultCharset         VALUE(NULL),
                                        /* Default charset */
-                       RIPCache[32]            VALUE("8m"),
+                       *RIPCache               VALUE(NULL),
                                        /* Amount of memory for RIPs */
-                       TempDir[1024]           VALUE(CUPS_REQUESTS "/tmp"),
+                       *TempDir                VALUE(NULL),
                                        /* Temporary directory */
-                       Printcap[1024]          VALUE(""),
+                       *Printcap               VALUE(NULL),
                                        /* Printcap file */
-                       PrintcapGUI[1024]       VALUE("/usr/bin/glpoptions"),
+                       *PrintcapGUI            VALUE(NULL),
                                        /* GUI program to use for IRIX */
-                       FontPath[1024]          VALUE(CUPS_FONTPATH),
+                       *FontPath               VALUE(NULL),
                                        /* Font search path */
-                       RemoteRoot[32]          VALUE("remroot"),
+                       *RemoteRoot             VALUE(NULL),
                                        /* Remote root user */
-                       Classification[IPP_MAX_NAME]    VALUE("");
+                       *Classification         VALUE(NULL);
                                        /* Classification of system */
 VAR int                        ClassifyOverride        VALUE(0),
                                        /* Allow overrides? */
@@ -161,9 +161,9 @@ VAR const char              **MimeTypes             VALUE(NULL);
                                        /* Array of MIME types */
 
 #ifdef HAVE_SSL
-VAR char               ServerCertificate[1024] VALUE("ssl/server.crt"),
+VAR char               *ServerCertificate      VALUE(NULL),
                                        /* Server certificate file */
-                       ServerKey[1024]         VALUE("ssl/server.key");
+                       *ServerKey              VALUE(NULL);
                                        /* Server key file */
 #endif /* HAVE_SSL */
 #ifdef HAVE_CDSASSL
@@ -188,5 +188,5 @@ extern int  LogPage(job_t *job, const char *page);
 
 
 /*
- * End of "$Id: conf.h,v 1.36.2.13 2003/01/24 19:19:46 mike Exp $".
+ * End of "$Id: conf.h,v 1.36.2.14 2003/01/29 20:08:21 mike Exp $".
  */
index 374949286f114b46063e3df7c6e7506e52cad062..984d26df534df487682bcb6d22dfd681951331ec 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: cupsd.h,v 1.28.2.12 2003/01/29 15:38:46 mike Exp $"
+ * "$Id: cupsd.h,v 1.28.2.13 2003/01/29 20:08:21 mike Exp $"
  *
  *   Main header file for the Common UNIX Printing System (CUPS) scheduler.
  *
@@ -167,7 +167,7 @@ VAR fd_set          InputSet,       /* Input files for select() */
 
 VAR int                        NeedReload      VALUE(TRUE);
                                        /* Need to load configuration? */
-VAR char               TZ[1024]        VALUE("TZ=GMT");
+VAR char               *TZ             VALUE(NULL);
                                        /* Timezone configuration */
 
 VAR ipp_t              *Devices        VALUE(NULL),
@@ -181,13 +181,16 @@ VAR ipp_t         *Devices        VALUE(NULL),
  */
 
 extern void    CatchChildSignals(void);
+extern void    ClearString(char **s);
 extern void    IgnoreChildSignals(void);
 extern void    LoadDevices(const char *d);
 extern void    LoadPPDs(const char *d);
+extern void    SetString(char **s, const char *v);
+extern void    SetStringf(char **s, const char *f, ...);
 extern void    StartServer(void);
 extern void    StopServer(void);
 
 
 /*
- * End of "$Id: cupsd.h,v 1.28.2.12 2003/01/29 15:38:46 mike Exp $".
+ * End of "$Id: cupsd.h,v 1.28.2.13 2003/01/29 20:08:21 mike Exp $".
  */
index 7af3292747e7f49dff8c190996f570603d978cc4..3c219a4cc5e99ede30edf31d978f27bcac82b86c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: dirsvc.c,v 1.73.2.22 2003/01/24 18:00:54 mike Exp $"
+ * "$Id: dirsvc.c,v 1.73.2.23 2003/01/29 20:08:21 mike Exp $"
  *
  *   Directory services routines for the Common UNIX Printing System (CUPS).
  *
@@ -154,7 +154,7 @@ ProcessBrowseData(const char   *uri,        /* I - URI of printer/class */
     {
       if ((p = FindClass(resource + 9)) != NULL)
       {
-        if (strcasecmp(p->hostname, host) != 0 && p->hostname[0])
+        if (p->hostname && strcasecmp(p->hostname, host) != 0)
        {
         /*
          * Nope, this isn't the same host; if the hostname isn't the local host,
@@ -172,22 +172,22 @@ ProcessBrowseData(const char   *uri,      /* I - URI of printer/class */
 
           p = NULL;
        }
-       else if (!p->hostname[0])
+       else if (!p->hostname)
        {
-          strlcpy(p->hostname, host, sizeof(p->hostname));
-         strlcpy(p->uri, uri, sizeof(p->uri));
-         strlcpy(p->device_uri, uri, sizeof(p->device_uri));
+          SetString(&p->hostname, host);
+         SetString(&p->uri, uri);
+         SetString(&p->device_uri, uri);
           update = 1;
         }
       }
       else
         strlcpy(name, resource + 9, sizeof(name));
     }
-    else if (p != NULL && !p->hostname[0])
+    else if (p != NULL && !p->hostname)
     {
-      strlcpy(p->hostname, host, sizeof(p->hostname));
-      strlcpy(p->uri, uri, sizeof(p->uri));
-      strlcpy(p->device_uri, uri, sizeof(p->device_uri));
+      SetString(&p->hostname, host);
+      SetString(&p->uri, uri);
+      SetString(&p->device_uri, uri);
       update = 1;
     }
 
@@ -207,9 +207,9 @@ ProcessBrowseData(const char   *uri,        /* I - URI of printer/class */
 
       p->type      = type;
       p->accepting = 1;
-      strlcpy(p->uri, uri, sizeof(p->uri));
-      strlcpy(p->device_uri, uri, sizeof(p->device_uri));
-      strlcpy(p->hostname, host, sizeof(p->hostname));
+      SetString(&p->uri, uri);
+      SetString(&p->device_uri, uri);
+      SetString(&p->hostname, host);
 
       update = 1;
     }
@@ -229,7 +229,7 @@ ProcessBrowseData(const char   *uri,        /* I - URI of printer/class */
     {
       if ((p = FindPrinter(resource + 10)) != NULL)
       {
-        if (strcasecmp(p->hostname, host) != 0 && p->hostname[0])
+        if (p->hostname && strcasecmp(p->hostname, host) != 0)
        {
         /*
          * Nope, this isn't the same host; if the hostname isn't the local host,
@@ -239,30 +239,29 @@ ProcessBrowseData(const char   *uri,      /* I - URI of printer/class */
 
          if (p->type & CUPS_PRINTER_REMOTE)
          {
-            strlcat(p->name, "@", sizeof(p->name));
-           strlcat(p->name, p->hostname, sizeof(p->name));
+           SetStringf(&p->name, "%s@%s", p->name, p->hostname);
            SetPrinterAttrs(p);
            SortPrinters();
          }
 
           p = NULL;
        }
-       else if (!p->hostname[0])
+       else if (!p->hostname)
        {
-          strlcpy(p->hostname, host, sizeof(p->hostname));
-         strlcpy(p->uri, uri, sizeof(p->uri));
-         strlcpy(p->device_uri, uri, sizeof(p->device_uri));
+          SetString(&p->hostname, host);
+         SetString(&p->uri, uri);
+         SetString(&p->device_uri, uri);
           update = 1;
         }
       }
       else
         strlcpy(name, resource + 10, sizeof(name));
     }
-    else if (p != NULL && !p->hostname[0])
+    else if (p != NULL && !p->hostname)
     {
-      strlcpy(p->hostname, host, sizeof(p->hostname));
-      strlcpy(p->uri, uri, sizeof(p->uri));
-      strlcpy(p->device_uri, uri, sizeof(p->device_uri));
+      SetString(&p->hostname, host);
+      SetString(&p->uri, uri);
+      SetString(&p->device_uri, uri);
       update = 1;
     }
 
@@ -282,9 +281,9 @@ ProcessBrowseData(const char   *uri,        /* I - URI of printer/class */
 
       p->type      = type;
       p->accepting = 1;
-      strlcpy(p->hostname, host, sizeof(p->hostname));
-      strlcpy(p->uri, uri, sizeof(p->uri));
-      strlcpy(p->device_uri, uri, sizeof(p->device_uri));
+      SetString(&p->hostname, host);
+      SetString(&p->uri, uri);
+      SetString(&p->device_uri, uri);
 
       update = 1;
     }
@@ -303,15 +302,15 @@ ProcessBrowseData(const char   *uri,      /* I - URI of printer/class */
     update  = 1;
   }
 
-  if (strcmp(p->location, location))
+  if (!p->location || strcmp(p->location, location))
   {
-    strlcpy(p->location, location, sizeof(p->location));
+    SetString(&p->location, location);
     update = 1;
   }
 
-  if (strcmp(p->info, info))
+  if (!p->info || strcmp(p->info, info))
   {
-    strlcpy(p->info, info, sizeof(p->info));
+    SetString(&p->info, info);
     update = 1;
   }
 
@@ -328,9 +327,9 @@ ProcessBrowseData(const char   *uri,        /* I - URI of printer/class */
     snprintf(local_make_model, sizeof(local_make_model),
              "%s on %s", make_model, host);
 
-  if (strcmp(p->make_model, local_make_model))
+  if (!p->make_model || strcmp(p->make_model, local_make_model))
   {
-    strlcpy(p->make_model, local_make_model, sizeof(p->make_model));
+    SetString(&p->make_model, local_make_model);
     update = 1;
   }
 
@@ -404,8 +403,8 @@ ProcessBrowseData(const char   *uri,        /* I - URI of printer/class */
          pclass->accepting = 1;
          pclass->state     = IPP_PRINTER_IDLE;
 
-          strcpy(pclass->location, p->location);
-          strcpy(pclass->info, p->info);
+          SetString(&pclass->location, p->location);
+          SetString(&pclass->info, p->info);
 
           SetPrinterAttrs(pclass);
 
@@ -1882,5 +1881,5 @@ UpdateSLPBrowse(void)
 
 
 /*
- * End of "$Id: dirsvc.c,v 1.73.2.22 2003/01/24 18:00:54 mike Exp $".
+ * End of "$Id: dirsvc.c,v 1.73.2.23 2003/01/29 20:08:21 mike Exp $".
  */
index cba9928aa6ed6378ac8eb3f31dba0db5a6506134..a979609236fe6619a5558050ddea0b8268fa23ee 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: ipp.c,v 1.127.2.38 2003/01/24 14:06:40 mike Exp $"
+ * "$Id: ipp.c,v 1.127.2.39 2003/01/29 20:08:22 mike Exp $"
  *
  *   IPP routines for the Common UNIX Printing System (CUPS) scheduler.
  *
@@ -675,10 +675,10 @@ add_class(client_t        *con,           /* I - Client connection */
   */
 
   if ((attr = ippFindAttribute(con->request, "printer-location", IPP_TAG_TEXT)) != NULL)
-    strlcpy(pclass->location, attr->values[0].string.text, sizeof(pclass->location));
+    SetString(&pclass->location, attr->values[0].string.text);
 
   if ((attr = ippFindAttribute(con->request, "printer-info", IPP_TAG_TEXT)) != NULL)
-    strlcpy(pclass->info, attr->values[0].string.text, sizeof(pclass->info));
+    SetString(&pclass->info, attr->values[0].string.text);
 
   if ((attr = ippFindAttribute(con->request, "printer-is-accepting-jobs", IPP_TAG_BOOLEAN)) != NULL)
   {
@@ -710,15 +710,13 @@ add_class(client_t        *con,           /* I - Client connection */
     strlcpy(pclass->state_message, attr->values[0].string.text,
             sizeof(pclass->state_message));
   if ((attr = ippFindAttribute(con->request, "job-sheets-default", IPP_TAG_ZERO)) != NULL &&
-      !Classification[0])
+      !Classification)
   {
-    strlcpy(pclass->job_sheets[0], attr->values[0].string.text,
-            sizeof(pclass->job_sheets[0]));
+    SetString(&pclass->job_sheets[0], attr->values[0].string.text);
     if (attr->num_values > 1)
-      strlcpy(pclass->job_sheets[1], attr->values[1].string.text,
-              sizeof(pclass->job_sheets[1]));
+      SetString(&pclass->job_sheets[1], attr->values[1].string.text);
     else
-      strcpy(pclass->job_sheets[1], "none");
+      SetString(&pclass->job_sheets[1], "none");
   }
   if ((attr = ippFindAttribute(con->request, "requesting-user-name-allowed",
                                IPP_TAG_ZERO)) != NULL)
@@ -1087,12 +1085,10 @@ add_printer(client_t        *con,       /* I - Client connection */
   */
 
   if ((attr = ippFindAttribute(con->request, "printer-location", IPP_TAG_TEXT)) != NULL)
-    strlcpy(printer->location, attr->values[0].string.text,
-            sizeof(printer->location));
+    SetString(&printer->location, attr->values[0].string.text);
 
   if ((attr = ippFindAttribute(con->request, "printer-info", IPP_TAG_TEXT)) != NULL)
-    strlcpy(printer->info, attr->values[0].string.text,
-            sizeof(printer->info));
+    SetString(&printer->info, attr->values[0].string.text);
 
   if ((attr = ippFindAttribute(con->request, "device-uri", IPP_TAG_URI)) != NULL)
   {
@@ -1156,8 +1152,7 @@ add_printer(client_t        *con, /* I - Client connection */
     LogMessage(L_INFO, "Setting %s device-uri to \"%s\" (was \"%s\".)",
                printer->name, attr->values[0].string.text, printer->device_uri);
 
-    strlcpy(printer->device_uri, attr->values[0].string.text,
-            sizeof(printer->device_uri));
+    SetString(&printer->device_uri, attr->values[0].string.text);
   }
 
   if ((attr = ippFindAttribute(con->request, "printer-is-accepting-jobs", IPP_TAG_BOOLEAN)) != NULL)
@@ -1192,13 +1187,11 @@ add_printer(client_t        *con,       /* I - Client connection */
   if ((attr = ippFindAttribute(con->request, "job-sheets-default", IPP_TAG_ZERO)) != NULL &&
       !Classification[0])
   {
-    strlcpy(printer->job_sheets[0], attr->values[0].string.text,
-            sizeof(printer->job_sheets[0]));
+    SetString(&printer->job_sheets[0], attr->values[0].string.text);
     if (attr->num_values > 1)
-      strlcpy(printer->job_sheets[1], attr->values[1].string.text,
-              sizeof(printer->job_sheets[1]));
+      SetString(&printer->job_sheets[1], attr->values[1].string.text);
     else
-      strcpy(printer->job_sheets[1], "none");
+      SetString(&printer->job_sheets[1], "none");
   }
   if ((attr = ippFindAttribute(con->request, "requesting-user-name-allowed",
                                IPP_TAG_ZERO)) != NULL)
@@ -1253,8 +1246,8 @@ add_printer(client_t        *con, /* I - Client connection */
   * See if we have all required attributes...
   */
 
-  if (printer->device_uri[0] == '\0')
-    strcpy(printer->device_uri, "file:/dev/null");
+  if (!printer->device_uri)
+    SetString(&printer->device_uri, "file:/dev/null");
 
  /*
   * See if we have an interface script or PPD file attached to the request...
@@ -2237,22 +2230,21 @@ create_job(client_t        *con,        /* I - Client connection */
   job->attrs   = con->request;
   con->request = NULL;
 
-  strlcpy(job->title, title, sizeof(job->title));
+  SetString(&job->title, title);
 
   attr = ippFindAttribute(job->attrs, "requesting-user-name", IPP_TAG_NAME);
 
   if (con->username[0])
-    strlcpy(job->username, con->username, sizeof(job->username));
+    SetString(&job->username, con->username);
   else if (attr != NULL)
   {
     LogMessage(L_DEBUG, "create_job: requesting-user-name = \'%s\'",
                attr->values[0].string.text);
 
-    strlcpy(job->username, attr->values[0].string.text,
-            sizeof(job->username));
+    SetString(&job->username, attr->values[0].string.text);
   }
   else
-    strcpy(job->username, "anonymous");
+    SetString(&job->username, "anonymous");
 
   if (attr == NULL)
     ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-originating-user-name",
@@ -2260,8 +2252,7 @@ create_job(client_t        *con,  /* I - Client connection */
   else
   {
     attr->group_tag = IPP_TAG_JOB;
-    free(attr->name);
-    attr->name = strdup("job-originating-user-name");
+    SetString(&attr->name, "job-originating-user-name");
   }
 
   if ((attr = ippFindAttribute(job->attrs, "job-originating-host-name",
@@ -2382,7 +2373,7 @@ create_job(client_t        *con,  /* I - Client connection */
 
   job->state->values[0].integer = IPP_JOB_HELD;
 
-  if (!(printer->type & CUPS_PRINTER_REMOTE) || Classification[0])
+  if (!(printer->type & CUPS_PRINTER_REMOTE) || Classification)
   {
    /*
     * Add job sheets options...
@@ -2405,7 +2396,7 @@ create_job(client_t        *con,  /* I - Client connection */
     * Enforce classification level if set...
     */
 
-    if (Classification[0])
+    if (Classification)
     {
       if (ClassifyOverride)
       {
@@ -2417,8 +2408,7 @@ create_job(client_t        *con,  /* I - Client connection */
           * Force the leading banner to have the classification on it...
          */
 
-          free(attr->values[0].string.text);
-         attr->values[0].string.text = strdup(Classification);
+          SetString(&attr->values[0].string.text, Classification);
        }
        else if (attr->num_values == 2 &&
                 strcmp(attr->values[0].string.text, attr->values[1].string.text) != 0 &&
@@ -2429,8 +2419,7 @@ create_job(client_t        *con,  /* I - Client connection */
          * Can't put two different security markings on the same document!
          */
 
-          free(attr->values[1].string.text);
-         attr->values[1].string.text = strdup(attr->values[0].string.text);
+          SetString(&attr->values[1].string.text, attr->values[0].string.text);
        }
       }
       else if (strcmp(attr->values[0].string.text, Classification) != 0 &&
@@ -2441,8 +2430,7 @@ create_job(client_t        *con,  /* I - Client connection */
         * Force the leading banner to have the classification on it...
        */
 
-        free(attr->values[0].string.text);
-       attr->values[0].string.text = strdup(Classification);
+        SetString(&attr->values[0].string.text, Classification);
       }
     }
 
@@ -3480,12 +3468,9 @@ get_printers(client_t *con,              /* I - Client connection */
       {
        /*
         * Make a copy of the printer name...
-       *
-       * Note: name and printer->name are both IPP_MAX_NAME characters
-       *       in size, so strcpy() is safe...
        */
 
-        strcpy(name, printer->name);
+        strlcpy(name, printer->name, sizeof(name));
 
        if ((nameptr = strchr(name, '@')) != NULL)
        {
@@ -4151,21 +4136,21 @@ print_job(client_t        *con,         /* I - Client connection */
   * Copy the rest of the job info...
   */
 
-  strlcpy(job->title, title, sizeof(job->title));
+  SetString(&job->title, title);
 
   attr = ippFindAttribute(job->attrs, "requesting-user-name", IPP_TAG_NAME);
 
   if (con->username[0])
-    strlcpy(job->username, con->username, sizeof(job->username));
+    SetString(&job->username, con->username);
   else if (attr != NULL)
   {
     LogMessage(L_DEBUG, "print_job: requesting-user-name = \'%s\'",
                attr->values[0].string.text);
 
-    strlcpy(job->username, attr->values[0].string.text, sizeof(job->username));
+    SetString(&job->username, attr->values[0].string.text);
   }
   else
-    strcpy(job->username, "anonymous");
+    SetString(&job->username, "anonymous");
 
   if (attr == NULL)
     ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, "job-originating-user-name",
@@ -4173,8 +4158,7 @@ print_job(client_t        *con,           /* I - Client connection */
   else
   {
     attr->group_tag = IPP_TAG_JOB;
-    free(attr->name);
-    attr->name = strdup("job-originating-user-name");
+    SetString(&attr->name, "job-originating-user-name");
   }
 
  /*
@@ -4299,7 +4283,7 @@ print_job(client_t        *con,           /* I - Client connection */
     SetJobHoldUntil(job->id, attr->values[0].string.text);
   }
 
-  if (!(printer->type & CUPS_PRINTER_REMOTE) || Classification[0])
+  if (!(printer->type & CUPS_PRINTER_REMOTE) || Classification)
   {
    /*
     * Add job sheets options...
@@ -4322,7 +4306,7 @@ print_job(client_t        *con,           /* I - Client connection */
     * Enforce classification level if set...
     */
 
-    if (Classification[0])
+    if (Classification)
     {
       if (ClassifyOverride)
       {
@@ -4334,8 +4318,7 @@ print_job(client_t        *con,           /* I - Client connection */
           * Force the leading banner to have the classification on it...
          */
 
-          free(attr->values[0].string.text);
-         attr->values[0].string.text = strdup(Classification);
+          SetString(&attr->values[0].string.text, Classification);
        }
        else if (attr->num_values == 2 &&
                 strcmp(attr->values[0].string.text, attr->values[1].string.text) != 0 &&
@@ -4346,8 +4329,7 @@ print_job(client_t        *con,           /* I - Client connection */
          * Can't put two different security markings on the same document!
          */
 
-          free(attr->values[1].string.text);
-         attr->values[1].string.text = strdup(attr->values[0].string.text);
+          SetString(&attr->values[1].string.text, attr->values[0].string.text);
        }
       }
       else if (strcmp(attr->values[0].string.text, Classification) != 0 &&
@@ -4358,8 +4340,7 @@ print_job(client_t        *con,           /* I - Client connection */
         * Force the leading banner to have the classification on it...
        */
 
-        free(attr->values[0].string.text);
-       attr->values[0].string.text = strdup(Classification);
+        SetString(&attr->values[0].string.text, Classification);
       }
     }
 
@@ -5633,7 +5614,7 @@ set_job_attrs(client_t        *con,       /* I - Client connection */
       */
 
       if (strcmp(attr->name, "job-name") == 0)
-        strlcpy(job->title, attr->values[0].string.text, sizeof(job->title));
+        SetString(&job->title, attr->values[0].string.text);
       else if (strcmp(attr->name, "job-hold-until") == 0)
       {
         SetJobHoldUntil(job->id, attr->values[0].string.text);
@@ -6096,5 +6077,5 @@ validate_user(client_t   *con,            /* I - Client connection */
 
 
 /*
- * End of "$Id: ipp.c,v 1.127.2.38 2003/01/24 14:06:40 mike Exp $".
+ * End of "$Id: ipp.c,v 1.127.2.39 2003/01/29 20:08:22 mike Exp $".
  */
index 1098931bdd4b0d8ae8e6024d72dcf58fbc9b1a99..9a9f474d988338eaf288dc0affa267d75460422d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: job.c,v 1.124.2.43 2003/01/24 21:15:43 mike Exp $"
+ * "$Id: job.c,v 1.124.2.44 2003/01/29 20:08:25 mike Exp $"
  *
  *   Job management routines for the Common UNIX Printing System (CUPS).
  *
@@ -98,7 +98,7 @@ AddJob(int        priority,   /* I - Job priority */
   job->print_pipes[1] = -1;
   job->status_pipe    = -1;
 
-  strlcpy(job->dest, dest, sizeof(job->dest));
+  SetString(&job->dest, dest);
 
   NumJobs ++;
 
@@ -615,20 +615,20 @@ LoadAllJobs(void)
        if (strncmp(resource, "/classes/", 9) == 0)
        {
          p = AddClass(resource + 9);
-         strcpy(p->make_model, "Remote Class on unknown");
+         SetString(&p->make_model, "Remote Class on unknown");
        }
        else
        {
          p = AddPrinter(resource + 10);
-         strcpy(p->make_model, "Remote Printer on unknown");
+         SetString(&p->make_model, "Remote Printer on unknown");
        }
 
         p->state       = IPP_PRINTER_STOPPED;
        p->type        |= CUPS_PRINTER_REMOTE;
        p->browse_time = 2147483647;
 
-       strcpy(p->location, "Location Unknown");
-       strcpy(p->info, "No Information Available");
+       SetString(&p->location, "Location Unknown");
+       SetString(&p->info, "No Information Available");
        p->hostname[0] = '\0';
 
        SetPrinterAttrs(p);
@@ -645,7 +645,7 @@ LoadAllJobs(void)
        continue;
       }
 
-      strlcpy(job->dest, dest, sizeof(job->dest));
+      SetString(&job->dest, dest);
 
       job->sheets     = ippFindAttribute(job->attrs, "job-media-sheets-completed",
                                          IPP_TAG_INTEGER);
@@ -655,12 +655,10 @@ LoadAllJobs(void)
       job->priority = attr->values[0].integer;
 
       attr = ippFindAttribute(job->attrs, "job-name", IPP_TAG_NAME);
-      strlcpy(job->title, attr->values[0].string.text,
-              sizeof(job->title));
+      SetString(&job->title, attr->values[0].string.text);
 
       attr = ippFindAttribute(job->attrs, "job-originating-user-name", IPP_TAG_NAME);
-      strlcpy(job->username, attr->values[0].string.text,
-              sizeof(job->username));
+      SetString(&job->username, attr->values[0].string.text);
 
      /*
       * Insert the job into the array, sorting by job priority and ID...
@@ -795,7 +793,7 @@ MoveJob(int        id,              /* I - Job ID */
       if (current->state->values[0].integer >= IPP_JOB_PROCESSING)
         break;
 
-      strlcpy(current->dest, dest, sizeof(current->dest));
+      SetString(&current->dest, dest);
       current->dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_REMOTE |
                                   CUPS_PRINTER_IMPLICIT);
 
@@ -1612,7 +1610,7 @@ StartJob(int       id,            /* I - Job ID */
   else
     class_name[0] = '\0';
 
-  if (Classification[0] && !banner_page)
+  if (Classification && !banner_page)
   {
     if ((attr = ippFindAttribute(current->attrs, "job-sheets",
                                  IPP_TAG_NAME)) == NULL)
@@ -2600,5 +2598,5 @@ start_process(const char *command,        /* I - Full path to command */
 
 
 /*
- * End of "$Id: job.c,v 1.124.2.43 2003/01/24 21:15:43 mike Exp $".
+ * End of "$Id: job.c,v 1.124.2.44 2003/01/29 20:08:25 mike Exp $".
  */
index ff9dfb484bb0cdacbe8a752e8a3c0968d4656c4f..a5b1063d3d9f45010b67fe42d3d523f4c28b3b12 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: job.h,v 1.25.2.6 2003/01/07 18:27:24 mike Exp $"
+ * "$Id: job.h,v 1.25.2.7 2003/01/29 20:08:26 mike Exp $"
  *
  *   Print job definitions for the Common UNIX Printing System (CUPS) scheduler.
  *
@@ -41,10 +41,10 @@ typedef struct job_str
   ipp_attribute_t *state;              /* Job state */
   ipp_attribute_t *sheets;             /* job-media-sheets-completed */
   time_t       hold_until;             /* Hold expiration date/time */
-  char         username[33];           /* Printing user */
-  char         dest[IPP_MAX_NAME];     /* Destination printer or class */
+  char         *username;              /* Printing user */
+  char         *dest;                  /* Destination printer or class */
   cups_ptype_t dtype;                  /* Destination type (class/remote bits) */
-  char         title[IPP_MAX_NAME];    /* Job name/title */
+  char         *title;                 /* Job name/title */
   ipp_attribute_t *job_sheets;         /* Job sheets (NULL if none) */
   int          num_files;              /* Number of files in job */
   int          current_file;           /* Current file in job */
@@ -109,5 +109,5 @@ extern void UpdateJob(job_t *job);
 
 
 /*
- * End of "$Id: job.h,v 1.25.2.6 2003/01/07 18:27:24 mike Exp $".
+ * End of "$Id: job.h,v 1.25.2.7 2003/01/29 20:08:26 mike Exp $".
  */
index 731e27077c3a303f11e0d576cb08465a79aa4bda..4e3ce0b22b852c1ed3fc53be38add975590ffb4c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: main.c,v 1.57.2.28 2003/01/13 20:38:38 mike Exp $"
+ * "$Id: main.c,v 1.57.2.29 2003/01/29 20:08:26 mike Exp $"
  *
  *   Scheduler main loop for the Common UNIX Printing System (CUPS).
  *
@@ -26,6 +26,8 @@
  *   main()               - Main entry for the CUPS scheduler.
  *   CatchChildSignals()  - Catch SIGCHLD signals...
  *   IgnoreChildSignals() - Ignore SIGCHLD signals...
+ *   SetString()          - Set a string value.
+ *   SetStringf()         - Set a formatted string value.
  *   sigchld_handler()    - Handle 'child' signals from old processes.
  *   sighup_handler()     - Handle 'hangup' signals to reconfigure the scheduler.
  *   sigterm_handler()    - Handle 'terminate' signals that stop the scheduler.
@@ -116,7 +118,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
                * Absolute directory...
                */
 
-               strlcpy(ConfigurationFile, argv[i], sizeof(ConfigurationFile));
+               SetString(&ConfigurationFile, argv[i]);
               }
              else
              {
@@ -124,9 +126,11 @@ main(int  argc,                    /* I - Number of command-line arguments */
                * Relative directory...
                */
 
-                getcwd(ConfigurationFile, sizeof(ConfigurationFile));
-               strlcat(ConfigurationFile, "/", sizeof(ConfigurationFile));
-               strlcat(ConfigurationFile, argv[i], sizeof(ConfigurationFile));
+                char current[1024];    /* Current directory */
+
+
+                getcwd(current, sizeof(current));
+               SetStringf(&ConfigurationFile, "%s/%s", current, argv[i]);
               }
              break;
 
@@ -232,9 +236,9 @@ main(int  argc,                     /* I - Number of command-line arguments */
   */
 
   if (getenv("TZ") != NULL)
-    snprintf(TZ, sizeof(TZ), "TZ=%s", getenv("TZ"));
+    SetStringf(&TZ, "TZ=%s", getenv("TZ"));
   else
-    TZ[0] = '\0';
+    SetString(&TZ, "");
 
   tzset();
 
@@ -669,6 +673,21 @@ CatchChildSignals(void)
 }
 
 
+/*
+ * 'ClearString()' - Clear a string.
+ */
+
+void
+ClearString(char **s)                  /* O - String value */
+{
+  if (s && *s)
+  {
+    free(*s);
+    *s = NULL;
+  }
+}
+
+
 /*
  * 'IgnoreChildSignals()' - Ignore SIGCHLD signals...
  */
@@ -695,6 +714,59 @@ IgnoreChildSignals(void)
 }
 
 
+/*
+ * 'SetString()' - Set a string value.
+ */
+
+void
+SetString(char       **s,              /* O - New string */
+          const char *v)               /* I - String value */
+{
+  if (!s)
+    return;
+
+  if (*s)
+    free(*s);
+
+  if (v)
+    *s = strdup(v);
+  else
+    *s = NULL;
+}
+
+
+/*
+ * 'SetStringf()' - Set a formatted string value.
+ */
+
+void
+SetStringf(char       **s,             /* O - New string */
+           const char *f,              /* I - Printf-style format string */
+          ...)                         /* I - Additional args as needed */
+{
+  char         v[1024];                /* Formatting string value */
+  va_list      ap;                     /* Argument pointer */
+
+
+  if (!s)
+    return;
+
+  if (*s)
+    free(*s);
+
+  if (f)
+  {
+    va_start(ap, f);
+    vsnprintf(v, sizeof(v), f, ap);
+    va_end(ap);
+
+    *s = strdup(v);
+  }
+  else
+    *s = NULL;
+}
+
+
 /*
  * 'sigchld_handler()' - Handle 'child' signals from old processes.
  */
@@ -930,5 +1002,5 @@ usage(void)
 
 
 /*
- * End of "$Id: main.c,v 1.57.2.28 2003/01/13 20:38:38 mike Exp $".
+ * End of "$Id: main.c,v 1.57.2.29 2003/01/29 20:08:26 mike Exp $".
  */
index e3ca97eee555c45c632cd2967bd26e8037150f5d..4b2afe459dc44fba80b46b85e1a0582cf72206fa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: printers.c,v 1.93.2.33 2003/01/24 18:00:55 mike Exp $"
+ * "$Id: printers.c,v 1.93.2.34 2003/01/29 20:08:27 mike Exp $"
  *
  *   Printer routines for the Common UNIX Printing System (CUPS).
  *
@@ -91,25 +91,25 @@ AddPrinter(const char *name)        /* I - Name of printer */
   if ((p = calloc(1, sizeof(printer_t))) == NULL)
     return (NULL);
 
-  strlcpy(p->name, name, sizeof(p->name));
-  strlcpy(p->info, name, sizeof(p->info));
-  strlcpy(p->hostname, ServerName, sizeof(p->hostname));
+  SetString(&p->name, name);
+  SetString(&p->info, name);
+  SetString(&p->hostname, ServerName);
 
 #ifdef AF_INET6
   if (Listeners[0].address.addr.sa_family == AF_INET6)
-    snprintf(p->uri, sizeof(p->uri), "ipp://%s:%d/printers/%s", ServerName,
-             ntohs(Listeners[0].address.ipv6.sin6_port), name);
+    SetStringf(&p->uri, "ipp://%s:%d/printers/%s", ServerName,
+               ntohs(Listeners[0].address.ipv6.sin6_port), name);
   else
 #endif /* AF_INET6 */
-  snprintf(p->uri, sizeof(p->uri), "ipp://%s:%d/printers/%s", ServerName,
-           ntohs(Listeners[0].address.ipv4.sin_port), name);
+  SetStringf(&p->uri, "ipp://%s:%d/printers/%s", ServerName,
+             ntohs(Listeners[0].address.ipv4.sin_port), name);
 
   p->state     = IPP_PRINTER_STOPPED;
   p->accepting = 0;
   p->filetype  = mimeAddType(MimeDatabase, "printer", name);
 
-  strcpy(p->job_sheets[0], "none");
-  strcpy(p->job_sheets[1], "none");
+  SetString(&p->job_sheets[0], "none");
+  SetString(&p->job_sheets[1], "none");
 
  /*
   * Insert the printer in the printer list alphabetically...
@@ -357,6 +357,17 @@ DeletePrinter(printer_t *p)        /* I - Printer to delete */
   FreePrinterUsers(p);
   FreeQuotas(p);
 
+  ClearString(&p->uri);
+  ClearString(&p->hostname);
+  ClearString(&p->name);
+  ClearString(&p->location);
+  ClearString(&p->make_model);
+  ClearString(&p->info);
+  ClearString(&p->job_sheets[0]);
+  ClearString(&p->job_sheets[1]);
+  ClearString(&p->device_uri);
+  ClearString(&p->backend);
+
   free(p);
 
  /*
@@ -612,11 +623,11 @@ LoadAllPrinters(void)
       return;
     }
     else if (strcmp(name, "Info") == 0)
-      strlcpy(p->info, value, sizeof(p->info));
+      SetString(&p->info, value);
     else if (strcmp(name, "Location") == 0)
-      strlcpy(p->location, value, sizeof(p->location));
+      SetString(&p->location, value);
     else if (strcmp(name, "DeviceURI") == 0)
-      strlcpy(p->device_uri, value, sizeof(p->device_uri));
+      SetString(&p->device_uri, value);
     else if (strcmp(name, "State") == 0)
     {
      /*
@@ -661,7 +672,7 @@ LoadAllPrinters(void)
       if (*valueptr)
         *valueptr++ = '\0';
 
-      strlcpy(p->job_sheets[0], value, sizeof(p->job_sheets[0]));
+      SetString(&p->job_sheets[0], value);
 
       while (isspace(*valueptr))
         valueptr ++;
@@ -673,7 +684,7 @@ LoadAllPrinters(void)
        if (*valueptr)
           *valueptr++ = '\0';
 
-       strlcpy(p->job_sheets[1], value, sizeof(p->job_sheets[1]));
+       SetString(&p->job_sheets[1], value);
       }
     }
     else if (strcmp(name, "AllowUser") == 0)
@@ -787,13 +798,13 @@ SaveAllPrinters(void)
     else
       fprintf(fp, "<Printer %s>\n", printer->name);
 
-    if (printer->info[0])
+    if (printer->info)
       fprintf(fp, "Info %s\n", printer->info);
 
-    if (printer->location[0])
+    if (printer->location)
       fprintf(fp, "Location %s\n", printer->location);
 
-    if (printer->device_uri[0])
+    if (printer->device_uri)
       fprintf(fp, "DeviceURI %s\n", printer->device_uri);
 
     if (printer->state == IPP_PRINTER_STOPPED)
@@ -1005,9 +1016,9 @@ SetPrinterAttrs(printer_t *p)             /* I - Printer to setup */
   ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-name", NULL,
                p->name);
   ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-location",
-               NULL, p->location);
+               NULL, p->location ? p->location : "");
   ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-info",
-               NULL, p->info);
+               NULL, p->info ? p->info : "");
   ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-more-info",
                NULL, p->uri);
   ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
@@ -1082,7 +1093,7 @@ SetPrinterAttrs(printer_t *p)             /* I - Printer to setup */
     * Setup the job-sheets-supported and job-sheets-default attributes...
     */
 
-    if (Classification[0] && !ClassifyOverride)
+    if (Classification && !ClassifyOverride)
       attr = ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
                          "job-sheets-supported", NULL, Classification);
     else
@@ -1093,7 +1104,7 @@ SetPrinterAttrs(printer_t *p)             /* I - Printer to setup */
       LogMessage(L_EMERG, "SetPrinterAttrs: Unable to allocate memory for "
                           "job-sheets-supported attribute: %s!",
                 strerror(errno));
-    else if (!Classification[0] || ClassifyOverride)
+    else if (!Classification || ClassifyOverride)
     {
       attr->values[0].string.text = strdup("none");
 
@@ -1108,9 +1119,9 @@ SetPrinterAttrs(printer_t *p)             /* I - Printer to setup */
 
       if (attr != NULL)
       {
-       attr->values[0].string.text = strdup(Classification[0] ?
+       attr->values[0].string.text = strdup(Classification ?
                                             Classification : p->job_sheets[0]);
-       attr->values[1].string.text = strdup(Classification[0] ?
+       attr->values[1].string.text = strdup(Classification ?
                                             Classification : p->job_sheets[1]);
       }
     }
@@ -1188,7 +1199,9 @@ SetPrinterAttrs(printer_t *p)             /* I - Printer to setup */
       * URI so it doesn't have a username or password in it...
       */
 
-      if (strstr(p->device_uri, "://") != NULL)
+      if (!p->device_uri)
+        strcpy(uri, "file:/dev/null");
+      else if (strstr(p->device_uri, "://") != NULL)
       {
        /*
         * http://..., ipp://..., etc.
@@ -1207,7 +1220,7 @@ SetPrinterAttrs(printer_t *p)             /* I - Printer to setup */
         * file:..., serial:..., etc.
        */
 
-        strcpy(uri, p->device_uri);
+        strlcpy(uri, p->device_uri, sizeof(uri));
       }
 
       ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL,
@@ -1244,11 +1257,11 @@ SetPrinterAttrs(printer_t *p)           /* I - Printer to setup */
                        "pages-per-minute", ppd->throughput);
 
         if (ppd->nickname)
-          strlcpy(p->make_model, ppd->nickname, sizeof(p->make_model));
+          SetString(&p->make_model, ppd->nickname);
        else if (ppd->modelname)
-          strlcpy(p->make_model, ppd->modelname, sizeof(p->make_model));
+          SetString(&p->make_model, ppd->modelname);
        else
-         strcpy(p->make_model, "Bad PPD File");
+         SetString(&p->make_model, "Bad PPD File");
 
        ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
                      "printer-make-and-model", NULL, p->make_model);
@@ -1421,7 +1434,8 @@ SetPrinterAttrs(printer_t *p)             /* I - Printer to setup */
                   ServerRoot, p->name);
          AddPrinterFilter(p, filename);
        }
-       else if (strncmp(p->device_uri, "ipp://", 6) == 0 &&
+       else if (p->device_uri &&
+                strncmp(p->device_uri, "ipp://", 6) == 0 &&
                 (strstr(p->device_uri, "/printers/") != NULL ||
                  strstr(p->device_uri, "/classes/") != NULL))
         {
@@ -1860,7 +1874,7 @@ WritePrintcap(void)
          fprintf(fp, "%s:\\\n"
                      "\t:bsdaddr=%s,%s:\\\n"
                      "\t:description=%s:\n",
-                 p->name, ServerName, p->name, p->info);
+                 p->name, ServerName, p->name, p->info ? p->info : "");
         break;
   }
 
@@ -1983,10 +1997,10 @@ write_irix_config(printer_t *p) /* I - Printer to update */
   {
     fprintf(fp, "Printer Class      | %s\n",
             (p->type & CUPS_PRINTER_COLOR) ? "ColorPostScript" : "MonoPostScript");
-    fprintf(fp, "Printer Model      | %s\n", p->make_model);
-    fprintf(fp, "Location Code      | %s\n", p->location);
-    fprintf(fp, "Physical Location  | %s\n", p->info);
-    fprintf(fp, "Port Path          | %s\n", p->device_uri);
+    fprintf(fp, "Printer Model      | %s\n", p->make_model ? p->make_model : "");
+    fprintf(fp, "Location Code      | %s\n", p->location ? p->location : "");
+    fprintf(fp, "Physical Location  | %s\n", p->info ? p->info : "");
+    fprintf(fp, "Port Path          | %s\n", p->device_uri ? p->device_uri : "");
     fprintf(fp, "Config Path        | /var/spool/lp/pod/%s.config\n", p->name);
     fprintf(fp, "Active Status Path | /var/spool/lp/pod/%s.status\n", p->name);
     fputs("Status Update Wait | 10 seconds\n", fp);
@@ -2029,7 +2043,8 @@ write_irix_state(printer_t *p)    /* I - Printer to update */
               (p->state == IPP_PRINTER_PROCESSING) ? "Busy" :
                                                      "Faulted");
       fprintf(fp, "Information        | 01 00 00 | %s\n", CUPS_SVERSION);
-      fprintf(fp, "Information        | 02 00 00 | Device URI: %s\n", p->device_uri);
+      fprintf(fp, "Information        | 02 00 00 | Device URI: %s\n",
+              p->device_uri ? p->device_uri : "");
       fprintf(fp, "Information        | 03 00 00 | %s jobs\n",
               p->accepting ? "Accepting" : "Not accepting");
       fprintf(fp, "Information        | 04 00 00 | %s\n", p->state_message);
@@ -2127,5 +2142,5 @@ write_irix_state(printer_t *p)    /* I - Printer to update */
 
 
 /*
- * End of "$Id: printers.c,v 1.93.2.33 2003/01/24 18:00:55 mike Exp $".
+ * End of "$Id: printers.c,v 1.93.2.34 2003/01/29 20:08:27 mike Exp $".
  */
index 1e729d28166a3f796cca1e5b4d331efba19153e3..bc2f637c58671d7b6bbdc980db287eccbe6af09d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: printers.h,v 1.22.2.7 2003/01/24 18:00:56 mike Exp $"
+ * "$Id: printers.h,v 1.22.2.8 2003/01/29 20:08:28 mike Exp $"
  *
  *   Printer definitions for the Common UNIX Printing System (CUPS) scheduler.
  *
@@ -42,28 +42,25 @@ typedef struct
 typedef struct printer_str
 {
   struct printer_str *next;            /* Next printer in list */
-  char         uri[HTTP_MAX_URI],      /* Printer URI */
-               hostname[HTTP_MAX_HOST],/* Host printer resides on */
-               name[IPP_MAX_NAME],     /* Printer name */
-               location[IPP_MAX_NAME], /* Location code */
-               make_model[IPP_MAX_NAME],
-                                       /* Make and model */
-               info[IPP_MAX_NAME],     /* Description */
-               op_policy[IPP_MAX_NAME],/* Operation policy name */
-               error_policy[IPP_MAX_NAME];
-                                       /* Error policy */
+  char         *uri,                   /* Printer URI */
+               *hostname,              /* Host printer resides on */
+               *name,                  /* Printer name */
+               *location,              /* Location code */
+               *make_model,            /* Make and model */
+               *info,                  /* Description */
+               *op_policy,             /* Operation policy name */
+               *error_policy;          /* Error policy */
   policy_t     *op_policy_ptr;         /* Pointer to operation policy */
   int          accepting;              /* Accepting jobs? */
   ipp_pstate_t state;                  /* Printer state */
   char         state_message[1024];    /* Printer state message */
   ipp_attribute_t *state_reasons;      /* Printer state reasons */
   time_t       state_time;             /* Time at this state */
-  char         job_sheets[2][IPP_MAX_NAME];
-                                       /* Banners/job sheets */
+  char         *job_sheets[2];         /* Banners/job sheets */
   cups_ptype_t type;                   /* Printer type (color, small, etc.) */
   time_t       browse_time;            /* Last time update was sent/received */
-  char         device_uri[HTTP_MAX_URI],/* Device URI */
-               backend[1024];          /* Backend to use */
+  char         *device_uri,            /* Device URI */
+               *backend;               /* Backend to use */
   int          raw;                    /* Raw queue? */
   mime_type_t  *filetype;              /* Pseudo-filetype for printer */
   void         *job;                   /* Current job in queue */
@@ -122,5 +119,5 @@ extern void         WritePrintcap(void);
 
 
 /*
- * End of "$Id: printers.h,v 1.22.2.7 2003/01/24 18:00:56 mike Exp $".
+ * End of "$Id: printers.h,v 1.22.2.8 2003/01/29 20:08:28 mike Exp $".
  */