Skip to content

Commit 7162d05

Browse files
committed
upipe_http_src_test: add HTTPS support
1 parent d597125 commit 7162d05

File tree

2 files changed

+124
-13
lines changed

2 files changed

+124
-13
lines changed

tests/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,10 @@ upipe_auto_inner_test_LDADD = $(LDADD) $(top_builddir)/lib/upipe-modules/libupip
598598
upipe_dtsdi_test_LDADD = $(LDADD) $(EV_LIBS) $(top_builddir)/lib/upump-ev/libupump_ev.la $(top_builddir)/lib/upipe-modules/libupipe_modules.la
599599
upipe_auto_source_test_LDADD = $(LDADD) -lev $(top_builddir)/lib/upump-ev/libupump_ev.la $(top_builddir)/lib/upipe-modules/libupipe_modules.la
600600
if HAVE_BEARSSL
601+
upipe_http_src_test_LDADD += $(top_builddir)/lib/upipe-bearssl/libupipe_bearssl.la
601602
upipe_auto_source_test_LDADD += $(top_builddir)/lib/upipe-bearssl/libupipe_bearssl.la
602603
endif
603604
if HAVE_OPENSSL
605+
upipe_http_src_test_LDADD += $(top_builddir)/lib/upipe-openssl/libupipe_openssl.la
604606
upipe_auto_source_test_LDADD += $(top_builddir)/lib/upipe-openssl/libupipe_openssl.la
605607
endif

tests/upipe_http_src_test.c

Lines changed: 122 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
#undef NDEBUG
3131

32+
#include "upipe/config.h"
3233
#include "upipe/uprobe.h"
3334
#include "upipe/uprobe_stdio.h"
3435
#include "upipe/uprobe_prefix.h"
@@ -48,18 +49,26 @@
4849
#include "upipe/upipe.h"
4950
#include "upipe-modules/upipe_http_source.h"
5051
#include "upipe-modules/upipe_null.h"
52+
#ifdef UPIPE_HAVE_BEARSSL_H
53+
#include "upipe-bearssl/uprobe_https_bearssl.h"
54+
#endif
55+
#ifdef UPIPE_HAVE_OPENSSL_SSL_H
56+
#include "upipe-openssl/uprobe_https_openssl.h"
57+
#endif
5158

5259
#include <stdlib.h>
5360
#include <stdio.h>
5461
#include <assert.h>
62+
#include <getopt.h>
5563

5664
#define UDICT_POOL_DEPTH 10
5765
#define UREF_POOL_DEPTH 10
5866
#define UBUF_POOL_DEPTH 10
5967
#define UPUMP_POOL 1
6068
#define UPUMP_BLOCKER_POOL 1
6169
#define READ_SIZE 4096
62-
#define UPROBE_LOG_LEVEL UPROBE_LOG_DEBUG
70+
71+
static int log_level = UPROBE_LOG_NOTICE;
6372

6473
/** definition of our uprobe */
6574
static int catch(struct uprobe *uprobe, struct upipe *upipe,
@@ -72,20 +81,109 @@ static int catch(struct uprobe *uprobe, struct upipe *upipe,
7281
case UPROBE_READY:
7382
case UPROBE_DEAD:
7483
case UPROBE_SOURCE_END:
84+
case UPROBE_NEW_FLOW_DEF:
7585
break;
7686
}
7787
return UBASE_ERR_NONE;
7888
}
7989

