atext/server/src/atextmetadata.cpp
changeset 51 20ac952a623c
parent 33 4e80e1b997a8
--- a/atext/server/src/atextmetadata.cpp	Thu Sep 23 17:06:47 2010 +0300
+++ b/atext/server/src/atextmetadata.cpp	Wed Oct 13 16:20:29 2010 +0300
@@ -1529,7 +1529,6 @@
         aCleanupInfo.iEntryCreated = ETrue;
         aCleanupInfo.iEntryIndex = iPluginData->Count() - 1;
         foundIndex = aCleanupInfo.iEntryIndex;
-        foundEntry = &(*iPluginData)[foundIndex];
         }
     // Now foundEntry is either the found entry or a newly added entry.
     // Make the iSupport metadata point to this.
@@ -1565,9 +1564,12 @@
         TRACE_FUNC_EXIT
         User::Leave( KErrGeneral );
         }
+    TBool createdEntries = EFalse;
     if ( !aEntries )
         {
         aEntries = new (ELeave) CArrayFixFlat<TATExtOneCmdSupport>( KGranularity );
+        CleanupDeleteAndNullPushL( aEntries ); // we can't expect the caller to do this as they don't know about it yet
+        createdEntries = ETrue;
         }
     TATExtOneCmdSupport oneCmdSupport;
     oneCmdSupport.iSupportType = aSupportType;
@@ -1601,6 +1603,11 @@
             User::Leave( KErrNotSupported );
             }
         }
+    if ( createdEntries )
+        {
+        // ownership is transferred to the caller
+        CleanupStack::Pop( aEntries );
+        }
     TRACE_FUNC_EXIT
     return retVal;
     }
@@ -1996,21 +2003,40 @@
     TRACE_FUNC_ENTRY
     // First extract the base of AT command from aAtCmdFull
     // ('=' and everything after that)
-    TInt newLength = aAtCmdFull.Length();
+    TInt fullLength = aAtCmdFull.Length();
+    TInt newLength = fullLength;
+    TInt findIndex = KErrNotFound;
     TInt foundPos = aAtCmdFull.Locate( '=' );
-    if ( foundPos >= 2 )  // After "AT"
+    TRACE_INFO(( _L8("Base length before = %d"), fullLength ));
+    if ( foundPos >= 0 )
         {
+        findIndex = foundPos - 1;
         newLength = foundPos;
+        TRACE_INFO(( _L8("Adjust case 1 = %d/%d"), findIndex, newLength ));
         }
-    else if ( newLength >= 1 )
+    else
         {
         // There was no '=' so check if the last character is '?'.
         // If it is then remove it.
-        if ( aAtCmdFull[newLength-1] == '?' )
+        TInt lastIndex = fullLength - 1;
+        if ( aAtCmdFull[lastIndex] == '?' )
             {
-            newLength--;
+            findIndex = lastIndex - 1;
+            newLength = fullLength - 1;
+            }
+        TRACE_INFO(( _L8("Adjust case 2 = %d/%d"), findIndex, newLength ));
+        }
+    // Next correct newLength so that it doesn't contain the space(s)
+    for ( ; findIndex>=0; findIndex--,newLength-- )
+        {
+        TChar character = aAtCmdFull[findIndex];
+        if ( !(character.IsSpace()||character==0x00) )
+            {
+            break;
             }
         }
+    // The following should tolerate also zero length
+    TRACE_INFO(( _L8("Base length after = %d"), newLength ));
     HBufC8* baseCmd = HBufC8::NewMaxLC( newLength );
     TPtr8 baseCmdPtr = baseCmd->Des();
     baseCmdPtr.Copy( &aAtCmdFull[0], newLength );
@@ -2045,11 +2071,12 @@
         aComplInfo.iProcessed = EFalse;
         aComplInfo.iReplyExpected = ETrue;
         CreateSelfReplyData( aMessage );
-        CleanupStack::PopAndDestroy();
         TRACE_FUNC_EXIT
         return;
         }
-    TATExtEntrySupport entrySupport( aAtCmdFull, aMessage, support );
+    TATExtEntrySupport entrySupport( aAtCmdFull,
+                                     const_cast<RMessage2&>(aMessage),
+                                     support );
     TInt i;
     aComplInfo.iProcessed = EFalse;
     TInt count = support->Count();
@@ -2141,11 +2168,14 @@
     HBufC8* atCmdFull = HBufC8::NewMaxLC( aEntrySupport.iAtCmdFull.Length() );
     TPtr8 atCmdFullPtr = atCmdFull->Des();
     atCmdFullPtr.Copy( aEntrySupport.iAtCmdFull );
+    // First send the entry to the observers
+    TATExtEntrySupport handleCommandEntry = aEntrySupport;
+    aEntrySupport.iStartIndex = aStartIndex;
+    SendToMultipleObserverL( aEntrySupport, atCmdFull );
+    aEntrySupport = handleCommandEntry;
     // Now execute the HandleCommand()
     iCmdData.iReplyExpected = ETrue;  // Set before HandleCommandL()
     HandleCommandL( aEntrySupport, ETrue );
-    aEntrySupport.iStartIndex = aStartIndex;
-    SendToMultipleObserverL( aEntrySupport, atCmdFull );
     CleanupStack::PopAndDestroy( atCmdFull );
     aReplyExpected = ETrue;
     TRACE_FUNC_EXIT
@@ -2187,8 +2217,8 @@
         TPtr8 atCmdFullPtr = atCmdFull->Des();
         atCmdFullPtr.Copy( aEntrySupport.iAtCmdFull );
         // Now execute the HandleCommand()
+        SendToMultipleObserverL( nextSupport, atCmdFull );
         HandleCommandL( aEntrySupport, EFalse );
-        SendToMultipleObserverL( nextSupport, atCmdFull );
         CleanupStack::PopAndDestroy( atCmdFull );
         }
     else
@@ -2289,6 +2319,7 @@
         TRACE_FUNC_EXIT
         return support;
         }
+    CleanupStack::PopAndDestroy( support );
     TRACE_FUNC_EXIT
     return NULL;
     }
@@ -2727,3 +2758,22 @@
     TRACE_FUNC_EXIT
     return KErrNone;
     }
+
+// ---------------------------------------------------------------------------
+// Assignment operator for ease of usage
+// ---------------------------------------------------------------------------
+//
+TATExtEntrySupport& TATExtEntrySupport::operator=( TATExtEntrySupport& aEntrySupport )
+    {
+    if ( &aEntrySupport == this )
+        {
+        return aEntrySupport;
+        }
+    iAtCmdFull = aEntrySupport.iAtCmdFull;
+    iMessage = aEntrySupport.iMessage;
+    iSupport = aEntrySupport.iSupport;
+    iEntry = aEntrySupport.iEntry;
+    iStartIndex = aEntrySupport.iStartIndex;
+    iSupportFound = aEntrySupport.iSupportFound;
+    return *this;
+    }