summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael BOUCHAUD <michael.bouchaud@gmail.com>2012-10-16 13:53:16 +0000
committerMichael BOUCHAUD <michael.bouchaud@gmail.com>2012-10-16 13:53:16 +0000
commit9867470c83c1b929fdea86a7efd084ae48138cbf (patch)
treef19f393893e684c9f641cfa3a2883ecbab429ced
parent15d7b94344ce0d17e6611ec411667109355951fc (diff)
libeweather: kill the google plugins, the webservice is down
SVN revision: 78062
-rw-r--r--configure.ac1
-rw-r--r--src/plugins/Makefile.am2
-rw-r--r--src/plugins/google/Makefile.am24
-rw-r--r--src/plugins/google/google.c407
-rw-r--r--src/plugins/google/google_logo.jpgbin283114 -> 0 bytes
5 files changed, 1 insertions, 433 deletions
diff --git a/configure.ac b/configure.ac
index abac9c0..98a53ad 100644
--- a/configure.ac
+++ b/configure.ac
@@ -134,7 +134,6 @@ src/bin/Makefile
134src/plugins/Makefile 134src/plugins/Makefile
135src/plugins/test/Makefile 135src/plugins/test/Makefile
136src/plugins/yahoo/Makefile 136src/plugins/yahoo/Makefile
137src/plugins/google/Makefile
138]) 137])
139 138
140echo 139echo
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am
index c5e216a..5b62bcc 100644
--- a/src/plugins/Makefile.am
+++ b/src/plugins/Makefile.am
@@ -1,4 +1,4 @@
1MAINTAINERCLEANFILES = Makefile.in 1MAINTAINERCLEANFILES = Makefile.in
2 2
3SUBDIRS = google test yahoo 3SUBDIRS = test yahoo
4 4
diff --git a/src/plugins/google/Makefile.am b/src/plugins/google/Makefile.am
deleted file mode 100644
index e9d6d56..0000000
--- a/src/plugins/google/Makefile.am
+++ /dev/null
@@ -1,24 +0,0 @@
1MAINTAINERCLEANFILES = Makefile.in
2
3icondir = $(pkgdatadir)
4icon_DATA = google_logo.jpg
5
6AM_CPPFLAGS = \
7-I$(top_srcdir)/src/plugins/google \
8-I$(top_srcdir)/src/lib \
9-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \
10@EFL_EWEATHER_BUILD@ \
11@EWEATHER_CFLAGS@
12
13pkgdir = $(pkglibdir)/plugins
14pkg_LTLIBRARIES = google.la
15
16google_la_SOURCES = google.c
17google_la_LIBADD = $(top_builddir)/src/lib/libeweather.la @EWEATHER_LIBS@
18google_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -module -avoid-version
19google_la_LIBTOOLFLAGS = --tag=disable-static
20
21EXTRA_DIST = google_logo.jpg
22
23clean-local:
24 rm -rf *~
diff --git a/src/plugins/google/google.c b/src/plugins/google/google.c
deleted file mode 100644
index 969e869..0000000
--- a/src/plugins/google/google.c
+++ /dev/null
@@ -1,407 +0,0 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <stdio.h>
6
7#include <Ecore.h>
8#include <Ecore_Con.h>
9
10#include "EWeather_Plugins.h"
11
12typedef struct Instance Instance;
13
14static void _init(EWeather *eweather);
15static void _shutdown(EWeather *eweather);
16static void _poll_time_updated(EWeather *eweather);
17static void _code_updated(EWeather *eweather);
18static Eina_Bool _server_add(void *data, int type, void *event);
19static Eina_Bool _server_del(void *data, int type, void *event);
20static Eina_Bool _server_error(void *data, int type, void *event);
21static Eina_Bool _server_data(void *data, int type, void *event);
22static Eina_Bool _weather_cb_check(void *data);
23static EWeather_Type _weather_type_get(const char* id);
24static Eina_Bool _server_data(void *data, int type, void *event);
25static int _parse(Instance* inst);
26
27
28struct _Id_Type
29{
30 const char * id;
31 EWeather_Type type;
32};
33
34static struct _Id_Type _tab[] =
35{
36 {"Chance of Ice", EWEATHER_TYPE_SNOW},
37 {"Chance of Rain", EWEATHER_TYPE_RAIN},
38 {"Chance of Showers", EWEATHER_TYPE_RAIN},
39 {"Chance of Snow", EWEATHER_TYPE_SNOW},
40 {"Chance of Storm", EWEATHER_TYPE_ISOLATED_THUNDERSTORMS},
41 {"Clear", EWEATHER_TYPE_SUNNY},
42 {"Cloudy", EWEATHER_TYPE_CLOUDY},
43 {"Drizzle", EWEATHER_TYPE_RAIN},
44 {"Dust", EWEATHER_TYPE_FOGGY}, /* not sure */
45 {"Fog", EWEATHER_TYPE_FOGGY},
46 {"Flurries", EWEATHER_TYPE_SNOW}, /* not sure */
47 {"Haze", EWEATHER_TYPE_FOGGY}, /* not sure */
48 {"Icy", EWEATHER_TYPE_SNOW}, /* not sure */
49 {"Isolated Thunderstorms", EWEATHER_TYPE_ISOLATED_THUNDERSTORMS},
50 {"Light Rain", EWEATHER_TYPE_RAIN},
51 {"Light Snow", EWEATHER_TYPE_SNOW},
52 {"Mist", EWEATHER_TYPE_FOGGY}, /* not sure */
53 {"Overcast", EWEATHER_TYPE_CLOUDY},
54 {"Mostly Cloudy", EWEATHER_TYPE_MOSTLY_CLOUDY_DAY},
55 {"Mostly Sunny", EWEATHER_TYPE_PARTLY_CLOUDY_DAY},
56 {"Overcast", EWEATHER_TYPE_CLOUDY},
57 {"Partly Cloudy", EWEATHER_TYPE_PARTLY_CLOUDY_DAY},
58 {"Partly Sunny", EWEATHER_TYPE_PARTLY_CLOUDY_DAY},
59 {"Rain", EWEATHER_TYPE_RAIN},
60 {"Scattered Showers", EWEATHER_TYPE_RAIN},
61 {"Scattered Thunderstorms", EWEATHER_TYPE_SCATTERED_THUNDERSTORMS},
62 {"Showers", EWEATHER_TYPE_RAIN},
63 {"Sunny", EWEATHER_TYPE_SUNNY},
64 {"Sleet", EWEATHER_TYPE_RAIN_SNOW}, /* not sure */
65 {"Smoke", EWEATHER_TYPE_FOGGY},
66 {"Snow", EWEATHER_TYPE_SNOW},
67 {"Snow Showers", EWEATHER_TYPE_RAIN_SNOW},
68 {"Thunderstorm", EWEATHER_TYPE_THUNDERSTORMS},
69 {"Thunderstorms", EWEATHER_TYPE_THUNDERSTORMS},
70 {"Windy", EWEATHER_TYPE_WINDY},
71 {"", EWEATHER_TYPE_UNKNOWN}
72// {"/ig/images/weather/rain_snow.gif", EWEATHER_TYPE_RAIN_SNOW},
73};
74
75struct Instance
76{
77 EWeather *weather;
78
79 Ecore_Con_Server *server;
80 Ecore_Event_Handler *add_handler;
81 Ecore_Event_Handler *del_handler;
82 Ecore_Event_Handler *err_handler;
83 Ecore_Event_Handler *data_handler;
84 Ecore_Timer *check_timer;
85
86 char *buffer, *location;
87 int bufsize, cursize;
88
89 const char *host;
90};
91
92EAPI EWeather_Plugin _plugin_class =
93{
94 "Google",
95 "http://www.google.fr/",
96 PACKAGE_DATA_DIR"/google_logo.jpg",
97 _init,
98 _shutdown,
99 _poll_time_updated,
100 _code_updated
101};
102
103static void _init(EWeather *eweather)
104{
105 Instance *inst = calloc(1, sizeof(Instance));
106 eweather->plugin.data = inst;
107 inst->weather = eweather;
108 inst->host = eina_stringshare_add("www.google.com");
109
110 printf("INIT %d\n",ecore_con_init());
111
112 inst->add_handler =
113 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD,
114 _server_add, inst);
115 inst->del_handler =
116 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL,
117 _server_del, inst);
118 inst->err_handler =
119 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ERROR,
120 _server_error, inst);
121 inst->data_handler =
122 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA,
123 _server_data, inst);
124
125 inst->check_timer =
126 ecore_timer_add(0, _weather_cb_check, inst);
127}
128
129static void _shutdown(EWeather *eweather)
130{
131 Instance *inst = eweather->plugin.data;
132
133 if (inst->host) eina_stringshare_del(inst->host);
134
135 if (inst->buffer) free(inst->buffer);
136
137 if (inst->check_timer) ecore_timer_del(inst->check_timer);
138 if (inst->add_handler) ecore_event_handler_del(inst->add_handler);
139 if (inst->data_handler) ecore_event_handler_del(inst->data_handler);
140 if (inst->err_handler) ecore_event_handler_del(inst->err_handler);
141 if (inst->del_handler) ecore_event_handler_del(inst->del_handler);
142 if (inst->server) ecore_con_server_del(inst->server);
143
144 ecore_con_shutdown();
145
146 free(inst);
147}
148
149static void _poll_time_updated(EWeather *eweather)
150{
151 Instance *inst = eweather->plugin.data;
152
153 if(inst->check_timer)
154 ecore_timer_del(inst->check_timer);
155
156 inst->check_timer =
157 ecore_timer_add(0, _weather_cb_check, inst);
158}
159
160static void _code_updated(EWeather *eweather)
161{
162 Instance *inst = eweather->plugin.data;
163
164 if(inst->check_timer)
165 ecore_timer_del(inst->check_timer);
166
167 inst->check_timer =
168 ecore_timer_add(0, _weather_cb_check, inst);
169}
170
171 static Eina_Bool
172_weather_cb_check(void *data)
173{
174 Instance *inst;
175
176 printf("CHECK\n");
177 if (!(inst = data)) return EINA_FALSE;
178 if (inst->server) ecore_con_server_del(inst->server);
179 inst->server = NULL;
180
181 if (inst->weather->proxy.port != 0)
182 inst->server =
183 ecore_con_server_connect(ECORE_CON_REMOTE_SYSTEM, inst->weather->proxy.host,
184 inst->weather->proxy.port, inst);
185 else
186 {
187 inst->server =
188 ecore_con_server_connect(ECORE_CON_REMOTE_SYSTEM, inst->host, 80, inst);
189
190 printf("CHECX %p\n", inst->server);
191 }
192
193 if (!inst->server) return EINA_FALSE;
194
195 ecore_timer_interval_set(inst->check_timer, inst->weather->poll_time);
196 return EINA_TRUE;
197}
198
199 static Eina_Bool
200_server_add(void *data, int type, void *event)
201{
202 Instance *inst;
203 Ecore_Con_Event_Server_Add *ev;
204 char buf[1024];
205 char *s;
206 int i;
207
208 printf("SERVER ADD\n");
209 if (!(inst = data)) return EINA_TRUE;
210 if(!inst->weather->code) return EINA_FALSE;
211
212 ev = event;
213 if ((!inst->server) || (inst->server != ev->server)) return EINA_TRUE;
214
215 s = strdup(inst->weather->code);
216 for(i=0; i<strlen(s); i++)
217 if(s[i] == ' ')
218 s[i] = '+';
219
220 snprintf(buf, sizeof(buf), "GET http://%s/ig/api?weather=%s HTTP/1.1\r\nHost: %s\r\n\r\n",
221 inst->host, s, inst->host);
222
223 ecore_con_server_send(inst->server, buf, strlen (buf));
224 return EINA_FALSE;
225}
226
227 static Eina_Bool
228_server_del(void *data, int type, void *event)
229{
230 Instance *inst;
231 Ecore_Con_Event_Server_Del *ev;
232 int ret;
233
234 inst = data;
235 ev = event;
236
237 if ((!inst->server) || (inst->server != ev->server)) return EINA_TRUE;
238
239 ecore_con_server_del(inst->server);
240 inst->server = NULL;
241
242 ret = _parse(inst);
243
244 inst->bufsize = 0;
245 inst->cursize = 0;
246
247 if(inst->buffer) free(inst->buffer);
248 inst->buffer = NULL;
249 return EINA_FALSE;
250}
251
252static Eina_Bool
253_server_error(void *data, int type, void *event)
254{
255 Instance *inst;
256 Ecore_Con_Event_Server_Error *ev;
257
258 inst = data;
259 ev = event;
260 if ((!inst->server) || (inst->server != ev->server)) return EINA_TRUE;
261
262 fprintf(stderr, "Connection error to %s : %s\n",
263 ecore_con_server_name_get(inst->server) ,ev->error);
264
265 return EINA_FALSE;
266}
267
268 static Eina_Bool
269_server_data(void *data, int type, void *event)
270{
271 Instance *inst;
272 Ecore_Con_Event_Server_Data *ev;
273
274 inst = data;
275 ev = event;
276
277 if ((!inst->server) || (inst->server != ev->server)) return EINA_TRUE;
278
279 while ((inst->cursize + ev->size) >= inst->bufsize)
280 {
281 inst->bufsize += 4096;
282 inst->buffer = realloc(inst->buffer, inst->bufsize);
283 }
284
285 memcpy(inst->buffer + inst->cursize, ev->data, ev->size);
286 inst->cursize += ev->size;
287 inst->buffer[inst->cursize] = 0;
288
289 _parse(inst);
290
291 return EINA_FALSE;
292}
293
294 static int
295_parse(Instance *inst)
296{
297 char *needle;
298 char location[1024];
299 char day[1024];
300 char date[1024];
301 EWeather_Data *e_data = eweather_data_current_get(inst->weather);
302 EWeather_Data *e_data_current;
303 char code[1024];
304 int i;
305
306 location[0] = 0;
307
308 if (!inst->buffer) return 0;
309
310 //printf("%s\n", inst->buffer);
311
312 needle = strstr(inst->buffer, "<city data=\"");
313 if (!needle) goto error;
314 needle+=12;
315 sscanf(needle, "%[^\"]\"", e_data->city);
316
317 needle = strstr(needle, "<current_date_time data=\"");
318 if (!needle) goto error;
319 needle+=25;
320 sscanf(needle, "%[^+]+", date);
321
322 needle = strstr(needle, "<condition data=\"");
323 if (!needle) goto error;
324 needle += 17;
325 sscanf(needle, "%[^\"]\"", code);
326
327 e_data->type = _weather_type_get(code);
328
329 needle = strstr(needle, "<temp_f data=\"");
330 if (!needle) goto error;
331 needle+=14;
332 sscanf(needle, "%lf\"", &(e_data->temp));
333
334 needle = strstr(needle, "<day_of_week data=\"");
335 if (!needle) goto error;
336 needle += 19;
337 sscanf(needle, "%[^\"]\"", day);
338
339 snprintf(e_data->date, 256, "%s %s", day, date);
340
341
342 needle = strstr(needle, "<low data=\"");
343 if (!needle) goto error;
344 needle+=11;
345 sscanf(needle, "%lf\"", &(e_data->temp_min));
346
347 needle = strstr(needle, "<high data=\"");
348 if (!needle) goto error;
349 needle+=12;
350 sscanf(needle, "%lf\"", &(e_data->temp_max));
351
352 e_data_current = e_data;
353
354 for(i=1; i<4; i++)
355 {
356 e_data = eweather_data_get(inst->weather, i);
357
358 needle = strstr(needle, "<day_of_week data=\"");
359 if (!needle) goto error;
360 needle+= 19;
361 sscanf(needle, "%[^\"]\"", e_data->date);
362
363 needle = strstr(needle, "<low data=\"");
364 if (!needle) goto error;
365 needle+=11;
366 sscanf(needle, "%lf\"", &(e_data->temp_min));
367
368 needle = strstr(needle, "<high data=\"");
369 if (!needle) goto error;
370 needle+=12;
371 sscanf(needle, "%lf\"", &(e_data->temp_max));
372
373 e_data->temp = ( e_data->temp_min + e_data->temp_max ) / 2;
374
375 needle = strstr(needle, "<condition data=\"");
376 if (!needle) goto error;
377 needle += 17;
378 sscanf(needle, "%[^\"]\"", code);
379
380 e_data->type = _weather_type_get(code);
381
382 strcpy(e_data->country, e_data_current->country);
383 strcpy(e_data->region, e_data_current->region);
384 strcpy(e_data->city, e_data_current->city);
385 }
386
387 eweather_plugin_update(inst->weather);
388 return 1;
389error:
390 //printf ("ERROR: Couldn't parse info\n");
391 return 0;
392}
393
394
395
396
397static EWeather_Type _weather_type_get(const char *id)
398{
399 int i;
400 for (i = 0; i < sizeof (_tab) / sizeof (struct _Id_Type); ++i)
401 if ( !strcasecmp(_tab[i].id, id))
402 {
403 return _tab[i].type;
404 }
405
406 return EWEATHER_TYPE_UNKNOWN;
407}
diff --git a/src/plugins/google/google_logo.jpg b/src/plugins/google/google_logo.jpg
deleted file mode 100644
index f959e39..0000000
--- a/src/plugins/google/google_logo.jpg
+++ /dev/null
Binary files differ