1 /***** 2 * 3 * Copyright (C) 2002-2015 CS-SI. All Rights Reserved. 4 * Author: Yoann Vandoorselaere <yoann.v@prelude-ids.com> 5 * 6 * This file is part of the Prelude library. 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2, or (at your option) 11 * 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 General Public License along 19 * with this program; if not, write to the Free Software Foundation, Inc., 20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 21 * 22 *****/ 23 24 #ifndef _LIBPRELUDE_COMMON_H 25 #define _LIBPRELUDE_COMMON_H 26 27 #ifdef HAVE_CONFIG_H 28 # include "config.h" 29 #endif 30 31 #include "idmef.h" 32 #include "prelude-msg.h" 33 #include "prelude-inttypes.h" 34 #include "prelude-log.h" 35 #include <sys/types.h> 36 37 #ifdef WIN32 38 # include <winsock2.h> 39 #else 40 # include <sys/socket.h> 41 # include <netinet/in.h> 42 #endif 43 44 #include <time.h> 45 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 50 #define prelude_return_val_if_fail(cond, val) do { \ 51 if ( ! (cond) ) { \ 52 prelude_log(PRELUDE_LOG_CRIT, "assertion '%s' failed\n", #cond); \ 53 return val; \ 54 } \ 55 } while(0) 56 57 58 #define prelude_return_if_fail(cond) do { \ 59 if ( ! (cond) ) { \ 60 prelude_log(PRELUDE_LOG_CRIT, "assertion '%s' failed\n", #cond); \ 61 return; \ 62 } \ 63 } while(0) 64 65 66 int prelude_parse_address(const char *str, char **addr, unsigned int *port); 67 68 uint64_t prelude_hton64(uint64_t val); 69 70 uint32_t prelude_htonf(float fval); 71 72 time_t prelude_timegm(struct tm *tm); 73 74 int prelude_get_gmt_offset(long *gmt_offset); 75 76 int prelude_get_gmt_offset_from_tm(struct tm *tm, long *gmtoff); 77 78 int prelude_get_gmt_offset_from_time(const time_t *utc, long *gmtoff); 79 80 int prelude_read_multiline(FILE *fd, unsigned int *line, char *buf, size_t size); 81 82 int prelude_read_multiline2(FILE *fd, unsigned int *line, prelude_string_t *out); 83 84 void *prelude_sockaddr_get_inaddr(struct sockaddr *sa); 85 86 void *_prelude_realloc(void *ptr, size_t size); 87 88 int _prelude_get_file_name_and_path(const char *str, char **name, char **path); 89 90 prelude_msg_priority_t _idmef_impact_severity_to_msg_priority(idmef_impact_severity_t severity); 91 92 int _idmef_message_assign_missing(prelude_client_t *client, idmef_message_t *msg); 93 94 int _prelude_load_file(const char *filename, unsigned char **fdata, size_t *outsize); 95 96 void _prelude_unload_file(unsigned char *fdata, size_t size); 97 98 double prelude_simple_strtod(const char *s, char **endptr); 99 100 #ifdef __cplusplus 101 } 102 #endif 103 104 #endif /* _LIBPRELUDE_COMMON_H */ 105