util.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* util.h
  2. *
  3. * Wrapper functions and data structures
  4. *
  5. * Slitheen - a decoy routing system for censorship resistance
  6. * Copyright (C) 2017 Cecylia Bocovich (cbocovic@uwaterloo.ca)
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, version 3.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. * Additional permission under GNU GPL version 3 section 7
  21. *
  22. * If you modify this Program, or any covered work, by linking or combining
  23. * it with the OpenSSL library (or a modified version of that library),
  24. * containing parts covered by the terms of the OpenSSL Licence and the
  25. * SSLeay license, the licensors of this Program grant you additional
  26. * permission to convey the resulting work. Corresponding Source for a
  27. * non-source form of such a combination shall include the source code
  28. * for the parts of the OpenSSL library used as well as that of the covered
  29. * work.
  30. */
  31. #ifndef UTIL_H
  32. #define UTIL_H
  33. #include <stddef.h>
  34. #include <stdint.h>
  35. /* Defined debugging types */
  36. #ifdef DEBUG_HS
  37. #define DEBUG_HS 1
  38. #else
  39. #define DEBUG_HS 0
  40. #endif
  41. #ifdef DEBUG_CRYPTO
  42. #define DEBUG_CRYPTO 1
  43. #else
  44. #define DEBUG_CRYPTO 0
  45. #endif
  46. #ifdef DEBUG_FLOW
  47. #define DEBUG_FLOW 1
  48. #else
  49. #define DEBUG_FLOW 0
  50. #endif
  51. #ifdef DEBUG_UP
  52. #define DEBUG_UP 1
  53. #else
  54. #define DEBUG_UP 0
  55. #endif
  56. #ifdef DEBUG_PROXY
  57. #define DEBUG_PROXY 1
  58. #else
  59. #define DEBUG_PROXY 0
  60. #endif
  61. #ifdef DEBUG_DOWN
  62. #define DEBUG_DOWN 1
  63. #else
  64. #define DEBUG_DOWN 0
  65. #endif
  66. /* Debugging macros */
  67. #define DEBUG_MSG(type, ...) \
  68. do { \
  69. if(type) printf(__VA_ARGS__); \
  70. } while(0)
  71. #define DEBUG_BYTES(type, ptr, len) \
  72. do { \
  73. if(type) { \
  74. for(int i=0; i < len; i++) printf("%02x ", ptr[i]); \
  75. printf("\n"); \
  76. } \
  77. } while(0)
  78. void *smalloc(size_t size);
  79. void *scalloc(size_t nmemb, size_t size);
  80. typedef struct queue_st queue;
  81. queue *init_queue();
  82. void enqueue(queue *list, void *data);
  83. void *dequeue(queue *list);
  84. void *peek(queue *list, int32_t n);
  85. void remove_queue(queue *list);
  86. #endif /* UTIL_H */