1 /* Cydia - iPhone UIKit Front-End for Debian APT
2 * Copyright (C) 2008-2015 Jay Freeman (saurik)
5 /* GNU General Public License, Version 3 {{{ */
7 * Cydia is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation, either version 3 of the License,
10 * or (at your option) any later version.
12 * Cydia is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Cydia. If not, see <http://www.gnu.org/licenses/>.
22 #include <CyteKit/UCPlatform.h>
24 #include <CyteKit/RegEx.hpp>
25 #include <CyteKit/WebViewController.h>
26 #include <CyteKit/extern.h>
28 #include <SystemConfiguration/SystemConfiguration.h>
29 #include <UIKit/UIKit.h>
31 #include <sys/sysctl.h>
33 #include <Menes/ObjectHandle.h>
41 bool CyteIsReachable(const char *name) {
42 SCNetworkReachabilityFlags flags; {
43 SCNetworkReachabilityRef reachability(SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, name));
44 SCNetworkReachabilityGetFlags(reachability, &flags);
45 CFRelease(reachability);
48 // XXX: this elaborate mess is what Apple is using to determine this? :(
49 // XXX: do we care if the user has to intervene? maybe that's ok?
51 (flags & kSCNetworkReachabilityFlagsReachable) != 0 && (
52 (flags & kSCNetworkReachabilityFlagsConnectionRequired) == 0 || (
53 (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) != 0 ||
54 (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0
55 ) && (flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0 ||
56 (flags & kSCNetworkReachabilityFlagsIsWWAN) != 0
61 void CyteInitialize(NSString *agent) {
62 UIScreen *screen([UIScreen mainScreen]);
63 if ([screen respondsToSelector:@selector(scale)])
64 ScreenScale_ = [screen scale];
68 UIDevice *device([UIDevice currentDevice]);
69 if ([device respondsToSelector:@selector(userInterfaceIdiom)]) {
70 UIUserInterfaceIdiom idiom([device userInterfaceIdiom]);
71 if (idiom == UIUserInterfaceIdiomPad)
77 sysctlbyname("kern.osversion", NULL, &size, NULL, 0);
78 char *osversion = new char[size];
79 if (sysctlbyname("kern.osversion", osversion, &size, NULL, 0) == -1)
80 perror("sysctlbyname(\"kern.osversion\", ?)");
84 sysctlbyname("hw.machine", NULL, &size, NULL, 0);
85 char *machine = new char[size];
86 if (sysctlbyname("hw.machine", machine, &size, NULL, 0) == -1)
87 perror("sysctlbyname(\"hw.machine\", ?)");
94 if (NSDictionary *info = [NSDictionary dictionaryWithContentsOfFile:@"/Applications/MobileSafari.app/Info.plist"]) {
95 product = [info objectForKey:@"SafariProductVersion"] ?: [info objectForKey:@"CFBundleShortVersionString"];
96 safari = [info objectForKey:@"CFBundleVersion"];
99 agent = [NSString stringWithFormat:@"%@ CyF/%.2f", agent, kCFCoreFoundationVersionNumber];
102 if (RegEx match = RegEx("([0-9]+(\\.[0-9]+)+).*", safari))
103 agent = [NSString stringWithFormat:@"Safari/%@ %@", match[1], agent];
104 if (RegEx match = RegEx("([0-9]+[A-Z][0-9]+[a-z]?).*", System_))
105 agent = [NSString stringWithFormat:@"Mobile/%@ %@", match[1], agent];
107 if (RegEx match = RegEx("([0-9]+(\\.[0-9]+)+).*", product))
108 agent = [NSString stringWithFormat:@"Version/%@ %@", match[1], agent];
110 [CyteWebViewController setApplicationNameForUserAgent:agent];