Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /*  | 
2  |  |  * Copyright (c) 2012 Tim Ruehsen  | 
3  |  |  * Copyright (c) 2015-2024 Free Software Foundation, Inc.  | 
4  |  |  *  | 
5  |  |  * This file is part of libwget.  | 
6  |  |  *  | 
7  |  |  * Libwget is free software: you can redistribute it and/or modify  | 
8  |  |  * it under the terms of the GNU Lesser General Public License as published by  | 
9  |  |  * the Free Software Foundation, either version 3 of the License, or  | 
10  |  |  * (at your option) any later version.  | 
11  |  |  *  | 
12  |  |  * Libwget is distributed in the hope that it will be useful,  | 
13  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of  | 
14  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  | 
15  |  |  * GNU Lesser General Public License for more details.  | 
16  |  |  *  | 
17  |  |  * You should have received a copy of the GNU Lesser General Public License  | 
18  |  |  * along with libwget.  If not, see <https://www.gnu.org/licenses/>.  | 
19  |  |  *  | 
20  |  |  *  | 
21  |  |  * Logging routines  | 
22  |  |  *  | 
23  |  |  * Changelog  | 
24  |  |  * 27.04.2012  Tim Ruehsen  created  | 
25  |  |  *  | 
26  |  |  */  | 
27  |  |  | 
28  |  | #include <config.h>  | 
29  |  |  | 
30  |  | #include <stdio.h>  | 
31  |  | #include <stdarg.h>  | 
32  |  | #include <stdlib.h>  | 
33  |  | #include <time.h>  | 
34  |  | #include <errno.h>  | 
35  |  | #include <sys/time.h>  | 
36  |  |  | 
37  |  | #include <wget.h>  | 
38  |  | #include "private.h"  | 
39  |  | #include "logger.h"  | 
40  |  |  | 
41  |  | static wget_logger  | 
42  |  |   info_logger,  | 
43  |  |   error_logger,  | 
44  |  |   debug_logger;  | 
45  |  |  | 
46  |  | void wget_info_vprintf(const char *fmt, va_list args)  | 
47  | 0  | { | 
48  | 0  |   if (info_logger.vprintf)  | 
49  | 0  |     info_logger.vprintf(&info_logger, fmt, args);  | 
50  | 0  | }  | 
51  |  |  | 
52  |  | void wget_info_printf(const char *fmt, ...)  | 
53  | 0  | { | 
54  | 0  |   if (info_logger.vprintf) { | 
55  | 0  |     va_list args;  | 
56  |  | 
  | 
57  | 0  |     va_start(args, fmt);  | 
58  | 0  |     info_logger.vprintf(&info_logger, fmt, args);  | 
59  | 0  |     va_end(args);  | 
60  | 0  |   }  | 
61  | 0  | }  | 
62  |  |  | 
63  |  | void wget_error_vprintf(const char *fmt, va_list args)  | 
64  | 0  | { | 
65  | 0  |   if (error_logger.vprintf)  | 
66  | 0  |     error_logger.vprintf(&error_logger, fmt, args);  | 
67  | 0  | }  | 
68  |  |  | 
69  |  | void wget_error_printf(const char *fmt, ...)  | 
70  | 874  | { | 
71  | 874  |   if (error_logger.vprintf) { | 
72  | 0  |     va_list args;  | 
73  |  | 
  | 
74  | 0  |     va_start(args, fmt);  | 
75  | 0  |     error_logger.vprintf(&error_logger, fmt, args);  | 
76  | 0  |     va_end(args);  | 
77  | 0  |   }  | 
78  | 874  | }  | 
79  |  |  | 
80  |  | void wget_error_printf_exit(const char *fmt, ...)  | 
81  | 0  | { | 
82  | 0  |   if (error_logger.vprintf) { | 
83  | 0  |     va_list args;  | 
84  |  | 
  | 
85  | 0  |     va_start(args, fmt);  | 
86  | 0  |     error_logger.vprintf(&error_logger, fmt, args);  | 
87  | 0  |     va_end(args);  | 
88  | 0  |   }  | 
89  |  | 
  | 
90  | 0  |   exit(EXIT_FAILURE);  | 
91  | 0  | }  | 
92  |  |  | 
93  |  | void wget_debug_vprintf(const char *fmt, va_list args)  | 
94  | 0  | { | 
95  | 0  |   if (debug_logger.vprintf)  | 
96  | 0  |     debug_logger.vprintf(&debug_logger, fmt, args);  | 
97  | 0  | }  | 
98  |  |  | 
99  |  | void wget_debug_printf(const char *fmt, ...)  | 
100  | 19.8k  | { | 
101  | 19.8k  |   if (debug_logger.vprintf) { | 
102  | 0  |     va_list args;  | 
103  |  | 
  | 
104  | 0  |     va_start(args, fmt);  | 
105  | 0  |     debug_logger.vprintf(&debug_logger, fmt, args);  | 
106  | 0  |     va_end(args);  | 
107  | 0  |   }  | 
108  | 19.8k  | }  | 
109  |  |  | 
110  |  | void wget_debug_write(const char *buf, size_t len)  | 
111  | 0  | { | 
112  | 0  |   if (debug_logger.write)  | 
113  | 0  |     debug_logger.write(&debug_logger, buf, len);  | 
114  | 0  | }  | 
115  |  |  | 
116  |  | wget_logger *wget_get_logger(int id)  | 
117  | 7.78k  | { | 
118  | 7.78k  |   if (id == WGET_LOGGER_DEBUG)  | 
119  | 7.78k  |     return &debug_logger;  | 
120  | 0  |   else if (id == WGET_LOGGER_ERROR)  | 
121  | 0  |     return &error_logger;  | 
122  | 0  |   else if (id == WGET_LOGGER_INFO)  | 
123  | 0  |     return &info_logger;  | 
124  | 0  |   else  | 
125  | 0  |     return NULL;  | 
126  | 7.78k  | }  |