From fc6ba89c611c4afdf62816753b5c3749cd0ef85a Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Thu, 3 Mar 2022 21:34:07 +0100 Subject: [PATCH] properly rename internal `[v]snprintf()` functions Otherwise it clashes when we want to re-introduce the `xmpp_` prefix'ed versions. Signed-off-by: Steffen Jaeckel --- src/auth.c | 4 ++-- src/conn.c | 4 ++-- src/crypto.c | 2 +- src/ctx.c | 4 ++-- src/resolver.c | 8 ++++---- src/sasl.c | 6 +++--- src/snprintf.c | 4 ++-- src/snprintf.h | 6 ++---- src/sock.c | 2 +- src/stanza.c | 12 ++++++------ src/tls_gnutls.c | 2 +- src/tls_openssl.c | 2 +- tests/test_rand.c | 2 +- tests/test_snprintf.c | 4 ++-- 14 files changed, 30 insertions(+), 32 deletions(-) diff --git a/src/auth.c b/src/auth.c index 7bb05b9..eaaf3cc 100644 --- a/src/auth.c +++ b/src/auth.c @@ -540,7 +540,7 @@ static char *_make_scram_init_msg(xmpp_conn_t *conn) message_len = strlen(node) + strlen(nonce) + 8 + 1; message = strophe_alloc(ctx, message_len); if (message) { - xmpp_snprintf(message, message_len, "n,,n=%s,r=%s", node, nonce); + strophe_snprintf(message, message_len, "n,,n=%s,r=%s", node, nonce); } strophe_free(ctx, node); @@ -1298,7 +1298,7 @@ int _handle_component_auth(xmpp_conn_t *conn) if (digest) { /* convert the digest into string representation */ for (i = 0; i < sizeof(md_value); i++) - xmpp_snprintf(digest + i * 2, 3, "%02x", md_value[i]); + strophe_snprintf(digest + i * 2, 3, "%02x", md_value[i]); digest[2 * sizeof(md_value)] = '\0'; strophe_debug(conn->ctx, "auth", "Digest: %s, len: %d", digest, diff --git a/src/conn.c b/src/conn.c index 7e5ff58..af22498 100644 --- a/src/conn.c +++ b/src/conn.c @@ -919,7 +919,7 @@ void xmpp_send_raw_string(xmpp_conn_t *conn, const char *fmt, ...) return; va_start(ap, fmt); - len = xmpp_vsnprintf(buf, sizeof(buf), fmt, ap); + len = strophe_vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); if (len >= sizeof(buf)) { @@ -933,7 +933,7 @@ void xmpp_send_raw_string(xmpp_conn_t *conn, const char *fmt, ...) return; } va_start(ap, fmt); - xmpp_vsnprintf(bigbuf, len, fmt, ap); + strophe_vsnprintf(bigbuf, len, fmt, ap); va_end(ap); /* len - 1 so we don't send trailing \0 */ diff --git a/src/crypto.c b/src/crypto.c index d0409ed..60c3371 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -42,7 +42,7 @@ static char *digest_to_string(const uint8_t *digest, char *s, size_t len) return NULL; for (i = 0; i < SHA1_DIGEST_SIZE; ++i) - xmpp_snprintf(s + i * 2, 3, "%02x", digest[i]); + strophe_snprintf(s + i * 2, 3, "%02x", digest[i]); return s; } diff --git a/src/ctx.c b/src/ctx.c index 9156a39..74aa02d 100644 --- a/src/ctx.c +++ b/src/ctx.c @@ -283,7 +283,7 @@ static void _strophe_log(const xmpp_ctx_t *ctx, return; va_copy(copy, ap); - ret = xmpp_vsnprintf(smbuf, sizeof(smbuf), fmt, ap); + ret = strophe_vsnprintf(smbuf, sizeof(smbuf), fmt, ap); if (ret >= (int)sizeof(smbuf)) { buf = (char *)strophe_alloc(ctx, ret + 1); if (!buf) { @@ -294,7 +294,7 @@ static void _strophe_log(const xmpp_ctx_t *ctx, return; } oldret = ret; - ret = xmpp_vsnprintf(buf, ret + 1, fmt, copy); + ret = strophe_vsnprintf(buf, ret + 1, fmt, copy); if (ret > oldret) { strophe_error(ctx, "log", "Unexpected error"); strophe_free(ctx, buf); diff --git a/src/resolver.c b/src/resolver.c index 22ef952..c0b6a68 100644 --- a/src/resolver.c +++ b/src/resolver.c @@ -179,8 +179,8 @@ int resolver_srv_lookup(xmpp_ctx_t *ctx, (void)buf; (void)len; - xmpp_snprintf(fulldomain, sizeof(fulldomain), "_%s._%s.%s", service, proto, - domain); + strophe_snprintf(fulldomain, sizeof(fulldomain), "_%s._%s.%s", service, + proto, domain); *srv_rr_list = NULL; @@ -715,8 +715,8 @@ static int resolver_win32_srv_lookup(xmpp_ctx_t *ctx, rr->port = current->Data.Srv.wPort; rr->priority = current->Data.Srv.wPriority; rr->weight = current->Data.Srv.wWeight; - xmpp_snprintf(rr->target, sizeof(rr->target), "%s", - current->Data.Srv.pNameTarget); + strophe_snprintf(rr->target, sizeof(rr->target), "%s", + current->Data.Srv.pNameTarget); *srv_rr_list = rr; } current = current->pNext; diff --git a/src/sasl.c b/src/sasl.c index d6d9f2a..66c3a81 100644 --- a/src/sasl.c +++ b/src/sasl.c @@ -440,9 +440,9 @@ char *sasl_scram(xmpp_ctx_t *ctx, goto out_auth; } - xmpp_snprintf(response, response_len, "c=biws,%s", r); - xmpp_snprintf(auth, auth_len, "%s,%s,%s", first_bare + 3, challenge, - response); + strophe_snprintf(response, response_len, "c=biws,%s", r); + strophe_snprintf(auth, auth_len, "%s,%s,%s", first_bare + 3, challenge, + response); SCRAM_ClientKey(alg, (uint8_t *)password, strlen(password), (uint8_t *)sval, sval_len, (uint32_t)ival, key); diff --git a/src/snprintf.c b/src/snprintf.c index 93b9bad..bd09a99 100644 --- a/src/snprintf.c +++ b/src/snprintf.c @@ -61,7 +61,7 @@ /* JAM: we don't need this - #include "config.h" */ -/* JAM: changed declarations to xmpp_snprintf and xmpp_vsnprintf to +/* JAM: changed declarations to strophe_snprintf and strophe_vsnprintf to avoid namespace collision. */ #include "snprintf.h" @@ -722,7 +722,7 @@ int strophe_snprintf(char *str, size_t count, const char *fmt, ...) int total; VA_START(fmt); - total = xmpp_vsnprintf(str, count, fmt, ap); + total = strophe_vsnprintf(str, count, fmt, ap); VA_END; return total; } diff --git a/src/snprintf.h b/src/snprintf.h index 4a58f49..7133211 100644 --- a/src/snprintf.h +++ b/src/snprintf.h @@ -20,16 +20,14 @@ #endif #ifdef HAVE_SNPRINTF -#define xmpp_snprintf snprintf +#define strophe_snprintf snprintf #else -#define xmpp_snprintf strophe_snprintf int strophe_snprintf(char *str, size_t count, const char *fmt, ...); #endif #ifdef HAVE_VSNPRINTF -#define xmpp_vsnprintf vsnprintf +#define strophe_vsnprintf vsnprintf #else -#define xmpp_vsnprintf strophe_vsnprintf int strophe_vsnprintf(char *str, size_t count, const char *fmt, va_list arg); #endif diff --git a/src/sock.c b/src/sock.c index cbbd1dd..6f01b08 100644 --- a/src/sock.c +++ b/src/sock.c @@ -76,7 +76,7 @@ sock_t sock_connect(const char *host, unsigned short port) struct addrinfo *res, *ainfo, hints; int err; - xmpp_snprintf(service, 6, "%u", port); + strophe_snprintf(service, 6, "%u", port); memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; diff --git a/src/stanza.c b/src/stanza.c index 7be79b7..ef33b6b 100644 --- a/src/stanza.c +++ b/src/stanza.c @@ -336,7 +336,7 @@ _render_stanza_recursive(xmpp_stanza_t *stanza, char *buf, size_t buflen) tmp = _escape_xml(stanza->ctx, stanza->data); if (tmp == NULL) return XMPP_EMEM; - ret = xmpp_snprintf(ptr, left, "%s", tmp); + ret = strophe_snprintf(ptr, left, "%s", tmp); strophe_free(stanza->ctx, tmp); if (ret < 0) return XMPP_EMEM; @@ -346,7 +346,7 @@ _render_stanza_recursive(xmpp_stanza_t *stanza, char *buf, size_t buflen) return XMPP_EINVOP; /* write beginning of tag and attributes */ - ret = xmpp_snprintf(ptr, left, "<%s", stanza->data); + ret = strophe_snprintf(ptr, left, "<%s", stanza->data); if (ret < 0) return XMPP_EMEM; _render_update(&written, buflen, ret, &left, &ptr); @@ -374,7 +374,7 @@ _render_stanza_recursive(xmpp_stanza_t *stanza, char *buf, size_t buflen) hash_iter_release(iter); return XMPP_EMEM; } - ret = xmpp_snprintf(ptr, left, " %s=\"%s\"", key, tmp); + ret = strophe_snprintf(ptr, left, " %s=\"%s\"", key, tmp); strophe_free(stanza->ctx, tmp); if (ret < 0) { hash_iter_release(iter); @@ -387,7 +387,7 @@ _render_stanza_recursive(xmpp_stanza_t *stanza, char *buf, size_t buflen) if (!stanza->children) { /* write end if singleton tag */ - ret = xmpp_snprintf(ptr, left, "/>"); + ret = strophe_snprintf(ptr, left, "/>"); if (ret < 0) return XMPP_EMEM; _render_update(&written, buflen, ret, &left, &ptr); @@ -395,7 +395,7 @@ _render_stanza_recursive(xmpp_stanza_t *stanza, char *buf, size_t buflen) /* this stanza has child stanzas */ /* write end of start tag */ - ret = xmpp_snprintf(ptr, left, ">"); + ret = strophe_snprintf(ptr, left, ">"); if (ret < 0) return XMPP_EMEM; _render_update(&written, buflen, ret, &left, &ptr); @@ -413,7 +413,7 @@ _render_stanza_recursive(xmpp_stanza_t *stanza, char *buf, size_t buflen) } /* write end tag */ - ret = xmpp_snprintf(ptr, left, "", stanza->data); + ret = strophe_snprintf(ptr, left, "", stanza->data); if (ret < 0) return XMPP_EMEM; diff --git a/src/tls_gnutls.c b/src/tls_gnutls.c index 3d9d8a5..b56810e 100644 --- a/src/tls_gnutls.c +++ b/src/tls_gnutls.c @@ -214,7 +214,7 @@ static xmpp_tlscert_t *_x509_to_tlscert(xmpp_ctx_t *ctx, gnutls_x509_crt_t cert) hex_encode(buf, smallbuf, size); tlscert->elements[XMPP_CERT_FINGERPRINT_SHA256] = strophe_strdup(ctx, buf); - xmpp_snprintf(buf, sizeof(buf), "%d", gnutls_x509_crt_get_version(cert)); + strophe_snprintf(buf, sizeof(buf), "%d", gnutls_x509_crt_get_version(cert)); tlscert->elements[XMPP_CERT_VERSION] = strophe_strdup(ctx, buf); algo = gnutls_x509_crt_get_pk_algorithm(cert, NULL); diff --git a/src/tls_openssl.c b/src/tls_openssl.c index bf245fa..ab962b6 100644 --- a/src/tls_openssl.c +++ b/src/tls_openssl.c @@ -433,7 +433,7 @@ static xmpp_tlscert_t *_x509_to_tlscert(xmpp_ctx_t *ctx, X509 *cert) tlscert->elements[XMPP_CERT_FINGERPRINT_SHA256] = _get_fingerprint(ctx, cert, XMPP_CERT_FINGERPRINT_SHA256); - xmpp_snprintf(buf, sizeof(buf), "%ld", X509_get_version(cert) + 1); + strophe_snprintf(buf, sizeof(buf), "%ld", X509_get_version(cert) + 1); tlscert->elements[XMPP_CERT_VERSION] = strophe_strdup(ctx, buf); tlscert->elements[XMPP_CERT_KEYALG] = _get_alg(ctx, cert, XMPP_CERT_KEYALG); diff --git a/tests/test_rand.c b/tests/test_rand.c index 7ee4cd7..183cea1 100644 --- a/tests/test_rand.c +++ b/tests/test_rand.c @@ -35,7 +35,7 @@ void strophe_free(const xmpp_ctx_t *ctx, void *p) } #ifndef HAVE_SNPRINTF -int xmpp_snprintf(char *str, size_t count, const char *fmt, ...) +int strophe_snprintf(char *str, size_t count, const char *fmt, ...) { (void)str; (void)count; diff --git a/tests/test_snprintf.c b/tests/test_snprintf.c index 9c8617e..3cbe231 100644 --- a/tests/test_snprintf.c +++ b/tests/test_snprintf.c @@ -37,7 +37,7 @@ int main(void) for (x = 0; fp_fmt[x] != NULL; x++) for (y = 0; fp_nums[y] != 0; y++) { - xmpp_snprintf(buf1, sizeof(buf1), fp_fmt[x], fp_nums[y]); + strophe_snprintf(buf1, sizeof(buf1), fp_fmt[x], fp_nums[y]); sprintf(buf2, fp_fmt[x], fp_nums[y]); if (strcmp(buf1, buf2)) { printf("xmpp_snprintf doesn't match Format: " @@ -50,7 +50,7 @@ int main(void) for (x = 0; int_fmt[x] != NULL; x++) for (y = 0; int_nums[y] != 0; y++) { - xmpp_snprintf(buf1, sizeof(buf1), int_fmt[x], int_nums[y]); + strophe_snprintf(buf1, sizeof(buf1), int_fmt[x], int_nums[y]); sprintf(buf2, int_fmt[x], int_nums[y]); if (strcmp(buf1, buf2)) { printf("xmpp_snprintf doesn't match Format: "