File: qgsnetworkreplyparser.h

package info (click to toggle)
qgis 2.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 374,696 kB
  • ctags: 66,263
  • sloc: cpp: 396,139; ansic: 241,070; python: 130,609; xml: 14,884; perl: 1,290; sh: 1,287; sql: 500; yacc: 268; lex: 242; makefile: 168
file content (90 lines) | stat: -rw-r--r-- 2,864 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
/***************************************************************************
      qgsnetworkreplyparser.h - Multipart QNetworkReply parser
                             -------------------
    begin                : 4 January, 2013
    copyright            : (C) 2013 by Radim Blazek
    email                : radim dot blazek at gmail.com

 ***************************************************************************/

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

#ifndef QGSNETWORKREPLYPARSER_H
#define QGSNETWORKREPLYPARSER_H

#include <QNetworkReply>

/**
  \brief Multipart QNetworkReply parser.

  It seams that Qt does not have currently support for multipart reply
  and it is not even possible to create QNetworkReply from raw data
  so we need a class for multipart QNetworkReply parsing.

*/

class CORE_EXPORT QgsNetworkReplyParser : public QObject
{
    Q_OBJECT

  public:
    typedef QMap<QByteArray, QByteArray> RawHeaderMap;

    /** Constructor
      * @param reply */
    QgsNetworkReplyParser( QNetworkReply *reply );

    /** Indicates if successfully parsed
      * @return true if successfully parsed */
    bool isValid() const { return mValid; }

    /** Get number of parts
      * @return number of parts */
    int parts() const { return mHeaders.size(); }

    /** Get part header
      * @param part part index
      * @param headerName header name
      * @return raw header */
    QByteArray rawHeader( int part, const QByteArray & headerName ) const { return mHeaders.value( part ).value( headerName ); }

    /** Get headers */
    QList< RawHeaderMap > headers() const { return mHeaders; }

    /** Get part part body
      * @param part part index
      * @return part body */
    QByteArray body( int part ) const { return mBodies.value( part ); }

    /** Get bodies */
    QList<QByteArray> bodies() const { return mBodies; }

    /** Parsing error */
    QString error() const { return mError; }

    /** Test if reply is multipart.
      * @return true if reply is multipart */
    static bool isMultipart( QNetworkReply *reply );

  private:
    QNetworkReply *mReply;

    bool mValid;

    QString mError;

    /* List of header maps */
    QList< RawHeaderMap > mHeaders;

    /* List of part bodies */
    QList<QByteArray> mBodies;
};

#endif