Mercurial > pidgin
comparison src/html.c @ 2584:34812d648f72
[gaim-migrate @ 2597]
heh. this was pointless.
committer: Tailor Script <tailor@pidgin.im>
| author | Eric Warmenhoven <eric@warmenhoven.org> |
|---|---|
| date | Tue, 23 Oct 2001 08:06:09 +0000 |
| parents | 8229710b343b |
| children | b0c5770156e1 |
comparison
equal
deleted
inserted
replaced
| 2583:ce3df2c43f46 | 2584:34812d648f72 |
|---|---|
| 115 struct grab_url_data { | 115 struct grab_url_data { |
| 116 void (*callback)(gpointer, char *); | 116 void (*callback)(gpointer, char *); |
| 117 gpointer data; | 117 gpointer data; |
| 118 struct g_url *website; | 118 struct g_url *website; |
| 119 char *url; | 119 char *url; |
| 120 gboolean full; | |
| 120 | 121 |
| 121 int inpa; | 122 int inpa; |
| 122 | 123 |
| 123 gboolean sentreq; | 124 gboolean sentreq; |
| 125 gboolean newline; | |
| 126 gboolean startsaving; | |
| 124 char *webdata; | 127 char *webdata; |
| 125 int len; | 128 int len; |
| 126 gboolean startsaving; | |
| 127 }; | 129 }; |
| 128 | 130 |
| 129 static void grab_url_callback(gpointer dat, gint sock, GaimInputCondition cond) | 131 static void grab_url_callback(gpointer dat, gint sock, GaimInputCondition cond) |
| 130 { | 132 { |
| 131 struct grab_url_data *gunk = dat; | 133 struct grab_url_data *gunk = dat; |
| 139 return; | 141 return; |
| 140 } | 142 } |
| 141 | 143 |
| 142 if (!gunk->sentreq) { | 144 if (!gunk->sentreq) { |
| 143 char buf[256]; | 145 char buf[256]; |
| 144 g_snprintf(buf, sizeof(buf), "GET /%s HTTP/1.0\r\n\r\n", gunk->website->page); | 146 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); | |
| 145 debug_printf("Request: %s\n", buf); | 148 debug_printf("Request: %s\n", buf); |
| 146 write(sock, buf, strlen(buf)); | 149 write(sock, buf, strlen(buf)); |
| 147 fcntl(sock, F_SETFL, O_NONBLOCK); | 150 fcntl(sock, F_SETFL, O_NONBLOCK); |
| 148 gunk->sentreq = TRUE; | 151 gunk->sentreq = TRUE; |
| 149 gunk->inpa = gaim_input_add(sock, GAIM_INPUT_READ, grab_url_callback, dat); | 152 gunk->inpa = gaim_input_add(sock, GAIM_INPUT_READ, grab_url_callback, dat); |
| 154 if (errno == EWOULDBLOCK) { | 157 if (errno == EWOULDBLOCK) { |
| 155 errno = 0; | 158 errno = 0; |
| 156 return; | 159 return; |
| 157 } | 160 } |
| 158 | 161 |
| 159 if (!gunk->startsaving && data == '<') { | 162 if (!gunk->startsaving) { |
| 160 if (gunk->webdata) | 163 if (data == '\r') |
| 161 g_free(gunk->webdata); | 164 return; |
| 162 gunk->webdata = NULL; | 165 if (data == '\n') { |
| 163 gunk->len = 0; | 166 if (gunk->newline) |
| 164 gunk->startsaving = 1; | 167 gunk->startsaving = TRUE; |
| 165 } | 168 else |
| 166 | 169 gunk->newline = TRUE; |
| 167 gunk->len++; | 170 return; |
| 168 gunk->webdata = g_realloc(gunk->webdata, gunk->len); | 171 } |
| 169 gunk->webdata[gunk->len - 1] = data; | 172 gunk->newline = FALSE; |
| 173 } else { | |
| 174 gunk->len++; | |
| 175 gunk->webdata = g_realloc(gunk->webdata, gunk->len); | |
| 176 gunk->webdata[gunk->len - 1] = data; | |
| 177 } | |
| 170 } else if (errno != ETIMEDOUT) { | 178 } else if (errno != ETIMEDOUT) { |
| 171 | 179 |
| 172 gunk->webdata = g_realloc(gunk->webdata, gunk->len + 1); | 180 gunk->webdata = g_realloc(gunk->webdata, gunk->len + 1); |
| 173 gunk->webdata[gunk->len] = 0; | 181 gunk->webdata[gunk->len] = 0; |
| 174 | 182 |
| 192 g_free(gunk->url); | 200 g_free(gunk->url); |
| 193 g_free(gunk); | 201 g_free(gunk); |
| 194 } | 202 } |
| 195 } | 203 } |
| 196 | 204 |
| 197 void grab_url(char *url, void (*callback)(gpointer, char *), gpointer data) | 205 void grab_url(char *url, gboolean full, void (*callback)(gpointer, char *), gpointer data) |
| 198 { | 206 { |
| 199 int sock; | 207 int sock; |
| 200 struct grab_url_data *gunk = g_new0(struct grab_url_data, 1); | 208 struct grab_url_data *gunk = g_new0(struct grab_url_data, 1); |
| 201 | 209 |
| 202 gunk->callback = callback; | 210 gunk->callback = callback; |
| 203 gunk->data = data; | 211 gunk->data = data; |
| 204 gunk->url = g_strdup(url); | 212 gunk->url = g_strdup(url); |
| 205 gunk->website = parse_url(url); | 213 gunk->website = parse_url(url); |
| 214 gunk->full = full; | |
| 206 | 215 |
| 207 if ((sock = proxy_connect(gunk->website->address, gunk->website->port, | 216 if ((sock = proxy_connect(gunk->website->address, gunk->website->port, |
| 208 grab_url_callback, gunk)) < 0) { | 217 grab_url_callback, gunk)) < 0) { |
| 209 g_free(gunk->website); | 218 g_free(gunk->website); |
| 210 g_free(gunk->url); | 219 g_free(gunk->url); |
