summaryrefslogtreecommitdiffstats
path: root/meta-xfce/recipes-panel-plugins/weather/xfce4-weather-plugin/0002-parsers-Generalise-input-to-array-of-gchar.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta-xfce/recipes-panel-plugins/weather/xfce4-weather-plugin/0002-parsers-Generalise-input-to-array-of-gchar.patch')
-rw-r--r--meta-xfce/recipes-panel-plugins/weather/xfce4-weather-plugin/0002-parsers-Generalise-input-to-array-of-gchar.patch289
1 files changed, 289 insertions, 0 deletions
diff --git a/meta-xfce/recipes-panel-plugins/weather/xfce4-weather-plugin/0002-parsers-Generalise-input-to-array-of-gchar.patch b/meta-xfce/recipes-panel-plugins/weather/xfce4-weather-plugin/0002-parsers-Generalise-input-to-array-of-gchar.patch
new file mode 100644
index 0000000000..a76a7741bf
--- /dev/null
+++ b/meta-xfce/recipes-panel-plugins/weather/xfce4-weather-plugin/0002-parsers-Generalise-input-to-array-of-gchar.patch
@@ -0,0 +1,289 @@
1From 3c095487e3a6c14f2900762c18c6e2170d22a283 Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?=C4=90o=C3=A0n=20Tr=E1=BA=A7n=20C=C3=B4ng=20Danh?=
3 <congdanhqx@gmail.com>
4Date: Fri, 1 Mar 2024 21:56:34 +0700
5Subject: [PATCH 2/5] parsers: Generalise input to array of gchar
6
7In a later change, we will move to libsoup-3.0, which doesn't expose
8`response_body' in SoupMessage.
9
10Prepare for that move.
11
12Upstream-Status: Backport [https://github.com/xfce-mirror/xfce4-weather-plugin/commit/3c095487e3a6c14f2900762c18c6e2170d22a283]
13Signed-off-by: Khem Raj <raj.khem@gmail.com>
14---
15 panel-plugin/weather-config.c | 18 +++++++++++++++--
16 panel-plugin/weather-parsers.c | 36 ++++++++++++++++++----------------
17 panel-plugin/weather-parsers.h | 7 +++----
18 panel-plugin/weather-search.c | 18 +++++++++++++++--
19 panel-plugin/weather.c | 26 ++++++++++++++++++++----
20 5 files changed, 76 insertions(+), 29 deletions(-)
21
22diff --git a/panel-plugin/weather-config.c b/panel-plugin/weather-config.c
23index 2645408..19fa1d8 100644
24--- a/panel-plugin/weather-config.c
25+++ b/panel-plugin/weather-config.c
26@@ -245,6 +245,13 @@ cb_lookup_altitude(SoupSession *session,
27 xfceweather_dialog *dialog = (xfceweather_dialog *) user_data;
28 xml_altitude *altitude;
29 gdouble alt = 0;
30+ const gchar *body = NULL;
31+ gsize len = 0;
32+
33+ if (G_LIKELY(msg->response_body && msg->response_body->data)) {
34+ body = msg->response_body->data;
35+ len = msg->response_body->length;
36+ }
37
38 if (global_dialog == NULL) {
39 weather_debug("%s called after dialog was destroyed", G_STRFUNC);
40@@ -252,7 +259,7 @@ cb_lookup_altitude(SoupSession *session,
41 }
42
43 altitude = (xml_altitude *)
44- parse_xml_document(msg, (XmlParseFunc) parse_altitude);
45+ parse_xml_document(body, len, (XmlParseFunc) parse_altitude);
46
47 if (altitude) {
48 alt = string_to_double(altitude->altitude, -9999);
49@@ -274,6 +281,13 @@ cb_lookup_timezone(SoupSession *session,
50 {
51 xfceweather_dialog *dialog = (xfceweather_dialog *) user_data;
52 xml_timezone *xml_tz;
53+ const gchar *body = NULL;
54+ gsize len = 0;
55+
56+ if (G_LIKELY(msg->response_body && msg->response_body->data)) {
57+ body = msg->response_body->data;
58+ len = msg->response_body->length;
59+ }
60
61 if (global_dialog == NULL) {
62 weather_debug("%s called after dialog was destroyed", G_STRFUNC);
63@@ -281,7 +295,7 @@ cb_lookup_timezone(SoupSession *session,
64 }
65
66 xml_tz = (xml_timezone *)
67- parse_xml_document(msg, (XmlParseFunc) parse_timezone);
68+ parse_xml_document(body, len, (XmlParseFunc) parse_timezone);
69 weather_dump(weather_dump_timezone, xml_tz);
70
71 if (xml_tz) {
72diff --git a/panel-plugin/weather-parsers.c b/panel-plugin/weather-parsers.c
73index d53a2bc..28934c4 100644
74--- a/panel-plugin/weather-parsers.c
75+++ b/panel-plugin/weather-parsers.c
76@@ -791,49 +791,51 @@ parse_timezone(xmlNode *cur_node)
77
78
79 xmlDoc *
80-get_xml_document(SoupMessage *msg)
81+get_xml_document(const gchar *data, gsize len)
82 {
83- if (G_LIKELY(msg && msg->response_body && msg->response_body->data)) {
84- if (g_utf8_validate(msg->response_body->data, -1, NULL)) {
85+ if (G_LIKELY(data && len)) {
86+ if (g_utf8_validate(data, len, NULL)) {
87 /* force parsing as UTF-8, the XML encoding header may lie */
88- return xmlReadMemory(msg->response_body->data,
89- strlen(msg->response_body->data),
90+ return xmlReadMemory(data, len,
91 NULL, "UTF-8", 0);
92 } else {
93- return xmlParseMemory(msg->response_body->data,
94- strlen(msg->response_body->data));
95+ return xmlParseMemory(data, len);
96 }
97 }
98 return NULL;
99 }
100
101 json_object *
102-get_json_tree(SoupMessage *msg)
103+get_json_tree(const gchar *data, gsize len)
104 {
105 json_object *res=NULL;
106- enum json_tokener_error err;
107+ struct json_tokener *tok = json_tokener_new();
108
109- if (G_LIKELY(msg && msg->response_body && msg->response_body->data)) {
110- res = json_tokener_parse_verbose(msg->response_body->data, &err);
111- if (err != json_tokener_success)
112- g_warning("get_json_tree: error =%d",err);
113+ if (G_UNLIKELY(tok == NULL)) {
114+ return NULL;
115+ } else if (G_LIKELY(data && len)) {
116+ res = json_tokener_parse_ex(tok, data, len);
117+ if (res == NULL)
118+ g_warning("get_json_tree: error =%d",
119+ json_tokener_get_error(tok));
120 }
121+ json_tokener_free(tok);
122 return res;
123 }
124
125 gpointer
126-parse_xml_document(SoupMessage *msg,
127+parse_xml_document(const gchar *data, gsize len,
128 XmlParseFunc parse_func)
129 {
130 xmlDoc *doc;
131 xmlNode *root_node;
132 gpointer user_data = NULL;
133
134- g_assert(msg != NULL);
135- if (G_UNLIKELY(msg == NULL))
136+ g_assert(data != NULL);
137+ if (G_UNLIKELY(data == NULL || len == 0))
138 return NULL;
139
140- doc = get_xml_document(msg);
141+ doc = get_xml_document(data, len);
142 if (G_LIKELY(doc)) {
143 root_node = xmlDocGetRootElement(doc);
144 if (G_LIKELY(root_node))
145diff --git a/panel-plugin/weather-parsers.h b/panel-plugin/weather-parsers.h
146index a9d019d..09b9c02 100644
147--- a/panel-plugin/weather-parsers.h
148+++ b/panel-plugin/weather-parsers.h
149@@ -22,7 +22,6 @@
150 #include <glib.h>
151 #include <gtk/gtk.h>
152 #include <libxml/parser.h>
153-#include <libsoup/soup.h>
154 #include <json-c/json_tokener.h>
155
156 #define DATA_EXPIRY_TIME (24 * 3600)
157@@ -157,11 +156,11 @@ xml_astro *get_astro(const GArray *astrodata,
158 const time_t day_t,
159 guint *index);
160
161-xmlDoc *get_xml_document(SoupMessage *msg);
162+xmlDoc *get_xml_document(const gchar *data, gsize len);
163
164-json_object *get_json_tree(SoupMessage *msg);
165+json_object *get_json_tree(const gchar *data, gsize len);
166
167-gpointer parse_xml_document(SoupMessage *msg,
168+gpointer parse_xml_document(const gchar *data, gsize len,
169 XmlParseFunc parse_func);
170
171 xml_astro *xml_astro_copy(const xml_astro *src);
172diff --git a/panel-plugin/weather-search.c b/panel-plugin/weather-search.c
173index 7e87ae8..6a2ba1f 100644
174--- a/panel-plugin/weather-search.c
175+++ b/panel-plugin/weather-search.c
176@@ -89,6 +89,13 @@ cb_searchdone(SoupSession *session,
177 gint found = 0;
178 GtkTreeIter iter;
179 GtkTreeSelection *selection;
180+ const gchar *body = NULL;
181+ gsize len = 0;
182+
183+ if (G_LIKELY(msg->response_body && msg->response_body->data)) {
184+ body = msg->response_body->data;
185+ len = msg->response_body->length;
186+ }
187
188 if (global_dialog == NULL) {
189 weather_debug("%s called after dialog was destroyed", G_STRFUNC);
190@@ -97,7 +104,7 @@ cb_searchdone(SoupSession *session,
191
192 gtk_widget_set_sensitive(dialog->find_button, TRUE);
193
194- doc = get_xml_document(msg);
195+ doc = get_xml_document(body, len);
196 if (!doc)
197 return;
198
199@@ -385,6 +392,13 @@ cb_geolocation(SoupSession *session,
200 xml_geolocation *geo;
201 gchar *full_loc;
202 units_config *units;
203+ const gchar *body = NULL;
204+ gsize len = 0;
205+
206+ if (G_LIKELY(msg->response_body && msg->response_body->data)) {
207+ body = msg->response_body->data;
208+ len = msg->response_body->length;
209+ }
210
211 if (global_dialog == NULL) {
212 weather_debug("%s called after dialog was destroyed", G_STRFUNC);
213@@ -392,7 +406,7 @@ cb_geolocation(SoupSession *session,
214 }
215
216 geo = (xml_geolocation *)
217- parse_xml_document(msg, (XmlParseFunc) parse_geolocation);
218+ parse_xml_document(body, len, (XmlParseFunc) parse_geolocation);
219 weather_dump(weather_dump_geolocation, geo);
220
221 if (!geo) {
222diff --git a/panel-plugin/weather.c b/panel-plugin/weather.c
223index 0a92b4e..b75c633 100644
224--- a/panel-plugin/weather.c
225+++ b/panel-plugin/weather.c
226@@ -489,11 +489,17 @@ cb_astro_update_sun(SoupSession *session,
227 json_object *json_tree;
228 time_t now_t;
229 guint astro_forecast_days;
230+ const gchar *body = NULL;
231+ gsize len = 0;
232
233 data->msg_parse->sun_msg_processed++;
234 data->astro_update->http_status_code = msg->status_code;
235 if ((msg->status_code == 200 || msg->status_code == 203)) {
236- json_tree = get_json_tree(msg);
237+ if (G_LIKELY(msg->response_body && msg->response_body->data)) {
238+ body = msg->response_body->data;
239+ len = msg->response_body->length;
240+ }
241+ json_tree = get_json_tree(body, len);
242 if (G_LIKELY(json_tree)) {
243 if (!parse_astrodata_sun(json_tree, data->astrodata)) {
244 data->msg_parse->sun_msg_parse_error++;
245@@ -545,11 +551,17 @@ cb_astro_update_moon(SoupSession *session,
246 json_object *json_tree;
247 time_t now_t;
248 guint astro_forecast_days;
249+ const gchar *body = NULL;
250+ gsize len = 0;
251
252 data->msg_parse->moon_msg_processed++;
253 data->astro_update->http_status_code = msg->status_code;
254 if ((msg->status_code == 200 || msg->status_code == 203)) {
255- json_tree = get_json_tree(msg);
256+ if (G_LIKELY(msg->response_body && msg->response_body->data)) {
257+ body = msg->response_body->data;
258+ len = msg->response_body->length;
259+ }
260+ json_tree = get_json_tree(body, len);
261 if (G_LIKELY(json_tree)) {
262 if (!parse_astrodata_moon(json_tree, data->astrodata)) {
263 data->msg_parse->moon_msg_parse_error++;
264@@ -606,17 +618,23 @@ cb_weather_update(SoupSession *session,
265 gpointer user_data)
266 {
267 plugin_data *data = user_data;
268- xmlDoc *doc;
269+ xmlDoc *doc = NULL;
270 xmlNode *root_node;
271 time_t now_t;
272 gboolean parsing_error = TRUE;
273+ const gchar *body = NULL;
274+ gsize len = 0;
275
276 weather_debug("Processing downloaded weather data.");
277 time(&now_t);
278 data->weather_update->attempt++;
279 data->weather_update->http_status_code = msg->status_code;
280 if (msg->status_code == 200 || msg->status_code == 203) {
281- doc = get_xml_document(msg);
282+ if (G_LIKELY(msg->response_body && msg->response_body->data)) {
283+ body = msg->response_body->data;
284+ len = msg->response_body->length;
285+ }
286+ doc = get_xml_document(body, len);
287 if (G_LIKELY(doc)) {
288 root_node = xmlDocGetRootElement(doc);
289 if (G_LIKELY(root_node))