1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-23 09:57:40 +03:00

printing: std_pcap_cache_reload xfile->stdio

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
Volker Lendecke 2016-11-26 09:27:19 +01:00
parent 2d9409341f
commit a366463ff9

View File

@ -57,31 +57,32 @@
#include "includes.h" #include "includes.h"
#include "system/filesys.h" #include "system/filesys.h"
#include "printing/pcap.h" #include "printing/pcap.h"
#include "lib/util/xfile.h"
/* handle standard printcap - moved from pcap_printer_fn() */ /* handle standard printcap - moved from pcap_printer_fn() */
bool std_pcap_cache_reload(const char *pcap_name, struct pcap_cache **_pcache) bool std_pcap_cache_reload(const char *pcap_name, struct pcap_cache **_pcache)
{ {
TALLOC_CTX *frame = talloc_stackframe(); TALLOC_CTX *frame = talloc_stackframe();
XFILE *pcap_file; FILE *pcap_file;
char *pcap_line; char *pcap_line;
struct pcap_cache *pcache = NULL; struct pcap_cache *pcache = NULL;
bool print_warning = false; bool print_warning = false;
if ((pcap_file = x_fopen(pcap_name, O_RDONLY, 0)) == NULL) { if ((pcap_file = fopen(pcap_name, "r")) == NULL) {
DEBUG(0, ("Unable to open printcap file %s for read!\n", pcap_name)); DEBUG(0, ("Unable to open printcap file %s for read!\n", pcap_name));
talloc_free(frame); talloc_free(frame);
return false; return false;
} }
for (; (pcap_line = x_fgets_slash(NULL, 1024, pcap_file)) != NULL; while ((pcap_line = fgets_slash(frame, NULL, 1024,
free(pcap_line)) { pcap_file)) != NULL) {
char *name = NULL; char *name = NULL;
char *comment = NULL; char *comment = NULL;
char *p, *q; char *p, *q;
if (*pcap_line == '#' || *pcap_line == 0) if (*pcap_line == '#' || *pcap_line == 0) {
TALLOC_FREE(pcap_line);
continue; continue;
}
/* now we have a real printer line - cut at the first : */ /* now we have a real printer line - cut at the first : */
if ((p = strchr_m(pcap_line, ':')) != NULL) if ((p = strchr_m(pcap_line, ':')) != NULL)
@ -108,11 +109,13 @@ bool std_pcap_cache_reload(const char *pcap_name, struct pcap_cache **_pcache)
if (name == NULL && !has_punctuation) { if (name == NULL && !has_punctuation) {
name = talloc_strdup(frame, p); name = talloc_strdup(frame, p);
TALLOC_FREE(pcap_line);
continue; continue;
} }
if (has_punctuation) { if (has_punctuation) {
comment = talloc_strdup(frame, p); comment = talloc_strdup(frame, p);
TALLOC_FREE(pcap_line);
continue; continue;
} }
} }
@ -129,7 +132,7 @@ bool std_pcap_cache_reload(const char *pcap_name, struct pcap_cache **_pcache)
comment, comment,
NULL); NULL);
if (!ok) { if (!ok) {
x_fclose(pcap_file); fclose(pcap_file);
pcap_cache_destroy_specific(&pcache); pcap_cache_destroy_specific(&pcache);
talloc_free(frame); talloc_free(frame);
return false; return false;
@ -137,6 +140,7 @@ bool std_pcap_cache_reload(const char *pcap_name, struct pcap_cache **_pcache)
} }
TALLOC_FREE(name); TALLOC_FREE(name);
TALLOC_FREE(comment); TALLOC_FREE(comment);
TALLOC_FREE(pcap_line);
} }
if (print_warning) { if (print_warning) {
@ -146,7 +150,7 @@ bool std_pcap_cache_reload(const char *pcap_name, struct pcap_cache **_pcache)
(unsigned int)MAXPRINTERLEN); (unsigned int)MAXPRINTERLEN);
} }
x_fclose(pcap_file); fclose(pcap_file);
*_pcache = pcache; *_pcache = pcache;
talloc_free(frame); talloc_free(frame);
return true; return true;