| 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); |