diff options
author | Ben Laurie <ben@openssl.org> | 2010-07-28 10:06:55 +0000 |
---|---|---|
committer | Ben Laurie <ben@openssl.org> | 2010-07-28 10:06:55 +0000 |
commit | ee2ffc279417f15fef3b1073c7dc81a908991516 (patch) | |
tree | e2af21f279101d5a8f8e841bf7f70b940496907f /apps/apps.c | |
parent | b122e482f94f1dbda6a93b4c53ccdc92b4046deb (diff) | |
download | openssl-ee2ffc279417f15fef3b1073c7dc81a908991516.tar.gz |
Add Next Protocol Negotiation.
Diffstat (limited to 'apps/apps.c')
-rw-r--r-- | apps/apps.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/apps/apps.c b/apps/apps.c index 3a3009d473..5bd19c5d01 100644 --- a/apps/apps.c +++ b/apps/apps.c @@ -3031,3 +3031,46 @@ int raw_write_stdout(const void *buf,int siz) int raw_write_stdout(const void *buf,int siz) { return write(fileno(stdout),buf,siz); } #endif + +#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NPN) +/* next_protos_parse parses a comma separated list of strings into a string + * in a format suitable for passing to SSL_CTX_set_next_protos_advertised. + * outlen: (output) set to the length of the resulting buffer on success. + * in: a NUL termianted string like "abc,def,ghi" + * + * returns: a malloced buffer or NULL on failure. + */ +unsigned char *next_protos_parse(unsigned short *outlen, const char *in) + { + size_t len; + unsigned char *out; + size_t i, start = 0; + + len = strlen(in); + if (len > 65535) + return NULL; + + out = OPENSSL_malloc(strlen(in) + 1); + if (!out) + return NULL; + + for (i = 0; i <= len; ++i) + { + if (i == len || in[i] == ',') + { + if (i - start > 255) + { + OPENSSL_free(out); + return NULL; + } + out[start] = i - start; + start = i + 1; + } + else + out[i+1] = in[i]; + } + + *outlen = len + 1; + return out; + } +#endif /* !OPENSSL_NO_TLSEXT && !OPENSSL_NO_NPN */ |