]> git.saurik.com Git - cydget.git/commitdiff
Re-envisioned Cycript configuration tag as a regex on URLs.
authorJay Freeman (saurik) <saurik@saurik.com>
Mon, 9 Nov 2009 09:02:44 +0000 (09:02 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Mon, 9 Nov 2009 09:02:44 +0000 (09:02 +0000)
LockScreen.mm
Welcome.plist
control
make.sh
makefile

index 1653fe88f7354d811b0cd6cd849190439f86b89a..bfb5432869561584653d1c168fef3981ec8d0356 100644 (file)
@@ -73,6 +73,7 @@ extern NSString * const kCAFilterNearest;
 #include "SourceCode.h"
 
 #include <apr-1/apr_pools.h>
 #include "SourceCode.h"
 
 #include <apr-1/apr_pools.h>
+#include <pcre.h>
 
 @interface WebView (UICaboodle)
 - (void) setScriptDebugDelegate:(id)delegate;
 
 @interface WebView (UICaboodle)
 - (void) setScriptDebugDelegate:(id)delegate;
@@ -129,6 +130,50 @@ static Class $CydgetController(objc_getClass("CydgetController"));
 
 @end
 
 
 @end
 
+/* Perl-Compatible RegEx {{{ */
+class Pcre {
+  private:
+    pcre *code_;
+    pcre_extra *study_;
+    int capture_;
+    int *matches_;
+    const char *data_;
+
+  public:
+    Pcre(const char *regex, int options = 0) :
+        study_(NULL)
+    {
+        const char *error;
+        int offset;
+        code_ = pcre_compile(regex, options, &error, &offset, NULL);
+
+        if (code_ == NULL)
+            @throw [NSException exceptionWithName:NSInvalidArgumentException reason:[NSString stringWithFormat:@"*** Pcre(,): [%u] %s", offset, error] userInfo:nil];
+
+        pcre_fullinfo(code_, study_, PCRE_INFO_CAPTURECOUNT, &capture_);
+        matches_ = new int[(capture_ + 1) * 3];
+    }
+
+    ~Pcre() {
+        pcre_free(code_);
+        delete matches_;
+    }
+
+    NSString *operator [](size_t match) {
+        return [[[NSString alloc] initWithBytes:(data_ + matches_[match * 2]) length:(matches_[match * 2 + 1] - matches_[match * 2]) encoding:NSUTF8StringEncoding] autorelease];
+    }
+
+    bool operator ()(NSString *data) {
+        // XXX: length is for characters, not for bytes
+        return operator ()([data UTF8String], [data length]);
+    }
+
+    bool operator ()(const char *data, size_t size) {
+        data_ = data;
+        return pcre_exec(code_, study_, data, size, 0, 0, matches_, (capture_ + 1) * 3) >= 0;
+    }
+};
+/* }}} */
 /* WebCycript Delegate {{{ */
 @interface WebCycriptDelegate : NSObject {
     _transient volatile id delegate_;
 /* WebCycript Delegate {{{ */
 @interface WebCycriptDelegate : NSObject {
     _transient volatile id delegate_;
@@ -236,7 +281,7 @@ static Class $CydgetController(objc_getClass("CydgetController"));
     UIScroller *scroller_;
     UIWebDocumentView *document_;
 
     UIScroller *scroller_;
     UIWebDocumentView *document_;
 
-    bool cycript_;
+    NSString *cycript_;
     bool scrollable_;
 
     float width_;
     bool scrollable_;
 
     float width_;
@@ -487,7 +532,7 @@ static Class $CydgetController(objc_getClass("CydgetController"));
 
         NSDictionary *configuration([$CydgetController currentConfiguration]);
 
 
         NSDictionary *configuration([$CydgetController currentConfiguration]);
 
-        cycript_ = [[configuration objectForKey:@"Cycript"] boolValue];
+        cycript_ = [configuration objectForKey:@"Cycript"];
 
         scrollable_ = [[configuration objectForKey:@"Scrollable"] boolValue];
         [scroller_ setScrollingEnabled:scrollable_];
 
         scrollable_ = [[configuration objectForKey:@"Scrollable"] boolValue];
         [scroller_ setScrollingEnabled:scrollable_];
@@ -595,14 +640,16 @@ static Class $CydgetController(objc_getClass("CydgetController"));
 }
 
 - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
 }
 
 - (void) webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)window forFrame:(WebFrame *)frame {
-    if (cycript_)
-        if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL))
-            if (void (*CYSetupContext)(JSGlobalContextRef) = reinterpret_cast<void (*)(JSGlobalContextRef)>(dlsym(handle, "CydgetSetupContext"))) {
-                WebView *webview([document_ webView]);
-                WebFrame *frame([webview mainFrame]);
-                JSGlobalContextRef context([frame globalContext]);
-                CYSetupContext(context);
-            }
+    if (cycript_ != nil)
+        if (NSString *href = [[[[frame dataSource] request] URL] absoluteString])
+            if (Pcre([cycript_ UTF8String], 0 /*XXX:PCRE_UTF8*/)(href))
+                if (void *handle = dlopen("/usr/lib/libcycript.dylib", RTLD_LAZY | RTLD_GLOBAL))
+                    if (void (*CYSetupContext)(JSGlobalContextRef) = reinterpret_cast<void (*)(JSGlobalContextRef)>(dlsym(handle, "CydgetSetupContext"))) {
+                        WebView *webview([document_ webView]);
+                        WebFrame *frame([webview mainFrame]);
+                        JSGlobalContextRef context([frame globalContext]);
+                        CYSetupContext(context);
+                    }
 }
 
 - (bool) isLoading {
 }
 
 - (bool) isLoading {
index 043ab3839ca0c85026cc7a0ba2e054b295bb7010..ba23259615707ef824997c164e09d73cb69a4696 100644 (file)
@@ -3,6 +3,6 @@ Plugin = "WebCycriptLockScreen";
 
 Configuration = {
     Homepage = "file:///System/Library/LockCydgets/Welcome.cydget/Welcome.html";
 
 Configuration = {
     Homepage = "file:///System/Library/LockCydgets/Welcome.cydget/Welcome.html";
-    Cycript = "YES";
+    Cycript = "^file:///System/Library/LockCydgets/Welcome\\.cydget/Welcome\\.html$";
     Scrollable = "NO";
 };
     Scrollable = "NO";
 };
diff --git a/control b/control
index 64a5ab248901342a60885fb441f2276800b2f0d0..c037282869ddc4c2f3eb2ed07e6ae6a22b45ddb5 100644 (file)
--- a/control
+++ b/control
@@ -3,10 +3,10 @@ Priority: optional
 Section: Development
 Maintainer: Jay Freeman (saurik) <saurik@saurik.com>
 Architecture: iphoneos-arm
 Section: Development
 Maintainer: Jay Freeman (saurik) <saurik@saurik.com>
 Architecture: iphoneos-arm
-Version: 0.9.3083-1
+Version: 0.9.3084-1
 Description: framework for managing lock screen plugins
 Name: Cydget
 Description: framework for managing lock screen plugins
 Name: Cydget
-Depends: mobilesubstrate (>= 0.9.2587-1), firmware (>= 2.2), preferenceloader, apr-lib
+Depends: mobilesubstrate (>= 0.9.2587-1), firmware (>= 2.2), preferenceloader, apr-lib, pcre
 Replaces: cydialer (<< 0.9.17)
 Author: Jay Freeman (saurik) <saurik@saurik.com>
 Depiction: http://cydia.saurik.com/info/cydget/
 Replaces: cydialer (<< 0.9.17)
 Author: Jay Freeman (saurik) <saurik@saurik.com>
 Depiction: http://cydia.saurik.com/info/cydget/
diff --git a/make.sh b/make.sh
index 9ddd6573046d67cc5f4a6525fb696c130cdf8dd7..c36fb5333b3198746aadb9adee7d8b08a3fa4524 100755 (executable)
--- a/make.sh
+++ b/make.sh
@@ -1,2 +1,2 @@
 #!/bin/bash
 #!/bin/bash
-PKG_ARCH=iphoneos-arm /apl/tel/exec.sh :apr:apr-lib make package "$@"
+PKG_ARCH=iphoneos-arm /apl/tel/exec.sh :apr:apr-lib:pcre make package "$@"
index 3d33f2357537411d004cef029f22461ae9866d25..2f4df5d81eeb671419c926be67cbf7d71f585467 100644 (file)
--- a/makefile
+++ b/makefile
@@ -15,7 +15,7 @@ CydgetSettings: CydgetSettings.mm makefile
        ldid -S $@
 
 WebCycriptLockScreen: LockScreen.mm makefile $(base)/../mobilesubstrate/substrate.h
        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
+       $(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
        ldid -S $@
 
 extra:
        ldid -S $@
 
 extra: