1 /*
2  * Notification functions
3  *
4  * Copyright (C) 2008-2021, Joachim Metz <joachim.metz@gmail.com>
5  *
6  * Refer to AUTHORS for acknowledgements.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #include <common.h>
23 #include <file_stream.h>
24 #include <types.h>
25 
26 #if defined( HAVE_STDLIB_H ) || defined( WINAPI )
27 #include <stdlib.h>
28 #endif
29 
30 #include "libolecf_libcerror.h"
31 #include "libolecf_libcnotify.h"
32 #include "libolecf_notify.h"
33 
34 #if !defined( HAVE_LOCAL_LIBOLECF )
35 
36 /* Sets the verbose notification
37  */
libolecf_notify_set_verbose(int verbose)38 void libolecf_notify_set_verbose(
39       int verbose )
40 {
41 	libcnotify_verbose_set(
42 	 verbose );
43 }
44 
45 /* Sets the notification stream
46  * Returns 1 if successful or -1 on error
47  */
libolecf_notify_set_stream(FILE * stream,libcerror_error_t ** error)48 int libolecf_notify_set_stream(
49      FILE *stream,
50      libcerror_error_t **error )
51 {
52 	static char *function = "libolecf_notify_set_stream";
53 
54 	if( libcnotify_stream_set(
55 	     stream,
56 	     error ) != 1 )
57 	{
58 		libcerror_error_set(
59 		 error,
60 		 LIBCERROR_ERROR_DOMAIN_RUNTIME,
61 		 LIBCERROR_RUNTIME_ERROR_SET_FAILED,
62 		 "%s: unable to set stream.",
63 		 function );
64 
65 		return( -1 );
66 	}
67 	return( 1 );
68 }
69 
70 /* Opens the notification stream using a filename
71  * The stream is opened in append mode
72  * Returns 1 if successful or -1 on error
73  */
libolecf_notify_stream_open(const char * filename,libcerror_error_t ** error)74 int libolecf_notify_stream_open(
75      const char *filename,
76      libcerror_error_t **error )
77 {
78 	static char *function = "libolecf_notify_stream_open";
79 
80 	if( libcnotify_stream_open(
81 	     filename,
82 	     error ) != 1 )
83 	{
84 		libcerror_error_set(
85 		 error,
86 		 LIBCERROR_ERROR_DOMAIN_IO,
87 		 LIBCERROR_IO_ERROR_OPEN_FAILED,
88 		 "%s: unable to open stream.",
89 		 function );
90 
91 		return( -1 );
92 	}
93 	return( 1 );
94 }
95 
96 /* Closes the notification stream if opened using a filename
97  * Returns 0 if successful or -1 on error
98  */
libolecf_notify_stream_close(libcerror_error_t ** error)99 int libolecf_notify_stream_close(
100      libcerror_error_t **error )
101 {
102 	static char *function = "libolecf_notify_stream_close";
103 
104 	if( libcnotify_stream_close(
105 	     error ) != 0 )
106 	{
107 		libcerror_error_set(
108 		 error,
109 		 LIBCERROR_ERROR_DOMAIN_IO,
110 		 LIBCERROR_IO_ERROR_OPEN_FAILED,
111 		 "%s: unable to open stream.",
112 		 function );
113 
114 		return( -1 );
115 	}
116 	return( 0 );
117 }
118 
119 #endif /* !defined( HAVE_LOCAL_LIBOLECF ) */
120 
121