[vlc-commits] [Git][videolan/vlc][3.0.x] 3 commits: upnp: fix some misuse of strncmp()

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Fri Dec 17 11:54:51 UTC 2021



Jean-Baptiste Kempf pushed to branch 3.0.x at VideoLAN / VLC


Commits:
ca1279d1 by Lyndon Brown at 2021-12-17T10:29:32+00:00
upnp: fix some misuse of strncmp()

we do not want to be doing a 'starts with' check in these cases, they
should be an equality check

(cherry picked from commit 785c6dfeb8961b975e6b8acab511aea4e8c8d70a)
Signed-off-by: Felix Paul Kühne <felix at feepk.net>

- - - - -
6e995d58 by Lyndon Brown at 2021-12-17T10:29:32+00:00
upnp: improve auto mode handling code

(no functional change)

 - better prepare for the next commit where we need to support both "Auto"
   and "auto".
 - avoid multiple `strdup()`.
 - avoid avoidable string comparisons.

(cherry picked from commit 31f283ad76a791fbe2344404ed42fff5da0fe8ac)
Signed-off-by: Felix Paul Kühne <felix at feepk.net>

- - - - -
a31161d9 by Lyndon Brown at 2021-12-17T10:29:32+00:00
upnp: fix bad option default

the lowercase "auto" default option value did not match the uppercase
"Auto" in the choice list.

option values should typically be lowercase. this fixes the mistake with
the case of the choice value, whilst maintaining backwards compatibility
with existing CLI usage and from saved settings files. this was the
clear preference for fixing this resulting from the MR discussion.

(cherry picked from commit 230068f35d3b243c131853992f91e27313e6f7b3)
Signed-off-by: Felix Paul Kühne <felix at feepk.net>

- - - - -


1 changed file:

- modules/services_discovery/upnp.cpp


Changes:

