Bug 226890 - Thunderbird doesn't handle news URIs properly, part 4.5: Introduce nsCString to m_searchData. r=Standard8
authorJoshua Cranmer <Pidgeot18@gmail.com>
Wed, 04 May 2011 09:47:27 -0400
changeset 7697 36381d5e01efc8cc51d868796f8908468aefba47
parent 7696 15f14ac7e2dd243d58ea3b78f314e2cb9af21fb3
child 7698 d9b0c5b283f48006ba4131202b5f2c47108cb2c8
push idunknown
push userunknown
push dateunknown
reviewersStandard8
bugs226890
Bug 226890 - Thunderbird doesn't handle news URIs properly, part 4.5: Introduce nsCString to m_searchData. r=Standard8
mailnews/news/src/nsNNTPProtocol.cpp
mailnews/news/src/nsNNTPProtocol.h
mailnews/news/test/unit/test_internalUris.js
--- a/mailnews/news/src/nsNNTPProtocol.cpp
+++ b/mailnews/news/src/nsNNTPProtocol.cpp
@@ -316,18 +316,16 @@ nsNNTPProtocol::nsNNTPProtocol(nsIURI * 
 
   m_cancelFromHdr = nsnull;
   m_cancelNewsgroups = nsnull;
   m_cancelDistribution = nsnull;
   m_cancelID = nsnull;
 
   m_key = nsMsgKey_None;
 
-  m_searchData = nsnull;
-
   mBytesReceived = 0;
   mBytesReceivedSinceLastStatusUpdate = 0;
   m_startTime = PR_Now();
 
   if (aMsgWindow) {
     m_msgWindow = aMsgWindow;
   }
 
@@ -1037,22 +1035,21 @@ nsresult nsNNTPProtocol::LoadUrl(nsIURI 
     m_typeWanted = IDS_WANTED;
     rv = m_nntpServer->FindGroup(group, getter_AddRefs(m_newsFolder));
   }
   else if (m_newsAction == nsINntpUrl::ActionSearch)
   {
     m_typeWanted = SEARCH_WANTED;
 
     // Get the search data
-    nsCString commandSpecificData, unescapedCommandSpecificData;
+    nsCString commandSpecificData;
     nsCOMPtr<nsIURL> url = do_QueryInterface(m_runningURL);
     rv = url->GetQuery(commandSpecificData);
     NS_ENSURE_SUCCESS(rv, rv);
-    MsgUnescapeString(commandSpecificData, 0, unescapedCommandSpecificData);
-    m_searchData = ToNewCString(unescapedCommandSpecificData);
+    MsgUnescapeString(commandSpecificData, 0, m_searchData);
 
     rv = m_nntpServer->FindGroup(group, getter_AddRefs(m_newsFolder));
     if (!m_newsFolder)
       goto FAIL;
   }
   else if (m_newsAction == nsINntpUrl::ActionGetNewNews)
   {
     PRBool containsGroup = PR_TRUE;
@@ -1196,17 +1193,17 @@ FAIL:
     {
       NS_ASSERTION(!m_messageID.IsEmpty(), "CANCEL_WANTED needs m_messageID");
       NS_ASSERTION(m_newsFolder, "CANCEL_WANTED needs m_newsFolder");
       NS_ASSERTION(m_key != nsMsgKey_None, "CANCEL_WANTED needs m_key");
     }
     else if (m_typeWanted == GROUP_WANTED)
       NS_ASSERTION(m_newsFolder, "GROUP_WANTED needs m_newsFolder");
     else if (m_typeWanted == SEARCH_WANTED)
-      NS_ASSERTION(m_searchData, "SEARCH_WANTED needs m_searchData");
+      NS_ASSERTION(!m_searchData.IsEmpty(), "SEARCH_WANTED needs m_searchData");
     else if (m_typeWanted == IDS_WANTED)
       NS_ASSERTION(m_newsFolder, "IDS_WANTED needs m_newsFolder");
 
     return rv;
 }
 
 void nsNNTPProtocol::FinishMemCacheEntry(PRBool valid)
 {
@@ -1926,59 +1923,34 @@ PRInt32 nsNNTPProtocol::SendFirstNNTPCom
         m_lastArticle = 0;
 
         NS_MsgSACopy(&command, "GROUP ");
         NS_MsgSACat(&command, group_name.get());
       }
   else if (m_typeWanted == SEARCH_WANTED)
   {
     nsresult rv;
-    PRBool searchable=PR_FALSE;
-    if (!m_nntpServer) {
-      NNTP_LOG_NOTE("m_nntpServer is null, panic!");
-      return -1;
-    }
-    rv = m_nntpServer->QueryExtension("SEARCH", &searchable);
-    if (NS_SUCCEEDED(rv) && searchable)
-    {
-      /* use the SEARCH extension */
-      char *slash = PL_strchr (m_searchData, '/');
-      if (slash)
-      {
-        char *allocatedCommand = MSG_UnEscapeSearchUrl (slash + 1);
-        if (allocatedCommand)
-        {
-          NS_MsgSACopy (&command, allocatedCommand);
-          PR_Free(allocatedCommand);
-        }
-      }
-      m_nextState = NNTP_RESPONSE;
-      m_nextStateAfterResponse = NNTP_SEARCH_RESPONSE;
+    PR_LOG(NNTP,PR_LOG_ALWAYS,("(%p) doing GROUP for XPAT", this));
+    nsCString group_name;
+
+    /* for XPAT, we have to GROUP into the group before searching */
+    if (!m_newsFolder) {
+        NNTP_LOG_NOTE("m_newsFolder is null, panic!");
+        return -1;
     }
-    else
-    {
-            PR_LOG(NNTP,PR_LOG_ALWAYS,("(%p) doing GROUP for XPAT", this));
-            nsCString group_name;
-
-            /* for XPAT, we have to GROUP into the group before searching */
-            if (!m_newsFolder) {
-                NNTP_LOG_NOTE("m_newsFolder is null, panic!");
-                return -1;
-            }
-            rv = m_newsFolder->GetRawName(group_name);
-            if (NS_FAILED(rv)) return -1;
-
-            NS_MsgSACopy(&command, "GROUP ");
-            NS_MsgSACat (&command, group_name.get());
-
-            // force a GROUP next time
-            m_currentGroup.Truncate();
-            m_nextState = NNTP_RESPONSE;
-            m_nextStateAfterResponse = NNTP_XPAT_SEND;
-    }
+    rv = m_newsFolder->GetRawName(group_name);
+    if (NS_FAILED(rv)) return -1;
+
+    NS_MsgSACopy(&command, "GROUP ");
+    NS_MsgSACat (&command, group_name.get());
+
+    // force a GROUP next time
+    m_currentGroup.Truncate();
+    m_nextState = NNTP_RESPONSE;
+    m_nextStateAfterResponse = NNTP_XPAT_SEND;
   }
   else if (m_typeWanted == IDS_WANTED)
   {
     m_nextState = NNTP_LIST_GROUP;
     return 0;
   }
   else  /* article or cancel */
   {
@@ -3983,26 +3955,26 @@ FAIL:
   PR_Free (body);
 
   return status;
 }
 
 PRInt32 nsNNTPProtocol::XPATSend()
 {
   int status = 0;
-  char *thisTerm = NULL;
-
-  if (m_searchData &&
-    (thisTerm = PL_strchr(m_searchData, '/')) != NULL) {
+  PRInt32 slash = m_searchData.FindChar('/');
+
+  if (slash >= 0)
+  {
     /* extract the XPAT encoding for one query term */
     /* char *next_search = NULL; */
     char *command = NULL;
     char *unescapedCommand = NULL;
     char *endOfTerm = NULL;
-    NS_MsgSACopy (&command, ++thisTerm);
+    NS_MsgSACopy (&command, m_searchData.get() + slash + 1);
     endOfTerm = PL_strchr(command, '/');
     if (endOfTerm)
       *endOfTerm = '\0';
     NS_MsgSACat(&command, CRLF);
 
     unescapedCommand = MSG_UnEscapeSearchUrl(command);
 
     /* send one term off to the server */
@@ -4066,22 +4038,22 @@ PRInt32 nsNNTPProtocol::XPATResponse(nsI
           if (searchAdapter)
             searchAdapter->AddHit((PRUint32) articleNumber);
         }
       }
     }
     else
     {
       /* set up the next term for next time around */
-      char *nextTerm = PL_strchr(m_searchData, '/');
-
-      if (nextTerm)
-        m_searchData = ++nextTerm;
+      PRInt32 slash = m_searchData.FindChar('/');
+
+      if (slash >= 0)
+        m_searchData.Cut(0, slash + 1);
       else
-        m_searchData = nsnull;
+        m_searchData.Truncate();
 
       m_nextState = NNTP_XPAT_SEND;
       ClearFlag(NNTP_PAUSE_FOR_READ);
       PR_FREEIF(line);
       return 0;
     }
   }
   PR_FREEIF(line);
--- a/mailnews/news/src/nsNNTPProtocol.h
+++ b/mailnews/news/src/nsNNTPProtocol.h
@@ -248,17 +248,17 @@ private:
   PRInt32    m_cancelStatus;
 
   // variable for ReadNewsList
   PRInt32   m_readNewsListCount;
 
   // Per news article state information. (article number, author, subject, id, etc
   nsCString m_messageID;
   PRInt32   m_articleNumber;   /* current article number */
-  char   *m_searchData;
+  nsCString m_searchData;
 
   PRInt32   m_originalContentLength; /* the content length at the time of calling graph progress */
 
   nsCOMPtr<nsIStringBundle> m_stringBundle;
 
   nsCOMPtr<nsINntpIncomingServer> m_nntpServer;
 
   nsresult GetNewsStringByName(const char *aName, PRUnichar **aString);
--- a/mailnews/news/test/unit/test_internalUris.js
+++ b/mailnews/news/test/unit/test_internalUris.js
@@ -186,16 +186,17 @@ function test_forwardInline() {
     localserver, Ci.nsIMsgComposeService.kForwardInline);
 }
 
 function run_test() {
   daemon = setupNNTPDaemon();
   localserver = setupLocalServer(NNTP_PORT);
   server = new nsMailServer(new NNTP_RFC2980_handler(daemon));
   server.start(NNTP_PORT);
+  server.setDebugLevel(fsDebugAll);
 
   // Set up an identity for posting
   var acctmgr = Cc["@mozilla.org/messenger/account-manager;1"]
                   .getService(Ci.nsIMsgAccountManager);
   let identity = acctmgr.createIdentity();
   identity.fullName = "Normal Person";
   identity.email = "fake@acme.invalid";
   acctmgr.FindAccountForServer(localserver).addIdentity(identity);