90+
enum opt {
91+
OPT_HELP = 'h',
92+
OPT_VERBOSE = 'v',
93+
OPT_QUIET = 'q',
94+
OPT_USE_BEARSSL = 0x100,
95+
OPT_USE_OPENSSL,
96+
};
97+
98+
static struct option options[] = {
99+
{ "help", no_argument, NULL, OPT_HELP },
100+
{ "verbose", no_argument, NULL, OPT_VERBOSE },
101+
{ "quiet", no_argument, NULL, OPT_QUIET },
102+
{ "use-bearssl", no_argument, NULL, OPT_USE_BEARSSL },
103+
{ "use-openssl", no_argument, NULL, OPT_USE_OPENSSL },
104+
{ 0, 0, 0, 0 },
105+
};
106+
107+
static int usage(const char *name)
108+
{
109+
fprintf(stdout, "Usage: %s [options] <url>\n", name);
110+
for (int i = 0; options[i].name; i++) {
111+
if (options[i].val < 0x100) {
112+
fprintf(stdout, " -%c, --%s\n", options[i].val, options[i].name);
113+
} else {
114+
fprintf(stdout, " --%s\n", options[i].name);
115+
}
116+
}
117+
return 0;
118+
}
119+
80120
int main(int argc, char *argv[])
81121
{
82122
const char *url;
123+
int opt;
124+
int index;
125+
#ifdef UPIPE_HAVE_BEARSSL_H
126+
bool use_bearssl = true;
127+
#endif
128+
#ifdef UPIPE_HAVE_OPENSSL_SSL_H
129+
bool use_openssl = true;
130+
#endif
131+
132+
/*
133+
* parse options
134+
*/
135+
while ((opt = getopt_long(argc, argv, "hvq", options, &index)) != -1) {
136+
switch (opt) {
137+
case OPT_HELP:
138+
usage(argv[0]);
139+
exit(EXIT_SUCCESS);
140+
return 0;
141+
142+
case OPT_VERBOSE:
143+
if (log_level > UPROBE_LOG_VERBOSE)
144+
log_level--;
145+
break;
146+
147+
case OPT_QUIET:
148+
if (log_level < UPROBE_LOG_ERROR)
149+
log_level++;
150+
break;
83151

84-
if (argc < 2) {
85-
fprintf(stdout, "Usage: %s <url>\n", argv[0]);
152+
#ifdef UPIPE_HAVE_BEARSSL_H
153+
case OPT_USE_BEARSSL:
154+
use_bearssl = true;
155+
#ifdef UPIPE_HAVE_OPENSSL_SSL_H
156+
use_openssl = false;
157+
#endif
158+
break;
159+
#endif
160+
161+
#ifdef UPIPE_HAVE_OPENSSL_SSL_H
162+
case OPT_USE_OPENSSL:
163+
use_openssl = true;
164+
#ifdef UPIPE_HAVE_BEARSSL_H
165+
use_bearssl = false;
166+
#endif
167+
break;
168+
#endif
169+
170+
case -1:
171+
break;
172+
173+
default:
174+
abort();
175+
}
176+
}
177+
178+
/*
179+
* parse arguments
180+
*/
181+
if (optind >= argc) {
182+
usage(argv[0]);
86183
exit(EXIT_FAILURE);
184+
return -1;
87185
}
88-
url = argv[1];
186+
url = argv[optind];
89187

90188
struct umem_mgr *umem_mgr = umem_alloc_mgr_alloc();
91189
assert(umem_mgr != NULL);
@@ -102,31 +200,42 @@ int main(int argc, char *argv[])
102200
assert(uclock != NULL);
103201
struct uprobe uprobe;
104202
uprobe_init(&uprobe, catch, NULL);
105-
struct uprobe *logger = uprobe_stdio_alloc(&uprobe, stdout,
106-
UPROBE_LOG_LEVEL);
203+
struct uprobe *logger = uprobe_stdio_alloc(&uprobe, stdout, log_level);
107204
assert(logger != NULL);
108205
logger = uprobe_uref_mgr_alloc(logger, uref_mgr);
109206
assert(logger != NULL);
110207
logger = uprobe_upump_mgr_alloc(logger, upump_mgr);
111208
assert(logger != NULL);
209+
#ifdef UPIPE_HAVE_BEARSSL_H
210+
if (use_bearssl) {
211+
logger = uprobe_https_bearssl_alloc(logger);
212+
assert(logger);
213+
}
214+
#endif
215+
216+
#ifdef UPIPE_HAVE_OPENSSL_SSL_H
217+
if (use_openssl) {
218+
logger = uprobe_https_openssl_alloc(logger);
219+
assert(logger);
220+
}
221+
#endif
222+
112223
logger = uprobe_ubuf_mem_alloc(logger, umem_mgr, UBUF_POOL_DEPTH,
113224
UBUF_POOL_DEPTH);
114225
assert(logger != NULL);
115226

116227
struct upipe_mgr *upipe_null_mgr = upipe_null_mgr_alloc();
117228
struct upipe *upipe_null = upipe_void_alloc(upipe_null_mgr,
118-
uprobe_pfx_alloc(uprobe_use(logger), UPROBE_LOG_LEVEL,
119-
"null"));
229+
uprobe_pfx_alloc(uprobe_use(logger), log_level, "null"));
120230

121231
struct upipe_mgr *upipe_http_src_mgr = upipe_http_src_mgr_alloc();
122232
assert(upipe_http_src_mgr != NULL);
123233
struct upipe *upipe_http_src = upipe_void_alloc(upipe_http_src_mgr,
124-
uprobe_pfx_alloc(uprobe_use(logger), UPROBE_LOG_LEVEL,
125-
"http"));
234+
uprobe_pfx_alloc(uprobe_use(logger), log_level, "http"));
126235
assert(upipe_http_src != NULL);
127-
assert(upipe_set_output_size(upipe_http_src, READ_SIZE));
128-
assert(upipe_set_uri(upipe_http_src, url));
129-
assert(upipe_set_output(upipe_http_src, upipe_null));
236+
ubase_assert(upipe_set_output_size(upipe_http_src, READ_SIZE));
237+
ubase_assert(upipe_set_uri(upipe_http_src, url));
238+
ubase_assert(upipe_set_output(upipe_http_src, upipe_null));
130239
upipe_release(upipe_null);
131240

132241
upump_mgr_run(upump_mgr, NULL);

0 commit comments

Comments
 (0)