emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ELPA-diffs] ELPA branch, master, updated. ba3d658c98d275eb144789165146c


From: Andrew Hyatt
Subject: [ELPA-diffs] ELPA branch, master, updated. ba3d658c98d275eb144789165146cf99ce4dfd14
Date: Sun, 15 Sep 2013 23:53:30 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "ELPA".

The branch, master has been updated
       via  ba3d658c98d275eb144789165146cf99ce4dfd14 (commit)
      from  ebecf964123ab7b4e6deec85aa2f2fd58eddea29 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit ba3d658c98d275eb144789165146cf99ce4dfd14
Author: Andrew Hyatt <address@hidden>
Date:   Sun Sep 15 19:52:34 2013 -0400

    2013-09-15 Andrew Hyatt  <address@hidden>
    
            * websocket.el (websocket-mask-frames, websocket-encode-frame,
              websocket, websocket-send): Get rid of
              `websocket-mask-frames' variable, which was a mistake, and
              make masking mandatory for clients and forbidden for
              servers.
            * websocket-test.el (websocket-encode-frame,
              websocket-outer-filter): Alter tests to pass new argument
              for `websocket-encode-frame'.
    
            * websocket.el (websocket-close, websocket-open,
              websocket-server-accept): Only call the on-close callback on
              process state change if the process is now closed or
              similar, and always call the on-close callback from
              `websocket-close'
            * websocket-test.el (websocket-close): Add an on-close callback
              which the `websocket-close' method now expects.
    
            * magit-functiona-test.el: Assert on ready-state, and increase
              the sleep time for the wss test.

diff --git a/packages/websocket/websocket-functional-test.el 
b/packages/websocket/websocket-functional-test.el
index af1a4ee..6a9481f 100644
--- a/packages/websocket/websocket-functional-test.el
+++ b/packages/websocket/websocket-functional-test.el
@@ -107,9 +107,10 @@
         wstest-msgs nil)
   (sleep-for 0.3)
   (assert (websocket-openp wstest-ws))
