]> git.sesse.net Git - vlc/blobdiff - modules/video_filter/rss.c
Factorize the gcrypt thread support
[vlc] / modules / video_filter / rss.c
index b7b1dee6f3858945cb58c5fde709e4b7294e6f36..9dac79064235840baca5933bbd968b7831df1fde 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <string.h>
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
 
 #include <vlc/vlc.h>
 #include <vlc_vout.h>
@@ -45,6 +48,8 @@
 
 #include "vlc_image.h"
 
+#include <time.h>
+
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
@@ -110,7 +115,7 @@ struct filter_sys_t
 
     int i_ttl;
     time_t t_last_update;
-    vlc_bool_t b_images;
+    bool b_images;
     int i_title;
 
     int i_cur_feed;
@@ -179,36 +184,36 @@ static const char *ppsz_title_modes[] =
  * Module descriptor
  *****************************************************************************/
 vlc_module_begin();
-    set_capability( "sub filter", 0 );
+    set_capability( "sub filter", 1 );
     set_shortname( "RSS / Atom" );
     set_callbacks( CreateFilter, DestroyFilter );
     set_category( CAT_VIDEO );
     set_subcategory( SUBCAT_VIDEO_SUBPIC );
-    add_string( CFG_PREFIX "urls", "rss", NULL, MSG_TEXT, MSG_LONGTEXT, VLC_FALSE );
+    add_string( CFG_PREFIX "urls", "rss", NULL, MSG_TEXT, MSG_LONGTEXT, false );
 
     set_section( N_("Position"), NULL );
-    add_integer( CFG_PREFIX "x", -1, NULL, POSX_TEXT, POSX_LONGTEXT, VLC_TRUE );
-    add_integer( CFG_PREFIX "y", 0, NULL, POSY_TEXT, POSY_LONGTEXT, VLC_TRUE );
-    add_integer( CFG_PREFIX "position", 5, NULL, POS_TEXT, POS_LONGTEXT, VLC_FALSE );
+    add_integer( CFG_PREFIX "x", 0, NULL, POSX_TEXT, POSX_LONGTEXT, true );
+    add_integer( CFG_PREFIX "y", 0, NULL, POSY_TEXT, POSY_LONGTEXT, true );
+    add_integer( CFG_PREFIX "position", -1, NULL, POS_TEXT, POS_LONGTEXT, false );
         change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 );
 
     set_section( N_("Font"), NULL );
     /* 5 sets the default to top [1] left [4] */
     add_integer_with_range( CFG_PREFIX "opacity", 255, 0, 255, NULL,
-        OPACITY_TEXT, OPACITY_LONGTEXT, VLC_FALSE );
+        OPACITY_TEXT, OPACITY_LONGTEXT, false );
     add_integer( CFG_PREFIX "color", 0xFFFFFF, NULL, COLOR_TEXT, COLOR_LONGTEXT,
-                  VLC_FALSE );
+                  false );
         change_integer_list( pi_color_values, ppsz_color_descriptions, 0 );
-    add_integer( CFG_PREFIX "size", -1, NULL, SIZE_TEXT, SIZE_LONGTEXT, VLC_FALSE );
+    add_integer( CFG_PREFIX "size", -1, NULL, SIZE_TEXT, SIZE_LONGTEXT, false );
 
     set_section( N_("Misc"), NULL );
     add_integer( CFG_PREFIX "speed", 100000, NULL, SPEED_TEXT, SPEED_LONGTEXT,
-                 VLC_FALSE );
+                 false );
     add_integer( CFG_PREFIX "length", 60, NULL, LENGTH_TEXT, LENGTH_LONGTEXT,
-                 VLC_FALSE );
-    add_integer( CFG_PREFIX "ttl", 1800, NULL, TTL_TEXT, TTL_LONGTEXT, VLC_FALSE );
-    add_bool( CFG_PREFIX "images", 1, NULL, IMAGE_TEXT, IMAGE_LONGTEXT, VLC_FALSE );
-    add_integer( CFG_PREFIX "title", default_title, NULL, TITLE_TEXT, TITLE_LONGTEXT, VLC_FALSE );
+                 false );
+    add_integer( CFG_PREFIX "ttl", 1800, NULL, TTL_TEXT, TTL_LONGTEXT, false );
+    add_bool( CFG_PREFIX "images", 1, NULL, IMAGE_TEXT, IMAGE_LONGTEXT, false );
+    add_integer( CFG_PREFIX "title", default_title, NULL, TITLE_TEXT, TITLE_LONGTEXT, false );
         change_integer_list( pi_title_modes, ppsz_title_modes, 0 );
 
     set_description( _("RSS and Atom feed display") );
