/* * Copyright 2017 Yann Weber * * This file is part of Ttail. * * Ttail is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * Ttail is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Ttail. If not, see . */ #ifndef _ttail_search_files_h__ #define _ttail_search_files_h__ #include #include #include #include #include #include #include typedef struct _ttail_search_file_s ttail_search_file_t; struct _ttail_files_off_s { size_t id; off_t off; }; typedef struct _ttail_files_off_s ttail_files_off_t; /*session->file.buf), &(TTAIL->session->file.buf_sz),\ TTAIL->logfile[ID])) /*session->file.buf) /**@brief @ref ttail_search_closest() implementation for logfiles * *Will set struct _ttail_search_file_s.id and struct _ttail_search_file_s.off *@param ttail_t* *@return 0 if ok -1 if fatal error 1 if not found */ int _ttail_search_closest_files(ttail_t*); /**@brief Output result loglines to stdout *@param ttail_t* *@param int fd */ void _ttail_search_print_files(ttail_t*, int); int _ttail_search_closest_files_init(ttail_t*); int _ttail_search_closest_files_set_fsizes(ttail_t*); /**@brief Binary search of the last logline with a date < tm *@param ttail ttail_t* *@param tm struct tm* *param min short if 1 process min else process max *@param ftm struct tm** local variable of @ref _ttail_search_closest_files() *@return 0 if ok -1 if error 1 if empty result */ int _ttail_search_files_binary_search(ttail_t*, const struct tm*, const struct tm**, short); /**@brief Binary search of the last logline with a date < tm in a file * *@note uses ttail_t session data to know where to search *@param ttail ttail_t* *@param tm struct tm* *@param ftm struct tm** local variable of @ref _ttail_search_closest_files() *param min short if 1 process min else process max *@return 0 if ok -1 if error 1 if empty result */ int _ttail_search_file_binary_search(ttail_t*, const struct tm*, const struct tm**, short); /**@brief Attempt to reopen a file *@param ttail_t* ttail *@param size_t id file id in ttail *@return 0 on success, -1 on failure and errno is set *@throw EINVAL if id is too big */ int _ttail_file_reopen(ttail_t*, size_t); /**@brief Set min & max date of file *@param ttail_t* ttail *@param size_t id file id in ttail *@param struct tm[2] will be set to min & max *@return 0 on success 1 if no date found or no fp -1 if error */ inline int _ttail_file_minmax(ttail_t*, size_t, struct tm[2]); /**@brief Search next line * *Set f pos to next line begining and return the position *@param FILE* f *@return -1 on error 0 on EOF else return the next line position *@todo change header to int _ttail_file_next_line(ttail_t, size_t, size_t*) */ inline long _ttail_file_next_line(FILE*); /**@brief Search line start * *Set f pos to line begining and return the position *@param FILE* f *@return -1 on error else return the next line position *@todo change header to int _ttail_file_start_line(ttail_t, size_t, size_t*) */ inline long _ttail_file_start_line(FILE*); /**@brief Search last line with a date < tm from EOF *@param ttail ttail_t* *@param id size_t *@param tm const struct tm* *@return -1 on error else the offset of the line first chr *@todo checks */ inline off_t _ttail_from_search_from_end(ttail_t*, size_t, const struct tm*); /**@brief Read a line from off and compare its date to tm *@param t ttail_t* *@param id site_t *@param off off_t *@param tm const struct tm* *@param res int* see return value of @ref ttail_tm_cmp() *@return 0 on success -1 on error 1 if no date found */ inline int _ttail_file_off_cmp(ttail_t*, size_t, off_t, const struct tm*, int*); /**@brief Same than _ttail_file_off_cmp() but from current pos *@return 0 on success -1 on error 1 if no date found*/ inline int _ttail_file_cur_cmp(ttail_t*, size_t, const struct tm*, int*); /**@brief Free the ttail_search_file_t session *@param ttail_t* ttail */ void _ttail_search_file_free(ttail_t*); #endif