summaryrefslogtreecommitdiff
path: root/data/_apt1.8/apt_nito.diff
diff options
context:
space:
mode:
Diffstat (limited to 'data/_apt1.8/apt_nito.diff')
-rw-r--r--data/_apt1.8/apt_nito.diff106
1 files changed, 106 insertions, 0 deletions
diff --git a/data/_apt1.8/apt_nito.diff b/data/_apt1.8/apt_nito.diff
new file mode 100644
index 000000000..eec3b1b61
--- /dev/null
+++ b/data/_apt1.8/apt_nito.diff
@@ -0,0 +1,106 @@
+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 <stddef.h>
+ #include <stdio.h>
+ #include <stdlib.h>
++#include <sys/fcntl.h>
+ #include <sys/select.h>
+ #include <sys/sysctl.h>
+ #include <sys/stat.h>
+@@ -50,6 +51,8 @@
+ #include <lockdown.h>
+ #include <CoreFoundation/CoreFoundation.h>
+ #include <CFNetwork/CFNetwork.h>
++#include <TargetConditionals.h>
++
+ extern "C" CFDictionaryRef SCDynamicStoreCopyProxies(void *);
+ /*}}}*/
+ using namespace std;
+@@ -163,6 +166,45 @@ std::unique_ptr<ServerState> 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<char*>(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);
+