00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 #ifndef __SSDP_H__
00012 #define __SSDP_H__
00013
00014 #include <qthread.h>
00015 #include <qsocketdevice.h>
00016 #include <qfile.h>
00017
00018 #include "httpserver.h"
00019 #include "taskqueue.h"
00020
00021 #include "ssdpcache.h"
00022 #include "upnptasknotify.h"
00023
00024 #define SSDP_GROUP "239.255.255.250"
00025 #define SSDP_PORT 1900
00026 #define SSDP_SEARCHPORT 6549
00027
00028 typedef enum
00029 {
00030 SSDPM_Unknown = 0,
00031 SSDPM_GetDeviceDesc = 1,
00032 SSDPM_GetDeviceList = 2
00033
00034 } SSDPMethod;
00035
00036 typedef enum
00037 {
00038 SSDP_Unknown = 0,
00039 SSDP_MSearch = 1,
00040 SSDP_MSearchResp = 2,
00041 SSDP_Notify = 3
00042
00043 } SSDPRequestType;
00044
00047
00048
00049
00052
00053 #define SocketIdx_Search 0
00054 #define SocketIdx_Multicast 1
00055 #define SocketIdx_Broadcast 2
00056
00057 #define NumberOfSockets (sizeof( m_Sockets ) / sizeof( QSocketDevice * ))
00058
00059 class SSDP : public QThread
00060 {
00061 private:
00062
00063 QSocketDevice *m_Sockets[3];
00064
00065 int m_nPort;
00066 int m_nSearchPort;
00067 int m_nServicePort;
00068
00069 UPnpNotifyTask *m_pNotifyTask;
00070
00071 bool m_bTermRequested;
00072 QMutex m_lock;
00073
00074 protected:
00075
00076 bool ProcessSearchRequest ( const QStringMap &sHeaders,
00077 QHostAddress peerAddress,
00078 Q_UINT16 peerPort );
00079 bool ProcessSearchResponse( const QStringMap &sHeaders );
00080 bool ProcessNotify ( const QStringMap &sHeaders );
00081
00082 bool IsTermRequested ();
00083
00084 QString GetHeaderValue ( const QStringMap &headers,
00085 const QString &sKey,
00086 const QString &sDefault );
00087
00088 void ProcessData ( QSocketDevice *pSocket );
00089
00090 SSDPRequestType ProcessRequestLine( const QString &sLine );
00091
00092 public:
00093
00094 SSDP ( int nServicePort );
00095 ~SSDP ();
00096
00097 virtual void run ();
00098
00099 void RequestTerminate(void);
00100
00101 void EnableNotifications ();
00102 void DisableNotifications();
00103
00104 void PerformSearch( const QString &sST );
00105
00106 };
00107
00110
00111
00112
00115
00116 class SSDPExtension : public HttpServerExtension
00117 {
00118 private:
00119
00120 QString m_sUPnpDescPath;
00121 int m_nServicePort;
00122
00123 private:
00124
00125 SSDPMethod GetMethod( const QString &sURI );
00126
00127 void GetDeviceDesc( HTTPRequest *pRequest );
00128 void GetFile ( HTTPRequest *pRequest, QString sFileName );
00129 void GetDeviceList( HTTPRequest *pRequest );
00130
00131 public:
00132 SSDPExtension( int nServicePort );
00133 virtual ~SSDPExtension( );
00134
00135 bool ProcessRequest( HttpWorkerThread *pThread, HTTPRequest *pRequest );
00136 };
00137
00138 #endif