Guest User

Untitled

a guest
Jan 24th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 11.15 KB | None | 0 0
  1. Index: include/libgadu.h.in
  2. ===================================================================
  3. --- include/libgadu.h.in    (wersja 1185)
  4. +++ include/libgadu.h.in    (kopia robocza)
  5. @@ -98,6 +98,12 @@
  6.  #include <openssl/ssl.h>
  7.  #endif
  8.  
  9. +#ifdef _WIN32
  10. +#  undef GG_CONFIG_HAVE_FORK
  11. +#else
  12. +#  define GG_CONFIG_HAVE_FORK
  13. +#endif
  14. +
  15.  #ifdef GG_CONFIG_HAVE_STDINT_H
  16.  #include <stdint.h>
  17.  #else
  18. Index: include/resolver.h
  19. ===================================================================
  20. --- include/resolver.h  (wersja 1185)
  21. +++ include/resolver.h  (kopia robocza)
  22. @@ -19,7 +19,7 @@
  23.  #ifndef LIBGADU_RESOLVER_H
  24.  #define LIBGADU_RESOLVER_H
  25.  
  26. -#include <arpa/inet.h>
  27. +#include "compat.h"
  28.  
  29.  int gg_gethostbyname_real(const char *hostname, struct in_addr **result, unsigned int *count, int pthread);
  30.  
  31. Index: include/compat.h
  32. ===================================================================
  33. --- include/compat.h    (wersja 1185)
  34. +++ include/compat.h    (kopia robocza)
  35. @@ -29,10 +29,36 @@
  36.  #define __COMPAT_H
  37.  
  38.  #include <sys/types.h>
  39. -#include <sys/socket.h>
  40. -#include <netinet/in.h>
  41. -#include <arpa/inet.h>
  42.  
  43. +#ifdef _WIN32
  44. +#  include <ws2tcpip.h>
  45. +#  include <winsock2.h>
  46. +#  define EINPROGRESS WSAEINPROGRESS
  47. +#  define ETIMEDOUT WSAETIMEDOUT
  48. +#  define ENOTCONN WSAENOTCONN
  49. +#  define ECONNRESET WSAECONNRESET
  50. +#  define SHUT_RDWR SD_BOTH
  51. +#  define SIOCGIFCONF 0x8912
  52. +#  undef small
  53. +#  define random (long)rand
  54. +#  define getsockopt( socket, level, optname, optval, optlenptr ) \
  55. +   gg_win32_getsockopt( socket, level, optname, optval, optlenptr )
  56. +#  define ioctl( fd, command, val ) \
  57. +   gg_win32_ioctl( fd, command, val )
  58. +
  59. +int gg_win32_getsockopt(int socket, int level, int optname, void *optval,
  60. +   socklen_t *optlenptr);
  61. +int gg_win32_ioctl(int fd, int command, void* val);
  62. +#else
  63. +#  include <sys/wait.h>
  64. +#  include <sys/ioctl.h>
  65. +#  include <netdb.h>
  66. +#  include <sys/socket.h>
  67. +#  include <netinet/in.h>
  68. +#  include <arpa/inet.h>
  69. +#  include <signal.h>
  70. +#endif
  71. +
  72.  #ifdef sun
  73.  #  define INADDR_NONE   ((in_addr_t) 0xffffffff)
  74.  #endif
  75. Index: src/handlers.c
  76. ===================================================================
  77. --- src/handlers.c  (wersja 1185)
  78. +++ src/handlers.c  (kopia robocza)
  79. @@ -27,9 +27,6 @@
  80.   */
  81.  
  82.  #include <sys/types.h>
  83. -#include <sys/socket.h>
  84. -#include <netinet/in.h>
  85. -#include <arpa/inet.h>
  86.  #include <ctype.h>
  87.  #ifdef sun
  88.  #  include <sys/filio.h>
  89. @@ -46,7 +43,6 @@
  90.  #include "deflate.h"
  91.  
  92.  #include <errno.h>
  93. -#include <netdb.h>
  94.  #include <stdarg.h>
  95.  #include <stdio.h>
  96.  #include <stdlib.h>
  97. Index: src/resolver.c
  98. ===================================================================
  99. --- src/resolver.c  (wersja 1185)
  100. +++ src/resolver.c  (kopia robocza)
  101. @@ -26,13 +26,10 @@
  102.   * \brief Funkcje rozwiązywania nazw
  103.   */
  104.  
  105. -#include <sys/wait.h>
  106. -#include <netdb.h>
  107.  #include <errno.h>
  108.  #include <stdlib.h>
  109.  #include <string.h>
  110.  #include <unistd.h>
  111. -#include <signal.h>
  112.  
  113.  #include "compat.h"
  114.  #include "libgadu.h"
  115. @@ -242,6 +239,7 @@
  116.  #endif /* GG_CONFIG_HAVE_GETHOSTBYNAME_R */
  117.  }
  118.  
  119. +#if defined(GG_CONFIG_HAVE_PTHREAD) || defined(GG_CONFIG_HAVE_FORK)
  120.  /**
  121.   * \internal Rozwiązuje nazwę i zapisuje wynik do podanego desktyptora.
  122.   *
  123. @@ -280,6 +278,7 @@
  124.  
  125.     return res;
  126.  }
  127. +#endif
  128.  
  129.  /**
  130.   * \internal Odpowiednik \c gethostbyname zapewniający współbieżność.
  131. @@ -311,6 +310,7 @@
  132.     int pid;        /*< Identyfikator procesu */
  133.  };
  134.  
  135. +#ifdef GG_CONFIG_HAVE_FORK
  136.  /**
  137.   * \internal Rozwiązuje nazwę serwera w osobnym procesie.
  138.   *
  139. @@ -365,9 +365,9 @@
  140.         close(pipes[0]);
  141.  
  142.         if (gg_resolver_run(pipes[1], hostname) == -1)
  143. -           exit(1);
  144. +           _Exit(1);
  145.         else
  146. -           exit(0);
  147. +           _Exit(0);
  148.     }
  149.  
  150.     close(pipes[1]);
  151. @@ -416,6 +416,7 @@
  152.  
  153.     free(data);
  154.  }
  155. +#endif
  156.  
  157.  #ifdef GG_CONFIG_HAVE_PTHREAD
  158.  
  159. @@ -593,11 +594,13 @@
  160.     }
  161.  
  162.     switch (type) {
  163. +#ifdef GG_CONFIG_HAVE_FORK
  164.         case GG_RESOLVER_FORK:
  165.             gs->resolver_type = type;
  166.             gs->resolver_start = gg_resolver_fork_start;
  167.             gs->resolver_cleanup = gg_resolver_fork_cleanup;
  168.             return 0;
  169. +#endif
  170.  
  171.  #ifdef GG_CONFIG_HAVE_PTHREAD
  172.         case GG_RESOLVER_PTHREAD:
  173. @@ -702,11 +705,13 @@
  174.     }
  175.  
  176.     switch (type) {
  177. +#ifdef GG_CONFIG_HAVE_FORK
  178.         case GG_RESOLVER_FORK:
  179.             gh->resolver_type = type;
  180.             gh->resolver_start = gg_resolver_fork_start;
  181.             gh->resolver_cleanup = gg_resolver_fork_cleanup;
  182.             return 0;
  183. +#endif
  184.  
  185.  #ifdef GG_CONFIG_HAVE_PTHREAD
  186.         case GG_RESOLVER_PTHREAD:
  187. @@ -778,11 +783,13 @@
  188.             gg_global_resolver_cleanup = NULL;
  189.             return 0;
  190.  
  191. +#ifdef GG_CONFIG_HAVE_FORK
  192.         case GG_RESOLVER_FORK:
  193.             gg_global_resolver_type = type;
  194.             gg_global_resolver_start = gg_resolver_fork_start;
  195.             gg_global_resolver_cleanup = gg_resolver_fork_cleanup;
  196.             return 0;
  197. +#endif
  198.  
  199.  #ifdef GG_CONFIG_HAVE_PTHREAD
  200.         case GG_RESOLVER_PTHREAD:
  201. Index: src/events.c
  202. ===================================================================
  203. --- src/events.c    (wersja 1185)
  204. +++ src/events.c    (kopia robocza)
  205. @@ -30,7 +30,6 @@
  206.   */
  207.  
  208.  #include "compat.h"
  209. -#include <sys/ioctl.h>
  210.  #include <ctype.h>
  211.  
  212.  #include "libgadu.h"
  213. @@ -353,7 +352,7 @@
  214.  static int gg_async_connect_failed(struct gg_session *gs, int *res_ptr)
  215.  {
  216.     int res = 0;
  217. -   unsigned int res_size = sizeof(res);
  218. +   socklen_t res_size = sizeof(res);
  219.  
  220.     if (!gs->async)
  221.         return 0;
  222. Index: src/libgadu.c
  223. ===================================================================
  224. --- src/libgadu.c   (wersja 1185)
  225. +++ src/libgadu.c   (kopia robocza)
  226. @@ -44,7 +44,6 @@
  227.  #include "deflate.h"
  228.  
  229.  #include <errno.h>
  230. -#include <netdb.h>
  231.  #include <stdarg.h>
  232.  #include <stdio.h>
  233.  #include <stdlib.h>
  234. Index: src/http.c
  235. ===================================================================
  236. --- src/http.c  (wersja 1185)
  237. +++ src/http.c  (kopia robocza)
  238. @@ -30,7 +30,6 @@
  239.  
  240.  #include <ctype.h>
  241.  #include <errno.h>
  242. -#include <netdb.h>
  243.  #include <signal.h>
  244.  #include <stdarg.h>
  245.  #include <stdio.h>
  246. @@ -251,7 +250,7 @@
  247.     }
  248.  
  249.     if (h->state == GG_STATE_SENDING_QUERY) {
  250. -       int res;
  251. +       ssize_t res;
  252.  
  253.         res = write(h->fd, h->query, strlen(h->query));
  254.  
  255. Index: src/dcc7.c
  256. ===================================================================
  257. --- src/dcc7.c  (wersja 1185)
  258. +++ src/dcc7.c  (kopia robocza)
  259. @@ -31,7 +31,6 @@
  260.  
  261.  #include "compat.h"
  262.  #include <sys/stat.h>
  263. -#include <sys/ioctl.h>
  264.  #ifdef sun
  265.  #  include <sys/filio.h>
  266.  #endif
  267. Index: src/compat.c
  268. ===================================================================
  269. --- src/compat.c    (wersja 0)
  270. +++ src/compat.c    (wersja 0)
  271. @@ -0,0 +1,106 @@
  272. +#include <errno.h>
  273. +
  274. +#include "compat.h"
  275. +
  276. +#ifdef _WIN32
  277. +#undef getsockopt
  278. +
  279. +struct ifconf
  280. +{
  281. +   int ifc_len;
  282. +   union
  283. +   {
  284. +       char *ifcu_buf;
  285. +       struct ifreq *ifcu_req;
  286. +   } ifc_ifcu;
  287. +};
  288. +#define ifc_buf ifc_ifcu.ifcu_buf
  289. +#define ifc_req ifc_ifcu.ifcu_req
  290. +
  291. +struct ifreq
  292. +{
  293. +   union
  294. +   {
  295. +       char ifrn_name[6];
  296. +   } ifr_ifrn;
  297. +
  298. +   union
  299. +   {
  300. +       struct sockaddr ifru_addr;
  301. +       char *ifru_data;
  302. +   } ifr_ifru;
  303. +};
  304. +#define ifr_name ifr_ifrn.ifrn_name
  305. +#define ifr_addr ifr_ifru.ifru_addr
  306. +
  307. +int gg_win32_getsockopt(int socket, int level, int optname, void *optval,
  308. +   socklen_t *optlenptr) {
  309. +   if(getsockopt(socket, level, optname, optval, optlenptr) ==
  310. +       SOCKET_ERROR ) {
  311. +       errno = WSAGetLastError();
  312. +       return -1;
  313. +   }
  314. +   return 0;
  315. +}
  316. +
  317. +/* sys/ioctl.h */
  318. +int gg_win32_ioctl(int fd, int command, void* val) {
  319. +   switch( command ) {
  320. +   case FIONBIO:
  321. +   {
  322. +       if (ioctlsocket(fd, FIONBIO, (unsigned long *)val) ==
  323. +           SOCKET_ERROR) {
  324. +           errno = WSAGetLastError();
  325. +           return -1;
  326. +       }
  327. +       return 0;
  328. +   }
  329. +   case SIOCGIFCONF:
  330. +   {
  331. +       INTERFACE_INFO InterfaceList[20];
  332. +       unsigned long nBytesReturned;
  333. +       if (WSAIoctl(fd, SIO_GET_INTERFACE_LIST,
  334. +               0, 0, &InterfaceList,
  335. +               sizeof(InterfaceList), &nBytesReturned,
  336. +               0, 0) == SOCKET_ERROR) {
  337. +           errno = WSAGetLastError();
  338. +           return -1;
  339. +       } else {
  340. +           int i;
  341. +           struct ifconf *ifc = val;
  342. +           char *tmp = ifc->ifc_buf;
  343. +           int nNumInterfaces =
  344. +               nBytesReturned / sizeof(INTERFACE_INFO);
  345. +           for (i = 0; i < nNumInterfaces; i++) {
  346. +               INTERFACE_INFO ii = InterfaceList[i];
  347. +               struct ifreq *ifr = (struct ifreq *) tmp;
  348. +               struct sockaddr_in *sa =
  349. +                   (struct sockaddr_in *) &ifr->ifr_addr;
  350. +
  351. +               sa->sin_family =
  352. +                   ii.iiAddress.AddressIn.sin_family;
  353. +               sa->sin_port =
  354. +                   ii.iiAddress.AddressIn.sin_port;
  355. +               sa->sin_addr.s_addr =
  356. +                   ii.iiAddress.AddressIn.sin_addr.s_addr;
  357. +               tmp += sizeof(struct ifreq);
  358. +
  359. +               /* Make sure that we can fit in the original
  360. +                * buffer */
  361. +               if (tmp >= (ifc->ifc_buf + ifc->ifc_len +
  362. +                   sizeof(struct ifreq))) {
  363. +                   break;
  364. +               }
  365. +           }
  366. +           /* Replace the length with the actually used length */
  367. +           ifc->ifc_len = ifc->ifc_len - (ifc->ifc_buf - tmp);
  368. +           return 0;
  369. +       }
  370. +   }
  371. +   default:
  372. +       errno = EINVAL;
  373. +       return -1;
  374. +   }/*end switch*/
  375. +}
  376. +
  377. +#endif /* _WIN32 */
  378. Index: src/pubdir.c
  379. ===================================================================
  380. --- src/pubdir.c    (wersja 1185)
  381. +++ src/pubdir.c    (kopia robocza)
  382. @@ -26,6 +26,7 @@
  383.   * \brief Obsługa katalogu publicznego
  384.   */
  385.  
  386. +#include "compat.h"
  387.  #include <ctype.h>
  388.  #include <errno.h>
  389.  #include <stdarg.h>
  390. @@ -167,6 +168,7 @@
  391.  
  392.  #endif /* DOXYGEN */
  393.  
  394. +
  395.  /**
  396.   * Usuwa użytkownika.
  397.   *
  398. Index: src/common.c
  399. ===================================================================
  400. --- src/common.c    (wersja 1185)
  401. +++ src/common.c    (kopia robocza)
  402. @@ -24,18 +24,14 @@
  403.   *
  404.   * \brief Funkcje wykorzystywane przez różne moduły biblioteki
  405.   */
  406. +#include "compat.h"
  407.  #include <sys/types.h>
  408. -#include <sys/ioctl.h>
  409. -#include <sys/socket.h>
  410. -#include <netinet/in.h>
  411. -#include <arpa/inet.h>
  412.  #ifdef sun
  413.  #  include <sys/filio.h>
  414.  #endif
  415.  
  416.  #include <errno.h>
  417.  #include <fcntl.h>
  418. -#include <netdb.h>
  419.  #include <stdarg.h>
  420.  #include <stdio.h>
  421.  #include <stdlib.h>
  422. Index: src/Makefile.am
  423. ===================================================================
  424. --- src/Makefile.am (wersja 1185)
  425. +++ src/Makefile.am (kopia robocza)
  426. @@ -1,5 +1,5 @@
  427.  lib_LTLIBRARIES = libgadu.la
  428. -libgadu_la_SOURCES = common.c dcc.c dcc7.c debug.c deflate.c encoding.c endian.c events.c handlers.c http.c libgadu.c message.c obsolete.c pubdir.c pubdir50.c resolver.c sha1.c
  429. +libgadu_la_SOURCES = common.c compat.c dcc.c dcc7.c debug.c deflate.c encoding.c endian.c events.c handlers.c http.c libgadu.c message.c obsolete.c pubdir.c pubdir50.c resolver.c sha1.c
  430.  libgadu_la_CFLAGS = -I$(top_srcdir) -I$(top_srcdir)/include -DGG_IGNORE_DEPRECATED
  431.  libgadu_la_LDFLAGS = -version-number 3:13 -export-symbols libgadu.sym
  432.  EXTRA_DIST = libgadu.sym
  433. Index: src/dcc.c
  434. ===================================================================
  435. --- src/dcc.c   (wersja 1185)
  436. +++ src/dcc.c   (kopia robocza)
  437. @@ -28,7 +28,6 @@
  438.  
  439.  #include "compat.h"
  440.  #include <sys/stat.h>
  441. -#include <sys/ioctl.h>
  442.  #ifdef sun
  443.  #  include <sys/filio.h>
  444.  #endif
  445. Index: src/pubdir50.c
  446. ===================================================================
  447. --- src/pubdir50.c  (wersja 1185)
  448. +++ src/pubdir50.c  (kopia robocza)
  449. @@ -25,6 +25,7 @@
  450.   * testowa konwersja, żeby poznać długość tekstu wynikowego.
  451.   */
  452.  
  453. +#include "compat.h"
  454.  #include <errno.h>
  455.  #include <stdlib.h>
  456.  #include <string.h>
Add Comment
Please, Sign In to add comment