Skip to content

Commit 02d80cc

Browse files
authored
Remove references to old "crustls" name (#289)
Remove symlinking of old library name (libcrustls.a and crustls.h). Rename header guard to "RUSTLS_H". Rename CRUSTLS_DEMO_* constants to DEMO_*.
1 parent a327dca commit 02d80cc

9 files changed

+81
-83
lines changed

Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ install: target/$(PROFILE)/librustls_ffi.a
5858
install target/$(PROFILE)/librustls_ffi.a $(DESTDIR)/lib/librustls.a
5959
mkdir -p $(DESTDIR)/include
6060
install src/rustls.h $(DESTDIR)/include/
61-
ln -s librustls.a $(DESTDIR)/lib/libcrustls.a
62-
ln -s rustls.h $(DESTDIR)/include/crustls.h
6361

6462
clean:
6563
rm -rf target

cbindgen.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
include_guard = "CRUSTLS_H"
1+
include_guard = "RUSTLS_H"
22

33
usize_is_size_t = true
44

src/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ impl rustls_client_config {
557557
let client = ClientConnection::new(config, server_name).unwrap();
558558

559559
// We've succeeded. Put the client on the heap, and transfer ownership
560-
// to the caller. After this point, we must return CRUSTLS_OK so the
560+
// to the caller. After this point, we must return rustls_result::Ok so the
561561
// caller knows it is responsible for this memory.
562562
let c = Connection::from_client(client);
563563
BoxCastPtr::set_mut_ptr(conn_out, c);

src/rustls.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef CRUSTLS_H
2-
#define CRUSTLS_H
1+
#ifndef RUSTLS_H
2+
#define RUSTLS_H
33

44
#include <stdarg.h>
55
#include <stdbool.h>
@@ -1553,4 +1553,4 @@ rustls_result rustls_server_config_builder_set_persistence(struct rustls_server_
15531553
rustls_session_store_get_callback get_cb,
15541554
rustls_session_store_put_callback put_cb);
15551555

1556-
#endif /* CRUSTLS_H */
1556+
#endif /* RUSTLS_H */

src/server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ impl rustls_server_config {
340340
Err(e) => return map_error(e),
341341
};
342342
// We've succeeded. Put the server on the heap, and transfer ownership
343-
// to the caller. After this point, we must return CRUSTLS_OK so the
343+
// to the caller. After this point, we must return rustls_result::Ok so the
344344
// caller knows it is responsible for this memory.
345345
let c = Connection::from_server(server_connection);
346346
BoxCastPtr::set_mut_ptr(conn_out, c);

tests/client.c

+19-19
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ int
3434
make_conn(const char *hostname, const char *port)
3535
{
3636
int sockfd = 0;
37-
enum crustls_demo_result result = 0;
37+
enum demo_result result = 0;
3838
struct addrinfo *getaddrinfo_output = NULL, hints;
3939

4040
memset(&hints, 0, sizeof(hints));
@@ -64,7 +64,7 @@ make_conn(const char *hostname, const char *port)
6464
goto cleanup;
6565
}
6666
result = nonblock(sockfd);
67-
if(result != CRUSTLS_DEMO_OK) {
67+
if(result != DEMO_OK) {
6868
return 1;
6969
}
7070

@@ -85,13 +85,13 @@ make_conn(const char *hostname, const char *port)
8585
* Do one read from the socket, and process all resulting bytes into the
8686
* rustls_connection, then copy all plaintext bytes from the session to stdout.
8787
* Returns:
88-
* - CRUSTLS_DEMO_OK for success
89-
* - CRUSTLS_DEMO_AGAIN if we got an EAGAIN or EWOULDBLOCK reading from the
88+
* - DEMO_OK for success
89+
* - DEMO_AGAIN if we got an EAGAIN or EWOULDBLOCK reading from the
9090
* socket
91-
* - CRUSTLS_DEMO_EOF if we got EOF
92-
* - CRUSTLS_DEMO_ERROR for other errors.
91+
* - DEMO_EOF if we got EOF
92+
* - DEMO_ERROR for other errors.
9393
*/
94-
enum crustls_demo_result
94+
enum demo_result
9595
do_read(struct conndata *conn, struct rustls_connection *rconn)
9696
{
9797
int err = 1;
@@ -106,21 +106,21 @@ do_read(struct conndata *conn, struct rustls_connection *rconn)
106106
fprintf(stderr,
107107
"client: reading from socket: EAGAIN or EWOULDBLOCK: %s\n",
108108
strerror(errno));
109-
return CRUSTLS_DEMO_AGAIN;
109+
return DEMO_AGAIN;
110110
}
111111
else if(err != 0) {
112112
fprintf(stderr, "client: reading from socket: errno %d\n", err);
113-
return CRUSTLS_DEMO_ERROR;
113+
return DEMO_ERROR;
114114
}
115115

116116
result = rustls_connection_process_new_packets(rconn);
117117
if(result != RUSTLS_RESULT_OK) {
118118
print_error("server", "in process_new_packets", result);
119-
return CRUSTLS_DEMO_ERROR;
119+
return DEMO_ERROR;
120120
}
121121

122122
result = copy_plaintext_to_buffer(conn);
123-
if(result != CRUSTLS_DEMO_EOF) {
123+
if(result != DEMO_EOF) {
124124
return result;
125125
}
126126

@@ -131,15 +131,15 @@ do_read(struct conndata *conn, struct rustls_connection *rconn)
131131
fprintf(stderr,
132132
"client: error: read returned %zu bytes after receiving close_notify\n",
133133
n);
134-
return CRUSTLS_DEMO_ERROR;
134+
return DEMO_ERROR;
135135
}
136136
else if (signed_n < 0 && errno != EWOULDBLOCK) {
137137
fprintf(stderr,
138138
"client: error: read returned incorrect error after receiving close_notify: %s\n",
139139
strerror(errno));
140-
return CRUSTLS_DEMO_ERROR;
140+
return DEMO_ERROR;
141141
}
142-
return CRUSTLS_DEMO_EOF;
142+
return DEMO_EOF;
143143
}
144144

145145
static const char *CONTENT_LENGTH = "Content-Length";
@@ -224,13 +224,13 @@ send_request_and_read_response(struct conndata *conn,
224224
select awaiting the next bit of data. */
225225
for(;;) {
226226
result = do_read(conn, rconn);
227-
if(result == CRUSTLS_DEMO_AGAIN) {
227+
if(result == DEMO_AGAIN) {
228228
break;
229229
}
230-
else if(result == CRUSTLS_DEMO_EOF) {
230+
else if(result == DEMO_EOF) {
231231
goto drain_plaintext;
232232
}
233-
else if(result != CRUSTLS_DEMO_OK) {
233+
else if(result != DEMO_OK) {
234234
goto cleanup;
235235
}
236236
if(headers_len == 0) {
@@ -276,7 +276,7 @@ send_request_and_read_response(struct conndata *conn,
276276
stderr, "client: error in rustls_connection_write_tls: errno %d\n", err);
277277
goto cleanup;
278278
}
279-
if(result == CRUSTLS_DEMO_AGAIN) {
279+
if(result == DEMO_AGAIN) {
280280
break;
281281
}
282282
else if(n == 0) {
@@ -291,7 +291,7 @@ send_request_and_read_response(struct conndata *conn,
291291

292292
drain_plaintext:
293293
result = copy_plaintext_to_buffer(conn);
294-
if(result != CRUSTLS_DEMO_OK && result != CRUSTLS_DEMO_EOF) {
294+
if(result != DEMO_OK && result != DEMO_EOF) {
295295
goto cleanup;
296296
}
297297
fprintf(stderr, "client: writing %zu bytes to stdout\n", conn->data.len);

tests/common.c

+18-18
Original file line numberDiff line numberDiff line change
@@ -74,32 +74,32 @@ write_all(int fd, const char *buf, int n)
7474
/*
7575
* Set a socket to be nonblocking.
7676
*
77-
* Returns CRUSTLS_DEMO_OK on success, CRUSTLS_DEMO_ERROR on error.
77+
* Returns DEMO_OK on success, DEMO_ERROR on error.
7878
*/
79-
enum crustls_demo_result
79+
enum demo_result
8080
nonblock(int sockfd)
8181
{
8282
#ifdef _WIN32
8383
u_long nonblock = 1UL;
8484

8585
if(ioctlsocket(sockfd, FIONBIO, &nonblock) != 0) {
8686
perror("Error setting socket nonblocking");
87-
return CRUSTLS_DEMO_ERROR;
87+
return DEMO_ERROR;
8888
}
8989
#else
9090
int flags;
9191
flags = fcntl(sockfd, F_GETFL, 0);
9292
if(flags < 0) {
9393
perror("getting socket flags");
94-
return CRUSTLS_DEMO_ERROR;
94+
return DEMO_ERROR;
9595
}
9696
flags = fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
9797
if(flags < 0) {
9898
perror("setting socket nonblocking");
99-
return CRUSTLS_DEMO_ERROR;
99+
return DEMO_ERROR;
100100
}
101101
#endif
102-
return CRUSTLS_DEMO_OK;
102+
return DEMO_OK;
103103
}
104104

105105
int
@@ -183,8 +183,8 @@ bytevec_consume(struct bytevec *vec, size_t n)
183183

184184
// Ensure there are at least n bytes available between vec->len and
185185
// vec->capacity. If this requires reallocating, this may return
186-
// CRUSTLS_DEMO_ERROR.
187-
enum crustls_demo_result
186+
// DEMO_ERROR.
187+
enum demo_result
188188
bytevec_ensure_available(struct bytevec *vec, size_t n)
189189
{
190190
size_t available = vec->capacity - vec->len;
@@ -198,12 +198,12 @@ bytevec_ensure_available(struct bytevec *vec, size_t n)
198198
newdata = realloc(vec->data, newsize);
199199
if(newdata == NULL) {
200200
fprintf(stderr, "out of memory trying to get %zu bytes\n", newsize);
201-
return CRUSTLS_DEMO_ERROR;
201+
return DEMO_ERROR;
202202
}
203203
vec->data = newdata;
204204
vec->capacity = newsize;
205205
}
206-
return CRUSTLS_DEMO_OK;
206+
return DEMO_OK;
207207
}
208208

209209
/**
@@ -217,8 +217,8 @@ copy_plaintext_to_buffer(struct conndata *conn)
217217
size_t n;
218218
struct rustls_connection *rconn = conn->rconn;
219219

220-
if(bytevec_ensure_available(&conn->data, 1024) != CRUSTLS_DEMO_OK) {
221-
return CRUSTLS_DEMO_ERROR;
220+
if(bytevec_ensure_available(&conn->data, 1024) != DEMO_OK) {
221+
return DEMO_ERROR;
222222
}
223223

224224
for(;;) {
@@ -227,23 +227,23 @@ copy_plaintext_to_buffer(struct conndata *conn)
227227
result = rustls_connection_read(rconn, (uint8_t *)buf, avail, &n);
228228
if(result == RUSTLS_RESULT_PLAINTEXT_EMPTY) {
229229
/* This is expected. It just means "no more bytes for now." */
230-
return CRUSTLS_DEMO_OK;
230+
return DEMO_OK;
231231
}
232232
if(result != RUSTLS_RESULT_OK) {
233233
print_error(conn->program_name, "Error in rustls_connection_read", result);
234-
return CRUSTLS_DEMO_ERROR;
234+
return DEMO_ERROR;
235235
}
236236
if(n == 0) {
237237
fprintf(stderr, "got 0-byte read, cleanly ending connection\n");
238-
return CRUSTLS_DEMO_EOF;
238+
return DEMO_EOF;
239239
}
240240
bytevec_consume(&conn->data, n);
241-
if(bytevec_ensure_available(&conn->data, 1024) != CRUSTLS_DEMO_OK) {
242-
return CRUSTLS_DEMO_ERROR;
241+
if(bytevec_ensure_available(&conn->data, 1024) != DEMO_OK) {
242+
return DEMO_ERROR;
243243
}
244244
}
245245

246-
return CRUSTLS_DEMO_ERROR;
246+
return DEMO_ERROR;
247247
}
248248

249249
/**

tests/common.h

+11-11
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ const char * ws_strerror(int err);
2323
#endif /* !STDOUT_FILENO */
2424
#endif /* _WIN32 */
2525

26-
enum crustls_demo_result
26+
enum demo_result
2727
{
28-
CRUSTLS_DEMO_OK,
29-
CRUSTLS_DEMO_ERROR,
30-
CRUSTLS_DEMO_AGAIN,
31-
CRUSTLS_DEMO_EOF,
28+
DEMO_OK,
29+
DEMO_ERROR,
30+
DEMO_AGAIN,
31+
DEMO_EOF,
3232
};
3333

3434
/* A growable vector of bytes. */
@@ -53,7 +53,7 @@ int
5353
write_all(int fd, const char *buf, int n);
5454

5555
/* Make a socket nonblocking. */
56-
enum crustls_demo_result
56+
enum demo_result
5757
nonblock(int sockfd);
5858

5959
/* A callback that reads bytes from the network. */
@@ -88,17 +88,17 @@ bytevec_consume(struct bytevec *vec, size_t n);
8888

8989
/* Ensure there are at least n bytes available between vec->len and
9090
* vec->capacity. If this requires reallocating, this may return
91-
* CRUSTLS_DEMO_ERROR. */
92-
enum crustls_demo_result
91+
* DEMO_ERROR. */
92+
enum demo_result
9393
bytevec_ensure_available(struct bytevec *vec, size_t n);
9494

9595
/* Read all available bytes from the rustls_connection until EOF.
9696
* Note that EOF here indicates "no more bytes until
9797
* process_new_packets", not "stream is closed".
9898
*
99-
* Returns CRUSTLS_DEMO_OK for success,
100-
* CRUSTLS_DEMO_ERROR for error,
101-
* CRUSTLS_DEMO_EOF for "connection cleanly terminated by peer"
99+
* Returns DEMO_OK for success,
100+
* DEMO_ERROR for error,
101+
* DEMO_EOF for "connection cleanly terminated by peer"
102102
*/
103103
int
104104
copy_plaintext_to_buffer(struct conndata *conn);

0 commit comments

Comments
 (0)