merge with master
[framework/osp/net.git] / src / http / FNetHttp_HttpCommon.cpp
index 99c7901..b790eff 100644 (file)
@@ -34,6 +34,7 @@
 #include <FApp_AppInfo.h>
 #include <FIoDirectory.h>
 #include "FNetHttp_HttpCommon.h"
+#include "FNetHttp_HttpTransactionEvent.h"
 
 using namespace std;
 using namespace Tizen::Base;
@@ -119,10 +120,23 @@ static const char* NetHttpTransactionEventTypesToString[] =
        "_HTTP_TRANSACTION_EVENT_TYPE_DOWNLOAD_PROGRESS"
 };
 
+static const char* NetHttpCertificateVerificationFlagToString[] =
+{
+       "HTTP_CV_FLAG_AUTOMATIC",
+       "HTTP_CV_FLAG_MANUAL",
+       "HTTP_CV_FLAG_IGNORED"
+};
+
+const char*
+_HttpUtility::ConvertHttpTransactionEventTypeToString(_HttpTransactionEventType type)
+{
+       return NetHttpTransactionEventTypesToString[type];
+}
+
 const char*
-_HttpUtility::ConvertHttpTransactionEventTypeToString(_HttpTransactionEventType index)
+_HttpUtility::ConvertNetHttpCertificateVerificationFlagToString(NetHttpCertificateVerificationFlag flag)
 {
-       return NetHttpTransactionEventTypesToString[index];
+       return NetHttpCertificateVerificationFlagToString[flag];
 }
 
 void
@@ -456,7 +470,7 @@ _HttpUtility::GetSslCertList(void)
 }
 
 result
-_HttpUtility::AddSslCertInfo(_HttpSslInfo & sslInfo)
+_HttpUtility::SetSslCertInfo(_HttpSslInfo & sslInfo)
 {
        result r = E_SUCCESS;
 
@@ -474,15 +488,11 @@ _HttpUtility::AddSslCertInfo(_HttpSslInfo & sslInfo)
        return r;
 }
 
-IList*
-_HttpUtility::GetSslCertInfoN(int socketFd)
+_HttpSslInfo*
+_HttpUtility::GetSslCertInfo(int socketFd)
 {
        ClearLastResult();
 
-       unique_ptr<IList> pResultList(new (std::nothrow)LinkedList());
-       SysTryReturn(NID_NET_HTTP, pResultList != null, null, E_OUT_OF_MEMORY,
-                               "[E_OUT_OF_MEMORY] Memory allocation failed.");
-
        IList* pServerCertList = GetSslCertList();
        Mutex* pHttpMutex = GetHttpMutex();
        _HttpSslInfo* pSSLInfo = null;
@@ -504,42 +514,26 @@ _HttpUtility::GetSslCertInfoN(int socketFd)
                if (pSSLInfo->GetSocketFd() == socketFd)
                {
                        SysLog(NID_NET_HTTP, "Found the same server cert.");
-                       pResultList->Add(*pSSLInfo);
+                       return pSSLInfo;
                }
        }
 
-       return pResultList.release();
+       return null;
 }
 
 result
-_HttpUtility::RemoveSslCertInfo(int socketFd)
+_HttpUtility::RemoveSslCertInfo(_HttpSslInfo & sslInfo)
 {
        ClearLastResult();
        result r = E_SUCCESS;
        Mutex* pHttpMutex = GetHttpMutex();
-       _HttpSslInfo* pSSLInfo = null;
        IList *pServerCertList = GetSslCertList();
 
-       unique_ptr<IList> pResultList(GetSslCertInfoN(socketFd));
-       SysTryReturnResult(NID_NET_HTTP, pResultList != null, E_OUT_OF_MEMORY,
-                       "Memory allocation failed.");
-
        MutexGuard locked(*pHttpMutex);
        SysTryReturnResult(NID_NET_HTTP, locked.IsLocked(), E_SYSTEM,
                        "Failed to lock mutex.");
 
-       unique_ptr<IEnumerator> pEnum(pResultList->GetEnumeratorN());
-       while (pEnum->MoveNext() == E_SUCCESS)
-       {
-               pSSLInfo = dynamic_cast< _HttpSslInfo* >(pEnum->GetCurrent());
-               SysTryReturnResult(NID_NET_HTTP, pSSLInfo != null, E_OUT_OF_MEMORY,
-                                       "Memory allocation failed.");
-
-               SysLog(NID_NET_HTTP, "Found the server cert. socketFd(%d), depth(%d)", pSSLInfo->GetSocketFd(), pSSLInfo->GetDepth());
-               pServerCertList->Remove(*pSSLInfo, false);
-       }
-
-       pResultList->RemoveAll(true);
+       pServerCertList->Remove(sslInfo, true);
 
        return r;
 }
@@ -749,6 +743,16 @@ _HttpSslInfo::_HttpSslInfo(int socketFd, int depth, const String & serverCert, c
        __depth = depth;
        __serverCert = serverCert;
        __errorMessage = errorMessage;
+       __pHttpTransactionEvent = null;
+       __flag = HTTP_CV_FLAG_AUTOMATIC;
+}
+
+_HttpSslInfo::_HttpSslInfo(int socketFd, _HttpTransactionEvent* pHttpTransactionEvent)
+{
+       __socketFd = socketFd;
+       __depth = -1;
+       __pHttpTransactionEvent = pHttpTransactionEvent;
+       __flag = HTTP_CV_FLAG_MANUAL;
 }
 
 _HttpSslInfo::~_HttpSslInfo()
@@ -779,4 +783,16 @@ _HttpSslInfo::GetSocketFd() const
        return __socketFd;
 }
 
+_HttpTransactionEvent*
+_HttpSslInfo::GetHttpTransactionEvent(void) const
+{
+       return __pHttpTransactionEvent;
+}
+
+NetHttpCertificateVerificationFlag
+_HttpSslInfo::GetCertificateVerificationFlag(void) const
+{
+       return __flag;
+}
+
 } } } // Tizen::Net::Http