=====================================
modules/services_discovery/upnp.cpp
=====================================
@@ -72,7 +72,7 @@ const char* SATIP_SERVER_DEVICE_TYPE = "urn:ses-com:device:SatIPServer:1";
 #define SATIP_CHANNEL_LIST N_("SAT>IP channel list")
 #define SATIP_CHANNEL_LIST_URL N_("Custom SAT>IP channel list URL")
 static const char *const ppsz_satip_channel_lists[] = {
-    "Auto", "ASTRA_19_2E", "ASTRA_28_2E", "ASTRA_23_5E", "MasterList", "ServerList", "CustomList"
+    "auto", "ASTRA_19_2E", "ASTRA_28_2E", "ASTRA_23_5E", "MasterList", "ServerList", "CustomList"
 };
 static const char *const ppsz_readible_satip_channel_lists[] = {
     N_("Auto"), "Astra 19.2°E", "Astra 28.2°E", "Astra 23.5°E", N_("Master List"), N_("Server List"), N_("Custom List")
@@ -588,18 +588,26 @@ MediaServerList::parseSatipServer( IXML_Element* p_device_element, const char *p
     SD::MediaServerDesc* p_server = NULL;
 
     char *psz_satip_channellist = config_GetPsz(m_sd, "satip-channelist");
-    if( !psz_satip_channellist ) {
-        psz_satip_channellist = strdup("Auto");
-    }
 
-    if( unlikely( !psz_satip_channellist ) )
-        return;
+    /* In Auto mode, default to MasterList list from satip.info */
+    bool automode = false;
+    if( !psz_satip_channellist || /* On lookup failure or empty string, use auto mode */
+        strcmp(psz_satip_channellist, "auto") == 0 ||
+        strcmp(psz_satip_channellist, "Auto") == 0 ) /* for backwards compatibility */
+    {
+        automode = true;
+        if( psz_satip_channellist )
+            free(psz_satip_channellist);
+        psz_satip_channellist = strdup( "MasterList" );
+        if( unlikely( !psz_satip_channellist ) )
+            return;
+    }
 
     vlc_url_t url;
     vlc_UrlParse( &url, psz_base_url );
 
     /* Part 1: a user may have provided a custom playlist url */
-    if (strncmp(psz_satip_channellist, "CustomList", 10) == 0) {
+    if (strcmp(psz_satip_channellist, "CustomList") == 0) {
         char *psz_satip_playlist_url = config_GetPsz(m_sd, "satip-channellist-url" );
         if ( psz_satip_playlist_url ) {
             p_server = new(std::nothrow) SD::MediaServerDesc( psz_udn, psz_friendly_name, psz_satip_playlist_url, iconUrl );
@@ -622,8 +630,7 @@ MediaServerList::parseSatipServer( IXML_Element* p_device_element, const char *p
 
     /* Part 2: device playlist
      * In Automatic mode, or if requested by the user, check for a SAT>IP m3u list on the device */
-    if (strncmp(psz_satip_channellist, "ServerList", 10) == 0 ||
-        strncmp(psz_satip_channellist, "Auto", strlen ("Auto")) == 0 ) {
+    if (automode || strcmp(psz_satip_channellist, "ServerList") == 0) {
         const char* psz_m3u_url = xml_getChildElementValue( p_device_element, "satip:X_SATIPM3U" );
         if ( psz_m3u_url ) {
             if ( strncmp( "http", psz_m3u_url, 4) )
@@ -653,7 +660,7 @@ MediaServerList::parseSatipServer( IXML_Element* p_device_element, const char *p
             msg_Dbg( m_sd, "SAT>IP server '%s' did not provide a playlist", url.psz_host);
         }
 
-        if(strncmp(psz_satip_channellist, "ServerList", 10) == 0) {
+        if (!automode) {
             /* to comply with the SAT>IP specifications, we don't fallback on another channel list if this path failed,
              * but in Automatic mode, we continue */
             free(psz_satip_channellist);
@@ -667,12 +674,6 @@ MediaServerList::parseSatipServer( IXML_Element* p_device_element, const char *p
      * which will be processed by a lua script a bit later, to make it work sanely
      * MasterList is a list of usual Satellites */
 
-    /* In Auto mode, default to MasterList list from satip.info */
-    if( strncmp(psz_satip_channellist, "Auto", strlen ("Auto")) == 0 ) {
-        free(psz_satip_channellist);
-        psz_satip_channellist = strdup( "MasterList" );
-    }
-
     char *psz_url;
     if (asprintf( &psz_url, "http://www.satip.info/Playlists/%s.m3u",
                 psz_satip_channellist ) < 0 ) {
@@ -869,13 +870,13 @@ namespace
             psz_album_artist = xml_getChildElementValue( itemElement, "upnp:albumArtist" );
             psz_albumArt = xml_getChildElementValue( itemElement, "upnp:albumArtURI" );
             const char *psz_media_type = xml_getChildElementValue( itemElement, "upnp:class" );
-            if (strncmp(psz_media_type, "object.item.videoItem", 21) == 0)
+            if (strcmp(psz_media_type, "object.item.videoItem") == 0)
                 media_type = VIDEO;
-            else if (strncmp(psz_media_type, "object.item.audioItem", 21) == 0)
+            else if (strcmp(psz_media_type, "object.item.audioItem") == 0)
                 media_type = AUDIO;
-            else if (strncmp(psz_media_type, "object.item.imageItem", 21) == 0)
+            else if (strcmp(psz_media_type, "object.item.imageItem") == 0)
                 media_type = IMAGE;
-            else if (strncmp(psz_media_type, "object.container", 16 ) == 0)
+            else if (strcmp(psz_media_type, "object.container") == 0)
                 media_type = CONTAINER;
             else
                 return false;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/aedf1d4a24239be24d66d2e3f82077612ed9cfe5...a31161d93ea2dc3a0e8b864c88476bacef2579da

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/aedf1d4a24239be24d66d2e3f82077612ed9cfe5...a31161d93ea2dc3a0e8b864c88476bacef2579da
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list