]> git.saurik.com Git - cydget.git/commitdiff
Do people really use PHP?
authorJay Freeman (saurik) <saurik@saurik.com>
Thu, 24 Dec 2009 05:05:50 +0000 (05:05 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Thu, 24 Dec 2009 05:05:50 +0000 (05:05 +0000)
LockScreen.mm
control

index 0fc9a10d1989798bc4e13d8ffc31dc0a47ab486a..5889908f2e6ac783f8ed6ce19ded238aba1168b9 100644 (file)
@@ -94,6 +94,13 @@ _disused static unsigned trace_;
     ); \
 } while (false)
 
+#define _assert(test) do \
+    if (!(test)) { \
+        fprintf(stderr, "_assert(%d:%s)@%s:%u[%s]\n", errno, #test, __FILE__, __LINE__, __FUNCTION__); \
+        exit(-1); \
+    } \
+while (false)
+
 @protocol CydgetController
 - (NSDictionary *) currentConfiguration;
 @end
@@ -951,6 +958,84 @@ MSHook(bool, _ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6
 - (void) stopLoading {
 }
 
+@end
+/* }}} */
+/* Cydget-PHP:// Protocol {{{ */
+@interface CydgetPHPURLProtocol : NSURLProtocol {
+}
+
+@end
+
+@implementation CydgetPHPURLProtocol
+
++ (BOOL) canInitWithRequest:(NSURLRequest *)request {
+    NSURL *url([request URL]);
+    if (url == nil)
+        return NO;
+    NSString *scheme([[url scheme] lowercaseString]);
+    if (scheme == nil || ![scheme isEqualToString:@"cydget-php"])
+        return NO;
+    return YES;
+}
+
++ (NSURLRequest *) canonicalRequestForRequest:(NSURLRequest *)request {
+    return request;
+}
+
+- (void) startLoading {
+    id<NSURLProtocolClient> client([self client]);
+    NSURLRequest *request([self request]);
+    NSURL *url([request URL]);
+    NSString *href([url absoluteString]);
+
+    NSString *path([href substringFromIndex:13]);
+    if (path == nil || ![path hasSuffix:@".php"])
+        [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]];
+
+    NSFileManager *manager([NSFileManager defaultManager]);
+    if (![manager fileExistsAtPath:path])
+        [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]];
+
+    int fds[2];
+    _assert(pipe(fds) != -1);
+
+    pid_t pid(fork());
+    if (pid == 0) {
+        _assert(dup2(fds[1], 1) != -1);
+        _assert(close(fds[0]) != -1);
+        _assert(close(fds[1]) != -1);
+        execl("/usr/bin/php", "php", [path UTF8String], NULL);
+        exit(1);
+        _assert(false);
+    }
+
+    _assert(close(fds[1]) != -1);
+
+    NSMutableData *data([NSMutableData dataWithCapacity:16*1024]);
+
+    if (FILE *file = fdopen(fds[0], "r")) {
+        char buffer[16*1024];
+      read:
+        size_t count(fread(buffer, 1, sizeof(buffer), file));
+        if (count != 0)
+            [data appendBytes:buffer length:count];
+        if (count == sizeof(buffer))
+            goto read;
+        if (ferror(file))
+            [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorNetworkConnectionLost userInfo:nil]];
+        fclose(file);
+    } else _assert(close(fds[0]));
+
+    NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:@"text/html" expectedContentLength:-1 textEncodingName:nil] autorelease]);
+
+    [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
+    [client URLProtocol:self didLoadData:data];
+    [client URLProtocolDidFinishLoading:self];
+}
+
+- (void) stopLoading {
+}
+
 @end
 /* }}} */
 
@@ -974,6 +1059,7 @@ static void dlset(Type_ &function, const char *name) {
     apr_initialize();
 
     [NSURLProtocol registerClass:[CydgetURLProtocol class]];
+    [NSURLProtocol registerClass:[CydgetPHPURLProtocol class]];
 
     void (*_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE)(JSC::SourceCode **, JSC::JSGlobalData *, int *, JSC::UString *);
     dlset(_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE, "_ZN3JSC6Parser5parseEPNS_12JSGlobalDataEPiPNS_7UStringE");
diff --git a/control b/control
index 8cbc2ad86e88488489853be9209c054dae454e30..51914b90c5ae933a1e1ebfe3596a48906774110b 100644 (file)
--- a/control
+++ b/control
@@ -3,7 +3,7 @@ Priority: optional
 Section: Development
 Maintainer: Jay Freeman (saurik) <saurik@saurik.com>
 Architecture: iphoneos-arm
-Version: 0.9.3093-1
+Version: 0.9.3098M-1
 Description: framework for managing lock screen plugins
 Name: Cydget
 Depends: mobilesubstrate (>= 0.9.2587-1), firmware (>= 2.2), preferenceloader, apr-lib, pcre, cycript (>= 0.9.292-1)