timed tail for logfiles. Display loglines given a minimum date and/or a maximum date.
c
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ttail_search.h 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright 2017 Yann Weber
  3. *
  4. * This file is part of Ttail.
  5. *
  6. * Ttail is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * any later version.
  10. *
  11. * Ttail is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with Ttail. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _ttail_search_h__
  20. #define _ttail_search_h__
  21. #include <errno.h>
  22. #include <string.h>
  23. #include <time.h>
  24. #include <regex.h>
  25. #include <sys/types.h>
  26. #include <sys/stat.h>
  27. #include <unistd.h>
  28. typedef union _ttail_search_u ttail_search_t;
  29. #include "ttail.h"
  30. typedef char* (*ttail_search_subst_f)(ttail_t*, const char*);
  31. /**@brief Comparison results
  32. *
  33. * -1 if a < b, 1 if a > b, 0 if a == b, -2 if exception
  34. *
  35. * If an exception occur, exception flags are set with | on the result.
  36. * Exceptions flags are : TTAIL_NODATE_A and TTAIL_NODATE_B
  37. */
  38. typedef int ttail_cmp_res;
  39. #include "config.h"
  40. #include "ttail_search_files.h"
  41. #include "ttail_search_std.h"
  42. /**@brief Search session is an union depending in the search method
  43. * employed
  44. */
  45. union _ttail_search_u
  46. {
  47. ttail_search_file_t file;
  48. ttail_search_stdin_t std;
  49. };
  50. /**@brief Init ttail search session
  51. *
  52. *If logfiles given as argument start a files session. Else a stdin session
  53. *is started
  54. *@param ttail_t* t
  55. *@return 0 on success -1 on error
  56. */
  57. int ttail_search_init_session(ttail_t*);
  58. /**@brief Begin a search session placing it in a ready to print situation
  59. *@param ttail_t*
  60. *@param struct tm* tmin
  61. *@return 0 if ok -1 if fatal error 1 if not found
  62. */
  63. int ttail_search_closest(ttail_t*);
  64. /**@brief Print search result on t->out_fd
  65. *@param ttail_t*
  66. */
  67. void ttail_search_print_res(ttail_t*);
  68. /**@brief Loglines comparison function
  69. *@param ttail_t* ttail
  70. *@param const char* logline a
  71. *@param const char* logline b
  72. *@return @ref ttail_cmp_res
  73. */
  74. ttail_cmp_res ttail_cmp_loglines(ttail_t*, const char*, const char*);
  75. /**@brief Fetch a date from a logline
  76. *@param ttail_t* ttail
  77. *@param const char* logline
  78. *@param struct tm* tm will be set to extracted date if not NULL
  79. *@return 0 if ok, -1 if error 1 if no prefix found 2 if no date found
  80. */
  81. int ttail_logline2date(ttail_t*, const char*, struct tm*);
  82. /**@brief Apply the choosen substitution to the logline
  83. *@param ttail_t* ttail
  84. *@param const char* logline
  85. *@return a pointer on the end of the subst string or NULL if subst fails
  86. */
  87. const char* ttail_logline_subst(ttail_t*, const char*);
  88. /**@brief Compare two struct tm
  89. *@param a struct tm*
  90. *@param b struct tm*
  91. *@return <0 if a<b, >0 if a>b and 0 if a == b
  92. */
  93. int ttail_tm_cmp(const struct tm*, const struct tm*);
  94. /**<! Set all fields to -1 */
  95. void ttail_tm_init(struct tm* tm);
  96. /**@brief Print a struct tm on stdout
  97. *@param struct tm *
  98. */
  99. void ttail_tm_print(const struct tm*);
  100. #endif