comparison src/html.c @ 3630:9682c0e022c6

[gaim-migrate @ 3753] Yeah this will probably break a lot of shit knowing my luck. But hey, I really don't care what people thnk. committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Fri, 11 Oct 2002 03:14:01 +0000
parents dd78d89c910b
children 988485669631
comparison
equal deleted inserted replaced
3629:afc5bb164c5a 3630:9682c0e022c6
23 #include <config.h> 23 #include <config.h>
24 #endif 24 #endif
25 #include <string.h> 25 #include <string.h>
26 #include <stdio.h> 26 #include <stdio.h>
27 #include <stdlib.h> 27 #include <stdlib.h>
28
29 #ifndef _WIN32
28 #include <sys/time.h> 30 #include <sys/time.h>
29 #include <unistd.h> 31 #include <unistd.h>
30 #include "gaim.h"
31 #include <sys/types.h>
32 #include <sys/socket.h> 32 #include <sys/socket.h>
33 #include <netdb.h> 33 #include <netdb.h>
34 #include <netinet/in.h> 34 #include <netinet/in.h>
35 #else
36 #include <winsock.h>
37 #include <io.h>
38 #endif
39
40 #include <sys/types.h>
35 #include <fcntl.h> 41 #include <fcntl.h>
36 #include <errno.h> 42 #include <errno.h>
43 #include "gaim.h"
37 #include "proxy.h" 44 #include "proxy.h"
38
39 struct g_url {
40 char address[255];
41 int port;
42 char page[255];
43 };
44 45
45 gchar *strip_html(gchar *text) 46 gchar *strip_html(gchar *text)
46 { 47 {
47 int i, j, k; 48 int i, j, k;
48 int visible = 1; 49 int visible = 1;
72 } 73 }
73 text2[j] = '\0'; 74 text2[j] = '\0';
74 return text2; 75 return text2;
75 } 76 }
76 77
77 static struct g_url *parse_url(char *url) 78 struct g_url *parse_url(char *url)
78 { 79 {
79 struct g_url *test = g_new0(struct g_url, 1); 80 struct g_url *test = g_new0(struct g_url, 1);
80 char scan_info[255]; 81 char scan_info[255];
81 char port[5]; 82 char port[5];
82 int f; 83 int f;
141 return; 142 return;
142 } 143 }
143 144
144 if (!gunk->sentreq) { 145 if (!gunk->sentreq) {
145 char buf[256]; 146 char buf[256];
147 #ifdef _WIN32
148 int imode=1;
149 #endif
146 g_snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\r\n\r\n", gunk->full ? "" : "/", 150 g_snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\r\n\r\n", gunk->full ? "" : "/",
147 gunk->full ? gunk->url : gunk->website->page); 151 gunk->full ? gunk->url : gunk->website->page);
148 debug_printf("Request: %s\n", buf); 152 debug_printf("Request: %s\n", buf);
153 #ifdef _WIN32
154 send(sock, buf, strlen(buf), 0);
155 ioctlsocket(sock, FIONBIO, (unsigned long *)&imode);
156 #else
149 write(sock, buf, strlen(buf)); 157 write(sock, buf, strlen(buf));
150 fcntl(sock, F_SETFL, O_NONBLOCK); 158 fcntl(sock, F_SETFL, O_NONBLOCK);
159 #endif
151 gunk->sentreq = TRUE; 160 gunk->sentreq = TRUE;
152 gunk->inpa = gaim_input_add(sock, GAIM_INPUT_READ, grab_url_callback, dat); 161 gunk->inpa = gaim_input_add(sock, GAIM_INPUT_READ, grab_url_callback, dat);
153 return; 162 return;
154 } 163 }
155 164
165 #ifdef _WIN32
166 if (recv(sock, &data, 1, 0) > 0 || WSAEWOULDBLOCK == WSAGetLastError()) {
167 if (WSAEWOULDBLOCK == WSAGetLastError()) {
168 WSASetLastError(0);
169 return;
170 }
171 #else
156 if (read(sock, &data, 1) > 0 || errno == EWOULDBLOCK) { 172 if (read(sock, &data, 1) > 0 || errno == EWOULDBLOCK) {
157 if (errno == EWOULDBLOCK) { 173 if (errno == EWOULDBLOCK) {
158 errno = 0; 174 errno = 0;
159 return; 175 return;
160 } 176 }
161 177 #endif
162 if (!gunk->startsaving) { 178 if (!gunk->startsaving) {
163 if (data == '\r') 179 if (data == '\r')
164 return; 180 return;
165 if (data == '\n') { 181 if (data == '\n') {
166 if (gunk->newline) 182 if (gunk->newline)
173 } else { 189 } else {
174 gunk->len++; 190 gunk->len++;
175 gunk->webdata = g_realloc(gunk->webdata, gunk->len); 191 gunk->webdata = g_realloc(gunk->webdata, gunk->len);
176 gunk->webdata[gunk->len - 1] = data; 192 gunk->webdata[gunk->len - 1] = data;
177 } 193 }
194 #ifdef _WIN32
195 } else if (WSAETIMEDOUT == WSAGetLastError()) {
196 #else
178 } else if (errno != ETIMEDOUT) { 197 } else if (errno != ETIMEDOUT) {
179 198 #endif
180 gunk->webdata = g_realloc(gunk->webdata, gunk->len + 1); 199 gunk->webdata = g_realloc(gunk->webdata, gunk->len + 1);
181 gunk->webdata[gunk->len] = 0; 200 gunk->webdata[gunk->len] = 0;
182 201
183 debug_printf(_("Received: '%s'\n"), gunk->webdata); 202 debug_printf(_("Received: '%s'\n"), gunk->webdata);
184 203
185 gaim_input_remove(gunk->inpa); 204 gaim_input_remove(gunk->inpa);
205 #ifdef _WIN32
206 closesocket(sock);
207 #else
186 close(sock); 208 close(sock);
209 #endif
187 gunk->callback(gunk->data, gunk->webdata); 210 gunk->callback(gunk->data, gunk->webdata);
188 if (gunk->webdata) 211 if (gunk->webdata)
189 g_free(gunk->webdata); 212 g_free(gunk->webdata);
190 g_free(gunk->website); 213 g_free(gunk->website);
191 g_free(gunk->url); 214 g_free(gunk->url);
192 g_free(gunk); 215 g_free(gunk);
193 } else { 216 } else {
194 gaim_input_remove(gunk->inpa); 217 gaim_input_remove(gunk->inpa);
218 #ifdef _WIN32
219 closesocket(sock);
220 #else
195 close(sock); 221 close(sock);
222 #endif
196 gunk->callback(gunk->data, NULL); 223 gunk->callback(gunk->data, NULL);
197 if (gunk->webdata) 224 if (gunk->webdata)
198 g_free(gunk->webdata); 225 g_free(gunk->webdata);
199 g_free(gunk->website); 226 g_free(gunk->website);
200 g_free(gunk->url); 227 g_free(gunk->url);