1 /*
2  * Copyright 2013 Vitaly Valtman
3  * Copyright 2014 Canonical Ltd.
4  * Authors:
5  *      Roberto Mier
6  *      Tiago Herrmann
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 3.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef INBOUNDPKT_H
23 #define INBOUNDPKT_H
24 
25 #include <QObject>
26 #include <QLoggingCategory>
27 
28 #include <openssl/bn.h>
29 
Q_DECLARE_LOGGING_CATEGORY(TG_CORE_INBOUNDPKT)30 Q_DECLARE_LOGGING_CATEGORY(TG_CORE_INBOUNDPKT)
31 
32 class InboundPkt
33 {
34 public:
35     explicit InboundPkt(char* buffer, qint32 len);
36     virtual ~InboundPkt();
37 
38     virtual const char *buffer() const;
39     virtual qint32 length() const;
40     virtual void setInPtr(qint32 *inPtr);
41     virtual void setInEnd(qint32 *inEnd);
42     virtual qint32 *inPtr();
43     virtual qint32 *inEnd();
44     virtual void forwardInPtr(qint32 positions);
45 
46     virtual qint32 prefetchInt();
47     virtual qint32 fetchInt();
48     virtual bool fetchBool();
49     virtual qint32 *fetchInts(qint32 length);
50     virtual double fetchDouble();
51     virtual qint64 fetchLong();
52     virtual qint32 prefetchStrlen();
53     virtual char *fetchStr(qint32 length);
54     virtual QByteArray fetchBytes();
55     virtual QString fetchQString();
56     virtual qint32 fetchBignum (BIGNUM *x);
57     virtual qint32 fetchDate();
58 
59 protected:
60     char *m_buffer;
61     qint32 m_length;
62 
63     qint32 *m_inPtr;
64     qint32 *m_inEnd;
65 };
66 
67 #endif // INBOUNDPKT_H
68