Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Updated SSL code for it to work properly and added curl_easy_cleanup where required.
authorSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 20 Sep 2015 12:02:03 +0000 (13:02 +0100)
committerSteve Brokenshire <sbrokenshire@xestia.co.uk>
Sun, 20 Sep 2015 12:02:03 +0000 (13:02 +0100)
source/carddav/carddav.cpp

index 4b08fbb..851b55c 100644 (file)
@@ -456,7 +456,7 @@ bool CardDAV::Connect(){
 \r
                }\r
 \r
-               /*curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));\r
+               curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));\r
                curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);\r
                curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);\r
                curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);\r
@@ -470,11 +470,6 @@ bool CardDAV::Connect(){
                curl_easy_setopt(conn, CURLOPT_CERTINFO, 1);\r
 \r
                conncode = (curl_easy_perform(conn));\r
-\r
-               union {\r
-                       struct curl_slist       *certdata;\r
-                       struct curl_certinfo    *certinfo;\r
-               } ptr;\r
                \r
                ptr.certdata = NULL;\r
 \r
@@ -958,7 +953,7 @@ void CardDAV::ProcessDataThread(){
                        SSLCertCol = BuildSSLCollection(sslerrconn);\r
                        SSLCertCol.SuccessCode = 1;\r
 \r
-                       return;\r
+                       return;\r
                \r
                } else if (claconncode == CURLE_HTTP_RETURNED_ERROR){\r
                \r
@@ -1171,7 +1166,7 @@ void CardDAV::ProcessDataThread(){
        \r
        // Catch all.\r
        \r
-       ActIter->second = 1;\r
+       //ActIter->second = 1;\r
        *ServerResult = TRUE;\r
        return;\r
 \r
@@ -1357,21 +1352,22 @@ void CardDAV::GetServerContactData()
 \r
                        wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");\r
 \r
-                       curl_easy_setopt(conn, CURLOPT_URL, (const char*)ServerAddressSSL.mb_str(wxConvUTF8));\r
-                       curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1L);\r
-                       curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);\r
-                       curl_easy_setopt(conn, CURLOPT_TIMEOUT, 60);\r
-                       curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);\r
-                       curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);             \r
-                       curl_easy_setopt(conn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));\r
-                       curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFunc);\r
-                       curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);\r
-                       curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);\r
-                       curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);\r
+                       curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8));\r
+                       curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 1L);\r
+                       curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);\r
+                       curl_easy_setopt(sslerrconn, CURLOPT_TIMEOUT, 60);\r
+                       curl_easy_setopt(sslerrconn, CURLOPT_FAILONERROR, TRUE);\r
+                       curl_easy_setopt(sslerrconn, CURLOPT_USERAGENT, XSDAB_USERAGENT);               \r
+                       curl_easy_setopt(sslerrconn, CURLOPT_USERPWD, (const char*)ServerAuth.mb_str(wxConvUTF8));\r
+                       curl_easy_setopt(sslerrconn, CURLOPT_WRITEFUNCTION, WritebackFunc);\r
+                       curl_easy_setopt(sslerrconn, CURLOPT_WRITEDATA, &PageData);\r
+                       curl_easy_setopt(sslerrconn, CURLOPT_WRITEHEADER, &PageHeader);\r
+                       curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1);\r
                \r
                        //UploadData.readptr = &CardDAVDataQuery;\r
                        //UploadData.sizeleft = CardDAVDataQuery.Len();\r
                        curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0);\r
+                       curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYHOST, 0);\r
                        curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1);\r
                \r
                        wxString SSLLocalData;\r
@@ -1394,9 +1390,6 @@ void CardDAV::GetServerContactData()
                        // Load the recovery database for tasks not done.\r
        \r
                        if (SSLLocalFile.IsOpened() == TRUE){\r
-\r
-                       // Check if we are using wxWidgets version 2.8 or less and\r
-                       // execute the required command accordingly.\r
        \r
                                SSLLocalFile.ReadAll(&SSLLocalData, wxConvAuto());\r
                \r
@@ -1592,7 +1585,8 @@ void CardDAV::GetServerETagValueThread()
        SSLStatus = TRUE;\r
        AuthPassed = TRUE;\r
        AbortConnection = FALSE;\r
-\r
+       \r
+       bool FilenameIsDirectory = FALSE;\r
         CURL *conn;\r
         CURLcode conncode;\r
        wxString ServerAddressURL;\r
@@ -1624,6 +1618,14 @@ void CardDAV::GetServerETagValueThread()
        \r
        ServerAuth = ServerUser + wxT(":") + ServerPass;\r
        \r
+       // Workout if path is directory or filename.\r
+       \r
+       /*if (ServerAddress){\r
+               FilenameIsDirectory = TRUE;\r
+       } else {\r
+               FilenameIsDirectory = FALSE;\r
+       }*/\r
+       \r
        // Try SSL first.\r
 \r
 \r
@@ -1727,7 +1729,7 @@ void CardDAV::GetServerETagValueThread()
                        curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT");\r
                        curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);\r
                        curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);\r
-                       curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));   \r
+                       curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));\r
                        \r
                        claconncode = (curl_easy_perform(conn));\r
                        \r
@@ -1760,6 +1762,9 @@ void CardDAV::GetServerETagValueThread()
 \r
                        wxString ServerAddressOnly = wxT("https://") + ServerAddress + wxT(":") + wxString::Format(wxT("%i"), ServerPort) + wxT("/");\r
 \r
