Mercurial > pidgin.yaz
comparison src/util.c @ 14082:426a98fa4527
[gaim-migrate @ 16703]
Don't use the same callback for both gaim_proxy_connect() and
gaim_input_add(). Aside from being a little confusing, it's
hindering some changes I want to make to gaim_proxy_connect().
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 11 Aug 2006 07:15:39 +0000 |
parents | 5e6d4c36630a |
children | 10e8eb6a4910 |
comparison
equal
deleted
inserted
replaced
14081:dee8540be099 | 14082:426a98fa4527 |
---|---|
3200 return content_len; | 3200 return content_len; |
3201 } | 3201 } |
3202 | 3202 |
3203 | 3203 |
3204 static void | 3204 static void |
3205 url_fetched_cb(gpointer url_data, gint sock, GaimInputCondition cond) | 3205 url_fetch_recv_cb(gpointer url_data, gint source, GaimInputCondition cond) |
3206 { | 3206 { |
3207 GaimFetchUrlData *gfud = url_data; | 3207 GaimFetchUrlData *gfud = url_data; |
3208 int len; | 3208 int len; |
3209 char buf[4096]; | 3209 char buf[4096]; |
3210 char *data_cursor; | 3210 char *data_cursor; |
3211 gboolean got_eof = FALSE; | 3211 gboolean got_eof = FALSE; |
3212 | 3212 |
3213 while((len = read(sock, buf, sizeof(buf))) > 0) { | 3213 while((len = read(source, buf, sizeof(buf))) > 0) { |
3214 /* If we've filled up our butfer, make it bigger */ | 3214 /* If we've filled up our butfer, make it bigger */ |
3215 if((gfud->len + len) >= gfud->data_len) { | 3215 if((gfud->len + len) >= gfud->data_len) { |
3216 while((gfud->len + len) >= gfud->data_len) | 3216 while((gfud->len + len) >= gfud->data_len) |
3217 gfud->data_len += sizeof(buf); | 3217 gfud->data_len += sizeof(buf); |
3218 | 3218 |
3238 | 3238 |
3239 gaim_debug_misc("gaim_url_fetch", "Response headers: '%.*s'\n", | 3239 gaim_debug_misc("gaim_url_fetch", "Response headers: '%.*s'\n", |
3240 header_len, gfud->webdata); | 3240 header_len, gfud->webdata); |
3241 | 3241 |
3242 /* See if we can find a redirect. */ | 3242 /* See if we can find a redirect. */ |
3243 if(parse_redirect(gfud->webdata, header_len, sock, gfud)) | 3243 if(parse_redirect(gfud->webdata, header_len, source, gfud)) |
3244 return; | 3244 return; |
3245 | 3245 |
3246 gfud->got_headers = TRUE; | 3246 gfud->got_headers = TRUE; |
3247 | 3247 |
3248 /* No redirect. See if we can find a content length. */ | 3248 /* No redirect. See if we can find a content length. */ |
3271 new_data = g_try_malloc(content_len); | 3271 new_data = g_try_malloc(content_len); |
3272 if(new_data == NULL) { | 3272 if(new_data == NULL) { |
3273 gaim_debug_error("gaim_url_fetch", "Failed to allocate %u bytes: %s\n", | 3273 gaim_debug_error("gaim_url_fetch", "Failed to allocate %u bytes: %s\n", |
3274 content_len, strerror(errno)); | 3274 content_len, strerror(errno)); |
3275 gaim_input_remove(gfud->inpa); | 3275 gaim_input_remove(gfud->inpa); |
3276 close(sock); | 3276 close(source); |
3277 gfud->callback(gfud->user_data, NULL, 0); | 3277 gfud->callback(gfud->user_data, NULL, 0); |
3278 destroy_fetch_url_data(gfud); | 3278 destroy_fetch_url_data(gfud); |
3279 | 3279 |
3280 return; | 3280 return; |
3281 } | 3281 } |
3308 return; | 3308 return; |
3309 } else if(errno != ETIMEDOUT) { | 3309 } else if(errno != ETIMEDOUT) { |
3310 got_eof = TRUE; | 3310 got_eof = TRUE; |
3311 } else { | 3311 } else { |
3312 gaim_input_remove(gfud->inpa); | 3312 gaim_input_remove(gfud->inpa); |
3313 close(sock); | 3313 close(source); |
3314 | 3314 |
3315 gfud->callback(gfud->user_data, NULL, 0); | 3315 gfud->callback(gfud->user_data, NULL, 0); |
3316 | 3316 |
3317 destroy_fetch_url_data(gfud); | 3317 destroy_fetch_url_data(gfud); |
3318 return; | 3318 return; |
3324 gfud->webdata[gfud->len] = '\0'; | 3324 gfud->webdata[gfud->len] = '\0'; |
3325 | 3325 |
3326 /* gaim_debug_misc("gaim_url_fetch", "Received: '%s'\n", gfud->webdata); */ | 3326 /* gaim_debug_misc("gaim_url_fetch", "Received: '%s'\n", gfud->webdata); */ |
3327 | 3327 |
3328 gaim_input_remove(gfud->inpa); | 3328 gaim_input_remove(gfud->inpa); |
3329 close(sock); | 3329 close(source); |
3330 gfud->callback(gfud->user_data, gfud->webdata, gfud->len); | 3330 gfud->callback(gfud->user_data, gfud->webdata, gfud->len); |
3331 | 3331 |
3332 destroy_fetch_url_data(gfud); | 3332 destroy_fetch_url_data(gfud); |
3333 } | 3333 } |
3334 } | 3334 } |
3335 | 3335 |
3336 static void | 3336 static void |
3337 url_fetch_connect_cb(gpointer url_data, gint sock, GaimInputCondition cond) { | 3337 url_fetch_send_cb(gpointer data, gint source, GaimInputCondition cond) |
3338 GaimFetchUrlData *gfud = url_data; | 3338 { |
3339 GaimFetchUrlData *gfud; | |
3339 int len, total_len; | 3340 int len, total_len; |
3340 | 3341 |
3341 if(sock == -1) { | 3342 gfud = data; |
3343 | |
3344 total_len = strlen(gfud->request); | |
3345 | |
3346 len = write(source, gfud->request + gfud->request_written, | |
3347 total_len - gfud->request_written); | |
3348 | |
3349 if(len < 0 && errno == EAGAIN) | |
3350 return; | |
3351 else if(len < 0) { | |
3352 gaim_input_remove(gfud->inpa); | |
3353 close(source); | |
3342 gfud->callback(gfud->user_data, NULL, 0); | 3354 gfud->callback(gfud->user_data, NULL, 0); |
3343 destroy_fetch_url_data(gfud); | 3355 destroy_fetch_url_data(gfud); |
3344 return; | 3356 return; |
3345 } | 3357 } |
3346 | 3358 gfud->request_written += len; |
3347 if (!gfud->request) { | 3359 |
3360 if(gfud->request_written != total_len) | |
3361 return; | |
3362 | |
3363 /* We're done writing, now start reading */ | |
3364 gaim_input_remove(gfud->inpa); | |
3365 gfud->inpa = gaim_input_add(source, GAIM_INPUT_READ, url_fetch_recv_cb, | |
3366 gfud); | |
3367 } | |
3368 | |
3369 static void | |
3370 url_fetch_connect_cb(gpointer url_data, gint source, GaimInputCondition cond) | |
3371 { | |
3372 GaimFetchUrlData *gfud; | |
3373 | |
3374 gfud = url_data; | |
3375 | |
3376 if (source == -1) | |
3377 { | |
3378 gfud->callback(gfud->user_data, NULL, 0); | |
3379 destroy_fetch_url_data(gfud); | |
3380 return; | |
3381 } | |
3382 | |
3383 if (!gfud->request) | |
3384 { | |
3348 if (gfud->user_agent) { | 3385 if (gfud->user_agent) { |
3349 /* Host header is not forbidden in HTTP/1.0 requests, and HTTP/1.1 | 3386 /* Host header is not forbidden in HTTP/1.0 requests, and HTTP/1.1 |
3350 * clients must know how to handle the "chunked" transfer encoding. | 3387 * clients must know how to handle the "chunked" transfer encoding. |
3351 * Gaim doesn't know how to handle "chunked", so should always send | 3388 * Gaim doesn't know how to handle "chunked", so should always send |
3352 * the Host header regardless, to get around some observed problems | 3389 * the Host header regardless, to get around some observed problems |
3374 } | 3411 } |
3375 } | 3412 } |
3376 | 3413 |
3377 gaim_debug_misc("gaim_url_fetch", "Request: '%s'\n", gfud->request); | 3414 gaim_debug_misc("gaim_url_fetch", "Request: '%s'\n", gfud->request); |
3378 | 3415 |
3379 if(!gfud->inpa) | 3416 gfud->inpa = gaim_input_add(source, GAIM_INPUT_WRITE, |
3380 gfud->inpa = gaim_input_add(sock, GAIM_INPUT_WRITE, | 3417 url_fetch_send_cb, gfud); |
3381 url_fetch_connect_cb, gfud); | 3418 url_fetch_send_cb(gfud, source, GAIM_INPUT_WRITE); |
3382 | |
3383 total_len = strlen(gfud->request); | |
3384 | |
3385 len = write(sock, gfud->request + gfud->request_written, | |
3386 total_len - gfud->request_written); | |
3387 | |
3388 if(len < 0 && errno == EAGAIN) | |
3389 return; | |
3390 else if(len < 0) { | |
3391 gaim_input_remove(gfud->inpa); | |
3392 close(sock); | |
3393 gfud->callback(gfud->user_data, NULL, 0); | |
3394 destroy_fetch_url_data(gfud); | |
3395 return; | |
3396 } | |
3397 gfud->request_written += len; | |
3398 | |
3399 if(gfud->request_written != total_len) | |
3400 return; | |
3401 | |
3402 gaim_input_remove(gfud->inpa); | |
3403 | |
3404 gfud->inpa = gaim_input_add(sock, GAIM_INPUT_READ, url_fetched_cb, | |
3405 gfud); | |
3406 } | 3419 } |
3407 | 3420 |
3408 void | 3421 void |
3409 gaim_url_fetch_request(const char *url, gboolean full, | 3422 gaim_url_fetch_request(const char *url, gboolean full, |
3410 const char *user_agent, gboolean http11, | 3423 const char *user_agent, gboolean http11, |