|
Packit |
aea12f |
;;; Help produce Guile wrappers for GnuTLS types.
|
|
Packit |
aea12f |
;;;
|
|
Packit |
aea12f |
;;; GnuTLS --- Guile bindings for GnuTLS.
|
|
Packit |
aea12f |
;;; Copyright (C) 2007-2012, 2014 Free Software Foundation, Inc.
|
|
Packit |
aea12f |
;;;
|
|
Packit |
aea12f |
;;; GnuTLS is free software; you can redistribute it and/or
|
|
Packit |
aea12f |
;;; modify it under the terms of the GNU Lesser General Public
|
|
Packit |
aea12f |
;;; License as published by the Free Software Foundation; either
|
|
Packit |
aea12f |
;;; version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
aea12f |
;;;
|
|
Packit |
aea12f |
;;; GnuTLS is distributed in the hope that it will be useful,
|
|
Packit |
aea12f |
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
aea12f |
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
aea12f |
;;; Lesser General Public License for more details.
|
|
Packit |
aea12f |
;;;
|
|
Packit |
aea12f |
;;; You should have received a copy of the GNU Lesser General Public
|
|
Packit |
aea12f |
;;; License along with GnuTLS; if not, write to the Free Software
|
|
Packit |
aea12f |
;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
;;; Written by Ludovic Courtès <ludo@chbouib.org>
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define-module (gnutls build smobs)
|
|
Packit |
aea12f |
:use-module (srfi srfi-9)
|
|
Packit |
aea12f |
:use-module (srfi srfi-13)
|
|
Packit |
aea12f |
:use-module (gnutls build utils)
|
|
Packit |
aea12f |
:export (make-smob-type smob-type-tag smob-free-function
|
|
Packit |
aea12f |
smob-type-predicate-scheme-name
|
|
Packit |
aea12f |
smob-type-from-c-function smob-type-to-c-function
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
output-smob-type-definition output-smob-type-declaration
|
|
Packit |
aea12f |
output-smob-type-predicate
|
|
Packit |
aea12f |
output-c->smob-converter output-smob->c-converter
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
%gnutls-smobs))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
;;;
|
|
Packit |
aea12f |
;;; SMOB types.
|
|
Packit |
aea12f |
;;;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define-record-type <smob-type>
|
|
Packit |
aea12f |
(%make-smob-type c-name scm-name free-function)
|
|
Packit |
aea12f |
smob-type?
|
|
Packit |
aea12f |
(c-name smob-type-c-name)
|
|
Packit |
aea12f |
(scm-name smob-type-scheme-name)
|
|
Packit |
aea12f |
(free-function smob-type-free-function))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define (make-smob-type c-name scm-name . free-function)
|
|
Packit |
aea12f |
(%make-smob-type c-name scm-name
|
|
Packit |
aea12f |
(if (null? free-function)
|
|
Packit |
aea12f |
(string-append "gnutls_"
|
|
Packit |
aea12f |
(scheme-symbol->c-name scm-name)
|
|
Packit |
aea12f |
"_deinit")
|
|
Packit |
aea12f |
(car free-function))))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define (smob-type-tag type)
|
|
Packit |
aea12f |
;; Return the name of the C variable holding the type tag for TYPE.
|
|
Packit |
aea12f |
(string-append "scm_tc16_gnutls_"
|
|
Packit |
aea12f |
(scheme-symbol->c-name (smob-type-scheme-name type))))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define (smob-type-predicate-scheme-name type)
|
|
Packit |
aea12f |
;; Return a string denoting the Scheme name of TYPE's type predicate.
|
|
Packit |
aea12f |
(string-append (symbol->string (smob-type-scheme-name type)) "?"))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define (smob-type-to-c-function type)
|
|
Packit |
aea12f |
;; Return the name of the C `scm_to_' function for SMOB.
|
|
Packit |
aea12f |
(string-append "scm_to_gnutls_"
|
|
Packit |
aea12f |
(scheme-symbol->c-name (smob-type-scheme-name type))))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define (smob-type-from-c-function type)
|
|
Packit |
aea12f |
;; Return the name of the C `scm_from_' function for SMOB.
|
|
Packit |
aea12f |
(string-append "scm_from_gnutls_"
|
|
Packit |
aea12f |
(scheme-symbol->c-name (smob-type-scheme-name type))))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
;;;
|
|
Packit |
aea12f |
;;; C code generation.
|
|
Packit |
aea12f |
;;;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define (output-smob-type-definition type port)
|
|
Packit |
aea12f |
(format port "SCM_GLOBAL_SMOB (~a, \"~a\", 0);~%"
|
|
Packit |
aea12f |
(smob-type-tag type)
|
|
Packit |
aea12f |
(smob-type-scheme-name type))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(format port "SCM_SMOB_FREE (~a, ~a_free, obj)~%{~%"
|
|
Packit |
aea12f |
(smob-type-tag type)
|
|
Packit |
aea12f |
(scheme-symbol->c-name (smob-type-scheme-name type)))
|
|
Packit |
aea12f |
(format port " ~a c_obj;~%"
|
|
Packit |
aea12f |
(smob-type-c-name type))
|
|
Packit |
aea12f |
(format port " c_obj = (~a) SCM_SMOB_DATA (obj);~%"
|
|
Packit |
aea12f |
(smob-type-c-name type))
|
|
Packit |
aea12f |
(format port " ~a (c_obj);~%"
|
|
Packit |
aea12f |
(smob-type-free-function type))
|
|
Packit |
aea12f |
(format port " return 0;~%")
|
|
Packit |
aea12f |
(format port "}~%"))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define (output-smob-type-declaration type port)
|
|
Packit |
aea12f |
;; Issue a header file declaration for the SMOB type tag of TYPE.
|
|
Packit |
aea12f |
(format port "SCM_API scm_t_bits ~a;~%"
|
|
Packit |
aea12f |
(smob-type-tag type)))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define (output-smob-type-predicate type port)
|
|
Packit |
aea12f |
(define (texi-doc-string)
|
|
Packit |
aea12f |
(string-append "Return true if @var{obj} is of type @code{"
|
|
Packit |
aea12f |
(symbol->string (smob-type-scheme-name type))
|
|
Packit |
aea12f |
"}."))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(let ((c-name (string-append "scm_gnutls_"
|
|
Packit |
aea12f |
(string-map (lambda (chr)
|
|
Packit |
aea12f |
(if (char=? chr #\-)
|
|
Packit |
aea12f |
#\_
|
|
Packit |
aea12f |
chr))
|
|
Packit |
aea12f |
(symbol->string
|
|
Packit |
aea12f |
(smob-type-scheme-name type)))
|
|
Packit |
aea12f |
"_p")))
|
|
Packit |
aea12f |
(format port "SCM_DEFINE (~a, \"~a\", 1, 0, 0,~%"
|
|
Packit |
aea12f |
c-name (smob-type-predicate-scheme-name type))
|
|
Packit |
aea12f |
(format port " (SCM obj),~%")
|
|
Packit |
aea12f |
(format port " \"~a\")~%"
|
|
Packit |
aea12f |
(texi-doc-string))
|
|
Packit |
aea12f |
(format port "#define FUNC_NAME s_~a~%"
|
|
Packit |
aea12f |
c-name)
|
|
Packit |
aea12f |
(format port "{~%")
|
|
Packit |
aea12f |
(format port " return (scm_from_bool (SCM_SMOB_PREDICATE (~a, obj)));~%"
|
|
Packit |
aea12f |
(smob-type-tag type))
|
|
Packit |
aea12f |
(format port "}~%#undef FUNC_NAME~%")))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define (output-c->smob-converter type port)
|
|
Packit |
aea12f |
(format port "static inline SCM~%~a (~a c_obj)~%{~%"
|
|
Packit |
aea12f |
(smob-type-from-c-function type)
|
|
Packit |
aea12f |
(smob-type-c-name type))
|
|
Packit |
aea12f |
(format port " SCM_RETURN_NEWSMOB (~a, (scm_t_bits) c_obj);~%"
|
|
Packit |
aea12f |
(smob-type-tag type))
|
|
Packit |
aea12f |
(format port "}~%"))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define (output-smob->c-converter type port)
|
|
Packit |
aea12f |
(format port "static inline ~a~%~a (SCM obj, "
|
|
Packit |
aea12f |
(smob-type-c-name type)
|
|
Packit |
aea12f |
(smob-type-to-c-function type))
|
|
Packit |
aea12f |
(format port "unsigned pos, const char *func)~%")
|
|
Packit |
aea12f |
(format port "#define FUNC_NAME func~%")
|
|
Packit |
aea12f |
(format port "{~%")
|
|
Packit |
aea12f |
(format port " SCM_VALIDATE_SMOB (pos, obj, ~a);~%"
|
|
Packit |
aea12f |
(string-append "gnutls_"
|
|
Packit |
aea12f |
(scheme-symbol->c-name (smob-type-scheme-name type))))
|
|
Packit |
aea12f |
(format port " return ((~a) SCM_SMOB_DATA (obj));~%"
|
|
Packit |
aea12f |
(smob-type-c-name type))
|
|
Packit |
aea12f |
(format port "}~%")
|
|
Packit |
aea12f |
(format port "#undef FUNC_NAME~%"))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
;;;
|
|
Packit |
aea12f |
;;; Actual SMOB types.
|
|
Packit |
aea12f |
;;;
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define %session-smob
|
|
Packit |
aea12f |
(make-smob-type "gnutls_session_t" 'session
|
|
Packit |
aea12f |
"gnutls_deinit"))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define %anonymous-client-credentials-smob
|
|
Packit |
aea12f |
(make-smob-type "gnutls_anon_client_credentials_t" 'anonymous-client-credentials
|
|
Packit |
aea12f |
"gnutls_anon_free_client_credentials"))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define %anonymous-server-credentials-smob
|
|
Packit |
aea12f |
(make-smob-type "gnutls_anon_server_credentials_t" 'anonymous-server-credentials
|
|
Packit |
aea12f |
"gnutls_anon_free_server_credentials"))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define %dh-parameters-smob
|
|
Packit |
aea12f |
(make-smob-type "gnutls_dh_params_t" 'dh-parameters
|
|
Packit |
aea12f |
"gnutls_dh_params_deinit"))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define %certificate-credentials-smob
|
|
Packit |
aea12f |
(make-smob-type "gnutls_certificate_credentials_t" 'certificate-credentials
|
|
Packit |
aea12f |
"gnutls_certificate_free_credentials"))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define %srp-server-credentials-smob
|
|
Packit |
aea12f |
(make-smob-type "gnutls_srp_server_credentials_t" 'srp-server-credentials
|
|
Packit |
aea12f |
"gnutls_srp_free_server_credentials"))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define %srp-client-credentials-smob
|
|
Packit |
aea12f |
(make-smob-type "gnutls_srp_client_credentials_t" 'srp-client-credentials
|
|
Packit |
aea12f |
"gnutls_srp_free_client_credentials"))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define %psk-server-credentials-smob
|
|
Packit |
aea12f |
(make-smob-type "gnutls_psk_server_credentials_t" 'psk-server-credentials
|
|
Packit |
aea12f |
"gnutls_psk_free_server_credentials"))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define %psk-client-credentials-smob
|
|
Packit |
aea12f |
(make-smob-type "gnutls_psk_client_credentials_t" 'psk-client-credentials
|
|
Packit |
aea12f |
"gnutls_psk_free_client_credentials"))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define %x509-certificate-smob
|
|
Packit |
aea12f |
(make-smob-type "gnutls_x509_crt_t" 'x509-certificate
|
|
Packit |
aea12f |
"gnutls_x509_crt_deinit"))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define %x509-private-key-smob
|
|
Packit |
aea12f |
(make-smob-type "gnutls_x509_privkey_t" 'x509-private-key
|
|
Packit |
aea12f |
"gnutls_x509_privkey_deinit"))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define %openpgp-certificate-smob
|
|
Packit |
aea12f |
(make-smob-type "gnutls_openpgp_crt_t" 'openpgp-certificate
|
|
Packit |
aea12f |
"gnutls_openpgp_crt_deinit"))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define %openpgp-private-key-smob
|
|
Packit |
aea12f |
(make-smob-type "gnutls_openpgp_privkey_t" 'openpgp-private-key
|
|
Packit |
aea12f |
"gnutls_openpgp_privkey_deinit"))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define %openpgp-keyring-smob
|
|
Packit |
aea12f |
(make-smob-type "gnutls_openpgp_keyring_t" 'openpgp-keyring
|
|
Packit |
aea12f |
"gnutls_openpgp_keyring_deinit"))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
(define %gnutls-smobs
|
|
Packit |
aea12f |
;; All SMOB types.
|
|
Packit |
aea12f |
(list %session-smob %anonymous-client-credentials-smob
|
|
Packit |
aea12f |
%anonymous-server-credentials-smob %dh-parameters-smob
|
|
Packit |
aea12f |
%certificate-credentials-smob
|
|
Packit |
aea12f |
%srp-server-credentials-smob %srp-client-credentials-smob
|
|
Packit |
aea12f |
%psk-server-credentials-smob %psk-client-credentials-smob
|
|
Packit |
aea12f |
%x509-certificate-smob %x509-private-key-smob
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
%openpgp-certificate-smob %openpgp-private-key-smob
|
|
Packit |
aea12f |
%openpgp-keyring-smob))
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
;;; Local Variables:
|
|
Packit |
aea12f |
;;; mode: scheme
|
|
Packit |
aea12f |
;;; coding: latin-1
|
|
Packit |
aea12f |
;;; End:
|
|
Packit |
aea12f |
|
|
Packit |
aea12f |
;;; arch-tag: 26bf79ef-6dee-45f2-9e9d-2d209c518278
|