Commit 5e3c66ce authored by Timothy B. Terriberry's avatar Timothy B. Terriberry

Move last few URL functions into http.c

This makes it easier to split http.c and friends into their own
 library.
This allows distributions to ship a libopusfile with generic Opus
 parsing support, and a libopusurl with http/https support.
Keeping the latter in a separate library means that GPL
 applications don't have to link against the GPL-incompatible
 openssl, and distributions don't have to disable http support to
 allow GPL applications to use libopusfile.
parent efc0d57a
......@@ -3220,3 +3220,51 @@ void *op_url_stream_create(OpusFileCallbacks *_cb,
va_end(ap);
return ret;
}
/*Convenience routines to open/test URLs in a single step.*/
OggOpusFile *op_vopen_url(const char *_url,int *_error,va_list _ap){
OpusFileCallbacks cb;
OggOpusFile *of;
void *source;
source=op_url_stream_vcreate(&cb,_url,_ap);
if(OP_UNLIKELY(source==NULL)){
if(_error!=NULL)*_error=OP_EFAULT;
return NULL;
}
of=op_open_callbacks(source,&cb,NULL,0,_error);
if(OP_UNLIKELY(of==NULL))(*cb.close)(source);
return of;
}
OggOpusFile *op_open_url(const char *_url,int *_error,...){
OggOpusFile *ret;
va_list ap;
va_start(ap,_error);
ret=op_vopen_url(_url,_error,ap);
va_end(ap);
return ret;
}
OggOpusFile *op_vtest_url(const char *_url,int *_error,va_list _ap){
OpusFileCallbacks cb;
OggOpusFile *of;
void *source;
source=op_url_stream_vcreate(&cb,_url,_ap);
if(OP_UNLIKELY(source==NULL)){
if(_error!=NULL)*_error=OP_EFAULT;
return NULL;
}
of=op_test_callbacks(source,&cb,NULL,0,_error);
if(OP_UNLIKELY(of==NULL))(*cb.close)(source);
return of;
}
OggOpusFile *op_test_url(const char *_url,int *_error,...){
OggOpusFile *ret;
va_list ap;
va_start(ap,_error);
ret=op_vtest_url(_url,_error,ap);
va_end(ap);
return ret;
}
......@@ -1611,21 +1611,6 @@ OggOpusFile *op_open_memory(const unsigned char *_data,size_t _size,
_error);
}
OggOpusFile *op_vopen_url(const char *_url,int *_error,va_list _ap){
OpusFileCallbacks cb;
return op_open_close_on_failure(op_url_stream_vcreate(&cb,_url,_ap),&cb,
_error);
}
OggOpusFile *op_open_url(const char *_url,int *_error,...){
OggOpusFile *ret;
va_list ap;
va_start(ap,_error);
ret=op_vopen_url(_url,_error,ap);
va_end(ap);
return ret;
}
/*Convenience routine to clean up from failure for the open functions that
create their own streams.*/
static OggOpusFile *op_test_close_on_failure(void *_source,
......@@ -1652,21 +1637,6 @@ OggOpusFile *op_test_memory(const unsigned char *_data,size_t _size,
_error);
}
OggOpusFile *op_vtest_url(const char *_url,int *_error,va_list _ap){
OpusFileCallbacks cb;
return op_test_close_on_failure(op_url_stream_vcreate(&cb,_url,_ap),&cb,
_error);
}
OggOpusFile *op_test_url(const char *_url,int *_error,...){
OggOpusFile *ret;
va_list ap;
va_start(ap,_error);
ret=op_vtest_url(_url,_error,ap);
va_end(ap);
return ret;
}
int op_test_open(OggOpusFile *_of){
int ret;
if(OP_UNLIKELY(_of->ready_state!=OP_PARTOPEN))return OP_EINVAL;
......
......@@ -5,6 +5,7 @@ TESTBINDIR = tests
TARGETLIBDIR = .
# Name of the targets
LIBOPUSFILE_TARGET = libopusfile.a
LIBOPUSURL_TARGET = libopusurl.a
OPUSFILE_EXAMPLE_TARGET = opusfile_example
SEEKING_EXAMPLE_TARGET = seeking_example
# Test targets
......@@ -70,11 +71,17 @@ internal.c \
opusfile.c \
stream.c \
LIBOPUSFILE_CHEADERS = \
internal.h \
LIBOPUSURL_CSOURCES = \
http.c \
ifneq ($(findstring mingw,${CC}),)
LIBOPUSFILE_CSOURCES += wincerts.c
LIBOPUSURL_CSOURCES += wincerts.c
endif
LIBOPUSFILE_CHEADERS = \
LIBOPUSURL_CHEADERS = \
internal.h \
OPUSFILE_EXAMPLE_CSOURCES = opusfile_example.c
......@@ -87,12 +94,16 @@ FOO_CSOURCES = tests/foo.c
LIBOPUSFILE_OBJS:= ${LIBOPUSFILE_CSOURCES:%.c=${WORKDIR}/%.o}
LIBOPUSFILE_ASMS:= ${LIBOPUSFILE_OBJS:%.o=%.s}
LIBOPUSFILE_DEPS:= ${LIBOPUSFILE_OBJS:%.o=%.d}
LIBOPUSURL_OBJS:= ${LIBOPUSURL_CSOURCES:%.c=${WORKDIR}/%.o}
LIBOPUSURL_ASMS:= ${LIBOPUSURL_OBJS:%.o=%.s}
LIBOPUSURL_DEPS:= ${LIBOPUSURL_OBJS:%.o=%.d}
OPUSFILE_EXAMPLE_OBJS:= ${OPUSFILE_EXAMPLE_CSOURCES:%.c=${WORKDIR}/%.o}
SEEKING_EXAMPLE_OBJS:= ${SEEKING_EXAMPLE_CSOURCES:%.c=${WORKDIR}/%.o}
#TODO: tests
FOO_OBJS:= ${FOO_CSOURCES:%.c=${WORKDIR}/%.o}
ALL_OBJS:= \
${LIBOPUSFILE_OBJS} \
${LIBOPUSURL_OBJS} \
${OPUSFILE_EXAMPLE_OBJS} \
${SEEKING_EXAMPLE_OBJS} \
......@@ -104,12 +115,15 @@ ALL_DEPS:= ${ALL_OBJS:%.o=%.d}
# Prepend source path to file names.
LIBOPUSFILE_CSOURCES:= ${LIBOPUSFILE_CSOURCES:%=${LIBSRCDIR}/%}
LIBOPUSFILE_CHEADERS:= ${LIBOPUSFILE_CHEADERS:%=${LIBSRCDIR}/%}
LIBOPUSURL_CSOURCES:= ${LIBOPUSURL_CSOURCES:%=${LIBSRCDIR}/%}
LIBOPUSURL_CHEADERS:= ${LIBOPUSURL_CHEADERS:%=${LIBSRCDIR}/%}
OPUSFILE_EXAMPLE_CSOURCES:= ${OPUSFILE_EXAMPLE_CSOURCES:%=${BINSRCDIR}/%}
SEEKING_EXAMPLE_CSOURCES:= ${SEEKING_EXAMPLE_CSOURCES:%=${BINSRCDIR}/%}
#TODO: tests
FOO_CSOURCES:= ${FOO_CSOURCES:%=${TESTSRCDIR}/%}
ALL_CSOURCES:= \
${LIBOPUSFILE_CSOURCES} \
${LIBOPUSURL_CSOURCES} \
${OPUSFILE_EXAMPLE_CSOURCES} \
${SEEKING_EXAMPLE_CSOURCES} \
......@@ -117,6 +131,7 @@ ALL_CSOURCES:= \
# ${FOO_CSOURCES} \
# Prepand target path to file names.
LIBOPUSFILE_TARGET:= ${TARGETLIBDIR}/${LIBOPUSFILE_TARGET}
LIBOPUSURL_TARGET:= ${TARGETLIBDIR}/${LIBOPUSURL_TARGET}
OPUSFILE_EXAMPLE_TARGET:= ${TARGETBINDIR}/${OPUSFILE_EXAMPLE_TARGET}${EXEEXT}
SEEKING_EXAMPLE_TARGET:= ${TARGETBINDIR}/${SEEKING_EXAMPLE_TARGET}${EXEEXT}
# Prepend test path to file names.
......@@ -125,6 +140,7 @@ FOO_TARGET:= ${TESTBINDIR}/${FOO_TARGET}
# Complete set of targets
ALL_TARGETS:= \
${LIBOPUSFILE_TARGET} \
${LIBOPUSURL_TARGET} \
${OPUSFILE_EXAMPLE_TARGET} \
${SEEKING_EXAMPLE_TARGET} \
......@@ -141,17 +157,25 @@ ${LIBOPUSFILE_TARGET}: ${LIBOPUSFILE_OBJS}
$(AR) cqs $@ ${LIBOPUSFILE_OBJS}
-$(RANLIB) $@
# libopusurl
${LIBOPUSURL_TARGET}: ${LIBOPUSURL_OBJS}
mkdir -p ${TARGETLIBDIR}
$(AR) cqs $@ ${LIBOPUSURL_OBJS}
-$(RANLIB) $@
# opusfile_example
${OPUSFILE_EXAMPLE_TARGET}: ${OPUSFILE_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET}
${OPUSFILE_EXAMPLE_TARGET}: ${OPUSFILE_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET} \
${LIBOPUSURL_TARGET}
mkdir -p ${TARGETBINDIR}
${CC} ${CFLAGS} ${OPUSFILE_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET} ${LIBS} \
-o $@
${CC} ${CFLAGS} ${OPUSFILE_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET} \
${LIBOPUSURL_TARGET} ${LIBS} -o $@
# seeking_example
${SEEKING_EXAMPLE_TARGET}: ${SEEKING_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET}
${SEEKING_EXAMPLE_TARGET}: ${SEEKING_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET} \
${LIBOPUSURL_TARGET}
mkdir -p ${TARGETBINDIR}
${CC} ${CFLAGS} ${SEEKING_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET} ${LIBS} \
-o $@
${CC} ${CFLAGS} ${SEEKING_EXAMPLE_OBJS} ${LIBOPUSFILE_TARGET} \
${LIBOPUSURL_TARGET} ${LIBS} -o $@
#TODO:
#tests: foo
......
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