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.

282 lines
5.8 KiB

8 years ago
8 years ago
8 years ago
6 years ago
7 years ago
2 years ago
7 years ago
3 years ago
8 years ago
7 years ago
7 years ago
4 years ago
8 years ago
8 years ago
8 years ago
7 years ago
8 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
6 years ago
6 years ago
6 years ago
7 years ago
8 years ago
  1. /**
  2. * @file platform_windows.h
  3. * @brief Windows platform-specific implementation details
  4. * @license GNU General Public License 3.0 - see LICENSE.txt
  5. */
  6. #ifndef PLATFORM_WINDOWS_H
  7. #define PLATFORM_WINDOWS_H
  8. // Windows platform specifica
  9. #ifndef _EXPORT_PEP_ENGINE_DLL
  10. #define _EXPORT_PEP_ENGINE_DLL
  11. #endif
  12. #pragma warning(disable : 4996)
  13. // We need to make sure winsock2 is included before windows.h, or we will get redefinitions of symbols
  14. // as windows.h includes winsock1.h, so we will have duplicate symbols if windows.h is included first.
  15. // It seems some of our code includes sync.h before including winsock.h, leading to the failure.
  16. // Including winsock2.h here fixes the problem for now...
  17. #ifdef WIN32
  18. // winsock2.h includes windows.h and that leads to the definition of `min` and `max`
  19. // which causes compile errors elsewhere.
  20. #define NOMINMAX
  21. #include <winsock2.h>
  22. #endif // WIN32
  23. #include <Rpc.h>
  24. #include <string.h>
  25. #include <io.h>
  26. #include <basetsd.h>
  27. #include <time.h>
  28. #include "timestamp.h"
  29. // pEp files and directories
  30. #ifndef PER_USER_DIRECTORY
  31. #define PER_USER_DIRECTORY "%LOCALAPPDATA%\\pEp"
  32. #endif
  33. #ifndef PER_MACHINE_DIRECTORY
  34. #define PER_MACHINE_DIRECTORY "%ALLUSERSPROFILE%\\pEp"
  35. #endif
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. #define ssize_t SSIZE_T
  40. #define RTLD_LAZY 1
  41. #define mode_t int
  42. #ifndef MIN
  43. #define MIN(A, B) ((A)>(B) ? (B) : (A))
  44. #define MAX(A, B) ((A)>(B) ? (A) : (B))
  45. #endif
  46. /**
  47. * <!-- dlopen() -->
  48. *
  49. * @brief TODO
  50. *
  51. * @param[in] filename const char*
  52. * @param[in] flag int
  53. *
  54. */
  55. void *dlopen(const char *filename, int flag);
  56. /**
  57. * <!-- dlclose() -->
  58. *
  59. * @brief TODO
  60. *
  61. * @param[in] handle void*
  62. *
  63. */
  64. int dlclose(void *handle);
  65. /**
  66. * <!-- dlsym() -->
  67. *
  68. * @brief TODO
  69. *
  70. * @param[in] handle void*
  71. * @param[in] symbol const char*
  72. *
  73. */
  74. void *dlsym(void *handle, const char *symbol);
  75. /**
  76. * <!-- mkstemp() -->
  77. *
  78. * @brief TODO
  79. *
  80. * @param[in] templ char*
  81. *
  82. */
  83. int mkstemp(char *templ);
  84. // Nota bene: It does _not_ respect timeptr->tm_gmtoff, so it behaves the same as its POSIX original.
  85. // Use timegm_with_gmtoff() from <pEp/timestamp.h> or that.
  86. /**
  87. * <!-- timegm() -->
  88. *
  89. * @brief TODO
  90. *
  91. * @param[in] timeptr timestamp*
  92. *
  93. */
  94. DYNAMIC_API time_t timegm(timestamp *timeptr);
  95. #ifndef strdup
  96. #define strdup(A) _strdup((A))
  97. #endif
  98. #ifndef snprintf
  99. #if _MSC_VER<1900 // Includes undefined case. This is a check for VS 2015, which throws an error.
  100. #define snprintf(...) _snprintf(__VA_ARGS__)
  101. #endif
  102. #endif
  103. #ifndef strtok_r
  104. #define strtok_r(A, B, C) strtok_s((A), (B), (C))
  105. #endif
  106. #ifndef strncasecmp
  107. #define strncasecmp(A, B, C) _strnicmp((A), (B), (C))
  108. #endif
  109. #ifndef strcasecmp
  110. #define strcasecmp(A, B) _stricmp((A), (B))
  111. #endif
  112. #ifndef gmtime_r
  113. #define gmtime_r(A, B) gmtime_s((B), (A))
  114. #endif
  115. #ifndef ftruncate
  116. #define ftruncate(A, B) _chsize((A), (B))
  117. #endif
  118. #ifndef ftello
  119. #define ftello(A) ((off_t) _ftelli64(A))
  120. #endif
  121. /**
  122. * <!-- strndup() -->
  123. *
  124. * @brief TODO
  125. *
  126. * @param[in] s1 const char*
  127. * @param[in] n size_t
  128. *
  129. */
  130. char *strndup(const char *s1, size_t n);
  131. /**
  132. * <!-- stpcpy() -->
  133. *
  134. * @brief TODO
  135. *
  136. * @param[in] dst char*
  137. * @param[in] src const char*
  138. *
  139. */
  140. char *stpcpy(char *dst, const char *src);
  141. /**
  142. * <!-- strlcpy() -->
  143. *
  144. * @brief TODO
  145. *
  146. * @param[in] dst char*
  147. * @param[in] src const char*
  148. * @param[in] size size_t
  149. *
  150. */
  151. size_t strlcpy(char* dst, const char* src, size_t size);
  152. /**
  153. * <!-- strlcat() -->
  154. *
  155. * @brief TODO
  156. *
  157. * @param[in] dst char*
  158. * @param[in] src const char*
  159. * @param[in] size size_t
  160. *
  161. */
  162. size_t strlcat(char* dst, const char* src, size_t size);
  163. /**
  164. * <!-- strnstr() -->
  165. *
  166. * @brief TODO
  167. *
  168. * @param[in] big const char*
  169. * @param[in] little const char*
  170. * @param[in] len size_t
  171. *
  172. */
  173. char *strnstr(const char *big, const char *little, size_t len);
  174. /**
  175. * <!-- windoze_keys_db() -->
  176. *
  177. * @brief TODO
  178. *
  179. *
  180. */
  181. const char *windoze_keys_db(void);
  182. /**
  183. * <!-- windoze_local_db() -->
  184. *
  185. * @brief TODO
  186. *
  187. *
  188. */
  189. const char *windoze_local_db(void);
  190. /**
  191. * <!-- windoze_system_db() -->
  192. *
  193. * @brief TODO
  194. *
  195. *
  196. */
  197. const char *windoze_system_db(void);
  198. /**
  199. * <!-- log_output_debug() -->
  200. *
  201. * @brief TODO
  202. *
  203. * @param[in] title const char*
  204. * @param[in] entity const char*
  205. * @param[in] description const char*
  206. * @param[in] comment const char*
  207. *
  208. */
  209. void log_output_debug(const char *title, const char *entity, const char *description, const char *comment);
  210. /**
  211. * <!-- random() -->
  212. *
  213. * @brief TODO
  214. *
  215. *
  216. */
  217. long random(void);
  218. // on Windoze, uuid_t needs pointer semantics
  219. typedef UUID pEpUUID[1];
  220. #define _UUID_STRING_T
  221. typedef char uuid_string_t[37];
  222. /**
  223. * <!-- uuid_generate_random() -->
  224. *
  225. * @brief TODO
  226. *
  227. * @param[in] out pEpUUID
  228. *
  229. */
  230. void uuid_generate_random(pEpUUID out);
  231. /**
  232. * <!-- uuid_parse() -->
  233. *
  234. * @brief TODO
  235. *
  236. * @param[in] in char*
  237. * @param[in] uu pEpUUID
  238. *
  239. */
  240. int uuid_parse(char *in, pEpUUID uu);
  241. /**
  242. * <!-- uuid_unparse_upper() -->
  243. *
  244. * @brief TODO
  245. *
  246. * @param[in] uu pEpUUID
  247. * @param[in] out uuid_string_t
  248. *
  249. */
  250. void uuid_unparse_upper(pEpUUID uu, uuid_string_t out);
  251. #ifndef __cplusplus
  252. #define inline __inline
  253. #endif
  254. #ifdef __cplusplus
  255. }
  256. #endif
  257. #endif