You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by as...@apache.org on 2023/07/11 20:06:10 UTC
[qpid-proton] branch main updated (139ed8bc2 -> 97fcd648f)
This is an automated email from the ASF dual-hosted git repository.
astitcher pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
from 139ed8bc2 PROTON-2746: Fix potential uninitialized/illegal read
new b86dcb9ed NO-JIRA: Make pn_bytes()/pn_rwbytes() inlinable
new 0545b51c2 PROTON-2753: Split util.h so that we can keep the C++ in the schannel impl happy
new a2c54b3a2 PROTON-2751: Use pn_rwbytes_t not pn_buffer_t for scratch space
new f2693f29d PROTON-2751: Don't use pn_buffer for delivery tag
new 31e25638e PROTON-2751: Remove unused functionality of pn_buffer_t
new 97fcd648f PROTON-2752: Make more use of pn_string_t instead of char*
The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
c/include/proton/types.h | 12 ++-
c/src/core/buffer.c | 88 +----------------
c/src/core/buffer.h | 5 -
c/src/core/emitters.h | 31 +++---
c/src/core/engine-internal.h | 5 +-
c/src/core/engine.c | 19 ++--
c/src/core/error.c | 2 +-
c/src/core/logger.c | 2 +-
c/src/core/message.c | 14 +--
c/src/core/object/string.c | 13 ++-
c/src/core/object_private.h | 1 +
c/src/core/transport.c | 109 +++++++++++----------
c/src/core/types.c | 13 +--
c/src/core/util.h | 37 +++++--
.../libFuzzingEngine.h => src/core/util_str.h} | 28 +++---
c/src/extra/url.c | 2 +-
c/src/messenger/messenger.c | 1 +
c/src/sasl/sasl-internal.h | 4 +-
c/src/sasl/sasl.c | 41 ++++----
c/src/ssl/openssl.c | 1 +
c/src/ssl/schannel.cpp | 2 +-
c/tools/codec-generator/generate.py | 8 +-
22 files changed, 195 insertions(+), 243 deletions(-)
copy c/{tests/fuzz/libFuzzingEngine.h => src/core/util_str.h} (70%)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[qpid-proton] 02/06: PROTON-2753: Split util.h so that we can keep the C++ in the schannel impl happy
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astitcher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
commit 0545b51c234260fe6977e8545c785a442732950d
Author: Andrew Stitcher <as...@apache.org>
AuthorDate: Thu May 4 15:31:51 2023 -0400
PROTON-2753: Split util.h so that we can keep the C++ in the schannel impl happy
---
c/src/core/engine-internal.h | 1 -
c/src/core/error.c | 2 +-
c/src/core/logger.c | 2 +-
c/src/core/transport.c | 2 ++
c/src/core/util.h | 5 -----
c/src/core/util_str.h | 42 ++++++++++++++++++++++++++++++++++++++++++
c/src/extra/url.c | 2 +-
c/src/messenger/messenger.c | 1 +
c/src/sasl/sasl.c | 2 ++
c/src/ssl/openssl.c | 1 +
c/src/ssl/schannel.cpp | 2 +-
11 files changed, 52 insertions(+), 10 deletions(-)
diff --git a/c/src/core/engine-internal.h b/c/src/core/engine-internal.h
index 5ff6ae4ce..29e84eb02 100644
--- a/c/src/core/engine-internal.h
+++ b/c/src/core/engine-internal.h
@@ -29,7 +29,6 @@
#include "buffer.h"
#include "dispatcher.h"
#include "logger_private.h"
-#include "util.h"
#if __cplusplus
extern "C" {
diff --git a/c/src/core/error.c b/c/src/core/error.c
index fa7b137c0..c4b5c0497 100644
--- a/c/src/core/error.c
+++ b/c/src/core/error.c
@@ -23,7 +23,7 @@
#include "memory.h"
#include "platform/platform.h"
-#include "util.h"
+#include "util_str.h"
#include <proton/connection.h>
#include <proton/link.h>
diff --git a/c/src/core/logger.c b/c/src/core/logger.c
index ea1659347..003a3ce5b 100644
--- a/c/src/core/logger.c
+++ b/c/src/core/logger.c
@@ -24,7 +24,7 @@
#include "fixed_string.h"
#include "memory.h"
-#include "util.h"
+#include "util_str.h"
#include "value_dump.h"
#include <assert.h>
diff --git a/c/src/core/transport.c b/c/src/core/transport.c
index 1fad3773a..38d3a188d 100644
--- a/c/src/core/transport.c
+++ b/c/src/core/transport.c
@@ -28,6 +28,8 @@
#include "platform/platform_fmt.h"
#include "sasl/sasl-internal.h"
#include "ssl/ssl-internal.h"
+#include "util.h"
+#include "util_str.h"
#include "autodetect.h"
#include "protocol.h"
diff --git a/c/src/core/util.h b/c/src/core/util.h
index 692f8fdb6..7924bc9bd 100644
--- a/c/src/core/util.h
+++ b/c/src/core/util.h
@@ -46,11 +46,6 @@ bool pn_env_bool(const char *name);
pn_timestamp_t pn_timestamp_min(pn_timestamp_t a, pn_timestamp_t b);
extern const pn_class_t PN_CLASSCLASS(pn_strdup)[];
-char *pn_strdup(const char *src);
-char *pn_strndup(const char *src, size_t n);
-
-int pn_strcasecmp(const char* a, const char* b);
-int pn_strncasecmp(const char* a, const char* b, size_t len);
static inline bool pn_bytes_equal(const pn_bytes_t a, const pn_bytes_t b) {
return (a.size == b.size && !memcmp(a.start, b.start, a.size));
diff --git a/c/src/core/util_str.h b/c/src/core/util_str.h
new file mode 100644
index 000000000..2f20e6709
--- /dev/null
+++ b/c/src/core/util_str.h
@@ -0,0 +1,42 @@
+#ifndef _PROTON_SRC_UTIL_STR_H
+#define _PROTON_SRC_UTIL_STR_H 1
+
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+#include <stddef.h>
+
+#if __cplusplus
+extern "C" {
+#endif
+
+char *pn_strdup(const char *src);
+char *pn_strndup(const char *src, size_t n);
+
+int pn_strcasecmp(const char* a, const char* b);
+int pn_strncasecmp(const char* a, const char* b, size_t len);
+
+
+#if __cplusplus
+}
+#endif
+
+#endif /* util_str.h */
diff --git a/c/src/extra/url.c b/c/src/extra/url.c
index 383d19719..d388b9a2a 100644
--- a/c/src/extra/url.c
+++ b/c/src/extra/url.c
@@ -22,7 +22,7 @@
#define PN_USE_DEPRECATED_API 1
#include "core/fixed_string.h"
-#include "core/util.h"
+#include "core/util_str.h"
#include "proton/url.h"
#include "proton/object.h"
diff --git a/c/src/messenger/messenger.c b/c/src/messenger/messenger.c
index add1491a7..ec3f0514a 100644
--- a/c/src/messenger/messenger.c
+++ b/c/src/messenger/messenger.c
@@ -39,6 +39,7 @@
#include "core/log_private.h"
#include "core/util.h"
+#include "core/util_str.h"
#include "platform/platform.h" // pn_i_getpid, pn_i_now
#include "platform/platform_fmt.h"
#include "store.h"
diff --git a/c/src/sasl/sasl.c b/c/src/sasl/sasl.c
index 3de63aa45..1e1d877af 100644
--- a/c/src/sasl/sasl.c
+++ b/c/src/sasl/sasl.c
@@ -28,6 +28,7 @@
#include "core/frame_generators.h"
#include "core/frame_consumers.h"
#include "core/util.h"
+#include "core/util_str.h"
#include "platform/platform_fmt.h"
#include "protocol.h"
@@ -35,6 +36,7 @@
#include "proton/types.h"
#include <assert.h>
+#include <stdlib.h>
// Machinery to allow plugin SASL implementations
// Change this to &default_sasl_impl when we change cyrus to opt in
diff --git a/c/src/ssl/openssl.c b/c/src/ssl/openssl.c
index caa7ea011..41965dcd6 100644
--- a/c/src/ssl/openssl.c
+++ b/c/src/ssl/openssl.c
@@ -24,6 +24,7 @@
#include "core/engine-internal.h"
#include "core/logger_private.h"
#include "core/util.h"
+#include "core/util_str.h"
#include <proton/ssl.h>
#include <proton/engine.h>
diff --git a/c/src/ssl/schannel.cpp b/c/src/ssl/schannel.cpp
index 5d2ff8b02..de1a182fb 100644
--- a/c/src/ssl/schannel.cpp
+++ b/c/src/ssl/schannel.cpp
@@ -35,7 +35,7 @@
#include "core/autodetect.h"
#include "core/engine-internal.h"
#include "core/logger_private.h"
-#include "core/util.h"
+#include "core/util_str.h"
#include "platform/platform.h"
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[qpid-proton] 05/06: PROTON-2751: Remove unused functionality of pn_buffer_t
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astitcher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
commit 31e25638ea74551465f1331c41bdfaced5438b69
Author: Andrew Stitcher <as...@apache.org>
AuthorDate: Wed Jul 5 18:47:51 2023 -0400
PROTON-2751: Remove unused functionality of pn_buffer_t
Also rearrange implementation struct to be more efficient
---
c/src/core/buffer.c | 88 +++--------------------------------------------------
c/src/core/buffer.h | 5 ---
2 files changed, 4 insertions(+), 89 deletions(-)
diff --git a/c/src/core/buffer.c b/c/src/core/buffer.c
index 5b697d686..dc3a753d6 100644
--- a/c/src/core/buffer.c
+++ b/c/src/core/buffer.c
@@ -34,10 +34,10 @@
#include "util.h"
struct pn_buffer_t {
- size_t capacity;
- size_t start;
- size_t size;
char *bytes;
+ uint32_t capacity;
+ uint32_t start;
+ uint32_t size;
};
PN_STRUCT_CLASSDEF(pn_buffer)
@@ -113,33 +113,6 @@ static size_t pni_buffer_tail_space(pn_buffer_t *buf)
}
}
-static size_t pni_buffer_head_space(pn_buffer_t *buf)
-{
- if (pni_buffer_wrapped(buf)) {
- return pn_buffer_available(buf);
- } else {
- return pni_buffer_head(buf);
- }
-}
-
-static size_t pni_buffer_head_size(pn_buffer_t *buf)
-{
- if (pni_buffer_wrapped(buf)) {
- return buf->capacity - pni_buffer_head(buf);
- } else {
- return pni_buffer_tail(buf) - pni_buffer_head(buf);
- }
-}
-
-static size_t pni_buffer_tail_size(pn_buffer_t *buf)
-{
- if (pni_buffer_wrapped(buf)) {
- return pni_buffer_tail(buf);
- } else {
- return 0;
- }
-}
-
int pn_buffer_ensure(pn_buffer_t *buf, size_t size)
{
size_t old_capacity = buf->capacity;
@@ -186,29 +159,6 @@ int pn_buffer_append(pn_buffer_t *buf, const char *bytes, size_t size)
return 0;
}
-int pn_buffer_prepend(pn_buffer_t *buf, const char *bytes, size_t size)
-{
- int err = pn_buffer_ensure(buf, size);
- if (err) return err;
-
- size_t head = pni_buffer_head(buf);
- size_t head_space = pni_buffer_head_space(buf);
- size_t n = pn_min(head_space, size);
-
- memcpy(buf->bytes + head - n, bytes + size - n, n);
- memcpy(buf->bytes + buf->capacity - (size - n), bytes, size - n);
-
- if (buf->start >= size) {
- buf->start -= size;
- } else {
- buf->start = buf->capacity - (size - buf->start);
- }
-
- buf->size += size;
-
- return 0;
-}
-
static size_t pni_buffer_index(pn_buffer_t *buf, size_t index)
{
size_t result = buf->start + index;
@@ -284,7 +234,7 @@ static void pn_buffer_rotate (pn_buffer_t *buf, size_t sz) {
}
}
-int pn_buffer_defrag(pn_buffer_t *buf)
+static inline int pn_buffer_defrag(pn_buffer_t *buf)
{
pn_buffer_rotate(buf, buf->start);
buf->start = 0;
@@ -308,33 +258,3 @@ pn_rwbytes_t pn_buffer_memory(pn_buffer_t *buf)
pn_buffer_defrag(buf);
return (pn_rwbytes_t){.size=buf->size, .start=buf->bytes};
}
-
-pn_rwbytes_t pn_buffer_free_memory(pn_buffer_t *buf)
-{
- if (!buf) {
- return (pn_rwbytes_t){0, NULL};
- }
- size_t free_size = buf->capacity-buf->size;
- if (buf->start == 0) {
- return (pn_rwbytes_t){.size=free_size, .start=buf->bytes};
- }
- // If free memory in one single blob don't need to defragment
- if (buf->start+buf->size > buf->capacity) {
- return (pn_rwbytes_t){.size=free_size, .start=buf->bytes+buf->start-free_size};
- }
- pn_buffer_defrag(buf);
- return (pn_rwbytes_t){.size=free_size, .start=buf->bytes+buf->start+buf->size};
-}
-
-int pn_buffer_quote(pn_buffer_t *buf, pn_string_t *str, size_t n)
-{
- size_t hsize = pni_buffer_head_size(buf);
- size_t tsize = pni_buffer_tail_size(buf);
- if (hsize >= n) {
- pn_quote(str, buf->bytes + pni_buffer_head(buf), n);
- return 0;
- }
- pn_quote(str, buf->bytes + pni_buffer_head(buf), hsize);
- pn_quote(str, buf->bytes, pn_min(tsize, n-hsize));
- return 0;
-}
diff --git a/c/src/core/buffer.h b/c/src/core/buffer.h
index e205c9b55..b5bf94032 100644
--- a/c/src/core/buffer.h
+++ b/c/src/core/buffer.h
@@ -40,16 +40,11 @@ size_t pn_buffer_capacity(pn_buffer_t *buf);
size_t pn_buffer_available(pn_buffer_t *buf);
int pn_buffer_ensure(pn_buffer_t *buf, size_t size);
int pn_buffer_append(pn_buffer_t *buf, const char *bytes, size_t size);
-int pn_buffer_prepend(pn_buffer_t *buf, const char *bytes, size_t size);
size_t pn_buffer_get(pn_buffer_t *buf, size_t offset, size_t size, char *dst);
int pn_buffer_trim(pn_buffer_t *buf, size_t left, size_t right);
void pn_buffer_clear(pn_buffer_t *buf);
-int pn_buffer_defrag(pn_buffer_t *buf);
pn_bytes_t pn_buffer_bytes(pn_buffer_t *buf);
pn_rwbytes_t pn_buffer_memory(pn_buffer_t *buf);
-pn_rwbytes_t pn_buffer_free_memory(pn_buffer_t *buf);
-struct pn_string_t;
-int pn_buffer_quote(pn_buffer_t *buf, struct pn_string_t *string, size_t n);
#ifdef __cplusplus
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[qpid-proton] 03/06: PROTON-2751: Use pn_rwbytes_t not pn_buffer_t for scratch space
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astitcher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
commit a2c54b3a245356b734e22bbdd5f732ed00d44398
Author: Andrew Stitcher <as...@apache.org>
AuthorDate: Mon May 8 20:15:42 2023 -0400
PROTON-2751: Use pn_rwbytes_t not pn_buffer_t for scratch space
---
c/src/core/emitters.h | 15 ++++++++-------
c/src/core/engine-internal.h | 2 +-
c/src/core/transport.c | 28 ++++++++++++++--------------
c/src/core/util.h | 18 ++++++++++++++++++
c/src/sasl/sasl.c | 10 +++++-----
c/tools/codec-generator/generate.py | 4 ++--
6 files changed, 48 insertions(+), 29 deletions(-)
diff --git a/c/src/core/emitters.h b/c/src/core/emitters.h
index 9b4ec1b50..a9399ba5c 100644
--- a/c/src/core/emitters.h
+++ b/c/src/core/emitters.h
@@ -24,7 +24,9 @@
/* Definitions of AMQP type codes */
#include "encodings.h"
-#include "buffer.h"
+#include "engine-internal.h"
+#include "protocol.h"
+#include "util.h"
#include <proton/codec.h>
@@ -56,11 +58,10 @@ typedef struct pni_emitter_t {
size_t position;
} pni_emitter_t;
-static inline pni_emitter_t make_emitter_from_buffer(pn_buffer_t* buffer) {
- pn_rwbytes_t output_bytes = pn_buffer_free_memory(buffer);
+static inline pni_emitter_t make_emitter_from_rwbytes(pn_rwbytes_t* output_bytes) {
return (pni_emitter_t){
- .output_start = output_bytes.start,
- .size = output_bytes.size,
+ .output_start = output_bytes->start,
+ .size = output_bytes->size,
.position = 0
};
}
@@ -81,8 +82,8 @@ static inline bool resize_required(pni_emitter_t* emitter) {
return emitter->position > emitter->size;
}
-static inline void size_buffer_to_emitter(pn_buffer_t* buffer, pni_emitter_t* emitter) {
- pn_buffer_ensure(buffer, pn_buffer_capacity(buffer)+(emitter->position-emitter->size));
+static inline void size_buffer_to_emitter(pn_rwbytes_t* buffer, pni_emitter_t* emitter) {
+ pn_rwbytes_realloc(buffer, buffer->size+emitter->position-emitter->size);
}
static inline bool encode_succeeded(pni_emitter_t* emitter, pni_compound_context* compound) {
diff --git a/c/src/core/engine-internal.h b/c/src/core/engine-internal.h
index 29e84eb02..4cf6ea502 100644
--- a/c/src/core/engine-internal.h
+++ b/c/src/core/engine-internal.h
@@ -165,7 +165,7 @@ struct pn_transport_t {
/* scratch area */
- pn_buffer_t *frame; // frame under construction
+ pn_rwbytes_t scratch_space;
// Temporary - ??
pn_buffer_t *output_buffer;
diff --git a/c/src/core/transport.c b/c/src/core/transport.c
index 38d3a188d..e414789e5 100644
--- a/c/src/core/transport.c
+++ b/c/src/core/transport.c
@@ -410,7 +410,7 @@ static void pn_transport_initialize(void *object)
transport->tracer = NULL;
transport->sasl = NULL;
transport->ssl = NULL;
- transport->frame = pn_buffer(PN_TRANSPORT_INITIAL_FRAME_SIZE);
+ transport->scratch_space = pn_rwbytes_alloc(PN_TRANSPORT_INITIAL_FRAME_SIZE);
transport->input_frames_ct = 0;
transport->output_frames_ct = 0;
@@ -662,7 +662,7 @@ static void pn_transport_finalize(void *object)
pn_free(transport->remote_channels);
pni_mem_subdeallocate(pn_class(transport), transport, transport->input_buf);
pni_mem_subdeallocate(pn_class(transport), transport, transport->output_buf);
- pn_buffer_free(transport->frame);
+ pn_rwbytes_free(transport->scratch_space);
pn_free(transport->context);
pn_buffer_free(transport->output_buffer);
pni_logger_fini(&transport->logger);
@@ -901,7 +901,7 @@ static int pni_post_amqp_transfer_frame(pn_transport_t *transport, uint16_t ch,
compute_performatives:;
/* "DL[IIzI?o?on?DLC?o?o?o]" */
pn_bytes_t performative =
- pn_amqp_encode_DLEIIzIQoQonQDLCQoQoQoe(transport->frame, TRANSFER,
+ pn_amqp_encode_DLEIIzIQoQonQDLCQoQoQoe(&transport->scratch_space, TRANSFER,
handle,
id,
tag->size, tag->start,
@@ -960,7 +960,7 @@ static int pni_post_close(pn_transport_t *transport, pn_condition_t *cond)
info = pn_condition_info(cond);
}
/* "DL[?DL[sSC]]" */
- pn_bytes_t buf = pn_amqp_encode_DLEQDLEsSCee(transport->frame, CLOSE,
+ pn_bytes_t buf = pn_amqp_encode_DLEQDLEsSCee(&transport->scratch_space, CLOSE,
(bool) condition, ERROR, condition, description, info);
return pn_framing_send_amqp(transport, 0, buf);
}
@@ -1871,7 +1871,7 @@ static int pni_process_conn_setup(pn_transport_t *transport, pn_endpoint_t *endp
const char *cid = pn_string_get(connection->container);
pni_calculate_channel_max(transport);
/* "DL[SS?I?H?InnMMC]" */
- pn_bytes_t buf = pn_amqp_encode_DLESSQIQHQInnMMCe(transport->frame, OPEN,
+ pn_bytes_t buf = pn_amqp_encode_DLESSQIQHQInnMMCe(&transport->scratch_space, OPEN,
cid ? cid : "",
pn_string_get(connection->hostname),
// TODO: This is messy, because we also have to allow local_max_frame_ to be 0 to mean unlimited
@@ -1960,7 +1960,7 @@ static int pni_process_ssn_setup(pn_transport_t *transport, pn_endpoint_t *endpo
state->incoming_window = pni_session_incoming_window(ssn);
state->outgoing_window = pni_session_outgoing_window(ssn);
/* "DL[?HIIII]" */
- pn_bytes_t buf = pn_amqp_encode_DLEQHIIIIe(transport->frame, BEGIN,
+ pn_bytes_t buf = pn_amqp_encode_DLEQHIIIIe(&transport->scratch_space, BEGIN,
((int16_t) state->remote_channel >= 0), state->remote_channel,
state->outgoing_transfer_count,
state->incoming_window,
@@ -2021,7 +2021,7 @@ static int pni_process_link_setup(pn_transport_t *transport, pn_endpoint_t *endp
const pn_distribution_mode_t dist_mode = (pn_distribution_mode_t) link->source.distribution_mode;
if (link->target.type == PN_COORDINATOR) {
/* "DL[SIoBB?DL[SIsIoC?sCnCC]DL[C]nnI]" */
- pn_bytes_t buf = pn_amqp_encode_DLESIoBBQDLESIsIoCQsCnCCeDLECennIe(transport->frame, ATTACH,
+ pn_bytes_t buf = pn_amqp_encode_DLESIoBBQDLESIsIoCQsCnCCeDLECennIe(&transport->scratch_space, ATTACH,
pn_string_get(link->name),
state->local_handle,
endpoint->type == RECEIVER,
@@ -2044,7 +2044,7 @@ static int pni_process_link_setup(pn_transport_t *transport, pn_endpoint_t *endp
if (err) return err;
} else {
/* "DL[SIoBB?DL[SIsIoC?sCnMM]?DL[SIsIoCM]nnILnnC]" */
- pn_bytes_t buf = pn_amqp_encode_DLESIoBBQDLESIsIoCQsCnMMeQDLESIsIoCMennILnnCe(transport->frame, ATTACH,
+ pn_bytes_t buf = pn_amqp_encode_DLESIoBBQDLESIsIoCQsCnMMeQDLESIsIoCMennILnnCe(&transport->scratch_space, ATTACH,
pn_string_get(link->name),
state->local_handle,
endpoint->type == RECEIVER,
@@ -2091,7 +2091,7 @@ static int pni_post_flow(pn_transport_t *transport, pn_session_t *ssn, pn_link_t
bool linkq = (bool) link;
pn_link_state_t *state = &link->state;
/* "DL[?IIII?I?I?In?o]" */
- pn_bytes_t buf = pn_amqp_encode_DLEQIIIIQIQIQInQoe(transport->frame, FLOW,
+ pn_bytes_t buf = pn_amqp_encode_DLEQIIIIQIQIQInQoe(&transport->scratch_space, FLOW,
(int16_t) ssn->state.remote_channel >= 0, ssn->state.incoming_transfer_count,
ssn->state.incoming_window,
ssn->state.outgoing_transfer_count,
@@ -2127,7 +2127,7 @@ static int pni_flush_disp(pn_transport_t *transport, pn_session_t *ssn)
bool settled = ssn->state.disp_settled;
if (ssn->state.disp) {
/* "DL[oI?I?o?DL[]]" */
- pn_bytes_t buf = pn_amqp_encode_DLEoIQIQoQDLEee(transport->frame, DISPOSITION,
+ pn_bytes_t buf = pn_amqp_encode_DLEoIQIQoQDLEee(&transport->scratch_space, DISPOSITION,
ssn->state.disp_type,
ssn->state.disp_first,
ssn->state.disp_last!=ssn->state.disp_first, ssn->state.disp_last,
@@ -2164,7 +2164,7 @@ static int pni_post_disp(pn_transport_t *transport, pn_delivery_t *delivery)
pn_data_clear(transport->disp_data);
PN_RETURN_IF_ERROR(pni_disposition_encode(&delivery->local, transport->disp_data));
/* "DL[oIn?o?DLC]" */
- pn_bytes_t buf = pn_amqp_encode_DLEoInQoQDLCe(transport->frame,DISPOSITION,
+ pn_bytes_t buf = pn_amqp_encode_DLEoInQoQDLCe(&transport->scratch_space,DISPOSITION,
role, state->id,
delivery->local.settled, delivery->local.settled,
(bool)code, code, transport->disp_data);
@@ -2402,7 +2402,7 @@ static int pni_process_link_teardown(pn_transport_t *transport, pn_endpoint_t *e
info = pn_condition_info(&endpoint->condition);
}
/* "DL[I?o?DL[sSC]]" */
- pn_bytes_t buf = pn_amqp_encode_DLEIQoQDLEsSCee(transport->frame, DETACH,
+ pn_bytes_t buf = pn_amqp_encode_DLEIQoQDLEsSCee(&transport->scratch_space, DETACH,
state->local_handle,
!link->detached, !link->detached,
(bool)name, ERROR, name, description, info);
@@ -2478,7 +2478,7 @@ static int pni_process_ssn_teardown(pn_transport_t *transport, pn_endpoint_t *en
info = pn_condition_info(&endpoint->condition);
}
/* "DL[?DL[sSC]]" */
- pn_bytes_t buf = pn_amqp_encode_DLEQDLEsSCee(transport->frame, END,
+ pn_bytes_t buf = pn_amqp_encode_DLEQDLEsSCee(&transport->scratch_space, END,
(bool) name, ERROR, name, description, info);
int err = pn_framing_send_amqp(transport, state->local_channel, buf);
if (err) return err;
@@ -2555,7 +2555,7 @@ static void pn_error_amqp(pn_transport_t* transport, unsigned int layer)
if (!transport->close_sent) {
if (!transport->open_sent) {
/* "DL[S]" */
- pn_bytes_t buf = pn_amqp_encode_DLESe(transport->frame, OPEN, "");
+ pn_bytes_t buf = pn_amqp_encode_DLESe(&transport->scratch_space, OPEN, "");
pn_framing_send_amqp(transport, 0, buf);
}
diff --git a/c/src/core/util.h b/c/src/core/util.h
index 7924bc9bd..7ed5b925f 100644
--- a/c/src/core/util.h
+++ b/c/src/core/util.h
@@ -55,6 +55,24 @@ static inline pn_bytes_t pn_string_bytes(struct pn_string_t *s) {
return pn_bytes(pn_string_size(s), pn_string_get(s));
}
+static inline pn_rwbytes_t pn_rwbytes_alloc(size_t size) {
+ char* space = malloc(size);
+ size_t s = space ? size : 0;
+ return (pn_rwbytes_t){.size=s, .start=space};
+}
+
+
+static inline pn_rwbytes_t pn_rwbytes_realloc(pn_rwbytes_t *in, size_t size) {
+ char* space = realloc(in->start, size);
+ size_t s = space ? size : 0;
+ *in = (pn_rwbytes_t){.size=s, .start=space};
+ return *in;
+}
+
+static inline void pn_rwbytes_free(pn_rwbytes_t in) {
+ free((void*)in.start);
+}
+
static inline void pni_write16(char *bytes, uint16_t value)
{
bytes[0] = 0xFF & (value >> 8);
diff --git a/c/src/sasl/sasl.c b/c/src/sasl/sasl.c
index 1e1d877af..0dff90a6a 100644
--- a/c/src/sasl/sasl.c
+++ b/c/src/sasl/sasl.c
@@ -491,7 +491,7 @@ static void pni_post_sasl_frame(pn_transport_t *transport)
switch (desired_state) {
case SASL_POSTED_INIT: {
/* GENERATE_CODEC_CODE: "DL[szS]" */
- pn_bytes_t buf = pn_amqp_encode_DLEszSe(transport->frame, SASL_INIT, sasl->selected_mechanism, out.size, out.start, sasl->local_fqdn);
+ pn_bytes_t buf = pn_amqp_encode_DLEszSe(&transport->scratch_space, SASL_INIT, sasl->selected_mechanism, out.size, out.start, sasl->local_fqdn);
pn_framing_send_sasl(transport, buf);
pni_emit(transport);
break;
@@ -506,7 +506,7 @@ static void pni_post_sasl_frame(pn_transport_t *transport)
pni_split_mechs(mechlist, sasl->included_mechanisms, mechs, &count);
}
/* GENERATE_CODEC_CODE: "DL[@T[*s]]" */
- pn_bytes_t buf = pn_amqp_encode_DLEATEjsee(transport->frame, SASL_MECHANISMS, PN_SYMBOL, count, mechs);
+ pn_bytes_t buf = pn_amqp_encode_DLEATEjsee(&transport->scratch_space, SASL_MECHANISMS, PN_SYMBOL, count, mechs);
free(mechlist);
pn_framing_send_sasl(transport, buf);
pni_emit(transport);
@@ -515,7 +515,7 @@ static void pni_post_sasl_frame(pn_transport_t *transport)
case SASL_POSTED_RESPONSE:
if (sasl->last_state != SASL_POSTED_RESPONSE) {
/* "DL[Z]" */
- pn_bytes_t buf = pn_amqp_encode_DLEZe(transport->frame, SASL_RESPONSE, out.size, out.start);
+ pn_bytes_t buf = pn_amqp_encode_DLEZe(&transport->scratch_space, SASL_RESPONSE, out.size, out.start);
pn_framing_send_sasl(transport, buf);
pni_emit(transport);
}
@@ -526,7 +526,7 @@ static void pni_post_sasl_frame(pn_transport_t *transport)
continue;
} else if (sasl->last_state != SASL_POSTED_CHALLENGE) {
/* "DL[Z]" */
- pn_bytes_t buf = pn_amqp_encode_DLEZe(transport->frame, SASL_CHALLENGE, out.size, out.start);
+ pn_bytes_t buf = pn_amqp_encode_DLEZe(&transport->scratch_space, SASL_CHALLENGE, out.size, out.start);
pn_framing_send_sasl(transport, buf);
pni_emit(transport);
}
@@ -537,7 +537,7 @@ static void pni_post_sasl_frame(pn_transport_t *transport)
continue;
}
/* "DL[Bz]" */
- pn_bytes_t buf = pn_amqp_encode_DLEBze(transport->frame, SASL_OUTCOME, sasl->outcome, out.size, out.start);
+ pn_bytes_t buf = pn_amqp_encode_DLEBze(&transport->scratch_space, SASL_OUTCOME, sasl->outcome, out.size, out.start);
pn_framing_send_sasl(transport, buf);
pni_emit(transport);
if (sasl->outcome!=PN_SASL_OK) {
diff --git a/c/tools/codec-generator/generate.py b/c/tools/codec-generator/generate.py
index 348df1bc0..e9ec2445c 100644
--- a/c/tools/codec-generator/generate.py
+++ b/c/tools/codec-generator/generate.py
@@ -414,7 +414,7 @@ def emit_function(name_prefix: str, fill_spec: str, prefix_args: List[Tuple[str,
f'{function_spec}',
'{',
f'{p.mk_indent(1)}do {{',
- f'{p.mk_indent(2)}pni_emitter_t emitter = make_emitter_from_buffer({", ".join(prefix_params)});',
+ f'{p.mk_indent(2)}pni_emitter_t emitter = make_emitter_from_rwbytes({", ".join(prefix_params)});',
f'{p.mk_indent(2)}if ({p.mk_funcall(inner_function_name, ["&emitter", *args])}) {{',
f'{p.mk_indent(3)}{p.mk_funcall("size_buffer_to_emitter", [*prefix_params, "&emitter"])};',
f'{p.mk_indent(3)}continue;',
@@ -494,7 +494,7 @@ def emit(fill_specs, decl_filename, impl_filename):
decls: Dict[str, str] = {}
defns: Dict[str, List[str]] = {}
for fill_spec in fill_specs:
- decl, defn = emit_function('pn_amqp_encode', fill_spec, [('buffer', 'pn_buffer_t*')])
+ decl, defn = emit_function('pn_amqp_encode', fill_spec, [('buffer', 'pn_rwbytes_t*')])
decls[fill_spec] = decl
defns[fill_spec] = defn
if decl_filename and impl_filename:
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[qpid-proton] 01/06: NO-JIRA: Make pn_bytes()/pn_rwbytes() inlinable
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astitcher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
commit b86dcb9ed139199a71d0dece6fa4384b8b80925b
Author: Andrew Stitcher <as...@apache.org>
AuthorDate: Thu Jun 29 15:50:29 2023 -0400
NO-JIRA: Make pn_bytes()/pn_rwbytes() inlinable
---
c/include/proton/types.h | 12 ++++++++++--
c/src/core/types.c | 13 ++-----------
2 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/c/include/proton/types.h b/c/include/proton/types.h
index becf3fa63..2fed2b74d 100644
--- a/c/include/proton/types.h
+++ b/c/include/proton/types.h
@@ -223,7 +223,11 @@ typedef struct pn_bytes_t {
*
* @ingroup api_types
*/
-PN_EXTERN pn_bytes_t pn_bytes(size_t size, const char *start);
+PN_EXTERN inline pn_bytes_t pn_bytes(size_t size, const char *start)
+{
+ pn_bytes_t bytes = {size, start};
+ return bytes;
+}
PN_EXTERN extern const pn_bytes_t pn_bytes_null;
@@ -242,7 +246,11 @@ typedef struct pn_rwbytes_t {
*
* @ingroup api_types
*/
-PN_EXTERN pn_rwbytes_t pn_rwbytes(size_t size, char *start);
+PN_EXTERN inline pn_rwbytes_t pn_rwbytes(size_t size, char *start)
+{
+ pn_rwbytes_t bytes = {size, start};
+ return bytes;
+}
PN_EXTERN extern const pn_rwbytes_t pn_rwbytes_null;
diff --git a/c/src/core/types.c b/c/src/core/types.c
index 0ca2bfc32..fc64b38cb 100644
--- a/c/src/core/types.c
+++ b/c/src/core/types.c
@@ -24,14 +24,5 @@
const pn_bytes_t pn_bytes_null = { 0, NULL };
const pn_rwbytes_t pn_rwbytes_null = { 0, NULL };
-pn_bytes_t pn_bytes(size_t size, const char *start)
-{
- pn_bytes_t bytes = {size, start};
- return bytes;
-}
-
-pn_rwbytes_t pn_rwbytes(size_t size, char *start)
-{
- pn_rwbytes_t bytes = {size, start};
- return bytes;
-}
+extern inline pn_bytes_t pn_bytes(size_t size, const char *start);
+extern inline pn_rwbytes_t pn_rwbytes(size_t size, char *start);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[qpid-proton] 06/06: PROTON-2752: Make more use of pn_string_t instead of char*
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astitcher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
commit 97fcd648fd826a68b3e0d681d054c11031e6b06a
Author: Andrew Stitcher <as...@apache.org>
AuthorDate: Wed Jul 5 23:38:46 2023 -0400
PROTON-2752: Make more use of pn_string_t instead of char*
---
c/src/core/emitters.h | 16 ++++-----
c/src/core/message.c | 14 ++++----
c/src/core/object/string.c | 13 +++++--
c/src/core/object_private.h | 1 +
c/src/core/transport.c | 72 ++++++++++++++++++-------------------
c/src/core/util.h | 4 ---
c/src/sasl/sasl-internal.h | 4 +--
c/src/sasl/sasl.c | 31 ++++++++--------
c/tools/codec-generator/generate.py | 4 +--
9 files changed, 82 insertions(+), 77 deletions(-)
diff --git a/c/src/core/emitters.h b/c/src/core/emitters.h
index a9399ba5c..46cec39db 100644
--- a/c/src/core/emitters.h
+++ b/c/src/core/emitters.h
@@ -414,23 +414,19 @@ static inline void emit_symbol_bytes(pni_emitter_t* emitter, pni_compound_contex
compound->count++;
}
-static inline void emit_symbol(pni_emitter_t* emitter, pni_compound_context* compound, const char* symbol) {
- // FIXME: Yuck we need to use strlen to find the end of the string - would be better to take pn_bytes_t
- if (symbol == NULL) {
+static inline void emit_symbol(pni_emitter_t* emitter, pni_compound_context* compound, pn_bytes_t bytes) {
+ if (bytes.start == NULL) {
emit_null(emitter, compound);
} else {
- size_t size = strlen(symbol);
- emit_symbol_bytes(emitter, compound, (pn_bytes_t){.size = size, .start = symbol});
+ emit_symbol_bytes(emitter, compound, bytes);
}
}
-static inline void emit_string(pni_emitter_t* emitter, pni_compound_context* compound, const char* string) {
- // FIXME: Yuck we need to use strlen to find the end of the string - would be better to take pn_bytes_t
- if (string == NULL) {
+static inline void emit_string(pni_emitter_t* emitter, pni_compound_context* compound, pn_bytes_t bytes) {
+ if (bytes.start == NULL) {
emit_null(emitter, compound);
} else {
- size_t size = strlen(string);
- emit_string_bytes(emitter, compound, (pn_bytes_t){.size = size, .start = string});
+ emit_string_bytes(emitter, compound, bytes);
}
}
diff --git a/c/src/core/message.c b/c/src/core/message.c
index dd12a4207..b4def0b14 100644
--- a/c/src/core/message.c
+++ b/c/src/core/message.c
@@ -856,22 +856,22 @@ int pn_message_encode(pn_message_t *msg, char *bytes, size_t *isize)
last_size = pn_amqp_encode_bytes_DLEazSSSassQtQtSQISe(bytes, remaining, PROPERTIES,
&id,
pn_string_size(msg->user_id), pn_string_get(msg->user_id),
- pn_string_get(msg->address),
- pn_string_get(msg->subject),
- pn_string_get(msg->reply_to),
+ pn_string_bytes(msg->address),
+ pn_string_bytes(msg->subject),
+ pn_string_bytes(msg->reply_to),
&correlation_id,
- pn_string_get(msg->content_type),
- pn_string_get(msg->content_encoding),
+ pn_string_bytes(msg->content_type),
+ pn_string_bytes(msg->content_encoding),
(bool)msg->expiry_time, msg->expiry_time,
(bool)msg->creation_time, msg->creation_time,
- pn_string_get(msg->group_id),
+ pn_string_bytes(msg->group_id),
/*
* As a heuristic, null out group_sequence if there is no group_id and
* group_sequence is 0. In this case it is extremely unlikely we want
* group semantics
*/
(bool)pn_string_get(msg->group_id) || (bool)msg->group_sequence , msg->group_sequence,
- pn_string_get(msg->reply_to_group_id));
+ pn_string_bytes(msg->reply_to_group_id));
if (last_size > remaining) return PN_OVERFLOW;
remaining -= last_size;
diff --git a/c/src/core/object/string.c b/c/src/core/object/string.c
index efcb642f3..e773226fc 100644
--- a/c/src/core/object/string.c
+++ b/c/src/core/object/string.c
@@ -36,8 +36,8 @@
struct pn_string_t {
char *bytes;
- ssize_t size; // PNI_NULL_SIZE (-1) means null
- size_t capacity;
+ int32_t size; // PNI_NULL_SIZE (-1) means null
+ uint32_t capacity;
};
static void pn_string_finalize(void *object)
@@ -136,6 +136,15 @@ size_t pn_string_size(pn_string_t *string)
}
}
+pn_bytes_t pn_string_bytes(pn_string_t *string)
+{
+ if (!string || string->size == PNI_NULL_SIZE) {
+ return (pn_bytes_t){0, NULL};
+ } else {
+ return (pn_bytes_t){string->size, string->bytes};
+ }
+}
+
int pn_string_set(pn_string_t *string, const char *bytes)
{
return pn_string_setn(string, bytes, bytes ? strlen(bytes) : 0);
diff --git a/c/src/core/object_private.h b/c/src/core/object_private.h
index 12a784506..c6864625e 100644
--- a/c/src/core/object_private.h
+++ b/c/src/core/object_private.h
@@ -177,6 +177,7 @@ PN_EXTERN void *pn_hash_value(pn_hash_t *hash, pn_handle_t entry);
PN_EXTERN pn_string_t *pn_string(const char *bytes);
PN_EXTERN const char *pn_string_get(pn_string_t *string);
+pn_bytes_t pn_string_bytes(pn_string_t *string);
PN_EXTERN pn_string_t *pn_stringn(const char *bytes, size_t n);
PN_EXTERN size_t pn_string_size(pn_string_t *string);
PN_EXTERN int pn_string_set(pn_string_t *string, const char *bytes);
diff --git a/c/src/core/transport.c b/c/src/core/transport.c
index 8e3fe2373..5dd37e43e 100644
--- a/c/src/core/transport.c
+++ b/c/src/core/transport.c
@@ -951,17 +951,17 @@ static int pni_post_close(pn_transport_t *transport, pn_condition_t *cond)
if (!cond && transport->connection) {
cond = pn_connection_condition(transport->connection);
}
- const char *condition = NULL;
- const char *description = NULL;
+ pn_string_t *condition = NULL;
+ pn_string_t *description = NULL;
pn_data_t *info = NULL;
if (pn_condition_is_set(cond)) {
- condition = pn_condition_get_name(cond);
- description = pn_condition_get_description(cond);
+ condition = cond->name;
+ description = cond->description;
info = pn_condition_info(cond);
}
/* "DL[?DL[sSC]]" */
pn_bytes_t buf = pn_amqp_encode_DLEQDLEsSCee(&transport->scratch_space, CLOSE,
- (bool) condition, ERROR, condition, description, info);
+ (bool) condition, ERROR, pn_string_bytes(condition), pn_string_bytes(description), info);
return pn_framing_send_amqp(transport, 0, buf);
}
@@ -1193,16 +1193,16 @@ static pn_distribution_mode_t symbol2dist_mode(const pn_bytes_t symbol)
return PN_DIST_MODE_UNSPECIFIED;
}
-static const char *dist_mode2symbol(const pn_distribution_mode_t mode)
+static pn_bytes_t dist_mode2symbol(const pn_distribution_mode_t mode)
{
switch (mode)
{
case PN_DIST_MODE_COPY:
- return "copy";
+ return PN_BYTES_LITERAL(copy);
case PN_DIST_MODE_MOVE:
- return "move";
+ return PN_BYTES_LITERAL(move);
default:
- return NULL;
+ return (pn_bytes_t){0, NULL};
}
}
@@ -1868,12 +1868,13 @@ static int pni_process_conn_setup(pn_transport_t *transport, pn_endpoint_t *endp
? (transport->local_idle_timeout/2)
: 0;
pn_connection_t *connection = (pn_connection_t *) endpoint;
- const char *cid = pn_string_get(connection->container);
+ pn_bytes_t cid = pn_string_bytes(connection->container);
+ if (cid.start==NULL) cid = (pn_bytes_t){.size=0, .start=""};
pni_calculate_channel_max(transport);
/* "DL[SS?I?H?InnMMC]" */
pn_bytes_t buf = pn_amqp_encode_DLESSQIQHQInnMMCe(&transport->scratch_space, OPEN,
- cid ? cid : "",
- pn_string_get(connection->hostname),
+ cid,
+ pn_string_bytes(connection->hostname),
// TODO: This is messy, because we also have to allow local_max_frame_ to be 0 to mean unlimited
// otherwise flow control goes wrong
transport->local_max_frame!=0 && transport->local_max_frame!=OPEN_MAX_FRAME_SIZE_DEFAULT,
@@ -1973,22 +1974,22 @@ static int pni_process_ssn_setup(pn_transport_t *transport, pn_endpoint_t *endpo
return 0;
}
-static const char *expiry_symbol(pn_terminus_t* terminus)
+static pn_bytes_t expiry_symbol(pn_terminus_t* terminus)
{
- if (!terminus->has_expiry_policy) return NULL;
+ if (!terminus->has_expiry_policy) return (pn_bytes_t){0, NULL};
switch (terminus->expiry_policy)
{
case PN_EXPIRE_WITH_LINK:
- return "link-detach";
+ return PN_BYTES_LITERAL(link-detach);
case PN_EXPIRE_WITH_SESSION:
- return "session-end";
+ return PN_BYTES_LITERAL(session-end);
case PN_EXPIRE_WITH_CONNECTION:
- return "connection-close";
+ return PN_BYTES_LITERAL(connection-close);
case PN_EXPIRE_NEVER:
- return "never";
+ return PN_BYTES_LITERAL(never);
}
- return NULL;
+ return (pn_bytes_t){0, NULL};
}
static int pni_map_local_handle(pn_link_t *link) {
@@ -2020,15 +2021,14 @@ static int pni_process_link_setup(pn_transport_t *transport, pn_endpoint_t *endp
}
const pn_distribution_mode_t dist_mode = (pn_distribution_mode_t) link->source.distribution_mode;
if (link->target.type == PN_COORDINATOR) {
- /* "DL[SIoBB?DL[SIsIoC?sCnCC]DL[C]nnI]" */
pn_bytes_t buf = pn_amqp_encode_DLESIoBBQDLESIsIoCQsCnCCeDLECennIe(&transport->scratch_space, ATTACH,
- pn_string_get(link->name),
+ pn_string_bytes(link->name),
state->local_handle,
endpoint->type == RECEIVER,
link->snd_settle_mode,
link->rcv_settle_mode,
(bool) link->source.type, SOURCE,
- pn_string_get(link->source.address),
+ pn_string_bytes(link->source.address),
link->source.durability,
expiry_symbol(&link->source),
link->source.timeout,
@@ -2045,14 +2045,14 @@ static int pni_process_link_setup(pn_transport_t *transport, pn_endpoint_t *endp
} else {
/* "DL[SIoBB?DL[SIsIoC?sCnMM]?DL[SIsIoCM]nnILnnC]" */
pn_bytes_t buf = pn_amqp_encode_DLESIoBBQDLESIsIoCQsCnMMeQDLESIsIoCMennILnnCe(&transport->scratch_space, ATTACH,
- pn_string_get(link->name),
+ pn_string_bytes(link->name),
state->local_handle,
endpoint->type == RECEIVER,
link->snd_settle_mode,
link->rcv_settle_mode,
(bool) link->source.type, SOURCE,
- pn_string_get(link->source.address),
+ pn_string_bytes(link->source.address),
link->source.durability,
expiry_symbol(&link->source),
link->source.timeout,
@@ -2064,7 +2064,7 @@ static int pni_process_link_setup(pn_transport_t *transport, pn_endpoint_t *endp
link->source.capabilities,
(bool) link->target.type, TARGET,
- pn_string_get(link->target.address),
+ pn_string_bytes(link->target.address),
link->target.durability,
expiry_symbol(&link->target),
link->target.timeout,
@@ -2391,20 +2391,20 @@ static int pni_process_link_teardown(pn_transport_t *transport, pn_endpoint_t *e
(int16_t) ssn_state->remote_channel != -2 &&
!transport->close_rcvd) return 0;
- const char *name = NULL;
- const char *description = NULL;
+ pn_string_t *name = NULL;
+ pn_string_t *description = NULL;
pn_data_t *info = NULL;
if (pn_condition_is_set(&endpoint->condition)) {
- name = pn_condition_get_name(&endpoint->condition);
- description = pn_condition_get_description(&endpoint->condition);
+ name = endpoint->condition.name;
+ description = endpoint->condition.description;
info = pn_condition_info(&endpoint->condition);
}
/* "DL[I?o?DL[sSC]]" */
pn_bytes_t buf = pn_amqp_encode_DLEIQoQDLEsSCee(&transport->scratch_space, DETACH,
state->local_handle,
!link->detached, !link->detached,
- (bool)name, ERROR, name, description, info);
+ (bool)name, ERROR, pn_string_bytes(name), pn_string_bytes(description), info);
int err = pn_framing_send_amqp(transport, ssn_state->local_channel, buf);
if (err) return err;
pni_unmap_local_handle(link);
@@ -2467,18 +2467,18 @@ static int pni_process_ssn_teardown(pn_transport_t *transport, pn_endpoint_t *en
return 0;
}
- const char *name = NULL;
- const char *description = NULL;
+ pn_string_t *name = NULL;
+ pn_string_t *description = NULL;
pn_data_t *info = NULL;
if (pn_condition_is_set(&endpoint->condition)) {
- name = pn_condition_get_name(&endpoint->condition);
- description = pn_condition_get_description(&endpoint->condition);
+ name = endpoint->condition.name;
+ description = endpoint->condition.description;
info = pn_condition_info(&endpoint->condition);
}
/* "DL[?DL[sSC]]" */
pn_bytes_t buf = pn_amqp_encode_DLEQDLEsSCee(&transport->scratch_space, END,
- (bool) name, ERROR, name, description, info);
+ (bool) name, ERROR, pn_string_bytes(name), pn_string_bytes(description), info);
int err = pn_framing_send_amqp(transport, state->local_channel, buf);
if (err) return err;
pni_unmap_local_channel(session);
@@ -2554,7 +2554,7 @@ static void pn_error_amqp(pn_transport_t* transport, unsigned int layer)
if (!transport->close_sent) {
if (!transport->open_sent) {
/* "DL[S]" */
- pn_bytes_t buf = pn_amqp_encode_DLESe(&transport->scratch_space, OPEN, "");
+ pn_bytes_t buf = pn_amqp_encode_DLESe(&transport->scratch_space, OPEN, (pn_bytes_t){.size=0, .start=""});
pn_framing_send_amqp(transport, 0, buf);
}
diff --git a/c/src/core/util.h b/c/src/core/util.h
index ceb70720f..d55d7b898 100644
--- a/c/src/core/util.h
+++ b/c/src/core/util.h
@@ -51,10 +51,6 @@ static inline bool pn_bytes_equal(const pn_bytes_t a, const pn_bytes_t b) {
return (a.size == b.size && !memcmp(a.start, b.start, a.size));
}
-static inline pn_bytes_t pn_string_bytes(struct pn_string_t *s) {
- return pn_bytes(pn_string_size(s), pn_string_get(s));
-}
-
static inline pn_bytes_t pn_bytes_dup(pn_bytes_t in) {
if (in.size) {
char* rbytes = malloc(in.size);
diff --git a/c/src/sasl/sasl-internal.h b/c/src/sasl/sasl-internal.h
index 376854e0e..ae183361e 100644
--- a/c/src/sasl/sasl-internal.h
+++ b/c/src/sasl/sasl-internal.h
@@ -41,13 +41,13 @@ void pni_sasl_set_external_security(pn_transport_t *transport, int ssf, const ch
struct pni_sasl_t {
void *impl_context;
const pnx_sasl_implementation* impl;
- char *selected_mechanism;
+ pn_string_t *selected_mechanism;
char *included_mechanisms;
const char *username;
const char *authzid;
char *password;
const char *remote_fqdn;
- char *local_fqdn;
+ pn_string_t *local_fqdn;
char *external_auth;
int external_ssf;
size_t max_encrypt_size;
diff --git a/c/src/sasl/sasl.c b/c/src/sasl/sasl.c
index 0dff90a6a..517a73dc4 100644
--- a/c/src/sasl/sasl.c
+++ b/c/src/sasl/sasl.c
@@ -136,7 +136,7 @@ const char *pnx_sasl_get_remote_fqdn(pn_transport_t *transport)
const char *pnx_sasl_get_selected_mechanism(pn_transport_t *transport)
{
- return transport->sasl ? transport->sasl->selected_mechanism : NULL;
+ return transport->sasl ? pn_string_get(transport->sasl->selected_mechanism) : NULL;
}
void pnx_sasl_set_bytes_out(pn_transport_t *transport, pn_bytes_t bytes)
@@ -149,7 +149,7 @@ void pnx_sasl_set_bytes_out(pn_transport_t *transport, pn_bytes_t bytes)
void pnx_sasl_set_selected_mechanism(pn_transport_t *transport, const char *mechanism)
{
if (transport->sasl) {
- transport->sasl->selected_mechanism = pn_strdup(mechanism);
+ transport->sasl->selected_mechanism = pn_string(mechanism);
}
}
@@ -163,10 +163,10 @@ void pnx_sasl_set_succeeded(pn_transport_t *transport, const char *username, co
if (authzid) {
PN_LOG(&transport->logger, PN_SUBSYSTEM_SASL, PN_LEVEL_INFO, "Authenticated user: %s for %s with mechanism %s",
- username, authzid, transport->sasl->selected_mechanism);
+ username, authzid, pn_string_get(transport->sasl->selected_mechanism));
} else {
PN_LOG(&transport->logger, PN_SUBSYSTEM_SASL, PN_LEVEL_INFO, "Authenticated user: %s with mechanism %s",
- username, transport->sasl->selected_mechanism);
+ username, pn_string_get(transport->sasl->selected_mechanism));
}
}
}
@@ -491,7 +491,7 @@ static void pni_post_sasl_frame(pn_transport_t *transport)
switch (desired_state) {
case SASL_POSTED_INIT: {
/* GENERATE_CODEC_CODE: "DL[szS]" */
- pn_bytes_t buf = pn_amqp_encode_DLEszSe(&transport->scratch_space, SASL_INIT, sasl->selected_mechanism, out.size, out.start, sasl->local_fqdn);
+ pn_bytes_t buf = pn_amqp_encode_DLEszSe(&transport->scratch_space, SASL_INIT, pn_string_bytes(sasl->selected_mechanism), out.size, out.start, pn_string_bytes(sasl->local_fqdn));
pn_framing_send_sasl(transport, buf);
pni_emit(transport);
break;
@@ -541,8 +541,9 @@ static void pni_post_sasl_frame(pn_transport_t *transport)
pn_framing_send_sasl(transport, buf);
pni_emit(transport);
if (sasl->outcome!=PN_SASL_OK) {
+ const char *selected_mechanism = transport->sasl->selected_mechanism ? pn_string_get(transport->sasl->selected_mechanism) : NULL;
pn_do_error(transport, "amqp:unauthorized-access", "Failed to authenticate client [mech=%s]",
- transport->sasl->selected_mechanism ? transport->sasl->selected_mechanism : "none");
+ selected_mechanism ? selected_mechanism : "none");
desired_state = SASL_ERROR;
}
break;
@@ -553,11 +554,13 @@ static void pni_post_sasl_frame(pn_transport_t *transport)
continue;
}
break;
- case SASL_RECVED_FAILURE:
+ case SASL_RECVED_FAILURE: {
+ const char *selected_mechanism = transport->sasl->selected_mechanism ? pn_string_get(transport->sasl->selected_mechanism) : NULL;
pn_do_error(transport, "amqp:unauthorized-access", "Authentication failed [mech=%s]",
- transport->sasl->selected_mechanism ? transport->sasl->selected_mechanism : "none");
+ selected_mechanism ? selected_mechanism : "none");
desired_state = SASL_ERROR;
break;
+ }
case SASL_ERROR:
break;
case SASL_NONE:
@@ -793,11 +796,11 @@ void pn_sasl_free(pn_transport_t *transport)
if (transport) {
pni_sasl_t *sasl = transport->sasl;
if (sasl) {
- free(sasl->selected_mechanism);
+ pn_free(sasl->selected_mechanism);
free(sasl->included_mechanisms);
free(sasl->password);
free(sasl->external_auth);
- free(sasl->local_fqdn);
+ pn_free(sasl->local_fqdn);
if (sasl->impl_context) {
pni_sasl_impl_free(transport);
@@ -818,7 +821,7 @@ void pni_sasl_set_remote_hostname(pn_transport_t * transport, const char * fqdn)
void pnx_sasl_set_local_hostname(pn_transport_t * transport, const char * fqdn)
{
pni_sasl_t *sasl = transport->sasl;
- sasl->local_fqdn = pn_strdup(fqdn);
+ sasl->local_fqdn = pn_string(fqdn);
}
void pni_sasl_set_user_password(pn_transport_t *transport, const char *user, const char *authzid, const char *password)
@@ -853,7 +856,7 @@ const char *pn_sasl_get_authorization(pn_sasl_t *sasl0)
const char *pn_sasl_get_mech(pn_sasl_t *sasl0)
{
pni_sasl_t *sasl = get_sasl_internal(sasl0);
- return sasl->selected_mechanism;
+ return pn_string_get(sasl->selected_mechanism);
}
void pn_sasl_allowed_mechs(pn_sasl_t *sasl0, const char *mechs)
@@ -905,7 +908,7 @@ int pn_do_init(pn_transport_t *transport, uint8_t frame_type, uint16_t channel,
pn_bytes_t recv;
pn_amqp_decode_DqEsze(payload, &mech, &recv);
- sasl->selected_mechanism = pn_strndup(mech.start, mech.size);
+ sasl->selected_mechanism = pn_stringn(mech.start, mech.size);
// We need to filter out a supplied mech in in the inclusion list
// as the client could have used a mech that we support, but that
@@ -915,7 +918,7 @@ int pn_do_init(pn_transport_t *transport, uint8_t frame_type, uint16_t channel,
sasl->outcome = PN_SASL_AUTH;
pnx_sasl_set_desired_state(transport, SASL_POSTED_OUTCOME);
} else {
- pni_sasl_impl_process_init(transport, sasl->selected_mechanism, &recv);
+ pni_sasl_impl_process_init(transport, pn_string_get(sasl->selected_mechanism), &recv);
}
return 0;
diff --git a/c/tools/codec-generator/generate.py b/c/tools/codec-generator/generate.py
index e9ec2445c..260edf80f 100644
--- a/c/tools/codec-generator/generate.py
+++ b/c/tools/codec-generator/generate.py
@@ -304,9 +304,9 @@ def parse_item(format: str) -> Tuple[ASTNode, str]:
elif format.startswith('.'):
return NullNode('anything'), format[1:]
elif format.startswith('s'):
- return ASTNode('symbol', ['const char*'], consume_types=['pn_bytes_t*']), format[1:]
+ return ASTNode('symbol', ['pn_bytes_t'], consume_types=['pn_bytes_t*']), format[1:]
elif format.startswith('S'):
- return ASTNode('string', ['const char*'], consume_types=['pn_bytes_t*']), format[1:]
+ return ASTNode('string', ['pn_bytes_t'], consume_types=['pn_bytes_t*']), format[1:]
elif format.startswith('C'):
return ASTNode('copy', ['pn_data_t*'], consume_types=['pn_data_t*']), format[1:]
elif format.startswith('I'):
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org
[qpid-proton] 04/06: PROTON-2751: Don't use pn_buffer for delivery tag
Posted by as...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
astitcher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
commit f2693f29d1226b224477c3eab62654c49499ec6b
Author: Andrew Stitcher <as...@apache.org>
AuthorDate: Tue May 9 16:24:29 2023 -0400
PROTON-2751: Don't use pn_buffer for delivery tag
---
c/src/core/engine-internal.h | 2 +-
c/src/core/engine.c | 19 +++++++++----------
c/src/core/transport.c | 9 ++++-----
c/src/core/util.h | 14 ++++++++++++++
4 files changed, 28 insertions(+), 16 deletions(-)
diff --git a/c/src/core/engine-internal.h b/c/src/core/engine-internal.h
index 4cf6ea502..69f8a8293 100644
--- a/c/src/core/engine-internal.h
+++ b/c/src/core/engine-internal.h
@@ -330,8 +330,8 @@ struct pn_disposition_t {
struct pn_delivery_t {
pn_disposition_t local;
pn_disposition_t remote;
+ pn_delivery_tag_t tag;
pn_link_t *link; // reference counted
- pn_buffer_t *tag;
pn_delivery_t *unsettled_next;
pn_delivery_t *unsettled_prev;
pn_delivery_t *work_next;
diff --git a/c/src/core/engine.c b/c/src/core/engine.c
index 70138566d..02c41299b 100644
--- a/c/src/core/engine.c
+++ b/c/src/core/engine.c
@@ -1471,7 +1471,8 @@ static void pn_delivery_finalize(void *object)
? &link->session->state.outgoing
: &link->session->state.incoming,
delivery);
- pn_buffer_clear(delivery->tag);
+ pn_bytes_free(delivery->tag);
+ delivery->tag = (pn_delivery_tag_t){0, NULL};
pn_buffer_clear(delivery->bytes);
pn_record_clear(delivery->context);
delivery->settled = true;
@@ -1488,7 +1489,8 @@ static void pn_delivery_finalize(void *object)
if (!pooled) {
pn_free(delivery->context);
- pn_buffer_free(delivery->tag);
+ pn_bytes_free(delivery->tag);
+ delivery->tag = (pn_delivery_tag_t){0, NULL};
pn_buffer_free(delivery->bytes);
pn_disposition_finalize(&delivery->local);
pn_disposition_finalize(&delivery->remote);
@@ -1522,7 +1524,7 @@ static void pn_disposition_clear(pn_disposition_t *ds)
void pn_delivery_inspect(void *obj, pn_fixed_string_t *dst) {
pn_delivery_t *d = (pn_delivery_t*)obj;
const char* dir = pn_link_is_sender(d->link) ? "sending" : "receiving";
- pn_bytes_t bytes = pn_buffer_bytes(d->tag);
+ pn_bytes_t bytes = d->tag;
pn_fixed_string_addf(dst, "pn_delivery<%p>{%s, tag=b\"", obj, dir);
pn_fixed_string_quote(dst, bytes.start, bytes.size);
pn_fixed_string_addf(dst, "\", local=%s, remote=%s}",
@@ -1544,7 +1546,6 @@ pn_delivery_t *pn_delivery(pn_link_t *link, pn_delivery_tag_t tag)
if (!delivery) {
delivery = (pn_delivery_t *) pn_class_new(&PN_CLASSCLASS(pn_delivery), sizeof(pn_delivery_t));
if (!delivery) return NULL;
- delivery->tag = pn_buffer(16);
delivery->bytes = pn_buffer(64);
pn_disposition_init(&delivery->local);
pn_disposition_init(&delivery->remote);
@@ -1554,8 +1555,7 @@ pn_delivery_t *pn_delivery(pn_link_t *link, pn_delivery_tag_t tag)
}
delivery->link = link;
pn_incref(delivery->link); // keep link until finalized
- pn_buffer_clear(delivery->tag);
- pn_buffer_append(delivery->tag, tag.start, tag.size);
+ delivery->tag = pn_bytes_dup(tag);
pn_disposition_clear(&delivery->local);
pn_disposition_clear(&delivery->remote);
delivery->updated = false;
@@ -1640,7 +1640,7 @@ bool pn_delivery_current(pn_delivery_t *delivery)
void pn_delivery_dump(pn_delivery_t *d)
{
char tag[1024];
- pn_bytes_t bytes = pn_buffer_bytes(d->tag);
+ pn_bytes_t bytes = d->tag;
pn_quote_data(tag, 1024, bytes.start, bytes.size);
printf("{tag=%s, local.type=%" PRIu64 ", remote.type=%" PRIu64 ", local.settled=%u, "
"remote.settled=%u, updated=%u, current=%u, writable=%u, readable=%u, "
@@ -1743,10 +1743,9 @@ pn_condition_t *pn_disposition_condition(pn_disposition_t *disposition)
pn_delivery_tag_t pn_delivery_tag(pn_delivery_t *delivery)
{
if (delivery) {
- pn_bytes_t tag = pn_buffer_bytes(delivery->tag);
- return pn_dtag(tag.start, tag.size);
+ return delivery->tag;
} else {
- return pn_dtag(0, 0);
+ return (pn_delivery_tag_t){0, NULL};
}
}
diff --git a/c/src/core/transport.c b/c/src/core/transport.c
index e414789e5..8e3fe2373 100644
--- a/c/src/core/transport.c
+++ b/c/src/core/transport.c
@@ -883,7 +883,7 @@ static int pni_post_amqp_transfer_frame(pn_transport_t *transport, uint16_t ch,
uint32_t handle,
pn_sequence_t id,
pn_bytes_t *full_payload,
- const pn_bytes_t *tag,
+ const pn_bytes_t tag,
uint32_t message_format,
bool settled,
bool more,
@@ -904,7 +904,7 @@ static int pni_post_amqp_transfer_frame(pn_transport_t *transport, uint16_t ch,
pn_amqp_encode_DLEIIzIQoQonQDLCQoQoQoe(&transport->scratch_space, TRANSFER,
handle,
id,
- tag->size, tag->start,
+ tag.size, tag.start,
message_format,
settled, settled,
more_flag, more_flag,
@@ -916,7 +916,7 @@ static int pni_post_amqp_transfer_frame(pn_transport_t *transport, uint16_t ch,
return PN_ERR;
}
- // At this point the side affect of the fill is to encode the performative into transport->frame
+ // At this point the side affect of the fill is to encode the performative into transport->scratch_space
do { // send as many frames as possible without changing the 'more' flag...
@@ -2222,13 +2222,12 @@ static int pni_process_tpwork_sender(pn_transport_t *transport, pn_delivery_t *d
pn_bytes_t bytes = pn_buffer_bytes(delivery->bytes);
size_t full_size = bytes.size;
- pn_bytes_t tag = pn_buffer_bytes(delivery->tag);
pn_data_clear(transport->disp_data);
PN_RETURN_IF_ERROR(pni_disposition_encode(&delivery->local, transport->disp_data));
int count = pni_post_amqp_transfer_frame(transport,
ssn_state->local_channel,
link_state->local_handle,
- state->id, &bytes, &tag,
+ state->id, &bytes, delivery->tag,
0, // message-format
delivery->local.settled,
!delivery->done,
diff --git a/c/src/core/util.h b/c/src/core/util.h
index 7ed5b925f..ceb70720f 100644
--- a/c/src/core/util.h
+++ b/c/src/core/util.h
@@ -55,6 +55,20 @@ static inline pn_bytes_t pn_string_bytes(struct pn_string_t *s) {
return pn_bytes(pn_string_size(s), pn_string_get(s));
}
+static inline pn_bytes_t pn_bytes_dup(pn_bytes_t in) {
+ if (in.size) {
+ char* rbytes = malloc(in.size);
+ memcpy(rbytes, in.start, in.size);
+ return (pn_bytes_t){in.size, rbytes};
+ } else {
+ return (pn_bytes_t){0, NULL};
+ }
+}
+
+static inline void pn_bytes_free(pn_bytes_t in) {
+ free((void*)in.start);
+}
+
static inline pn_rwbytes_t pn_rwbytes_alloc(size_t size) {
char* space = malloc(size);
size_t s = space ? size : 0;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org