input_stream: return errors with GError

This commit is contained in:
Max Kellermann
2009-11-14 23:53:04 +01:00
parent d000d31355
commit 228b03edf8
36 changed files with 422 additions and 175 deletions

View File

@@ -233,9 +233,17 @@ asx_open_stream(struct input_stream *is)
&parser, asx_parser_destroy);
while (true) {
nbytes = input_stream_read(is, buffer, sizeof(buffer));
if (nbytes == 0)
nbytes = input_stream_read(is, buffer, sizeof(buffer), &error);
if (nbytes == 0) {
if (error != NULL) {
g_markup_parse_context_free(context);
g_warning("%s", error->message);
g_error_free(error);
return NULL;
}
break;
}
success = g_markup_parse_context_parse(context, buffer, nbytes,
&error);

View File

@@ -86,27 +86,41 @@ static char *
lastfm_get(const char *url)
{
struct input_stream input_stream;
GError *error = NULL;
bool success;
int ret;
char buffer[4096];
size_t length = 0, nbytes;
success = input_stream_open(&input_stream, url);
if (!success)
success = input_stream_open(&input_stream, url, &error);
if (!success) {
if (error != NULL) {
g_warning("%s", error->message);
g_error_free(error);
}
return NULL;
}
while (!input_stream.ready) {
ret = input_stream_buffer(&input_stream);
ret = input_stream_buffer(&input_stream, &error);
if (ret < 0) {
input_stream_close(&input_stream);
g_warning("%s", error->message);
g_error_free(error);
return NULL;
}
}
do {
nbytes = input_stream_read(&input_stream, buffer + length,
sizeof(buffer) - length);
sizeof(buffer) - length, &error);
if (nbytes == 0) {
if (error != NULL) {
g_warning("%s", error->message);
g_error_free(error);
}
if (input_stream_eof(&input_stream))
break;
@@ -152,6 +166,7 @@ static struct playlist_provider *
lastfm_open_uri(const char *uri)
{
struct lastfm_playlist *playlist;
GError *error = NULL;
char *p, *q, *response, *session;
bool success;
@@ -216,20 +231,27 @@ lastfm_open_uri(const char *uri)
NULL);
g_free(session);
success = input_stream_open(&playlist->is, p);
success = input_stream_open(&playlist->is, p, &error);
g_free(p);
if (!success) {
g_warning("Failed to load XSPF playlist");
if (error != NULL) {
g_warning("Failed to load XSPF playlist: %s",
error->message);
g_error_free(error);
} else
g_warning("Failed to load XSPF playlist");
g_free(playlist);
return NULL;
}
while (!playlist->is.ready) {
int ret = input_stream_buffer(&playlist->is);
int ret = input_stream_buffer(&playlist->is, &error);
if (ret < 0) {
input_stream_close(&playlist->is);
g_free(playlist);
g_warning("%s", error->message);
g_error_free(error);
return NULL;
}

View File

@@ -115,9 +115,18 @@ pls_open_stream(struct input_stream *is)
GString *kf_data = g_string_new("");
do {
nbytes = input_stream_read(is, buffer, sizeof(buffer));
if(nbytes ==0)
nbytes = input_stream_read(is, buffer, sizeof(buffer), &error);
if (nbytes == 0) {
if (error != NULL) {
g_string_free(kf_data, TRUE);
g_warning("%s", error->message);
g_error_free(error);
return NULL;
}
break;
}
kf_data = g_string_append_len(kf_data, buffer,nbytes);
/* Limit to 64k */
} while(kf_data->len < 65536);

View File

@@ -253,9 +253,17 @@ xspf_open_stream(struct input_stream *is)
&parser, xspf_parser_destroy);
while (true) {
nbytes = input_stream_read(is, buffer, sizeof(buffer));
if (nbytes == 0)
nbytes = input_stream_read(is, buffer, sizeof(buffer), &error);
if (nbytes == 0) {
if (error != NULL) {
g_markup_parse_context_free(context);
g_warning("%s", error->message);
g_error_free(error);
return NULL;
}
break;
}
success = g_markup_parse_context_parse(context, buffer, nbytes,
&error);