passdb.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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_H
  21. #define _PASSDB_H
  22. #define CREDENTIAL_LEN (32)
  23. #define RULENAME_LEN (24)
  24. #define PARAM_LEN (24)
  25. #define ID_INVALID (0)
  26. typedef unsigned long long seq_t;
  27. typedef unsigned long long logical_card_id_t;
  28. //THIS STRUCTURE MUST BE A POWER OF 2 BYTES IN SIZE
  29. typedef struct rider_record_struct
  30. {
  31. seq_t seq; //sequence number
  32. logical_card_id_t id; //rider ID
  33. char magstripe_value[CREDENTIAL_LEN];
  34. char rfid_value[CREDENTIAL_LEN];
  35. char rule_name[RULENAME_LEN];
  36. char rule_param[PARAM_LEN];
  37. } rider_record;
  38. typedef struct rider_node_struct
  39. {
  40. int idx;
  41. struct rider_node_struct *next;
  42. } rider_node;
  43. typedef struct passdb_context_struct
  44. {
  45. rider_record *riders;
  46. rider_node *freelist;
  47. rider_node *activelist;
  48. //rider_node *logical_card_id_hash[STORED_PASS_HASH];
  49. //rider_node *rider_mag_hash[STORED_PASS_HASH];
  50. //rider_node *rider_rf_hash[STORED_PASS_HASH];
  51. rider_node **logical_card_id_hash;
  52. rider_node **rider_mag_hash;
  53. rider_node **rider_rf_hash;
  54. seq_t seq;
  55. //THESE ARE USED IF MMAP IS DETERMINED TO BE BROKEN...
  56. int mmap_broken;
  57. int passes_fd;
  58. } passdb_context;
  59. #define PASS_MAP_SIZE (NUM_STORED_PASSES * sizeof(rider_record))
  60. //--------------------------
  61. int format_new_passdb();
  62. int attach_to_passdb(passdb_context *ctx);
  63. int detach_from_passdb(passdb_context *ctx);
  64. int delete_rider(passdb_context *ctx, rider_record *rec, int sync);
  65. int update_rider(passdb_context *ctx, rider_record *rec, int sync);
  66. void sync_all_riders(passdb_context *ctx);
  67. void dump_hashes(passdb_context *ctx);
  68. int find_mag_in_hash(passdb_context *ctx, char *mag);
  69. int find_rf_in_hash(passdb_context *ctx, char *rfid);
  70. int lookup_qr_credential(passdb_context *ctx, char *payload, char *cred);
  71. #endif