LibIRCClient 1.10 Used by Probotic
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
Dieses Repo ist archiviert. Du kannst Dateien sehen und es klonen, kannst aber nicht pushen oder Issues/Pull-Requests öffnen.

150 Zeilen
3.3KB

  1. /*
  2. * Copyright (C) 2004-2012 George Yunaev gyunaev@ulduzsoft.com
  3. *
  4. * This library is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU Lesser General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or (at your
  7. * option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  12. * License for more details.
  13. */
  14. #if !defined (_WIN32)
  15. #include "config.h"
  16. #include <stdio.h>
  17. #include <stdarg.h>
  18. #include <unistd.h>
  19. #include <string.h>
  20. #include <stdlib.h>
  21. #include <sys/stat.h>
  22. #include <sys/types.h>
  23. #include <sys/socket.h>
  24. #include <netdb.h>
  25. #include <arpa/inet.h>
  26. #include <netinet/in.h>
  27. #include <fcntl.h>
  28. #include <errno.h>
  29. #include <ctype.h>
  30. #include <time.h>
  31. #if defined (ENABLE_THREADS)
  32. #include <pthread.h>
  33. typedef pthread_mutex_t port_mutex_t;
  34. #if !defined (PTHREAD_MUTEX_RECURSIVE) && defined (PTHREAD_MUTEX_RECURSIVE_NP)
  35. #define PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE_NP
  36. #endif
  37. #endif
  38. #else
  39. #include <winsock2.h>
  40. #include <ws2tcpip.h>
  41. #include <windows.h>
  42. #include <time.h>
  43. #include <stdio.h>
  44. #include <stdarg.h>
  45. #include <string.h>
  46. #include <stdlib.h>
  47. #include <sys/stat.h>
  48. #if defined (ENABLE_THREADS)
  49. typedef CRITICAL_SECTION port_mutex_t;
  50. #endif
  51. #define inline
  52. #define snprintf _snprintf
  53. #define vsnprintf _vsnprintf
  54. #define strncasecmp _strnicmp
  55. #endif
  56. #if defined (ENABLE_SSL)
  57. #include <openssl/ssl.h>
  58. #include <openssl/err.h>
  59. #include <openssl/rand.h>
  60. #endif
  61. #if defined (ENABLE_THREADS)
  62. static inline int libirc_mutex_init (port_mutex_t * mutex)
  63. {
  64. #if defined (_WIN32)
  65. InitializeCriticalSection (mutex);
  66. return 0;
  67. #elif defined (PTHREAD_MUTEX_RECURSIVE)
  68. pthread_mutexattr_t attr;
  69. return (pthread_mutexattr_init (&attr)
  70. || pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE)
  71. || pthread_mutex_init (mutex, &attr));
  72. #else /* !defined (PTHREAD_MUTEX_RECURSIVE) */
  73. return pthread_mutex_init (mutex, 0);
  74. #endif /* defined (_WIN32) */
  75. }
  76. static inline void libirc_mutex_destroy (port_mutex_t * mutex)
  77. {
  78. #if defined (_WIN32)
  79. DeleteCriticalSection (mutex);
  80. #else
  81. pthread_mutex_destroy (mutex);
  82. #endif
  83. }
  84. static inline void libirc_mutex_lock (port_mutex_t * mutex)
  85. {
  86. #if defined (_WIN32)
  87. EnterCriticalSection (mutex);
  88. #else
  89. pthread_mutex_lock (mutex);
  90. #endif
  91. }
  92. static inline void libirc_mutex_unlock (port_mutex_t * mutex)
  93. {
  94. #if defined (_WIN32)
  95. LeaveCriticalSection (mutex);
  96. #else
  97. pthread_mutex_unlock (mutex);
  98. #endif
  99. }
  100. #else
  101. typedef void * port_mutex_t;
  102. static inline int libirc_mutex_init (port_mutex_t * mutex) { return 0; }
  103. static inline void libirc_mutex_destroy (port_mutex_t * mutex) {}
  104. static inline void libirc_mutex_lock (port_mutex_t * mutex) {}
  105. static inline void libirc_mutex_unlock (port_mutex_t * mutex) {}
  106. #endif
  107. /*
  108. * Stub for WIN32 dll to initialize winsock API
  109. */
  110. #if defined (WIN32_DLL)
  111. BOOL WINAPI DllMain (HINSTANCE hinstDll, DWORD fdwReason, LPVOID lpvReserved)
  112. {
  113. switch(fdwReason)
  114. {
  115. case DLL_PROCESS_ATTACH:
  116. DisableThreadLibraryCalls (hinstDll);
  117. break;
  118. case DLL_PROCESS_DETACH:
  119. break;
  120. }
  121. return TRUE;
  122. }
  123. #endif