+  (assert (eq 'open (websocket-ready-state wstest-ws)))
   (assert (null wstest-msgs))
   (websocket-send-text wstest-ws "Hi!")
-  (sleep-for 0.3)
+  (sleep-for 1)
   (assert (equal (car wstest-msgs) "Hi!"))
   (websocket-close wstest-ws))
 
diff --git a/packages/websocket/websocket-test.el 
b/packages/websocket/websocket-test.el
index 3cc51f9..5de21d3 100644
--- a/packages/websocket/websocket-test.el
+++ b/packages/websocket/websocket-test.el
@@ -282,38 +282,36 @@
 (ert-deftest websocket-encode-frame ()
   ;; We've tested websocket-read-frame, now we can use that to help
   ;; test websocket-encode-frame.
-  (let ((websocket-mask-frames nil))
-    (should (equal
+  (should (equal
              websocket-test-hello
              (websocket-encode-frame
-              (make-websocket-frame :opcode 'text :payload "Hello" :completep 
t))))
-    (dolist (len '(200 70000))
-      (let ((long-string (make-string len ?x)))
-        (should (equal long-string
-                       (websocket-frame-payload
-                        (websocket-read-frame
-                         (websocket-encode-frame
-                          (make-websocket-frame :opcode 'text
-                                                :payload long-string)))))))))
-  (let ((websocket-mask-frames t))
-    (flet ((websocket-genbytes (n) (substring websocket-test-masked-hello 2 
6)))
+              (make-websocket-frame :opcode 'text :payload "Hello" :completep 
t) nil)))
+  (dolist (len '(200 70000))
+        (let ((long-string (make-string len ?x)))
+          (should (equal long-string
+                         (websocket-frame-payload
+                          (websocket-read-frame
+                           (websocket-encode-frame
+                            (make-websocket-frame :opcode 'text
+                                                  :payload long-string) 
t)))))))
+  (flet ((websocket-genbytes (n) (substring websocket-test-masked-hello 2 6)))
       (should (equal websocket-test-masked-hello
                      (websocket-encode-frame
                       (make-websocket-frame :opcode 'text :payload "Hello"
-                                            :completep t))))))
+                                            :completep t) t))))
   (should-not
    (websocket-frame-completep
     (websocket-read-frame
      (websocket-encode-frame (make-websocket-frame :opcode 'text
                                                    :payload "Hello"
-                                                   :completep nil)))))
+                                                   :completep nil) t))))
   (dolist (opcode '(close ping pong))
     (should (equal
              opcode
              (websocket-frame-opcode
               (websocket-read-frame
                (websocket-encode-frame (make-websocket-frame :opcode opcode
-                                                             :completep 
t))))))))
+                                                             :completep t) 
t)))))))
 
 (ert-deftest websocket-close ()
   (let ((sent-frames)
@@ -326,7 +324,8 @@
       (websocket-close (websocket-inner-create
                         :conn "fake-conn"
                         :url t
-                        :accept-string t))
+                        :accept-string t
+                        :on-close 'identity))
       (should (equal sent-frames (list
                                   (make-websocket-frame :opcode 'close
                                                         :completep t))))
@@ -349,8 +348,8 @@
          (open-callback-called)
          (websocket-frames
           (concat
-           (websocket-encode-frame frame1)
-           (websocket-encode-frame frame2))))
+           (websocket-encode-frame frame1 t)
+           (websocket-encode-frame frame2 t))))
     (flet ((websocket-process-frame
             (websocket frame)
             (lexical-let ((frame frame))
diff --git a/packages/websocket/websocket.el b/packages/websocket/websocket.el
index 7ea9c93..564e041 100644
--- a/packages/websocket/websocket.el
+++ b/packages/websocket/websocket.el
@@ -111,11 +111,6 @@ URL of the connection.")
   "The websocket GUID as defined in RFC 6455.
 Do not change unless the RFC changes.")
 
-(defvar websocket-mask-frames t
-  "If true, we mask frames as defined in the spec.
-This is recommended to be true, and some servers will refuse to
-communicate with unmasked clients.")
-
 (defvar websocket-callback-debug-on-error nil
   "If true, when an error happens in a client callback, invoke the debugger.
 Having this on can cause issues with missing frames if the debugger is
@@ -295,13 +290,14 @@ Otherwise we throw the error 
`websocket-incomplete-frame'."
   (when (< (length s) n)
     (throw 'websocket-incomplete-frame nil)))
 
-(defun websocket-encode-frame (frame)
-  "Encode the FRAME struct to the binary representation."
+(defun websocket-encode-frame (frame should-mask)
+  "Encode the FRAME struct to the binary representation.
+We mask the frame or not, depending on SHOULD-MASK."
   (let* ((opcode (websocket-frame-opcode frame))
          (payload (websocket-frame-payload frame))
          (fin (websocket-frame-completep frame))
          (payloadp (memq opcode '(continuation text binary)))
-         (mask-key (when websocket-mask-frames  (websocket-genbytes 4))))
+         (mask-key (when should-mask (websocket-genbytes 4))))
     (apply 'unibyte-string
            (append (list
                     (logior (cond ((eq opcode 'continuation) 0)
@@ -314,7 +310,7 @@ Otherwise we throw the error `websocket-incomplete-frame'."
                    (when payloadp
                      (list
                       (logior
-                       (if websocket-mask-frames 128 0)
+                       (if should-mask 128 0)
                        (cond ((< (length payload) 126) (length payload))
                              ((< (length payload) 65536) 126)
                              (t 127)))))
@@ -323,11 +319,10 @@ Otherwise we throw the error 
`websocket-incomplete-frame'."
                                           (cond ((< (length payload) 126) 1)
                                                 ((< (length payload) 65536) 2)
                                                 (t 8))) nil))
-                   (when (and payloadp websocket-mask-frames)
+                   (when (and payloadp should-mask)
                      (append mask-key nil))
                    (when payloadp
-                     (append (if websocket-mask-frames
-                                 (websocket-mask mask-key payload)
+                     (append (if should-mask (websocket-mask mask-key payload)
                                payload)
                              nil))))))
 
@@ -542,7 +537,8 @@ the `websocket-error' condition."
   (unless (websocket-openp websocket)
     (signal 'websocket-closed frame))
   (process-send-string (websocket-conn websocket)
-                       (websocket-encode-frame frame)))
+                       ;; We mask only when we're a client, following the spec.
+                       (websocket-encode-frame frame (not (websocket-server-p 
websocket)))))
 
 (defun websocket-openp (websocket)
   "Check WEBSOCKET and return non-nil if it is open, and either
@@ -554,6 +550,7 @@ connecting or open."
 (defun websocket-close (websocket)
   "Close WEBSOCKET and erase all the old websocket data."
   (websocket-debug websocket "Closing websocket")
+  (websocket-try-callback 'websocket-on-close 'on-close websocket)
   (when (websocket-openp websocket)
     (websocket-send websocket
                     (make-websocket-frame :opcode 'close
@@ -692,9 +689,10 @@ describing the problem with the frame.
      conn
      (lambda (process change)
        (let ((websocket (process-get process :websocket)))
-         (websocket-debug websocket
-                          "State change to %s" change)
-         (unless (eq 'closed (websocket-ready-state websocket))
+         (websocket-debug websocket "State change to %s" change)
+         (when (and
+                (member (process-status process) '(closed failed exit signal))
+                (not (eq 'closed (websocket-ready-state websocket))))
            (websocket-try-callback 'websocket-on-close 'on-close websocket)))))
     (set-process-query-on-exit-flag conn nil)
     (process-send-string conn
@@ -827,6 +825,7 @@ connection, which should be kept in order to pass to
              :server-conn server
              :conn client
              :url client
+             :server-p t
              :on-open (or (process-get server :on-open) 'identity)
              :on-message (or (process-get server :on-message) (lambda (_ws 
_frame)))
              :on-close (lexical-let ((user-method
@@ -849,7 +848,9 @@ connection, which should be kept in order to pass to
      (lambda (process change)
        (let ((websocket (process-get process :websocket)))
          (websocket-debug websocket "State change to %s" change)
-         (unless (eq 'closed (websocket-ready-state websocket))
+         (when (and
+                (member (process-status process) '(closed failed exit signal))
+                (not (eq 'closed (websocket-ready-state websocket))))
            (websocket-try-callback 'websocket-on-close 'on-close 
websocket)))))))
 
 (defun websocket-create-headers (url key protocol extensions)

-----------------------------------------------------------------------

Summary of changes:
 packages/websocket/websocket-functional-test.el |    3 +-
 packages/websocket/websocket-test.el            |   37 +++++++++++------------
 packages/websocket/websocket.el                 |   35 +++++++++++----------
 3 files changed, 38 insertions(+), 37 deletions(-)


hooks/post-receive
-- 
ELPA



reply via email to

[Prev in Thread] Current Thread [Next in Thread]