File: | weather-bom.c |
Warning: | line 33, column 18 Value stored to 'session' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */ |
2 | /* weather-bom.c - Australian Bureau of Meteorology forecast source |
3 | * |
4 | * This program is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU General Public License as |
6 | * published by the Free Software Foundation; either version 2 of the |
7 | * License, or (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, but |
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, see |
16 | * <http://www.gnu.org/licenses/>. |
17 | */ |
18 | |
19 | #ifdef HAVE_CONFIG_H1 |
20 | #include <config.h> |
21 | #endif |
22 | |
23 | #include <string.h> |
24 | |
25 | #define CAFEWEATHER_I_KNOW_THIS_IS_UNSTABLE |
26 | #include "weather.h" |
27 | #include "weather-priv.h" |
28 | |
29 | static void |
30 | bom_finish (GObject *object, GAsyncResult *result, gpointer data) |
31 | { |
32 | char *p, *rp; |
33 | SoupSession *session = SOUP_SESSION (object); |
Value stored to 'session' during its initialization is never read | |
34 | SoupMessage *msg = soup_session_get_async_result_message (SOUP_SESSION (object), result); |
35 | WeatherInfo *info = (WeatherInfo *)data; |
36 | GBytes *response_body = NULL((void*)0); |
37 | const gchar *msgdata; |
38 | |
39 | g_return_if_fail (info != NULL)do { if ((info != ((void*)0))) { } else { g_return_if_fail_warning ("CafeWeather", ((const char*) (__func__)), "info != NULL"); return; } } while (0); |
40 | |
41 | response_body = soup_session_send_and_read_finish(SOUP_SESSION(object), |
42 | result, NULL((void*)0)/*&error*/); |
43 | |
44 | if (!SOUP_STATUS_IS_SUCCESSFUL (soup_message_get_status (msg))((soup_message_get_status (msg)) >= 200 && (soup_message_get_status (msg)) < 300)) { |
45 | g_warning ("Failed to get BOM forecast data: %d %s.\n", |
46 | soup_message_get_status (msg), soup_message_get_reason_phrase (msg)); |
47 | request_done (info, FALSE(0)); |
48 | return; |
49 | } |
50 | |
51 | msgdata = g_bytes_get_data(response_body, NULL((void*)0)/*&length*/); |
52 | |
53 | p = strstr (msgdata, "Forecast for the rest"); |
54 | if (p != NULL((void*)0)) { |
55 | rp = strstr (p, "The next routine forecast will be issued"); |
56 | if (rp == NULL((void*)0)) |
57 | info->forecast = g_strdup (p)g_strdup_inline (p); |
58 | else |
59 | info->forecast = g_strndup (p, rp - p); |
60 | } |
61 | |
62 | if (info->forecast == NULL((void*)0)) |
63 | info->forecast = g_strdup (msgdata)g_strdup_inline (msgdata); |
64 | |
65 | g_print ("%s\n", info->forecast); |
66 | request_done (info, TRUE(!(0))); |
67 | } |
68 | |
69 | void |
70 | bom_start_open (WeatherInfo *info) |
71 | { |
72 | gchar *url; |
73 | SoupMessage *msg; |
74 | WeatherLocation *loc; |
75 | |
76 | loc = info->location; |
77 | |
78 | url = g_strdup_printf ("http://www.bom.gov.au/fwo/%s.txt", |
79 | loc->zone + 1); |
80 | |
81 | msg = soup_message_new ("GET", url); |
82 | soup_session_send_and_read_async (info->session, msg, G_PRIORITY_DEFAULT0, NULL((void*)0), bom_finish, info); |
83 | g_free (url); |
84 | |
85 | info->requests_pending++; |
86 | } |