[cups-devel] Cannot Retrieve Default Media Type

Jim Orcheson jimorcheson at gmail.com
Sat Jan 30 07:05:27 PST 2021


I cannot retrieve the default media type for my printer. Here is the C++ 
code that I am using:

             cups_dinfo_t *info = cupsCopyDestInfo(CUPS_HTTP_DEFAULT, 
m_dest);
             const char *defaultType =
                 cupsGetOption(CUPS_MEDIA_TYPE, m_dest->num_options, 
m_dest->options);
             if(defaultType != nullptr)
             {
                 m_defaultMediaType = MediaType(defaultType);
             }
             else
             {
                 ipp_attribute_t *type = 
cupsFindDestDefault(CUPS_HTTP_DEFAULT, m_dest,
                     info, CUPS_MEDIA_TYPE);
                 int count = ippGetCount(type);
                 if (count != 0)
                 {
                     const char *defaultType = ippGetString(type, 0, NULL);
                     m_defaultMediaType = MediaType(defaultType);
                 }
                 else
                 {
                     m_defaultMediaType = nullopt;
                 }

             }
             m_gotDefaultMediaType = true;

m_defaultMediaType is of type std::optional. After the call to 
ippGetCount, count = 0.

I have similar code to retrieve the default color mode:

             cups_dinfo_t *info = cupsCopyDestInfo(CUPS_HTTP_DEFAULT, 
m_dest);
             const char *defaultColorMode =
                 cupsGetOption(CUPS_PRINT_COLOR_MODE, 
m_dest->num_options, m_dest->options);
             if (defaultColorMode != nullptr)
             {
                 m_defaultColorMode = ColorMode(defaultColorMode);
             }
             else
             {
                 ipp_attribute_t *defColorMode = 
cupsFindDestDefault(http, m_dest,
                     info, CUPS_PRINT_COLOR_MODE);
                 int count = ippGetCount(defColorMode);
                 if (count != 0)
                 {
                     const char *defaultColorMode = 
ippGetString(defColorMode, 0, NULL);
                     m_defaultColorMode = ColorMode(defaultColorMode);
                 }
                 else
                 {
                     m_defaultColorMode = nullopt;
                 }

             }
             m_gotDefaultColorMode = true;

After the call to ippGetCount, count = 1.

What is wrong with the code to retrieve the default media type?

This is on Ubuntu 20.04 with cups 2.3.1.



More information about the cups-devel mailing list