1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
|
/***************************************************************************
* This file is part of KDevelop *
* Copyright 2007 Andreas Pakulat <apaku@gmx.de> *
* Copyright 2007 Dukju Ahn <dukjuahn@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "svninternaljobbase.h"
#include <QMutex>
#include <QDateTime>
#include <iostream>
#include <KLocalizedString>
extern "C" {
#include <svn_auth.h>
}
#include <vcs/vcsrevision.h>
#include <svnjobbase.h>
#include "kdevsvncpp/context.hpp"
#include "kdevsvncpp/apr.hpp"
#include "kdevsvncpp/revision.hpp"
SvnInternalJobBase::SvnInternalJobBase(SvnJobBase* parentJob)
: m_ctxt( new svn::Context() )
, m_guiSemaphore( 0 )
, m_mutex()
, m_killMutex()
, m_parentJob(parentJob)
{
m_ctxt->setListener(this);
}
SvnInternalJobBase::~SvnInternalJobBase()
{
m_ctxt->setListener(nullptr);
delete m_ctxt;
m_ctxt = nullptr;
}
void SvnInternalJobBase::defaultBegin(const ThreadWeaver::JobPointer& self, ThreadWeaver::Thread *thread)
{
emit started();
ThreadWeaver::Job::defaultBegin(self, thread);
}
void SvnInternalJobBase::defaultEnd(const ThreadWeaver::JobPointer& self, ThreadWeaver::Thread *thread)
{
ThreadWeaver::Job::defaultEnd(self, thread);
if (!self->success()) {
emit failed();
}
emit done();
// at this ppint this object cannot yet be deleted (e.g. as part of the parent job destruction,
// ThreadWeaver logic still holds and uses a reference to finish the execution logic
}
bool SvnInternalJobBase::contextGetLogin( const std::string& realm,
std::string& username, std::string& password,
bool& maySave )
{
emit needLogin( QString::fromUtf8( realm.c_str() ) );
m_guiSemaphore.acquire( 1 );
QMutexLocker l(&m_mutex);
if( m_login_username.isEmpty() || m_login_password.isEmpty() )
return false;
username = std::string(m_login_username.toUtf8().constData());
password = std::string(m_login_password.toUtf8().constData());
maySave = this->m_maySave;
return true;
}
void SvnInternalJobBase::contextNotify( const char* path, svn_wc_notify_action_t action,
svn_node_kind_t kind, const char* mimetype,
svn_wc_notify_state_t contentState,
svn_wc_notify_state_t propState, svn_revnum_t rev )
{
QString notifyString;
switch( action ){
case svn_wc_notify_add:
notifyString = i18nc( "A file was marked to be added to svn", "Added %1", QString::fromUtf8( path ) );
break;
case svn_wc_notify_delete:
notifyString = i18nc( "A file was marked for deletion from svn", "Deleted %1", QString::fromUtf8( path ) );
break;
// various update notifications
case svn_wc_notify_update_delete:
notifyString = i18nc( "A file was deleted during an svn update operation", "Deleted %1", QString::fromUtf8( path ) );
break;
case svn_wc_notify_update_add:
notifyString = i18nc( "A file was added during an svn update operation", "Added %1", QString::fromUtf8( path ) );
break;
case svn_wc_notify_update_update:
/* If this is an inoperative dir change, do no notification.
An inoperative dir change is when a directory gets closed
without any props having been changed. */
if (! ((kind == svn_node_dir)
&& ((propState == svn_wc_notify_state_inapplicable)
|| (propState == svn_wc_notify_state_unknown)
|| (propState == svn_wc_notify_state_unchanged)))) {
if (kind == svn_node_file) {
if (contentState == svn_wc_notify_state_conflicted)
notifyString = QStringLiteral("Conflict On File");
else if (contentState == svn_wc_notify_state_merged)
notifyString = QStringLiteral("File Merged");
else if (contentState == svn_wc_notify_state_changed)
notifyString = QStringLiteral("File Updated");
}
if (propState == svn_wc_notify_state_conflicted)
notifyString += QLatin1String(" Conflict On Property");
else if (propState == svn_wc_notify_state_merged)
notifyString += QLatin1String(" Properties Merged");
else if (propState == svn_wc_notify_state_changed)
notifyString += QLatin1String(" Properties Updated");
else
notifyString += QLatin1Char(' ');
if (! ((contentState == svn_wc_notify_state_unchanged
|| contentState == svn_wc_notify_state_unknown)
&& (propState == svn_wc_notify_state_unchanged
|| propState == svn_wc_notify_state_unknown)))
notifyString += QLatin1Char(' ') + QString::fromUtf8(path);
}
break;
case svn_wc_notify_update_completed:
// The last notification in an update (including updates of externals).
notifyString = i18n("Revision %1", rev );
break;
case svn_wc_notify_update_external:
notifyString = i18n("Updating externals: %1", QString::fromUtf8( path ) );
break;
case svn_wc_notify_status_completed:
break;
case svn_wc_notify_status_external:
break;
// various commit notifications
case svn_wc_notify_commit_modified:
notifyString = i18n( "Sending %1", QString::fromUtf8( path ) );
break;
case svn_wc_notify_commit_added:
if( mimetype ){
notifyString = i18n("Adding %1 using mimetype %2.", QString::fromUtf8(path), QString::fromUtf8(mimetype));
} else {
notifyString = i18n( "Adding %1.", QString::fromUtf8( path ) );
}
break;
case svn_wc_notify_commit_deleted:
notifyString = i18n( "Deleting %1.", QString::fromUtf8( path ) );
break;
case svn_wc_notify_commit_replaced:
notifyString = i18n( "Replacing %1.", QString::fromUtf8( path ) );
break;
case svn_wc_notify_commit_postfix_txdelta:
if ( sendFirstDelta ) {
sendFirstDelta = false;
notifyString=i18n("Transmitting file data ");
} else {
notifyString = QStringLiteral(".");
}
break;
case svn_wc_notify_blame_revision:
notifyString = i18n( "Blame finished for revision %1, path %2", rev, QString::fromUtf8( path ) );
break;
case svn_wc_notify_revert:
notifyString = i18n( "Reverted working copy %1", QString::fromUtf8( path ) );
break;
case svn_wc_notify_failed_revert:
notifyString = i18n( "Reverting failed on working copy %1", QString::fromUtf8( path ) );
break;
case svn_wc_notify_copy:
notifyString = i18n( "Copied %1", QString::fromUtf8( path ) );
break;
default:
break;
}
emit showNotification( QString::fromUtf8( path ), notifyString );
}
bool SvnInternalJobBase::contextCancel()
{
QMutexLocker lock( &m_killMutex );
return killed;
}
bool SvnInternalJobBase::contextGetLogMessage( std::string& msg )
{
emit needCommitMessage();
m_guiSemaphore.acquire( 1 );
QMutexLocker l( &m_mutex );
QByteArray ba = m_commitMessage.toUtf8();
msg = std::string( ba.data() );
return true;
}
void SvnInternalJobBase::initBeforeRun()
{
connect( this, &SvnInternalJobBase::needCommitMessage,
m_parentJob, &SvnJobBase::askForCommitMessage, Qt::QueuedConnection );
connect( this, &SvnInternalJobBase::needLogin,
m_parentJob, &SvnJobBase::askForLogin, Qt::QueuedConnection );
connect( this, &SvnInternalJobBase::needSslServerTrust,
m_parentJob, &SvnJobBase::askForSslServerTrust, Qt::QueuedConnection );
connect( this, &SvnInternalJobBase::showNotification,
m_parentJob, &SvnJobBase::showNotification, Qt::QueuedConnection );
connect( this, &SvnInternalJobBase::needSslClientCert,
m_parentJob, &SvnJobBase::askForSslClientCert, Qt::QueuedConnection );
connect( this, &SvnInternalJobBase::needSslClientCertPassword,
m_parentJob, &SvnJobBase::askForSslClientCertPassword, Qt::QueuedConnection );
}
svn::ContextListener::SslServerTrustAnswer SvnInternalJobBase::contextSslServerTrustPrompt(
const svn::ContextListener::SslServerTrustData& data,
apr_uint32_t& acceptedFailures )
{
std::string host = data.hostname;
std::string print = data.fingerprint;
std::string from = data.validFrom;
std::string until = data.validUntil;
std::string issue = data.issuerDName;
std::string realm = data.realm;
acceptedFailures = data.failures;
QStringList failures;
if( data.failures & SVN_AUTH_SSL_NOTYETVALID )
{
failures << i18n("Certificate is not yet valid.");
}
if( data.failures & SVN_AUTH_SSL_EXPIRED )
{
failures << i18n("Certificate has expired.");
}
if( data.failures & SVN_AUTH_SSL_CNMISMATCH )
{
failures << i18n("Certificate's CN (hostname) doesn't match the remote hostname.");
}
if( data.failures & SVN_AUTH_SSL_UNKNOWNCA )
{
failures << i18n("Certificate authority is unknown.");
}
if( data.failures & SVN_AUTH_SSL_NOTYETVALID )
{
failures << i18n("Other unknown error.");
}
emit needSslServerTrust( failures,
QString::fromUtf8( host.c_str() ),
QString::fromUtf8( print.c_str() ),
QString::fromUtf8( from.c_str() ),
QString::fromUtf8( until.c_str() ),
QString::fromUtf8( issue.c_str() ),
QString::fromUtf8( realm.c_str() ) );
m_guiSemaphore.acquire(1);
QMutexLocker l(&m_mutex);
return m_trustAnswer;
}
bool SvnInternalJobBase::contextSslClientCertPrompt( std::string& cert )
{
emit needSslClientCert( QString::fromUtf8( cert.c_str() ) );
m_guiSemaphore.acquire( 1 );
return true;
}
bool SvnInternalJobBase::contextSslClientCertPwPrompt( std::string& pw, const std::string& realm,
bool& maySave )
{
Q_UNUSED(pw);
Q_UNUSED(maySave);
emit needSslClientCertPassword( QString::fromUtf8( realm.c_str() ) );
m_guiSemaphore.acquire( 1 );
return false;
}
bool SvnInternalJobBase::success() const
{
return m_success;
}
svn::Revision SvnInternalJobBase::createSvnCppRevisionFromVcsRevision( const KDevelop::VcsRevision& revision )
{
svn::Revision rev;
QVariant value = revision.revisionValue();
switch( revision.revisionType() )
{
case KDevelop::VcsRevision::Special:
{
if( value.canConvert<KDevelop::VcsRevision::RevisionSpecialType>() )
{
auto specialtype =
value.value<KDevelop::VcsRevision::RevisionSpecialType>();
switch( specialtype )
{
case KDevelop::VcsRevision::Head:
rev = svn::Revision( svn::Revision::HEAD );
break;
case KDevelop::VcsRevision::Working:
rev = svn::Revision( svn::Revision::WORKING );
break;
case KDevelop::VcsRevision::Base:
rev = svn::Revision( svn::Revision::BASE );
break;
case KDevelop::VcsRevision::Previous:
rev = svn::Revision( svn_opt_revision_previous );
break;
case KDevelop::VcsRevision::Start:
rev = svn::Revision( svn::Revision::START );
break;
default:
break;
}
}
break;
}
case KDevelop::VcsRevision::GlobalNumber:
case KDevelop::VcsRevision::FileNumber:
{
bool ok;
qlonglong number = value.toLongLong(&ok);
if( ok )
{
rev = svn::Revision( number );
}
break;
}
case KDevelop::VcsRevision::Date:
{
QDateTime dt = value.toDateTime();
if( dt.isValid() )
{
rev = svn::Revision( dt.toSecsSinceEpoch() );
}
break;
}
default:
break;
}
return rev;
}
void SvnInternalJobBase::setErrorMessage( const QString& msg )
{
QMutexLocker lock( &m_mutex );
m_errorMessage = msg;
}
QString SvnInternalJobBase::errorMessage() const
{
QMutexLocker lock( &m_mutex );
return m_errorMessage;
}
void SvnInternalJobBase::kill()
{
QMutexLocker lock( &m_killMutex );
killed = true;
}
|