Classified ads
binaryfilemodel.h
Go to the documentation of this file.
1 /* -*-C++-*- -*-coding: utf-8-unix;-*-
2  Classified Ads is Copyright (c) Antti Jarvinen 2013.
3 
4  This file is part of Classified Ads.
5 
6  Classified Ads is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Classified Ads is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Classified Ads. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef CLASSIFIED_BINARYFILEMODEL_H
21 #define CLASSIFIED_BINARYFILEMODEL_H
22 #include <QSqlDatabase>
23 #include "../mcontroller.h" // because enum from there is needed
24 #include "../net/connection.h"
25 #include "datamodelbase.h"
26 
27 class Hash ;
28 class BinaryFile ;
30 class Profile ;
31 
38 class BinaryFileModel : public ModelBase {
39  Q_OBJECT
40 
41 public:
42  BinaryFileModel(MController *aMController,
43  const MModelProtocolInterface &aModel) ;
45 
79  Hash publishBinaryFile(const Profile& aPublishingProfile,
80  const QString& aFileName,
81  const QString& aDescription,
82  const QString& aMimeType,
83  const QByteArray& aContents,
84  bool aIsCompressed,
85  bool aNoEncryption = false,
86  const QList<Hash>* aBinaryRecipientList = NULL ) ;
87 
100  BinaryFile* binaryFileByFingerPrint(const Hash& aFingerPrint) ;
101 
120  bool binaryFileDataByFingerPrint(const Hash& aFingerPrint,
121  const Hash& aPresumedSender,
122  QByteArray& aResultingBinaryFileData,
123  QByteArray& aResultingSignature,
124  bool* aIsBinaryFilePrivate ) ;
144  bool publishedBinaryFileReceived(const Hash& aFingerPrint,
145  const QByteArray& aContent,
146  const QByteArray& aSignature,
147  const QList<quint32>& aBangPath,
148  const QByteArray& aKeyOfPublisher,
149  const unsigned char aFlags,
150  const quint32 aTimeStamp,
151  const Hash& aFromNode ) ;
166  bool sentBinaryFileReceived(const Hash& aFingerPrint,
167  const QByteArray& aContent,
168  const QByteArray& aSignature,
169  const QByteArray& aKeyOfPublisher,
170  const unsigned char aFlags,
171  const quint32 aTimeStamp,
172  const Hash& aFromNode ) ;
173 
180  bool binaryFileDataForPublish(const Hash& aFingerPrint,
181  QByteArray& aResultingBinaryFileData,
182  QByteArray& aResultingSignature,
183  QByteArray& aPublicKeyOfPublisher,
184  bool* aIsBinaryFilePrivate,
185  bool* iIsBinaryFileCompressed ) ;
192  bool binaryFileDataForSend(const Hash& aFingerPrint,
193  QByteArray& aResultingBinaryFileData,
194  QByteArray& aResultingSignature,
195  QByteArray& aPublicKeyOfPublisher,
196  bool* aIsBinaryFilePrivate,
197  bool* aIsBinaryFileCompressed,
198  quint32* aTimeOfPublish) ;
199 
222  void fillBucket(QList<SendQueueItem>& aSendQueue,
223  const Hash& aStartOfBucket,
224  const Hash& aEndOfBucket,
225  quint32 aLastMutualConnectTime,
226  const Hash& aForNode );
227 signals:
229  const QString& aExplanation) ;
230  void contentReceived(const Hash& aHashOfContent,
231  const ProtocolItemType aTypeOfReceivdContent) ;
232 private: // methods
234 bool doFindBinaryFileForPublishOrSend(const Hash& aFingerPrint,
235  QByteArray& aResultingBinaryFileData,
236  QByteArray& aResultingSignature,
237  QByteArray& aPublicKeyOfPublisher,
238  bool* aIsBinaryFilePrivate,
239  bool* aIsBinaryFileCompressed,
240  quint32* aTimeOfPublish) ;
244 bool doHandleReceivedFile(const Hash& aFingerPrint,
245  const QByteArray& aContent,
246  const QByteArray& aSignature,
247  const QList<quint32>& aBangPath,
248  const QByteArray& aKeyOfPublisher,
249  const unsigned char aFlags,
250  const quint32 aTimeStamp,
251  const bool aWasPublish,
252  const Hash& aFromNode ) ;
253 private: // member variables:
256 } ;
257 #endif
bool binaryFileDataByFingerPrint(const Hash &aFingerPrint, const Hash &aPresumedSender, QByteArray &aResultingBinaryFileData, QByteArray &aResultingSignature, bool *aIsBinaryFilePrivate)
MController * iController
Definition: binaryfilemodel.h:254
bool sentBinaryFileReceived(const Hash &aFingerPrint, const QByteArray &aContent, const QByteArray &aSignature, const QByteArray &aKeyOfPublisher, const unsigned char aFlags, const quint32 aTimeStamp, const Hash &aFromNode)
bool doFindBinaryFileForPublishOrSend(const Hash &aFingerPrint, QByteArray &aResultingBinaryFileData, QByteArray &aResultingSignature, QByteArray &aPublicKeyOfPublisher, bool *aIsBinaryFilePrivate, bool *aIsBinaryFileCompressed, quint32 *aTimeOfPublish)
Hash is class that carries 160-bit digest.
Definition: hash.h:37
CAErrorSituation
Definition: mcontroller.h:48
void error(MController::CAErrorSituation aError, const QString &aExplanation)
ProtocolItemType
Definition: protocol.h:124
Carrier-class for binary blob.
Definition: binaryfile.h:36
bool binaryFileDataForSend(const Hash &aFingerPrint, QByteArray &aResultingBinaryFileData, QByteArray &aResultingSignature, QByteArray &aPublicKeyOfPublisher, bool *aIsBinaryFilePrivate, bool *aIsBinaryFileCompressed, quint32 *aTimeOfPublish)
Pure-virtual interface of datamodel for message parser to use.
Definition: mmodelprotocolinterface.h:44
Pure-virtual interface class for controller. This is spammed across parties needing access to applica...
Definition: mcontroller.h:39
datamodel-parts common part. this is inherited and contains common funcs
Definition: datamodelbase.h:38
void contentReceived(const Hash &aHashOfContent, const ProtocolItemType aTypeOfReceivdContent)
Hash publishBinaryFile(const Profile &aPublishingProfile, const QString &aFileName, const QString &aDescription, const QString &aMimeType, const QByteArray &aContents, bool aIsCompressed, bool aNoEncryption=false, const QList< Hash > *aBinaryRecipientList=NULL)
const MModelProtocolInterface & iModel
Definition: binaryfilemodel.h:255
bool binaryFileDataForPublish(const Hash &aFingerPrint, QByteArray &aResultingBinaryFileData, QByteArray &aResultingSignature, QByteArray &aPublicKeyOfPublisher, bool *aIsBinaryFilePrivate, bool *iIsBinaryFileCompressed)
BinaryFile * binaryFileByFingerPrint(const Hash &aFingerPrint)
bool doHandleReceivedFile(const Hash &aFingerPrint, const QByteArray &aContent, const QByteArray &aSignature, const QList< quint32 > &aBangPath, const QByteArray &aKeyOfPublisher, const unsigned char aFlags, const quint32 aTimeStamp, const bool aWasPublish, const Hash &aFromNode)
bool publishedBinaryFileReceived(const Hash &aFingerPrint, const QByteArray &aContent, const QByteArray &aSignature, const QList< quint32 > &aBangPath, const QByteArray &aKeyOfPublisher, const unsigned char aFlags, const quint32 aTimeStamp, const Hash &aFromNode)
Carrier-class for user-profile data.
Definition: profile.h:36
BinaryFileModel(MController *aMController, const MModelProtocolInterface &aModel)
void fillBucket(QList< SendQueueItem > &aSendQueue, const Hash &aStartOfBucket, const Hash &aEndOfBucket, quint32 aLastMutualConnectTime, const Hash &aForNode)
This is part of datamodel for any binary blobs.
Definition: binaryfilemodel.h:38