00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00057
00058
00059
00060 #ifndef __MX_HTTPGETSTREAMSOURCECORE_H__
00061 #define __MX_HTTPGETSTREAMSOURCECORE_H__
00062
00063
00064
00065 #define MX_HTTPGETSTREAMSOURCECORE_HEADERBUFFER_SIZE 1024
00066
00067
00068
00069 #include <interfaces/IHTTPGetStreamSource.h>
00070
00071 #include <mxm/core/mxmIPAddress.h>
00072 #include <mxm/core/mxmStringList.h>
00073
00074 #include <QObject>
00075
00076
00077
00078 namespace mx {
00079
00081
00091 class HTTPGetStreamSourceCore : public QObject,
00092 public mxmObject,
00093 public virtual IHTTPGetStreamSource {
00094
00095 Q_OBJECT
00096
00097 private:
00098 enum HTTPNegotiationState { SendGET_NoAuth,
00099 ReceiveResponseHeader_NoAuth,
00100 RaisedAuthenticationDialog,
00101 WaitForAuthenticationDialog,
00102 SendGET_EnteredAuth,
00103 ReceiveResponseHeader_EnteredAuth,
00104 NegotiationSucceeded,
00105 NegotiationFailed
00106 };
00107
00108 protected:
00109 bool Active;
00110 mxmIPAddress Host;
00111 mxmIPAddress Proxy;
00112
00113 private:
00114 bool HostSet;
00115 mxmStringList URLList;
00116
00117 bool HTTPNegotiationMode;
00118 HTTPNegotiationState NegotiationState;
00119 char HTTPHeaderBuffer
00120 [MX_HTTPGETSTREAMSOURCECORE_HEADERBUFFER_SIZE];
00121 int HTTPHeaderBytesRead;
00122 int HTTPHeaderSize;
00123
00124 bool AuthenticationEntered,
00125 AuthenticationDialogRaised,
00126 AuthenticationDialogWasRaised;
00127 mxmString AuthenticationUser,
00128 AuthenticationPassword;
00129
00130 bool FirstAuth;
00131 int URLAttempt;
00132
00133 protected:
00134 bool Connected,
00135 Disconnected;
00136 bool Up;
00137 bool ErrorEncountered;
00138
00139 public:
00140 HTTPGetStreamSourceCore();
00141 ~HTTPGetStreamSourceCore();
00142
00143 signals:
00145 void bytesAvailable();
00148
00155 void authenticationRequest(const QString &msg,
00156 bool first_request_for_current_procedure);
00157
00158 public slots:
00162 void processAuthentication(const QString &user, const QString &password);
00166 void processAuthenticationCancellation();
00167
00168 public:
00170 void setHost(const mxmIPAddress &host);
00172 void setWebPages(const mxmStringList &web_pages);
00174 void setProxy(const mxmIPAddress &proxy);
00176 bool activate();
00177
00179 mxmQtSignal streamBytesAvailableSignal() const;
00180
00182 mxmQtSignal authenticationRequestSignal() const;
00184 mxmQtSlot processAuthenticationSlot() const;
00186 mxmQtSlot processAuthenticationCancellationSlot() const;
00187
00189 bool errorState();
00191 void setErrorState();
00192
00194 bool awaitingAuthentication();
00196 bool wasAwaitingAuthentication();
00197
00198 private slots:
00200 void processIncomingBytes();
00202 void processSocketDisconnected();
00203
00204 private:
00206 virtual void establishConnection() = 0;
00208 virtual void abortConnection() = 0;
00210
00214 virtual bool readChar(char *c) = 0;
00216 virtual void send(const mxmString &txt) = 0;
00217
00219 void sendGETRequest(const char *user = 0, const char *password = 0);
00221 bool receiveHTTPHeader();
00222
00223 };
00224 };
00225
00226
00227
00228 #endif // __MX_HTTPGETSTREAMSOURCECORE_H__
00229