diff options
author | Andy Green <andy@warmcat.com> | 2019-06-19 19:10:14 +0100 |
---|---|---|
committer | Andy Green <andy@warmcat.com> | 2019-06-19 19:10:14 +0100 |
commit | a72b422be3a6f5e290a18f7069ef7554c34bca66 (patch) | |
tree | 8e673d7930fc523e7fa1368380ec8ab1d5e7c82f /minimal-examples/api-tests | |
parent | 5462529bcc10060ef4b959b2181da335ed9a7f71 (diff) | |
download | libwebsockets-a72b422be3a6f5e290a18f7069ef7554c34bca66.tar.gz |
abstract: add abstract transport tokens
SMTP was improved to use the new abstract stuff a while ago,
but it was only implemented with raw socket abstract transport,
and a couple of 'api cheats' remained passing network information
for the peer connection through the supposedly abstract apis.
This patch adds a flexible generic token array to supply
abstract transport-specific information through the abstract apis,
removing the network information from the abstract connect() op.
The SMTP minimal example is modified to use this new method to
pass the network information.
The abstract transport struct was opaque, but there are real
uses to override it in user code, so this patch also makes it
part of the public abi.
Diffstat (limited to 'minimal-examples/api-tests')
-rw-r--r-- | minimal-examples/api-tests/api-test-smtp_client/main.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/minimal-examples/api-tests/api-test-smtp_client/main.c b/minimal-examples/api-tests/api-test-smtp_client/main.c index 4ba79f82..109350f9 100644 --- a/minimal-examples/api-tests/api-test-smtp_client/main.c +++ b/minimal-examples/api-tests/api-test-smtp_client/main.c @@ -9,6 +9,8 @@ #include <libwebsockets.h> +#include <signal.h> + static int interrupted, result = 1; static const char *recip; @@ -37,6 +39,21 @@ email_sent_or_failed(struct lws_smtp_email *email, void *buf, size_t len) return 0; } +/* + * We're going to bind to the raw-skt transport, so tell that what we want it + * to connect to + */ + +static const lws_token_map_t smtp_abs_tokens[] = { +{ + .u = { .value = "127.0.0.1" }, + .name_index = LTMI_PEER_DNS_ADDRESS, +}, { + .u = { .lvalue = 25l }, + .name_index = LTMI_PEER_PORT, +}}; + + int main(int argc, const char **argv) { int n = 1, logs = LLL_USER | LLL_ERR | LLL_WARN | LLL_NOTICE; @@ -84,10 +101,12 @@ int main(int argc, const char **argv) /* create the smtp client */ memset(&sci, 0, sizeof(sci)); - sci.data = NULL /* stmp client specific user data */; + sci.data = NULL; /* stmp client specific user data */ sci.abs = lws_abstract_get_by_name("raw_skt"); + /* tell raw_skt transport what we want it to do */ + sci.abs_tokens = smtp_abs_tokens; sci.vh = vh; - lws_strncpy(sci.ip, "127.0.0.1", sizeof(sci.ip)); + lws_strncpy(sci.helo, "lws-test-client", sizeof(sci.helo)); smtpc = lws_smtp_client_create(&sci); |