syslog-ng source
loggen_helper.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018 Balabit
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * As an additional exemption you are allowed to compile & link against the
19  * OpenSSL libraries as published by the OpenSSL project. See the file
20  * COPYING for details.
21  *
22  */
23 
24 #ifndef LOGGEN_HELPER_H_INCLUDED
25 #define LOGGEN_HELPER_H_INCLUDED
26 
27 #include "compat/compat.h"
28 #include "compat/glib.h"
29 
30 #include <stddef.h>
31 #include <stdio.h>
32 #include <glib.h>
33 #include <sys/un.h>
34 #include <netdb.h>
35 #include <openssl/ssl.h>
36 
37 #include <libgen.h>
38 
39 #define MAX_MESSAGE_LENGTH 8192
40 #define USEC_PER_SEC 1000000
41 #define CONNECTION_TIMEOUT_SEC 5
42 
43 int get_debug_level(void);
44 void set_debug_level(int new_debug);
45 unsigned long time_val_diff_in_usec(struct timeval *t1, struct timeval *t2);
46 double time_val_diff_in_sec(struct timeval *t1, struct timeval *t2);
47 void time_val_diff_in_timeval(struct timeval *res, const struct timeval *t1, const struct timeval *t2);
48 size_t get_now_timestamp(char *stamp, gsize stamp_size);
49 size_t get_now_timestamp_bsd(char *stamp, gsize stamp_size);
50 void format_timezone_offset_with_colon(char *timestamp, int timestamp_size, struct tm *tm);
51 int connect_ip_socket(int sock_type, const char *target, const char *port, int use_ipv6);
52 int connect_unix_domain_socket(int sock_type, const char *path);
53 SSL *open_ssl_connection(int sock_fd);
54 void close_ssl_connection(SSL *ssl);
55 int generate_proxy_header(char *buffer, int buffer_size, int thread_id, int proxy_version, const char *proxy_src_ip,
56  const char *proxy_dst_ip, const char *proxy_src_port, const char *proxy_dst_port);
57 
58 #define ERROR(format,...) do {\
59  gchar *base = g_path_get_basename(__FILE__);\
60  fprintf(stderr, "error [%s:%s:%d] ", base, __func__, __LINE__);\
61  fprintf(stderr, format, ##__VA_ARGS__);\
62  g_free(base);\
63 } while (0)
64 
65 /* debug messages can be turned on by "--debug" command line option */
66 #define DEBUG(format,...) do {\
67  if (!get_debug_level()) \
68  break; \
69  gchar *base = g_path_get_basename(__FILE__);\
70  fprintf(stdout, "debug [%s:%s:%d] ", base, __func__, __LINE__); \
71  fprintf(stdout, format, ##__VA_ARGS__);\
72  g_free(base);\
73 } while(0)
74 
75 #endif
unsigned long time_val_diff_in_usec(struct timeval *t1, struct timeval *t2)
Definition: loggen_helper.c:201
size_t get_now_timestamp_bsd(char *stamp, gsize stamp_size)
Definition: loggen_helper.c:238
int generate_proxy_header(char *buffer, int buffer_size, int thread_id, int proxy_version, const char *proxy_src_ip, const char *proxy_dst_ip, const char *proxy_src_port, const char *proxy_dst_port)
Definition: loggen_helper.c:435
void format_timezone_offset_with_colon(char *timestamp, int timestamp_size, struct tm *tm)
Definition: loggen_helper.c:249
void set_debug_level(int new_debug)
Definition: loggen_helper.c:53
size_t get_now_timestamp(char *stamp, gsize stamp_size)
Definition: loggen_helper.c:227
int get_debug_level(void)
Definition: loggen_helper.c:47
SSL * open_ssl_connection(int sock_fd)
Definition: loggen_helper.c:261
void close_ssl_connection(SSL *ssl)
Definition: loggen_helper.c:292
double time_val_diff_in_sec(struct timeval *t1, struct timeval *t2)
Definition: loggen_helper.c:219
int connect_unix_domain_socket(int sock_type, const char *path)
Definition: loggen_helper.c:170
void time_val_diff_in_timeval(struct timeval *res, const struct timeval *t1, const struct timeval *t2)
Definition: loggen_helper.c:207
int connect_ip_socket(int sock_type, const char *target, const char *port, int use_ipv6)
Definition: loggen_helper.c:117
GString * buffer
Definition: test_smart_multi_line.c:69