trying to follow cspot...

This commit is contained in:
philippe44
2023-04-19 00:43:06 +02:00
parent dc62afd788
commit 7dbed7a67b
36 changed files with 625 additions and 424 deletions

View File

@@ -1,12 +1,12 @@
#pragma once
#include <functional>
#include <memory>
#include "CSpotContext.h"
#include "Utils.h"
#include <functional> // for function
#include <memory> // for shared_ptr
#include <string> // for string
namespace cspot {
struct Context;
class AccessKeyFetcher {
public:
AccessKeyFetcher(std::shared_ptr<cspot::Context> ctx);

View File

@@ -1,13 +1,9 @@
#pragma once
#include <memory>
#include <string>
#include "HTTPClient.h"
#include <string> // for string
#ifdef BELL_ONLY_CJSON
#include "cJSON.h"
#else
#include "nlohmann/json.hpp"
#endif
namespace cspot {

View File

@@ -1,20 +1,14 @@
#pragma once
#include <algorithm>
#include <climits>
#include <functional>
#include <memory>
#include <random>
#include <vector>
#include <cstdint> // for uint8_t
#include <memory> // for unique_ptr
#include <string> // for string
#include <vector> // for vector
#include "Crypto.h"
#include "Logger.h"
#include "NanoPBHelper.h"
#include "Utils.h"
#include "protobuf/authentication.pb.h"
#include "protobuf/keyexchange.pb.h"
#include "Crypto.h" // for Crypto
#include "protobuf/authentication.pb.h" // for ClientResponseEncrypted
#include "protobuf/keyexchange.pb.h" // for APResponseMessage, ClientHello
namespace cspot {
class AuthChallenges {

View File

@@ -1,16 +1,20 @@
#pragma once
#include <cstddef>
#include <memory>
#include "Crypto.h"
#include "WrappedSemaphore.h"
#include <cstddef> // for size_t
#include <cstdint> // for uint8_t
#include <memory> // for shared_ptr, unique_ptr
#include <string> // for string
#include <vector> // for vector
#include "Logger.h"
#include "Utils.h"
#include "CSpotContext.h"
#include "AccessKeyFetcher.h"
#include "Crypto.h" // for Crypto
#include "HTTPClient.h" // for HTTPClient
namespace bell {
class WrappedSemaphore;
} // namespace bell
namespace cspot {
class AccessKeyFetcher;
class CDNTrackStream {

View File

@@ -5,6 +5,7 @@
#include "MercurySession.h"
#include "TimeProvider.h"
#include "protobuf/metadata.pb.h"
#include "LoginBlob.h"
namespace cspot {
struct Context {

View File

@@ -1,17 +1,12 @@
#pragma once
#include <iostream>
#include <map>
#include <memory>
#ifndef BELL_ONLY_CJSON
#include <nlohmann/json.hpp>
#endif
#include <vector>
#include <cstdint> // for uint8_t, uint32_t
#include <map> // for map
#include <memory> // for unique_ptr
#include <string> // for string
#include <vector> // for vector
#include "ConstantParameters.h"
#include "Crypto.h"
#include "protobuf/authentication.pb.h"
#include "Crypto.h" // for CryptoMbedTLS, Crypto
namespace cspot {
class LoginBlob {

View File

@@ -1,22 +1,23 @@
#pragma once
#include <atomic>
#include <functional>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "BellTask.h"
#include "Logger.h"
#include "NanoPBHelper.h"
#include "Packet.h"
#include "Queue.h"
#include "Session.h"
#include "TimeProvider.h"
#include "Utils.h"
#include "protobuf/mercury.pb.h"
#include <atomic> // for atomic
#include <cstdint> // for uint8_t, uint64_t, uint32_t
#include <functional> // for function
#include <memory> // for shared_ptr
#include <mutex> // for mutex
#include <string> // for string
#include <unordered_map> // for unordered_map
#include <vector> // for vector
#include "BellTask.h" // for Task
#include "Packet.h" // for Packet
#include "Queue.h" // for Queue
#include "Session.h" // for Session
#include "protobuf/mercury.pb.h" // for Header
namespace cspot {
class TimeProvider;
class MercurySession : public bell::Task, public cspot::Session {
public:
MercurySession(std::shared_ptr<cspot::TimeProvider> timeProvider);

View File

@@ -3,19 +3,15 @@
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#include "win32shim.h"
#else
#include <netdb.h>
#include <unistd.h>
#include "sys/socket.h"
#include <netinet/in.h>
#include <unistd.h> // for size_t
#endif
#include <cstdint>
#include <functional>
#include <string>
#include <vector>
#include "Packet.h"
#include "Utils.h"
#include <cstdint> // for uint8_t
#include <functional> // for function
#include <string> // for string
#include <vector> // for vector
typedef std::function<bool()> timeoutCallback;

View File

@@ -1,18 +1,14 @@
#pragma once
#include <NanoPBHelper.h>
#include <memory>
#include <string>
#include <vector>
#include "CSpotContext.h"
#include "ConstantParameters.h"
#include "CspotAssert.h"
#include "TimeProvider.h"
#include "Utils.h"
#include <stdint.h> // for uint8_t, uint32_t
#include <memory> // for shared_ptr
#include <string> // for string
#include <vector> // for vector
#include "protobuf/spirc.pb.h"
#include "protobuf/spirc.pb.h" // for Frame, TrackRef, CapabilityType, Mess...
namespace cspot {
struct Context;
class PlaybackState {
private:

View File

@@ -1,20 +1,16 @@
#pragma once
#include <algorithm>
#include <functional>
#include <memory>
#include <vector>
#include <stdint.h> // for uint8_t
#include <memory> // for shared_ptr, unique_ptr
#include <string> // for string
#include <vector> // for vector
#include "ApResolve.h"
#include "AuthChallenges.h"
#include "ConstantParameters.h"
#include "Logger.h"
#include "LoginBlob.h"
#include "Packet.h"
#include "PlainConnection.h"
#include "ShannonConnection.h"
#include "Utils.h"
#include "protobuf/mercury.pb.h"
namespace cspot {
class AuthChallenges;
class LoginBlob;
class PlainConnection;
class ShannonConnection;
} // namespace cspot
#define LOGIN_REQUEST_COMMAND 0xAB
#define AUTH_SUCCESSFUL_COMMAND 0xAC

View File

@@ -1,8 +1,9 @@
#ifndef SHANNON_H
#define SHANNON_H
#include <cstdint>
#include <vector>
#include <cstdint> // for uint32_t, uint8_t
#include <vector> // for vector
class Shannon
{
public:

View File

@@ -1,18 +1,18 @@
#ifndef SHANNONCONNECTION_H
#define SHANNONCONNECTION_H
#include <sys/types.h>
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
#include <cstdint> // for uint8_t, uint32_t
#include <memory> // for shared_ptr, unique_ptr
#include <mutex> // for mutex
#include <vector> // for vector
#include "Packet.h"
#include "PlainConnection.h"
#include "Shannon.h"
#include <mutex>
#include "Utils.h"
#include "Logger.h"
#include "Packet.h" // for Packet
class Shannon;
namespace cspot {
class PlainConnection;
} // namespace cspot
#define MAC_SIZE 4
namespace cspot {

View File

@@ -1,16 +1,20 @@
#pragma once
#include <memory>
#include "BellTask.h"
#include <stdint.h> // for uint32_t, uint8_t
#include <functional> // for function
#include <memory> // for shared_ptr, unique_ptr
#include <string> // for string
#include <variant> // for variant
#include <vector> // for vector
#include "CDNTrackStream.h"
#include "CSpotContext.h"
#include "PlaybackState.h"
#include "TrackPlayer.h"
#include "TrackProvider.h"
#include "protobuf/spirc.pb.h"
#include "CDNTrackStream.h" // for CDNTrackStream, CDNTrackStream::Track...
#include "PlaybackState.h" // for PlaybackState
#include "protobuf/spirc.pb.h" // for MessageType
namespace cspot {
class TrackPlayer;
struct Context;
class SpircHandler {
public:
SpircHandler(std::shared_ptr<cspot::Context> ctx);

View File

@@ -1,9 +1,7 @@
#pragma once
#include <stdint.h>
#include <vector>
#include "Utils.h"
#include <stdint.h> // for uint8_t
#include <vector> // for vector
namespace cspot {
class TimeProvider {

View File

@@ -1,22 +1,31 @@
#pragma once
#include <functional>
#include <memory>
#include <mutex>
#include <atomic>
#include <BellUtils.h>
#include <WrappedSemaphore.h>
#include "CDNTrackStream.h"
#include "CSpotContext.h"
#include "TrackProvider.h"
#include "TrackReference.h"
#include <atomic> // for atomic
#include <cstdint> // for uint8_t, int64_t
#include <ctime> // for size_t, time
#include <functional> // for function
#include <memory> // for shared_ptr, unique_ptr
#include <mutex> // for mutex
#include <string_view> // for string_view
#include <vector> // for vector
#include "BellTask.h" // for Task
#include "CDNTrackStream.h" // for CDNTrackStream, CDNTrackStream::TrackInfo
namespace bell {
class WrappedSemaphore;
} // namespace bell
#ifdef BELL_VORBIS_FLOAT
#include "vorbis/vorbisfile.h"
#else
#include "ivorbisfile.h"
#include "ivorbisfile.h" // for OggVorbis_File, ov_callbacks
#endif
namespace cspot {
class TrackProvider;
struct Context;
struct TrackReference;
class TrackPlayer : bell::Task {
public:
typedef std::function<void()> TrackLoadedCallback;

View File

@@ -1,15 +1,18 @@
#pragma once
#include <memory>
#include <stdint.h> // for uint8_t
#include <memory> // for shared_ptr, unique_ptr, weak_ptr
#include <vector> // for vector
#include "AccessKeyFetcher.h"
#include "CDNTrackStream.h"
#include "CSpotContext.h"
#include "TrackReference.h"
#include "protobuf/metadata.pb.h"
#include "protobuf/spirc.pb.h"
#include "MercurySession.h" // for MercurySession
#include "TrackReference.h" // for TrackReference
#include "protobuf/metadata.pb.h" // for Episode, Restriction, Track
namespace cspot {
class AccessKeyFetcher;
class CDNTrackStream;
struct Context;
class TrackProvider {
public:
TrackProvider(std::shared_ptr<cspot::Context> ctx);
@@ -23,11 +26,13 @@ class TrackProvider {
std::unique_ptr<cspot::CDNTrackStream> cdnStream;
Track trackInfo;
Episode episodeInfo;
std::weak_ptr<CDNTrackStream> currentTrackReference;
TrackReference trackIdInfo;
void queryMetadata();
void onMetadataResponse(MercurySession::Response& res);
bool doRestrictionsApply(Restriction* restrictions, int count);
void fetchFile(const std::vector<uint8_t>& fileId,
const std::vector<uint8_t>& trackId);
bool canPlayTrack(int index);

View File

@@ -28,12 +28,11 @@ struct TrackReference {
// Episode GID is being fetched via base62 encoded URI
auto uri = std::string(ref->uri);
auto idString = uri.substr(uri.find_last_of(":") + 1, uri.size());
trackRef.gid = {0};
std::string_view alphabet(base62Alphabet);
for (int x = 0; x < uri.size(); x++) {
size_t d = alphabet.find(uri[x]);
for (int x = 0; x < idString.size(); x++) {
size_t d = alphabet.find(idString[x]);
trackRef.gid = bigNumMultiply(trackRef.gid, 62);
trackRef.gid = bigNumAdd(trackRef.gid, d);
}

View File

@@ -1,27 +1,20 @@
#ifndef UTILS_H
#define UTILS_H
#include <vector>
#include <cstdio> // for snprintf, size_t
#include <vector> // for vector
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#include "win32shim.h"
#else
#include <unistd.h>
#include "sys/socket.h"
#include <netdb.h>
#include <netinet/in.h>
#endif
#include <cstdint>
#include <cstring>
#include <memory>
#include <chrono>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <memory>
#include <string>
#include <stdexcept>
#include <cstdint> // for uint8_t, uint64_t
#include <cstring> // for memcpy
#include <memory> // for unique_ptr
#include <stdexcept> // for runtime_error
#include <string> // for string
#define HMAC_SHA1_BLOCKSIZE 64