1
/* $Id: weather-bom.c 9804 2006-08-07 14:05:56Z davyd $ */
4
* Papadimitriou Spiros <spapadim+@cs.cmu.edu>
6
* This code released under the GNU GPL.
7
* Read the file COPYING for more information.
9
* Weather server functions (BOM)
18
#include <libgweather/weather.h>
19
#include "weather-priv.h"
21
static gchar *bom_parse (gchar *meto)
25
g_return_val_if_fail (meto != NULL, NULL);
27
p = strstr(meto, "<pre>");
28
g_return_val_if_fail (p != NULL, NULL);
30
rp = strstr(p, "</pre>");
31
g_return_val_if_fail (rp !=NULL, NULL);
33
p += 5; /* skip the <pre> */
35
return g_strndup(p, rp-p);
38
static void bom_finish_read(GnomeVFSAsyncHandle *handle, GnomeVFSResult result,
39
gpointer buffer, GnomeVFSFileSize requested,
40
GnomeVFSFileSize body_len, gpointer data)
42
WeatherInfo *info = (WeatherInfo *)data;
43
gchar *body, *forecast, *temp;
45
g_return_if_fail(info != NULL);
46
g_return_if_fail(handle == info->bom_handle);
48
info->forecast = NULL;
49
body = (gchar *)buffer;
50
body[body_len] = '\0';
52
if (info->bom_buffer == NULL)
53
info->bom_buffer = g_strdup(body);
56
temp = g_strdup(info->bom_buffer);
57
g_free(info->bom_buffer);
58
info->bom_buffer = g_strdup_printf("%s%s", temp, body);
62
if (result == GNOME_VFS_ERROR_EOF)
64
forecast = bom_parse(info->bom_buffer);
65
info->forecast = forecast;
67
else if (result != GNOME_VFS_OK) {
68
info->bom_handle = NULL;
69
requests_done_check (info);
70
g_warning("Failed to get BOM data.\n");
72
gnome_vfs_async_read(handle, body, DATA_SIZE - 1, bom_finish_read, info);
77
request_done(info->bom_handle, info);
82
static void bom_finish_open (GnomeVFSAsyncHandle *handle, GnomeVFSResult result, gpointer data)
84
WeatherInfo *info = (WeatherInfo *)data;
88
g_return_if_fail(info != NULL);
89
g_return_if_fail(handle == info->bom_handle);
91
body = g_malloc0(DATA_SIZE);
93
info->bom_buffer = NULL;
95
g_free (info->forecast);
96
info->forecast = NULL;
98
g_return_if_fail(loc != NULL);
100
if (result != GNOME_VFS_OK) {
101
g_warning("Failed to get BOM forecast data.\n");
102
info->bom_handle = NULL;
103
requests_done_check (info);
106
gnome_vfs_async_read(handle, body, DATA_SIZE - 1, bom_finish_read, info);
111
void bom_start_open (WeatherInfo *info)
114
WeatherLocation *loc;
115
loc = info->location;
117
url = g_strdup_printf("http://www.bom.gov.au/cgi-bin/wrap_fwo.pl?%s.txt",
120
gnome_vfs_async_open(&info->bom_handle, url, GNOME_VFS_OPEN_READ,
121
0, bom_finish_open, info);