@@ -238,7 +243,7 @@ static int CreateFilter( vlc_object_t *p_this )
         return VLC_ENOMEM;
     }
 
-    vlc_mutex_init( p_filter, &p_sys->lock );
+    vlc_mutex_init( &p_sys->lock );
     vlc_mutex_lock( &p_sys->lock );
 
     config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
@@ -255,10 +260,28 @@ static int CreateFilter( vlc_object_t *p_this )
     p_sys->i_length = var_CreateGetInteger( p_filter, CFG_PREFIX "length" );
     p_sys->i_ttl = __MAX( 0, var_CreateGetInteger( p_filter, CFG_PREFIX "ttl" ) );
     p_sys->b_images = var_CreateGetBool( p_filter, CFG_PREFIX "images" );
+
     p_sys->psz_marquee = (char *)malloc( p_sys->i_length + 1 );
+    if( p_sys->psz_marquee == NULL )
+    {
+        msg_Err( p_filter, "out of memory" );
+        vlc_mutex_unlock( &p_sys->lock );
+        vlc_mutex_destroy( &p_sys->lock );
+        free( p_sys );
+        return VLC_ENOMEM;
+    }
     p_sys->psz_marquee[p_sys->i_length] = '\0';
 
     p_sys->p_style = malloc( sizeof( text_style_t ));
+    if( p_sys->p_style == NULL )
+    {
+        msg_Err( p_filter, "out of memory" );
+        free( p_sys->psz_marquee );
+        vlc_mutex_unlock( &p_sys->lock );
+        vlc_mutex_destroy( &p_sys->lock );
+        free( p_sys );
+        return VLC_ENOMEM;
+    }
     memcpy( p_sys->p_style, &default_text_style, sizeof( text_style_t ));
 
     p_sys->i_xoff = var_CreateGetInteger( p_filter, CFG_PREFIX "x" );
@@ -268,7 +291,7 @@ static int CreateFilter( vlc_object_t *p_this )
     p_sys->p_style->i_font_color = var_CreateGetInteger( p_filter, CFG_PREFIX "color" );
     p_sys->p_style->i_font_size = var_CreateGetInteger( p_filter, CFG_PREFIX "size" );
 
-    if( p_sys->b_images == VLC_TRUE && p_sys->p_style->i_font_size == -1 )
+    if( p_sys->b_images == true && p_sys->p_style->i_font_size == -1 )
     {
         msg_Warn( p_filter, "rrs-size wasn't specified. Feed images will thus be displayed without being resized" );
     }
@@ -276,23 +299,37 @@ static int CreateFilter( vlc_object_t *p_this )
     if( FetchRSS( p_filter ) )
     {
         msg_Err( p_filter, "failed while fetching RSS ... too bad" );
+        free( p_sys->p_style );
+        free( p_sys->psz_marquee );
         vlc_mutex_unlock( &p_sys->lock );
+        vlc_mutex_destroy( &p_sys->lock );
+        free( p_sys );
         return VLC_EGENERIC;
     }
     p_sys->t_last_update = time( NULL );
 
     if( p_sys->i_feeds == 0 )
     {
+        free( p_sys->p_style );
+        free( p_sys->psz_marquee );
         vlc_mutex_unlock( &p_sys->lock );
+        vlc_mutex_destroy( &p_sys->lock );
+        free( p_sys );
         return VLC_EGENERIC;
     }
     for( i_feed=0; i_feed < p_sys->i_feeds; i_feed ++ )
