File: protocol_message_parser.h

package info (click to toggle)
classified-ads 0.13-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 6,772 kB
  • sloc: cpp: 34,291; tcl: 1,175; xml: 64; makefile: 40
file content (201 lines) | stat: -rw-r--r-- 8,328 bytes parent folder | download
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
/*     -*-C++-*- -*-coding: utf-8-unix;-*-
  Classified Ads is Copyright (c) Antti Järvinen 2013-2017.

  This file is part of Classified Ads.

  Classified Ads is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  Classified Ads 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
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with Classified Ads; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/



#ifndef PROTOCOL_MESSAGE_PARSER_H
#define PROTOCOL_MESSAGE_PARSER_H
#include "protocol.h"
#include <QObject>
#include <QHostAddress> // Q_IPV6ADDR
#include "node.h" // KNullIpv6Addr
#include "connection.h"
class MController ;
class MModelProtocolInterface ;
class MNodeModelProtocolInterface ;
class Connection ;
/**
 * @brief Class containing routines for parsing protocol messages.
 * Methods are mainly called from network connection instances
 * and this class will forward the parsed protocol entities
 * to datamodel
 */
class ProtocolMessageParser : public QObject {
    Q_OBJECT
public:
    ProtocolMessageParser (MController &aController,
                           MModelProtocolInterface &aModel) ;

    /**
     * the open mouth
     * @param aGoodFood is the message
     * @return false if such a fatal error that peer needs to be disconnected
     */
    bool parseMessage(const QByteArray& aGoodFood,
                      Connection& aConnection ) ;
private: // private methods for doing the actual work
    /** Peer hello message  */
    bool parseNodeGreetingV1(const QByteArray& aSingleNodeGreeting,
                             const Connection &aConnection ) ;
    /**
     * Peer number of hello messages
     * @param aGoodFood at least one node greeting
     * @param aConnection the orignating connection
     */
    bool parseMultipleNodeGreetingsV1(const QByteArray& aGoodFood,
                                      const Connection& aConnection ) ;
    /**
     * utility method: extract integer from bytearray. integer
     * will be returned in host byte order e.g.
     * @param aGoodFood is the bytearray from which to extract
     * @param aPos is the position where integer is expected to
     *        be found
     * @param aResult is the quint32 where result will be written
     *        e.g. this is the output variable
     * @return true if reading succeeded
     */
    bool uintFromPosition(const QByteArray& aGoodFood,
                          const int aPos,
                          quint32* aResult) const ;
    /**
     * utility method: extract hash from bytearray.
     * @param aGoodFood is the bytearray from which to extract
     * @param aPos is the position where integer is expected to
     *        be found
     * @param aResultHash is the hash that will have its
     *                    value set from contents of aGoodFood
     * @return true if success
     */
    bool hashFromPosition(const QByteArray& aGoodFood,
                          const int aPos,
                          Hash* aResultHash) const ;

    /**
     * Method for parsing request to send one or more objects
     * specified by a hash.
     */
    bool parseRequestForObjectsAroundHash(const QByteArray& aNodeRefRequest,
                                          const Connection &aConnection ) ;
    /**
     * Method for parsing published content. Content-type is given
     * as parameter ; single method as the structure is anyway same,
     * handling is different..
     *
     * This method is also used to parse content sent ; it differs from
     * published content so, that it has no bangpath but otherwise
     * the format is the same.
     */
    bool parseContentPublishedOrSent(const unsigned char aProtocolItemType,
                                     const QByteArray& aPublishedContent,
                                     const Connection &aConnection ) ;
    /**
     * Method for parsing published private message. Does about same
     * work as @ref parseContentPublishedOrSent but structure of
     * private messages is somewhat different.
     */
    bool parsePrivMsgPublishedOrSent(const unsigned char aProtocolItemType,
                                     const QByteArray& aPublishedContent,
                                     const Connection &aConnection ) ;

    /**
     * Method for parsing published profile comments. Does about same
     * work as @ref parseContentPublishedOrSent but structure of
     * profile commentss is somewhat different.
     */
    bool parseProfileCommentPublishedOrSent(const unsigned char aProtocolItemType,
                                            const QByteArray& aPublishedContent,
                                            const Connection &aConnection ) ;


    /**
     * method for parsing request that requests for classified
     * ads whose classification matches given hash
     * @param aQueryBytes contains the query
     * @param aConnection is the requester
     */
    bool  parseAdsClassifiedAtHash( const QByteArray& aQueryBytes,
                                    const Connection &aConnection) ;
    /**
     * Method for parsing list of headers of classified ads.
     * In practice this parses the protocol message sent with
     * id KListOfAdsClassifiedAtHash.
     */
    bool  parseListOfAdsClassifiedAtHash( const QByteArray& aQueryBytes,
                                          const Connection &aConnection) ;
    /**
     * Method for parsing a search request from remote node.
     * If parse is successful, this method will also ask searchmodel
     * to perform the search and place possible results immediately
     * into send-queue of aConnection so search works slightly differently
     * compared to rest of the network requests
     * @param aQueryBytes serialized query-description
     * @param aConnection is connection of the node who sent the request
     * @return true if things went all right.
     */
    bool  parseSearchRequest( const QByteArray& aQueryBytes,
                              Connection& aConnection) ;
    /**
     * Method for parsing a search result from remote node.
     * In this case this node made a search request and this
     * is reply (containing list of objects matching
     * the query).
     * @param aQueryBytes serialized query-description
     * @param aConnection is connection of the node who sent the request
     * @return true if things went all right.
     */
    bool  parseSearchResults( const QByteArray& aQueryBytes,
                              const Connection& aConnection) ;
    /**
     * Method for parsing voice call status data. This parses
     * call status, not call realtime (audio) data. 
     *
     * @param aQueryBytes serialized call-status data
     * @param aConnection is connection of the node who sent the request
     * @return true if things went all right.
     */
    bool  parseVoiceCall( const QByteArray& aQueryBytes,
                          const Connection& aConnection) ;

    /**
     * Method for parsing voice call data. This parses actual 
     * data stream like audio, not call control data. 
     *
     * @param aQueryBytes serialized call data
     * @param aConnection is connection of the node whose operator
     * made a statement. 
     * @return true if things went all right.
     */
    bool  parseCallRtData( const QByteArray& aQueryBytes,
                           const Connection& aConnection) ;
    /**
     * method for parsing record of distributed database
     */
    bool parseDbRecord( const QByteArray& aQueryBytes,
                        const Connection& aConnection) ;
    /**
     * method for parsing search request regarding db record
     */
    bool parseDbRecordSearchTerms( const QByteArray& aQueryBytes,
                                   Connection& aConnection) ;
private:
    MController &iController ;
    MModelProtocolInterface &iModel ;
} ;
#endif