File indexing completed on 2025-01-19 03:55:40

0001 #ifndef O2REPLYSERVER_H
0002 #define O2REPLYSERVER_H
0003 
0004 #include <QTcpServer>
0005 #include <QMap>
0006 #include <QByteArray>
0007 #include <QString>
0008 
0009 #include "o0export.h"
0010 
0011 /// HTTP server to process authentication response.
0012 class O0_EXPORT O2ReplyServer: public QTcpServer {
0013     Q_OBJECT
0014 
0015 public:
0016     explicit O2ReplyServer(QObject *parent = 0);
0017 
0018     /// Page content on local host after successful oauth - in case you do not want to close the browser, but display something
0019     Q_PROPERTY(QByteArray replyContent READ replyContent WRITE setReplyContent)
0020     QByteArray replyContent();
0021     void setReplyContent(const QByteArray &value);
0022 
0023     /// Seconds to keep listening *after* first response for a callback with token content
0024     Q_PROPERTY(int timeout READ timeout WRITE setTimeout)
0025     int timeout();
0026     void setTimeout(int timeout);
0027 
0028     /// Maximum number of callback tries to accept, in case some don't have token content (favicons, etc.)
0029     Q_PROPERTY(int callbackTries READ callbackTries WRITE setCallbackTries)
0030     int callbackTries();
0031     void setCallbackTries(int maxtries);
0032 
0033     QString uniqueState();
0034     void setUniqueState(const QString &state);
0035 
0036 Q_SIGNALS:
0037     void verificationReceived(QMap<QString, QString>);
0038     void serverClosed(bool); // whether it has found parameters
0039 
0040 public Q_SLOTS:
0041     void onIncomingConnection();
0042     void onBytesReady();
0043     QMap<QString, QString> parseQueryParams(QByteArray *data);
0044     void closeServer(QTcpSocket *socket = 0, bool hasparameters = false);
0045 
0046 protected:
0047     QByteArray replyContent_;
0048     int timeout_;
0049     int maxtries_;
0050     int tries_;
0051     QString uniqueState_;
0052 };
0053 
0054 #endif // O2REPLYSERVER_H