libpurple/win32/libc_interface.c

Sat, 24 Nov 2018 08:30:47 +0000

author
Gary Kramlich <grim@reaperworld.com>
date
Sat, 24 Nov 2018 08:30:47 +0000
changeset 39320
c412d5619fe2
parent 39020
2f397c683f6c
child 39373
47667f5c6696
permissions
-rw-r--r--

Merged in EionRobb/pidgin/http-fixes (pull request #413)

Fix HTTP errors from static analysis

Approved-by: Mike Ruprecht <cmaiku@gmail.com>
Approved-by: Gary Kramlich <grim@reaperworld.com>

3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
1 /*
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
2 * purple
17666
9c32c365b852 Pretend that WSAEINPROGRESS is EAGAIN (for our purposes, I think they are equivalent). I think this might help #485. References #485.
Daniel Atallah <datallah@pidgin.im>
parents: 15884
diff changeset
3 *
5913
4d016c00bb36 [gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents: 5474
diff changeset
4 * Copyright (C) 2002-2003, Herman Bloggs <hermanator12002@yahoo.com>
4d016c00bb36 [gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents: 5474
diff changeset
5 *
4d016c00bb36 [gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents: 5474
diff changeset
6 * This program is free software; you can redistribute it and/or modify
4d016c00bb36 [gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents: 5474
diff changeset
7 * it under the terms of the GNU General Public License as published by
4d016c00bb36 [gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents: 5474
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
4d016c00bb36 [gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents: 5474
diff changeset
9 * (at your option) any later version.
4d016c00bb36 [gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents: 5474
diff changeset
10 *
4d016c00bb36 [gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents: 5474
diff changeset
11 * This program is distributed in the hope that it will be useful,
4d016c00bb36 [gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents: 5474
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4d016c00bb36 [gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents: 5474
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4d016c00bb36 [gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents: 5474
diff changeset
14 * GNU General Public License for more details.
4d016c00bb36 [gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents: 5474
diff changeset
15 *
4d016c00bb36 [gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents: 5474
diff changeset
16 * You should have received a copy of the GNU General Public License
4d016c00bb36 [gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents: 5474
diff changeset
17 * along with this program; if not, write to the Free Software
19859
71d37b57eff2 The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 18553
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
5913
4d016c00bb36 [gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents: 5474
diff changeset
19 *
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
20 */
35892
02bf3200b9cb cross-win32: make use of WIN32_LEAN_AND_MEAN define
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35855
diff changeset
21
02bf3200b9cb cross-win32: make use of WIN32_LEAN_AND_MEAN define
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35855
diff changeset
22 #include <config.h>
02bf3200b9cb cross-win32: make use of WIN32_LEAN_AND_MEAN define
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35855
diff changeset
23
8244
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
24 #include <winsock2.h>
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
25 #include <ws2tcpip.h>
3777
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
26 #include <io.h>
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
27 #include <stdlib.h>
3777
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
28 #include <stdio.h>
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
29 #include <errno.h>
3777
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
30 #include <sys/timeb.h>
4905
1464e05926f0 [gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents: 4193
diff changeset
31 #include <sys/stat.h>
3777
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
32 #include <time.h>
10589
4e10236e06d4 [gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents: 9611
diff changeset
33 #include <glib.h>
6425
3e86c949c98a [gaim-migrate @ 6933]
Herman Bloggs <herman@bluedigits.com>
parents: 5913
diff changeset
34 #include "debug.h"
3777
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
35 #include "libc_internal.h"
38688
79304d0f6d43 Fix mingw32 compilation
Daniel Kamil Kozar <dkk089@gmail.com>
parents: 38259
diff changeset
36 #include "util.h"
25333
182125d7b7fc Fix from the QuteCom folks to compile with Glib < 2.8.5 with MSVC. Fixes #7761. Also some minor cleanup from me.
Daniel Atallah <datallah@pidgin.im>
parents: 24843
diff changeset
37 #include <glib/gstdio.h>
38604
9ad76b0d9de7 win32/libc_interface: Add missing util.h include for purple_strequal()
Mike Ruprecht <cmaiku@gmail.com>
parents: 38358
diff changeset
38 #include "util.h"
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
39
29735
f36754cb9828 Win32 build updates
Daniel Atallah <datallah@pidgin.im>
parents: 29491
diff changeset
40 /** This is redefined here because we can't include internal.h */
21771
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
41 #ifdef ENABLE_NLS
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
42 # include <locale.h>
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
43 # include <libintl.h>
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
44 # define _(String) ((const char *)dgettext(PACKAGE, String))
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
45 # ifdef gettext_noop
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
46 # define N_(String) gettext_noop (String)
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
47 # else
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
48 # define N_(String) (String)
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
49 # endif
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
50 #else
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
51 # include <locale.h>
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
52 # define N_(String) (String)
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
53 # ifndef _
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
54 # define _(String) ((const char *)String)
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
55 # endif
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
56 # define ngettext(Singular, Plural, Number) ((Number == 1) ? ((const char *)Singular) : ((const char *)Plural))
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
57 # define dngettext(Domain, Singular, Plural, Number) ((Number == 1) ? ((const char *)Singular) : ((const char *)Plural))
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
58 #endif
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
59
25333
182125d7b7fc Fix from the QuteCom folks to compile with Glib < 2.8.5 with MSVC. Fixes #7761. Also some minor cleanup from me.
Daniel Atallah <datallah@pidgin.im>
parents: 24843
diff changeset
60 #ifndef S_ISDIR
182125d7b7fc Fix from the QuteCom folks to compile with Glib < 2.8.5 with MSVC. Fixes #7761. Also some minor cleanup from me.
Daniel Atallah <datallah@pidgin.im>
parents: 24843
diff changeset
61 # define S_ISDIR(m) (((m)&S_IFDIR)==S_IFDIR)
182125d7b7fc Fix from the QuteCom folks to compile with Glib < 2.8.5 with MSVC. Fixes #7761. Also some minor cleanup from me.
Daniel Atallah <datallah@pidgin.im>
parents: 24843
diff changeset
62 #endif
21771
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
63
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
64 static char errbuf[1024];
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
65
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
66 /* helpers */
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
67 static int wpurple_is_socket( int fd ) {
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
68 int optval;
29797
5cdd3be38077 Warning fixes
Daniel Atallah <datallah@pidgin.im>
parents: 29735
diff changeset
69 int optlen = sizeof(int);
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
70
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
71 if( (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void*)&optval, &optlen)) == SOCKET_ERROR ) {
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
72 int error = WSAGetLastError();
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
73 if( error == WSAENOTSOCK )
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
74 return FALSE;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
75 else {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
76 purple_debug(PURPLE_DEBUG_WARNING, "wpurple", "wpurple_is_socket: getsockopt returned error: %d\n", error);
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
77 return FALSE;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
78 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
79 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
80 return TRUE;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
81 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
82
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
83 /* socket.h */
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
84 int wpurple_socket (int namespace, int style, int protocol) {
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
85 int ret;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
86
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
87 ret = socket( namespace, style, protocol );
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
88
35855
3e60f9385431 cross-win32: libpurple builds now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 33884
diff changeset
89 if (ret == (int)INVALID_SOCKET) {
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
90 errno = WSAGetLastError();
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
91 return -1;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
92 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
93 return ret;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
94 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
95
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
96 int wpurple_connect(int socket, struct sockaddr *addr, u_long length) {
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
97 int ret;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
98
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
99 ret = connect( socket, addr, length );
17666
9c32c365b852 Pretend that WSAEINPROGRESS is EAGAIN (for our purposes, I think they are equivalent). I think this might help #485. References #485.
Daniel Atallah <datallah@pidgin.im>
parents: 15884
diff changeset
100
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
101 if( ret == SOCKET_ERROR ) {
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
102 errno = WSAGetLastError();
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
103 if( errno == WSAEWOULDBLOCK )
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
104 errno = WSAEINPROGRESS;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
105 return -1;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
106 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
107 return 0;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
108 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
109
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
110 int wpurple_getsockopt(int socket, int level, int optname, void *optval, socklen_t *optlenptr) {
8244
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
111 if(getsockopt(socket, level, optname, optval, optlenptr) == SOCKET_ERROR ) {
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
112 errno = WSAGetLastError();
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
113 return -1;
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
114 }
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
115 return 0;
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
116 }
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
117
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
118 int wpurple_setsockopt(int socket, int level, int optname, const void *optval, socklen_t optlen) {
8244
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
119 if(setsockopt(socket, level, optname, optval, optlen) == SOCKET_ERROR ) {
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
120 errno = WSAGetLastError();
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
121 return -1;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
122 }
8244
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
123 return 0;
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
124 }
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
125
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
126 int wpurple_getsockname(int socket, struct sockaddr *addr, socklen_t *lenptr) {
8244
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
127 if(getsockname(socket, addr, lenptr) == SOCKET_ERROR) {
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
128 errno = WSAGetLastError();
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
129 return -1;
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
130 }
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
131 return 0;
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
132 }
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
133
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
134 int wpurple_bind(int socket, struct sockaddr *addr, socklen_t length) {
8244
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
135 if(bind(socket, addr, length) == SOCKET_ERROR) {
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
136 errno = WSAGetLastError();
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
137 return -1;
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
138 }
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
139 return 0;
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
140 }
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
141
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
142 int wpurple_listen(int socket, unsigned int n) {
8244
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
143 if(listen(socket, n) == SOCKET_ERROR) {
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
144 errno = WSAGetLastError();
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
145 return -1;
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
146 }
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
147 return 0;
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
148 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
149
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
150 int wpurple_sendto(int socket, const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen) {
11431
60971f504319 [gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents: 11364
diff changeset
151 int ret;
60971f504319 [gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents: 11364
diff changeset
152 if ((ret = sendto(socket, buf, len, flags, to, tolen)
60971f504319 [gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents: 11364
diff changeset
153 ) == SOCKET_ERROR) {
60971f504319 [gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents: 11364
diff changeset
154 errno = WSAGetLastError();
17666
9c32c365b852 Pretend that WSAEINPROGRESS is EAGAIN (for our purposes, I think they are equivalent). I think this might help #485. References #485.
Daniel Atallah <datallah@pidgin.im>
parents: 15884
diff changeset
155 if(errno == WSAEWOULDBLOCK || errno == WSAEINPROGRESS)
9c32c365b852 Pretend that WSAEINPROGRESS is EAGAIN (for our purposes, I think they are equivalent). I think this might help #485. References #485.
Daniel Atallah <datallah@pidgin.im>
parents: 15884
diff changeset
156 errno = EAGAIN;
11431
60971f504319 [gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents: 11364
diff changeset
157 return -1;
60971f504319 [gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents: 11364
diff changeset
158 }
60971f504319 [gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents: 11364
diff changeset
159 return ret;
60971f504319 [gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents: 11364
diff changeset
160 }
60971f504319 [gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents: 11364
diff changeset
161
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
162 /* fcntl.h */
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
163 /* This is not a full implementation of fcntl. Update as needed.. */
20239
ae122f419324 applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 19859
diff changeset
164 int wpurple_fcntl(int socket, int command, ...) {
ae122f419324 applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 19859
diff changeset
165
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
166 switch( command ) {
20239
ae122f419324 applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 19859
diff changeset
167 case F_GETFL:
ae122f419324 applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 19859
diff changeset
168 return 0;
ae122f419324 applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 19859
diff changeset
169
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
170 case F_SETFL:
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
171 {
20239
ae122f419324 applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 19859
diff changeset
172 va_list args;
ae122f419324 applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 19859
diff changeset
173 int val;
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
174 int ret=0;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
175
20239
ae122f419324 applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 19859
diff changeset
176 va_start(args, command);
ae122f419324 applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 19859
diff changeset
177 val = va_arg(args, int);
ae122f419324 applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 19859
diff changeset
178 va_end(args);
ae122f419324 applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 19859
diff changeset
179
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
180 switch( val ) {
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
181 case O_NONBLOCK:
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
182 {
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
183 u_long imode=1;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
184 ret = ioctlsocket(socket, FIONBIO, &imode);
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
185 break;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
186 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
187 case 0:
20239
ae122f419324 applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents: 19859
diff changeset
188 {
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
189 u_long imode=0;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
190 ret = ioctlsocket(socket, FIONBIO, &imode);
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
191 break;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
192 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
193 default:
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
194 errno = EINVAL;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
195 return -1;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
196 }/*end switch*/
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
197 if( ret == SOCKET_ERROR ) {
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
198 errno = WSAGetLastError();
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
199 return -1;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
200 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
201 return 0;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
202 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
203 default:
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
204 purple_debug(PURPLE_DEBUG_WARNING, "wpurple", "wpurple_fcntl: Unsupported command\n");
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
205 return -1;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
206 }/*end switch*/
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
207 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
208
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
209 /* sys/ioctl.h */
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
210 int wpurple_ioctl(int fd, int command, void* val) {
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
211 switch( command ) {
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
212 case FIONBIO:
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
213 {
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
214 if (ioctlsocket(fd, FIONBIO, (unsigned long *)val) == SOCKET_ERROR) {
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
215 errno = WSAGetLastError();
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
216 return -1;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
217 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
218 return 0;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
219 }
11364
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
220 case SIOCGIFCONF:
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
221 {
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
222 INTERFACE_INFO InterfaceList[20];
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
223 unsigned long nBytesReturned;
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
224 if (WSAIoctl(fd, SIO_GET_INTERFACE_LIST,
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
225 0, 0, &InterfaceList,
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
226 sizeof(InterfaceList), &nBytesReturned,
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
227 0, 0) == SOCKET_ERROR) {
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
228 errno = WSAGetLastError();
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
229 return -1;
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
230 } else {
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
231 int i;
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
232 struct ifconf *ifc = val;
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
233 char *tmp = ifc->ifc_buf;
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
234 int nNumInterfaces =
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
235 nBytesReturned / sizeof(INTERFACE_INFO);
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
236 for (i = 0; i < nNumInterfaces; i++) {
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
237 INTERFACE_INFO ii = InterfaceList[i];
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
238 struct ifreq *ifr = (struct ifreq *) tmp;
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
239 struct sockaddr_in *sa = (struct sockaddr_in *) &ifr->ifr_addr;
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
240
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
241 sa->sin_family = ii.iiAddress.AddressIn.sin_family;
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
242 sa->sin_port = ii.iiAddress.AddressIn.sin_port;
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
243 sa->sin_addr.s_addr = ii.iiAddress.AddressIn.sin_addr.s_addr;
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
244 tmp += sizeof(struct ifreq);
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
245
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
246 /* Make sure that we can fit in the original buffer */
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
247 if (tmp >= (ifc->ifc_buf + ifc->ifc_len + sizeof(struct ifreq))) {
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
248 break;
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
249 }
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
250 }
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
251 /* Replace the length with the actually used length */
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
252 ifc->ifc_len = ifc->ifc_len - (ifc->ifc_buf - tmp);
12488
72878a4bf35a [gaim-migrate @ 14800]
Daniel Atallah <datallah@pidgin.im>
parents: 11543
diff changeset
253 return 0;
11364
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
254 }
d754cf40ec4b [gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents: 10601
diff changeset
255 }
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
256 default:
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
257 errno = EINVAL;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
258 return -1;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
259 }/*end switch*/
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
260 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
261
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
262 /* arpa/inet.h */
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
263 int wpurple_inet_aton(const char *name, struct in_addr *addr) {
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
264 if((addr->s_addr = inet_addr(name)) == INADDR_NONE)
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
265 return 0;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
266 else
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
267 return 1;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
268 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
269
14974
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
270 /* Thanks to GNU wget for this inet_ntop() implementation */
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
271 const char *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
272 wpurple_inet_ntop (int af, const void *src, char *dst, socklen_t cnt)
14974
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
273 {
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
274 /* struct sockaddr can't accomodate struct sockaddr_in6. */
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
275 union {
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
276 struct sockaddr_in6 sin6;
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
277 struct sockaddr_in sin;
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
278 } sa;
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
279 DWORD dstlen = cnt;
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
280 size_t srcsize;
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
281
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
282 ZeroMemory(&sa, sizeof(sa));
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
283 switch (af)
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
284 {
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
285 case AF_INET:
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
286 sa.sin.sin_family = AF_INET;
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
287 sa.sin.sin_addr = *(struct in_addr *) src;
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
288 srcsize = sizeof (sa.sin);
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
289 break;
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
290 case AF_INET6:
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
291 sa.sin6.sin6_family = AF_INET6;
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
292 sa.sin6.sin6_addr = *(struct in6_addr *) src;
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
293 srcsize = sizeof (sa.sin6);
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
294 break;
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
295 default:
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
296 abort ();
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
297 }
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
298
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
299 if (WSAAddressToString ((struct sockaddr *) &sa, srcsize, NULL, dst, &dstlen) != 0)
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
300 {
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
301 errno = WSAGetLastError();
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
302 return NULL;
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
303 }
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
304 return (const char *) dst;
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
305 }
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
306
32069
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
307 int
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
308 wpurple_inet_pton(int af, const char *src, void *dst)
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
309 {
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
310 /* struct sockaddr can't accomodate struct sockaddr_in6. */
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
311 union {
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
312 struct sockaddr_in6 sin6;
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
313 struct sockaddr_in sin;
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
314 } sa;
33884
3fd1628aa718 Fixing warnings (win32, glib, others)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 32744
diff changeset
315 int srcsize;
32069
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
316
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
317 switch(af)
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
318 {
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
319 case AF_INET:
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
320 sa.sin.sin_family = AF_INET;
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
321 srcsize = sizeof (sa.sin);
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
322 break;
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
323 case AF_INET6:
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
324 sa.sin6.sin6_family = AF_INET6;
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
325 srcsize = sizeof (sa.sin6);
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
326 break;
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
327 default:
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
328 errno = WSAEPFNOSUPPORT;
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
329 return -1;
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
330 }
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
331
33884
3fd1628aa718 Fixing warnings (win32, glib, others)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents: 32744
diff changeset
332 if (WSAStringToAddress((LPTSTR)src, af, NULL, (struct sockaddr *) &sa, &srcsize) != 0)
32069
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
333 {
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
334 errno = WSAGetLastError();
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
335 return -1;
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
336 }
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
337
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
338 switch(af)
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
339 {
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
340 case AF_INET:
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
341 memcpy(dst, &sa.sin.sin_addr, sizeof(sa.sin.sin_addr));
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
342 break;
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
343 case AF_INET6:
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
344 memcpy(dst, &sa.sin6.sin6_addr, sizeof(sa.sin6.sin6_addr));
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
345 break;
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
346 }
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
347
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
348 return 1;
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
349 }
fc06dd6b7c3f Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents: 31957
diff changeset
350
14974
8180f0f2e20c [gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents: 14286
diff changeset
351
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
352 /* netdb.h */
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
353 struct hostent* wpurple_gethostbyname(const char *name) {
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
354 struct hostent *hp;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
355
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
356 if((hp = gethostbyname(name)) == NULL) {
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
357 errno = WSAGetLastError();
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
358 return NULL;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
359 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
360 return hp;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
361 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
362
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
363 /* string.h */
21771
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
364 char* wpurple_strerror(int errornum) {
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
365 if (errornum > WSABASEERR) {
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
366 switch(errornum) {
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
367 case WSAECONNABORTED: /* 10053 */
30792
155b65d26118 Fix some cases where an arbitrary string was being specified as a printf format.
Daniel Atallah <datallah@pidgin.im>
parents: 29797
diff changeset
368 g_snprintf(errbuf, sizeof(errbuf), "%s", _("Connection interrupted by other software on your computer."));
22641
c5e5a10e4799 I was wondering why the more sane error messges were never appearing... now I know. There is also a fix here that uses glib's internal rename stuff on recent versions because it is more robust than our win32 version.
Daniel Atallah <datallah@pidgin.im>
parents: 21771
diff changeset
369 break;
21771
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
370 case WSAECONNRESET: /* 10054 */
30792
155b65d26118 Fix some cases where an arbitrary string was being specified as a printf format.
Daniel Atallah <datallah@pidgin.im>
parents: 29797
diff changeset
371 g_snprintf(errbuf, sizeof(errbuf), "%s", _("Remote host closed connection."));
22641
c5e5a10e4799 I was wondering why the more sane error messges were never appearing... now I know. There is also a fix here that uses glib's internal rename stuff on recent versions because it is more robust than our win32 version.
Daniel Atallah <datallah@pidgin.im>
parents: 21771
diff changeset
372 break;
21771
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
373 case WSAETIMEDOUT: /* 10060 */
30792
155b65d26118 Fix some cases where an arbitrary string was being specified as a printf format.
Daniel Atallah <datallah@pidgin.im>
parents: 29797
diff changeset
374 g_snprintf(errbuf, sizeof(errbuf), "%s", _("Connection timed out."));
22641
c5e5a10e4799 I was wondering why the more sane error messges were never appearing... now I know. There is also a fix here that uses glib's internal rename stuff on recent versions because it is more robust than our win32 version.
Daniel Atallah <datallah@pidgin.im>
parents: 21771
diff changeset
375 break;
23883
222e2f637efd Fix running several Bonjour instances on the same machine.
Daniel Atallah <datallah@pidgin.im>
parents: 22871
diff changeset
376 case WSAECONNREFUSED: /* 10061 */
30792
155b65d26118 Fix some cases where an arbitrary string was being specified as a printf format.
Daniel Atallah <datallah@pidgin.im>
parents: 29797
diff changeset
377 g_snprintf(errbuf, sizeof(errbuf), "%s", _("Connection refused."));
22641
c5e5a10e4799 I was wondering why the more sane error messges were never appearing... now I know. There is also a fix here that uses glib's internal rename stuff on recent versions because it is more robust than our win32 version.
Daniel Atallah <datallah@pidgin.im>
parents: 21771
diff changeset
378 break;
23883
222e2f637efd Fix running several Bonjour instances on the same machine.
Daniel Atallah <datallah@pidgin.im>
parents: 22871
diff changeset
379 case WSAEADDRINUSE: /* 10048 */
30792
155b65d26118 Fix some cases where an arbitrary string was being specified as a printf format.
Daniel Atallah <datallah@pidgin.im>
parents: 29797
diff changeset
380 g_snprintf(errbuf, sizeof(errbuf), "%s", _("Address already in use."));
23883
222e2f637efd Fix running several Bonjour instances on the same machine.
Daniel Atallah <datallah@pidgin.im>
parents: 22871
diff changeset
381 break;
21771
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
382 default:
22871
a5ba9f9d340a Use g_snprintf() instead of snprintf(), which isn't really available on
Daniel Atallah <datallah@pidgin.im>
parents: 22641
diff changeset
383 g_snprintf(errbuf, sizeof(errbuf), "Windows socket error #%d", errornum);
21771
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
384 }
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
385 } else {
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
386 const char *tmp = g_strerror(errornum);
30792
155b65d26118 Fix some cases where an arbitrary string was being specified as a printf format.
Daniel Atallah <datallah@pidgin.im>
parents: 29797
diff changeset
387 g_snprintf(errbuf, sizeof(errbuf), "%s", tmp);
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
388 }
21771
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
389 return errbuf;
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
390 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
391
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
392 /* unistd.h */
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
393
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
394 /*
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
395 * We need to figure out whether fd is a file or socket handle.
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
396 */
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
397 int wpurple_read(int fd, void *buf, unsigned int size) {
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
398 int ret;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
399
24843
ab68c6d3c247 (Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents: 23883
diff changeset
400 if (fd < 0) {
ab68c6d3c247 (Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents: 23883
diff changeset
401 errno = EBADF;
ab68c6d3c247 (Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents: 23883
diff changeset
402 g_return_val_if_reached(-1);
ab68c6d3c247 (Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents: 23883
diff changeset
403 }
ab68c6d3c247 (Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents: 23883
diff changeset
404
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
405 if(wpurple_is_socket(fd)) {
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 12749
diff changeset
406 if((ret = recv(fd, buf, size, 0)) == SOCKET_ERROR) {
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
407 errno = WSAGetLastError();
17666
9c32c365b852 Pretend that WSAEINPROGRESS is EAGAIN (for our purposes, I think they are equivalent). I think this might help #485. References #485.
Daniel Atallah <datallah@pidgin.im>
parents: 15884
diff changeset
408 if(errno == WSAEWOULDBLOCK || errno == WSAEINPROGRESS)
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 12749
diff changeset
409 errno = EAGAIN;
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
410 return -1;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
411 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
412 else {
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
413 /* success reading socket */
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
414 return ret;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
415 }
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 12749
diff changeset
416 } else {
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
417 /* fd is not a socket handle.. pass it off to read */
22871
a5ba9f9d340a Use g_snprintf() instead of snprintf(), which isn't really available on
Daniel Atallah <datallah@pidgin.im>
parents: 22641
diff changeset
418 return _read(fd, buf, size);
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
419 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
420 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
421
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
422 int wpurple_send(int fd, const void *buf, unsigned int size, int flags) {
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
423 int ret;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
424
13780
f642a0729daa [gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents: 13371
diff changeset
425 ret = send(fd, buf, size, flags);
f642a0729daa [gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents: 13371
diff changeset
426
f642a0729daa [gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents: 13371
diff changeset
427 if (ret == SOCKET_ERROR) {
f642a0729daa [gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents: 13371
diff changeset
428 errno = WSAGetLastError();
17666
9c32c365b852 Pretend that WSAEINPROGRESS is EAGAIN (for our purposes, I think they are equivalent). I think this might help #485. References #485.
Daniel Atallah <datallah@pidgin.im>
parents: 15884
diff changeset
429 if(errno == WSAEWOULDBLOCK || errno == WSAEINPROGRESS)
13780
f642a0729daa [gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents: 13371
diff changeset
430 errno = EAGAIN;
f642a0729daa [gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents: 13371
diff changeset
431 return -1;
f642a0729daa [gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents: 13371
diff changeset
432 }
f642a0729daa [gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents: 13371
diff changeset
433 return ret;
f642a0729daa [gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents: 13371
diff changeset
434 }
f642a0729daa [gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents: 13371
diff changeset
435
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
436 int wpurple_write(int fd, const void *buf, unsigned int size) {
13780
f642a0729daa [gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents: 13371
diff changeset
437
24843
ab68c6d3c247 (Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents: 23883
diff changeset
438 if (fd < 0) {
ab68c6d3c247 (Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents: 23883
diff changeset
439 errno = EBADF;
ab68c6d3c247 (Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents: 23883
diff changeset
440 g_return_val_if_reached(-1);
ab68c6d3c247 (Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents: 23883
diff changeset
441 }
ab68c6d3c247 (Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents: 23883
diff changeset
442
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
443 if(wpurple_is_socket(fd))
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
444 return wpurple_send(fd, buf, size, 0);
13780
f642a0729daa [gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents: 13371
diff changeset
445 else
22871
a5ba9f9d340a Use g_snprintf() instead of snprintf(), which isn't really available on
Daniel Atallah <datallah@pidgin.im>
parents: 22641
diff changeset
446 return _write(fd, buf, size);
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
447 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
448
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
449 int wpurple_recv(int fd, void *buf, size_t len, int flags) {
12749
704b51d5007a [gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents: 12488
diff changeset
450 int ret;
704b51d5007a [gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents: 12488
diff changeset
451
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 12749
diff changeset
452 if((ret = recv(fd, buf, len, flags)) == SOCKET_ERROR) {
12749
704b51d5007a [gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents: 12488
diff changeset
453 errno = WSAGetLastError();
17666
9c32c365b852 Pretend that WSAEINPROGRESS is EAGAIN (for our purposes, I think they are equivalent). I think this might help #485. References #485.
Daniel Atallah <datallah@pidgin.im>
parents: 15884
diff changeset
454 if(errno == WSAEWOULDBLOCK || errno == WSAEINPROGRESS)
13201
8c224ef70efa [gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents: 12749
diff changeset
455 errno = EAGAIN;
12749
704b51d5007a [gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents: 12488
diff changeset
456 return -1;
704b51d5007a [gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents: 12488
diff changeset
457 } else {
704b51d5007a [gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents: 12488
diff changeset
458 return ret;
704b51d5007a [gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents: 12488
diff changeset
459 }
704b51d5007a [gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents: 12488
diff changeset
460 }
704b51d5007a [gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents: 12488
diff changeset
461
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
462 int wpurple_close(int fd) {
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
463 int ret;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
464
24843
ab68c6d3c247 (Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents: 23883
diff changeset
465 if (fd < 0) {
ab68c6d3c247 (Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents: 23883
diff changeset
466 errno = EBADF;
ab68c6d3c247 (Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents: 23883
diff changeset
467 g_return_val_if_reached(-1);
ab68c6d3c247 (Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents: 23883
diff changeset
468 }
ab68c6d3c247 (Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents: 23883
diff changeset
469
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
470 if( wpurple_is_socket(fd) ) {
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
471 if( (ret = closesocket(fd)) == SOCKET_ERROR ) {
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
472 errno = WSAGetLastError();
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
473 return -1;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
474 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
475 else
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
476 return 0;
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
477 }
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
478 else
22871
a5ba9f9d340a Use g_snprintf() instead of snprintf(), which isn't really available on
Daniel Atallah <datallah@pidgin.im>
parents: 22641
diff changeset
479 return _close(fd);
3712
d926a65b5f89 [gaim-migrate @ 3845]
Herman Bloggs <herman@bluedigits.com>
parents:
diff changeset
480 }
3777
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
481
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
482 int wpurple_gethostname(char *name, size_t size) {
8244
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
483 if(gethostname(name, size) == SOCKET_ERROR) {
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
484 errno = WSAGetLastError();
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
485 return -1;
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
486 }
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
487 return 0;
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
488 }
014ff38feea9 [gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents: 6425
diff changeset
489
3777
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
490 /* sys/time.h */
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
491
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
492 int wpurple_gettimeofday(struct timeval *p, struct timezone *z) {
3777
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
493 int res = 0;
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
494 struct _timeb timebuffer;
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
495
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
496 if (z != 0) {
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
497 _tzset();
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
498 z->tz_minuteswest = _timezone/60;
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
499 z->tz_dsttime = _daylight;
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
500 }
17666
9c32c365b852 Pretend that WSAEINPROGRESS is EAGAIN (for our purposes, I think they are equivalent). I think this might help #485. References #485.
Daniel Atallah <datallah@pidgin.im>
parents: 15884
diff changeset
501
3777
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
502 if (p != 0) {
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
503 _ftime(&timebuffer);
21771
0df7285a6164 Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents: 21635
diff changeset
504 p->tv_sec = timebuffer.time; /* seconds since 1-1-1970 */
3777
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
505 p->tv_usec = timebuffer.millitm*1000; /* microseconds */
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
506 }
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
507
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
508 return res;
a3f8adc4c3e0 [gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents: 3712
diff changeset
509 }
4905
1464e05926f0 [gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents: 4193
diff changeset
510
5113
8e545faf3d80 [gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents: 5084
diff changeset
511 /* time.h */
8e545faf3d80 [gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents: 5084
diff changeset
512
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
513 struct tm * wpurple_localtime_r (const time_t *time, struct tm *resultp) {
5113
8e545faf3d80 [gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents: 5084
diff changeset
514 struct tm* tmptm;
8e545faf3d80 [gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents: 5084
diff changeset
515
5474
eec4dad3e035 [gaim-migrate @ 5868]
Herman Bloggs <herman@bluedigits.com>
parents: 5113
diff changeset
516 if(!time)
5913
4d016c00bb36 [gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents: 5474
diff changeset
517 return NULL;
5113
8e545faf3d80 [gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents: 5084
diff changeset
518 tmptm = localtime(time);
8e545faf3d80 [gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents: 5084
diff changeset
519 if(resultp && tmptm)
8e545faf3d80 [gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents: 5084
diff changeset
520 return memcpy(resultp, tmptm, sizeof(struct tm));
8e545faf3d80 [gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents: 5084
diff changeset
521 else
8e545faf3d80 [gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents: 5084
diff changeset
522 return NULL;
8e545faf3d80 [gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents: 5084
diff changeset
523 }
13334
d0d48650f114 [gaim-migrate @ 15703]
Richard Laager <rlaager@pidgin.im>
parents: 13201
diff changeset
524

mercurial