Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Implemented EditContact and GetContact in CardDAV2
[xestiaab/.git] / source / carddav2 / carddav2.cpp
index f5bc2a3..9d42c04 100644 (file)
@@ -77,8 +77,15 @@ size_t CardDAV2::WritebackFuncImplementation(char *ptr, size_t size, size_t nmem
 }
 
 CardDAV2::~CardDAV2(){
+       
        curl_easy_cleanup(ConnectionSession);
        ConnectionSession = nullptr;
+       
+       if (HeaderList != nullptr){
+               curl_slist_free_all(HeaderList);
+               HeaderList = nullptr;
+       }
+       
 }
 
 #if defined(__APPLE__)
@@ -172,11 +179,12 @@ COConnectResult CardDAV2::Connect(bool DoAuthentication){
        if (TestMode == true){
                SessionResult = curl_easy_perform(ConnectionSession);
        } else {
-               
+               SessionResult = curl_easy_perform(ConnectionSession);           
        }
        
        switch(SessionResult){
                case CURLE_OK:
+               case CURLE_HTTP_RETURNED_ERROR:
                        SSLStatus = true;
                        SSLVerified = COSSL_VERIFIED;
                        ConnectResult = COCONNECT_OK;
@@ -209,7 +217,7 @@ COConnectResult CardDAV2::Connect(bool DoAuthentication){
                        ConnectResult = COCONNECT_OK;
                        AuthPassed = true;
                        ValidResponse = true;
-               } else if (SessionResponseCode == 403){
+               } else if (SessionResponseCode == 401){
                        ConnectResult = COCONNECT_AUTHFAIL;
                        AuthPassed = false;
                        ValidResponse = true;
@@ -336,7 +344,7 @@ COServerResponse CardDAV2::GetDefaultPrefix(string *ServerPrefix){
        } else if (SessionResponseCode == 403){
                AuthPassed = false;
                ValidResponse = true;
-       } else if (SessionResponseCode >= 200) {
+       } else if (SessionResponseCode >= 400) {
                AuthPassed = false;
                ValidResponse = true;
        } else {
@@ -393,19 +401,15 @@ COServerResponse CardDAV2::GetDefaultPrefix(string *ServerPrefix){
        curl_easy_getinfo(ConnectionSession, CURLINFO_RESPONSE_CODE, &SessionResponseCode);
        
        if (SessionResponseCode == 200 || SessionResponseCode == 207){
-               //ConnectResult = COCONNECT_OK;
                AuthPassed = true;
                ValidResponse = true;
        } else if (SessionResponseCode == 403){
-               //ConnectResult = COCONNECT_AUTHFAIL;
                AuthPassed = false;
                ValidResponse = true;
-       } else if (SessionResponseCode >= 200) {
-               //ConnectResult = COCONNECT_INVALID;
+       } else if (SessionResponseCode >= 400) {
                AuthPassed = false;
                ValidResponse = true;
        } else {
-               //ConnectResult = COCONNECT_INVALID;
                AuthPassed = false;
                ValidResponse = false;                  
        }
@@ -472,7 +476,7 @@ COServerResponse CardDAV2::GetDefaultPrefix(string *ServerPrefix){
                ValidResponse = false;                  
        }
        
-       if (ValidResponse == false && AuthPassed == false){
+       if (ValidResponse == false || AuthPassed == false){
                ServerResponse.RequestResult = COREQUEST_ERROR_SERVER;
                ServerResponse.EntityTag = "";
                ServerResponse.SessionCode = SessionResult;
@@ -741,9 +745,173 @@ std::string CardDAV2::GetDefaultAddressBookURI(){
 
 COServerResponse CardDAV2::AddContact(std::string Location, std::string Data){
        
+       // Check if authentication was successful, otherwise don't do anything.
+
+       COServerResponse ServerResponse;
+       
+       if (AuthPassed == false){
+               ServerResponse.RequestResult = COREQUEST_ERROR_NOTCONNECTED;
+               ServerResponse.EntityTag = "";
+               ServerResponse.SessionCode = 0;
+               ServerResponse.ResultCode = 0;
+               ServerResponse.ResultMessage = "";
+               return ServerResponse;
+       }
+
+       ServerSSL ? SetupDefaultParametersSSL(true) : SetupDefaultParametersNonSSL(true);
+       ResetResults();
+       
+       string ServerAddressURL = BuildURL(ServerPrefix + Location);
+       curl_easy_setopt(ConnectionSession, CURLOPT_URL, ServerAddressURL.c_str());
+       curl_easy_setopt(ConnectionSession, CURLOPT_CUSTOMREQUEST, "PUT");
+       curl_easy_setopt(ConnectionSession, CURLOPT_POSTFIELDS, Data.c_str());
+       curl_easy_setopt(ConnectionSession, CURLOPT_POSTFIELDSIZE, strlen(Data.c_str()));
+       
+       HeaderList = curl_slist_append(HeaderList, "Content-Type: text/vcard; charset=utf-8");
+
+       curl_easy_setopt(ConnectionSession, CURLOPT_HTTPHEADER, HeaderList);
+       
+       if (TestMode == true){
+               SessionResult = curl_easy_perform(ConnectionSession);
+       } else {
+               SessionResult = curl_easy_perform(ConnectionSession);
+       }
+       
+       switch(SessionResult){
+               case CURLE_OK:
+                       SSLStatus = true;
+                       SSLVerified = COSSL_VERIFIED;
+                       break;
+               case CURLE_SSL_CACERT:
+               case CURLE_SSL_CONNECT_ERROR:
+                       SSLStatus = true;
+                       SSLVerified = COSSL_UNABLETOVERIFY;
+                       break;
+               default:
+                       break;
+       };
+       
+       long SessionResponseCode = 0;
+       
+       curl_easy_getinfo(ConnectionSession, CURLINFO_RESPONSE_CODE, &SessionResponseCode);
+       
+       if (SessionResponseCode == 200 || SessionResponseCode == 201 || SessionResponseCode == 204){
+               AuthPassed = true;
+               ValidResponse = true;
+       } else if (SessionResponseCode == 403){
+               AuthPassed = false;
+               ValidResponse = true;
+       } else if (SessionResponseCode >= 400){
+               AuthPassed = false;
+               ValidResponse = true;
+       } else {
+               AuthPassed = false;
+               ValidResponse = false;                  
+       }
+       
+       if (ValidResponse == false || AuthPassed == false){
+               ServerResponse.RequestResult = COREQUEST_ERROR_SERVER;
+               ServerResponse.EntityTag = "";
+               ServerResponse.SessionCode = SessionResult;
+               ServerResponse.ResultCode = SessionResponseCode;
+               ServerResponse.ResultMessage = "";
+               return ServerResponse;
+       }
+       
+       CanProcess = true;
+       
+       ServerResponse.RequestResult = COREQUEST_OK;
+       ServerResponse.EntityTag = "";
+       ServerResponse.SessionCode = SessionResult;
+       ServerResponse.ResultCode = SessionResponseCode;
+       ServerResponse.ResultMessage = SessionErrorBuffer;
+       return ServerResponse;
+       
 }
 
 COServerResponse CardDAV2::EditContact(std::string Location, std::string Data){
+
+       // Check if authentication was successful, otherwise don't do anything.
+
+       COServerResponse ServerResponse;
+       
+       if (AuthPassed == false){
+               ServerResponse.RequestResult = COREQUEST_ERROR_NOTCONNECTED;
+               ServerResponse.EntityTag = "";
+               ServerResponse.SessionCode = 0;
+               ServerResponse.ResultCode = 0;
+               ServerResponse.ResultMessage = "";
+               return ServerResponse;
+       }
+
+       ServerSSL ? SetupDefaultParametersSSL(true) : SetupDefaultParametersNonSSL(true);
+       ResetResults();
+       
+       string ServerAddressURL = BuildURL(ServerPrefix + Location);
+       curl_easy_setopt(ConnectionSession, CURLOPT_URL, ServerAddressURL.c_str());
+       curl_easy_setopt(ConnectionSession, CURLOPT_CUSTOMREQUEST, "PUT");
+       curl_easy_setopt(ConnectionSession, CURLOPT_POSTFIELDS, Data.c_str());
+       curl_easy_setopt(ConnectionSession, CURLOPT_POSTFIELDSIZE, strlen(Data.c_str()));
+       
+       HeaderList = curl_slist_append(HeaderList, "Content-Type: text/vcard; charset=utf-8");
+
+       curl_easy_setopt(ConnectionSession, CURLOPT_HTTPHEADER, HeaderList);
+       
+       if (TestMode == true){
+               SessionResult = curl_easy_perform(ConnectionSession);
+       } else {
+               SessionResult = curl_easy_perform(ConnectionSession);
+       }
+       
+       switch(SessionResult){
+               case CURLE_OK:
+                       SSLStatus = true;
+                       SSLVerified = COSSL_VERIFIED;
+                       break;
+               case CURLE_SSL_CACERT:
+               case CURLE_SSL_CONNECT_ERROR:
+                       SSLStatus = true;
+                       SSLVerified = COSSL_UNABLETOVERIFY;
+                       break;
+               default:
+                       break;
+       };
+       
+       long SessionResponseCode = 0;
+       
+       curl_easy_getinfo(ConnectionSession, CURLINFO_RESPONSE_CODE, &SessionResponseCode);
+       
+       if (SessionResponseCode == 200 || SessionResponseCode == 201 || SessionResponseCode == 204){
+               AuthPassed = true;
+               ValidResponse = true;
+       } else if (SessionResponseCode == 403){
+               AuthPassed = false;
+               ValidResponse = true;
+       } else if (SessionResponseCode >= 400){
+               AuthPassed = false;
+               ValidResponse = true;
+       } else {
+               AuthPassed = false;
+               ValidResponse = false;                  
+       }
+       
+       if (ValidResponse == false || AuthPassed == false){
+               ServerResponse.RequestResult = COREQUEST_ERROR_SERVER;
+               ServerResponse.EntityTag = "";
+               ServerResponse.SessionCode = SessionResult;
+               ServerResponse.ResultCode = SessionResponseCode;
+               ServerResponse.ResultMessage = "";
+               return ServerResponse;
+       }
+       
+       CanProcess = true;
+       
+       ServerResponse.RequestResult = COREQUEST_OK;
+       ServerResponse.EntityTag = "";
+       ServerResponse.SessionCode = SessionResult;
+       ServerResponse.ResultCode = SessionResponseCode;
+       ServerResponse.ResultMessage = SessionErrorBuffer;
+       return ServerResponse;
        
 }
 
@@ -753,9 +921,176 @@ COServerResponse CardDAV2::DeleteContact(std::string Location, std::string Entit
 
 COServerResponse CardDAV2::GetServerEntityTagValue(std::string Location){
        
+       // Check if authentication was successful, otherwise don't do anything.
+
+       COServerResponse ServerResponse;
+       
+       if (AuthPassed == false){
+               ServerResponse.RequestResult = COREQUEST_ERROR_NOTCONNECTED;
+               ServerResponse.EntityTag = "";
+               ServerResponse.SessionCode = 0;
+               ServerResponse.ResultCode = 0;
+               ServerResponse.ResultMessage = "";
+               return ServerResponse;
+       }
+
+       ServerSSL ? SetupDefaultParametersSSL(true) : SetupDefaultParametersNonSSL(true);
+       ResetResults();
+       
+       static const char* GetETagQuery =
+       "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"
+       "<C:addressbook-query xmlns:D=\"DAV:\""
+       "       xmlns:C=\"urn:ietf:params:xml:ns:carddav\">"
+       "<D:prop><D:getetag/>"
+       "</D:prop>"
+       "<C:filter/>"
+       "</C:addressbook-query>";
+       
+       string ServerAddressURL = BuildURL(ServerPrefix + Location);
+       curl_easy_setopt(ConnectionSession, CURLOPT_URL, ServerAddressURL.c_str());
+       curl_easy_setopt(ConnectionSession, CURLOPT_CUSTOMREQUEST, "REPORT");
+       curl_easy_setopt(ConnectionSession, CURLOPT_POSTFIELDS, GetETagQuery);
+       curl_easy_setopt(ConnectionSession, CURLOPT_POSTFIELDSIZE, strlen(GetETagQuery));
+       
+       if (TestMode == true){
+               SessionResult = curl_easy_perform(ConnectionSession);
+       } else {
+               SessionResult = curl_easy_perform(ConnectionSession);
+       }
+       
+       switch(SessionResult){
+               case CURLE_OK:
+                       SSLStatus = true;
+                       SSLVerified = COSSL_VERIFIED;
+                       break;
+               case CURLE_SSL_CACERT:
+               case CURLE_SSL_CONNECT_ERROR:
+                       SSLStatus = true;
+                       SSLVerified = COSSL_UNABLETOVERIFY;
+                       break;
+               default:
+                       break;
+       };
+       
+       long SessionResponseCode = 0;
+       
+       curl_easy_getinfo(ConnectionSession, CURLINFO_RESPONSE_CODE, &SessionResponseCode);
+       
+       if (SessionResponseCode == 207){
+               AuthPassed = true;
+               ValidResponse = true;
+       } else if (SessionResponseCode == 403){
+               AuthPassed = false;
+               ValidResponse = true;
+       } else if (SessionResponseCode >= 400){
+               AuthPassed = false;
+               ValidResponse = true;
+       } else {
+               AuthPassed = false;
+               ValidResponse = false;                  
+       }
+       
+       if (ValidResponse == false || AuthPassed == false){
+               ServerResponse.RequestResult = COREQUEST_ERROR_SERVER;
+               ServerResponse.EntityTag = "";
+               ServerResponse.SessionCode = SessionResult;
+               ServerResponse.ResultCode = SessionResponseCode;
+               ServerResponse.ResultMessage = "";
+               return ServerResponse;
+       }
+       
+       CanProcess = true;
+       
+       ServerResponse.RequestResult = COREQUEST_OK;
+       ServerResponse.EntityTag = GetETagValue();
+       ServerResponse.SessionCode = SessionResult;
+       ServerResponse.ResultCode = SessionResponseCode;
+       ServerResponse.ResultMessage = SessionErrorBuffer;
+       
+       return ServerResponse;
+       
 }
 
-COServerResponse CardDAV2::GetContact(std::string Location){
+COServerResponse CardDAV2::GetContact(std::string Location, std::string *ContactData){
+       
+       // Check if authentication was successful, otherwise don't do anything.
+
+       COServerResponse ServerResponse;
+       
+       if (AuthPassed == false){
+               ServerResponse.RequestResult = COREQUEST_ERROR_NOTCONNECTED;
+               ServerResponse.EntityTag = "";
+               ServerResponse.SessionCode = 0;
+               ServerResponse.ResultCode = 0;
+               ServerResponse.ResultMessage = "";
+               return ServerResponse;
+       }
+
+       ServerSSL ? SetupDefaultParametersSSL(true) : SetupDefaultParametersNonSSL(true);
+       ResetResults();
+       
+       string ServerAddressURL = BuildURL(ServerPrefix + Location);
+       curl_easy_setopt(ConnectionSession, CURLOPT_URL, ServerAddressURL.c_str());
+       curl_easy_setopt(ConnectionSession, CURLOPT_CUSTOMREQUEST, "GET");
+       
+       if (TestMode == true){
+               SessionResult = curl_easy_perform(ConnectionSession);
+       } else {
+               SessionResult = curl_easy_perform(ConnectionSession);
+       }
+       
+       switch(SessionResult){
+               case CURLE_OK:
+                       SSLStatus = true;
+                       SSLVerified = COSSL_VERIFIED;
+                       break;
+               case CURLE_SSL_CACERT:
+               case CURLE_SSL_CONNECT_ERROR:
+                       SSLStatus = true;
+                       SSLVerified = COSSL_UNABLETOVERIFY;
+                       break;
+               default:
+                       break;
+       };
+       
+       long SessionResponseCode = 0;
+       
+       curl_easy_getinfo(ConnectionSession, CURLINFO_RESPONSE_CODE, &SessionResponseCode);
+       
+       if (SessionResponseCode == 200){
+               AuthPassed = true;
+               ValidResponse = true;
+       } else if (SessionResponseCode == 403){
+               AuthPassed = false;
+               ValidResponse = true;
+       } else if (SessionResponseCode >= 400){
+               AuthPassed = false;
+               ValidResponse = true;
+       } else {
+               AuthPassed = false;
+               ValidResponse = false;                  
+       }
+       
+       if (ValidResponse == false && AuthPassed == false){
+               ServerResponse.RequestResult = COREQUEST_ERROR_SERVER;
+               ServerResponse.EntityTag = "";
+               ServerResponse.SessionCode = SessionResult;
+               ServerResponse.ResultCode = SessionResponseCode;
+               ServerResponse.ResultMessage = "";
+               return ServerResponse;
+       }
+       
+       CanProcess = true;
+       
+       ServerResponse.RequestResult = COREQUEST_OK;
+       ServerResponse.EntityTag = "";
+       ServerResponse.SessionCode = SessionResult;
+       ServerResponse.ResultCode = SessionResponseCode;
+       ServerResponse.ResultMessage = SessionErrorBuffer;
+       
+       (*ContactData) = PageData;
+       
+       return ServerResponse;
        
 }
 
@@ -805,6 +1140,9 @@ void CardDAV2::SetupDefaultParametersNonSSL(bool DoAuthentication){
        curl_easy_setopt(ConnectionSession, CURLOPT_WRITEHEADER, &PageHeader);
        curl_easy_setopt(ConnectionSession, CURLOPT_NOSIGNAL, 1);
        curl_easy_setopt(ConnectionSession, CURLOPT_CUSTOMREQUEST, "GET");
+       curl_easy_setopt(ConnectionSession, CURLOPT_HTTPHEADER, nullptr);
+       curl_easy_setopt(ConnectionSession, CURLOPT_POSTFIELDS, nullptr);
+       curl_easy_setopt(ConnectionSession, CURLOPT_POSTFIELDSIZE, 0L);
        
        if (DoAuthentication == true){
                curl_easy_setopt(ConnectionSession, CURLOPT_USERPWD, UsernamePassword.c_str());
@@ -835,6 +1173,9 @@ void CardDAV2::SetupDefaultParametersSSL(bool DoAuthentication){
        curl_easy_setopt(ConnectionSession, CURLOPT_CERTINFO, 1);
        curl_easy_setopt(ConnectionSession, CURLOPT_VERBOSE, 1);
        curl_easy_setopt(ConnectionSession, CURLOPT_CUSTOMREQUEST, "GET");
+       curl_easy_setopt(ConnectionSession, CURLOPT_HTTPHEADER, nullptr);
+       curl_easy_setopt(ConnectionSession, CURLOPT_POSTFIELDS, nullptr);
+       curl_easy_setopt(ConnectionSession, CURLOPT_POSTFIELDSIZE, 0L);
        
        if (DoAuthentication == true){
                curl_easy_setopt(ConnectionSession, CURLOPT_USERPWD, UsernamePassword.c_str());
@@ -850,6 +1191,20 @@ void CardDAV2::SetupDefaultParametersSSL(bool DoAuthentication){
                curl_easy_setopt(ConnectionSession, CURLOPT_SSL_VERIFYPEER, 1);         
        }
        
+       if (TestMode == false && ServerAccount.size() > 0){
+               
+               // Check if the server certificate file exists.
+               
+               string CertificateFilename = GetAccountDir(ServerAccount, true);
+               
+               if (wxFile::Exists(CertificateFilename)){
+                       
+                       curl_easy_setopt(ConnectionSession, CURLOPT_CAINFO, CertificateFilename.c_str());
+                       
+               }
+               
+       }
+       
 }
 
 string CardDAV2::BuildURL(string URI){
@@ -886,18 +1241,240 @@ void CardDAV2::ResetResults(){
        SessionErrorBuffer[0] = '\0';
        PageData = "";
        PageHeader = "";
+       if (HeaderList != nullptr){
+               curl_slist_free_all(HeaderList);
+               HeaderList = nullptr;
+       }
        
 }
 
-vector<string> CardDAV2::GetDAVHeader(){
+string CardDAV2::GetETagValue(){
+       
+       xmlDocPtr xmlCardDAVDoc;
+
+       xmlCardDAVDoc = xmlReadMemory(PageData.c_str(), (int)PageData.size(), "noname.xml", NULL, 0);
+
+       xmlNodePtr nodeLevel1;
+       xmlNodePtr nodeLevel2;
+       xmlNodePtr nodeLevel3;
+       xmlNodePtr nodeLevel4;
+       xmlNodePtr nodeLevel5;
+       xmlNodePtr nodeLevel6;
+
+       //std::map<wxString,wxString> xmlDataMap;
+
+       std::string DataFilename;
+       std::string ETagData;
+
+       std::string xmlStringSafe;
+       std::string ETagValue;
+
+       // Tranverse through the catacombs of the response to get our ETag for the file.
+
+       for (nodeLevel1 = xmlCardDAVDoc->children;
+               nodeLevel1 != NULL;
+               nodeLevel1 = nodeLevel1->next)
+       {
+
+               bool HREFFound = FALSE;
+               bool ETagFound = FALSE;
+
+               for (nodeLevel2 = nodeLevel1->children;
+                       nodeLevel2 != NULL;
+                       nodeLevel2 = nodeLevel2->next)
+               {
+
+                       for (nodeLevel3 = nodeLevel2->children;
+                       nodeLevel3 != NULL;
+                       nodeLevel3 = nodeLevel3->next)
+                       {
+
+                               if (!xmlStrcmp(nodeLevel3->name, (const xmlChar *)"href") ||
+                               !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"d:href") ||
+                               !xmlStrcmp(nodeLevel3->name, (const xmlChar *)"D:href")
+                               ){
+
+                                       // Get the filename.
+                                       
+                                       for (nodeLevel4 = nodeLevel3->children;
+                                       nodeLevel4 != NULL;
+                                       nodeLevel4 = nodeLevel4->next)
+                                       {
+                                       
+                                               if (!xmlStrcmp(nodeLevel4->name, (const xmlChar *)"text") ||
+                                               !xmlStrcmp(nodeLevel4->name, (const xmlChar *)"d:text") ||
+                                               !xmlStrcmp(nodeLevel4->name, (const xmlChar *)"D:text")
+                                               ){
+
+                                                       DataFilename = wxString::FromUTF8((const char*)nodeLevel4->content);
+                                                       wxStringTokenizer wSTDFilename(DataFilename, wxT("/"));
+                                               
+                                                       while (wSTDFilename.HasMoreTokens()){
+                                                       
+                                                               DataFilename = wSTDFilename.GetNextToken().ToStdString();
+                                                       
+                                                       }
+                                                       
+                                                       HREFFound = TRUE;
+                                               
+                                               }
+                                               
+       
+                                       
+                                       }
+
+                               } else {
+
+                                       for (nodeLevel4 = nodeLevel3->children;
+                                       nodeLevel4 != NULL;
+                                       nodeLevel4 = nodeLevel4->next)
+                                       {
+                                                       
+                                                       for (nodeLevel5 = nodeLevel4->children;
+                                                       nodeLevel5 != NULL;
+                                                       nodeLevel5 = nodeLevel5->next)
+                                                       {
+
+                                                               if (!xmlStrcmp(nodeLevel5->name, (const xmlChar *)"getetag") ||
+                                                               !xmlStrcmp(nodeLevel5->name, (const xmlChar *)"d:getetag") ||
+                                                               !xmlStrcmp(nodeLevel5->name, (const xmlChar *)"D:getetag")
+                                                               ){
+
+                                                                       for (nodeLevel6 = nodeLevel5->children;
+                                                                       nodeLevel6 != NULL;
+                                                                       nodeLevel6 = nodeLevel6->next)
+                                                                       {
+                                                       
+                                                                               // Strip the quotes from the ETag.
+                                                       
+                                                                               ETagData = (const char*)nodeLevel6->content;
+                                                                               if (ETagData[0] == '"' && ETagData[(ETagData.size() - 1)] == '"'){
+                                                       
+                                                                                       ETagData.erase(0, 1);
+                                                                                       ETagData.erase((ETagData.size() - 1));
+                                                       
+                                                                               }
+                                                                       
+                                                                               ETagFound = TRUE;
+
+                                                                       }
+                                                                       
+                                                               }
+
+                                                       }       
+
+                                       }
+
+                               }
+
+                       }
+
+               }
+               
+               if (HREFFound == TRUE && ETagFound == TRUE){
+                               
+                       // Add to the map data.
+                               
+                       ETagValue = ETagData;
+                       
+                       HREFFound = FALSE;
+                       ETagFound = FALSE;
+                       break;
+                               
+               }
+
+
+       }
+
+       xmlFreeDoc(xmlCardDAVDoc);
+       
+       return ETagValue;
+       
+}
+
+string CardDAV2::GetETagHeader(){
        
        // Go through each of the lines looking for the
        // 'DAV:' section.
        
+       string HeaderName;
+       string HeaderValue;
+       bool FastForward = false;
+       
+       for (int HeaderSeek = 0; HeaderSeek < PageHeader.size(); HeaderSeek++){
+               
+               if (FastForward == true){
+                       
+                       if (PageHeader[HeaderSeek] == '\n'){
+                               FastForward = false;
+                       }
+                       
+                       continue;
+                       
+               }
+               
+               try {
+                       PageHeader.substr(HeaderSeek, 5) == "ETag:";
+               }
+               
+               catch (const out_of_range &oor){
+                       break;
+               }
+               
+               if (PageHeader.substr(HeaderSeek, 5) == "ETag:"){
+                       
+                       int CharacterSeek = 5;
+                       
+                       while ((HeaderSeek + CharacterSeek) < PageHeader.size()){
+                               
+                               if (PageHeader.substr((HeaderSeek + CharacterSeek), 2) == "\r\n"){
+                                       break;
+                               }
+                               
+                               HeaderValue += PageHeader.substr((HeaderSeek + CharacterSeek), 1);
+                               CharacterSeek++;
+                       }
+                       
+                       break;
+                       
+               } else {
+                       
+                       FastForward = true;
+                       continue;
+                       
+               }
+               
+               if (PageHeader[HeaderSeek] == '\n'){
+                       HeaderName = "";
+               }
+               
+               //HeaderName += PageHeader.substr(HeaderSeek, 1);
+               
+       }
+       
+       // Check for quotation marks at the start and end and strip
+       // them out.
+       
+       if (HeaderValue.size() >= 2){
+               
+               if (HeaderValue[0] == '"'){
+                       HeaderValue.erase((HeaderValue.size() - 1));
+                       HeaderValue.erase(0);
+               }
+               
+       }
+       
+       return HeaderValue;
+       
+}
+
+vector<string> CardDAV2::GetDAVHeader(){
+       
+       // Go through each of the lines looking for the
+       // 'DAV:' section.
        
        string HeaderName;
        string HeaderValue;
-       bool DAVFound = false;
        bool FastForward = false;
        vector<string> DAVHeaderList;
        
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