Mercurial > audlegacy-plugins
comparison src/mpg123/http.c @ 220:1e2d575fd2e7 trunk
[svn] - allow seeking in http streams that define a content length.
| author | nenolod |
|---|---|
| date | Sun, 05 Nov 2006 02:21:22 -0800 |
| parents | a6f6309ab0a0 |
| children | f6bdf10fe48c |
comparison
equal
deleted
inserted
replaced
| 219:469078516127 | 220:1e2d575fd2e7 |
|---|---|
| 62 static gsize rd_index, wr_index, buffer_length, prebuffer_length; | 62 static gsize rd_index, wr_index, buffer_length, prebuffer_length; |
| 63 static guint64 buffer_read = 0; | 63 static guint64 buffer_read = 0; |
| 64 static gchar *buffer; | 64 static gchar *buffer; |
| 65 static GThread *thread; | 65 static GThread *thread; |
| 66 static GtkWidget *error_dialog = NULL; | 66 static GtkWidget *error_dialog = NULL; |
| 67 static unsigned long range; | |
| 67 | 68 |
| 68 static VFSFile *output_file = NULL; | 69 static VFSFile *output_file = NULL; |
| 69 | 70 |
| 70 #define BASE64_LENGTH(len) (4 * (((len) + 2) / 3)) | 71 #define BASE64_LENGTH(len) (4 * (((len) + 2) / 3)) |
| 71 | 72 |
| 337 | 338 |
| 338 static gpointer | 339 static gpointer |
| 339 http_buffer_loop(gpointer arg) | 340 http_buffer_loop(gpointer arg) |
| 340 { | 341 { |
| 341 gchar line[1024], *user, *pass, *host, *filename, | 342 gchar line[1024], *user, *pass, *host, *filename, |
| 342 *status, *url, *temp, *file; | 343 *status, *url, *temp, *temp2, *file; |
| 343 gchar *chost; | 344 gchar *chost; |
| 344 gint cnt, written, error, port, cport; | 345 gint cnt, written, error, port, cport; |
| 345 guint err_len; | 346 guint err_len; |
| 346 gboolean redirect; | 347 gboolean redirect; |
| 347 gint udp_sock = 0; | 348 gint udp_sock = 0; |
| 508 "Proxy-Authorization"); | 509 "Proxy-Authorization"); |
| 509 } | 510 } |
| 510 } | 511 } |
| 511 else | 512 else |
| 512 file = g_strconcat("/", filename, NULL); | 513 file = g_strconcat("/", filename, NULL); |
| 513 temp = g_strdup_printf("GET %s HTTP/1.0\r\n" | 514 if (range) |
| 515 { | |
| 516 temp2 = g_strdup_printf("Range: bytes=%lu-\r\n", range); | |
| 517 } else | |
| 518 temp2 = NULL; | |
| 519 temp = g_strdup_printf("GET %s HTTP/1.1\r\n" | |
| 514 "Host: %s\r\n" | 520 "Host: %s\r\n" |
| 515 "User-Agent: %s/%s\r\n" | 521 "User-Agent: %s/%s\r\n" |
| 516 "%s%s%s%s\r\n", | 522 "%s%s%s%s%s\r\n", |
| 517 file, host, PACKAGE_NAME, PACKAGE_VERSION, | 523 file, host, PACKAGE_NAME, PACKAGE_VERSION, |
| 518 proxy_auth ? proxy_auth : "", | 524 proxy_auth ? proxy_auth : "", |
| 519 auth ? auth : "", | 525 auth ? auth : "", |
| 520 "Icy-MetaData:1\r\n", | 526 "Icy-MetaData:1\r\n", |
| 521 mpgdec_cfg. | 527 mpgdec_cfg. |
| 522 use_udp_channel ? udpspace : ""); | 528 use_udp_channel ? udpspace : "", |
| 529 temp2 != NULL ? temp2 : ""); | |
| 523 | 530 |
| 524 g_free(file); | 531 g_free(file); |
| 525 if (proxy_auth) | 532 if (proxy_auth) |
| 526 g_free(proxy_auth); | 533 g_free(proxy_auth); |
| 527 if (auth) | 534 if (auth) |
| 596 fprintf(stderr, | 603 fprintf(stderr, |
| 597 "Server wants udp messages on port %d\n", | 604 "Server wants udp messages on port %d\n", |
| 598 atoi(line + 20)); | 605 atoi(line + 20)); |
| 599 #endif | 606 #endif |
| 600 /* udp_serverport = atoi (line + 20); */ | 607 /* udp_serverport = atoi (line + 20); */ |
| 608 | |
| 601 } | 609 } |
| 602 | 610 |
| 611 if (!strncasecmp(line, "content-length:", 15)) { | |
| 612 mpgdec_info->filesize = atoi(line + 15); | |
| 613 } | |
| 603 } | 614 } |
| 604 else { | 615 else { |
| 605 eof = TRUE; | 616 eof = TRUE; |
| 606 mpgdec_ip.set_info_text(NULL); | 617 mpgdec_ip.set_info_text(NULL); |
| 607 break; | 618 break; |
| 723 | 734 |
| 724 return NULL; | 735 return NULL; |
| 725 } | 736 } |
| 726 | 737 |
| 727 int | 738 int |
| 728 mpgdec_http_open(gchar * _url) | 739 mpgdec_http_open(gchar * _url, unsigned long rng) |
| 729 { | 740 { |
| 730 gchar *url; | 741 gchar *url; |
| 731 | 742 |
| 732 url = g_strdup(_url); | 743 url = g_strdup(_url); |
| 733 | 744 |
| 740 prebuffering = TRUE; | 751 prebuffering = TRUE; |
| 741 mpgdec_ip.set_status_buffering(TRUE); | 752 mpgdec_ip.set_status_buffering(TRUE); |
| 742 going = TRUE; | 753 going = TRUE; |
| 743 eof = FALSE; | 754 eof = FALSE; |
| 744 buffer = g_malloc(buffer_length); | 755 buffer = g_malloc(buffer_length); |
| 756 range = rng; | |
| 745 | 757 |
| 746 thread = g_thread_create(http_buffer_loop, url, TRUE, NULL); | 758 thread = g_thread_create(http_buffer_loop, url, TRUE, NULL); |
| 747 | 759 |
| 748 return 0; | 760 return 0; |
| 749 } | 761 } |
