Use libstrophe base64 support

Use the base64 interface in libstrophe for encoding/decoding instead of
the undocumented interfaces in libresolv.
master
Michael Santos 7 years ago
parent e28f208103
commit fa2ebb799d

@ -5,7 +5,7 @@ RM=rm
UNAME_SYS := $(shell uname -s)
ifeq ($(UNAME_SYS), Linux)
LDFLAGS += -lresolv -Wl,-Bsymbolic-functions -Wl,-z,relro
LDFLAGS += -Wl,-Bsymbolic-functions -Wl,-z,relro
CFLAGS ?= -D_FORTIFY_SOURCE=2 -O2 -fstack-protector \
--param=ssp-buffer-size=4 -Wformat -Werror=format-security \
-fno-strict-aliasing
@ -24,9 +24,7 @@ else ifeq ($(UNAME_SYS), OpenBSD)
--param=ssp-buffer-size=4 -Wformat -Werror=format-security \
-fno-strict-aliasing
else ifeq ($(UNAME_SYS), SunOS)
LDFLAGS += -lresolv
else ifeq ($(UNAME_SYS), Darwin)
LDFLAGS += -lresolv
endif
XMPPIPE_SANDBOX ?= XMPPIPE_SANDBOX_RLIMIT
@ -46,7 +44,7 @@ $(PROG):
static:
$(CC) $(CFLAGS) -g -Wall -o xmppipe src/*.c -Wl,--no-as-needed \
-ldl -lz -lresolv \
-ldl -lz \
/usr/local/lib/libstrophe.a \
/usr/lib/*/libssl.a \
/usr/lib/*/libcrypto.a \

@ -1024,17 +1024,19 @@ handle_message(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
return 1;
if (state->encode) {
/* Does not need to be NULL terminated, buf is passed with length */
size_t len = strlen(message) * 3 / 4;
char *buf = xmppipe_calloc(len, 1);
int n = b64_pton(message, (u_char *)buf, len);
if (n <= 0 || n > len) {
size_t len = strlen(message);
unsigned char *buf = NULL;
size_t n = 0;
xmpp_base64_decode_bin(state->ctx, message, len, &buf, &n);
if (buf == NULL) {
/* Not a base64 message */
free(buf);
return 1;
}
emessage = xmppipe_nfmt(buf,n);
free(buf);
emessage = xmppipe_nfmt((char *)buf,n);
xmpp_free(state->ctx, buf);
}
else {
emessage = xmppipe_fmt(message);
@ -1168,12 +1170,14 @@ xmppipe_send_message(xmppipe_state_t *state, char *to, char *type, char *buf,
text = xmppipe_stanza_new(state->ctx);
if (state->encode) {
size_t b64len = BASE64_LENGTH(len) + 1; /* Include trailing NULL */
char *b64 = xmppipe_calloc(b64len, 1);
if (b64_ntop((u_char *)buf, len, b64, b64len) < 0)
errx(EXIT_FAILURE, "encode: invalid input: %zu/%zu", len, b64len);
size_t len = strlen(buf);
char *b64 = xmpp_base64_encode(state->ctx, (unsigned char *)buf, len);
if (b64 == NULL)
errx(EXIT_FAILURE, "encode: invalid input: %zu", len);
xmppipe_stanza_set_text(text, b64);
free(b64);
xmpp_free(state->ctx, b64);
}
else {
xmppipe_stanza_set_text(text, buf);

Loading…
Cancel
Save