+    {
         if( p_sys->p_feeds[i_feed].i_items == 0 )
         {
+            free( p_sys->p_style );
+            free( p_sys->psz_marquee );
+            FreeRSS( p_filter );
             vlc_mutex_unlock( &p_sys->lock );
+            vlc_mutex_destroy( &p_sys->lock );
+            free( p_sys );
             return VLC_EGENERIC;
         }
-
+    }
     /* Misc init */
     p_filter->pf_sub_filter = Filter;
     p_sys->last_date = (mtime_t)0;
@@ -311,8 +348,8 @@ static void DestroyFilter( vlc_object_t *p_this )
 
     vlc_mutex_lock( &p_sys->lock );
 
-    if( p_sys->p_style ) free( p_sys->p_style );
-    if( p_sys->psz_marquee ) free( p_sys->psz_marquee );
+    free( p_sys->p_style );
+    free( p_sys->psz_marquee );
     free( p_sys->psz_urls );
     FreeRSS( p_filter );
     vlc_mutex_unlock( &p_sys->lock );
@@ -476,24 +513,23 @@ static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
         p_spu->p_region->fmt.i_visible_height = p_sys->p_style->i_font_size;
     p_spu->i_start = date;
     p_spu->i_stop  = 0;
-    p_spu->b_ephemer = VLC_TRUE;
+    p_spu->b_ephemer = true;
 
     /*  where to locate the string: */
