aboutsummaryrefslogtreecommitdiff
path: root/guix/forge/socket.scm
blob: e6e38deaad56a4a947ab318ebadeac22b961946c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
;;; guix-forge --- Guix software forge meta-service
;;; Copyright © 2022, 2023 Arun Isaac <arunisaac@systemreboot.net>
;;;
;;; This file is part of guix-forge.
;;;
;;; guix-forge is free software: you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published
;;; by the Free Software Foundation, either version 3 of the License,
;;; or (at your option) any later version.
;;;
;;; guix-forge is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;;; General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with guix-forge.  If not, see
;;; <https://www.gnu.org/licenses/>.

(define-module (forge socket)
  #:use-module (guix records)
  #:export (<forge-host-socket>
            forge-host-socket
            forge-host-socket?
            forge-host-socket-hostname
            forge-host-socket-port
            <forge-ip-socket>
            forge-ip-socket
            forge-ip-socket?
            forge-ip-socket-ip
            forge-ip-socket-port
            ipv4-address?
            ipv6-address?
            <forge-unix-socket>
            forge-unix-socket
            forge-unix-socket?
            forge-unix-socket-path))

(define-record-type* <forge-host-socket>
  forge-host-socket make-forge-host-socket
  forge-host-socket?
  (hostname forge-host-socket-hostname
            (default "localhost"))
  (port forge-host-socket-port))

(define-record-type* <forge-ip-socket>
  forge-ip-socket make-forge-ip-socket
  forge-ip-socket?
  (ip forge-ip-socket-ip
      (default "127.0.0.1"))
  (port forge-ip-socket-port))

(define (ipv4-address? address)
  "Return #t if ADDRESS is an IPv4 address. Else, return #f."
  (string-contains address "."))

(define (ipv6-address? address)
  "Return #t if ADDRESS is an IPv6 address. Else, return #f."
  (string-contains address ":"))

(define-record-type* <forge-unix-socket>
  forge-unix-socket make-forge-unix-socket
  forge-unix-socket?
  (path forge-unix-socket-path))