Merge branch 'master' into doc-strings
authorAlejandro R Sedeño <asedeno@google.com>
Thu, 4 Apr 2013 02:27:17 +0000 (22:27 -0400)
committerAlejandro R Sedeño <asedeno@google.com>
Thu, 4 Apr 2013 02:27:17 +0000 (22:27 -0400)
Conflicts:
src/mysql-protocol/handshake.lisp
src/wire-protocol/compressed-protocol.lisp

1  2 
src/mysql-protocol/handshake.lisp
src/wire-protocol/compressed-protocol.lisp

      (values)))
  
  (defun send-ssl-request-packet (verify)
 -  "Sends a MySQL SSL Connection Request Packet and begins SSL Negotiation."
 +  "Sends a MySQL SSL Connection Request Packet and begins SSL negotiation."
-   (let ((s (flexi-streams:make-in-memory-output-stream :element-type '(unsigned-byte 8))))
-     (write-fixed-length-integer (mysql-connection-capabilities *mysql-connection*) 4 s)
-     (write-fixed-length-integer #x1000000 4 s)
-     (write-byte (mysql-connection-cs-coll *mysql-connection*) s)
-     (write-fixed-length-integer 0 23 s) ; 23 reserved bytes
-     (mysql-write-packet (flexi-streams:get-output-stream-sequence s))
-     ;; We may not have CL+SSL, in which case we'll never get to this function,
-     ;; but we still want it to compile.
-     (let ((stream (uiop/package:symbol-call
-                    :cl+ssl :make-ssl-client-stream
-                    (mysql-connection-stream *mysql-connection*))))
-       (when verify
-         (uiop/package:symbol-call
-          :cl+ssl :ssl-stream-check-verify
-          stream))
-       (setf (mysql-connection-stream *mysql-connection*) stream))))
+   (mysql-write-packet
+    (flexi-streams:with-output-to-sequence (s)
+      (write-fixed-length-integer (mysql-connection-capabilities *mysql-connection*) 4 s)
+      (write-fixed-length-integer #x1000000 4 s)
+      (write-byte (mysql-connection-cs-coll *mysql-connection*) s)
+      (write-fixed-length-integer 0 23 s))) ; 23 reserved bytes
+   ;; We may not have CL+SSL, in which case we'll never get to this function,
+   ;; but we still want it to compile.
+   (let ((stream (uiop/package:symbol-call
+                  :cl+ssl :make-ssl-client-stream
+                  (mysql-connection-stream *mysql-connection*))))
+     (when verify
+       (uiop/package:symbol-call
+        :cl+ssl :ssl-stream-check-verify
+        stream))
+     (setf (mysql-connection-stream *mysql-connection*) stream)))
  
 +;; We don't actually receive a Handshake Response packet as a client, but it looks like this.
 +
  ;; (define-packet handshake-response-v41
  ;;   ((capability-flags :mysql-type (integer 4))
  ;;    (max-packet-size :mysql-type (integer 4))
  ;;     :predicate (flagsp +mysql-capability-client-connect-attrs+ capability-flags))))
  
  (defun send-handshake-response-41 (&key username auth-plugin auth-response database)
 +  "Send a MySQL Handshake Response v41 to the default MySQL connection."
-   (let ((s (flexi-streams:make-in-memory-output-stream :element-type '(unsigned-byte 8))))
-     (write-fixed-length-integer (mysql-connection-capabilities *mysql-connection*) 4 s)
-     (write-fixed-length-integer #x1000000 4 s)
-     (write-byte (mysql-connection-cs-coll *mysql-connection*) s)
-     (write-fixed-length-integer 0 23 s) ; 23 reserved bytes
-     (write-null-terminated-string (babel:string-to-octets username) s)
-     (cond
-       ((mysql-has-capability +mysql-capability-client-plugin-auth-lenec-client-data+)
-        (write-length-encoded-integer (length auth-response) s)
-        (write-sequence auth-response s))
-       ((mysql-has-capability +mysql-capability-client-secure-connection+)
-        (write-byte (length auth-response) s)
-        (write-sequence auth-response s))
-       (T
-        (write-null-terminated-string auth-response s)))
-     ;; If the bit is still set at this point, then we have a database schema to specify.
-     (when (mysql-has-capability +mysql-capability-client-connect-with-db+)
-       (write-null-terminated-string (babel:string-to-octets database) s))
-     (when (mysql-has-capability +mysql-capability-client-plugin-auth+)
-       (write-null-terminated-string auth-plugin s))
-     #+mysql-client-connect-attributes
-     (when (mysql-has-capability +mysql-capability-client-connect-attrs+)
-       ;; asedeno-TODO: When this is implemented, what sort of
-       ;; attributes do we want to send? Are they hard-coded? Supplied
-       ;; by the user? Both? Stored in the connection object?
-       nil)
-     (mysql-write-packet (flexi-streams:get-output-stream-sequence s))))
+   (mysql-write-packet
+    (flexi-streams:with-output-to-sequence (s)
+      (write-fixed-length-integer (mysql-connection-capabilities *mysql-connection*) 4 s)
+      (write-fixed-length-integer #x1000000 4 s)
+      (write-byte (mysql-connection-cs-coll *mysql-connection*) s)
+      (write-fixed-length-integer 0 23 s) ; 23 reserved bytes
+      (write-null-terminated-string (babel:string-to-octets username) s)
+      (cond
+        ((mysql-has-capability +mysql-capability-client-plugin-auth-lenec-client-data+)
+         (write-length-encoded-integer (length auth-response) s)
+         (write-sequence auth-response s))
+        ((mysql-has-capability +mysql-capability-client-secure-connection+)
+         (write-byte (length auth-response) s)
+         (write-sequence auth-response s))
+        (T
+         (write-null-terminated-string auth-response s)))
+      ;; If the bit is still set at this point, then we have a database schema to specify.
+      (when (mysql-has-capability +mysql-capability-client-connect-with-db+)
+        (write-null-terminated-string (babel:string-to-octets database) s))
+      (when (mysql-has-capability +mysql-capability-client-plugin-auth+)
+        (write-null-terminated-string auth-plugin s))
+      #+mysql-client-connect-attributes
+      (when (mysql-has-capability +mysql-capability-client-connect-attrs+)
+        ;; asedeno-TODO: When this is implemented, what sort of
+        ;; attributes do we want to send? Are they hard-coded? Supplied
+        ;; by the user? Both? Stored in the connection object?
+        nil))))
  
  (defun process-initial-handshake-payload (payload)
 +  "Initial handshake processing dispatch."
    (ecase (aref payload 0)
      (10 (process-initial-handshake-v10 payload))))
  
@@@ -111,22 -85,21 +111,23 @@@ uncompressed, but for now using the Com
                    :documentation "The container for the outgoing, to be deflated, byte stream.")
     (sequence-id :type integer
                  :initform 0
 -                :accessor mysql-compressed-stream-sequence-id)))
 +                :accessor mysql-compressed-stream-sequence-id
 +                :documentation "Sequence IDs for the compressed protocol packet stream.")))
  
- (defun fill-input-buffer (stream)
+ (defun fill-input-buffer (stream &aux payload)
 -  "Allocates a new input buffer stream from the results of parsing a new compressed packet off of
 -   the captured stream"
 +  "Allocates a new input buffer stream from the results of parsing a new
 +   compressed packet off of the wrapped stream. Requires that the existing
 +   input buffer, if any, be empty."
    (assert (typep stream 'mysql-compressed-stream))
-   (let ((input-buffer (mysql-compressed-stream-input-buffer stream)))
-     (assert (null (and input-buffer (listen input-buffer)))))
-   (multiple-value-bind (payload sequence-id)
-       (read-compressed-wire-packet (mysql-compressed-stream-stream stream)
-                                    :expected-sequence-id (mysql-compressed-stream-sequence-id stream))
-     (setf (mysql-compressed-stream-input-buffer stream)
-           (flexi-streams:make-in-memory-input-stream payload))
-     (setf (mysql-compressed-stream-sequence-id stream) sequence-id)))
+   (with-accessors ((stream mysql-compressed-stream-stream)
+                    (input-buffer mysql-compressed-stream-input-buffer)
+                    (sequence-id mysql-compressed-stream-sequence-id))
+       stream
+     (assert (null (and input-buffer (listen input-buffer))))
+     (multiple-value-setq (payload sequence-id)
+       (read-compressed-wire-packet stream :expected-sequence-id sequence-id))
+     (when input-buffer (close input-buffer))
+     (setq input-buffer (flexi-streams:make-in-memory-input-stream payload))))
  
  ;;; Gray Stream methods for our compressed stream.
  (defmethod trivial-gray-streams:stream-listen ((stream mysql-compressed-stream))