X-Git-Url: http://Server1/repobrowser/?p=xestiaab%2F.git;a=blobdiff_plain;f=source%2Fcarddav2%2Fcarddav2.cpp;h=9d42c043ff731eef34894f94558c0114e70a1dd7;hp=66982d9ed7a1cf1e53f144a55e502048e76235b0;hb=d269801e3d32dbbea14af5f261190ef097635fce;hpb=22cf85aa4e55ff649647b36c5455db507104cd7c diff --git a/source/carddav2/carddav2.cpp b/source/carddav2/carddav2.cpp index 66982d9..9d42c04 100644 --- a/source/carddav2/carddav2.cpp +++ b/source/carddav2/carddav2.cpp @@ -476,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; @@ -809,7 +809,7 @@ COServerResponse CardDAV2::AddContact(std::string Location, std::string Data){ ValidResponse = false; } - if (ValidResponse == false && AuthPassed == false){ + if (ValidResponse == false || AuthPassed == false){ ServerResponse.RequestResult = COREQUEST_ERROR_SERVER; ServerResponse.EntityTag = ""; ServerResponse.SessionCode = SessionResult; @@ -830,6 +830,88 @@ COServerResponse CardDAV2::AddContact(std::string Location, std::string Data){ } 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; } @@ -908,7 +990,7 @@ COServerResponse CardDAV2::GetServerEntityTagValue(std::string Location){ ValidResponse = false; } - if (ValidResponse == false && AuthPassed == false){ + if (ValidResponse == false || AuthPassed == false){ ServerResponse.RequestResult = COREQUEST_ERROR_SERVER; ServerResponse.EntityTag = ""; ServerResponse.SessionCode = SessionResult; @@ -929,7 +1011,86 @@ COServerResponse CardDAV2::GetServerEntityTagValue(std::string Location){ } -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; } @@ -980,6 +1141,8 @@ void CardDAV2::SetupDefaultParametersNonSSL(bool DoAuthentication){ 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()); @@ -1011,6 +1174,8 @@ void CardDAV2::SetupDefaultParametersSSL(bool DoAuthentication){ 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());