ruleparam_db.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (c) 2019 Clementine Computing LLC.
  3. *
  4. * This file is part of PopuFare.
  5. *
  6. * PopuFare is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * PopuFare 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 Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with PopuFare. If not, see <https://www.gnu.org/licenses/>.
  18. *
  19. */
  20. #ifndef PASSDB_SLIM_RULEPARAM_DB_H
  21. #define PASSDB_SLIM_RULEPARAM_DB_H
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <time.h>
  26. #include <sys/time.h>
  27. #include <unistd.h>
  28. #include <errno.h>
  29. #include "../common/common_defs.h"
  30. #include "../commhub/commhub.h"
  31. #include "../commhub/client_utils.h"
  32. #define RULEPARAM_DB_FILE DATABASE_FILE_PATH "ruleparam.db"
  33. #define RULEPARAM_DB_NOT_FOUND (-1)
  34. #define RULEPARAM_DB_FULL (-2)
  35. #define RULEPARAM_DB_EMPTY (-3)
  36. #define RULEPARAM_DB_DUP (-4)
  37. #define RULEPARAM_DB_SANITY (-5)
  38. #define RULEPARAM_DB_MAX ( 2048 )
  39. typedef struct passdb_slim_ruleparam_t {
  40. int id;
  41. int reference_count;
  42. char name[RULENAME_LEN];
  43. char param[PARAM_LEN];
  44. struct passdb_slim_ruleparam_t *next;
  45. } passdb_slim_ruleparam;
  46. typedef struct passdb_slim_ruleparam_db_context_t {
  47. int n;
  48. passdb_slim_ruleparam *head;
  49. char *db_filename;
  50. int sync_counter;
  51. int sync_every_n;
  52. int n_filename_history; // We want to store some historic ruleparams, which we
  53. int pos_filename_history; // rotate through.
  54. unsigned long long seq;
  55. } ruleparam_db_ctx;
  56. passdb_slim_ruleparam *_alloc_ruleparam_db_nod(int id, char *name, char *param);
  57. int ruleparam_db_init( ruleparam_db_ctx * );
  58. ruleparam_db_ctx * ruleparam_db_alloc( );
  59. int ruleparam_db_load( ruleparam_db_ctx **, char * );
  60. int ruleparam_db_free( ruleparam_db_ctx * );
  61. int ruleparam_db_debug_dump( ruleparam_db_ctx *);
  62. //int ruleparam_db_save( ruleparam_db_ctx *, char * );
  63. int ruleparam_db_save( ruleparam_db_ctx * );
  64. //int ruleparam_db_rate_limited_sync( ruleparam_db_ctx *, char * );
  65. int ruleparam_db_rate_limited_sync( ruleparam_db_ctx * );
  66. int ruleparam_db_add( ruleparam_db_ctx *, char *, char *);
  67. int ruleparam_db_remove( ruleparam_db_ctx *, int );
  68. int ruleparam_db_find( ruleparam_db_ctx *, char *, char *);
  69. int ruleparam_db_reference_count( ruleparam_db_ctx *, char *, char *);
  70. int ruleparam_db_get( char *, char *, ruleparam_db_ctx *, int );
  71. int ruleparam_db_find_free_id( ruleparam_db_ctx * );
  72. int ruleparam_db_update( ruleparam_db_ctx *ctx, char *name, char *param, int delta_ref_count );
  73. int ruleparam_db_clean( ruleparam_db_ctx *ctx );
  74. int ruleparam_db_consistency_check( ruleparam_db_ctx *ctx );
  75. passdb_slim_ruleparam *ruleparam_db_get_node( ruleparam_db_ctx *ctx, int id );
  76. int format_new_ruleparamdb(char *);
  77. void ruleparam_db_dump(ruleparam_db_ctx *ctx);
  78. #endif