Permalink
Browse files

Fleshed out client command structure.

  • Loading branch information...
1 parent ea2ec24 commit 6166bfbe98791e6ebce6c1bf8a314c9c72af4069 @jwinnenb committed Jun 23, 2011
Showing with 31 additions and 8 deletions.
  1. +5 −0 src/kh/client/checksum.clj
  2. +5 −0 src/kh/client/command.clj
  3. +10 −8 src/kh/client/core.clj
  4. +6 −0 src/kh/client/download.clj
  5. +5 −0 src/kh/client/upload.clj
@@ -0,0 +1,5 @@
+(ns kh.client.checksum
+ (:import commons.apache.codec.digest.DigestUtils))
+
+(defn checksum [cookie path]
+ (DigestUtils/md5hex (input-stream (file path))))
@@ -0,0 +1,5 @@
+(ns kh.client.command
+ (:use clojure.contrib.shell-out))
+
+(defn command [cookie cmd]
+ (sh cmd :return-map true))
View
@@ -1,16 +1,18 @@
(ns kh.client.core
(:use [compojure core route]
- [kh.client keyboard mouse screen]
- ring.adapter.jetty))
+ [kh.client checksum command download keyboard mouse screen upload]
+ ring.adapter.jetty
+ ring.middleware.multipart-params))
(defroutes client-core
(GET "/screen" [cookie scale] (screen-png cookie scale))
- (GET "/keyboard" [cookie cmd key] (keyboard-cmd cookie cmd key))
- (GET "/mouse" [cookie cmd x y b] (mouse-cmd cmd cookie x y b))
- (GET "/upload" [] nil)
- (GET "/download" [] nil)
- (GET "/checksum" [] nil)
- (GET "/command" [] nil))
+ (GET "/keyboard" [cookie cmd key] (keyboard cookie cmd key))
+ (GET "/mouse" [cookie cmd x y b] (mouse cmd cookie x y b))
+ (wrap-multipart-params
+ (POST "/upload" [cookie file dst name] (upload cookie file dst name)))
+ (GET "/download" [cookie file-path] (download cookie file-path))
+ (GET "/checksum" [cookie file-path] (checksum cookie file-path))
+ (GET "/command" [cookie cmd] (command cookie cmd))
(defn launch-client [client-port client-ssl-cert client-ssl-pass]
(.start
@@ -0,0 +1,6 @@
+(ns kh.client.download
+ (:use clojure.contrib.io))
+
+
+(defn download [cookie path]
+ (input-stream (file path)))
View
@@ -0,0 +1,5 @@
+(ns kh.client.upload
+ (:use clojure.contrib.duck-streams))
+
+(defn upload [file dst name]
+ (copy (:tempfile file) (file-str dst name)))

0 comments on commit 6166bfb

Please sign in to comment.