#include <cups/http-private.h>
#include "cupsd.h"
#include <grp.h>
#ifdef HAVE_NOTIFY_H
# include <notify.h>
#endif
static int started = 0;
void
cupsdStartServer(void)
{
DefaultProfile = cupsdCreateProfile(0);
cupsdStartListening();
cupsdStartBrowsing();
cupsdStartPolling();
if (cupsdOpenPipe(CGIPipes))
cupsdLogMessage(CUPSD_LOG_ERROR,
"cupsdStartServer: Unable to create pipes for CGI status!");
else
{
CGIStatusBuffer = cupsdStatBufNew(CGIPipes[0], "[CGI]");
cupsdAddSelect(CGIPipes[0], (cupsd_selfunc_t)cupsdUpdateCGI, NULL, NULL);
}
LastEvent = CUPSD_EVENT_PRINTER_CHANGED | CUPSD_EVENT_JOB_STATE_CHANGED |
CUPSD_EVENT_SERVER_STARTED;
started = 1;
cupsdSetBusyState();
}
void
cupsdStopServer(void)
{
if (!started)
return;
cupsdCloseAllClients();
cupsdStopListening();
cupsdStopPolling();
cupsdStopBrowsing();
cupsdStopAllNotifiers();
cupsdDeleteAllCerts();
if (Clients)
{
cupsArrayDelete(Clients);
Clients = NULL;
}
if (CGIPipes[0] >= 0)
{
cupsdRemoveSelect(CGIPipes[0]);
cupsdStatBufDelete(CGIStatusBuffer);
close(CGIPipes[1]);
CGIPipes[0] = -1;
CGIPipes[1] = -1;
}
#ifdef HAVE_NOTIFY_POST
cupsdLogMessage(CUPSD_LOG_DEBUG2,
"notify_post(\"com.apple.printerListChange\") last");
notify_post("com.apple.printerListChange");
#endif
if (AccessFile != NULL)
{
cupsFileClose(AccessFile);
AccessFile = NULL;
}
if (ErrorFile != NULL)
{
cupsFileClose(ErrorFile);
ErrorFile = NULL;
}
if (PageFile != NULL)
{
cupsFileClose(PageFile);
PageFile = NULL;
}
cupsdDestroyProfile(DefaultProfile);
DefaultProfile = NULL;
if (DirtyFiles)
cupsdCleanDirty();
started = 0;
}