mirror of
https://github.com/samba-team/samba.git
synced 2025-01-25 06:04:04 +03:00
s3-printing: Use printer list tdb in pcap.
Signed-off-by: Andreas Schneider <asn@cynapses.org>
This commit is contained in:
parent
d2a027ea94
commit
7022554915
@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
#include "includes.h"
|
#include "includes.h"
|
||||||
#include "printing/pcap.h"
|
#include "printing/pcap.h"
|
||||||
|
#include "printer_list.h"
|
||||||
|
|
||||||
struct pcap_cache {
|
struct pcap_cache {
|
||||||
char *name;
|
char *name;
|
||||||
@ -45,9 +46,6 @@ struct pcap_cache {
|
|||||||
struct pcap_cache *next;
|
struct pcap_cache *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* The systemwide printcap cache. */
|
|
||||||
static struct pcap_cache *pcap_cache = NULL;
|
|
||||||
|
|
||||||
bool pcap_cache_add_specific(struct pcap_cache **ppcache, const char *name, const char *comment)
|
bool pcap_cache_add_specific(struct pcap_cache **ppcache, const char *name, const char *comment)
|
||||||
{
|
{
|
||||||
struct pcap_cache *p;
|
struct pcap_cache *p;
|
||||||
@ -83,19 +81,26 @@ void pcap_cache_destroy_specific(struct pcap_cache **pp_cache)
|
|||||||
|
|
||||||
bool pcap_cache_add(const char *name, const char *comment)
|
bool pcap_cache_add(const char *name, const char *comment)
|
||||||
{
|
{
|
||||||
return pcap_cache_add_specific(&pcap_cache, name, comment);
|
NTSTATUS status;
|
||||||
|
time_t t = time(NULL);
|
||||||
|
|
||||||
|
status = printer_list_set_printer(talloc_tos(), name, comment, t);
|
||||||
|
return NT_STATUS_IS_OK(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pcap_cache_loaded(void)
|
bool pcap_cache_loaded(void)
|
||||||
{
|
{
|
||||||
return (pcap_cache != NULL);
|
NTSTATUS status;
|
||||||
|
time_t last;
|
||||||
|
|
||||||
|
status = printer_list_get_last_refresh(&last);
|
||||||
|
return NT_STATUS_IS_OK(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pcap_cache_replace(const struct pcap_cache *pcache)
|
void pcap_cache_replace(const struct pcap_cache *pcache)
|
||||||
{
|
{
|
||||||
const struct pcap_cache *p;
|
const struct pcap_cache *p;
|
||||||
|
|
||||||
pcap_cache_destroy_specific(&pcap_cache);
|
|
||||||
for (p = pcache; p; p = p->next) {
|
for (p = pcache; p; p = p->next) {
|
||||||
pcap_cache_add(p->name, p->comment);
|
pcap_cache_add(p->name, p->comment);
|
||||||
}
|
}
|
||||||
@ -106,7 +111,7 @@ void pcap_cache_reload(struct tevent_context *ev,
|
|||||||
{
|
{
|
||||||
const char *pcap_name = lp_printcapname();
|
const char *pcap_name = lp_printcapname();
|
||||||
bool pcap_reloaded = False;
|
bool pcap_reloaded = False;
|
||||||
struct pcap_cache *tmp_cache = NULL;
|
NTSTATUS status;
|
||||||
|
|
||||||
DEBUG(3, ("reloading printcap cache\n"));
|
DEBUG(3, ("reloading printcap cache\n"));
|
||||||
|
|
||||||
@ -116,8 +121,11 @@ void pcap_cache_reload(struct tevent_context *ev,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp_cache = pcap_cache;
|
status = printer_list_mark_reload();
|
||||||
pcap_cache = NULL;
|
if (!NT_STATUS_IS_OK(status)) {
|
||||||
|
DEBUG(0, ("Failed to mark printer list for reload!\n"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_CUPS
|
#ifdef HAVE_CUPS
|
||||||
if (strequal(pcap_name, "cups")) {
|
if (strequal(pcap_name, "cups")) {
|
||||||
@ -152,11 +160,14 @@ void pcap_cache_reload(struct tevent_context *ev,
|
|||||||
done:
|
done:
|
||||||
DEBUG(3, ("reload status: %s\n", (pcap_reloaded) ? "ok" : "error"));
|
DEBUG(3, ("reload status: %s\n", (pcap_reloaded) ? "ok" : "error"));
|
||||||
|
|
||||||
if (pcap_reloaded)
|
if (pcap_reloaded) {
|
||||||
pcap_cache_destroy_specific(&tmp_cache);
|
/* cleanup old entries only if the operation was successful,
|
||||||
else {
|
* otherwise keep around the old entries until we can
|
||||||
pcap_cache_destroy_specific(&pcap_cache);
|
* successfuly reaload */
|
||||||
pcap_cache = tmp_cache;
|
status = printer_list_clean_old();
|
||||||
|
if (!NT_STATUS_IS_OK(status)) {
|
||||||
|
DEBUG(0, ("Failed to cleanup printer list!\n"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -165,13 +176,10 @@ done:
|
|||||||
|
|
||||||
bool pcap_printername_ok(const char *printername)
|
bool pcap_printername_ok(const char *printername)
|
||||||
{
|
{
|
||||||
struct pcap_cache *p;
|
NTSTATUS status;
|
||||||
|
|
||||||
for (p = pcap_cache; p != NULL; p = p->next)
|
status = printer_list_get_printer(talloc_tos(), printername, NULL, 0);
|
||||||
if (strequal(p->name, printername))
|
return NT_STATUS_IS_OK(status);
|
||||||
return True;
|
|
||||||
|
|
||||||
return False;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
@ -192,5 +200,11 @@ void pcap_printer_fn_specific(const struct pcap_cache *pc,
|
|||||||
|
|
||||||
void pcap_printer_fn(void (*fn)(const char *, const char *, void *), void *pdata)
|
void pcap_printer_fn(void (*fn)(const char *, const char *, void *), void *pdata)
|
||||||
{
|
{
|
||||||
pcap_printer_fn_specific(pcap_cache, fn, pdata);
|
NTSTATUS status;
|
||||||
|
|
||||||
|
status = printer_list_run_fn(fn, pdata);
|
||||||
|
if (!NT_STATUS_IS_OK(status)) {
|
||||||
|
DEBUG(3, ("Failed to run fn for all printers!\n"));
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user