billdb.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 _BILLDB_H
  21. #define _BILLDB_H
  22. #define BILLING_CHECKSUM_SIZE (33) //32 bytes + NUL
  23. #define BILLING_LINE_SIZE (512 - BILLING_CHECKSUM_SIZE)
  24. //THIS STRUCTURE MUST BE A POWER OF 2 BYTES IN SIZE
  25. typedef struct billing_record_struct
  26. {
  27. char checksum[BILLING_CHECKSUM_SIZE];
  28. char data[BILLING_LINE_SIZE];
  29. } billing_record;
  30. typedef struct billing_node_struct
  31. {
  32. int idx;
  33. struct billing_node_struct *next;
  34. } billing_node;
  35. typedef struct billdb_context_struct
  36. {
  37. billing_record *bills;
  38. time_t *last_tx;
  39. int num_free_records; //count of how many nodes should be on the free list
  40. billing_node *freelist;
  41. billing_node *activelist;
  42. //THESE ARE USED IF MMAP IS DETERMINED TO BE BROKEN...
  43. int mmap_broken;
  44. int billing_fd;
  45. } billdb_context;
  46. #define BILLING_MAP_SIZE (NUM_BILLING_ENTRIES * sizeof(billing_record))
  47. //--------------------------
  48. int format_new_billdb();
  49. int attach_to_billdb(billdb_context *ctx);
  50. int detach_from_billdb(billdb_context *ctx);
  51. int add_billing_entry(billdb_context *ctx, char *line);
  52. int clear_billing_entry(billdb_context *ctx, char *checksum);
  53. int next_pending_entry(billdb_context *ctx);
  54. #endif