3 * Many concepts and protocol specification in this code are taken from
4 * the Boxee project. http://www.boxee.tv
6 * Copyright (C) 2011-2013 Team XBMC
9 * This Program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2.1, or (at your option)
14 * This Program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with XBMC; see the file COPYING. If not, see
21 * <http://www.gnu.org/licenses/>.
29 #include <sys/socket.h>
30 #include "threads/Thread.h"
31 #include "threads/CriticalSection.h"
32 #include "utils/HttpParser.h"
33 #include "utils/StdString.h"
34 #include "interfaces/IAnnouncer.h"
38 #define AIRPLAY_SERVER_VERSION_STR "101.28"
40 class CAirPlayServer : public CThread, public ANNOUNCEMENT::IAnnouncer
44 virtual void Announce(ANNOUNCEMENT::AnnouncementFlag flag, const char *sender, const char *message, const CVariant &data);
47 static bool StartServer(int port, bool nonlocal);
48 static void StopServer(bool bWait);
49 static bool IsRunning();
50 static bool SetCredentials(bool usePassword, const CStdString& password);
51 static bool IsPlaying(){ return m_isPlaying > 0;}
52 static void backupVolume();
53 static void restoreVolume();
54 static int m_isPlaying;
60 CAirPlayServer(int port, bool nonlocal);
62 bool SetInternalCredentials(bool usePassword, const CStdString& password);
65 void AnnounceToClients(int state);
72 //Copying a CCriticalSection is not allowed, so copy everything but that
73 //when adding a member variable, make sure to copy it in CTCPClient::Copy
74 CTCPClient(const CTCPClient& client);
75 CTCPClient& operator=(const CTCPClient& client);
76 void PushBuffer(CAirPlayServer *host, const char *buffer,
77 int length, CStdString &sessionId,
78 std::map<CStdString, int> &reverseSockets);
79 void ComposeReverseEvent(CStdString& reverseHeader, CStdString& reverseBody, int state);
84 struct sockaddr_storage m_cliaddr;
86 CCriticalSection m_critSection;
88 CStdString m_sessionId;
91 int ProcessRequest( CStdString& responseHeader,
92 CStdString& response);
94 void ComposeAuthRequestAnswer(CStdString& responseHeader, CStdString& responseBody);
95 bool checkAuthorization(const CStdString& authStr, const CStdString& method, const CStdString& uri);
96 void Copy(const CTCPClient& client);
98 HttpParser* m_httpParser;
99 DllLibPlist *m_pLibPlist;//the lib
100 bool m_bAuthenticated;
102 CStdString m_authNonce;
105 CCriticalSection m_connectionLock;
106 std::vector<CTCPClient> m_connections;
107 std::map<CStdString, int> m_reverseSockets;
112 CStdString m_password;
115 static CAirPlayServer *ServerInstance;