10 |
10 |
11 else |
11 else |
12 errx(1, "%s: %s", func, gnutls_strerror(_err)); |
12 errx(1, "%s: %s", func, gnutls_strerror(_err)); |
13 } |
13 } |
14 |
14 |
15 static int sock_gnutls_read (struct sock_stream *base_sock, void *buf, size_t len) |
15 static err_t sock_gnutls_read (struct sock_stream *base_sock, void *buf, size_t len) |
16 { |
16 { |
17 struct sock_gnutls *sock = SOCK_FROM_BASE(base_sock, struct sock_gnutls); |
17 struct sock_gnutls *sock = SOCK_FROM_BASE(base_sock, struct sock_gnutls); |
18 |
18 |
19 // just map to gnutls_record_recv |
19 // just map to gnutls_record_recv |
20 return gnutls_record_recv(sock->session, buf, len); |
20 return gnutls_record_recv(sock->session, buf, len); |
21 } |
21 } |
22 |
22 |
23 static int sock_gnutls_write (struct sock_stream *base_sock, const void *buf, size_t len) |
23 static err_t sock_gnutls_write (struct sock_stream *base_sock, const void *buf, size_t len) |
24 { |
24 { |
25 struct sock_gnutls *sock = SOCK_FROM_BASE(base_sock, struct sock_gnutls); |
25 struct sock_gnutls *sock = SOCK_FROM_BASE(base_sock, struct sock_gnutls); |
26 |
26 |
27 // just map to gnutls_record_send |
27 // just map to gnutls_record_send |
28 return gnutls_record_send(sock->session, buf, len); |
28 return gnutls_record_send(sock->session, buf, len); |
49 void sock_gnutls_client_ctx_anon (struct sock_gnutls_client_ctx *ctx) |
49 void sock_gnutls_client_ctx_anon (struct sock_gnutls_client_ctx *ctx) |
50 { |
50 { |
51 gnutls_certificate_allocate_credentials(&ctx->xcred); |
51 gnutls_certificate_allocate_credentials(&ctx->xcred); |
52 } |
52 } |
53 |
53 |
54 // XXX: errors |
54 err_t sock_gnutls_init (void) |
55 void sock_gnutls_init (void) |
|
56 { |
55 { |
57 int _err; |
56 int _err; |
58 |
57 |
59 // global init |
58 // global init |
60 if ((_err = gnutls_global_init()) < 0) |
59 if ((_err = gnutls_global_init()) < 0) |
61 errx(1, "gnutls_global_init: %s", gnutls_strerror(_err)); |
60 errx(1, "gnutls_global_init: %s", gnutls_strerror(_err)); |
62 |
61 |
63 // init _sock_gnutls_ctx |
62 // init _sock_gnutls_ctx |
64 sock_gnutls_client_ctx_anon(&_sock_gnutls_client_ctx); |
63 sock_gnutls_client_ctx_anon(&_sock_gnutls_client_ctx); |
|
64 |
|
65 // done |
|
66 return SUCCESS; |
65 } |
67 } |
66 |
68 |
67 |
69 |
68 // XXX: errors |
70 // XXX: errors |
69 struct sock_stream *sock_ssl_connect (const char *host, const char *service) |
71 struct sock_stream *sock_ssl_connect (const char *host, const char *service) |