Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Split carddav/carddav.cpp down into 8 files to make it manageable.
[xestiaab/.git] / source / carddav / carddav.cpp
1 #include "carddav.h"\r
2 #include "../version.h"\r
3 #include <wx/wx.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
8 #include <map>\r
9 #include <thread>\r
10 #include "../vcard/vcard.h"\r
11 #include "../common/dirs.h"\r
12 \r
13 size_t WritebackFunc(char *ptr, size_t size, size_t nmemb, wxString *stream){\r
14         \r
15         wxString Data;\r
16         Data = wxString::FromUTF8((char *)ptr);\r
17         \r
18         stream->Append(Data);\r
19         \r
20         return size * nmemb;\r
21 \r
22 }\r
23 \r
24 int ProgressFunc(void *clientdata, double TTDown, double NDown, double TTUp, double NUp){\r
25 \r
26         int ProgressRet;\r
27         \r
28         CardDAV *IncCardDAV = static_cast<CardDAV*>(clientdata);\r
29         ProgressRet = IncCardDAV->ProgressFuncProc(clientdata, TTDown, NDown, TTUp, NUp);\r
30         if (ProgressRet != 0){\r
31                 return 1;\r
32         }\r
33         return 0;\r
34 \r
35 }\r
36 \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
73 \r
74 CardDAV::CardDAV(){\r
75         ServerPort = 8080;\r
76         SSLStatus = FALSE;\r
77         SSLVerified = FALSE;\r
78         AuthPassed = FALSE;\r
79         ValidResponse = FALSE;\r
80         HasCalDAVSupport = FALSE;\r
81         SSLCertCol.SuccessCode = 0;\r
82         AllowSelfSign = FALSE;\r
83 \r
84         AbortConnection = FALSE;\r
85         UploadMode = FALSE;\r
86         EditMode = FALSE;\r
87         HTTPErrorCode = 0;\r
88 }\r
89 \r
90 CardDAV::~CardDAV(){\r
91 \r
92 }\r
93 \r
94 size_t UploadReadFunc(void *ptr, size_t size, size_t nmemb, void *userdata){\r
95 \r
96         struct UploadDataStruc *UploadPtr = (struct UploadDataStruc *)userdata;\r
97 \r
98         if (UploadPtr->sizeleft){\r
99 \r
100                 //MeepMoop->sizeleft--;\r
101                 //return 1;\r
102 \r
103                 UploadPtr->sizeleft--;\r
104                 wxString wxSChar;\r
105 \r
106                 wxSChar = UploadPtr->readptr->Mid(UploadPtr->seek,1);\r
107 \r
108                 //*(char *)ptr = (char)wxSChar.mb_str();\r
109 \r
110                 strncpy((char *)ptr, (const char*)wxSChar.mb_str(wxConvUTF8), 1);\r
111 \r
112                 UploadPtr->seek++;\r
113 \r
114                 return 1;\r
115 \r
116         }\r
117 \r
118         return 0;\r
119 \r
120 }\r
121 \r
122 bool CardDAV::SetupConnection(wxString SvrAddress, int SvrPort, wxString SvrUser, wxString SvrPass, bool SvrSSL){\r
123 \r
124         ServerAddress = SvrAddress;\r
125         ServerPort = SvrPort;\r
126         ServerUser = SvrUser;\r
127         ServerPass = SvrPass;\r
128         ServerSSL = SvrSSL;\r
129         \r
130         return TRUE;\r
131 \r
132 }\r
133 \r
134 bool CardDAV::SetupConnection(wxString SvrAddress, int SvrPort, wxString SvrUser, wxString SvrPass, bool SvrSSL, wxString SvrPrefix, wxString SvrAccount){\r
135 \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
143 \r
144         return TRUE;\r
145 \r
146 }\r
147 \r
148 bool CardDAV::SetupResultBools(bool *SvrResult, bool *SvrMonitor){\r
149 \r
150         ServerResult = SvrResult;\r
151         ServerMonitor = SvrMonitor;\r
152 \r
153         return TRUE;\r
154 \r
155 }\r
156 \r
157 bool CardDAV::HasValidResponse(){\r
158 \r
159         return ValidResponse;\r
160 \r
161 }\r
162 \r
163 bool CardDAV::CanDoCardDAV(){\r
164 \r
165         return HasCalDAVSupport;\r
166 \r
167 }\r
168 \r
169 bool CardDAV::CanDoSSL(){\r
170 \r
171         return SSLStatus;\r
172 \r
173 }\r
174 \r
175 bool CardDAV::SSLVerify(){\r
176 \r
177         return SSLVerified;\r
178 \r
179 }\r
180 \r
181 bool CardDAV::AbleToLogin(){\r
182 \r
183         return AuthPassed;\r
184 \r
185 }\r
186 \r
187 bool CardDAV::IsSelfSigned(){\r
188 \r
189         return AllowSelfSign;\r
190 \r
191 }\r
192 \r
193 /*\r
194 \r
195 size_t CardDAV::WritebackFunc(char *ptr, size_t size, size_t nmemb, FILE *stream){\r
196 \r
197         wxString Data;\r
198         Data = wxString::FromUTF8((char *)ptr);\r
199         if ((bool)stream == TRUE){\r
200                 PageHeader.Append(Data);\r
201         } else {\r
202                 PageData.Append(Data);\r
203         }\r
204         return size * nmemb;\r
205 \r
206 }\r
207 \r
208 */\r
209 \r
210 int CardDAV::ProgressFuncProc(void *clientdata, double TTUp, double NUp, double TTDown, double NDown){\r
211 \r
212         if (AbortConnection == TRUE){\r
213         \r
214                 return -1;\r
215         \r
216         } else {\r
217         \r
218                 return 0;\r
219         \r
220         }\r
221 \r
222 }\r
223 \r
224 void CardDAV::Abort(){\r
225 \r
226         AbortConnection = TRUE;\r
227 \r
228 }\r
229 \r
230 SSLCertCollection CardDAV::GetSSLVerifyResults(){\r
231         return VerifyCertCollection;\r
232 }\r
233 \r
234 void CardDAV::AllowSelfSignTest(bool AllowSelfSignIn){\r
235         AllowSelfSign = AllowSelfSignIn;\r
236 }\r
237 \r
238 void CardDAV::GetSSLResults(){\r
239 \r
240         \r
241 \r
242 }\r
243 \r
244 void CardDAV::SetServerFilename(wxString Filename){\r
245 \r
246         ServerFilenameLocation = Filename;\r
247 \r
248 }\r
249 \r
250 wxString CardDAV::GetPageData()\r
251 {\r
252 \r
253         return PageData;\r
254 \r
255 }\r
256 \r
257 wxString CardDAV::ETagValueResult(){\r
258 \r
259         return ETagResult;\r
260 \r
261 }\r
262 \r
263 void CardDAV::SetupData(wxString Method, wxString FilenameLocation, wxString UploadData){\r
264 \r
265         ServerMethod = Method;\r
266         ServerFilenameLocation = FilenameLocation;\r
267         ServerUploadData = UploadData;\r
268 \r
269         // Check if ServerFilenameLocation has a / at \r
270         // the start and if not then append it.\r
271         \r
272         if (ServerFilenameLocation.Left(1) != wxT("/")){\r
273         \r
274                 // Not there so insert.\r
275                 \r
276                 ServerFilenameLocation = wxT("/") + ServerFilenameLocation;\r
277         \r
278         }\r
279 \r
280 }\r
281 \r
282 void CardDAV::SetupVariables(std::map<int, int> *actlist, int actindex){\r
283 \r
284         ActivityListPtr = actlist;\r
285         ItemIndex = actindex;\r
286 \r
287 }\r
288 \r
289 wxString CardDAV::GetETagData(){\r
290 \r
291         return ETagData;\r
292 \r
293 }\r
294 \r
295 void CardDAV::SetUploadMode(bool IncMode){\r
296 \r
297         UploadMode = IncMode;\r
298 \r
299 }\r
300 \r
301 void CardDAV::SetEditMode(bool EditModeInc){\r
302 \r
303         EditMode = EditModeInc;\r
304 \r
305 }\r
306 \r
307 int CardDAV::GetResultCode(){\r
308 \r
309         return (int)claconncode;\r
310 \r
311 }\r
312 \r
313 int CardDAV::GetHTTPCode(){\r
314 \r
315         return HTTPErrorCode;\r
316 \r
317 }\r
318 \r
319 wxString CardDAV::GetErrorBuffer(){\r
320 \r
321         wxString ErrorBuffer = wxString::FromUTF8(curlerrbuffer);\r
322 \r
323         return ErrorBuffer;\r
324 \r
325 }\r
326 \r
327 SSLCertCollection CardDAV::BuildSSLCollection(CURL *conn){\r
328 \r
329         SSLCertCollection SSLCertInfo;\r
330 \r
331         // Grab the certificate data.\r
332 \r
333         union {\r
334                 struct curl_slist *certdata;\r
335                 struct curl_certinfo *certinfo;\r
336         } certptr;\r
337 \r
338         certptr.certdata = NULL;\r
339         \r
340         curl_easy_getinfo(conn, CURLINFO_CERTINFO, &certptr.certinfo);\r
341 \r
342         wxString CertPropName;\r
343         wxString CertPropValue;\r
344 \r
345         for (int i = 0; i < certptr.certinfo->num_of_certs; i++){\r
346 \r
347                 struct curl_slist *slist;\r
348                 SSLCertData SSLCertDataInc;\r
349                 \r
350                 for (slist = certptr.certinfo->certinfo[i]; slist; slist = slist->next){\r
351                         \r
352                         wxStringTokenizer CertDataInc(wxString::FromUTF8(slist->data), ":");\r
353                         \r
354                         // Get first token as the property name.\r
355                         \r
356                         CertPropName = CertDataInc.GetNextToken();\r
357                         \r
358                         // Get remaining tokens as the property value.\r
359                         \r
360                         while(CertDataInc.HasMoreTokens()){\r
361                         \r
362                                 CertPropValue.Append(CertDataInc.GetNextToken());\r
363                         \r
364                         }\r
365                         \r
366                         SSLCertDataInc.CertData.insert(std::make_pair(CertPropName, CertPropValue));\r
367                         CertPropName.clear();\r
368                         CertPropValue.clear();\r
369                         \r
370                 }\r
371         \r
372                 SSLCertInfo.SSLCollection.insert(std::make_pair(i, SSLCertDataInc));\r
373         \r
374         }\r
375         \r
376         return SSLCertInfo;\r
377 \r
378 }\r
379 \r
380 SSLCertCollection CardDAV::GetCertificateData(){\r
381 \r
382         // Pass on the collected certificate data.\r
383 \r
384         return SSLCertCol;\r
385 \r
386 }\r
387 \r
388 wxString CardDAV::GetErrorMessage(){\r
389 \r
390         return ErrorMessage;\r
391 \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