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