00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 #ifndef __SSDP_H__
00014 #define __SSDP_H__
00015
00016 #include <QFile>
00017
00018 #include "upnpexp.h"
00019 #include "mthread.h"
00020 #include "httpserver.h"
00021 #include "taskqueue.h"
00022 #include "msocketdevice.h"
00023 #include "ssdpcache.h"
00024 #include "upnptasknotify.h"
00025
00026 #define SSDP_GROUP "239.255.255.250"
00027 #define SSDP_PORT 1900
00028 #define SSDP_SEARCHPORT 6549
00029
00030 typedef enum
00031 {
00032 SSDPM_Unknown = 0,
00033 SSDPM_GetDeviceDesc = 1,
00034 SSDPM_GetDeviceList = 2
00035
00036 } SSDPMethod;
00037
00038 typedef enum
00039 {
00040 SSDP_Unknown = 0,
00041 SSDP_MSearch = 1,
00042 SSDP_MSearchResp = 2,
00043 SSDP_Notify = 3
00044
00045 } SSDPRequestType;
00046
00049
00050
00051
00054
00055 #define SocketIdx_Search 0
00056 #define SocketIdx_Multicast 1
00057 #define SocketIdx_Broadcast 2
00058
00059 #define NumberOfSockets (sizeof( m_Sockets ) / sizeof( MSocketDevice * ))
00060
00061 class UPNP_PUBLIC SSDP : public MThread
00062 {
00063 private:
00064
00065 static SSDP* g_pSSDP;
00066
00067 QRegExp m_procReqLineExp;
00068 MSocketDevice *m_Sockets[3];
00069
00070 int m_nPort;
00071 int m_nSearchPort;
00072 int m_nServicePort;
00073
00074 UPnpNotifyTask *m_pNotifyTask;
00075 bool m_bAnnouncementsEnabled;
00076
00077 bool m_bTermRequested;
00078 QMutex m_lock;
00079
00080 private:
00081
00082
00083
00084
00085
00086 SSDP ();
00087
00088 protected:
00089
00090 bool ProcessSearchRequest ( const QStringMap &sHeaders,
00091 QHostAddress peerAddress,
00092 quint16 peerPort );
00093 bool ProcessSearchResponse( const QStringMap &sHeaders );
00094 bool ProcessNotify ( const QStringMap &sHeaders );
00095
00096 bool IsTermRequested ();
00097
00098 QString GetHeaderValue ( const QStringMap &headers,
00099 const QString &sKey,
00100 const QString &sDefault );
00101
00102 void ProcessData ( MSocketDevice *pSocket );
00103
00104 SSDPRequestType ProcessRequestLine( const QString &sLine );
00105
00106 virtual void run ();
00107
00108 public:
00109
00110 static SSDP* Instance();
00111 static void Shutdown();
00112
00113 ~SSDP();
00114
00115 void RequestTerminate(void);
00116
00117 void PerformSearch(const QString &sST, uint timeout_secs = 2);
00118
00119 void EnableNotifications ( int nServicePort );
00120 void DisableNotifications();
00121
00122
00123
00124 static void AddListener(QObject *listener)
00125 { SSDPCache::Instance()->addListener(listener); }
00126 static void RemoveListener(QObject *listener)
00127 { SSDPCache::Instance()->removeListener(listener); }
00128
00129 static SSDPCacheEntries *Find(const QString &sURI)
00130 { return SSDPCache::Instance()->Find(sURI); }
00131 static DeviceLocation *Find(const QString &sURI,
00132 const QString &sUSN)
00133 { return SSDPCache::Instance()->Find( sURI, sUSN ); }
00134 };
00135
00138
00139
00140
00143
00144 class SSDPExtension : public HttpServerExtension
00145 {
00146 private:
00147
00148 QString m_sUPnpDescPath;
00149 int m_nServicePort;
00150
00151 private:
00152
00153 SSDPMethod GetMethod( const QString &sURI );
00154
00155 void GetDeviceDesc( HTTPRequest *pRequest );
00156 void GetFile ( HTTPRequest *pRequest, QString sFileName );
00157 void GetDeviceList( HTTPRequest *pRequest );
00158
00159 public:
00160 SSDPExtension( int nServicePort, const QString sSharePath);
00161 virtual ~SSDPExtension( );
00162
00163 virtual QStringList GetBasePaths();
00164
00165 bool ProcessRequest( HTTPRequest *pRequest );
00166 };
00167
00168 #endif