Commit 2dfea679 authored by Eric Timmons's avatar Eric Timmons
Browse files

Lazy load openssl libraries

Load openssl libraries on image restore if possible. If there is an error
loading them or initializing cl+ssl's internal state, report that the drakma
client is unavailable.
parent b448a4b2
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -30,6 +30,17 @@
              :executable (typep o 'program-op)
              #+:sb-core-compression :compression #+:sb-core-compression t))

(defmethod cffi-toolchain:static-image-new-features
    (o (s (eql (find-system "clpm-exec/dynamic-libs"))))
  "Prevent cl-ssl from loading the foreign libraries at build time."
  (list :cl+ssl-foreign-libs-already-loaded))

(defmethod cffi-toolchain:static-image-remove-features-on-dump
    (o (s (eql (find-system "clpm-exec/dynamic-libs"))))
  "The libraries are not truly loaded, we just tricked cl+ssl, so remove that
feature on dump."
  (list :cl+ssl-foreign-libs-already-loaded))

(defsystem #:clpm-exec/static-libs
  :license "BSD-2-Clause"
  :defsystem-depends-on (#:cffi-toolchain)
+30 −0
Original line number Diff line number Diff line
;;;; Integration with CL+SSL
;;;;
;;;; This software is part of CLPM. See README.org for more information. See
;;;; LICENSE for license information.

(uiop:define-package #:clpm/http-client/cl-plus-ssl
    (:use #:cl
          #:cl+ssl)
  (:import-from #:cffi)
  (:import-from #:cl+ssl
                #:libcrypto
                #:libssl
                #:libeay32)
  (:export #:*openssl-available-p*))

(in-package #:clpm/http-client/cl-plus-ssl)

(defvar *openssl-available-p* nil
  "T if OpenSSL libraries are present and available in the image")

(defun maybe-load-openssl ()
  "Hook to be run on image restore that tries to load and initialize OpenSSL."
  ;; Errors could be from libraries not being available, or being unable to
  ;; initialize because an incompatible OpenSSL version was loaded.
  (ignore-errors
   (reload)
   (ensure-initialized)
   (setf *openssl-available-p* t)))

(uiop:register-image-restore-hook 'maybe-load-openssl)
+2 −1
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
(uiop:define-package #:clpm/http-client/drakma
    (:use #:cl
          #:alexandria
          #:clpm/http-client/cl-plus-ssl
          #:clpm/http-client/defs
          #:clpm/utils
          #:drakma)
@@ -24,7 +25,7 @@
(register-http-client :drakma 'drakma-client)

(defmethod http-client-available-p ((client drakma-client))
  t)
  *openssl-available-p*)

(defmethod %fetch-url-to-stream ((client drakma-client) url out-stream
                                 &key headers)