Commit 800be8c0 authored by Timothy B. Terriberry's avatar Timothy B. Terriberry

Make the URL API more extensible.

Right now we have no way to add any more parameters beyond a set of
 basic binary flags.
This unifies op_url_stream_create() and
 op_url_stream_create_with_proxy() into a single function that
 takes a variable-length list of arguments, which can be extended
 in the future to include more options of any type.

This is an incompatible API change.
parent 756c4c0b
......@@ -126,7 +126,7 @@ int main(int _argc,const char **_argv){
}
else{
/*Try to treat the argument as a URL.*/
of=op_open_url(_argv[1],OP_SSL_SKIP_CERTIFICATE_CHECK,&ret);
of=op_open_url(_argv[1],&ret,OP_SSL_SKIP_CERTIFICATE_CHECK(1),NULL);
#if 0
if(of==NULL){
OpusFileCallbacks cb={NULL,NULL,NULL,NULL};
......
......@@ -275,7 +275,8 @@ int main(int _argc,const char **_argv){
if(strcmp(_argv[1],"-")==0)fp=op_fdopen(&cb,fileno(stdin),"rb");
else{
/*Try to treat the argument as a URL.*/
fp=op_url_stream_create(&cb,_argv[1],OP_SSL_SKIP_CERTIFICATE_CHECK);
fp=op_url_stream_create(&cb,_argv[1],
OP_SSL_SKIP_CERTIFICATE_CHECK(1),NULL);
/*Fall back assuming it's a regular file name.*/
if(fp==NULL)fp=op_fopen(&cb,_argv[1],"rb");
}
......
This diff is collapsed.
......@@ -1725,7 +1725,7 @@ static int op_http_allow_pipelining(const char *_server){
}
static int op_http_stream_open(OpusHTTPStream *_stream,const char *_url,
int _flags,const char *_proxy_host,unsigned _proxy_port,
int _skip_certificate_check,const char *_proxy_host,unsigned _proxy_port,
const char *_proxy_user,const char *_proxy_pass){
struct addrinfo *addrs;
const char *last_host;
......@@ -1792,7 +1792,7 @@ static int op_http_stream_open(OpusHTTPStream *_stream,const char *_url,
# endif
ssl_ctx=SSL_CTX_new(SSLv23_client_method());
if(ssl_ctx==NULL)return OP_EFAULT;
if(!(_flags&OP_SSL_SKIP_CERTIFICATE_CHECK)){
if(!_skip_certificate_check){
SSL_CTX_set_verify(ssl_ctx,SSL_VERIFY_PEER,NULL);
}
_stream->ssl_ctx=ssl_ctx;
......@@ -2705,8 +2705,11 @@ static const OpusFileCallbacks OP_HTTP_CALLBACKS={
};
#endif
void *op_url_stream_create_with_proxy(OpusFileCallbacks *_cb,const char *_url,
int _flags,const char *_proxy_host,unsigned _proxy_port,
/*The actual URL stream creation function.
This one isn't extensible like the application-level interface, but because
it isn't public, we're free to change it in the future.*/
static void *op_url_stream_create_impl(OpusFileCallbacks *_cb,const char *_url,
int _skip_certificate_check,const char *_proxy_host,unsigned _proxy_port,
const char *_proxy_user,const char *_proxy_pass){
const char *path;
/*Check to see if this is a valid file: URL.*/
......@@ -2728,7 +2731,7 @@ void *op_url_stream_create_with_proxy(OpusFileCallbacks *_cb,const char *_url,
stream=(OpusHTTPStream *)_ogg_malloc(sizeof(*stream));
if(OP_UNLIKELY(stream==NULL))return NULL;
op_http_stream_init(stream);
ret=op_http_stream_open(stream,_url,_flags,
ret=op_http_stream_open(stream,_url,_skip_certificate_check,
_proxy_host,_proxy_port,_proxy_user,_proxy_pass);
if(OP_UNLIKELY(ret<0)){
op_http_stream_clear(stream);
......@@ -2739,7 +2742,7 @@ void *op_url_stream_create_with_proxy(OpusFileCallbacks *_cb,const char *_url,
return stream;
}
#else
(void)_flags;
(void)_skip_certificate_check;
(void)_proxy_host;
(void)_proxy_port;
(void)_proxy_user;
......@@ -2748,6 +2751,51 @@ void *op_url_stream_create_with_proxy(OpusFileCallbacks *_cb,const char *_url,
#endif
}
void *op_url_stream_create(OpusFileCallbacks *_cb,const char *_url,int _flags){
return op_url_stream_create_with_proxy(_cb,_url,_flags,NULL,0,NULL,NULL);
void *op_url_stream_vcreate(OpusFileCallbacks *_cb,
const char *_url,va_list _ap){
int skip_certificate_check;
const char *proxy_host;
opus_int32 proxy_port;
const char *proxy_user;
const char *proxy_pass;
skip_certificate_check=0;
proxy_host=NULL;
proxy_port=8080;
proxy_user=NULL;
proxy_pass=NULL;
for(;;){
ptrdiff_t request;
request=va_arg(_ap,char *)-(char *)NULL;
/*If we hit NULL, we're done processing options.*/
if(!request)break;
switch(request){
case OP_SSL_SKIP_CERTIFICATE_CHECK_REQUEST:{
skip_certificate_check=!!va_arg(_ap,opus_int32);
}break;
case OP_HTTP_PROXY_HOST_REQUEST:{
proxy_host=va_arg(_ap,const char *);
}break;
case OP_HTTP_PROXY_PORT_REQUEST:{
proxy_port=va_arg(_ap,opus_int32);
if(proxy_port<0||proxy_port>(opus_int32)65535)return NULL;
}break;
case OP_HTTP_PROXY_USER_REQUEST:{
proxy_user=va_arg(_ap,const char *);
}break;
case OP_HTTP_PROXY_PASS_REQUEST:{
proxy_pass=va_arg(_ap,const char *);
}break;
/*Some unknown option.*/
default:return NULL;
}
}
return op_url_stream_create_impl(_cb,_url,skip_certificate_check,
proxy_host,proxy_port,proxy_user,proxy_pass);
}
void *op_url_stream_create(OpusFileCallbacks *_cb,
const char *_url,...){
va_list ap;
va_start(ap,_url);
return op_url_stream_vcreate(_cb,_url,ap);
}
......@@ -1469,18 +1469,16 @@ OggOpusFile *op_open_memory(const unsigned char *_data,size_t _size,
_error);
}
OggOpusFile *op_open_url(const char *_url,int _flags,int *_error){
OggOpusFile *op_vopen_url(const char *_url,int *_error,va_list _ap){
OpusFileCallbacks cb;
return op_open_close_on_failure(
op_url_stream_create(&cb,_url,_flags),&cb,_error);
return op_open_close_on_failure(op_url_stream_vcreate(&cb,_url,_ap),&cb,
_error);
}
OggOpusFile *op_open_url_with_proxy(const char *_url,int _flags,
const char *_proxy_host,unsigned _proxy_port,
const char *_proxy_user,const char *_proxy_pass,int *_error){
OpusFileCallbacks cb;
return op_open_close_on_failure(op_url_stream_create_with_proxy(&cb,_url,
_flags,_proxy_host,_proxy_port,_proxy_pass,_proxy_user),&cb,_error);
OggOpusFile *op_open_url(const char *_url,int *_error,...){
va_list ap;
va_start(ap,_error);
return op_vopen_url(_url,_error,ap);
}
/*Convenience routine to clean up from failure for the open functions that
......@@ -1509,18 +1507,16 @@ OggOpusFile *op_test_memory(const unsigned char *_data,size_t _size,
_error);
}
OggOpusFile *op_test_url(const char *_url,int _flags,int *_error){
OggOpusFile *op_vtest_url(const char *_url,int *_error,va_list _ap){
OpusFileCallbacks cb;
return op_test_close_on_failure(
op_url_stream_create(&cb,_url,_flags),&cb,_error);
return op_test_close_on_failure(op_url_stream_vcreate(&cb,_url,_ap),&cb,
_error);
}
OggOpusFile *op_test_url_with_proxy(const char *_url,int _flags,
const char *_proxy_host,unsigned _proxy_port,
const char *_proxy_user,const char *_proxy_pass,int *_error){
OpusFileCallbacks cb;
return op_test_close_on_failure(op_url_stream_create_with_proxy(&cb,_url,
_flags,_proxy_host,_proxy_port,_proxy_pass,_proxy_user),&cb,_error);
OggOpusFile *op_test_url(const char *_url,int *_error,...){
va_list ap;
va_start(ap,_error);
return op_vtest_url(_url,_error,ap);
}
int op_test_open(OggOpusFile *_of){
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment