[prev in list] [next in list] [prev in thread] [next in thread] 

List:       helix-protocol-cvs
Subject:    [Protocol-cvs] sdp sdpmdgen.cpp,1.31.2.17.14.3,1.31.2.17.14.4
From:       jgordon () helixcommunity ! org
Date:       2006-04-05 15:07:27
[Download RAW message or body]

Update of /cvsroot/protocol/sdp
In directory cvs02.internal.helixcommunity.org:/tmp/cvs-serv3569

Modified Files:
      Tag: SERVER_11_1
	sdpmdgen.cpp 
Log Message:
Synopsis
========
Fixes PR 160349 - implements the same functionality as in 10.0 branch

Branches: SERVER_11_1, HEAD (SERVER_CURRENT)
Reviewer: seansmith


Description
===========
This implements the same functionality as was added on the 10.0 branch
but is not a direct merge.

If no title is present, then the filename will be used.

If config.SDPTitleNumCharsOfFilename is present, the file name will
be truncated to this many characters.

If config.SDPDefaultTitle is present, it will be used instead of the
filename.


Files Affected
==============
protocol/sdp/sdpmdgen.cpp
server/protocol/rtsp/rtspserv.cpp


Index: sdpmdgen.cpp
===================================================================
RCS file: /cvsroot/protocol/sdp/sdpmdgen.cpp,v
retrieving revision 1.31.2.17.14.3
retrieving revision 1.31.2.17.14.4
diff -u -d -r1.31.2.17.14.3 -r1.31.2.17.14.4
--- sdpmdgen.cpp	16 Mar 2006 20:24:34 -0000	1.31.2.17.14.3
+++ sdpmdgen.cpp	5 Apr 2006 15:07:23 -0000	1.31.2.17.14.4
@@ -77,6 +77,8 @@
 
 #define NADU_REPORT_FREQUENCY_CFG "config.3GPPStreamAdaptation.NADUReportFreq"
 #define REG_RTSP_PREF_TCP "config.Protocols.RTSP.PreferClientTCP"
+#define SDP_TITLE_CFG "config.SDPDefaultTitle"
+#define SDP_TITLE_LEN_CFG "config.SDPTitleNumCharsOfFilename"
 
 // Helix Rate Adaptation Configuration; default is TRUE
 #define REGISTRY_GL_HRA_CFG "config.MediaDelivery.ConfigHelixRAEnabled"
@@ -292,10 +294,10 @@
     SafeSprintf(pszSessionID, 40, "%lu", timeNow.m_lMicroSecond); 
     SafeSprintf(pszVersion, 40, "%lu", timeNow.m_lMicroSecond); 
 
+    IHXBuffer* pReqURL = NULL;
     IHXBuffer* pContentBase = NULL;
     IHXBuffer* pQueryParams = NULL;
     IHXBuffer* pHostname = NULL;
-
     double dBWMult = 1.0;
 
     if(pValueArray[1])
@@ -320,8 +322,8 @@
             pPropBuffer);
         while(rc == HXR_OK)
         {
-            if (m_bUseAbsoluteURL && strcasecmp(pPropName, 
-                "AbsoluteBaseURL") == 0)
+            if (m_bUseAbsoluteURL && 
+                strcasecmp(pPropName, "AbsoluteBaseURL") == 0)
             {
                 pContentBase = pPropBuffer;
             }
@@ -330,7 +332,10 @@
             {
                 pQueryParams = pPropBuffer;
             }
-
+            else if (strcasecmp(pPropName, "RequestURL") == 0)
+            {
+                pReqURL = pPropBuffer;
+            }
             else if (strcasecmp(pPropName, "Control") == 0)
             {
                 pControlStringBuff = pPropBuffer;
@@ -351,6 +356,7 @@
                 {
                     bIsIN6 = TRUE;
                 }
+
                 HX_RELEASE(pPropBuffer);
             }
             else if (strcasecmp(pPropName, "BandwidthProtocol") == 0)
@@ -516,8 +522,7 @@
 
             NEW_FAST_TEMP_STR(pszControlString, 512, ulBuffLen); 
             SafeSprintf(pszControlString, ulBuffLen, "a=control:%s%s%s%s",
-                     ((pContentBase) ? 
-                     ((char*)pContentBase->GetBuffer()) : ""),
+                     (pContentBase ? ((char*)pContentBase->GetBuffer()) : ""),
                      pControlStringBuff->GetBuffer(),
                      (pQueryParams) ?
                      ((char*)pQueryParams->GetBuffer()) : "", pszEOL);
@@ -802,21 +807,95 @@
         }
     }   
      
+    // Add a title in s=
+    const char* pActualTitle = pszTitle;
+    INT32 lTitleLen = 0;
+    IHXBuffer* pDefaultTitle = NULL;
 
-    if (!pszTitle)
+    // if there was no Title, check the registry for a default
+    if (!pActualTitle && m_pRegistry)
     {
-       SafeSprintf(psz256, 256,"s=<No title>%s", pszEOL); 
-       mDesc += psz256;
+        if (SUCCEEDED(m_pRegistry->GetStrByName(SDP_TITLE_CFG, pDefaultTitle)))
+        {
+            pActualTitle = (char*)pDefaultTitle->GetBuffer();
+        }
+
+        // if no default, look for a file name size limit
+        else if (SUCCEEDED(m_pRegistry->GetIntByName(SDP_TITLE_LEN_CFG, 
+                lTitleLen)) && lTitleLen < 0)
+        {
+            lTitleLen = 0;
+        }
     }
