2 #include "../version.h"
\r
4 #include <wx/tokenzr.h>
\r
5 #include <wx/ffile.h>
\r
6 #include <libxml/parser.h>
\r
7 #include <libxml/tree.h>
\r
10 #include "../vcard/vcard.h"
\r
11 #include "../common/dirs.h"
\r
13 size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, wxString *stream){
\r
16 Data = wxString::FromUTF8((char *)ptr);
\r
18 stream->Append(Data);
\r
20 return size * nmemb;
\r
24 int ProgressFunc(void *clientdata, double TTDown, double NDown, double TTUp, double NUp){
\r
28 CardDAV *IncCardDAV = static_cast<CardDAV*>(clientdata);
\r
29 ProgressRet = IncCardDAV->ProgressFuncProc(clientdata, TTDown, NDown, TTUp, NUp);
\r
30 if (ProgressRet != 0){
\r
37 wxString CardDAV::ServerAddress;
\r
38 int CardDAV::ServerPort;
\r
39 wxString CardDAV::ServerUser;
\r
40 wxString CardDAV::ServerPass;
\r
41 wxString CardDAV::ServerPrefix;
\r
42 wxString CardDAV::ServerAccount;
\r
43 bool CardDAV::ServerSSL;
\r
44 bool *CardDAV::ServerResult;
\r
45 bool *CardDAV::ServerMonitor;
\r
46 bool CardDAV::SSLStatus;
\r
47 bool CardDAV::SSLVerified;
\r
48 bool CardDAV::ValidResponse;
\r
49 bool CardDAV::AuthPassed;
\r
50 bool CardDAV::HasCalDAVSupport;
\r
51 bool CardDAV::AbortConnection;
\r
52 wxString CardDAV::ServerResponse;
\r
53 wxString CardDAV::ServerMethod;
\r
54 wxString CardDAV::ServerFilenameLocation;
\r
55 wxString CardDAV::ServerUploadData;
\r
56 wxString CardDAV::ETagData;
\r
57 wxString CardDAV::ETagResult;
\r
58 bool CardDAV::UploadMode;
\r
59 bool CardDAV::EditMode;
\r
60 long CardDAV::ItemIndex;
\r
61 std::map<int, int> *CardDAV::ActivityListPtr;
\r
62 char CardDAV::curlerrbuffer[CURL_ERROR_SIZE];
\r
63 SSLCertCollection CardDAV::SSLCertCol;
\r
64 int CardDAV::SSLErrorCode;
\r
65 int CardDAV::ConnectionErrorCode;
\r
66 wxString CardDAV::PageHeader;
\r
67 wxString CardDAV::PageData;
\r
68 CURLcode CardDAV::claconncode;
\r
69 int CardDAV::HTTPErrorCode;
\r
70 wxString CardDAV::ErrorMessage;
\r
71 SSLCertCollection CardDAV::VerifyCertCollection;
\r
72 bool CardDAV::AllowSelfSign;
\r
77 SSLVerified = FALSE;
\r
79 ValidResponse = FALSE;
\r
80 HasCalDAVSupport = FALSE;
\r
81 SSLCertCol.SuccessCode = 0;
\r
82 AllowSelfSign = FALSE;
\r
84 AbortConnection = FALSE;
\r
90 CardDAV::~CardDAV(){
\r
94 size_t UploadReadFunc(void *ptr, size_t size, size_t nmemb, void *userdata){
\r
96 struct UploadDataStruc *UploadPtr = (struct UploadDataStruc *)userdata;
\r
98 if (UploadPtr->sizeleft){
\r
100 //MeepMoop->sizeleft--;
\r
103 UploadPtr->sizeleft--;
\r
106 wxSChar = UploadPtr->readptr->Mid(UploadPtr->seek,1);
\r
108 //*(char *)ptr = (char)wxSChar.mb_str();
\r
110 strncpy((char *)ptr, (const char*)wxSChar.mb_str(wxConvUTF8), 1);
\r
122 bool CardDAV::SetupConnection(wxString SvrAddress, int SvrPort, wxString SvrUser, wxString SvrPass, bool SvrSSL){
\r
124 ServerAddress = SvrAddress;
\r
125 ServerPort = SvrPort;
\r
126 ServerUser = SvrUser;
\r
127 ServerPass = SvrPass;
\r
128 ServerSSL = SvrSSL;
\r
134 bool CardDAV::SetupConnection(wxString SvrAddress, int SvrPort, wxString SvrUser, wxString SvrPass, bool SvrSSL, wxString SvrPrefix, wxString SvrAccount){
\r
136 ServerAddress = SvrAddress;
\r
137 ServerPort = SvrPort;
\r
138 ServerUser = SvrUser;
\r
139 ServerPass = SvrPass;
\r
140 ServerSSL = SvrSSL;
\r
141 ServerPrefix = SvrPrefix;
\r
142 ServerAccount = SvrAccount;
\r
148 bool CardDAV::SetupResultBools(bool *SvrResult, bool *SvrMonitor){
\r
150 ServerResult = SvrResult;
\r
151 ServerMonitor = SvrMonitor;
\r
157 bool CardDAV::HasValidResponse(){
\r
159 return ValidResponse;
\r
163 bool CardDAV::CanDoCardDAV(){
\r
165 return HasCalDAVSupport;
\r
169 bool CardDAV::CanDoSSL(){
\r
175 bool CardDAV::SSLVerify(){
\r
177 return SSLVerified;
\r
181 bool CardDAV::AbleToLogin(){
\r
187 bool CardDAV::IsSelfSigned(){
\r
189 return AllowSelfSign;
\r
195 size_t CardDAV::WritebackFunc(char *ptr, size_t size, size_t nmemb, FILE *stream){
\r
198 Data = wxString::FromUTF8((char *)ptr);
\r
199 if ((bool)stream == TRUE){
\r
200 PageHeader.Append(Data);
\r
202 PageData.Append(Data);
\r
204 return size * nmemb;
\r
210 int CardDAV::ProgressFuncProc(void *clientdata, double TTUp, double NUp, double TTDown, double NDown){
\r
212 if (AbortConnection == TRUE){
\r
224 void CardDAV::Abort(){
\r
226 AbortConnection = TRUE;
\r
230 SSLCertCollection CardDAV::GetSSLVerifyResults(){
\r
231 return VerifyCertCollection;
\r
234 void CardDAV::AllowSelfSignTest(bool AllowSelfSignIn){
\r
235 AllowSelfSign = AllowSelfSignIn;
\r
238 void CardDAV::GetSSLResults(){
\r
244 void CardDAV::SetServerFilename(wxString Filename){
\r
246 ServerFilenameLocation = Filename;
\r
250 wxString CardDAV::GetPageData()
\r
257 wxString CardDAV::ETagValueResult(){
\r
263 void CardDAV::SetupData(wxString Method, wxString FilenameLocation, wxString UploadData){
\r
265 ServerMethod = Method;
\r
266 ServerFilenameLocation = FilenameLocation;
\r
267 ServerUploadData = UploadData;
\r
269 // Check if ServerFilenameLocation has a / at
\r
270 // the start and if not then append it.
\r
272 if (ServerFilenameLocation.Left(1) != wxT("/")){
\r
274 // Not there so insert.
\r
276 ServerFilenameLocation = wxT("/") + ServerFilenameLocation;
\r
282 void CardDAV::SetupVariables(std::map<int, int> *actlist, int actindex){
\r
284 ActivityListPtr = actlist;
\r
285 ItemIndex = actindex;
\r
289 wxString CardDAV::GetETagData(){
\r
295 void CardDAV::SetUploadMode(bool IncMode){
\r
297 UploadMode = IncMode;
\r
301 void CardDAV::SetEditMode(bool EditModeInc){
\r
303 EditMode = EditModeInc;
\r
307 int CardDAV::GetResultCode(){
\r
309 return (int)claconncode;
\r
313 int CardDAV::GetHTTPCode(){
\r
315 return HTTPErrorCode;
\r
319 wxString CardDAV::GetErrorBuffer(){
\r
321 wxString ErrorBuffer = wxString::FromUTF8(curlerrbuffer);
\r
323 return ErrorBuffer;
\r
327 SSLCertCollection CardDAV::BuildSSLCollection(CURL *conn){
\r
329 SSLCertCollection SSLCertInfo;
\r
331 // Grab the certificate data.
\r
334 struct curl_slist *certdata;
\r
335 struct curl_certinfo *certinfo;
\r
338 certptr.certdata = NULL;
\r
340 curl_easy_getinfo(conn, CURLINFO_CERTINFO, &certptr.certinfo);
\r
342 wxString CertPropName;
\r
343 wxString CertPropValue;
\r
345 for (int i = 0; i < certptr.certinfo->num_of_certs; i++){
\r
347 struct curl_slist *slist;
\r
348 SSLCertData SSLCertDataInc;
\r
350 for (slist = certptr.certinfo->certinfo[i]; slist; slist = slist->next){
\r
352 wxStringTokenizer CertDataInc(wxString::FromUTF8(slist->data), ":");
\r
354 // Get first token as the property name.
\r
356 CertPropName = CertDataInc.GetNextToken();
\r
358 // Get remaining tokens as the property value.
\r
360 while(CertDataInc.HasMoreTokens()){
\r
362 CertPropValue.Append(CertDataInc.GetNextToken());
\r
366 SSLCertDataInc.CertData.insert(std::make_pair(CertPropName, CertPropValue));
\r
367 CertPropName.clear();
\r
368 CertPropValue.clear();
\r
372 SSLCertInfo.SSLCollection.insert(std::make_pair(i, SSLCertDataInc));
\r
376 return SSLCertInfo;
\r
380 SSLCertCollection CardDAV::GetCertificateData(){
\r
382 // Pass on the collected certificate data.
\r
388 wxString CardDAV::GetErrorMessage(){
\r
390 return ErrorMessage;
\r