]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Accept job-originating-host-name attribute from local mini-daemons like
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Mon, 29 Apr 2002 17:25:26 +0000 (17:25 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Mon, 29 Apr 2002 17:25:26 +0000 (17:25 +0000)
cups-lpd.

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

CHANGES.txt
scheduler/cups-lpd.c
scheduler/ipp.c

index 541e4bd4d1a19f7f542133648c8cf1525ff76674..53fa18e39984e8420e9bc71b4bfacd7067945cf9 100644 (file)
@@ -1,10 +1,13 @@
-CHANGES.txt - 04/24/2002
+CHANGES.txt - 04/29/2002
 ------------------------
 
 CHANGES IN CUPS V1.1.15
 
        - Updated the CUPS license agreement for the new MacOS
          license exception.
+       - The LPD mini-daemon (cups-lpd) now passes the
+         job-originating-host-name attribute to the scheduler
+         (cupsd).
        - Updated the IPP backend to reconnect after downgrading
          from IPP/1.1 to 1.0, and when sending requests to HP
          JetDirect interfaces that don't support HTTP
index c07adcfd1adbbb85c196b729d3dc6799b68d6e9b..f39ef137c1cdb37a678601bf27286cb43f89d471 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: cups-lpd.c,v 1.31 2002/01/02 17:59:15 mike Exp $"
+ * "$Id: cups-lpd.c,v 1.32 2002/04/29 17:25:26 mike Exp $"
  *
  *   Line Printer Daemon interface for the Common UNIX Printing System (CUPS).
  *
@@ -106,7 +106,8 @@ main(int  argc,                     /* I - Number of command-line arguments */
   int          hostlen;        /* Size of client address */
   unsigned     hostip;         /* (32-bit) IP address */
   struct sockaddr_in hostaddr; /* Address of client */
-  struct hostent *hostname;    /* Name of client */
+  struct hostent *hostent;     /* Host entry of client */
+  char         hostname[256];  /* Hostname of client */
 
 
  /*
@@ -128,15 +129,29 @@ main(int  argc,                   /* I - Number of command-line arguments */
   hostlen = sizeof(hostaddr);
 
   if (getpeername(0, (struct sockaddr *)&hostaddr, &hostlen))
+  {
     syslog(LOG_WARNING, "Unable to get client address - %s", strerror(errno));
+    strcpy(hostname, "unknown");
+  }
   else
   {
     hostip   = ntohl(hostaddr.sin_addr.s_addr);
-    hostname = gethostbyaddr((void *)&(hostaddr.sin_addr), hostlen, AF_INET);
+    hostent  = gethostbyaddr((void *)&(hostaddr.sin_addr), hostlen, AF_INET);
+
+    if (hostent)
+    {
+      strncpy(hostname, hostent->h_name, sizeof(hostname) - 1);
+      hostname[sizeof(hostname) - 1] = '\0';
+    }
+    else
+    {
+      snprintf(hostname, sizeof(hostname), "%d.%d.%d.%d",
+               (hostip >> 24) & 255, (hostip >> 16) & 255,
+              (hostip >> 8) & 255, hostip & 255);
+    }
 
     syslog(LOG_INFO, "Connection from %s (%d.%d.%d.%d)",
-           hostname ? hostname->h_name : "unknown",
-           (hostip >> 24) & 255, (hostip >> 16) & 255,
+           hostname, (hostip >> 24) & 255, (hostip >> 16) & 255,
           (hostip >> 8) & 255, hostip & 255);
   }
 
@@ -147,6 +162,9 @@ main(int  argc,                     /* I - Number of command-line arguments */
   num_defaults = 0;
   defaults     = NULL;
 
+  num_defaults = cupsAddOption("job-originating-host-name", hostname,
+                               num_defaults, &defaults);
+
   for (i = 1; i < argc; i ++)
     if (argv[i][0] == '-')
     {
@@ -1283,5 +1301,5 @@ smart_gets(char *s,       /* I - Pointer to line buffer */
 
 
 /*
- * End of "$Id: cups-lpd.c,v 1.31 2002/01/02 17:59:15 mike Exp $".
+ * End of "$Id: cups-lpd.c,v 1.32 2002/04/29 17:25:26 mike Exp $".
  */
index 97cfc37e42a05477537fdefa7b65afbef62306d1..6bb59ce8c7d695f5b6e0a9caf5d0672ae4d0acd2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: ipp.c,v 1.156 2002/02/13 17:35:10 mike Exp $"
+ * "$Id: ipp.c,v 1.157 2002/04/29 17:25:26 mike Exp $"
  *
  *   IPP routines for the Common UNIX Printing System (CUPS) scheduler.
  *
@@ -2220,8 +2220,76 @@ create_job(client_t        *con, /* I - Client connection */
     attr->name = strdup("job-originating-user-name");
   }
 
-  ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, 
-               "job-originating-host-name", NULL, con->http.hostname);
+  if ((attr = ippFindAttribute(job->attrs, "job-originating-host-name",
+                               IPP_TAG_ZERO)) != NULL)
+  {
+   /*
+    * Request contains a job-originating-host-name attribute; validate it...
+    */
+
+    if (attr->value_tag != IPP_TAG_NAME ||
+        attr->num_values != 1 ||
+        strcmp(con->http.hostname, "localhost") != 0)
+    {
+     /*
+      * Can't override the value if we aren't connected via localhost.
+      * Also, we can only have 1 value and it must be a name value.
+      */
+
+      int i;   /* Looping var */
+
+      switch (attr->value_tag)
+      {
+        case IPP_TAG_STRING :
+       case IPP_TAG_TEXTLANG :
+       case IPP_TAG_NAMELANG :
+       case IPP_TAG_TEXT :
+       case IPP_TAG_NAME :
+       case IPP_TAG_KEYWORD :
+       case IPP_TAG_URI :
+       case IPP_TAG_URISCHEME :
+       case IPP_TAG_CHARSET :
+       case IPP_TAG_LANGUAGE :
+       case IPP_TAG_MIMETYPE :
+          /*
+           * Free old strings...
+           */
+
+           for (i = 0; i < attr->num_values; i ++)
+           {
+             free(attr->values[i].string.text);
+             attr->values[i].string.text = NULL;
+             if (attr->values[i].string.charset)
+             {
+               free(attr->values[i].string.charset);
+               attr->values[i].string.charset = NULL;
+             }
+            }
+
+       default :
+            break;
+      }
+
+     /*
+      * Use the default connection hostname instead...
+      */
+
+      attr->value_tag             = IPP_TAG_NAME;
+      attr->num_values            = 1;
+      attr->values[0].string.text = strdup(con->http.hostname);
+    }
+  }
+  else
+  {
+   /*
+    * No job-originating-host-name attribute, so use the hostname from
+    * the connection...
+    */
+
+    ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, 
+                "job-originating-host-name", NULL, con->http.hostname);
+  }
+
   ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "time-at-creation",
                 time(NULL));
   attr = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER,
@@ -4013,8 +4081,76 @@ print_job(client_t        *con,          /* I - Client connection */
   * Add remaining job attributes...
   */
 
-  ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, 
-               "job-originating-host-name", NULL, con->http.hostname);
+  if ((attr = ippFindAttribute(job->attrs, "job-originating-host-name",
+                               IPP_TAG_ZERO)) != NULL)
+  {
+   /*
+    * Request contains a job-originating-host-name attribute; validate it...
+    */
+
+    if (attr->value_tag != IPP_TAG_NAME ||
+        attr->num_values != 1 ||
+        strcmp(con->http.hostname, "localhost") != 0)
+    {
+     /*
+      * Can't override the value if we aren't connected via localhost.
+      * Also, we can only have 1 value and it must be a name value.
+      */
+
+      int i;   /* Looping var */
+
+      switch (attr->value_tag)
+      {
+        case IPP_TAG_STRING :
+       case IPP_TAG_TEXTLANG :
+       case IPP_TAG_NAMELANG :
+       case IPP_TAG_TEXT :
+       case IPP_TAG_NAME :
+       case IPP_TAG_KEYWORD :
+       case IPP_TAG_URI :
+       case IPP_TAG_URISCHEME :
+       case IPP_TAG_CHARSET :
+       case IPP_TAG_LANGUAGE :
+       case IPP_TAG_MIMETYPE :
+          /*
+           * Free old strings...
+           */
+
+           for (i = 0; i < attr->num_values; i ++)
+           {
+             free(attr->values[i].string.text);
+             attr->values[i].string.text = NULL;
+             if (attr->values[i].string.charset)
+             {
+               free(attr->values[i].string.charset);
+               attr->values[i].string.charset = NULL;
+             }
+            }
+
+       default :
+            break;
+      }
+
+     /*
+      * Use the default connection hostname instead...
+      */
+
+      attr->value_tag             = IPP_TAG_NAME;
+      attr->num_values            = 1;
+      attr->values[0].string.text = strdup(con->http.hostname);
+    }
+  }
+  else
+  {
+   /*
+    * No job-originating-host-name attribute, so use the hostname from
+    * the connection...
+    */
+
+    ippAddString(job->attrs, IPP_TAG_JOB, IPP_TAG_NAME, 
+                "job-originating-host-name", NULL, con->http.hostname);
+  }
+
   ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_INTEGER, "job-id", job->id);
   job->state = ippAddInteger(job->attrs, IPP_TAG_JOB, IPP_TAG_ENUM,
                              "job-state", IPP_JOB_PENDING);
@@ -5639,5 +5775,5 @@ validate_user(client_t   *con,            /* I - Client connection */
 
 
 /*
- * End of "$Id: ipp.c,v 1.156 2002/02/13 17:35:10 mike Exp $".
+ * End of "$Id: ipp.c,v 1.157 2002/04/29 17:25:26 mike Exp $".
  */