set_default(cupsd_client_t  *con,	/* I - Client connection */
            ipp_attribute_t *uri)	/* I - Printer URI */
{
  http_status_t		status;		/* Policy status */
  cups_ptype_t		dtype;		/* Destination type (printer/class) */
  cupsd_printer_t	*printer,	/* Printer */
			*oldprinter;	/* Old default printer */


  cupsdLogMessage(CUPSD_LOG_DEBUG2, "set_default(%p[%d], %s)", con,
                  con->number, uri->values[0].string.text);

 /*
  * Is the destination valid?
  */

  if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
  {
   /*
    * Bad URI...
    */

    send_ipp_status(con, IPP_NOT_FOUND,
                    _("The printer or class does not exist."));
    return;
  }

 /*
  * Check policy...
  */

  if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
  {
    send_http_error(con, status, NULL);
    return;
  }

 /*
  * Set it as the default...
  */

  oldprinter     = DefaultPrinter;
  DefaultPrinter = printer;

  if (oldprinter)
    cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE, oldprinter, NULL,
                  "%s is no longer the default printer.", oldprinter->name);

  cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE, printer, NULL,
		"%s is now the default printer.", printer->name);

  cupsdMarkDirty(CUPSD_DIRTY_PRINTERS | CUPSD_DIRTY_CLASSES |
                 CUPSD_DIRTY_PRINTCAP);

  cupsdLogMessage(CUPSD_LOG_INFO,
                  "Default destination set to \"%s\" by \"%s\".",
		  printer->name, get_username(con));

 /*
  * Everything was ok, so return OK status...
  */

  con->response->request.status.status_code = IPP_OK;
}
set_default(cupsd_client_t  *con,	 
            ipp_attribute_t *uri)	 
{
  http_status_t		status;		 
  cups_ptype_t		dtype;		 
  cupsd_printer_t	*printer,	 
			*oldprinter;	 


  cupsdLogMessage(CUPSD_LOG_DEBUG2, "set_default(%p[%d], %s)", con,
                  con->number, uri->values[0].string.text);

  

  if (!cupsdValidateDest(uri->values[0].string.text, &dtype, &printer))
  {
    

    send_ipp_status(con, IPP_NOT_FOUND,
                    _("The printer or class does not exist."));
    return;
  }

  

  if ((status = cupsdCheckPolicy(DefaultPolicyPtr, con, NULL)) != HTTP_OK)
  {
    send_http_error(con, status, NULL);
    return;
  }

  

  oldprinter     = DefaultPrinter;
  DefaultPrinter = printer;

  if (oldprinter)
    cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE, oldprinter, NULL,
                  "%s is no longer the default printer.", oldprinter->name);

  cupsdAddEvent(CUPSD_EVENT_PRINTER_STATE, printer, NULL,
		"%s is now the default printer.", printer->name);

  cupsdMarkDirty(CUPSD_DIRTY_PRINTERS | CUPSD_DIRTY_CLASSES |
                 CUPSD_DIRTY_PRINTCAP);

  cupsdLogMessage(CUPSD_LOG_INFO,
                  "Default destination set to \"%s\" by \"%s\".",
		  printer->name, get_username(con));

  

  con->response->request.status.status_code = IPP_OK;
}