3 #include "xestiacalendar_testcommon.h"
4 #include "../common/file.h"
6 ProcessConnectionDataFileResult ProcessConnectionDataFile(string DataFilename,
7 CalDAVConnectionData *ConnData){
9 ProcessConnectionDataFileResult ProcessResult = PROCESSCONNECTIONDATAFILE_UNITTESTFAIL;
11 // Check if the file exists and return
12 // PROCESSCONNECTIONDATAFILE_MISSING if not.
14 if (!FileExists(DataFilename)){
15 return PROCESSCONNECTIONDATAFILE_MISSING;
19 string ReceivedStringData = "";
21 FileStream.open(DataFilename, ifstream::in);
23 if (FileStream.rdstate() & ifstream::failbit){
24 return PROCESSCONNECTIONDATAFILE_CANNOTOPEN;
27 if (FileStream.rdstate() & ifstream::badbit){
28 return PROCESSCONNECTIONDATAFILE_CANNOTOPEN;
33 char *BufferRead = new char[256];
35 while (!FileStream.eof()){
37 FileStream.getline(BufferRead, 256);
38 ReceivedStringData.append(BufferRead);
39 ReceivedStringData.append("\n");
46 bool SkipMode = false;
47 bool EqualFound = false;
48 bool QuoteMode = false;
49 bool ServerNameFound = false;
50 bool ServerUserFound = false;
51 bool ServerPassFound = false;
52 bool ServerSSLFound = false;
53 bool ServerPortFound = false;
54 bool ServerPrefixFound = false;
56 int StringDataSize = ReceivedStringData.size();
61 while (SeekCount < StringDataSize){
63 if (ReceivedStringData[SeekCount] == '='){
67 } else if (ReceivedStringData[SeekCount] == '\n'){
69 // Newline reached. Check for what type of
72 // Chceck that the equals sign has been found,
73 // there is a values in the property name
74 // and property value before doing anything.
76 if (EqualFound == true &&
77 PropertyName.size() > 0 &&
78 PropertyValue.size() > 0){
80 if (PropertyName == "server" && ServerNameFound == false){
82 // Setup the server hostname.
84 ConnData->Hostname = PropertyValue;
85 ServerNameFound = true;
87 } else if (PropertyName == "port" && ServerPortFound == false){
89 // Setup the server port.
92 bool PortNumValid = true;
95 PortNum = stoi(PropertyValue);
98 catch(const invalid_argument &oor){
102 // Port Number is valid so add to the
103 // CalDAVConnectionData handle.
105 if (PortNumValid == true){
106 ConnData->Port = PortNum;
107 ServerPortFound = true;
110 } else if (PropertyName == "user" && ServerUserFound == false){
112 // Setup the server user.
114 ConnData->Username = PropertyValue;
115 ServerUserFound = true;
117 } else if (PropertyName == "pass" && ServerPassFound == false){
119 // Setup the server pass.
121 ConnData->Password = PropertyValue;
122 ServerPassFound = true;
124 } else if (PropertyName == "ssl" && ServerSSLFound == false){
126 // Setup the server SSL status.
128 if (PropertyValue == "true"){
129 ConnData->UseSSL = true;
131 ConnData->UseSSL = false;
134 ServerSSLFound = true;
136 } else if (PropertyName == "prefix" && ServerPrefixFound == false){
138 // Setup the server prefix.
140 ConnData->Prefix = PropertyValue;
141 ServerPrefixFound = true;
147 // Reset the variables.
150 PropertyName.clear();
151 PropertyValue.clear();
155 // No special character so add it to the
156 // Property name or value depending on
157 // if the equal sign has been found.
159 BufferChar = ReceivedStringData[SeekCount];
161 if (EqualFound == true){
162 PropertyValue += BufferChar;
164 PropertyName += BufferChar;
175 return ProcessResult;