DVB: small simplification
[vlc.git] / modules / access / dtv / en50221.c
index ac9bb4c..82ed742 100644 (file)
@@ -945,6 +945,68 @@ static void ResourceManagerOpen( cam_t * p_cam, unsigned i_session_id )
  */
 
 #ifdef ENABLE_HTTPD
+
+/****************************************************************************
+ * HTTPExtractValue: Extract a GET variable from psz_request
+ ****************************************************************************/
+static const char *HTTPExtractValue( const char *psz_uri, const char *psz_name,
+                        char *psz_value, int i_value_max )
+{
+    const char *p = psz_uri;
+
+    while( (p = strstr( p, psz_name )) )
+    {
+        /* Verify that we are dealing with a post/get argument */
+        if( (p == psz_uri || *(p - 1) == '&' || *(p - 1) == '\n')
+              && p[strlen(psz_name)] == '=' )
+            break;
+        p++;
+    }
+
+    if( p )
+    {
+        int i_len;
+
+        p += strlen( psz_name );
+        if( *p == '=' ) p++;
+
+        if( strchr( p, '&' ) )
+        {
+            i_len = strchr( p, '&' ) - p;
+        }
+        else
+        {
+            /* for POST method */
+            if( strchr( p, '\n' ) )
+            {
+                i_len = strchr( p, '\n' ) - p;
+                if( i_len && *(p+i_len-1) == '\r' ) i_len--;
+            }
+            else
+            {
+                i_len = strlen( p );
+            }
+        }
+        i_len = __MIN( i_value_max - 1, i_len );
+        if( i_len > 0 )
+        {
+            strncpy( psz_value, p, i_len );
+            psz_value[i_len] = '\0';
+        }
+        else
+        {
+            strncpy( psz_value, "", i_value_max );
+        }
+        p += i_len;
+    }
+    else
+    {
+        strncpy( psz_value, "", i_value_max );
+    }
+
+    return p;
+}
+
 /*****************************************************************************
  * ApplicationInformationEnterMenu
  *****************************************************************************/
@@ -1194,7 +1256,7 @@ static uint8_t *CAPMTES( system_ids_t *p_ids, uint8_t *p_capmt,
 
 static uint8_t *CAPMTBuild( cam_t * p_cam, int i_session_id,
                             dvbpsi_pmt_t *p_pmt, uint8_t i_list_mgt,
-                            uint8_t i_cmd, int *pi_capmt_size )
+                            uint8_t i_cmd, int *restrict pi_capmt_size )
 {
     system_ids_t *p_ids =
         (system_ids_t *)p_cam->p_sessions[i_session_id - 1].p_sys;
@@ -1214,7 +1276,6 @@ static uint8_t *CAPMTBuild( cam_t * p_cam, int i_session_id,
         msg_Warn( p_cam->obj,
                   "no compatible scrambling system for SID %d on session %d",
                   p_pmt->i_program_number, i_session_id );
-        *pi_capmt_size = 0;
         return NULL;
     }
 
@@ -1261,8 +1322,7 @@ static void CAPMTFirst( cam_t * p_cam, int i_session_id,
     p_capmt = CAPMTBuild( p_cam, i_session_id, p_pmt,
                           0x3 /* only */, 0x1 /* ok_descrambling */,
                           &i_capmt_size );
-
-    if( i_capmt_size )
+    if( p_capmt != NULL )
     {
         APDUSend( p_cam, i_session_id, AOT_CA_PMT, p_capmt, i_capmt_size );
         free( p_capmt );
@@ -1301,8 +1361,7 @@ static void CAPMTAdd( cam_t * p_cam, int i_session_id,
     p_capmt = CAPMTBuild( p_cam, i_session_id, p_pmt,
                           0x4 /* add */, 0x1 /* ok_descrambling */,
                           &i_capmt_size );
-
-    if( i_capmt_size )
+    if( p_capmt != NULL )
     {
         APDUSend( p_cam, i_session_id, AOT_CA_PMT, p_capmt, i_capmt_size );
         free( p_capmt );
@@ -1324,8 +1383,7 @@ static void CAPMTUpdate( cam_t * p_cam, int i_session_id,
     p_capmt = CAPMTBuild( p_cam, i_session_id, p_pmt,
                           0x5 /* update */, 0x1 /* ok_descrambling */,
                           &i_capmt_size );
-
-    if( i_capmt_size )
+    if( p_capmt != NULL )
     {
         APDUSend( p_cam, i_session_id, AOT_CA_PMT, p_capmt, i_capmt_size );
         free( p_capmt );
@@ -1348,8 +1406,7 @@ static void CAPMTDelete( cam_t * p_cam, int i_session_id,
     p_capmt = CAPMTBuild( p_cam, i_session_id, p_pmt,
                           0x5 /* update */, 0x4 /* not selected */,
                           &i_capmt_size );
-
-    if( i_capmt_size )
+    if( p_capmt != NULL )
     {
         APDUSend( p_cam, i_session_id, AOT_CA_PMT, p_capmt, i_capmt_size );
         free( p_capmt );