]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Replace the rest of the uses of __attribute__ that need to be portable (Issue #5349)
authorMichael R Sweet <michael.r.sweet@gmail.com>
Mon, 9 Jul 2018 17:42:25 +0000 (13:42 -0400)
committerMichael R Sweet <michael.r.sweet@gmail.com>
Mon, 9 Jul 2018 17:42:25 +0000 (13:42 -0400)
25 files changed:
backend/dnssd.c
backend/testbackend.c
backend/usb-darwin.c
berkeley/lpq.c
cgi-bin/help-index.c
cups/ipp.c
cups/testdest.c
cups/testsnmp.c
cups/versioning.h
filter/pstops.c
scheduler/cups-exec.c
scheduler/cupsfilter.c
scheduler/ipp.c
scheduler/main.c
scheduler/testlpd.c
scheduler/testspeed.c
scheduler/testsub.c
systemv/cupsaddsmb.c
systemv/cupsctl.c
systemv/cupstestdsc.c
systemv/cupstestppd.c
systemv/lpoptions.c
test/ippfind.c
test/ippserver.c
test/ipptool.c

index 7074f4294abc4613bcf9b798f64eebca3b1254b4..fde79ecb974733e57ed6d00d6cc47bcf61f0dd78 100644 (file)
@@ -82,23 +82,8 @@ static int           browsers = 0;   /* Number of running browsers */
  */
 
 #ifdef HAVE_DNSSD
-static void            browse_callback(DNSServiceRef sdRef,
-                                       DNSServiceFlags flags,
-                                       uint32_t interfaceIndex,
-                                       DNSServiceErrorType errorCode,
-                                       const char *serviceName,
-                                       const char *regtype,
-                                       const char *replyDomain, void *context)
-                                       __attribute__((nonnull(1,5,6,7,8)));
-static void            browse_local_callback(DNSServiceRef sdRef,
-                                             DNSServiceFlags flags,
-                                             uint32_t interfaceIndex,
-                                             DNSServiceErrorType errorCode,
-                                             const char *serviceName,
-                                             const char *regtype,
-                                             const char *replyDomain,
-                                             void *context)
-                                             __attribute__((nonnull(1,5,6,7,8)));
+static void            browse_callback(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *serviceName, const char *regtype, const char *replyDomain, void *context) _CUPS_NONNULL(1,5,6,7,8);
+static void            browse_local_callback(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *serviceName, const char *regtype, const char *replyDomain, void *context) _CUPS_NONNULL(1,5,6,7,8);
 #endif /* HAVE_DNSSD */
 #ifdef HAVE_AVAHI
 static void            browse_callback(AvahiServiceBrowser *browser,
@@ -116,22 +101,10 @@ static void               client_callback(AvahiClient *client,
 #endif /* HAVE_AVAHI */
 
 static int             compare_devices(cups_device_t *a, cups_device_t *b);
-static void            exec_backend(char **argv) __attribute__((noreturn));
-static cups_device_t   *get_device(cups_array_t *devices,
-                                   const char *serviceName,
-                                   const char *regtype,
-                                   const char *replyDomain)
-                                   __attribute__((nonnull(1,2,3,4)));
+static void            exec_backend(char **argv) _CUPS_NORETURN;
+static cups_device_t   *get_device(cups_array_t *devices, const char *serviceName, const char *regtype, const char *replyDomain) _CUPS_NONNULL(1,2,3,4);
 #ifdef HAVE_DNSSD
-static void            query_callback(DNSServiceRef sdRef,
-                                      DNSServiceFlags flags,
-                                      uint32_t interfaceIndex,
-                                      DNSServiceErrorType errorCode,
-                                      const char *fullName, uint16_t rrtype,
-                                      uint16_t rrclass, uint16_t rdlen,
-                                      const void *rdata, uint32_t ttl,
-                                      void *context)
-                                      __attribute__((nonnull(1,5,9,11)));
+static void            query_callback(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *fullName, uint16_t rrtype, uint16_t rrclass, uint16_t rdlen, const void *rdata, uint32_t ttl, void *context) _CUPS_NONNULL(1,5,9,11);
 #elif defined(HAVE_AVAHI)
 static int             poll_callback(struct pollfd *pollfds,
                                      unsigned int num_pollfds, int timeout,
@@ -147,8 +120,7 @@ static void         query_callback(AvahiRecordBrowser *browser,
                                       void *context);
 #endif /* HAVE_DNSSD */
 static void            sigterm_handler(int sig);
-static void            unquote(char *dst, const char *src, size_t dstsize)
-                           __attribute__((nonnull(1,2)));
+static void            unquote(char *dst, const char *src, size_t dstsize) _CUPS_NONNULL(1,2);
 
 
 /*
index b8dbe3bd1ebcff2788bb2431f5451e729bbb440c..6dbd0abee691651678b3ca330e9cddec835a3c1f 100644 (file)
@@ -33,7 +33,7 @@ static int    job_canceled = 0;
  */
 
 static void    sigterm_handler(int sig);
-static void    usage(void) __attribute__((noreturn));
+static void    usage(void) _CUPS_NORETURN;
 static void    walk_cb(const char *oid, const char *data, int datalen,
                        void *context);
 
index 4f31d031a8a6a99cc87fc85879a708f6588a4060..4a85b476619e6629e8a9430f459df4639028ae51 100644 (file)
@@ -290,10 +290,10 @@ static void status_timer_cb(CFRunLoopTimerRef timer, void *info);
 
 #if defined(__i386__) || defined(__x86_64__)
 static pid_t   child_pid;              /* Child PID */
-static void run_legacy_backend(int argc, char *argv[], int fd) __attribute__((noreturn));      /* Starts child backend process running as a ppc executable */
+static void run_legacy_backend(int argc, char *argv[], int fd) _CUPS_NORETURN; /* Starts child backend process running as a ppc executable */
 #endif /* __i386__ || __x86_64__ */
 static void sigterm_handler(int sig);  /* SIGTERM handler */
-static void sigquit_handler(int sig, siginfo_t *si, void *unused) __attribute__((noreturn));
+static void sigquit_handler(int sig, siginfo_t *si, void *unused) _CUPS_NORETURN;
 
 #ifdef PARSE_PS_ERRORS
 static const char *next_line (const char *buffer);
index eec41dbb6074b110c12aef9377688725b877085f..47220f5d77c2792694b597e52edf8334f4d427ba 100644 (file)
@@ -22,7 +22,7 @@ static http_t *connect_server(const char *, http_t *);
 static int     show_jobs(const char *, http_t *, const char *,
                          const char *, const int, const int);
 static void    show_printer(const char *, http_t *, const char *);
-static void    usage(void) __attribute__((noreturn));
+static void    usage(void) _CUPS_NORETURN;
 
 
 /*
index 8e00f04676b8c951aa212cc6df9ab887e6da5669..5f76d7aa55ab9993a89027d39dd77f261e5a6abc 100644 (file)
@@ -134,11 +134,7 @@ static int         help_load_file(help_index_t *hi,
                                       const char *filename,
                                       const char *relative,
                                       time_t     mtime);
-static help_node_t     *help_new_node(const char *filename, const char *anchor,
-                                      const char *section, const char *text,
-                                      time_t mtime, off_t offset,
-                                      size_t length)
-                                      __attribute__((nonnull(1,3,4)));
+static help_node_t     *help_new_node(const char *filename, const char *anchor, const char *section, const char *text, time_t mtime, off_t offset, size_t length) _CUPS_NONNULL(1,3,4);
 static int             help_sort_by_name(help_node_t *p1, help_node_t *p2);
 static int             help_sort_by_score(help_node_t *p1, help_node_t *p2);
 static int             help_sort_words(help_word_t *w1, help_word_t *w2);
index 325de02b9235ee20bfbebb04f6928bf959d480e2..904380c6dacf168c0de210e2afc748608f1c898a 100644 (file)
@@ -28,12 +28,8 @@ static ipp_attribute_t       *ipp_add_attr(ipp_t *ipp, const char *name,
                                      int num_values);
 static void            ipp_free_values(ipp_attribute_t *attr, int element,
                                        int count);
-static char            *ipp_get_code(const char *locale, char *buffer,
-                                     size_t bufsize)
-                                     __attribute__((nonnull(1,2)));
-static char            *ipp_lang_code(const char *locale, char *buffer,
-                                      size_t bufsize)
-                                      __attribute__((nonnull(1,2)));
+static char            *ipp_get_code(const char *locale, char *buffer, size_t bufsize) _CUPS_NONNULL(1,2);
+static char            *ipp_lang_code(const char *locale, char *buffer, size_t bufsize) _CUPS_NONNULL(1,2);
 static size_t          ipp_length(ipp_t *ipp, int collection);
 static ssize_t         ipp_read_http(http_t *http, ipp_uchar_t *buffer,
                                      size_t length);
index 7381ba34ee74442f3f28e8ff278810074702f319..a65e09960d84cd1219e8c1f010331595f023a2d0 100644 (file)
@@ -26,7 +26,7 @@ static void   show_conflicts(http_t *http, cups_dest_t *dest, cups_dinfo_t *dinfo,
 static void    show_default(http_t *http, cups_dest_t *dest, cups_dinfo_t *dinfo, const char *option);
 static void    show_media(http_t *http, cups_dest_t *dest, cups_dinfo_t *dinfo, unsigned flags, const char *name);
 static void    show_supported(http_t *http, cups_dest_t *dest, cups_dinfo_t *dinfo, const char *option, const char *value);
-static void    usage(const char *arg) __attribute__((noreturn));
+static void    usage(const char *arg) _CUPS_NORETURN;
 
 
 /*
index 7a493e1f093342b7123823cceca65f06bfcd8fe8..8071847a780353131dee099d2e5575c48293ffc2 100644 (file)
@@ -21,7 +21,7 @@
 static void    print_packet(cups_snmp_t *packet, void *data);
 static int     show_oid(int fd, const char *community,
                         http_addr_t *addr, const char *s, int walk);
-static void    usage(void) __attribute__((noreturn));
+static void    usage(void) _CUPS_NORETURN;
 
 
 /*
index 12328d688a68a80dc9667f2c0a39e6717c0ef16e..19cd186a6745f4daf7f4195da15980cbbecdd50f 100644 (file)
@@ -25,6 +25,7 @@
  *   - _CUPS_INTERNAL_MSG("msg"): Function is
  *   - _CUPS_NONNULL((arg list)): Specifies the comma-separated argument indices
  *     are assumed non-NULL.  Indices start at 1.
+ *   - _CUPS_NORETURN: Specifies the function does not return.
  *   - _CUPS_PRIVATE: Specifies the function is private to CUPS.
  *   - _CUPS_PUBLIC: Specifies the function is public API.
  */
@@ -41,6 +42,7 @@
 #  ifdef __has_extension               /* Clang */
 #    define _CUPS_HAS_DEPRECATED
 #    define _CUPS_HAS_FORMAT
+#    define _CUPS_HAS_NORETURN
 #    define _CUPS_HAS_VISIBILITY
 #    if __has_extension(attribute_deprecated_with_message)
 #      define _CUPS_HAS_DEPRECATED_WITH_MESSAGE
@@ -52,6 +54,7 @@
 #    if __GNUC__ >= 3                  /* GCC 3.0 or higher */
 #      define _CUPS_HAS_DEPRECATED
 #      define _CUPS_HAS_FORMAT
+#      define _CUPS_HAS_NORETURN
 #      define _CUPS_HAS_VISIBILITY
 #    endif /* __GNUC__ >= 3 */
 #    if __GNUC__ >= 5                  /* GCC 5.x */
 #  endif /* _CUPS_HAS_FORMAT */
 
 
+/*
+ * Define _CUPS_NORETURN macro for functions that don't return.
+ */
+
+#  ifdef _CUPS_HAS_NORETURN
+#    define _CUPS_NORETURN     __attribute__ ((noreturn))
+#  else
+#    define _CUPS_NORETURN
+#  endif /* _CUPS_HAS_NORETURN */
+
+
 #endif /* !_CUPS_VERSIONING_H_ */
index 906a6e78c2b3bc4380717493ee1bd9b1ac097811..d251abb0e78f74820049ef3d9698b96d8f8c1024 100644 (file)
@@ -157,8 +157,7 @@ static ssize_t              copy_trailer(cups_file_t *fp, pstops_doc_t *doc,
                                     ssize_t linelen, size_t linesize);
 static void            do_prolog(pstops_doc_t *doc, ppd_file_t *ppd);
 static void            do_setup(pstops_doc_t *doc, ppd_file_t *ppd);
-static void            doc_printf(pstops_doc_t *doc, const char *format, ...)
-                       __attribute__ ((__format__ (__printf__, 2, 3)));
+static void            doc_printf(pstops_doc_t *doc, const char *format, ...) _CUPS_FORMAT(2, 3);
 static void            doc_puts(pstops_doc_t *doc, const char *s);
 static void            doc_write(pstops_doc_t *doc, const char *s, size_t len);
 static void            end_nup(pstops_doc_t *doc, int number);
index abda0d5973ede28509142ed8a1eaa8653971f4fd..674de0a3a7e4f35e3866e79f7e074cac1b1f4b9a 100644 (file)
@@ -33,7 +33,7 @@
  * Local functions...
  */
 
-static void    usage(void) __attribute__((noreturn));
+static void    usage(void) _CUPS_NORETURN;
 
 
 /*
index 811d3fc137bd7f7167c0b7b62113776e86df5084..fa914d215adf10a03ab40a1ae06db2aeed18df86 100644 (file)
@@ -78,7 +78,7 @@ static int            open_pipe(int *fds);
 static int             read_cups_files_conf(const char *filename);
 static void            set_string(char **s, const char *val);
 static void            sighandler(int sig);
-static void            usage(const char *opt) __attribute__((noreturn));
+static void            usage(const char *opt) _CUPS_NORETURN;
 
 
 /*
index 89058d2851066e56a3f37328b2ce689968ac3804..979b31a8b74286dac8631c8fe519742b432828d7 100644 (file)
@@ -115,9 +115,7 @@ static void save_auth_info(cupsd_client_t *con, cupsd_job_t *job,
 static void    send_document(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    send_http_error(cupsd_client_t *con, http_status_t status,
                                cupsd_printer_t *printer);
-static void    send_ipp_status(cupsd_client_t *con, ipp_status_t status,
-                               const char *message, ...)
-               __attribute__((__format__(__printf__, 3, 4)));
+static void    send_ipp_status(cupsd_client_t *con, ipp_status_t status, const char *message, ...) _CUPS_FORMAT(3, 4);
 static void    set_default(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    set_job_attrs(cupsd_client_t *con, ipp_attribute_t *uri);
 static void    set_printer_attrs(cupsd_client_t *con, ipp_attribute_t *uri);
index d022aa2040f02d7e92d9ead07d2c6e852e752e5b..a992b540d12dbe70c8ef44cece43dbd5772de88d 100644 (file)
@@ -66,7 +66,7 @@ static void           sigterm_handler(int sig);
 static long            select_timeout(int fds);
 static void            service_checkin(void);
 static void            service_checkout(int shutdown);
-static void            usage(int status) __attribute__((noreturn));
+static void            usage(int status) _CUPS_NORETURN;
 
 
 /*
index 58447a0a33423797d48f441a834543841d54406f..d974c5269be81fb2260b4000ef2211a71f18644e 100644 (file)
  */
 
 static int     do_command(int outfd, int infd, const char *command);
-static int     print_job(int outfd, int infd, char *dest, char **args) __attribute__((nonnull(4)));
+static int     print_job(int outfd, int infd, char *dest, char **args) _CUPS_NONNULL(4);
 static int     print_waiting(int outfd, int infd, char *dest);
-static int     remove_job(int outfd, int infd, char *dest, char **args) __attribute__((nonnull(4)));
-static int     status_long(int outfd, int infd, char *dest, char **args) __attribute__((nonnull(4)));
-static int     status_short(int outfd, int infd, char *dest, char **args) __attribute__((nonnull(4)));
-static void    usage(void) __attribute__((noreturn));
+static int     remove_job(int outfd, int infd, char *dest, char **args) _CUPS_NONNULL(4);
+static int     status_long(int outfd, int infd, char *dest, char **args) _CUPS_NONNULL(4);
+static int     status_short(int outfd, int infd, char *dest, char **args) _CUPS_NONNULL(4);
+static void    usage(void) _CUPS_NORETURN;
 
 
 /*
index 0aa36e9d9d4b023e5debb39800ccc63457bccb9d..7cd875c972577f7ca3dca94f499ddcd36577eee8 100644 (file)
@@ -27,7 +27,7 @@
 static int     do_test(const char *server, int port,
                        http_encryption_t encryption, int requests,
                        const char *opstring, int verbose);
-static void    usage(void) __attribute__((noreturn));
+static void    usage(void) _CUPS_NORETURN;
 
 
 /*
index 08f0f7465a7b8f068251973bdfbc93b7ba7aadea..19d9dffce9aba804d810e9846f0ab558701a0992 100644 (file)
@@ -31,7 +31,7 @@ static int    terminate = 0;
 
 static void    print_attributes(ipp_t *ipp, int indent);
 static void    sigterm_handler(int sig);
-static void    usage(void) __attribute__((noreturn));
+static void    usage(void) _CUPS_NORETURN;
 
 
 /*
index b995c03862be79617034f87b7a25d71954fec98e..d1f9ac287adf375ae48c35caf727776e5b884308 100644 (file)
@@ -33,7 +33,7 @@ const char    *SAMBAUser,
  */
 
 int    export_dest(http_t *http, const char *dest);
-void   usage(void) __attribute__((noreturn));
+void   usage(void) _CUPS_NORETURN;
 
 
 /*
index eedd01344e5e7815ba5ec1489b00b0e6e2612193..053029b2392e8a95b691379b9052a926b9c2c4ad 100644 (file)
@@ -19,7 +19,7 @@
  * Local functions...
  */
 
-static void    usage(const char *opt) __attribute__((noreturn));
+static void    usage(const char *opt) _CUPS_NORETURN;
 
 
 /*
index be332a4114a2d7ae07edf0e99ec0889fe8a5305b..085037511d9dc16ff0c50ea8d9049cd50a6ef3cd 100644 (file)
@@ -21,7 +21,7 @@
  */
 
 static int     check_file(const char *filename);
-static void    usage(void) __attribute__((noreturn));
+static void    usage(void) _CUPS_NORETURN;
 
 
 /*
index 75c30328198d2c7cc113d1a04e6487d7598dcf08..1880a2dfab318a4dab9d3f0c194cdf84f341b1ba 100644 (file)
@@ -101,7 +101,7 @@ static int  check_translations(ppd_file_t *ppd, int errors, int verbose,
                                   int warn);
 static void    show_conflicts(ppd_file_t *ppd, const char *prefix);
 static int     test_raster(ppd_file_t *ppd, int verbose);
-static void    usage(void) __attribute__((noreturn));
+static void    usage(void) _CUPS_NORETURN;
 static int     valid_path(const char *keyword, const char *path, int errors,
                           int verbose, int warn);
 static int     valid_utf8(const char *s);
index ca148cd63f24fc7d5384db53c5c7e65c53f5819a..f80319a196935562ce5d35214d93a6fc82ef9e93 100644 (file)
@@ -21,7 +21,7 @@
 
 static void    list_group(ppd_file_t *ppd, ppd_group_t *group);
 static void    list_options(cups_dest_t *dest);
-static void    usage(void) __attribute__((noreturn));
+static void    usage(void) _CUPS_NORETURN;
 
 
 /*
index 79c0a065560b20bc9b4610a80d44fba5a30e32ac..2993ea7f8d0a73f0d5ea0f103da984081134911b 100644 (file)
@@ -144,23 +144,8 @@ static int ipp_version = 20;       /* IPP version for LIST */
  */
 
 #ifdef HAVE_DNSSD
-static void DNSSD_API  browse_callback(DNSServiceRef sdRef,
-                                       DNSServiceFlags flags,
-                                       uint32_t interfaceIndex,
-                                       DNSServiceErrorType errorCode,
-                                       const char *serviceName,
-                                       const char *regtype,
-                                       const char *replyDomain, void *context)
-                                       __attribute__((nonnull(1,5,6,7,8)));
-static void DNSSD_API  browse_local_callback(DNSServiceRef sdRef,
-                                             DNSServiceFlags flags,
-                                             uint32_t interfaceIndex,
-                                             DNSServiceErrorType errorCode,
-                                             const char *serviceName,
-                                             const char *regtype,
-                                             const char *replyDomain,
-                                             void *context)
-                                             __attribute__((nonnull(1,5,6,7,8)));
+static void DNSSD_API  browse_callback(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *serviceName, const char *regtype, const char *replyDomain, void *context) _CUPS_NONNULL(1,5,6,7,8);
+static void DNSSD_API  browse_local_callback(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *serviceName, const char *regtype, const char *replyDomain, void *context) _CUPS_NONNULL(1,5,6,7,8);
 #elif defined(HAVE_AVAHI)
 static void            browse_callback(AvahiServiceBrowser *browser,
                                        AvahiIfIndex interface,
@@ -182,27 +167,14 @@ static int                eval_expr(ippfind_srv_t *service,
                                  ippfind_expr_t *expressions);
 static int             exec_program(ippfind_srv_t *service, int num_args,
                                     char **args);
-static ippfind_srv_t   *get_service(cups_array_t *services,
-                                    const char *serviceName,
-                                    const char *regtype,
-                                    const char *replyDomain)
-                                    __attribute__((nonnull(1,2,3,4)));
+static ippfind_srv_t   *get_service(cups_array_t *services, const char *serviceName, const char *regtype, const char *replyDomain) _CUPS_NONNULL(1,2,3,4);
 static double          get_time(void);
 static int             list_service(ippfind_srv_t *service);
 static ippfind_expr_t  *new_expr(ippfind_op_t op, int invert,
                                  const char *value, const char *regex,
                                  char **args);
 #ifdef HAVE_DNSSD
-static void DNSSD_API  resolve_callback(DNSServiceRef sdRef,
-                                        DNSServiceFlags flags,
-                                        uint32_t interfaceIndex,
-                                        DNSServiceErrorType errorCode,
-                                        const char *fullName,
-                                        const char *hostTarget, uint16_t port,
-                                        uint16_t txtLen,
-                                        const unsigned char *txtRecord,
-                                        void *context)
-                                        __attribute__((nonnull(1,5,6,9, 10)));
+static void DNSSD_API  resolve_callback(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *fullName, const char *hostTarget, uint16_t port, uint16_t txtLen, const unsigned char *txtRecord, void *context) _CUPS_NONNULL(1,5,6,9, 10);
 #elif defined(HAVE_AVAHI)
 static int             poll_callback(struct pollfd *pollfds,
                                      unsigned int num_pollfds, int timeout,
@@ -222,8 +194,8 @@ static void         resolve_callback(AvahiServiceResolver *res,
                                         void *context);
 #endif /* HAVE_DNSSD */
 static void            set_service_uri(ippfind_srv_t *service);
-static void            show_usage(void) __attribute__((noreturn));
-static void            show_version(void) __attribute__((noreturn));
+static void            show_usage(void) _CUPS_NORETURN;
+static void            show_version(void) _CUPS_NORETURN;
 
 
 /*
index e2bdbb2c0f1d090ba883eb5df4008ef1bf8c27db..8769094e8f206179db7821d069e76a2e18c67e81 100644 (file)
@@ -405,8 +405,7 @@ static void         html_escape(_ipp_client_t *client, const char *s,
 static void            html_footer(_ipp_client_t *client);
 static void            html_header(_ipp_client_t *client, const char *title);
 static void            html_printf(_ipp_client_t *client, const char *format,
-                                   ...) __attribute__((__format__(__printf__,
-                                                                  2, 3)));
+                                   ...) _CUPS_FORMAT(2, 3);
 static void            ipp_cancel_job(_ipp_client_t *client);
 static void            ipp_close_job(_ipp_client_t *client);
 static void            ipp_create_job(_ipp_client_t *client);
@@ -432,13 +431,12 @@ static int                respond_http(_ipp_client_t *client, http_status_t code,
                                     const char *content_coding,
                                     const char *type, size_t length);
 static void            respond_ipp(_ipp_client_t *client, ipp_status_t status,
-                                   const char *message, ...)
-                       __attribute__ ((__format__ (__printf__, 3, 4)));
+                                   const char *message, ...) _CUPS_FORMAT(3, 4);
 static void            respond_unsupported(_ipp_client_t *client,
                                            ipp_attribute_t *attr);
 static void            run_printer(_ipp_printer_t *printer);
 static char            *time_string(time_t tv, char *buffer, size_t bufsize);
-static void            usage(int status) __attribute__((noreturn));
+static void            usage(int status) _CUPS_NORETURN;
 static int             valid_doc_attributes(_ipp_client_t *client);
 static int             valid_job_attributes(_ipp_client_t *client);
 
index 697ea8a9623e0c2f4411e8694173d248a7d4dad4..39ccb286b241f94d4df0d14e703cdcd75527e49a 100644 (file)
@@ -165,8 +165,9 @@ static int  Cancel = 0;             /* Cancel test? */
  * Local functions...
  */
 
-static void    add_stringf(cups_array_t *a, const char *s, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
+static void    add_stringf(cups_array_t *a, const char *s, ...) _CUPS_FORMAT(2, 3);
 static int      compare_uris(const char *a, const char *b);
+static void    copy_hex_string(char *buffer, unsigned char *data, int datalen, size_t bufsize);
 static int     do_test(_ipp_file_t *f, _ipp_vars_t *vars, _cups_testdata_t *data);
 static int     do_tests(const char *testfile, _ipp_vars_t *vars, _cups_testdata_t *data);
 static int     error_cb(_ipp_file_t *f, _cups_testdata_t *data, const char *error);
@@ -178,7 +179,7 @@ static char *iso_date(const ipp_uchar_t *date);
 static void    pause_message(const char *message);
 static void    print_attr(cups_file_t *outfile, int output, ipp_attribute_t *attr, ipp_tag_t *group);
 static void    print_csv(_cups_testdata_t *data, ipp_t *ipp, ipp_attribute_t *attr, int num_displayed, char **displayed, size_t *widths);
-static void    print_fatal_error(_cups_testdata_t *data, const char *s, ...) __attribute__ ((__format__ (__printf__, 2, 3)));
+static void    print_fatal_error(_cups_testdata_t *data, const char *s, ...) _CUPS_FORMAT(2, 3);
 static void    print_ippserver_attr(_cups_testdata_t *data, ipp_attribute_t *attr, int indent);
 static void    print_ippserver_string(_cups_testdata_t *data, const char *s, size_t len);
 static void    print_line(_cups_testdata_t *data, ipp_t *ipp, ipp_attribute_t *attr, int num_displayed, char **displayed, size_t *widths);
@@ -190,7 +191,7 @@ static void sigterm_handler(int sig);
 #endif /* WIN32 */
 static int     timeout_cb(http_t *http, void *user_data);
 static int     token_cb(_ipp_file_t *f, _ipp_vars_t *vars, _cups_testdata_t *data, const char *token);
-static void    usage(void) __attribute__((noreturn));
+static void    usage(void) _CUPS_NORETURN;
 static const char *with_flags_string(int flags);
 static int      with_value(_cups_testdata_t *data, cups_array_t *errors, char *value, int flags, ipp_attribute_t *attr, char *matchbuf, size_t matchlen);
 static int      with_value_from(cups_array_t *errors, ipp_attribute_t *fromattr, ipp_attribute_t *attr, char *matchbuf, size_t matchlen);
@@ -816,6 +817,69 @@ compare_uris(const char *a,             /* I - First URI */
 }
 
 
+/*
+ * 'copy_hex_string()' - Copy an octetString to a C string and encode as hex if
+ *                       needed.
+ */
+
+static void
+copy_hex_string(char          *buffer, /* I - String buffer */
+               unsigned char *data,    /* I - octetString data */
+               int           datalen,  /* I - octetString length */
+               size_t        bufsize)  /* I - Size of string buffer */
+{
+  char         *bufptr,                /* Pointer into string buffer */
+               *bufend = buffer + bufsize - 2;
+                                       /* End of string buffer */
+  unsigned char        *dataptr,               /* Pointer into octetString data */
+               *dataend = data + datalen;
+                                       /* End of octetString data */
+  static const char *hexdigits = "0123456789ABCDEF";
+                                       /* Hex digits */
+
+
+ /*
+  * First see if there are any non-ASCII bytes in the octetString...
+  */
+
+  for (dataptr = data; dataptr < dataend; dataptr ++)
+    if (*dataptr < 0x20 || *dataptr >= 0x7f)
+      break;
+
+  if (*dataptr)
+  {
+   /*
+    * Yes, encode as hex...
+    */
+
+    *buffer = '<';
+
+    for (bufptr = buffer + 1, dataptr = data; bufptr < bufend && dataptr < dataend; dataptr ++)
+    {
+      *bufptr++ = hexdigits[*dataptr >> 4];
+      *bufptr++ = hexdigits[*dataptr & 15];
+    }
+
+    if (bufptr < bufend)
+      *bufptr++ = '>';
+
+    *bufptr = '\0';
+  }
+  else
+  {
+   /*
+    * No, copy as a string...
+    */
+
+    if ((size_t)datalen > bufsize)
+      datalen = (int)bufsize - 1;
+
+    memcpy(buffer, data, datalen);
+    buffer[datalen] = '\0';
+  }
+}
+
+
 /*
  * 'do_test()' - Do a single test from the test file.
  */
@@ -1351,7 +1415,12 @@ do_test(_ipp_file_t      *f,             /* I - IPP data file */
            _ippVarsGet(vars, expect->if_not_defined))
          continue;
 
-       found = ippFindAttribute(response, expect->name, IPP_TAG_ZERO);
+       if ((found = ippFindAttribute(response, expect->name, IPP_TAG_ZERO)) != NULL && expect->in_group && expect->in_group != ippGetGroupTag(found))
+       {
+         while ((found = ippFindNextAttribute(response, expect->name, IPP_TAG_ZERO)) != NULL)
+           if (expect->in_group == ippGetGroupTag(found))
+             break;
+       }
 
        do
        {
@@ -4701,6 +4770,99 @@ with_value(_cups_testdata_t *data,       /* I - Test data */
         }
        break;
 
+    case IPP_TAG_STRING :
+        {
+          unsigned char        withdata[1023], /* WITH-VALUE data */
+                       *adata;         /* Pointer to octetString data */
+         int           withlen,        /* Length of WITH-VALUE data */
+                       adatalen;       /* Length of octetString */
+
+          if (*value == '<')
+          {
+           /*
+            * Grab hex-encoded value...
+            */
+
+            if ((withlen = (int)strlen(value)) & 1 || withlen > (2 * (sizeof(withdata) + 1)))
+            {
+             print_fatal_error(data, "Bad WITH-VALUE hex value.");
+              return (0);
+           }
+
+           withlen = withlen / 2 - 1;
+
+            for (valptr = value + 1, adata = withdata; *valptr; valptr += 2)
+            {
+              int ch;                  /* Current character/byte */
+
+             if (isdigit(valptr[0]))
+               ch = (valptr[0] - '0') << 4;
+             else if (isalpha(valptr[0]))
+               ch = (tolower(valptr[0]) - 'a' + 10) << 4;
+             else
+               break;
+
+             if (isdigit(valptr[1]))
+               ch |= valptr[1] - '0';
+             else if (isalpha(valptr[1]))
+               ch |= tolower(valptr[1]) - 'a' + 10;
+             else
+               break;
+
+             *adata++ = (unsigned char)ch;
+           }
+
+           if (*valptr)
+           {
+             print_fatal_error(data, "Bad WITH-VALUE hex value.");
+              return (0);
+           }
+          }
+          else
+          {
+           /*
+            * Copy literal string value...
+            */
+
+            withlen = (int)strlen(value);
+
+            memcpy(withdata, value, withlen);
+         }
+
+         for (i = 0; i < count; i ++)
+         {
+           adata = ippGetOctetString(attr, i, &adatalen);
+
+           if (withlen == adatalen && !memcmp(withdata, adata, (size_t)withlen))
+           {
+             if (!matchbuf[0])
+               copy_hex_string(matchbuf, adata, adatalen, matchlen);
+
+             if (!(flags & _CUPS_WITH_ALL))
+             {
+               match = 1;
+               break;
+             }
+           }
+           else if (flags & _CUPS_WITH_ALL)
+           {
+             match = 0;
+             break;
+           }
+         }
+
+         if (!match && errors)
+         {
+           for (i = 0; i < count; i ++)
+           {
+             adata = ippGetOctetString(attr, i, &adatalen);
+             copy_hex_string(temp, adata, adatalen, sizeof(temp));
+             add_stringf(data->errors, "GOT: %s=\"%s\"", name, temp);
+           }
+         }
+        }
+        break;
+
     default :
         break;
   }