-    if( p_sys->i_xoff < 0 || p_sys->i_yoff < 0 )
-    {   /* set to one of the 9 relative locations */
-        p_spu->p_region->i_align = p_sys->i_pos;
-        p_spu->i_x = 0;
-        p_spu->i_y = 0;
-        p_spu->b_absolute = VLC_FALSE;
+    if( p_sys->i_pos < 0 )
+    {   /*  set to an absolute xy */
+        p_spu->p_region->i_align = OSD_ALIGN_LEFT | OSD_ALIGN_TOP;
+        p_spu->b_absolute = true;
     }
     else
-    {   /*  set to an absolute xy, referenced to upper left corner */
-        p_spu->p_region->i_align = OSD_ALIGN_LEFT | OSD_ALIGN_TOP;
-        p_spu->i_x = p_sys->i_xoff;
-        p_spu->i_y = p_sys->i_yoff;
-        p_spu->b_absolute = VLC_TRUE;
+    {   /* set to one of the 9 relative locations */
+        p_spu->p_region->i_align = p_sys->i_pos;
+        p_spu->b_absolute = false;
     }
 
+    p_spu->i_x = p_sys->i_xoff;
+    p_spu->i_y = p_sys->i_yoff;
+
     p_spu->i_height = 1;
     p_spu->p_region->p_style = p_sys->p_style;
 
@@ -635,8 +671,8 @@ static int FetchRSS( filter_t *p_filter)
 
     int i_feed;
     int i_item;
-    vlc_bool_t b_is_item;
-    vlc_bool_t b_is_image;
+    bool b_is_item;
+    bool b_is_image;
     int i_int;
 
     FreeRSS( p_filter );
@@ -692,8 +728,8 @@ static int FetchRSS( filter_t *p_filter)
         }
 
         i_item = 0;
-        b_is_item = VLC_FALSE;
-        b_is_image = VLC_FALSE;
+        b_is_item = false;
+        b_is_image = false;
 
         while( xml_ReaderRead( p_xml_reader ) == 1 )
         {
@@ -704,11 +740,8 @@ static int FetchRSS( filter_t *p_filter)
                     return 1;
 
                 case XML_READER_STARTELEM:
-                    if( psz_eltname )
-                    {
-                        free( psz_eltname );
-                        psz_eltname = NULL;
-                    }
+                    free( psz_eltname );
+                    psz_eltname = NULL;
                     psz_eltname = xml_ReaderName( p_xml_reader );
                     if( !psz_eltname )
                     {
@@ -720,7 +753,7 @@ static int FetchRSS( filter_t *p_filter)
                     if( !strcmp( psz_eltname, "item" ) /* rss */
                      || !strcmp( psz_eltname, "entry" ) ) /* atom */
                     {
-                        b_is_item = VLC_TRUE;
+                        b_is_item = true;
                         p_feed->i_items++;
                         p_feed->p_items = (struct rss_item_t *)realloc( p_feed->p_items, p_feed->i_items * sizeof( struct rss_item_t ) );
                         p_feed->p_items[p_feed->i_items-1].psz_title = NULL;
@@ -730,7 +763,7 @@ static int FetchRSS( filter_t *p_filter)
                     }
                     else if( !strcmp( psz_eltname, "image" ) ) /* rss */
                     {
-                        b_is_image = VLC_TRUE;
+                        b_is_image = true;
                     }
                     else if( !strcmp( psz_eltname, "link" ) ) /* atom */
                     {
@@ -758,8 +791,8 @@ static int FetchRSS( filter_t *p_filter)
                         if( psz_rel && psz_href )
                         {
                             if( !strcmp( psz_rel, "alternate" )
-                                && b_is_item == VLC_FALSE
-                                && b_is_image == VLC_FALSE
+                                && b_is_item == false
+                                && b_is_image == false
                                 && !p_feed->psz_link )
                             {
                                 p_feed->psz_link = psz_href;
@@ -767,8 +800,8 @@ static int FetchRSS( filter_t *p_filter)
                             /* this isn't in the rfc but i found some ... */
                             else if( ( !strcmp( psz_rel, "logo" )
                                     || !strcmp( psz_rel, "icon" ) )
-                                    && b_is_item == VLC_FALSE
-                                    && b_is_image == VLC_FALSE
+                                    && b_is_item == false
+                                    && b_is_image == false
                                     && !p_feed->psz_image )
                             {
                                 p_feed->psz_image = psz_href;
@@ -780,18 +813,15 @@ static int FetchRSS( filter_t *p_filter)
                         }
                         else
                         {
-                            if( psz_href ) free( psz_href );
+                            free( psz_href );
                         }
-                        if( psz_rel ) free( psz_rel );
+                        free( psz_rel );
                     }
                     break;
 
                 case XML_READER_ENDELEM:
-                    if( psz_eltname )
-                    {
-                        free( psz_eltname );
-                        psz_eltname = NULL;
-                    }
+                    free( psz_eltname );
+                    psz_eltname = NULL;
                     psz_eltname = xml_ReaderName( p_xml_reader );
                     if( !psz_eltname )
                     {
@@ -803,12 +833,12 @@ static int FetchRSS( filter_t *p_filter)
                     if( !strcmp( psz_eltname, "item" ) /* rss */
                      || !strcmp( psz_eltname, "entry" ) ) /* atom */
                     {
-                        b_is_item = VLC_FALSE;
+                        b_is_item = false;
                         i_item++;
                     }
                     else if( !strcmp( psz_eltname, "image" ) ) /* rss */
                     {
-                        b_is_image = VLC_FALSE;
+                        b_is_image = false;
                     }
                     free( psz_eltname );
                     psz_eltname = NULL;
@@ -830,7 +860,7 @@ static int FetchRSS( filter_t *p_filter)
 #                   ifdef RSS_DEBUG
                     msg_Dbg( p_filter, "  text : <%s>", psz_eltvalue );
 #                   endif
-                    if( b_is_item == VLC_TRUE )
+                    if( b_is_item == true )
                     {
                         struct rss_item_t *p_item;
                         p_item = p_feed->p_items+i_item;
@@ -856,7 +886,7 @@ static int FetchRSS( filter_t *p_filter)
                             psz_eltvalue = NULL;
                         }
                     }
-                    else if( b_is_image == VLC_TRUE )
+                    else if( b_is_image == true )
                     {
                         if( !strcmp( psz_eltname, "url" ) /* rss */
                             && !p_feed->psz_image )
@@ -903,7 +933,7 @@ static int FetchRSS( filter_t *p_filter)
             }
         }
 
-        if( p_sys->b_images == VLC_TRUE
+        if( p_sys->b_images == true
             && p_feed->psz_image && !p_feed->p_pic )
         {
             p_feed->p_pic = LoadImage( p_filter, p_feed->psz_image );