]> git.sesse.net Git - vlc/blob - modules/video_filter/rss.c
if ttl==0, don't update the feeds
[vlc] / modules / video_filter / rss.c
1 /*****************************************************************************
2  * rss.c : rss feed display video plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2003-2005 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <string.h>
29
30 #include <vlc/vlc.h>
31 #include <vlc/vout.h>
32
33 #include "vlc_filter.h"
34 #include "vlc_block.h"
35 #include "osd.h"
36
37 #include "vlc_block.h"
38 #include "vlc_stream.h"
39 #include "vlc_xml.h"
40
41 /*****************************************************************************
42  * Local prototypes
43  *****************************************************************************/
44 static int  CreateFilter ( vlc_object_t * );
45 static void DestroyFilter( vlc_object_t * );
46 static subpicture_t *Filter( filter_t *, mtime_t );
47
48 static int FetchRSS( filter_t * );
49 static void FreeRSS( filter_t * );
50
51 static int pi_color_values[] = { 0xf0000000, 0x00000000, 0x00808080, 0x00C0C0C0,
52                0x00FFFFFF, 0x00800000, 0x00FF0000, 0x00FF00FF, 0x00FFFF00,
53                0x00808000, 0x00008000, 0x00008080, 0x0000FF00, 0x00800080,
54                0x00000080, 0x000000FF, 0x0000FFFF};
55 static char *ppsz_color_descriptions[] = { N_("Default"), N_("Black"),
56                N_("Gray"), N_("Silver"), N_("White"), N_("Maroon"), N_("Red"),
57                N_("Fuchsia"), N_("Yellow"), N_("Olive"), N_("Green"),
58                N_("Teal"), N_("Lime"), N_("Purple"), N_("Navy"), N_("Blue"),
59                N_("Aqua") };
60
61 /*****************************************************************************
62  * filter_sys_t: rss filter descriptor
63  *****************************************************************************/
64
65 struct rss_item_t
66 {
67     char *psz_title;
68     char *psz_description;
69     char *psz_link;
70 };
71
72 struct rss_feed_t
73 {
74     char *psz_title;
75     char *psz_description;
76     char *psz_link;
77
78     int i_items;
79     struct rss_item_t *p_items;
80 };
81
82 struct filter_sys_t
83 {
84     vlc_mutex_t lock;
85     vlc_mutex_t *p_lock;
86
87     int i_xoff, i_yoff;  /* offsets for the display string in the video window */
88     int i_pos; /* permit relative positioning (top, bottom, left, right, center) */
89     int i_speed;
90     int i_length;
91
92     char *psz_marquee;    /* marquee string */
93
94     int  i_font_color, i_font_opacity, i_font_size; /* font control */
95
96     mtime_t last_date;
97
98     char *psz_urls;
99     int i_feeds;
100     struct rss_feed_t *p_feeds;
101
102     int i_ttl;
103     time_t t_last_update;
104
105     int i_cur_feed;
106     int i_cur_item;
107     int i_cur_char;
108 };
109
110 #define MSG_TEXT N_("RSS feed URLs")
111 #define MSG_LONGTEXT N_("RSS feed '|' (pipe) seperated URLs")
112 #define SPEED_TEXT N_("RSS feed speed")
113 #define SPEED_LONGTEXT N_("RSS feed speed (bigger is slower)")
114 #define LENGTH_TEXT N_("RSS feed max number of chars displayed")
115 #define LENGTH_LONGTEXT N_("RSS feed max number of chars displayed")
116 #define TTL_TEXT N_("Number of seconds between each forced refresh of the feeds")
117 #define TTL_LONGTEXT N_("Number of seconds between each forced refresh of the feeds. If 0, the feeds will never be updated.")
118
119
120 #define POSX_TEXT N_("X offset, from left")
121 #define POSX_LONGTEXT N_("X offset, from the left screen edge" )
122 #define POSY_TEXT N_("Y offset, from the top")
123 #define POSY_LONGTEXT N_("Y offset, down from the top" )
124 #define OPACITY_TEXT N_("Opacity")
125 #define OPACITY_LONGTEXT N_("The opacity (inverse of transparency) of " \
126     "overlay text. 0 = transparent, 255 = totally opaque. " )
127 #define SIZE_TEXT N_("Font size, pixels")
128 #define SIZE_LONGTEXT N_("Specify the font size, in pixels, " \
129     "with -1 = use freetype-fontsize" )
130
131 #define COLOR_TEXT N_("Text Default Color")
132 #define COLOR_LONGTEXT N_("The color of overlay text. 1 byte for each color, hexadecimal. " \
133     "#000000 = all colors off, " \
134     "0xFF0000 = just Red, 0xFFFFFF = all color on [White]" )
135
136 #define POS_TEXT N_("Marquee position")
137 #define POS_LONGTEXT N_( \
138   "You can enforce the marquee position on the video " \
139   "(0=center, 1=left, 2=right, 4=top, 8=bottom, you can " \
140   "also use combinations of these values by adding them).")
141
142 static int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
143 static char *ppsz_pos_descriptions[] =
144      { N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
145      N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };
146
147 /*****************************************************************************
148  * Module descriptor
149  *****************************************************************************/
150 vlc_module_begin();
151     set_capability( "sub filter", 0 );
152     set_shortname( N_("RSS" ));
153     set_callbacks( CreateFilter, DestroyFilter );
154     set_category( CAT_VIDEO );
155     set_subcategory( SUBCAT_VIDEO_SUBPIC );
156     add_string( "rss-urls", "rss", NULL, MSG_TEXT, MSG_LONGTEXT, VLC_FALSE );
157
158     set_section( N_("Position"), NULL );
159     add_integer( "rss-x", -1, NULL, POSX_TEXT, POSX_LONGTEXT, VLC_FALSE );
160     add_integer( "rss-y", 0, NULL, POSY_TEXT, POSY_LONGTEXT, VLC_FALSE );
161     add_integer( "rss-position", 5, NULL, POS_TEXT, POS_LONGTEXT, VLC_TRUE );
162
163     set_section( N_("Font"), NULL );
164     /* 5 sets the default to top [1] left [4] */
165     change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 );
166     add_integer_with_range( "rss-opacity", 255, 0, 255, NULL,
167         OPACITY_TEXT, OPACITY_LONGTEXT, VLC_FALSE );
168     add_integer( "rss-color", 0xFFFFFF, NULL, COLOR_TEXT, COLOR_LONGTEXT, VLC_TRUE );
169         change_integer_list( pi_color_values, ppsz_color_descriptions, 0 );
170     add_integer( "rss-size", -1, NULL, SIZE_TEXT, SIZE_LONGTEXT, VLC_FALSE );
171
172     set_section( N_("Misc"), NULL );
173     add_integer( "rss-speed", 100000, NULL, SPEED_TEXT, SPEED_LONGTEXT,
174                  VLC_FALSE );
175     add_integer( "rss-length", 60, NULL, LENGTH_TEXT, LENGTH_LONGTEXT,
176                  VLC_FALSE );
177     add_integer( "rss-ttl", 900, NULL, TTL_TEXT, TTL_LONGTEXT, VLC_FALSE );
178
179     set_description( _("RSS feed display sub filter") );
180     add_shortcut( "rss" );
181 vlc_module_end();
182
183 /*****************************************************************************
184  * CreateFilter: allocates RSS video filter
185  *****************************************************************************/
186 static int CreateFilter( vlc_object_t *p_this )
187 {
188     filter_t *p_filter = (filter_t *)p_this;
189     filter_sys_t *p_sys;
190     int i_feed;
191
192     /* Allocate structure */
193     p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
194     if( p_sys == NULL )
195     {
196         msg_Err( p_filter, "out of memory" );
197         return VLC_ENOMEM;
198     }
199
200     vlc_mutex_init( p_filter, &p_sys->lock );
201     vlc_mutex_lock( &p_sys->lock );
202
203     p_sys->psz_urls = var_CreateGetString( p_filter, "rss-urls" );
204     p_sys->i_cur_feed = 0;
205     p_sys->i_cur_item = 0;
206     p_sys->i_cur_char = 0;
207     p_sys->i_feeds = 0;
208     p_sys->p_feeds = NULL;
209     p_sys->i_speed = var_CreateGetInteger( p_filter, "rss-speed" );
210     p_sys->i_length = var_CreateGetInteger( p_filter, "rss-length" );
211     p_sys->i_ttl = __MAX( 0, var_CreateGetInteger( p_filter, "rss-ttl" ) );
212     p_sys->psz_marquee = (char *)malloc( p_sys->i_length );
213
214     p_sys->i_xoff = var_CreateGetInteger( p_filter, "rss-x" );
215     p_sys->i_yoff = var_CreateGetInteger( p_filter, "rss-y" );
216     p_sys->i_pos = var_CreateGetInteger( p_filter, "rss-position" );
217     var_Create( p_filter, "rss-opacity", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
218     p_sys->i_font_opacity = var_CreateGetInteger( p_filter, "rss-opacity" );
219     p_sys->i_font_color = var_CreateGetInteger( p_filter, "rss-color" );
220     p_sys->i_font_size = var_CreateGetInteger( p_filter, "rss-size" );
221
222     if( FetchRSS( p_filter ) )
223     {
224         msg_Err( p_filter, "failed while fetching RSS ... too bad" );
225         vlc_mutex_unlock( &p_sys->lock );
226         return VLC_EGENERIC;
227     }
228     p_sys->t_last_update = time( NULL );
229
230     if( p_sys->i_feeds == 0 )
231     {
232         vlc_mutex_unlock( &p_sys->lock );
233         return VLC_EGENERIC;
234     }
235     for( i_feed=0; i_feed < p_sys->i_feeds; i_feed ++ )
236         if( p_sys->p_feeds[i_feed].i_items == 0 )
237         {
238             vlc_mutex_unlock( &p_sys->lock );
239             return VLC_EGENERIC;
240         }
241
242     /* Misc init */
243     p_filter->pf_sub_filter = Filter;
244     p_sys->last_date = (mtime_t)0;
245
246     vlc_mutex_unlock( &p_sys->lock );
247
248     return VLC_SUCCESS;
249 }
250 /*****************************************************************************
251  * DestroyFilter: destroy RSS video filter
252  *****************************************************************************/
253 static void DestroyFilter( vlc_object_t *p_this )
254 {
255     filter_t *p_filter = (filter_t *)p_this;
256     filter_sys_t *p_sys = p_filter->p_sys;
257
258     vlc_mutex_lock( &p_sys->lock );
259
260     if( p_sys->psz_marquee ) free( p_sys->psz_marquee );
261     free( p_sys->psz_urls );
262     FreeRSS( p_filter );
263     vlc_mutex_unlock( &p_sys->lock );
264     vlc_mutex_destroy( &p_sys->lock );
265     free( p_sys );
266
267     /* Delete the RSS variables */
268     var_Destroy( p_filter, "rss-urls" );
269     var_Destroy( p_filter, "rss-speed" );
270     var_Destroy( p_filter, "rss-length" );
271     var_Destroy( p_filter, "rss-ttl" );
272     var_Destroy( p_filter, "rss-x" );
273     var_Destroy( p_filter, "rss-y" );
274     var_Destroy( p_filter, "rss-position" );
275     var_Destroy( p_filter, "rss-color");
276     var_Destroy( p_filter, "rss-opacity");
277     var_Destroy( p_filter, "rss-size");
278 }
279
280 /****************************************************************************
281  * Filter: the whole thing
282  ****************************************************************************
283  * This function outputs subpictures at regular time intervals.
284  ****************************************************************************/
285 static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
286 {
287     filter_sys_t *p_sys = p_filter->p_sys;
288     subpicture_t *p_spu;
289     video_format_t fmt;
290
291     int i_feed, i_item;
292
293     vlc_mutex_lock( &p_sys->lock );
294
295     if( p_sys->last_date
296        + ( p_sys->i_cur_char == 0 && p_sys->i_cur_item == 0 ? 5 : 1 )
297            /* ( ... ? 5 : 1 ) means "wait more for the 1st char" */
298        * p_sys->i_speed > date )
299     {
300         vlc_mutex_unlock( &p_sys->lock );
301         return NULL;
302     }
303
304     /* Do we need to update the feeds ? */
305     if( p_sys->i_ttl
306         && time( NULL ) > p_sys->t_last_update + (time_t)p_sys->i_ttl )
307     {
308         msg_Dbg( p_filter, "Forcing update of all the RSS feeds" );
309         if( FetchRSS( p_filter ) )
310         {
311             msg_Err( p_filter, "failed while fetching RSS ... too bad" );
312             vlc_mutex_unlock( &p_sys->lock );
313             return NULL; /* FIXME : we most likely messed up all the data,
314                           * so we might need to do something about it */
315         }
316         p_sys->t_last_update = time( NULL );
317     }
318
319     p_sys->last_date = date;
320     p_sys->i_cur_char++;
321     if( p_sys->p_feeds[p_sys->i_cur_feed].p_items[p_sys->i_cur_item].psz_title[p_sys->i_cur_char] == 0 )
322     {
323         p_sys->i_cur_char = 0;
324         p_sys->i_cur_item++;
325         if( p_sys->i_cur_item >= p_sys->p_feeds[p_sys->i_cur_feed].i_items )
326         {
327             p_sys->i_cur_item = 0;
328             p_sys->i_cur_feed = (p_sys->i_cur_feed + 1)%p_sys->i_feeds;
329         }
330     }
331
332     p_spu = p_filter->pf_sub_buffer_new( p_filter );
333     if( !p_spu )
334     {
335         vlc_mutex_unlock( &p_sys->lock );
336         return NULL;
337     }
338
339     memset( &fmt, 0, sizeof(video_format_t) );
340     fmt.i_chroma = VLC_FOURCC('T','E','X','T');
341     fmt.i_aspect = 0;
342     fmt.i_width = 0;
343     fmt.i_height = 0;
344     fmt.i_x_offset = 0;
345     fmt.i_y_offset = 0;
346     p_spu->p_region = p_spu->pf_create_region( VLC_OBJECT(p_filter), &fmt );
347     if( !p_spu->p_region )
348     {
349         p_filter->pf_sub_buffer_del( p_filter, p_spu );
350         vlc_mutex_unlock( &p_sys->lock );
351         return NULL;
352     }
353
354     i_item = p_sys->i_cur_item;
355     i_feed = p_sys->i_cur_feed;
356     snprintf( p_sys->psz_marquee, p_sys->i_length, "%s : %s", p_sys->p_feeds[i_feed].psz_title, p_sys->p_feeds[i_feed].p_items[i_item].psz_title+p_sys->i_cur_char );
357     while( strlen( p_sys->psz_marquee ) < (unsigned int)p_sys->i_length )
358     {
359         i_item++;
360         if( i_item == p_sys->p_feeds[i_feed].i_items ) break;
361         snprintf( strchr( p_sys->psz_marquee, 0 ), p_sys->i_length - strlen( p_sys->psz_marquee ), " - %s", p_sys->p_feeds[i_feed].p_items[i_item].psz_title );
362     }
363
364     p_spu->p_region->psz_text = strdup(p_sys->psz_marquee);
365     p_spu->i_start = date;
366     p_spu->i_stop  = 0;
367     p_spu->b_ephemer = VLC_TRUE;
368
369     /*  where to locate the string: */
370     if( p_sys->i_xoff < 0 || p_sys->i_yoff < 0 )
371     {   /* set to one of the 9 relative locations */
372         p_spu->i_flags = p_sys->i_pos;
373         p_spu->i_x = 0;
374         p_spu->i_y = 0;
375         p_spu->b_absolute = VLC_FALSE;
376     }
377     else
378     {   /*  set to an absolute xy, referenced to upper left corner */
379         p_spu->i_flags = OSD_ALIGN_LEFT | OSD_ALIGN_TOP;
380         p_spu->i_x = p_sys->i_xoff;
381         p_spu->i_y = p_sys->i_yoff;
382         p_spu->b_absolute = VLC_TRUE;
383     }
384     p_spu->i_height = 1;
385     p_spu->p_region->i_text_color = p_sys->i_font_color;
386     p_spu->p_region->i_text_alpha = 255 - p_sys->i_font_opacity;
387     p_spu->p_region->i_text_size = p_sys->i_font_size;
388
389     vlc_mutex_unlock( &p_sys->lock );
390     return p_spu;
391 }
392
393 /****************************************************************************
394  * RSS related functions
395  ****************************************************************************
396  * You should always lock the p_filter mutex before using any of these
397  * functions
398  ***************************************************************************/
399
400 /****************************************************************************
401  * FetchRSS
402  ***************************************************************************/
403 static int FetchRSS( filter_t *p_filter)
404 {
405     filter_sys_t *p_sys = p_filter->p_sys;
406
407     stream_t *p_stream = NULL;
408     xml_t *p_xml = NULL;
409     xml_reader_t *p_xml_reader = NULL;
410
411     char *psz_eltname = NULL;
412     char *psz_eltvalue = NULL;
413     char *psz_feed = NULL;
414     char *psz_buffer = NULL;
415     char *psz_buffer_2 = NULL;
416
417     int i_feed;
418     int i_item;
419     int i_is_item;
420     int i_int;
421
422     FreeRSS( p_filter );
423     p_sys->i_feeds = 1;
424     i_int = 0;
425     while( p_sys->psz_urls[i_int] != 0 )
426         if( p_sys->psz_urls[i_int++] == '|' )
427             p_sys->i_feeds++;
428     p_sys->p_feeds = (struct rss_feed_t *)malloc( p_sys->i_feeds
429                                 * sizeof( struct rss_feed_t ) );
430
431     p_xml = xml_Create( p_filter );
432     if( !p_xml )
433     {
434         msg_Err( p_filter, "Failed to open XML parser" );
435         return 1;
436     }
437
438     psz_buffer = strdup( p_sys->psz_urls );
439     psz_buffer_2 = psz_buffer; /* keep track so we can free it */
440     for( i_feed = 0; i_feed < p_sys->i_feeds; i_feed++ )
441     {
442         struct rss_feed_t *p_feed = p_sys->p_feeds+i_feed;
443
444         if( psz_buffer == NULL ) break;
445         if( psz_buffer[0] == 0 ) psz_buffer++;
446         psz_feed = psz_buffer;
447         psz_buffer = strchr( psz_buffer, '|' );
448         if( psz_buffer != NULL ) psz_buffer[0] = 0;
449
450         p_feed->psz_title = NULL;
451         p_feed->psz_description = NULL;
452         p_feed->psz_link = NULL;
453         p_feed->i_items = 0;
454         p_feed->p_items = NULL;
455
456         msg_Dbg( p_filter, "Opening %s RSS feed ...", psz_feed );
457
458         p_stream = stream_UrlNew( p_filter, psz_feed );
459         if( !p_stream )
460         {
461             msg_Err( p_filter, "Failed to open %s for reading", psz_feed );
462             return 1;
463         }
464
465         p_xml_reader = xml_ReaderCreate( p_xml, p_stream );
466         if( !p_xml_reader )
467         {
468             msg_Err( p_filter, "Failed to open %s for parsing", psz_feed );
469             return 1;
470         }
471
472         i_item = 0;
473         i_is_item = VLC_FALSE;
474
475         while( xml_ReaderRead( p_xml_reader ) == 1 )
476         {
477             switch( xml_ReaderNodeType( p_xml_reader ) )
478             {
479                 // Error
480                 case -1:
481                     return 1;
482
483                 case XML_READER_STARTELEM:
484                     if( psz_eltname )
485                     {
486                         free( psz_eltname );
487                         psz_eltname = NULL;
488                     }
489                     psz_eltname = xml_ReaderName( p_xml_reader );
490                     if( !psz_eltname )
491                     {
492                         return 1;
493                     }
494 #                   ifdef RSS_DEBUG
495                     msg_Dbg( p_filter, "element name : %s", psz_eltname );
496 #                   endif
497                     if( !strcmp( psz_eltname, "item" ) )
498                     {
499                         i_is_item = VLC_TRUE;
500                         p_feed->i_items++;
501                         p_feed->p_items = (struct rss_item_t *)realloc( p_feed->p_items, p_feed->i_items * sizeof( struct rss_item_t ) );
502                         p_feed->p_items[p_feed->i_items-1].psz_title = NULL;
503                         p_feed->p_items[p_feed->i_items-1].psz_description
504                                                                      = NULL;
505                         p_feed->p_items[p_feed->i_items-1].psz_link = NULL;
506                     }
507                     break;
508
509                 case XML_READER_ENDELEM:
510                     if( psz_eltname )
511                     {
512                         free( psz_eltname );
513                         psz_eltname = NULL;
514                     }
515                     psz_eltname = xml_ReaderName( p_xml_reader );
516                     if( !psz_eltname )
517                     {
518                         return 1;
519                     }
520 #                   ifdef RSS_DEBUG
521                     msg_Dbg( p_filter, "element end : %s", psz_eltname );
522 #                   endif
523                     if( !strcmp( psz_eltname, "item" ) )
524                     {
525                         i_is_item = VLC_FALSE;
526                         i_item++;
527                     }
528                     free( psz_eltname );
529                     psz_eltname = NULL;
530                     break;
531
532                 case XML_READER_TEXT:
533                     psz_eltvalue = xml_ReaderValue( p_xml_reader );
534                     if( !psz_eltvalue )
535                     {
536                         return 1;
537                     }
538 #                   ifdef RSS_DEBUG
539                     msg_Dbg( p_filter, "  text : %s", psz_eltvalue );
540 #                   endif
541                     if( i_is_item == VLC_FALSE )
542                     {
543                         if( !strcmp( psz_eltname, "title" ) )
544                         {
545                             p_feed->psz_title = psz_eltvalue;
546                         }
547                         else if( !strcmp( psz_eltname, "link" ) )
548                         {
549                             p_feed->psz_link = psz_eltvalue;
550                         }
551                         else if( !strcmp( psz_eltname, "description" ) )
552                         {
553                             p_feed->psz_description = psz_eltvalue;
554                         }
555                         else
556                         {
557                             free( psz_eltvalue );
558                             psz_eltvalue = NULL;
559                         }
560                     }
561                     else
562                     {
563                         struct rss_item_t *p_item;
564                         p_item = p_feed->p_items+i_item;
565                         if( !strcmp( psz_eltname, "title" ) )
566                         {
567                             p_item->psz_title = psz_eltvalue;
568                         }
569                         else if( !strcmp( psz_eltname, "link" ) )
570                         {
571                             p_item->psz_link = psz_eltvalue;
572                         }
573                         else if( !strcmp( psz_eltname, "description" ) )
574                         {
575                             p_item->psz_description = psz_eltvalue;
576                         }
577                         else
578                         {
579                             free( psz_eltvalue );
580                             psz_eltvalue = NULL;
581                         }
582                     }
583                     break;
584             }
585         }
586
587         if( p_xml_reader && p_xml ) xml_ReaderDelete( p_xml, p_xml_reader );
588         if( p_stream ) stream_Delete( p_stream );
589         msg_Dbg( p_filter, "Done with %s RSS feed.", psz_feed );
590     }
591     free( psz_buffer_2 );
592     if( p_xml ) xml_Delete( p_xml );
593
594     return 0;
595 }
596
597 /****************************************************************************
598  * FreeRSS
599  ***************************************************************************/
600 static void FreeRSS( filter_t *p_filter)
601 {
602     filter_sys_t *p_sys = p_filter->p_sys;
603
604     struct rss_item_t *p_item;
605     struct rss_feed_t *p_feed;
606
607     int i_feed;
608     int i_item;
609
610     for( i_feed = 0; i_feed < p_sys->i_feeds; i_feed++ )
611     {
612         p_feed = p_sys->p_feeds+i_feed;
613         for( i_item = 0; i_item < p_feed->i_items; i_item++ )
614         {
615             p_item = p_feed->p_items+i_item;
616             free( p_item->psz_title );
617             free( p_item->psz_link );
618             free( p_item->psz_description );
619         }
620         free( p_feed->p_items );
621         free( p_feed->psz_title);
622         free( p_feed->psz_link );
623         free( p_feed->psz_description );
624     }
625     free( p_sys->p_feeds );
626     p_sys->i_feeds = 0;
627 }