|
33 | 33 | #include "gopher.h" |
34 | 34 | #include "select.h" |
35 | 35 | #include "strdup.h" |
| 36 | +#include "vtls/vtls.h" |
36 | 37 | #include "url.h" |
37 | 38 | #include "escape.h" |
38 | 39 | #include "warnless.h" |
|
46 | 47 | */ |
47 | 48 |
|
48 | 49 | static CURLcode gopher_do(struct connectdata *conn, bool *done); |
| 50 | +#ifdef USE_SSL |
| 51 | +static CURLcode gopher_connect(struct connectdata *conn, bool *done); |
| 52 | +static CURLcode gopher_connecting(struct connectdata *conn, bool *done); |
| 53 | +#endif |
49 | 54 |
|
50 | 55 | /* |
51 | 56 | * Gopher protocol handler. |
@@ -75,6 +80,46 @@ const struct Curl_handler Curl_handler_gopher = { |
75 | 80 | PROTOPT_NONE /* flags */ |
76 | 81 | }; |
77 | 82 |
|
| 83 | +#ifdef USE_SSL |
| 84 | +const struct Curl_handler Curl_handler_gophers = { |
| 85 | + "GOPHERS", /* scheme */ |
| 86 | + ZERO_NULL, /* setup_connection */ |
| 87 | + gopher_do, /* do_it */ |
| 88 | + ZERO_NULL, /* done */ |
| 89 | + ZERO_NULL, /* do_more */ |
| 90 | + gopher_connect, /* connect_it */ |
| 91 | + gopher_connecting, /* connecting */ |
| 92 | + ZERO_NULL, /* doing */ |
| 93 | + ZERO_NULL, /* proto_getsock */ |
| 94 | + ZERO_NULL, /* doing_getsock */ |
| 95 | + ZERO_NULL, /* domore_getsock */ |
| 96 | + ZERO_NULL, /* perform_getsock */ |
| 97 | + ZERO_NULL, /* disconnect */ |
| 98 | + ZERO_NULL, /* readwrite */ |
| 99 | + ZERO_NULL, /* connection_check */ |
| 100 | + PORT_GOPHER, /* defport */ |
| 101 | + CURLPROTO_GOPHER, /* protocol */ |
| 102 | + CURLPROTO_GOPHER, /* family */ |
| 103 | + PROTOPT_SSL /* flags */ |
| 104 | +}; |
| 105 | + |
| 106 | +static CURLcode gopher_connect(struct connectdata *conn, bool *done) |
| 107 | +{ |
| 108 | + (void)conn; |
| 109 | + (void)done; |
| 110 | + return CURLE_OK; |
| 111 | +} |
| 112 | + |
| 113 | +static CURLcode gopher_connecting(struct connectdata *conn, bool *done) |
| 114 | +{ |
| 115 | + CURLcode result = Curl_ssl_connect(conn, FIRSTSOCKET); |
| 116 | + if(result) |
| 117 | + connclose(conn, "Failed TLS connection"); |
| 118 | + *done = TRUE; |
| 119 | + return result; |
| 120 | +} |
| 121 | +#endif |
| 122 | + |
78 | 123 | static CURLcode gopher_do(struct connectdata *conn, bool *done) |
79 | 124 | { |
80 | 125 | CURLcode result = CURLE_OK; |
@@ -127,6 +172,11 @@ static CURLcode gopher_do(struct connectdata *conn, bool *done) |
127 | 172 | k = curlx_uztosz(len); |
128 | 173 |
|
129 | 174 | for(;;) { |
| 175 | + /* Break out of the loop if the selector is empty because OpenSSL and/or |
| 176 | + LibreSSL fail with errno 0 if this is the case. */ |
| 177 | + if(strlen(sel) < 1) |
| 178 | + break; |
| 179 | + |
130 | 180 | result = Curl_write(conn, sockfd, sel, k, &amount); |
131 | 181 | if(!result) { /* Which may not have written it all! */ |
132 | 182 | result = Curl_client_write(conn, CLIENTWRITE_HEADER, sel, amount); |
|
0 commit comments