From 5da12ed7f12ea15016c48598eabfcc4f5f2e37d8 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Sun, 1 Sep 2024 12:04:32 +0100 Subject: [PATCH] network_http_post_bin added to network functions for all targets --- Changelog.md | 6 +++++- common/src/fn_network/network_http_post_bin.c | 16 ++++++++++++++++ fujinet-network.h | 16 ++++++++++++++-- version.txt | 2 +- 4 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 common/src/fn_network/network_http_post_bin.c diff --git a/Changelog.md b/Changelog.md index 26befd7..7370796 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,7 +2,11 @@ ## [Unreleased] -## [4.5.3] - 2024-08-32 +## [4.6.0] - 2024-09-01 + +- [network] Add network_http_post_bin function to allow sending binary data instead of text, allowing for 00 char to be sent. + +## [4.5.3] - 2024-08-30 - network_read and network_read_nb will exit if there is a general error. network_read will set fn_bytes_read to the bytes read into the buffer so far, for client to decide what to do. diff --git a/common/src/fn_network/network_http_post_bin.c b/common/src/fn_network/network_http_post_bin.c new file mode 100644 index 0000000..340fc37 --- /dev/null +++ b/common/src/fn_network/network_http_post_bin.c @@ -0,0 +1,16 @@ +#ifdef _CMOC_VERSION_ +#include +#else +#include +#include +#endif /* _CMOC_VERSION_ */ +#include "fujinet-network.h" + +uint8_t network_http_post_bin(char *devicespec, uint8_t *data, uint16_t len) { + uint8_t err; + err = network_http_set_channel_mode(devicespec, HTTP_CHAN_MODE_POST_SET_DATA); + if (err) return err; + err = network_write(devicespec, data, len); + if (err) return err; + return network_http_set_channel_mode(devicespec, HTTP_CHAN_MODE_BODY); +} diff --git a/fujinet-network.h b/fujinet-network.h index 18ebea7..f4923ff 100644 --- a/fujinet-network.h +++ b/fujinet-network.h @@ -206,15 +206,27 @@ uint8_t network_http_add_header(char *devicespec, char *header); /** - * @brief Send POST HTTP request + * @brief Send POST HTTP request - assumes data is a string with nul terminator. This will not be able to send the 00 byte * @param devicespec pointer to device specification, e.g. "N1:HTTPS://fujinet.online/" - * @param data data to post + * @param data text data to post * @return fujinet-network error code (See FN_ERR_* values) * * Assumes an open connection. */ uint8_t network_http_post(char *devicespec, char *data); + +/** + * @brief Send POST HTTP request, sends binary data from data location for length len, which allows sending arbitrary binary data + * @param devicespec pointer to device specification, e.g. "N1:HTTPS://fujinet.online/" + * @param data binary data to post + * @param len length of binary data to send + * @return fujinet-network error code (See FN_ERR_* values) + * + * Assumes an open connection. + */ +uint8_t network_http_post_bin(char *devicespec, uint8_t *data, uint16_t len); + /** * @brief Send PUT HTTP request * @param devicespec pointer to device specification, e.g. "N1:HTTPS://fujinet.online/" diff --git a/version.txt b/version.txt index ae6e65b..28446a5 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -4.5.3 \ No newline at end of file +4.6.0 \ No newline at end of file