server-ipp.c
static int				// O - 1 if valid, 0 if not
valid_doc_attributes(
    lprint_client_t *client)		// I - Client
{
  int			valid = 1;	// Valid attributes?
  ipp_op_t		op = ippGetOperation(client->request);
					// IPP operation
  const char		*op_name = ippOpString(op);
					// IPP operation name
  ipp_attribute_t	*attr,		// Current attribute
			*supported;	// xxx-supported attribute
  const char		*compression = NULL,
					// compression value
			*format = NULL;	// document-format value


  // Check operation attributes...
  if ((attr = ippFindAttribute(client->request, "compression", IPP_TAG_ZERO)) != NULL)
  {
    // If compression is specified, only accept a supported value in a Print-Job
    // or Send-Document request...
    compression = ippGetString(attr, 0, NULL);
    supported   = ippFindAttribute(client->printer->attrs, "compression-supported", IPP_TAG_KEYWORD);

    if (ippGetCount(attr) != 1 || ippGetValueTag(attr) != IPP_TAG_KEYWORD || ippGetGroupTag(attr) != IPP_TAG_OPERATION || (op != IPP_OP_PRINT_JOB && op != IPP_OP_SEND_DOCUMENT && op != IPP_OP_VALIDATE_JOB) || !ippContainsString(supported, compression))
    {
      respond_unsupported(client, attr);
      valid = 0;
    }
    else
    {
      lprintLogClient(client, LPRINT_LOGLEVEL_DEBUG, "%s \"compression\"='%s'", op_name, compression);

      ippAddString(client->request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "compression-supplied", NULL, compression);

      if (strcmp(compression, "none"))
      {
        lprintLogClient(client, LPRINT_LOGLEVEL_INFO, "Receiving job file with '%s' compression.", compression);
        httpSetField(client->http, HTTP_FIELD_CONTENT_ENCODING, compression);
      }
    }
  }

  // Is it a format we support?
  if ((attr = ippFindAttribute(client->request, "document-format", IPP_TAG_ZERO)) != NULL)
  {
    if (ippGetCount(attr) != 1 || ippGetValueTag(attr) != IPP_TAG_MIMETYPE || ippGetGroupTag(attr) != IPP_TAG_OPERATION)
    {
      respond_unsupported(client, attr);
      valid = 0;
    }
    else
    {
      format = ippGetString(attr, 0, NULL);

      lprintLogClient(client, LPRINT_LOGLEVEL_DEBUG, "%s \"document-format\"='%s'", op_name, format);

      ippAddString(client->request, IPP_TAG_JOB, IPP_TAG_MIMETYPE, "document-format-supplied", NULL, format);
    }
  }
  else
  {
    format = ippGetString(ippFindAttribute(client->printer->attrs, "document-format-default", IPP_TAG_MIMETYPE), 0, NULL);
    if (!format)
      format = "application/octet-stream"; /* Should never happen */

    attr = ippAddString(client->request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format", NULL, format);
  }

  if (format && !strcmp(format, "application/octet-stream") && (ippGetOperation(client->request) == IPP_OP_PRINT_JOB || ippGetOperation(client->request) == IPP_OP_SEND_DOCUMENT))
  {
    // Auto-type the file using the first 8 bytes of the file...
    unsigned char	header[8];	// First 8 bytes of file

    memset(header, 0, sizeof(header));
    httpPeek(client->http, (char *)header, sizeof(header));

    if (!memcmp(header, "%PDF", 4))
      format = "application/pdf";
    else if (!memcmp(header, "%!", 2))
      format = "application/postscript";
    else if (!memcmp(header, "\377\330\377", 3) && header[3] >= 0xe0 && header[3] <= 0xef)
      format = "image/jpeg";
    else if (!memcmp(header, "\211PNG", 4))
      format = "image/png";
    else if (!memcmp(header, "RAS2", 4))
      format = "image/pwg-raster";
    else if (!memcmp(header, "UNIRAST", 8))
      format = "image/urf";
    else
      format = client->printer->driver->format;

    if (format)
    {
      lprintLogClient(client, LPRINT_LOGLEVEL_DEBUG, "%s Auto-typed \"document-format\"='%s'.", op_name, format);

      ippAddString(client->request, IPP_TAG_JOB, IPP_TAG_MIMETYPE, "document-format-detected", NULL, format);
    }
  }

  if (op != IPP_OP_CREATE_JOB && (supported = ippFindAttribute(client->printer->attrs, "document-format-supported", IPP_TAG_MIMETYPE)) != NULL && !ippContainsString(supported, format))
  {
    respond_unsupported(client, attr);
    valid = 0;
  }

  return (valid);
}
//
// 'valid_doc_attributes()' - Determine whether the document attributes are
//                            valid.
//
// When one or more document attributes are invalid, this function adds a
// suitable response and attributes to the unsupported group.
//
'valid_doc_attributes()' - Determine whether the document attributes are
valid.

When one or more document attributes are invalid, this function adds a
suitable response and attributes to the unsupported group.
' valid_doc_attributes () ' - Determine whether the document attributes are valid . When one or more document attributes are invalid this function adds a suitable response and attributes to the unsupported group .
static int				
valid_doc_attributes(
    lprint_client_t *client)		
{
  int			valid = 1;	
  ipp_op_t		op = ippGetOperation(client->request);
  const char		*op_name = ippOpString(op);
					 name
  ipp_attribute_t	*attr,		
			*supported;	
  const char		*compression = NULL,
			*format = NULL;	
  if ((attr = ippFindAttribute(client->request, "compression", IPP_TAG_ZERO)) != NULL)
  {
    compression = ippGetString(attr, 0, NULL);
    supported   = ippFindAttribute(client->printer->attrs, "compression-supported", IPP_TAG_KEYWORD);
    if (ippGetCount(attr) != 1 || ippGetValueTag(attr) != IPP_TAG_KEYWORD || ippGetGroupTag(attr) != IPP_TAG_OPERATION || (op != IPP_OP_PRINT_JOB && op != IPP_OP_SEND_DOCUMENT && op != IPP_OP_VALIDATE_JOB) || !ippContainsString(supported, compression))
    {
      respond_unsupported(client, attr);
      valid = 0;
    }
    else
    {
      lprintLogClient(client, LPRINT_LOGLEVEL_DEBUG, "%s \"compression\"='%s'", op_name, compression);
      ippAddString(client->request, IPP_TAG_JOB, IPP_TAG_KEYWORD, "compression-supplied", NULL, compression);
      if (strcmp(compression, "none"))
      {
        lprintLogClient(client, LPRINT_LOGLEVEL_INFO, "Receiving job file with '%s' compression.", compression);
        httpSetField(client->http, HTTP_FIELD_CONTENT_ENCODING, compression);
      }
    }
  }
  if ((attr = ippFindAttribute(client->request, "document-format", IPP_TAG_ZERO)) != NULL)
  {
    if (ippGetCount(attr) != 1 || ippGetValueTag(attr) != IPP_TAG_MIMETYPE || ippGetGroupTag(attr) != IPP_TAG_OPERATION)
    {
      respond_unsupported(client, attr);
      valid = 0;
    }
    else
    {
      format = ippGetString(attr, 0, NULL);
      lprintLogClient(client, LPRINT_LOGLEVEL_DEBUG, "%s \"document-format\"='%s'", op_name, format);
      ippAddString(client->request, IPP_TAG_JOB, IPP_TAG_MIMETYPE, "document-format-supplied", NULL, format);
    }
  }
  else
  {
    format = ippGetString(ippFindAttribute(client->printer->attrs, "document-format-default", IPP_TAG_MIMETYPE), 0, NULL);
    if (!format)
      format = "application/octet-stream"; 
    attr = ippAddString(client->request, IPP_TAG_OPERATION, IPP_TAG_MIMETYPE, "document-format", NULL, format);
  }
  if (format && !strcmp(format, "application/octet-stream") && (ippGetOperation(client->request) == IPP_OP_PRINT_JOB || ippGetOperation(client->request) == IPP_OP_SEND_DOCUMENT))
  {
    unsigned char	header[8];	
    memset(header, 0, sizeof(header));
    httpPeek(client->http, (char *)header, sizeof(header));
    if (!memcmp(header, "%PDF", 4))
      format = "application/pdf";
    else if (!memcmp(header, "%!", 2))
      format = "application/postscript";
    else if (!memcmp(header, "\377\330\377", 3) && header[3] >= 0xe0 && header[3] <= 0xef)
      format = "image/jpeg";
    else if (!memcmp(header, "\211PNG", 4))
      format = "image/png";
    else if (!memcmp(header, "RAS2", 4))
      format = "image/pwg-raster";
    else if (!memcmp(header, "UNIRAST", 8))
      format = "image/urf";
    else
      format = client->printer->driver->format;
    if (format)
    {
      lprintLogClient(client, LPRINT_LOGLEVEL_DEBUG, "%s Auto-typed \"document-format\"='%s'.", op_name, format);
      ippAddString(client->request, IPP_TAG_JOB, IPP_TAG_MIMETYPE, "document-format-detected", NULL, format);
    }
  }
  if (op != IPP_OP_CREATE_JOB && (supported = ippFindAttribute(client->printer->attrs, "document-format-supported", IPP_TAG_MIMETYPE)) != NULL && !ippContainsString(supported, format))
  {
    respond_unsupported(client, attr);
    valid = 0;
  }
  return (valid);
}
static int valid_doc_attributes ( lprint_client_t * client ) { int valid = 1 ; ipp_op_t op = ippGetOperation ( client -> request ) ; const char * op_name = ippOpString ( op ) ; ipp_attribute_t * attr , * supported ; const char * compression = NULL , * format = NULL ; if ( ( attr = ippFindAttribute ( client -> request , " " , IPP_TAG_ZERO ) ) != NULL ) { compression = ippGetString ( attr , 0 , NULL ) ; supported = ippFindAttribute ( client -> printer -> attrs , " " , IPP_TAG_KEYWORD ) ; if ( ippGetCount ( attr ) != 1 || ippGetValueTag ( attr ) != IPP_TAG_KEYWORD || ippGetGroupTag ( attr ) != IPP_TAG_OPERATION || ( op != IPP_OP_PRINT_JOB && op != IPP_OP_SEND_DOCUMENT && op != IPP_OP_VALIDATE_JOB ) || ! ippContainsString ( supported , compression ) ) { respond_unsupported ( client , attr ) ; valid = 0 ; } else { lprintLogClient ( client , LPRINT_LOGLEVEL_DEBUG , " \" \" " , op_name , compression ) ; ippAddString ( client -> request , IPP_TAG_JOB , IPP_TAG_KEYWORD , " " , NULL , compression ) ; if ( strcmp ( compression , " " ) ) { lprintLogClient ( client , LPRINT_LOGLEVEL_INFO , " " , compression ) ; httpSetField ( client -> http , HTTP_FIELD_CONTENT_ENCODING , compression ) ; } } } if ( ( attr = ippFindAttribute ( client -> request , " " , IPP_TAG_ZERO ) ) != NULL ) { if ( ippGetCount ( attr ) != 1 || ippGetValueTag ( attr ) != IPP_TAG_MIMETYPE || ippGetGroupTag ( attr ) != IPP_TAG_OPERATION ) { respond_unsupported ( client , attr ) ; valid = 0 ; } else { format = ippGetString ( attr , 0 , NULL ) ; lprintLogClient ( client , LPRINT_LOGLEVEL_DEBUG , " \" \" " , op_name , format ) ; ippAddString ( client -> request , IPP_TAG_JOB , IPP_TAG_MIMETYPE , " " , NULL , format ) ; } } else { format = ippGetString ( ippFindAttribute ( client -> printer -> attrs , " " , IPP_TAG_MIMETYPE ) , 0 , NULL ) ; if ( ! format ) format = " " ; attr = ippAddString ( client -> request , IPP_TAG_OPERATION , IPP_TAG_MIMETYPE , " " , NULL , format ) ; } if ( format && ! strcmp ( format , " " ) && ( ippGetOperation ( client -> request ) == IPP_OP_PRINT_JOB || ippGetOperation ( client -> request ) == IPP_OP_SEND_DOCUMENT ) ) { unsigned char header [ 8 ] ; memset ( header , 0 , sizeof ( header ) ) ; httpPeek ( client -> http , ( char * ) header , sizeof ( header ) ) ; if ( ! memcmp ( header , " " , 4 ) ) format = " " ; else if ( ! memcmp ( header , " " , 2 ) ) format = " " ; else if ( ! memcmp ( header , " \377 \330 \377 " , 3 ) && header [ 3 ] >= 0xe0 && header [ 3 ] <= 0xef ) format = " " ; else if ( ! memcmp ( header , " \211 " , 4 ) ) format = " " ; else if ( ! memcmp ( header , " " , 4 ) ) format = " " ; else if ( ! memcmp ( header , " " , 8 ) ) format = " " ; else format = client -> printer -> driver -> format ; if ( format ) { lprintLogClient ( client , LPRINT_LOGLEVEL_DEBUG , " \" \" " , op_name , format ) ; ippAddString ( client -> request , IPP_TAG_JOB , IPP_TAG_MIMETYPE , " " , NULL , format ) ; } } if ( op != IPP_OP_CREATE_JOB && ( supported = ippFindAttribute ( client -> printer -> attrs , " " , IPP_TAG_MIMETYPE ) ) != NULL && ! ippContainsString ( supported , format ) ) { respond_unsupported ( client , attr ) ; valid = 0 ; } return ( valid ) ; }
'valid_doc_attributes()' - Determine whether the document attributes are
valid.
' valid_doc_attributes () ' - Determine whether the document attributes are valid .
// O - 1 if valid, 0 if not // I - Client // Valid attributes? // IPP operation // IPP operation name // Current attribute // xxx-supported attribute // compression value // document-format value // Check operation attributes... // If compression is specified, only accept a supported value in a Print-Job // or Send-Document request... // Is it a format we support? /* Should never happen */ // Auto-type the file using the first 8 bytes of the file... // First 8 bytes of file