MCPcopy Create free account
hub / github.com/BaseXdb/basex / connectToBasex

Method connectToBasex

basex-api/src/main/qt/basexthread.cpp:116–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114}
115
116bool BaseXThread::connectToBasex(){
117 // wait for timestamp
118
119 bool leave = false;
120 QByteArray ts;
121 while (!leave) {
122 if (!socket->waitForReadyRead(Timeout)) {
123 emit socketError(socket->error(), socket->errorString());
124 return false;
125 }else{
126 ts = socket->readAll();
127 ts.chop(1); // skip NullTermintation
128 leave = true;
129 }
130 }
131
132
133 QByteArray codingArray;
134 codingArray.append(QCryptographicHash::hash(dbpasswd.toUtf8(), QCryptographicHash::Md5).toHex());
135 codingArray.append(ts);
136 codingArray = QCryptographicHash::hash(codingArray, QCryptographicHash::Md5).toHex();
137
138 QByteArray nameArray = dbuser.toUtf8();
139
140 //send name
141 char* nameChar = nameArray.data();
142 qDebug()<< socket->write(nameChar,strlen(nameChar)+1);
143
144 //send md(md(passwd) + timestamp)
145 char* codeChar = codingArray.data();
146 qDebug()<< socket->write(codeChar,strlen(codeChar)+1);
147
148 ts.clear();
149 if (!socket->waitForReadyRead(Timeout)) {
150 emit socketError(socket->error(), socket->errorString());
151 return false;
152 }else{
153 ts.append(socket->readAll());
154 if (ts.at(0)=='\0'){
155 qDebug()<<"connection ok";
156 }else{
157 emit socketError(1000, "BASEX user authentification failed.");
158 return false;
159 }
160 }
161
162 return true;
163
164}

Callers

nothing calls this directly

Calls 6

chopMethod · 0.80
appendMethod · 0.65
errorMethod · 0.45
dataMethod · 0.45
writeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected