]> git.saurik.com Git - cydget.git/commitdiff
Upgraded to realistic CGI for PHP.
authorJay Freeman (saurik) <saurik@saurik.com>
Thu, 24 Dec 2009 20:18:25 +0000 (20:18 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Thu, 24 Dec 2009 20:18:25 +0000 (20:18 +0000)
LockScreen.mm
control
makefile

index 5889908f2e6ac783f8ed6ce19ded238aba1168b9..ebe1631ddf4e1de27f5eaaa844e7c05e6bf9928b 100644 (file)
@@ -986,51 +986,86 @@ MSHook(bool, _ZN7WebCore16MIMETypeRegistry29isSupportedJavaScriptMIMETypeERKNS_6
     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"])
+    NSString *path([url path]);
+    if (path == nil || ![path hasSuffix:@".php"]) {
         [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorResourceUnavailable userInfo:nil]];
+        return;
+    }
 
     NSFileManager *manager([NSFileManager defaultManager]);
-    if (![manager fileExistsAtPath:path])
+    if (![manager fileExistsAtPath:path]) {
         [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist userInfo:nil]];
+        return;
+    }
+
+    NSLog(@"%@::%@", path, [url query]);
 
     int fds[2];
     _assert(pipe(fds) != -1);
 
     pid_t pid(fork());
     if (pid == 0) {
+        setenv("GATEWAY_INTERFACE", "CGI/1.1", true);
+        setenv("SCRIPT_FILENAME", [path UTF8String], true);
+        NSString *query([url query]);
+        if (query != nil)
+            setenv("QUERY_STRING", [query UTF8String], true);
+
         _assert(dup2(fds[1], 1) != -1);
         _assert(close(fds[0]) != -1);
         _assert(close(fds[1]) != -1);
-        execl("/usr/bin/php", "php", [path UTF8String], NULL);
+
+        execl("/usr/bin/php-cgi", "php-cgi", NULL);
         exit(1);
         _assert(false);
     }
 
     _assert(close(fds[1]) != -1);
 
-    NSMutableData *data([NSMutableData dataWithCapacity:16*1024]);
+    CFHTTPMessageRef http(CFHTTPMessageCreateEmpty(kCFAllocatorDefault, FALSE));
+
+    CFHTTPMessageAppendBytes(http, (const uint8_t *) "HTTP/1.1 200 OK\r\n", 17);
 
     if (FILE *file = fdopen(fds[0], "r")) {
-        char buffer[16*1024];
+        uint8_t buffer[16*1024];
       read:
         size_t count(fread(buffer, 1, sizeof(buffer), file));
-        if (count != 0)
-            [data appendBytes:buffer length:count];
+        if (count != 0) {
+            fwrite(buffer, 1, count, stderr);
+            CFHTTPMessageAppendBytes(http, buffer, count);
+        }
         if (count == sizeof(buffer))
             goto read;
-        if (ferror(file))
+        if (ferror(file)) {
             [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorNetworkConnectionLost userInfo:nil]];
+            fclose(file);
+            goto fail;
+        }
         fclose(file);
     } else _assert(close(fds[0]));
 
-    NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:@"text/html" expectedContentLength:-1 textEncodingName:nil] autorelease]);
+    {
+        CFStringRef mime(CFHTTPMessageCopyHeaderFieldValue(http, CFSTR("Content-type")));
+        if (mime == NULL) {
+            [client URLProtocol:self didFailWithError:[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorBadServerResponse userInfo:nil]];
+            goto fail;
+        }
+
+        NSURLResponse *response([[[NSURLResponse alloc] initWithURL:[request URL] MIMEType:(NSString *)mime expectedContentLength:-1 textEncodingName:nil] autorelease]);
+        CFRelease(mime);
+
+        [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
+
+        CFDataRef data(CFHTTPMessageCopyBody(http));
+        [client URLProtocol:self didLoadData:(NSData *)data];
+        CFRelease(data);
+
+        [client URLProtocolDidFinishLoading:self];
+    }
 
-    [client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
-    [client URLProtocol:self didLoadData:data];
-    [client URLProtocolDidFinishLoading:self];
+  fail:
+    CFRelease(http);
 }
 
 - (void) stopLoading {
diff --git a/control b/control
index 51914b90c5ae933a1e1ebfe3596a48906774110b..bc539d2be2232e5c8834e1375206db4f63dd967f 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.3098M-1
+Version: 0.9.3100-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)
index 3acf1a1475e3700b47620ce033f1a06980779803..bbb7b56612c91f74d7c79a44bc7cf8d54a9cbecd 100644 (file)
--- a/makefile
+++ b/makefile
@@ -15,7 +15,7 @@ CydgetSettings: CydgetSettings.mm makefile
        ldid -S $@
 
 WebCycriptLockScreen: LockScreen.mm makefile $(base)/../mobilesubstrate/substrate.h
-       $(target)g++ -F. -bundle -mthumb -g0 -O2 -Wall -Werror -o $@ $(filter %.mm,$^) -lobjc -I$(base)/../mobilesubstrate $(link) $(flags) -framework CoreGraphics -framework QuartzCore -framework SpringBoardUI -framework WebCore -framework GraphicsServices -framework TelephonyUI -I$(jscore) -iquote$(webcore)/{bindings/js,dom,loader,platform{,/animation,/cf,/network{,/cf},/text},/rendering/style} -iquote$(jscore)/{bytecode,debugger,interpreter,jit,parser,runtime} -lapr-1 -weak_reference_mismatches weak -framework JavaScriptCore -lpcre -DNDEBUG
+       $(target)g++ -F. -bundle -mthumb -g0 -O2 -Wall -Werror -o $@ $(filter %.mm,$^) -lobjc -I$(base)/../mobilesubstrate $(link) $(flags) -framework CoreGraphics -framework QuartzCore -framework SpringBoardUI -framework WebCore -framework GraphicsServices -framework TelephonyUI -I$(jscore) -iquote$(webcore)/{bindings/js,dom,loader,platform{,/animation,/cf,/network{,/cf},/text},/rendering/style} -iquote$(jscore)/{bytecode,debugger,interpreter,jit,parser,runtime} -lapr-1 -weak_reference_mismatches weak -framework JavaScriptCore -lpcre -DNDEBUG -framework CFNetwork
        ldid -S $@
 
 extra: