[cups] debugging file auto-typing

Tim Mooney Tim.Mooney at ndsu.edu
Tue Feb 26 15:14:08 PST 2019


In regard to: [cups] debugging file auto-typing, Tim Mooney said (at 7:03pm...:

Following up to my original email, to close out the thread and in the
hopes that this helps someone else down the road that may be wondering
what CUPS is doing for auto-typing...

> I know I can use local.types and my own types with priority() to force
> CUPS to prefer a particular type, but what I'm trying to determine is
> which types are coming out of the process as candidates.

With the old version of CUPS I'm using (1.4.2 on RHEL 6.10), I wasn't
able to find an easy way to get CUPS to tell me all the super/type matches.
I didn't expect LogLevel debug2 to provide that info, and I've verified
that (at least under this version) it does not.

Zdenek's response provided the information that was closest to what I
was asking for, including the mimeFileType() routine in scheduler/type.c .
That was extremely helpful, because it got me pointed at the place I
needed to start, right away.

I ended up downloading the RHEL 1.4.2-80 source RPM and adding some
debugging fprintf()'s in the for loop around checkrules().  That gave
me the kind of targeted debugging I was looking for.

Another option would be to build with the configure option
--enable-debug-printfs and then set CUPS_DEBUG_LOG=/path/to/some/file
and CUPS_DEBUG_LEVEL=9 and run cupsfilter with your file.

So, given a file that was originally a PDF that has been converted to
PCL and submitted, with a header that looks like this:

ESC%-12345X at PJL JOB NAME = "DataSvcsRequestForm-Mem Union.pdf"
@PJL COMMENT "PrintWhere 6.2 Plug-in 0974 (0.3.1584.23510); Windows Server 2016 Standard 6.2.9200.3; Unidrv 0.3.16299.402"
@PJL COMMENT "Username: someusername; App Filename: DataSvcsRequestForm-Mem Union.pdf; 2-11-2019"
@PJL COMMENT "NUP = NUP_1"
@PJL SET JOBATTR="OS=Windows"
@PJL SET JOBATTR="OS Version=Windows Server 2016 Standard 6.2.9200.3"
@PJL SET JOBATTR="Render Type=UPD"
@PJL SET JOBATTR="Render Name=HP Universal Printing PCL 6"
@PJL SET JOBATTR="Render Version=61.220.1.23510"
@PJL SET JOBATTR="JobAcct1=someusername"
@PJL SET JOBATTR="JobAcct2=PRINTERON"
@PJL SET JOBATTR="JobAcct3=AD"
@PJL SET JOBATTR="JobAcct4=20190211155143"
@PJL SET JOBATTR="JobAcct5=349c8e00-7d70-43dd-89e9-fdfb8eb7a3bf"
@PJL SET JOBATTR="JobAcct6=ACM_EXE Application"
@PJL SET JOBATTR="JobAcct7=ACM_EXE64.exe"
@PJL SET JOBATTR="JobAcct8=someusername"
@PJL SET JOBATTR="JobAcct9="
@PJL SET RET=OFF
@PJL DMINFO ASCIIHEX="0400040101020D101001153230313930323131323135313433"
@PJL SET PLANESINUSE=1
@PJL SET GRAYSCALE=BLACKONLY
@PJL SET SEPARATORPAGE=OFF
@PJL SET FOLD=""
@PJL SET PROCESSINGACTION=APPEND
@PJL SET PROCESSINGTYPE="PUNCH"
@PJL SET PROCESSINGOPTION="NONE"
@PJL SET PROCESSINGBOUNDARY=MOPY
@PJL SET OUTBIN=AUTO
@PJL SET OUTBIN=AUTO
@PJL SET EDGETOEDGE=NO
@PJL SET PROCESSINGACTION=APPEND
@PJL SET PROCESSINGTYPE="STAPLING"
@PJL SET PROCESSINGOPTION="NONE"
@PJL SET PROCESSINGBOUNDARY=MOPY
@PJL SET ECONOMODE=OFF
@PJL SET KEEPGLOSSMODE=UNDEFINED
@PJL SET RESOLUTION=600
@PJL SET BITSPERPIXEL=1
@PJL SET DUPLEX = OFF
@PJL SET PON_MODETYPE = "1"
@PJL SET RENDERMODE=GRAYSCALE
@PJL SET COLORMODE=MONO
@PJL SET PON_JOB = "1"
@PJL SET PON_ML = "0"
@PJL SET PON_JOBOWNER = "a.username"
@PJL SET HOSTLOGINNAME = "a.username"
@PJL SET USERNAME = "a.username"
@PJL SET PON_JOBNAME="DataSvcsRequestForm-Mem Union.pdf"
@PJL SET JOBNAME="DataSvcsRequestForm-Mem Union.pdf"
@PJL SET PON_HOSTNAME = "PRINTERON"
@PJL SET HOST = "PRINTERON"
@PJL SET PON_GUID = "900739427876"
@PJL SET PON_DEVALIAS = "qbb-228-b"
@PJL SET PON_REFID = "1000638"
@PJL SET PON_COVERPG = "0"
@PJL SET PON_SUBMITTYPE = "Web"
@PJL SET PON_SUBMITFILETYPE = "{0060d0f0-912c-01c2-ad00-1086643dd3ac}"
@PJL SET PON_PASSTHROUGH = "0"
@PJL SET PON_RENDERINGAPP = "PDFium"
@PJL SET PON_EMAILLOOKUPUSERTYPE = "anon"
@PJL SET PON_OUTPUTFILETYPE = "PCL"
@PJL ENTER LANGUAGE=PCLXL
) HP-PCL XL;2;1;Comment Copyright(c) 1999 Microsoft Corporation

[binary data after this point]


Running cupsfilter from my build directory (and forcing it to use my
modified library that includes the additional fprintf()'s) with the
file in question shows that there are actually 3 super/types that
are matching:

 	application/pdf
 	application/vnd.cups-raw
 	text/plain

They all have the same default priority (100), so CUPS breaks the
tie as described in mime.types(5), choosing application/pdf since
it's alphanumerically earliest.

I had expected the first two matches, but not the text/plain match.
I didn't add debugging to checkrules() beyond what --enable-debug-printfs
already provided, but there are only two rules defined in my mime.types
for text/plain:

text/plain          txt printable(0,1024)

The original filename did not have .txt as an extension, so it would
seem it has to be the printable(0,1024) that's matching.  I can
see in the output from DEBUG_printf that MIME_MAGIC_PRINTABLE is indeed
matching.  Based on my reading of mime.types(5), that seems like a bug
but I haven't dug any deeper.

In addition, the version of CUPS I have seems to have a separate bug
related to local mime.types.  If I keep /usr/share/cups/mime/mime.types
unmodified, including the default rule for application/pdf:

application/pdf         pdf string(0,%PDF)

but I add a local rule in /etc/cups/local.types like this:

application/pdf			string(0,%PDF)

my local rule doesn't override the filename extension portion of the
default from /usr/share/cups/mime/mime.types.  The checkrules() routine
still does filename match() checking for the .pdf extension.

The man pages doesn't make it clear whether that's by design or not,
but it certainly seems like a bug.

That seems to be the best current way to expose what checkrules() and
the auto-typing are doing.

Tim
-- 
Tim Mooney                                             Tim.Mooney at ndsu.edu
Enterprise Computing & Infrastructure                  701-231-1076 (Voice)
Room 242-J6, Quentin Burdick Building                  701-231-8541 (Fax)
North Dakota State University, Fargo, ND 58105-5164


More information about the cups mailing list