Skip to content

Commit 3389bfa

Browse files
committed
endpoint: Allow to pass NULL params in no query string case
Previously if you had an endpoint that only took an optional query string and didn't want to pass one then you had to construct a params array with a NULL member. Make it so that in this case you can also just pass NULL, as you can do for an endpoint that does not take any parameters. Signed-off-by: Andrew Clayton <ac@sigsegv.uk>
1 parent 57dbb8f commit 3389bfa

3 files changed

Lines changed: 8 additions & 11 deletions

File tree

docs/man/man3/mtd_ep.3

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" Automatically generated by Pandoc 3.7.0.2
22
.\"
3-
.TH "mtd_ep" "3" "May 19, 2026" "Version 1.6.2" "libmtdac"
3+
.TH "mtd_ep" "3" "May 23, 2026" "Version 1.6.2+" "libmtdac"
44
.SH NAME
55
\f[B]mtd_ep\f[R] \- send query to API endpoint
66
.SH LIBRARY
@@ -58,11 +58,9 @@ extras will be ignored.
5858
There is no need to pass in how many entries is in params (or for it to
5959
be NULL terminated) as this is dictated by each endpoint.
6060
.PP
61-
For any endpoints which don\(cqt require \f[I]any\f[R] parameters, this
62-
can be \f[B]NULL\f[R].
63-
If an endpoint \f[I]only\f[R] takes an \f[I]optional\f[R] query stirng,
64-
then you still need a params with a single entry either containing NULL
65-
or a valid query string.
61+
For any endpoints which don\(cqt require \f[I]any\f[R] parameters,
62+
including endpoints that take an optional query string where you
63+
don\(aqt want to pass one, this can be \f[B]NULL\f[R].
6664
.PP
6765
\f[B]NOTE:\f[R] nino (National Insurance Number) is not included in the
6866
above as that is acquired by libmtdac via other means.

docs/mtd_ep.3.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,9 @@ This function is used to send a query to a specified API endpoint.
5757
There is no need to pass in how many entries is in params (or for it
5858
to be NULL terminated) as this is dictated by each endpoint.
5959

60-
For any endpoints which don’t require *any* parameters, this can be
61-
**NULL**. If an endpoint *only* takes an *optional* query stirng,
62-
then you still need a params with a single entry either containing
63-
NULL or a valid query string.
60+
For any endpoints which don’t require *any* parameters, including
61+
endpoints that take an optional query string where you don't want to
62+
pass one, this can be **NULL**.
6463

6564
**NOTE:** nino (National Insurance Number) is not included in the
6665
above as that is acquired by libmtdac via other means.

src/endpoint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ char *ep_make_url(enum mtd_api_endpoint ep, const char * const params[],
164164
snprintf(url + len, URL_LEN+1 - len, "/%s", nino);
165165
else if (strstr(token, "query_params"))
166166
snprintf(url + len, URL_LEN+1 - len, "%s",
167-
params[p] ? params[p++] : "");
167+
params && params[p] ? params[p++] : "");
168168
else
169169
snprintf(url + len, URL_LEN+1 - len, "/%s",
170170
params[p++]);

0 commit comments

Comments
 (0)