util.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #ifndef HEADER_CURL_SERVER_UTIL_H
  2. #define HEADER_CURL_SERVER_UTIL_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at https://curl.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. * SPDX-License-Identifier: curl
  24. *
  25. ***************************************************************************/
  26. #include "server_setup.h"
  27. char *data_to_hex(char *data, size_t len);
  28. void logmsg(const char *msg, ...);
  29. long timediff(struct timeval newer, struct timeval older);
  30. #define TEST_DATA_PATH "%s/data/test%ld"
  31. #define ALTTEST_DATA_PATH "%s/test%ld"
  32. #define SERVERLOGS_LOCKDIR "lock" /* within logdir */
  33. /* global variable, where to find the 'data' dir */
  34. extern const char *path;
  35. /* global variable, log file name */
  36. extern const char *serverlogfile;
  37. extern const char *cmdfile;
  38. #ifdef WIN32
  39. #include <process.h>
  40. #include <fcntl.h>
  41. #define sleep(sec) Sleep ((sec)*1000)
  42. #undef perror
  43. #define perror(m) win32_perror(m)
  44. void win32_perror(const char *msg);
  45. void win32_init(void);
  46. void win32_cleanup(void);
  47. const char *sstrerror(int err);
  48. #else /* WIN32 */
  49. #define sstrerror(e) strerror(e)
  50. #endif /* WIN32 */
  51. /* fopens the test case file */
  52. FILE *test2fopen(long testno, const char *logdir);
  53. int wait_ms(int timeout_ms);
  54. curl_off_t our_getpid(void);
  55. int write_pidfile(const char *filename);
  56. int write_portfile(const char *filename, int port);
  57. void set_advisor_read_lock(const char *filename);
  58. void clear_advisor_read_lock(const char *filename);
  59. int strncasecompare(const char *first, const char *second, size_t max);
  60. /* global variable which if set indicates that the program should finish */
  61. extern volatile int got_exit_signal;
  62. /* global variable which if set indicates the first signal handled */
  63. extern volatile int exit_signal;
  64. #ifdef WIN32
  65. /* global event which if set indicates that the program should finish */
  66. extern HANDLE exit_event;
  67. #endif
  68. void install_signal_handlers(bool keep_sigalrm);
  69. void restore_signal_handlers(bool keep_sigalrm);
  70. #ifdef USE_UNIX_SOCKETS
  71. #include <curl/curl.h> /* for curl_socket_t */
  72. #ifdef HAVE_SYS_UN_H
  73. #include <sys/un.h> /* for sockaddr_un */
  74. #endif /* HAVE_SYS_UN_H */
  75. int bind_unix_socket(curl_socket_t sock, const char *unix_socket,
  76. struct sockaddr_un *sau);
  77. #endif /* USE_UNIX_SOCKETS */
  78. #endif /* HEADER_CURL_SERVER_UTIL_H */