Fix deprecation warning, to fix Werror build
[quassel.git] / src / client / client.cpp
1 /***************************************************************************
2  *   Copyright (C) 2005-2019 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
19  ***************************************************************************/
20
21 #include "client.h"
22
23 #include <cstdio>
24 #include <cstdlib>
25
26 #include "abstractmessageprocessor.h"
27 #include "abstractui.h"
28 #include "bufferinfo.h"
29 #include "buffermodel.h"
30 #include "buffersettings.h"
31 #include "buffersyncer.h"
32 #include "bufferviewconfig.h"
33 #include "bufferviewoverlay.h"
34 #include "clientaliasmanager.h"
35 #include "clientauthhandler.h"
36 #include "clientbacklogmanager.h"
37 #include "clientbufferviewmanager.h"
38 #include "clientidentity.h"
39 #include "clientignorelistmanager.h"
40 #include "clientirclisthelper.h"
41 #include "clienttransfermanager.h"
42 #include "clientuserinputhandler.h"
43 #include "coreaccountmodel.h"
44 #include "coreconnection.h"
45 #include "dccconfig.h"
46 #include "ircchannel.h"
47 #include "ircuser.h"
48 #include "message.h"
49 #include "messagemodel.h"
50 #include "network.h"
51 #include "networkconfig.h"
52 #include "networkmodel.h"
53 #include "quassel.h"
54 #include "signalproxy.h"
55 #include "transfermodel.h"
56 #include "util.h"
57
58 Client::Client(std::unique_ptr<AbstractUi> ui, QObject* parent)
59     : QObject(parent)
60     , Singleton<Client>(this)
61     , _signalProxy(new SignalProxy(SignalProxy::Client, this))
62     , _mainUi(std::move(ui))
63     , _networkModel(new NetworkModel(this))
64     , _bufferModel(new BufferModel(_networkModel))
65     , _backlogManager(new ClientBacklogManager(this))
66     , _bufferViewOverlay(new BufferViewOverlay(this))
67     , _coreInfo(new CoreInfo(this))
68     , _ircListHelper(new ClientIrcListHelper(this))
69     , _inputHandler(new ClientUserInputHandler(this))
70     , _transferModel(new TransferModel(this))
71     , _messageModel(_mainUi->createMessageModel(this))
72     , _messageProcessor(_mainUi->createMessageProcessor(this))
73     , _coreAccountModel(new CoreAccountModel(this))
74     , _coreConnection(new CoreConnection(this))
75 {
76 #ifdef EMBED_DATA
77     Q_INIT_RESOURCE(data);
78 #endif
79
80     connect(mainUi(), &AbstractUi::disconnectFromCore, this, &Client::disconnectFromCore);
81     connect(this, &Client::connected, mainUi(), &AbstractUi::connectedToCore);
82     connect(this, &Client::disconnected, mainUi(), &AbstractUi::disconnectedFromCore);
83
84     connect(this, &Client::networkRemoved, _networkModel, &NetworkModel::networkRemoved);
85     connect(this, &Client::networkRemoved, _messageProcessor, &AbstractMessageProcessor::networkRemoved);
86
87     connect(backlogManager(), &ClientBacklogManager::messagesReceived, _messageModel, &MessageModel::messagesReceived);
88     connect(coreConnection(), &CoreConnection::stateChanged, this, &Client::connectionStateChanged);
89
90     SignalProxy* p = signalProxy();
91
92     p->attachSlot(SIGNAL(displayMsg(Message)), this, &Client::recvMessage);
93     p->attachSlot(SIGNAL(displayStatusMsg(QString,QString)), this, &Client::recvStatusMsg);
94
95     p->attachSlot(SIGNAL(bufferInfoUpdated(BufferInfo)), _networkModel, &NetworkModel::bufferUpdated);
96     p->attachSignal(inputHandler(), &ClientUserInputHandler::sendInput);
97     p->attachSignal(this, &Client::requestNetworkStates);
98
99     p->attachSignal(this, &Client::requestCreateIdentity, SIGNAL(createIdentity(Identity,QVariantMap)));
100     p->attachSignal(this, &Client::requestRemoveIdentity, SIGNAL(removeIdentity(IdentityId)));
101     p->attachSlot(SIGNAL(identityCreated(Identity)), this, &Client::coreIdentityCreated);
102     p->attachSlot(SIGNAL(identityRemoved(IdentityId)), this, &Client::coreIdentityRemoved);
103
104     p->attachSignal(this, &Client::requestCreateNetwork, SIGNAL(createNetwork(NetworkInfo,QStringList)));
105     p->attachSignal(this, &Client::requestRemoveNetwork, SIGNAL(removeNetwork(NetworkId)));
106     p->attachSlot(SIGNAL(networkCreated(NetworkId)), this, &Client::coreNetworkCreated);
107     p->attachSlot(SIGNAL(networkRemoved(NetworkId)), this, &Client::coreNetworkRemoved);
108
109     p->attachSignal(this, &Client::requestPasswordChange, SIGNAL(changePassword(PeerPtr,QString,QString,QString)));
110     p->attachSlot(SIGNAL(passwordChanged(PeerPtr,bool)), this, &Client::corePasswordChanged);
111
112     p->attachSignal(this, &Client::requestKickClient, SIGNAL(kickClient(int)));
113     p->attachSlot(SIGNAL(disconnectFromCore()), this, &Client::disconnectFromCore);
114
115     p->synchronize(backlogManager());
116     p->synchronize(coreInfo());
117     p->synchronize(_ircListHelper);
118
119     coreAccountModel()->load();
120     coreConnection()->init();
121 }
122
123 Client::~Client()
124 {
125     disconnectFromCore();
126 }
127
128 AbstractUi* Client::mainUi()
129 {
130     return instance()->_mainUi.get();
131 }
132
133 bool Client::isCoreFeatureEnabled(Quassel::Feature feature)
134 {
135     return coreConnection()->peer() ? coreConnection()->peer()->hasFeature(feature) : false;
136 }
137
138 bool Client::isConnected()
139 {
140     return instance()->_connected;
141 }
142
143 bool Client::internalCore()
144 {
145     return currentCoreAccount().isInternal();
146 }
147
148 void Client::onDbUpgradeInProgress(bool inProgress)
149 {
150     emit dbUpgradeInProgress(inProgress);
151 }
152
153 void Client::onExitRequested(int exitCode, const QString& reason)
154 {
155     if (!reason.isEmpty()) {
156         qCritical() << reason;
157         emit exitRequested(reason);
158     }
159     QCoreApplication::exit(exitCode);
160 }
161
162 /*** Network handling ***/
163
164 QList<NetworkId> Client::networkIds()
165 {
166     return instance()->_networks.keys();
167 }
168
169 const Network* Client::network(NetworkId networkid)
170 {
171     if (instance()->_networks.contains(networkid))
172         return instance()->_networks[networkid];
173     else
174         return nullptr;
175 }
176
177 void Client::createNetwork(const NetworkInfo& info, const QStringList& persistentChannels)
178 {
179     emit instance()->requestCreateNetwork(info, persistentChannels);
180 }
181
182 void Client::removeNetwork(NetworkId id)
183 {
184     emit instance()->requestRemoveNetwork(id);
185 }
186
187 void Client::updateNetwork(const NetworkInfo& info)
188 {
189     Network* netptr = instance()->_networks.value(info.networkId, 0);
190     if (!netptr) {
191         qWarning() << "Update for unknown network requested:" << info;
192         return;
193     }
194     netptr->requestSetNetworkInfo(info);
195 }
196
197 void Client::addNetwork(Network* net)
198 {
199     net->setProxy(signalProxy());
200     signalProxy()->synchronize(net);
201     networkModel()->attachNetwork(net);
202     connect(net, &QObject::destroyed, instance(), &Client::networkDestroyed);
203     instance()->_networks[net->networkId()] = net;
204     emit instance()->networkCreated(net->networkId());
205 }
206
207 void Client::coreNetworkCreated(NetworkId id)
208 {
209     if (_networks.contains(id)) {
210         qWarning() << "Creation of already existing network requested!";
211         return;
212     }
213     auto* net = new Network(id, this);
214     addNetwork(net);
215 }
216
217 void Client::coreNetworkRemoved(NetworkId id)
218 {
219     if (!_networks.contains(id))
220         return;
221     Network* net = _networks.take(id);
222     emit networkRemoved(net->networkId());
223     net->deleteLater();
224 }
225
226 /*** Identity handling ***/
227
228 QList<IdentityId> Client::identityIds()
229 {
230     return instance()->_identities.keys();
231 }
232
233 const Identity* Client::identity(IdentityId id)
234 {
235     if (instance()->_identities.contains(id))
236         return instance()->_identities[id];
237     else
238         return nullptr;
239 }
240
241 void Client::createIdentity(const CertIdentity& id)
242 {
243     QVariantMap additional;
244 #ifdef HAVE_SSL
245     additional["KeyPem"] = id.sslKey().toPem();
246     additional["CertPem"] = id.sslCert().toPem();
247 #endif
248     emit instance()->requestCreateIdentity(id, additional);
249 }
250
251 void Client::updateIdentity(IdentityId id, const QVariantMap& ser)
252 {
253     Identity* idptr = instance()->_identities.value(id, 0);
254     if (!idptr) {
255         qWarning() << "Update for unknown identity requested:" << id;
256         return;
257     }
258     idptr->requestUpdate(ser);
259 }
260
261 void Client::removeIdentity(IdentityId id)
262 {
263     emit instance()->requestRemoveIdentity(id);
264 }
265
266 void Client::coreIdentityCreated(const Identity& other)
267 {
268     if (!_identities.contains(other.id())) {
269         auto* identity = new Identity(other, this);
270         _identities[other.id()] = identity;
271         identity->setInitialized();
272         signalProxy()->synchronize(identity);
273         emit identityCreated(other.id());
274     }
275     else {
276         qWarning() << tr("Identity already exists in client!");
277     }
278 }
279
280 void Client::coreIdentityRemoved(IdentityId id)
281 {
282     if (_identities.contains(id)) {
283         emit identityRemoved(id);
284         Identity* i = _identities.take(id);
285         i->deleteLater();
286     }
287 }
288
289 /*** User input handling ***/
290
291 void Client::userInput(const BufferInfo& bufferInfo, const QString& message)
292 {
293     // we need to make sure that AliasManager is ready before processing input
294     if (aliasManager() && aliasManager()->isInitialized())
295         inputHandler()->handleUserInput(bufferInfo, message);
296     else
297         instance()->_userInputBuffer.append(qMakePair(bufferInfo, message));
298 }
299
300 void Client::sendBufferedUserInput()
301 {
302     for (int i = 0; i < _userInputBuffer.count(); i++)
303         userInput(_userInputBuffer.at(i).first, _userInputBuffer.at(i).second);
304
305     _userInputBuffer.clear();
306 }
307
308 /*** core connection stuff ***/
309
310 void Client::connectionStateChanged(CoreConnection::ConnectionState state)
311 {
312     switch (state) {
313     case CoreConnection::Disconnected:
314         setDisconnectedFromCore();
315         break;
316     case CoreConnection::Synchronized:
317         setSyncedToCore();
318         break;
319     default:
320         break;
321     }
322 }
323
324 void Client::setSyncedToCore()
325 {
326     // create buffersyncer
327     Q_ASSERT(!_bufferSyncer);
328     _bufferSyncer = new BufferSyncer(this);
329     connect(bufferSyncer(), &BufferSyncer::lastSeenMsgSet, _networkModel, &NetworkModel::setLastSeenMsgId);
330     connect(bufferSyncer(), &BufferSyncer::markerLineSet, _networkModel, &NetworkModel::setMarkerLineMsgId);
331     connect(bufferSyncer(), &BufferSyncer::bufferRemoved, this, &Client::bufferRemoved);
332     connect(bufferSyncer(), &BufferSyncer::bufferRenamed, this, &Client::bufferRenamed);
333     connect(bufferSyncer(), &BufferSyncer::buffersPermanentlyMerged, this, &Client::buffersPermanentlyMerged);
334     connect(bufferSyncer(), &BufferSyncer::buffersPermanentlyMerged, _messageModel, &MessageModel::buffersPermanentlyMerged);
335     connect(bufferSyncer(), &BufferSyncer::bufferMarkedAsRead, this, &Client::bufferMarkedAsRead);
336     connect(bufferSyncer(), &BufferSyncer::bufferActivityChanged, _networkModel, &NetworkModel::bufferActivityChanged);
337     connect(bufferSyncer(), &BufferSyncer::highlightCountChanged, _networkModel, &NetworkModel::highlightCountChanged);
338     connect(networkModel(), &NetworkModel::requestSetLastSeenMsg, bufferSyncer(), &BufferSyncer::requestSetLastSeenMsg);
339
340     SignalProxy* p = signalProxy();
341     p->synchronize(bufferSyncer());
342
343     // create a new BufferViewManager
344     Q_ASSERT(!_bufferViewManager);
345     _bufferViewManager = new ClientBufferViewManager(p, this);
346     connect(_bufferViewManager, &SyncableObject::initDone, _bufferViewOverlay, &BufferViewOverlay::restore);
347
348     // create AliasManager
349     Q_ASSERT(!_aliasManager);
350     _aliasManager = new ClientAliasManager(this);
351     connect(aliasManager(), &SyncableObject::initDone, this, &Client::sendBufferedUserInput);
352     p->synchronize(aliasManager());
353
354     // create NetworkConfig
355     Q_ASSERT(!_networkConfig);
356     _networkConfig = new NetworkConfig("GlobalNetworkConfig", this);
357     p->synchronize(networkConfig());
358
359     // create IgnoreListManager
360     Q_ASSERT(!_ignoreListManager);
361     _ignoreListManager = new ClientIgnoreListManager(this);
362     p->synchronize(ignoreListManager());
363
364     // create Core-Side HighlightRuleManager
365     Q_ASSERT(!_highlightRuleManager);
366     _highlightRuleManager = new HighlightRuleManager(this);
367     p->synchronize(highlightRuleManager());
368     // Listen to network removed events
369     connect(this, &Client::networkRemoved, _highlightRuleManager, &HighlightRuleManager::networkRemoved);
370
371     /*  not ready yet
372         // create TransferManager and DccConfig if core supports them
373         Q_ASSERT(!_dccConfig);
374         Q_ASSERT(!_transferManager);
375         if (isCoreFeatureEnabled(Quassel::Feature::DccFileTransfer)) {
376             _dccConfig = new DccConfig(this);
377             p->synchronize(dccConfig());
378             _transferManager = new ClientTransferManager(this);
379             _transferModel->setManager(_transferManager);
380             p->synchronize(transferManager());
381         }
382     */
383
384     // trigger backlog request once all active bufferviews are initialized
385     connect(bufferViewOverlay(), &BufferViewOverlay::initDone, this, &Client::finishConnectionInitialization);
386
387     _connected = true;
388     emit connected();
389     emit coreConnectionStateChanged(true);
390 }
391
392 void Client::finishConnectionInitialization()
393 {
394     // usually it _should_ take longer until the bufferViews are initialized, so that's what
395     // triggers this slot. But we have to make sure that we know all buffers yet.
396     // so we check the BufferSyncer and in case it wasn't initialized we wait for that instead
397     if (!bufferSyncer()->isInitialized()) {
398         disconnect(bufferViewOverlay(), &BufferViewOverlay::initDone, this, &Client::finishConnectionInitialization);
399         connect(bufferSyncer(), &SyncableObject::initDone, this, &Client::finishConnectionInitialization);
400         return;
401     }
402     disconnect(bufferViewOverlay(), &BufferViewOverlay::initDone, this, &Client::finishConnectionInitialization);
403     disconnect(bufferSyncer(), &SyncableObject::initDone, this, &Client::finishConnectionInitialization);
404
405     requestInitialBacklog();
406     if (isCoreFeatureEnabled(Quassel::Feature::BufferActivitySync)) {
407         bufferSyncer()->markActivitiesChanged();
408         bufferSyncer()->markHighlightCountsChanged();
409     }
410 }
411
412 void Client::requestInitialBacklog()
413 {
414     _backlogManager->requestInitialBacklog();
415 }
416
417 void Client::requestLegacyCoreInfo()
418 {
419     // On older cores, the CoreInfo object was only synchronized on demand.  Synchronize now if
420     // needed.
421     if (isConnected() && !isCoreFeatureEnabled(Quassel::Feature::SyncedCoreInfo)) {
422         // Delete the existing core info object (it will always exist as client is single-threaded)
423         _coreInfo->deleteLater();
424         // No need to set to null when creating new one immediately after
425
426         // Create a fresh, unsynchronized CoreInfo object, emulating legacy behavior of CoreInfo not
427         // persisting
428         _coreInfo = new CoreInfo(this);
429         // Synchronize the new object
430         signalProxy()->synchronize(_coreInfo);
431
432         // Let others know signal handlers have been reset
433         emit coreInfoResynchronized();
434     }
435 }
436
437 void Client::disconnectFromCore()
438 {
439     if (!coreConnection()->isConnected())
440         return;
441
442     coreConnection()->disconnectFromCore();
443 }
444
445 void Client::setDisconnectedFromCore()
446 {
447     _connected = false;
448
449     emit disconnected();
450     emit coreConnectionStateChanged(false);
451
452     backlogManager()->reset();
453     messageProcessor()->reset();
454
455     // Clear internal data. Hopefully nothing relies on it at this point.
456
457     if (_bufferSyncer) {
458         _bufferSyncer->deleteLater();
459         _bufferSyncer = nullptr;
460     }
461
462     _coreInfo->reset();
463
464     if (_bufferViewManager) {
465         _bufferViewManager->deleteLater();
466         _bufferViewManager = nullptr;
467     }
468
469     _bufferViewOverlay->reset();
470
471     if (_aliasManager) {
472         _aliasManager->deleteLater();
473         _aliasManager = nullptr;
474     }
475
476     if (_ignoreListManager) {
477         _ignoreListManager->deleteLater();
478         _ignoreListManager = nullptr;
479     }
480
481     if (_highlightRuleManager) {
482         _highlightRuleManager->deleteLater();
483         _highlightRuleManager = nullptr;
484     }
485
486     if (_transferManager) {
487         _transferModel->setManager(nullptr);
488         _transferManager->deleteLater();
489         _transferManager = nullptr;
490     }
491
492     if (_dccConfig) {
493         _dccConfig->deleteLater();
494         _dccConfig = nullptr;
495     }
496
497     // we probably don't want to save pending input for reconnect
498     _userInputBuffer.clear();
499
500     _messageModel->clear();
501     _networkModel->clear();
502
503     QHash<NetworkId, Network*>::iterator netIter = _networks.begin();
504     while (netIter != _networks.end()) {
505         Network* net = netIter.value();
506         emit networkRemoved(net->networkId());
507         disconnect(net, &Network::destroyed, this, nullptr);
508         netIter = _networks.erase(netIter);
509         net->deleteLater();
510     }
511     Q_ASSERT(_networks.isEmpty());
512
513     QHash<IdentityId, Identity*>::iterator idIter = _identities.begin();
514     while (idIter != _identities.end()) {
515         emit identityRemoved(idIter.key());
516         Identity* id = idIter.value();
517         idIter = _identities.erase(idIter);
518         id->deleteLater();
519     }
520     Q_ASSERT(_identities.isEmpty());
521
522     if (_networkConfig) {
523         _networkConfig->deleteLater();
524         _networkConfig = nullptr;
525     }
526 }
527
528 /*** ***/
529
530 void Client::networkDestroyed()
531 {
532     auto* net = static_cast<Network*>(sender());
533     QHash<NetworkId, Network*>::iterator netIter = _networks.begin();
534     while (netIter != _networks.end()) {
535         if (*netIter == net) {
536             netIter = _networks.erase(netIter);
537             break;
538         }
539         else {
540             ++netIter;
541         }
542     }
543 }
544
545 // Hmm... we never used this...
546 void Client::recvStatusMsg(QString /*net*/, QString /*msg*/)
547 {
548     // recvMessage(net, Message::server("", QString("[STATUS] %1").arg(msg)));
549 }
550
551 void Client::recvMessage(const Message& msg)
552 {
553     Message msg_ = msg;
554     messageProcessor()->process(msg_);
555 }
556
557 void Client::setBufferLastSeenMsg(BufferId id, const MsgId& msgId)
558 {
559     if (bufferSyncer())
560         bufferSyncer()->requestSetLastSeenMsg(id, msgId);
561 }
562
563 void Client::setMarkerLine(BufferId id, const MsgId& msgId)
564 {
565     if (bufferSyncer())
566         bufferSyncer()->requestSetMarkerLine(id, msgId);
567 }
568
569 MsgId Client::markerLine(BufferId id)
570 {
571     if (id.isValid() && networkModel())
572         return networkModel()->markerLineMsgId(id);
573     return {};
574 }
575
576 void Client::removeBuffer(BufferId id)
577 {
578     if (!bufferSyncer())
579         return;
580     bufferSyncer()->requestRemoveBuffer(id);
581 }
582
583 void Client::renameBuffer(BufferId bufferId, const QString& newName)
584 {
585     if (!bufferSyncer())
586         return;
587     bufferSyncer()->requestRenameBuffer(bufferId, newName);
588 }
589
590 void Client::mergeBuffersPermanently(BufferId bufferId1, BufferId bufferId2)
591 {
592     if (!bufferSyncer())
593         return;
594     bufferSyncer()->requestMergeBuffersPermanently(bufferId1, bufferId2);
595 }
596
597 void Client::purgeKnownBufferIds()
598 {
599     if (!bufferSyncer())
600         return;
601     bufferSyncer()->requestPurgeBufferIds();
602 }
603
604 void Client::bufferRemoved(BufferId bufferId)
605 {
606     // select a sane buffer (status buffer)
607     /* we have to manually select a buffer because otherwise inconsitent changes
608      * to the model might occur:
609      * the result of a buffer removal triggers a change in the selection model.
610      * the newly selected buffer might be a channel that hasn't been selected yet
611      * and a new nickview would be created (which never heard of the "rowsAboutToBeRemoved").
612      * this new view (and/or) its sort filter will then only receive a "rowsRemoved" signal.
613      */
614     QModelIndex current = bufferModel()->currentIndex();
615     if (current.data(NetworkModel::BufferIdRole).value<BufferId>() == bufferId) {
616         bufferModel()->setCurrentIndex(current.sibling(0, 0));
617     }
618
619     // and remove it from the model
620     networkModel()->removeBuffer(bufferId);
621 }
622
623 void Client::bufferRenamed(BufferId bufferId, const QString& newName)
624 {
625     QModelIndex bufferIndex = networkModel()->bufferIndex(bufferId);
626     if (bufferIndex.isValid()) {
627         networkModel()->setData(bufferIndex, newName, Qt::DisplayRole);
628     }
629 }
630
631 void Client::buffersPermanentlyMerged(BufferId bufferId1, BufferId bufferId2)
632 {
633     QModelIndex idx = networkModel()->bufferIndex(bufferId1);
634     bufferModel()->setCurrentIndex(bufferModel()->mapFromSource(idx));
635     networkModel()->removeBuffer(bufferId2);
636 }
637
638 void Client::markBufferAsRead(BufferId id)
639 {
640     if (bufferSyncer() && id.isValid())
641         bufferSyncer()->requestMarkBufferAsRead(id);
642 }
643
644 void Client::refreshLegacyCoreInfo()
645 {
646     instance()->requestLegacyCoreInfo();
647 }
648
649 void Client::changePassword(const QString& oldPassword, const QString& newPassword)
650 {
651     CoreAccount account = currentCoreAccount();
652     account.setPassword(newPassword);
653     coreAccountModel()->createOrUpdateAccount(account);
654     emit instance()->requestPasswordChange(nullptr, account.user(), oldPassword, newPassword);
655 }
656
657 void Client::kickClient(int peerId)
658 {
659     emit instance()->requestKickClient(peerId);
660 }
661
662 void Client::corePasswordChanged(PeerPtr, bool success)
663 {
664     if (success)
665         coreAccountModel()->save();
666     emit passwordChanged(success);
667 }