Mercurial > pidgin.yaz
annotate src/win32/libc_interface.c @ 4075:2221f6801577
[gaim-migrate @ 4290]
Most of this is changing offline message parsing so it uses the channel 4
ICBM code, since it's basically the same. This fixes the receiving of
offline URLs.
I also added handling for those pager/web message thingies, and partial
support for email messages. I would finish it, but I can't get stupid
ICQ to email me any more.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 14 Dec 2002 22:48:38 +0000 |
parents | 10ffafd1c91f |
children | c297b9d4f67c |
rev | line source |
---|---|
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
1 /* |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
2 * libc_interface.c |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
3 * |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
4 * Author: Herman Bloggs <hermanator12002@yahoo.com> |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
5 * Date: October 14, 2002 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
6 * Description: Commonly used libc routines. |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
7 */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
8 #include <winsock.h> |
3777
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
9 #include <io.h> |
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
10 #include <stdlib.h> |
3777
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
11 #include <stdio.h> |
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
12 #include <errno.h> |
3777
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
13 #include <sys/timeb.h> |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
14 #include <time.h> |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
15 #include "libc_internal.h" |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
16 |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
17 /* |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
18 * PROTOS |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
19 */ |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
20 extern void debug_printf(char * fmt, ...); |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
21 |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
22 /* |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
23 * LOCALS |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
24 */ |
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
25 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
26 static char errbuf[1024]; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
27 |
3777
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
28 /* |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
29 * CODE |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
30 */ |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
31 |
3712
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
32 /* helpers */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
33 static int wgaim_is_socket( int fd ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
34 int optval; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
35 unsigned int optlen = sizeof(int); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
36 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
37 if( (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void*)&optval, &optlen)) == SOCKET_ERROR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
38 int error = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
39 if( error == WSAENOTSOCK ) |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
40 return FALSE; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
41 else { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
42 debug_printf("wgaim_read: getsockopt returned error: %d\n", error); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
43 return FALSE; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
44 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
45 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
46 return TRUE; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
47 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
48 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
49 /* socket.h */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
50 int wgaim_socket (int namespace, int style, int protocol) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
51 int ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
52 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
53 ret = socket( namespace, style, protocol ); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
54 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
55 if( ret == INVALID_SOCKET ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
56 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
57 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
58 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
59 return ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
60 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
61 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
62 int wgaim_connect(int socket, struct sockaddr *addr, u_long length) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
63 int ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
64 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
65 ret = connect( socket, addr, length ); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
66 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
67 if( ret == SOCKET_ERROR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
68 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
69 if( errno == WSAEWOULDBLOCK ) |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
70 errno = WSAEINPROGRESS; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
71 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
72 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
73 return 0; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
74 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
75 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
76 int wgaim_getsockopt(int socket, int level, int optname, void *optval, unsigned int *optlenptr) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
77 int ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
78 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
79 ret = getsockopt( socket, level, optname, optval, optlenptr ); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
80 if( ret == SOCKET_ERROR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
81 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
82 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
83 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
84 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
85 return 0; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
86 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
87 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
88 /* fcntl.h */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
89 /* This is not a full implementation of fcntl. Update as needed.. */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
90 int wgaim_fcntl(int socket, int command, int val) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
91 switch( command ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
92 case F_SETFL: |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
93 { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
94 int ret=0; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
95 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
96 switch( val ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
97 case O_NONBLOCK: |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
98 { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
99 u_long imode=1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
100 ret = ioctlsocket(socket, FIONBIO, &imode); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
101 break; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
102 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
103 case 0: |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
104 { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
105 u_long imode=0; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
106 ret = ioctlsocket(socket, FIONBIO, &imode); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
107 break; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
108 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
109 default: |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
110 errno = EINVAL; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
111 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
112 }/*end switch*/ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
113 if( ret == SOCKET_ERROR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
114 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
115 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
116 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
117 return 0; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
118 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
119 default: |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
120 debug_printf("wgaim_fcntl: Unsupported command\n"); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
121 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
122 }/*end switch*/ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
123 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
124 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
125 /* sys/ioctl.h */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
126 int wgaim_ioctl(int fd, int command, void* val) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
127 switch( command ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
128 case FIONBIO: |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
129 { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
130 if (ioctlsocket(fd, FIONBIO, (unsigned long *)val) == SOCKET_ERROR) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
131 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
132 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
133 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
134 return 0; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
135 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
136 default: |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
137 errno = EINVAL; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
138 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
139 }/*end switch*/ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
140 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
141 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
142 /* arpa/inet.h */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
143 int wgaim_inet_aton(const char *name, struct in_addr *addr) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
144 if((addr->s_addr = inet_addr(name)) == INADDR_NONE) |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
145 return 0; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
146 else |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
147 return 1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
148 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
149 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
150 /* netdb.h */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
151 struct hostent* wgaim_gethostbyname(const char *name) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
152 struct hostent *hp; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
153 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
154 if((hp = gethostbyname(name)) == NULL) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
155 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
156 return NULL; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
157 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
158 return hp; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
159 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
160 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
161 /* string.h */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
162 char* wgaim_strerror( int errornum ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
163 if( errornum > WSABASEERR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
164 sprintf( errbuf, "Windows socket error #%d", errornum ); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
165 return errbuf; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
166 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
167 else |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
168 return strerror( errornum ); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
169 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
170 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
171 /* unistd.h */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
172 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
173 /* |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
174 * We need to figure out whether fd is a file or socket handle. |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
175 */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
176 int wgaim_read(int fd, void *buf, unsigned int size) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
177 int ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
178 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
179 if( wgaim_is_socket(fd) ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
180 if( (ret = recv(fd, buf, size, 0)) == SOCKET_ERROR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
181 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
182 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
183 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
184 else if( ret == 0 ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
185 /* connection has been gracefully closed */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
186 errno = WSAENOTCONN; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
187 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
188 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
189 else { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
190 /* success reading socket */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
191 return ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
192 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
193 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
194 else { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
195 /* fd is not a socket handle.. pass it off to read */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
196 return read(fd, buf, size); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
197 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
198 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
199 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
200 int wgaim_write(int fd, const void *buf, unsigned int size) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
201 int ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
202 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
203 if( wgaim_is_socket(fd) ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
204 if( (ret = send(fd, buf, size, 0)) == SOCKET_ERROR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
205 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
206 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
207 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
208 else { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
209 /* success */ |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
210 return ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
211 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
212 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
213 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
214 else |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
215 return write(fd, buf, size); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
216 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
217 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
218 int wgaim_close(int fd) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
219 int ret; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
220 |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
221 if( wgaim_is_socket(fd) ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
222 if( (ret = closesocket(fd)) == SOCKET_ERROR ) { |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
223 errno = WSAGetLastError(); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
224 return -1; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
225 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
226 else |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
227 return 0; |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
228 } |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
229 else |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
230 return close(fd); |
ac6ca3890c53
[gaim-migrate @ 3845]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
diff
changeset
|
231 } |
3777
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
232 |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
233 /* sys/time.h */ |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
234 |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
235 int wgaim_gettimeofday(struct timeval *p, struct timezone *z) { |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
236 int res = 0; |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
237 struct _timeb timebuffer; |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
238 |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
239 if (z != 0) { |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
240 _tzset(); |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
241 z->tz_minuteswest = _timezone/60; |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
242 z->tz_dsttime = _daylight; |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
243 } |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
244 |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
245 if (p != 0) { |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
246 _ftime(&timebuffer); |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
247 p->tv_sec = timebuffer.time; /* seconds since 1-1-1970 */ |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
248 p->tv_usec = timebuffer.millitm*1000; /* microseconds */ |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
249 } |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
250 |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
251 return res; |
10ffafd1c91f
[gaim-migrate @ 3917]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
3712
diff
changeset
|
252 } |