copy_subscription_attrs(
    cupsd_client_t       *con,		/* I - Client connection */
    cupsd_subscription_t *sub,		/* I - Subscription */
    cups_array_t         *ra,		/* I - Requested attributes array */
    cups_array_t         *exclude)	/* I - Private attributes array */
{
  ipp_attribute_t	*attr;		/* Current attribute */
  char			printer_uri[HTTP_MAX_URI];
					/* Printer URI */
  int			count;		/* Number of events */
  unsigned		mask;		/* Current event mask */
  const char		*name;		/* Current event name */


  cupsdLogMessage(CUPSD_LOG_DEBUG2,
                  "copy_subscription_attrs(con=%p, sub=%p, ra=%p, exclude=%p)",
		  con, sub, ra, exclude);

 /*
  * Copy the subscription attributes to the response using the
  * requested-attributes attribute that may be provided by the client.
  */

  if (!exclude || !cupsArrayFind(exclude, "all"))
  {
    if ((!exclude || !cupsArrayFind(exclude, "notify-events")) &&
        (!ra || cupsArrayFind(ra, "notify-events")))
    {
      cupsdLogMessage(CUPSD_LOG_DEBUG2, "copy_subscription_attrs: notify-events");

      if ((name = cupsdEventName((cupsd_eventmask_t)sub->mask)) != NULL)
      {
       /*
	* Simple event list...
	*/

	ippAddString(con->response, IPP_TAG_SUBSCRIPTION,
		     (ipp_tag_t)(IPP_TAG_KEYWORD | IPP_TAG_COPY),
		     "notify-events", NULL, name);
      }
      else
      {
       /*
	* Complex event list...
	*/

	for (mask = 1, count = 0; mask < CUPSD_EVENT_ALL; mask <<= 1)
	  if (sub->mask & mask)
	    count ++;

	attr = ippAddStrings(con->response, IPP_TAG_SUBSCRIPTION,
			     (ipp_tag_t)(IPP_TAG_KEYWORD | IPP_TAG_COPY),
			     "notify-events", count, NULL, NULL);

	for (mask = 1, count = 0; mask < CUPSD_EVENT_ALL; mask <<= 1)
	  if (sub->mask & mask)
	  {
	    attr->values[count].string.text =
		(char *)cupsdEventName((cupsd_eventmask_t)mask);

	    count ++;
	  }
      }
    }

    if ((!exclude || !cupsArrayFind(exclude, "notify-lease-duration")) &&
        (!sub->job && (!ra || cupsArrayFind(ra, "notify-lease-duration"))))
      ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
		    "notify-lease-duration", sub->lease);

    if ((!exclude || !cupsArrayFind(exclude, "notify-recipient-uri")) &&
        (sub->recipient && (!ra || cupsArrayFind(ra, "notify-recipient-uri"))))
      ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
		   "notify-recipient-uri", NULL, sub->recipient);
    else if ((!exclude || !cupsArrayFind(exclude, "notify-pull-method")) &&
             (!ra || cupsArrayFind(ra, "notify-pull-method")))
      ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_KEYWORD,
		   "notify-pull-method", NULL, "ippget");

    if ((!exclude || !cupsArrayFind(exclude, "notify-subscriber-user-name")) &&
        (!ra || cupsArrayFind(ra, "notify-subscriber-user-name")))
      ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_NAME,
		   "notify-subscriber-user-name", NULL, sub->owner);

    if ((!exclude || !cupsArrayFind(exclude, "notify-time-interval")) &&
        (!ra || cupsArrayFind(ra, "notify-time-interval")))
      ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
		    "notify-time-interval", sub->interval);

    if (sub->user_data_len > 0 &&
	(!exclude || !cupsArrayFind(exclude, "notify-user-data")) &&
        (!ra || cupsArrayFind(ra, "notify-user-data")))
      ippAddOctetString(con->response, IPP_TAG_SUBSCRIPTION, "notify-user-data",
			sub->user_data, sub->user_data_len);
  }

  if (sub->job && (!ra || cupsArrayFind(ra, "notify-job-id")))
    ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
                  "notify-job-id", sub->job->id);

  if (sub->dest && (!ra || cupsArrayFind(ra, "notify-printer-uri")))
  {
    httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri),
                     "ipp", NULL, con->clientname, con->clientport,
		     "/printers/%s", sub->dest->name);
    ippAddString(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_URI,
        	 "notify-printer-uri", NULL, printer_uri);
  }

  if (!ra || cupsArrayFind(ra, "notify-subscription-id"))
    ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
                  "notify-subscription-id", sub->id);
}