]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Avoid copying option names and values, just break up the URI resource
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Tue, 4 Sep 2007 20:34:29 +0000 (20:34 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Tue, 4 Sep 2007 20:34:29 +0000 (20:34 +0000)
string...

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@6910 7a7537e8-13f0-0310-91df-b6672ffda945

backend/ipp.c
backend/lpd.c
backend/pap.c
backend/serial.c
backend/socket.c
backend/usb-darwin.c
backend/usb-unix.c
backend/usb.c

index 5b48fff70276492cb4e36a87b4c8472d4c8fd2a8..a7dceaa3ef87944a52c42c5f637227120c7bc9f2 100644 (file)
@@ -102,9 +102,9 @@ main(int  argc,                             /* I - Number of command-line args */
                resource[1024],         /* Resource info (printer name) */
                addrname[256],          /* Address name */
                *optptr,                /* Pointer to URI options */
-               name[255],              /* Name of option */
-               value[255],             /* Value of option */
-               *ptr;                   /* Pointer into name or value */
+               *name,                  /* Name of option */
+               *value,                 /* Value of option */
+               sep;                    /* Separator character */
   int          num_files;              /* Number of files to print */
   char         **files,                /* Files to print */
                *filename;              /* Pointer to single filename */
@@ -265,29 +265,30 @@ main(int  argc,                           /* I - Number of command-line args */
       * Get the name...
       */
 
-      for (ptr = name; *optptr && *optptr != '=';)
-        if (ptr < (name + sizeof(name) - 1))
-          *ptr++ = *optptr++;
-      *ptr = '\0';
+      name = optptr;
 
-      if (*optptr == '=')
+      while (*optptr && *optptr != '=' && *optptr != '+' && *optptr != '&')
+        optptr ++;
+
+      if ((sep = *optptr) != '\0')
+        *optptr++ = '\0';
+
+      if (sep == '=')
       {
        /*
         * Get the value...
        */
 
-        optptr ++;
+        value = optptr;
 
-       for (ptr = value; *optptr && *optptr != '+' && *optptr != '&';)
-          if (ptr < (value + sizeof(value) - 1))
-            *ptr++ = *optptr++;
-       *ptr = '\0';
-
-       if (*optptr == '+' || *optptr == '&')
+       while (*optptr && *optptr != '+' && *optptr != '&')
          optptr ++;
+
+        if (*optptr)
+         *optptr++ = '\0';
       }
       else
-        value[0] = '\0';
+        value = (char *)"";
 
      /*
       * Process the option...
@@ -473,7 +474,9 @@ main(int  argc,                             /* I - Number of command-line args */
     * Try loading authentication information from the environment.
     */
 
-    if ((ptr = getenv("AUTH_USERNAME")) != NULL)
+    const char *ptr = getenv("AUTH_USERNAME");
+
+    if (ptr)
       cupsSetUser(ptr);
 
     password = getenv("AUTH_PASSWORD");
index c071d851b4131e852429542c219583ee13b17ab2..fd99705f4a3413b82bd91c5ac38000e575f60f1d 100644 (file)
@@ -125,9 +125,9 @@ main(int  argc,                             /* I - Number of command-line arguments (6 or 7) */
                        username[255],  /* Username info */
                        resource[1024], /* Resource info (printer name) */
                        *options,       /* Pointer to options */
-                       name[255],      /* Name of option */
-                       value[255],     /* Value of option */
-                       *ptr,           /* Pointer into name or value */
+                       *name,          /* Name of option */
+                       *value,         /* Value of option */
+                       sep,            /* Separator character */
                        *filename,      /* File to print */
                        title[256];     /* Title string */
   int                  port;           /* Port number */
@@ -277,29 +277,30 @@ main(int  argc,                           /* I - Number of command-line arguments (6 or 7) */
       * Get the name...
       */
 
-      for (ptr = name; *options && *options != '=';)
-        if (ptr < (name + sizeof(name) - 1))
-          *ptr++ = *options++;
-      *ptr = '\0';
+      name = options;
 
-      if (*options == '=')
+      while (*options && *options != '=' && *options != '+' && *options != '&')
+        options ++;
+
+      if ((sep = *options) != '\0')
+        *options++ = '\0';
+
+      if (sep == '=')
       {
        /*
         * Get the value...
        */
 
-        options ++;
+        value = options;
 
-       for (ptr = value; *options && *options != '+' && *options != '&';)
-          if (ptr < (value + sizeof(value) - 1))
-            *ptr++ = *options++;
-       *ptr = '\0';
-
-       if (*options == '+' || *options == '&')
+       while (*options && *options != '+' && *options != '&')
          options ++;
+
+        if (*options)
+         *options++ = '\0';
       }
       else
-        value[0] = '\0';
+        value = (char *)"";
 
      /*
       * Process the option...
@@ -479,6 +480,8 @@ main(int  argc,                             /* I - Number of command-line arguments (6 or 7) */
     * the remote end...
     */
 
+    char *ptr;
+
     for (ptr = title; *ptr; ptr ++)
       if (!isalnum(*ptr & 255) && !isspace(*ptr & 255))
        *ptr = '_';
index 41ee390b2e34fb23eef3ea80b9180f57e6f81e03..53cb039f6a9001967f3432d6f94267ff9df4f0d3 100644 (file)
@@ -1365,9 +1365,9 @@ static int parseUri(const char* argv0, char* name, char* type, char* zone)
         *resourcePtr,
         *typePtr,
         *options,              /* Pointer to options */
-        optionName[255],       /* Name of option */
-        value[255],            /* Value of option */
-        *ptr;                  /* Pointer into name or value */
+        *optionName,           /* Name of option */
+        *value,                        /* Value of option */
+        sep;                   /* Separator character */
   int   port;                  /* Port number (not used) */
   int   statusInterval;                /* */
 
@@ -1395,53 +1395,54 @@ static int parseUri(const char* argv0, char* name, char* type, char* zone)
 
     while (*options != '\0')
     {
-      /*
+     /*
       * Get the name...
       */
-      for (ptr = optionName; *options && *options != '=' && *options != '+'; )
-        *ptr++ = *options++;
 
-      *ptr = '\0';
-      value[0] = '\0';
+      optionName = options;
 
-      if (*options == '=')
-      {
-        /*
-        * Get the value...
-        */
-        
+      while (*options && *options != '=' && *options != '+' && *options != '&')
         options ++;
-        
-        for (ptr = value; *options && *options != '+';)
-          *ptr++ = *options++;
-
-        *ptr = '\0';
-        
-        if (*options == '+')
-          options ++;
-      }
-      else if (*options == '+')
+
+      if ((sep = *options) != '\0')
+        *options++ = '\0';
+
+      if (sep == '=')
       {
-        options ++;
+       /*
+        * Get the value...
+       */
+
+        value = options;
+
+       while (*options && *options != '+' && *options != '&')
+         options ++;
+
+        if (*options)
+         *options++ = '\0';
       }
+      else
+        value = (char *)"";
 
-      /*
+     /*
       * Process the option...
       */
-      if (strcasecmp(optionName, "waiteof") == 0)
+
+      if (!strcasecmp(optionName, "waiteof"))
       {
-        /*
-        * Set the banner...
+       /*
+        * Wait for the end of the print file?
         */
-        if (strcasecmp(value, "on") == 0 ||
-          strcasecmp(value, "yes") == 0 ||
-          strcasecmp(value, "true") == 0)
+
+        if (!strcasecmp(value, "on") ||
+            !strcasecmp(value, "yes") ||
+            !strcasecmp(value, "true"))
         {
           gWaitEOF = true;
         }
-        else if (strcasecmp(value, "off") == 0 ||
-            strcasecmp(value, "no") == 0 ||
-            strcasecmp(value, "false") == 0)
+        else if (!strcasecmp(value, "off") ||
+                 !strcasecmp(value, "no") ||
+                 !strcasecmp(value, "false"))
         {
           gWaitEOF = false;
         }
@@ -1450,13 +1451,17 @@ static int parseUri(const char* argv0, char* name, char* type, char* zone)
           fprintf(stderr, "WARNING: Boolean expected for waiteof option \"%s\"\n", value);
         }
       }
-      else if (strcasecmp(optionName, "status") == 0)
+      else if (!strcasecmp(optionName, "status"))
       {
+       /*
+        * Set status reporting interval...
+       */
+
         statusInterval = atoi(value);
-        if (value[0] < '0' || value[0] > '9' || 
-          statusInterval < 0)
+        if (value[0] < '0' || value[0] > '9' || statusInterval < 0)
         {
-          fprintf(stderr, "WARNING: number expected for status option \"%s\"\n", value);
+          fprintf(stderr, "WARNING: number expected for status option \"%s\"\n",
+                 value);
         }
         else
         {
@@ -1471,20 +1476,24 @@ static int parseUri(const char* argv0, char* name, char* type, char* zone)
   if (*resourcePtr == '/')
     resourcePtr++;
 
-        /* If the resource has a slash we assume the slash seperates the AppleTalk object
-         * name from the AppleTalk type. If the slash is not present we assume the AppleTalk
-         * type is LaserWriter.
-         */
-        typePtr = strchr(resourcePtr, '/');
-        if (typePtr != NULL) {
-            *typePtr++ = '\0';
-        } else {
-            typePtr = "LaserWriter";
-        }
+ /* If the resource has a slash we assume the slash seperates the AppleTalk object
+  * name from the AppleTalk type. If the slash is not present we assume the AppleTalk
+  * type is LaserWriter.
+  */
+
+  typePtr = strchr(resourcePtr, '/');
+  if (typePtr != NULL)
+  {
+    *typePtr++ = '\0';
+  }
+  else
+  {
+    typePtr = "LaserWriter";
+  }
 
-  removePercentEscapes(hostname,    zone, NBP_NVE_STR_SIZE + 1);
-  removePercentEscapes(resourcePtr,  name, NBP_NVE_STR_SIZE + 1);
-  removePercentEscapes(typePtr,     type, NBP_NVE_STR_SIZE + 1);
+  removePercentEscapes(hostname, zone, NBP_NVE_STR_SIZE + 1);
+  removePercentEscapes(resourcePtr, name, NBP_NVE_STR_SIZE + 1);
+  removePercentEscapes(typePtr, type, NBP_NVE_STR_SIZE + 1);
 
   return 0;
 }
index 420039d15bd499372db95bd366dee925a635654d..724badcb6fc361f8a87326943c8da6d67a692976 100644 (file)
@@ -104,9 +104,9 @@ main(int  argc,                             /* I - Number of command-line arguments (6 or 7) */
                username[255],          /* Username info (not used) */
                resource[1024],         /* Resource info (device and options) */
                *options,               /* Pointer to options */
-               name[255],              /* Name of option */
-               value[255],             /* Value of option */
-               *ptr;                   /* Pointer into name or value */
+               *name,                  /* Name of option */
+               *value,                 /* Value of option */
+               sep;                    /* Option separator */
   int          port;                   /* Port number (not used) */
   int          copies;                 /* Number of copies to print */
   int          print_fd,               /* Print file */
@@ -289,29 +289,30 @@ main(int  argc,                           /* I - Number of command-line arguments (6 or 7) */
       * Get the name...
       */
 
-      for (ptr = name; *options && *options != '=';)
-        if (ptr < (name + sizeof(name) - 1))
-          *ptr++ = *options++;
-      *ptr = '\0';
+      name = options;
 
-      if (*options == '=')
+      while (*options && *options != '=' && *options != '+' && *options != '&')
+        options ++;
+
+      if ((sep = *options) != '\0')
+        *options++ = '\0';
+
+      if (sep == '=')
       {
        /*
         * Get the value...
        */
 
-        options ++;
-
-       for (ptr = value; *options && *options != '+' && *options != '&';)
-          if (ptr < (value + sizeof(value) - 1))
-            *ptr++ = *options++;
-       *ptr = '\0';
+        value = options;
 
-       if (*options == '+' || *options == '&')
+       while (*options && *options != '+' && *options != '&')
          options ++;
+
+        if (*options)
+         *options++ = '\0';
       }
       else
-        value[0] = '\0';
+        value = (char *)"";
 
      /*
       * Process the option...
index aff5875fb0a3b2c2d6f29718f9ed4623feb09d56..434ac99ff701abd5959086d02e1f6f93fb62a3f0 100644 (file)
@@ -68,9 +68,9 @@ main(int  argc,                               /* I - Number of command-line arguments (6 or 7) */
                username[255],          /* Username info (not used) */
                resource[1024],         /* Resource info (not used) */
                *options,               /* Pointer to options */
-               name[255],              /* Name of option */
-               value[255],             /* Value of option */
-               *ptr;                   /* Pointer into name or value */
+               *name,                  /* Name of option */
+               *value,                 /* Value of option */
+               sep;                    /* Option separator */
   int          print_fd;               /* Print file */
   int          copies;                 /* Number of copies to print */
   time_t       start_time;             /* Time of first connect */
@@ -83,7 +83,7 @@ main(int  argc,                               /* I - Number of command-line arguments (6 or 7) */
   int          device_fd;              /* AppSocket */
   int          error;                  /* Error code (if any) */
   http_addrlist_t *addrlist,           /* Address list */
-                 *addr;                /* Connected address */
+               *addr;                  /* Connected address */
   char         addrname[256];          /* Address name */
   ssize_t      tbytes;                 /* Total number of bytes written */
 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
@@ -191,29 +191,30 @@ main(int  argc,                           /* I - Number of command-line arguments (6 or 7) */
       * Get the name...
       */
 
-      for (ptr = name; *options && *options != '=';)
-        if (ptr < (name + sizeof(name) - 1))
-          *ptr++ = *options++;
-      *ptr = '\0';
+      name = options;
 
-      if (*options == '=')
+      while (*options && *options != '=' && *options != '+' && *options != '&')
+        options ++;
+
+      if ((sep = *options) != '\0')
+        *options++ = '\0';
+
+      if (sep == '=')
       {
        /*
         * Get the value...
        */
 
-        options ++;
-
-       for (ptr = value; *options && *options != '+' && *options != '&';)
-          if (ptr < (value + sizeof(value) - 1))
-            *ptr++ = *options++;
-       *ptr = '\0';
+        value = options;
 
-       if (*options == '+' || *options == '&')
+       while (*options && *options != '+' && *options != '&')
          options ++;
+
+        if (*options)
+         *options++ = '\0';
       }
       else
-        value[0] = '\0';
+        value = (char *)"";
 
      /*
       * Process the option...
index 81ce3fe6672c778bde156e37f2cd320a9cff3f38..fbf8150ae54abc0ec858b97e0730f8c0a1f4b25a 100644 (file)
@@ -267,7 +267,7 @@ static void copy_devicestring(io_service_t usbInterface, CFStringRef *deviceID,
 static void device_added(void *userdata, io_iterator_t iterator);
 static void get_device_id(cups_sc_status_t *status, char *data, int *datalen);
 static void iterate_printers(iterator_callback_t callBack, void *userdata);
-static void parse_options(const char *options, char *serial, int serial_size, UInt32 *location, Boolean *wait_eof);
+static void parse_options(char *options, char *serial, int serial_size, UInt32 *location, Boolean *wait_eof);
 static void release_deviceinfo(CFStringRef *make, CFStringRef *model, CFStringRef *serial);
 static void setup_cfLanguage(void);
 static void soft_reset();
@@ -304,7 +304,7 @@ int                                 /* O - Exit status */
 print_device(const char *uri,          /* I - Device URI */
              const char *hostname,     /* I - Hostname/manufacturer */
              const char *resource,     /* I - Resource/modelname */
-            const char *options,       /* I - Device options/serial number */
+            char       *options,       /* I - Device options/serial number */
             int        print_fd,       /* I - File descriptor to print */
             int        copies,         /* I - Copies to print */
             int        argc,           /* I - Number of command-line arguments (6 or 7) */
@@ -1543,18 +1543,19 @@ CFStringRef cfstr_create_trim(const char *cstr)
 
 #pragma mark -
 /*
- * 'parse_options()' - Parse uri options.
+ * 'parse_options()' - Parse URI options.
  */
 
-static void parse_options(const char *options,
+static void parse_options(char *options,
                          char *serial,
                          int serial_size,
                          UInt32 *location,
                          Boolean *wait_eof)
 {
-  char optionName[255],        /* Name of option */
-       value[255],             /* Value of option */
-       *ptr;                   /* Pointer into name or value */
+  char sep,                            /* Separator character */
+       *name,                          /* Name of option */
+       *value;                         /* Value of option */
+
 
   if (serial)
     *serial = '\0';
@@ -1564,58 +1565,61 @@ static void parse_options(const char *options,
   if (!options)
     return;
 
-  while (*options != '\0')
+  while (*options)
   {
-    /* Get the name... */
-    for (ptr = optionName; *options && *options != '=' && *options != '+';)
-      *ptr++ = *options++;
+   /*
+    * Get the name...
+    */
 
-    *ptr = '\0';
-    value[0] = '\0';
+    name = options;
 
-    if (*options == '=')
-    {
-      /* Get the value... */
+    while (*options && *options != '=' && *options != '+' && *options != '&')
       options ++;
 
-      for (ptr = value; *options && *options != '+';)
-       *ptr++ = *options++;
+    if ((sep = *options) != '\0')
+      *options++ = '\0';
+
+    if (sep == '=')
+    {
+     /*
+      * Get the value...
+      */
 
-      *ptr = '\0';
+      value = options;
 
-      if (*options == '+')
+      while (*options && *options != '+' && *options != '&')
        options ++;
+
+      if (*options)
+       *options++ = '\0';
     }
-    else if (*options == '+')
-      options ++;
+    else
+      value = (char *)"";
 
-    /*
-     * Process the option...
-     */
-    if (strcasecmp(optionName, "waiteof") == 0)
+   /*
+    * Process the option...
+    */
+
+    if (!strcasecmp(name, "waiteof"))
     {
-      if (strcasecmp(value, "on") == 0 ||
-         strcasecmp(value, "yes") == 0 ||
-         strcasecmp(value, "true") == 0)
+      if (!strcasecmp(value, "on") ||
+         !strcasecmp(value, "yes") ||
+         !strcasecmp(value, "true"))
        *wait_eof = true;
-      else if (strcasecmp(value, "off")   == 0 ||
-              strcasecmp(value, "no")    == 0 ||
-              strcasecmp(value, "false") == 0)
+      else if (!strcasecmp(value, "off") ||
+              !strcasecmp(value, "no") ||
+              !strcasecmp(value, "false"))
        *wait_eof = false;
       else
        _cupsLangPrintf(stderr,
                        _("WARNING: Boolean expected for waiteof option "
                          "\"%s\"\n"), value);
     }
-    else if (strcasecmp(optionName, "serial") == 0)
-    {
+    else if (!strcasecmp(name, "serial"))
       strlcpy(serial, value, serial_size);
-    }
-    else if (strcasecmp(optionName, "location") == 0 && location)
+    else if (!strcasecmp(name, "location") && location)
       *location = strtol(value, NULL, 16);
   }
-
-  return;
 }
 
 
index d83ed99d3393142f45000709055c8754e08d22d4..1161cba906e98bf94c7f266fb56143bbe7daabb0 100644 (file)
@@ -48,7 +48,7 @@ int                                   /* O - Exit status */
 print_device(const char *uri,          /* I - Device URI */
              const char *hostname,     /* I - Hostname/manufacturer */
              const char *resource,     /* I - Resource/modelname */
-            const char *options,       /* I - Device options/serial number */
+            char       *options,       /* I - Device options/serial number */
             int        print_fd,       /* I - File descriptor to print */
             int        copies,         /* I - Copies to print */
             int        argc,           /* I - Number of command-line arguments (6 or 7) */
index bf1730ff98a6ddfc269b572ccfb56fcf3133bb8e..b9c0fc45048617769f0d94219314e0f19a894d78 100644 (file)
@@ -54,7 +54,7 @@
 
 void   list_devices(void);
 int    print_device(const char *uri, const char *hostname,
-                    const char *resource, const char *options,
+                    const char *resource, char *options,
                     int print_fd, int copies, int argc, char *argv[]);
 
 
@@ -99,7 +99,7 @@ int                                   /* O - Exit status */
 print_device(const char *uri,          /* I - Device URI */
              const char *hostname,     /* I - Hostname/manufacturer */
              const char *resource,     /* I - Resource/modelname */
-            const char *options,       /* I - Device options/serial number */
+            char       *options,       /* I - Device options/serial number */
             int        print_fd,       /* I - File descriptor to print */
             int        copies,         /* I - Copies to print */
             int        argc,           /* I - Number of command-line arguments (6 or 7) */