1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
|
From 4455561d5107a73fb95c53f2d7c2016b3b58a609 Mon Sep 17 00:00:00 2001
From: https://github.com/mate-desktop/libmateweather/pull/133
From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
<congdanhqx@gmail.com>
Date: Mon, 4 Mar 2024 23:47:37 +0700
Subject: [PATCH] Port to libsoup-3.0
Signed-off-by: Thibaud CANALE <thican@thican.net>
---
.build.yml | 10 ++--
configure.ac | 6 ++-
libmateweather/mateweather-uninstalled.pc.in | 2 +-
libmateweather/mateweather.pc.in | 2 +-
libmateweather/weather-bom.c | 36 ++++++++-----
libmateweather/weather-iwin.c | 37 ++++++++-----
libmateweather/weather-met.c | 34 ++++++++----
libmateweather/weather-metar.c | 56 ++++++++++++++------
libmateweather/weather-priv.h | 6 ++-
libmateweather/weather-wx.c | 53 +++++++++---------
libmateweather/weather.c | 7 +--
11 files changed, 156 insertions(+), 93 deletions(-)
diff --git a/.build.yml b/.build.yml
index 622db502..024b8f4a 100644
--- a/.build.yml
+++ b/.build.yml
@@ -9,7 +9,7 @@ requires:
- gcc
- git
- gtk3
- - libsoup
+ - libsoup3
- make
- mate-common
- tzdata
@@ -27,8 +27,7 @@ requires:
- gtk-doc-tools
- libglib2.0-dev
- libgtk-3-dev
- - libsoup-gnome2.4-dev
- - libsoup2.4-dev
+ - libsoup-3.0-dev
- libxml2-dev
- libxml2-utils
- make
@@ -44,7 +43,7 @@ requires:
- gcc
- git
- gtk3-devel
- - libsoup-devel
+ - libsoup3-devel
- libxml2-devel
- make
- mate-common
@@ -60,8 +59,7 @@ requires:
- gtk-doc-tools
- libglib2.0-dev
- libgtk-3-dev
- - libsoup-gnome2.4-dev
- - libsoup2.4-dev
+ - libsoup-3.0-dev
- libxml2-dev
- libxml2-utils
- make
diff --git a/configure.ac b/configure.ac
index e0ca7be1..0e8b9ad1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -8,6 +8,7 @@ AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([1.9 no-dist-gzip dist-xz tar-ustar check-news])
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
+AC_USE_SYSTEM_EXTENSIONS
# Before making a release, the LT_VERSION string should be modified.
# The string is of the form C:R:A.
# - If interfaces have been changed or added, but binary compatibility has
@@ -23,7 +24,7 @@ AC_CANONICAL_HOST
GLIB_REQUIRED=2.56.0
GTK_REQUIRED=3.22.0
-LIBSOUP_REQUIRED=2.34.0
+LIBSOUP_REQUIRED=3.0.0
GIO_REQUIRED=2.25.0
LIBXML_REQUIRED=2.6.0
@@ -65,7 +66,7 @@ dnl -- Check for libxml (required) ------------------------------------------
PKG_CHECK_MODULES(LIBXML, libxml-2.0 >= $LIBXML_REQUIRED)
dnl -- check for libsoup (required) -----------------------------------------
-PKG_CHECK_MODULES(LIBSOUP, [libsoup-2.4 >= $LIBSOUP_REQUIRED])
+PKG_CHECK_MODULES(LIBSOUP, [libsoup-3.0 >= $LIBSOUP_REQUIRED])
dnl -- check for gio (required) -----------------------------------------
PKG_CHECK_MODULES(GIO,
@@ -100,6 +101,7 @@ AC_CHECK_FUNCS(regexec,,[AC_CHECK_LIB(regex,regexec,
[AC_MSG_ERROR([No regex library found])])])
AC_SUBST(REGEX_LIBS)
+AC_CHECK_FUNC(memmem,[],[AC_MSG_ERROR([memmem is required])])
dnl ***************************************************************************
dnl *** Check for presence of tm.tm_gmtoff on the system ***
diff --git a/libmateweather/mateweather-uninstalled.pc.in b/libmateweather/mateweather-uninstalled.pc.in
index 03e74617..c692842a 100644
--- a/libmateweather/mateweather-uninstalled.pc.in
+++ b/libmateweather/mateweather-uninstalled.pc.in
@@ -8,6 +8,6 @@ Name: MateWeather
Description: MateWeather shared library
Version: @VERSION@
Requires: glib-2.0 gobject-2.0 gdk-pixbuf-2.0 gtk+-3.0 gio-2.0
-Requires.private: libxml-2.0 libsoup-2.4
+Requires.private: libxml-2.0 libsoup-3.0
Libs: ${pc_top_builddir}/${pcfiledir}/libmateweather.la
Cflags: -I${pc_top_builddir}/${pcfiledir}/..
diff --git a/libmateweather/mateweather.pc.in b/libmateweather/mateweather.pc.in
index a617c334..bea024dd 100644
--- a/libmateweather/mateweather.pc.in
+++ b/libmateweather/mateweather.pc.in
@@ -8,7 +8,7 @@ Name: MateWeather
Description: MateWeather shared library
Version: @VERSION@
Requires: glib-2.0 gobject-2.0 gdk-pixbuf-2.0 gtk+-3.0 gio-2.0
-Requires.private: libxml-2.0 libsoup-2.4
+Requires.private: libxml-2.0 libsoup-3.0
Libs: -L${libdir} -lmateweather
Libs.private: -lm
Cflags: -I${includedir}
diff --git a/libmateweather/weather-bom.c b/libmateweather/weather-bom.c
index 47b2d0b9..f5c7a87d 100644
--- a/libmateweather/weather-bom.c
+++ b/libmateweather/weather-bom.c
@@ -27,34 +27,45 @@
#include "weather-priv.h"
static void
-bom_finish (SoupSession *session, SoupMessage *msg, gpointer data)
+bom_finish (GObject *source, GAsyncResult *result, gpointer data)
{
char *p, *rp;
WeatherInfo *info = (WeatherInfo *)data;
+ GError *error = NULL;
+ GBytes *bytes;
+ const char *response_body = NULL;
+ gsize len = 0;
g_return_if_fail (info != NULL);
- if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
- g_warning ("Failed to get BOM forecast data: %d %s.\n",
- msg->status_code, msg->reason_phrase);
- request_done (info, FALSE);
- return;
+ bytes = soup_session_send_and_read_finish (SOUP_SESSION(source),
+ result, &error);
+
+ if (error != NULL) {
+ g_warning ("Failed to get BOM forecast data: %s.\n", error->message);
+ request_done (info, error);
+ g_error_free (error);
+ return;
}
- p = strstr (msg->response_body->data, "Forecast for the rest");
+ response_body = g_bytes_get_data (bytes, &len);
+
+ p = xstrnstr (response_body, len, "Forecast for the rest");
if (p != NULL) {
- rp = strstr (p, "The next routine forecast will be issued");
+ rp = xstrnstr (p, len - (p - response_body),
+ "The next routine forecast will be issued");
if (rp == NULL)
- info->forecast = g_strdup (p);
+ info->forecast = g_strndup (p, len - (p - response_body));
else
info->forecast = g_strndup (p, rp - p);
}
if (info->forecast == NULL)
- info->forecast = g_strdup (msg->response_body->data);
+ info->forecast = g_strndup (response_body, len);
+ g_bytes_unref (bytes);
g_print ("%s\n", info->forecast);
- request_done (info, TRUE);
+ request_done (info, NULL);
}
void
@@ -70,7 +81,8 @@ bom_start_open (WeatherInfo *info)
loc->zone + 1);
msg = soup_message_new ("GET", url);
- soup_session_queue_message (info->session, msg, bom_finish, info);
+ soup_session_send_and_read_async (info->session, msg, G_PRIORITY_DEFAULT,
+ NULL, bom_finish, info);
g_free (url);
info->requests_pending++;
diff --git a/libmateweather/weather-iwin.c b/libmateweather/weather-iwin.c
index 9f7ff380..b1dc1ffa 100644
--- a/libmateweather/weather-iwin.c
+++ b/libmateweather/weather-iwin.c
@@ -93,7 +93,7 @@ hasAttr (xmlNode *node, const char *attr_name, const char *attr_value)
}
static GSList *
-parseForecastXml (const char *buff, WeatherInfo *master_info)
+parseForecastXml (const char *buff, gsize len, WeatherInfo *master_info)
{
GSList *res = NULL;
xmlDocPtr doc;
@@ -107,7 +107,7 @@ parseForecastXml (const char *buff, WeatherInfo *master_info)
#define XC (const xmlChar *)
#define isElem(_node,_name) g_str_equal ((const char *)_node->name, _name)
- doc = xmlParseMemory (buff, strlen (buff));
+ doc = xmlParseMemory (buff, len);
if (!doc)
return NULL;
@@ -380,26 +380,36 @@ parseForecastXml (const char *buff, WeatherInfo *master_info)
}
static void
-iwin_finish (SoupSession *session, SoupMessage *msg, gpointer data)
+iwin_finish (GObject *source, GAsyncResult *result, gpointer data)
{
WeatherInfo *info = (WeatherInfo *)data;
+ GError *error = NULL;
+ GBytes *bytes;
+ const char *response_body = NULL;
+ gsize len = 0;
g_return_if_fail (info != NULL);
- if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
+ bytes = soup_session_send_and_read_finish (SOUP_SESSION(source),
+ result, &error);
+
+ if (error != NULL) {
/* forecast data is not really interesting anyway ;) */
- g_warning ("Failed to get IWIN forecast data: %d %s\n",
- msg->status_code, msg->reason_phrase);
- request_done (info, FALSE);
+ g_warning ("Failed to get IWIN forecast data: %s\n",
+ error->message);
+ request_done (info, error);
+ g_error_free (error);
return;
}
+ response_body = g_bytes_get_data (bytes, &len);
if (info->forecast_type == FORECAST_LIST)
- info->forecast_list = parseForecastXml (msg->response_body->data, info);
+ info->forecast_list = parseForecastXml (response_body, len, info);
else
- info->forecast = formatWeatherMsg (g_strdup (msg->response_body->data));
+ info->forecast = formatWeatherMsg (g_strndup (response_body, len));
- request_done (info, TRUE);
+ g_bytes_unref (bytes);
+ request_done (info, NULL);
}
/* Get forecast into newly alloc'ed string */
@@ -439,7 +449,9 @@ iwin_start_open (WeatherInfo *info)
msg = soup_message_new ("GET", url);
g_free (url);
- soup_session_queue_message (info->session, msg, iwin_finish, info);
+ soup_session_send_and_read_async (info->session, msg,
+ G_PRIORITY_DEFAULT,
+ NULL, iwin_finish, info);
info->requests_pending++;
}
@@ -470,7 +482,8 @@ iwin_start_open (WeatherInfo *info)
msg = soup_message_new ("GET", url);
g_free (url);
- soup_session_queue_message (info->session, msg, iwin_finish, info);
+ soup_session_send_and_read_async (info->session, msg, G_PRIORITY_DEFAULT,
+ NULL, iwin_finish, info);
info->requests_pending++;
}
diff --git a/libmateweather/weather-met.c b/libmateweather/weather-met.c
index 164e9f23..7022abb2 100644
--- a/libmateweather/weather-met.c
+++ b/libmateweather/weather-met.c
@@ -119,19 +119,20 @@ met_reprocess (char *x, int len)
*/
static gchar *
-met_parse (const gchar *meto)
+met_parse (const gchar *meto, gsize len)
{
gchar *p;
gchar *rp;
gchar *r = g_strdup ("Met Office Forecast\n");
gchar *t;
+ const gchar *end = meto + len;
g_return_val_if_fail (meto != NULL, r);
- p = strstr (meto, "Summary: </b>");
+ p = xstrnstr (meto, len, "Summary: </b>");
g_return_val_if_fail (p != NULL, r);
- rp = strstr (p, "Text issued at:");
+ rp = xstrnstr (p, end - p, "Text issued at:");
g_return_val_if_fail (rp != NULL, r);
p += 13;
@@ -143,21 +144,31 @@ met_parse (const gchar *meto)
}
static void
-met_finish (SoupSession *session, SoupMessage *msg, gpointer data)
+met_finish (GObject *source, GAsyncResult *result, gpointer data)
{
WeatherInfo *info = (WeatherInfo *)data;
+ GError *error = NULL;
+ GBytes *bytes;
+ const char *response_body = NULL;
+ gsize len = 0;
g_return_if_fail (info != NULL);
- if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
- g_warning ("Failed to get Met Office forecast data: %d %s.\n",
- msg->status_code, msg->reason_phrase);
- request_done (info, FALSE);
+ bytes = soup_session_send_and_read_finish (SOUP_SESSION(source),
+ result, &error);
+
+ if (error != NULL) {
+ g_warning ("Failed to get Met Office forecast data: %s.\n",
+ error->message);
+ request_done (info, error);
+ g_error_free (error);
return;
}
- info->forecast = met_parse (msg->response_body->data);
- request_done (info, TRUE);
+ response_body = g_bytes_get_data (bytes, &len);
+ info->forecast = met_parse (response_body, len);
+ g_bytes_unref (bytes);
+ request_done (info, NULL);
}
void
@@ -171,7 +182,8 @@ metoffice_start_open (WeatherInfo *info)
url = g_strdup_printf ("http://www.metoffice.gov.uk/weather/europe/uk/%s.html", loc->zone + 1);
msg = soup_message_new ("GET", url);
- soup_session_queue_message (info->session, msg, met_finish, info);
+ soup_session_send_and_read_async (info->session, msg, G_PRIORITY_DEFAULT,
+ NULL, met_finish, info);
g_free (url);
info->requests_pending++;
diff --git a/libmateweather/weather-metar.c b/libmateweather/weather-metar.c
index 4698a077..dabca3a2 100644
--- a/libmateweather/weather-metar.c
+++ b/libmateweather/weather-metar.c
@@ -486,43 +486,60 @@ metar_parse (gchar *metar, WeatherInfo *info)
}
static void
-metar_finish (SoupSession *session, SoupMessage *msg, gpointer data)
+metar_finish (GObject *source, GAsyncResult *result, gpointer data)
{
WeatherInfo *info = (WeatherInfo *)data;
WeatherLocation *loc;
- const gchar *p, *endtag;
+ const gchar *p, *end, *endtag;
gchar *searchkey, *metar;
gboolean success = FALSE;
+ GError *error = NULL;
+ GBytes *bytes;
+ const char *response_body = NULL;
+ gsize len = 0;
g_return_if_fail (info != NULL);
- if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
- if (SOUP_STATUS_IS_TRANSPORT_ERROR (msg->status_code))
+ bytes = soup_session_send_and_read_finish (SOUP_SESSION(source),
+ result, &error);
+
+ if (error != NULL) {
+ /* https://libsoup.org/libsoup-3.0/migrating-from-libsoup-2.html#status-codes-no-longer-used-for-internal-errors */
+ switch (error->code) {
+ case SOUP_SESSION_ERROR_PARSING:
+ case SOUP_SESSION_ERROR_ENCODING:
+ case SOUP_SESSION_ERROR_TOO_MANY_REDIRECTS:
info->network_error = TRUE;
- else {
- /* Translators: %d is an error code, and %s the error string */
- g_warning (_("Failed to get METAR data: %d %s.\n"),
- msg->status_code, msg->reason_phrase);
+ break;
+ default:
+ break;
}
- request_done (info, FALSE);
+ g_warning (_("Failed to get METAR data: %s.\n"),
+ error->message);
+ request_done (info, error);
+ g_error_free (error);
return;
}
loc = info->location;
searchkey = g_strdup_printf ("<raw_text>METAR %s", loc->code);
- p = strstr (msg->response_body->data, searchkey);
- g_free (searchkey);
+
+ response_body = g_bytes_get_data (bytes, &len);
+ end = response_body + len;
+
+ p = xstrnstr (response_body, len, searchkey);
if (p) {
p += WEATHER_LOCATION_CODE_LEN + 11;
endtag = strstr (p, "</raw_text>");
+ endtag = xstrnstr (p, end - p, "</raw_text>");
if (endtag)
metar = g_strndup (p, endtag - p);
else
- metar = g_strdup (p);
+ metar = g_strndup (p, end - p);
success = metar_parse (metar, info);
g_free (metar);
- } else if (!strstr (msg->response_body->data, "aviationweather.gov")) {
+ } else if (!xstrnstr (response_body, len, "aviationweather.gov")) {
/* The response doesn't even seem to have come from NOAA...
* most likely it is a wifi hotspot login page. Call that a
* network error.
@@ -531,7 +548,8 @@ metar_finish (SoupSession *session, SoupMessage *msg, gpointer data)
}
info->valid = success;
- request_done (info, TRUE);
+ request_done (info, NULL);
+ g_bytes_unref(bytes);
}
/* Read current conditions and fill in info structure */
@@ -540,6 +558,7 @@ metar_start_open (WeatherInfo *info)
{
WeatherLocation *loc;
SoupMessage *msg;
+ char *query;
g_return_if_fail (info != NULL);
info->valid = info->network_error = FALSE;
@@ -549,8 +568,7 @@ metar_start_open (WeatherInfo *info)
return;
}
- msg = soup_form_request_new (
- "GET", "https://aviationweather.gov/api/data/dataserver",
+ query = soup_form_encode (
"dataSource", "metars",
"requestType", "retrieve",
"format", "xml",
@@ -559,7 +577,11 @@ metar_start_open (WeatherInfo *info)
"fields", "raw_text",
"stationString", loc->code,
NULL);
- soup_session_queue_message (info->session, msg, metar_finish, info);
+ msg = soup_message_new_from_encoded_form (
+ "GET", "https://aviationweather.gov/api/data/dataserver",
+ query);
+ soup_session_send_and_read_async (info->session, msg, G_PRIORITY_DEFAULT,
+ NULL, metar_finish, info);
info->requests_pending++;
}
diff --git a/libmateweather/weather-priv.h b/libmateweather/weather-priv.h
index 817f13c5..03cdcbd9 100644
--- a/libmateweather/weather-priv.h
+++ b/libmateweather/weather-priv.h
@@ -21,6 +21,7 @@
#include "config.h"
+#include <string.h>
#include <time.h>
#include <libintl.h>
#include <math.h>
@@ -34,6 +35,8 @@ const char *mateweather_dpgettext (const char *context, const char *str) G_GNUC_
#define _(str) (mateweather_gettext (str))
#define C_(context, str) (mateweather_dpgettext (context, str))
#define N_(str) (str)
+#define xstrnstr(haystack, hlen, needle) \
+ memmem(haystack, hlen, needle, strlen(needle))
#define WEATHER_LOCATION_CODE_LEN 4
@@ -95,7 +98,6 @@ struct _WeatherInfo {
GSList *forecast_list; /* list of WeatherInfo* for the forecast, NULL if not available */
gchar *radar_buffer;
gchar *radar_url;
- GdkPixbufLoader *radar_loader;
GdkPixbufAnimation *radar;
SoupSession *session;
gint requests_pending;
@@ -167,7 +169,7 @@ gboolean metar_parse (gchar *metar,
gboolean requests_init (WeatherInfo *info);
void request_done (WeatherInfo *info,
- gboolean ok);
+ GError *error);
void ecl2equ (gdouble t,
gdouble eclipLon,
diff --git a/libmateweather/weather-wx.c b/libmateweather/weather-wx.c
index e29ceccd..11f73368 100644
--- a/libmateweather/weather-wx.c
+++ b/libmateweather/weather-wx.c
@@ -25,48 +25,51 @@
#include "weather-priv.h"
static void
-wx_finish (SoupSession *session, SoupMessage *msg, gpointer data)
+wx_finish (GObject *source, GAsyncResult *result, gpointer data)
{
WeatherInfo *info = (WeatherInfo *)data;
GdkPixbufAnimation *animation;
+ GError *error = NULL;
g_return_if_fail (info != NULL);
- if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
- g_warning ("Failed to get radar map image: %d %s.\n",
- msg->status_code, msg->reason_phrase);
- g_object_unref (info->radar_loader);
- request_done (info, FALSE);
- return;
- }
+ animation = gdk_pixbuf_animation_new_from_stream_finish (result, &error);
- gdk_pixbuf_loader_close (info->radar_loader, NULL);
- animation = gdk_pixbuf_loader_get_animation (info->radar_loader);
+ if (error != NULL) {
+ g_warning ("Failed to get radar map image: %s.\n", error->message);
+ request_done (info, error);
+ g_error_free (error);
+ return;
+ }
if (animation != NULL) {
- if (info->radar)
- g_object_unref (info->radar);
- info->radar = animation;
- g_object_ref (info->radar);
+ if (info->radar)
+ g_object_unref (info->radar);
+ info->radar = animation;
+ g_object_ref (info->radar);
}
- g_object_unref (info->radar_loader);
- request_done (info, TRUE);
+ request_done (info, NULL);
}
static void
-wx_got_chunk (SoupMessage *msg, SoupBuffer *chunk, gpointer data)
+wx_got_chunk (GObject *source, GAsyncResult *result, gpointer data)
{
WeatherInfo *info = (WeatherInfo *)data;
GError *error = NULL;
+ GInputStream *istream;
g_return_if_fail (info != NULL);
- gdk_pixbuf_loader_write (info->radar_loader, (guchar *)chunk->data,
- chunk->length, &error);
- if (error) {
- g_print ("%s \n", error->message);
- g_error_free (error);
+ istream = soup_session_send_finish (SOUP_SESSION (source), result, &error);
+
+ if (error != NULL) {
+ g_warning ("Failed to get radar map image: %s.\n", error->message);
+ g_error_free (error);
+ request_done (info, error);
+ return;
}
+
+ gdk_pixbuf_animation_new_from_stream_async (istream, NULL, wx_finish, data);
}
/* Get radar map and into newly allocated pixmap */
@@ -79,7 +82,6 @@ wx_start_open (WeatherInfo *info)
g_return_if_fail (info != NULL);
info->radar = NULL;
- info->radar_loader = gdk_pixbuf_loader_new ();
loc = info->location;
g_return_if_fail (loc != NULL);
@@ -98,9 +100,8 @@ wx_start_open (WeatherInfo *info)
return;
}
- g_signal_connect (msg, "got-chunk", G_CALLBACK (wx_got_chunk), info);
- soup_message_body_set_accumulate (msg->response_body, FALSE);
- soup_session_queue_message (info->session, msg, wx_finish, info);
+ soup_session_send_async (info->session, msg, G_PRIORITY_DEFAULT, NULL,
+ wx_got_chunk, info);
g_free (url);
info->requests_pending++;
diff --git a/libmateweather/weather.c b/libmateweather/weather.c
index 86453fc5..1d7533a6 100644
--- a/libmateweather/weather.c
+++ b/libmateweather/weather.c
@@ -348,12 +348,13 @@ requests_init (WeatherInfo *info)
return TRUE;
}
-void request_done (WeatherInfo *info, gboolean ok)
+void request_done (WeatherInfo *info, GError *error)
{
- if (ok) {
+ if (error == NULL) {
(void) calc_sun (info);
info->moonValid = info->valid && calc_moon (info);
- }
+ } else if (error->code == G_IO_ERROR_CANCELLED)
+ return; /* Caused by soup_session_abort */
if (!--info->requests_pending)
info->finish_cb (info, info->cb_data);
}
--
2.51.2
|