+                       PageData.clear();\r
+                       PageHeader.clear();\r
+\r
                        curl_easy_setopt(sslerrconn, CURLOPT_URL, (const char*)ServerAddressOnly.mb_str(wxConvUTF8));\r
                        curl_easy_setopt(sslerrconn, CURLOPT_NOPROGRESS, 0);\r
                        curl_easy_setopt(sslerrconn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);\r
@@ -1774,6 +1779,9 @@ void CardDAV::GetServerETagValueThread()
                        curl_easy_setopt(sslerrconn, CURLOPT_NOSIGNAL, 1);\r
                        curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 0);\r
                        curl_easy_setopt(sslerrconn, CURLOPT_CERTINFO, 1);\r
+                       curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYPEER, 1);\r
+                       curl_easy_setopt(sslerrconn, CURLOPT_SSL_VERIFYHOST, 2);\r
+                       curl_easy_setopt(sslerrconn, CURLOPT_CAINFO, (const char*)ServerCertFilename.mb_str(wxConvUTF8));\r
                \r
                        wxString SSLLocalData;\r
                        wxString SSLServerData;\r
@@ -1791,7 +1799,7 @@ void CardDAV::GetServerETagValueThread()
 #else\r
                        SSLLocalFile.Open(ServerCertFilename, wxT("r"));\r
 #endif \r
-       \r
+\r
                        // Load the recovery database for tasks not done.\r
        \r
                        if (SSLLocalFile.IsOpened() == TRUE){\r
@@ -1832,7 +1840,9 @@ void CardDAV::GetServerETagValueThread()
                                curl_easy_setopt(conn, CURLOPT_CUSTOMREQUEST, "REPORT");\r
                                curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);\r
                                curl_easy_setopt(conn, CURLOPT_POSTFIELDS, query);\r
-                               curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));           \r
+                               curl_easy_setopt(conn, CURLOPT_POSTFIELDSIZE, strlen(query));\r
+                               curl_easy_setopt(conn, CURLOPT_SSL_VERIFYPEER, 0);\r
+                               curl_easy_setopt(conn, CURLOPT_SSL_VERIFYHOST, 0);              \r
                        \r
                                claconncode = (curl_easy_perform(conn));\r
                                \r
@@ -1851,8 +1861,6 @@ void CardDAV::GetServerETagValueThread()
                \r
                }\r
 \r
-\r
-\r
                // Sort out SSL error.\r
                \r
                // When SSL cert error occurs, connect again and fetch certificates.\r
@@ -1892,6 +1900,9 @@ void CardDAV::GetServerETagValueThread()
                        SSLCertCol = BuildSSLCollection(sslerrconn);\r
                        SSLCertCol.SuccessCode = 1;\r
 \r
+                       curl_easy_cleanup(conn);\r
+                       curl_easy_cleanup(sslerrconn);\r
+\r
                        return;\r
                \r
                } else if (claconncode == CURLE_HTTP_RETURNED_ERROR){\r
@@ -1901,6 +1912,8 @@ void CardDAV::GetServerETagValueThread()
                        int http_code = 0;\r
                        curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code);\r
                        fprintf(stderr, "Error code was: %d\n", http_code);\r
+\r
+                       curl_easy_cleanup(conn);\r
                                        \r
                        return;\r
                \r
@@ -1912,6 +1925,8 @@ void CardDAV::GetServerETagValueThread()
                        curl_easy_getinfo(conn, CURLINFO_RESPONSE_CODE, &http_code);\r
                        fprintf(stderr, "Error code was: %d\n", http_code);\r
 \r
+                       curl_easy_cleanup(conn);\r
+\r
                        return;\r
 \r
                }\r
@@ -1958,7 +1973,7 @@ void CardDAV::GetServerETagValueThread()
                \r
                        fprintf(stderr, "curl_easy_perform() failed: %s\n",\r
                                        curl_easy_strerror(conncode));\r
-                                       \r
+                               \r
                        return;\r
                \r
                } else {\r
@@ -1997,6 +2012,9 @@ void CardDAV::GetServerETagValueThread()
                nodeLevel1 = nodeLevel1->next)\r
        {\r
 \r
+               bool HREFFound = FALSE;\r
+               bool ETagFound = FALSE;\r
+\r
                for (nodeLevel2 = nodeLevel1->children;\r
                        nodeLevel2 != NULL;\r
                        nodeLevel2 = nodeLevel2->next)\r
@@ -2007,9 +2025,6 @@ void CardDAV::GetServerETagValueThread()
                        nodeLevel3 = nodeLevel3->next)\r
                        {\r
 \r
-                               bool HREFFound = FALSE;\r
-                               bool ETagFound = FALSE;\r
-\r
                                if (!xmlStrcmp(nodeLevel3->name, (const xmlChar *)"href") ||\r
                                !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"d:href") ||\r
                                !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"D:href")\r
@@ -2088,21 +2103,19 @@ void CardDAV::GetServerETagValueThread()
 \r
                                }\r
 \r
-                               if (HREFFound == TRUE && ETagFound == TRUE){\r
+                       }\r
+\r
+               }\r
+               \r
+               if (HREFFound == TRUE && ETagFound == TRUE){\r
                                \r
-                                       // Add to the map data.\r
+                       // Add to the map data.\r
                                        \r
-                                       xmlDataMap.insert(std::make_pair(DataFilename, ETagData));\r
-                               \r
-                               }\r
+                       xmlDataMap.insert(std::make_pair(DataFilename, ETagData));\r
                                \r
-                               // Reset the values.\r
+                       HREFFound = FALSE;\r
+                       ETagFound = FALSE;\r
                                \r
-                               HREFFound = FALSE;\r
-                               ETagFound = FALSE;\r
-\r
-                       }\r
-\r
                }\r
 \r
 \r
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy