]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - test/ippfind.c
libcupsimage is now in the "cups" directory.
[thirdparty/cups.git] / test / ippfind.c
index 8e5c9569659be59aa28e8d91d900e9f0f425f4c6..ba814147364e2c86a2d75bca2e95ad8d461f1fdd 100644 (file)
@@ -1,19 +1,12 @@
 /*
- * "$Id$"
- *
  * Utility to find IPP printers via Bonjour/DNS-SD and optionally run
  * commands such as IPP and Bonjour conformance tests.  This tool is
  * inspired by the UNIX "find" command, thus its name.
  *
- * Copyright 2008-2014 by Apple Inc.
- *
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
- * which should have been included with this file.  If this file is
- * file is missing or damaged, see the license at "http://www.cups.org/".
+ * Copyright 2008-2017 by Apple Inc.
  *
- * This file is subject to the Apple OS-Developed Software exception.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more
+ * information.
  */
 
 /*
@@ -1175,27 +1168,46 @@ main(int  argc,                         /* I - Number of command-line args */
                        *domain;        /* Domain, if any */
 
     strlcpy(buf, search, sizeof(buf));
-    if (buf[0] == '_')
-    {
-      regtype = buf;
-    }
-    else if ((regtype = strstr(buf, "._")) != NULL)
+    if ((regtype = strstr(buf, "._")) != NULL)
     {
-      name = buf;
-      *regtype++ = '\0';
+      if (strcmp(regtype, "._tcp"))
+      {
+       /*
+        * "something._protocol._tcp" -> search for something with the given
+        * protocol...
+        */
+
+       name = buf;
+       *regtype++ = '\0';
+      }
+      else
+      {
+       /*
+        * "_protocol._tcp" -> search for everything with the given protocol...
+        */
+
+        /* name = NULL; */
+        regtype = buf;
+      }
     }
     else
     {
+     /*
+      * "something" -> search for something with IPP protocol...
+      */
+
       name    = buf;
       regtype = "_ipp._tcp";
     }
 
     for (domain = regtype; *domain; domain ++)
+    {
       if (*domain == '.' && domain[1] != '_')
       {
-        *domain++ = '\0';
-        break;
+       *domain++ = '\0';
+       break;
       }
+    }
 
     if (!*domain)
       domain = NULL;
@@ -1266,14 +1278,6 @@ main(int  argc,                          /* I - Number of command-line args */
       _cupsLangPrintf(stderr, _("ippfind: Unable to browse or resolve: %s"),
                       dnssd_error_string(err));
 
-      if (name)
-        printf("name=\"%s\"\n", name);
-
-      printf("regtype=\"%s\"\n", regtype);
-
-      if (domain)
-        printf("domain=\"%s\"\n", domain);
-
       return (IPPFIND_EXIT_BONJOUR);
     }
   }
@@ -1978,14 +1982,14 @@ exec_program(ippfind_srv_t *service,    /* I - Service */
          else if (!strcmp(keyword, "service_path"))
            strlcpy(tptr, service->resource, sizeof(temp) - (size_t)(tptr - temp));
          else if (!strcmp(keyword, "service_port"))
-           strlcpy(tptr, port + 20, sizeof(temp) - (size_t)(tptr - temp));
+           strlcpy(tptr, port + 21, sizeof(temp) - (size_t)(tptr - temp));
          else if (!strcmp(keyword, "service_scheme"))
            strlcpy(tptr, scheme + 22, sizeof(temp) - (size_t)(tptr - temp));
          else if (!strncmp(keyword, "txt_", 4))
          {
-           const char *txt = cupsGetOption(keyword + 4, service->num_txt, service->txt);
-           if (txt)
-             strlcpy(tptr, txt, sizeof(temp) - (size_t)(tptr - temp));
+           const char *val = cupsGetOption(keyword + 4, service->num_txt, service->txt);
+           if (val)
+             strlcpy(tptr, val, sizeof(temp) - (size_t)(tptr - temp));
            else
              *tptr = '\0';
          }
@@ -2564,6 +2568,10 @@ resolve_callback(
   service->host        = strdup(hostTarget);
   service->port        = ntohs(port);
 
+  value = service->host + strlen(service->host) - 1;
+  if (value >= service->host && *value == '.')
+    *value = '\0';
+
  /*
   * Loop through the TXT key/value pairs and add them to an array...
   */
@@ -2635,6 +2643,10 @@ resolve_callback(
   service->host        = strdup(hostTarget);
   service->port        = port;
 
+  value = service->host + strlen(service->host) - 1;
+  if (value >= service->host && *value == '.')
+    *value = '\0';
+
  /*
   * Loop through the TXT key/value pairs and add them to an array...
   */
@@ -2832,8 +2844,3 @@ show_version(void)
 
   exit(IPPFIND_EXIT_TRUE);
 }
-
-
-/*
- * End of "$Id$".
- */