A helper function for dealing with NPN in client side or ALPN in
server side. The |input| contains peer's protocol list in preferable
order. The format of |input| is length-prefixed and not
null-terminated. For example, HTTP-draft-04/2.0 and
http/1.1 stored in |input| like this::
A helper function for dealing with NPN in client side or ALPN in server side. The |input| contains peer's protocol list in preferable order. The format of |input| is length-prefixed and not null-terminated. For example, HTTP-draft-04/2.0 and http/1.1 stored in |input| like this::
in[0] = 17 in[1..17] = "HTTP-draft-04/2.0" in[18] = 8 in[19..26] = "http/1.1" inlen = 27
The selection algorithm is as follows:
1. If peer's list contains HTTP/2 protocol the library supports, it is selected and returns 1. The following step is not taken.
2. If peer's list contains http/1.1, this function selects http/1.1 and returns 0. The following step is not taken.
3. This function selects nothing and returns -1 (So called non-overlap case). In this case, |output| is left untouched.
Selecting HTTP-draft-04/2.0 means that HTTP-draft-04/2.0 is written into |*out| and its length (which is 17) is assigned to |*outlen|.
For ALPN, refer to https://tools.ietf.org/html/draft-ietf-tls-applayerprotoneg-05
See http://technotes.googlecode.com/git/nextprotoneg.html for more details about NPN.
For NPN, to use this method you should do something like::
static int select_next_proto_cb(SSL* ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg) { int rv; rv = selectNextProtocol(out, outlen, in, inlen); if(rv == 1) { (cast(MyType*)arg).http2_selected = 1; } return SSL_TLSEXT_ERR_OK; } ... SSL_CTX_set_next_proto_select_cb(ssl_ctx, select_next_proto_cb, my_obj);