From c0c15a15b076daa2dda326fa3d0c99bedab353aa Mon Sep 17 00:00:00 2001 From: Sam Bingner Date: Mon, 25 Nov 2019 09:44:59 -1000 Subject: Add nitotv cookies --- methods/http.cc | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/methods/http.cc b/methods/http.cc index 16c0de611..508cf5727 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -50,6 +51,8 @@ #include #include #include +#include + extern "C" CFDictionaryRef SCDynamicStoreCopyProxies(void *); /*}}}*/ using namespace std; @@ -163,6 +166,45 @@ std::unique_ptr HttpMethod::CreateServerState(URI const &uri)/*{{{* void HttpMethod::RotateDNS() /*{{{*/ { } + +#if TARGET_OS_TV +char * createCookie() { + FILE *fp; + long lSize; + char *buffer; + const char *tp = "/var/mobile/Documents/nitoStoreToken"; + if (access(tp, R_OK)) return NULL; + fp = fopen ( tp , "rb" ); + if( !fp ) { + perror(tp); + return NULL; + } + fseek( fp , 0L , SEEK_END); + lSize = ftell( fp ); + rewind( fp ); + + /* allocate memory for entire content */ + buffer = static_cast(calloc( 1, lSize+1 )); + if( !buffer ) { + fclose(fp); + return NULL; + } + + /* copy the file into the buffer */ + if( 1!=fread( buffer , lSize, 1 , fp) ) + { + fclose(fp); + free(buffer); + return NULL; + } + /* do your work here, buffer is a string contains the whole text */ + + fclose(fp); + + return buffer; +} +#endif + /*}}}*/ BaseHttpMethod::DealWithHeadersResult HttpMethod::DealWithHeaders(FetchResult &Res, RequestState &Req)/*{{{*/ { @@ -253,6 +295,17 @@ int HttpMethod::Loop() } CFStringRef sr = CFStringCreateWithCString(kCFAllocatorDefault, urs.c_str(), se); +#if TARGET_OS_TV + bool isNito = false; + if (sr) { + CFStringRef nitoBaseURL = CFSTR("https://nito.tv/"); + size_t nitoURLLength = CFStringGetLength(nitoBaseURL); + size_t srLength = CFStringGetLength(sr); + if (srLength >= nitoURLLength && CFStringCompareWithOptions(sr, nitoBaseURL, CFRangeMake(0, nitoURLLength), kCFCompareCaseInsensitive) == kCFCompareEqualTo) { + isNito = true; + } + } +#endif CFURLRef ur = CFURLCreateWithString(kCFAllocatorDefault, sr, NULL); CFRelease(sr); CFHTTPMessageRef hm = CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("GET"), ur, kCFHTTPVersion1_1); @@ -290,6 +343,20 @@ int HttpMethod::Loop() CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("User-Agent"), CFSTR("Telesphoreo APT-HTTP/1.0.592")); +#if TARGET_OS_TV + if (isNito) { + char *cookie = createCookie(); + if (cookie) { + size_t cookie_len = strlen(cookie); + CFStringRef cookieString = CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, (unsigned char *)cookie, cookie_len, kCFStringEncodingUTF8, false, kCFAllocatorDefault); + if (cookieString) { + CFHTTPMessageSetHeaderFieldValue(hm, CFSTR("Set-Cookie"), cookieString); + CFRelease(cookieString); + } + } + } +#endif + CFReadStreamRef rs = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, hm); CFRelease(hm); -- cgit v1.2.3