-    else
+
+    // If no title from file header or SDPDefaultTitle
+    // configured default then get the file name
+    if (!pActualTitle && (pReqURL || pContentBase))
     {
-        ulLen = strlen(pszTitle) + 64;
-        NEW_FAST_TEMP_STR(pszTmpStr, 256, ulLen);
-        SafeSprintf(pszTmpStr, ulLen, "s=%s%s", pszTitle, pszEOL); 
-        mDesc += pszTmpStr;
-        DELETE_FAST_TEMP_STR(pszTmpStr);
+        if (pReqURL)
+        {
+            pActualTitle = (char*)pReqURL->GetBuffer();
+        }
+        else if (pContentBase)
+        {
+            pActualTitle = (char*)pContentBase->GetBuffer();
+        }
+
+        const char* pTitleStart;
+        INT32 lLen = 0;
+        const char* pTitleEnd = strchr(pActualTitle, '?');
+
+        // If we don't have query params, it goes to the end
+        // minus a trailing '/' if present
+        if (!pTitleEnd)
+        {
+            lLen = strlen(pActualTitle);
+            if (lLen > 1 && pActualTitle[lLen-1] == '/')
+            {
+                lLen--;
+            }
+            pTitleEnd = pActualTitle + lLen;
+        }
+
+        // Search back for the preceding '/' to find the start
+        // of the file name
+        for (pTitleStart = pTitleEnd; 
+             pTitleStart > pActualTitle && *(pTitleStart-1) != '/';
+             --pTitleStart)
+        {
+        }
+
+        // Calculate the length, but if we have a max length
+        // from the config, don't go past that.
+        lLen = pTitleEnd - pTitleStart;
+        if (!lTitleLen || lLen < lTitleLen)
+        {
+            lTitleLen = lLen;
+        }
+
+        pActualTitle = pTitleStart;
+    }
+    
+    // If still no title, we will just use a single space 
+    if (!pActualTitle)
+    {
+        pActualTitle = (char*)" ";
+        lTitleLen = 1;
     }
 
+    if (!lTitleLen)
+    {
+        lTitleLen = strlen(pActualTitle);
+    }
+
+    ulLen = 2 + lTitleLen + sizeof(pszEOL);
+    NEW_FAST_TEMP_STR(pszTitleStr, 256, ulLen);
+    sprintf(pszTitleStr, "s=%.*s%s", lTitleLen, pActualTitle, pszEOL); /* Flawfinder: ignore */
+    mDesc += pszTitleStr;
+    DELETE_FAST_TEMP_STR(pszTitleStr);
+    
+    HX_RELEASE(pDefaultTitle);
+
     if (sessionInfo.pszInfo)
     {
         ulLen = strlen(sessionInfo.pszInfo) + 64;
@@ -1482,13 +1561,13 @@
                 if (pContentBase || pQueryParams)
                 {
                     UINT32 ulBuffLen = 64;
-                    ulBuffLen += (pContentBase) ? pContentBase->GetSize() : 0;
+                    ulBuffLen += pContentBase ? pContentBase->GetSize() : 0;
                     ulBuffLen += (pQueryParams) ? pQueryParams->GetSize() : 0;
 
                     NEW_FAST_TEMP_STR(pszControlString, 512, ulBuffLen); 
                     SafeSprintf(pszControlString, ulBuffLen, 
                         "%sa=control:%s%s%s%s", szAltPrefix,
-                        (pContentBase)? ((char*)pContentBase->GetBuffer()) : "",
+                        pContentBase ? ((char*)pContentBase->GetBuffer()) : "",
                         pControlStringBuff->GetBuffer(),
                         (pQueryParams)?((char*)pQueryParams->GetBuffer()) : "",
                         pszEOL);
@@ -1518,15 +1597,15 @@
                 if (pContentBase || pQueryParams)
                 {
                     UINT32 ulBuffLen = 64;
-                    ulBuffLen += (pContentBase) ? (pContentBase->GetSize()) : 0;
+                    ulBuffLen += pContentBase ? (pContentBase->GetSize()) : 0;
                     ulBuffLen += (pQueryParams) ? (pQueryParams->GetSize()) : 0;
 
                     NEW_FAST_TEMP_STR(pszControlField, 256, ulBuffLen);
                     SafeSprintf(pszControlField, ulBuffLen, "%s%s%s%s%u%s%s", 
                         szAltPrefix, pszFieldPrefix, 
-                        (pContentBase)?((char*)pContentBase->GetBuffer()) : "",
+                        pContentBase ?((char*)pContentBase->GetBuffer()) : "",
                         pszStreamLabel, pStreamInfo->ulControlID, 
-                        (pQueryParams)?((char*)pQueryParams->GetBuffer()) : "",
+                        pQueryParams ?((char*)pQueryParams->GetBuffer()) : "",
                         pszEOL);
 
                     mDesc += pszControlField;
@@ -1851,6 +1930,7 @@
     }
 
     HX_RELEASE(pControlStringBuff);
+    HX_RELEASE(pReqURL);
     HX_RELEASE(pContentBase);
     HX_RELEASE(pQueryParams);
     HX_RELEASE(pUserAgent);



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic