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.

64 lines
1.5 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "basicReportRecord.h"
  2. int char2int(char input){
  3. if (input >= '0' && input <= '9')
  4. return input - '0';
  5. if (input >= 'A' && input <= 'F')
  6. return input - 'A' + 10;
  7. if (input >= 'a' && input <= 'f')
  8. return input - 'a' + 10;
  9. return -1;
  10. };
  11. // This function assumes src to be a zero terminated sanitized string with
  12. // an even number of [0-9a-f] characters, and target to be sufficiently large
  13. void hex2bin(CSTR src, uint8_t *target){
  14. while (*src && src[1]){
  15. *(target++) = char2int(*src) * 16 + char2int(src[1]);
  16. src += 2;
  17. };
  18. };
  19. bool eventGroupToMD5(uint8_t *evtGrp, CSTR md5){
  20. sprintf(md5, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
  21. evtGrp[0], evtGrp[1],
  22. evtGrp[2], evtGrp[3],
  23. evtGrp[4], evtGrp[5],
  24. evtGrp[6], evtGrp[7],
  25. evtGrp[8], evtGrp[9],
  26. evtGrp[10], evtGrp[11],
  27. evtGrp[12], evtGrp[13],
  28. evtGrp[14], evtGrp[15]
  29. );
  30. return true;
  31. };
  32. bool MD5ToEventGroup(CSTR md5, uint8_t *evtGrp){
  33. hex2bin(md5, evtGrp);
  34. return true;
  35. };
  36. bool writeRecord(FILE *fd, ReportRecord *rec){
  37. size_t RetVal;
  38. RetVal = fwrite(rec, sizeof(ReportRecord), 1, fd);
  39. if (RetVal == 1) return true;
  40. return false;
  41. };
  42. bool readRecord(FILE *fd, ReportRecord *rec){
  43. size_t RetVal;
  44. RetVal = fread(rec, sizeof(ReportRecord), 1, fd);
  45. if (RetVal == 1) return true;
  46. return false;
  47. };
  48. size_t getRecordCountInFile(CSTR fName){
  49. int RetVal;
  50. struct stat cData;
  51. RetVal = stat( fName, &cData );
  52. if (RetVal == 0){
  53. return (cData.st_size / sizeof(ReportRecord));
  54. };
  55. return 0;
  56. };