Skip to content

Commit

Permalink
libopenarc: use standard strings in external interfaces
Browse files Browse the repository at this point in the history
Since we've already slightly problematized API compatibility with the
const change, we might as well do this also.

This makes the interface easier to use, and makes it clear to callers
which arguments are normal strings and which are binary strings.
  • Loading branch information
flowerysong committed Nov 1, 2024
1 parent 5e9c759 commit a2c3fdb
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 133 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ All notable changes to this project will be documented in this file.
are excluded from the AMS, as required by [RFC 8617 section 4.1.2](https://datatracker.ietf.org/doc/html/rfc8617#section-4.1.2).
- libopenarc - ARC headers are returned with a space before the header value.
- libopenarc - String arguments are marked as `const` where applicable.
- libopenarc - String arguments are normal strings (`char *`) unless the
argument expects a binary string.
- libopenarc - `ARC-Seal` headers containing `h=` tags cause a validation
failure, as required by [RFC 8617 section 4.1.3](https://datatracker.ietf.org/doc/html/rfc8617#section-4.1.3).
- milter - `Authentication-Results` and `ARC-Authentication-Results` include
Expand Down
12 changes: 6 additions & 6 deletions libopenarc/arc-canon.c
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ arc_canon_selecthdrs(ARC_MESSAGE *msg,
char *colon;
struct arc_hdrfield *hdr;
struct arc_hdrfield **lhdrs;
unsigned char **hdrs;
char **hdrs;

assert(msg != NULL);
assert(ptrs != NULL);
Expand Down Expand Up @@ -855,7 +855,7 @@ arc_canon_selecthdrs(ARC_MESSAGE *msg,
shcnt++;
}
}
hdrs = ARC_CALLOC(shcnt, sizeof(unsigned char *));
hdrs = ARC_CALLOC(shcnt, sizeof(char *));
if (hdrs == NULL)
{
ARC_FREE(lhdrs);
Expand All @@ -868,7 +868,7 @@ arc_canon_selecthdrs(ARC_MESSAGE *msg,
for (bar = strtok_r(msg->arc_hdrlist, ":", &ctx); bar != NULL;
bar = strtok_r(NULL, ":", &ctx))
{
hdrs[n] = (unsigned char *) bar;
hdrs[n] = bar;
n++;
}

Expand All @@ -878,7 +878,7 @@ arc_canon_selecthdrs(ARC_MESSAGE *msg,
{
lhdrs[shcnt] = NULL;

len = MIN(ARC_MAXHEADER, strlen((char *) hdrs[c]));
len = MIN(ARC_MAXHEADER, strlen(hdrs[c]));
while (len > 0 && ARC_ISWSP(hdrs[c][len - 1]))
{
len--;
Expand All @@ -892,7 +892,7 @@ arc_canon_selecthdrs(ARC_MESSAGE *msg,
}

if (len == hdr->hdr_namelen &&
strncasecmp((char *) hdr->hdr_text, (char *) hdrs[c], len) == 0)
strncasecmp(hdr->hdr_text, hdrs[c], len) == 0)
{
lhdrs[shcnt] = hdr;
}
Expand Down Expand Up @@ -1334,7 +1334,7 @@ arc_canon_runheaders(ARC_MESSAGE *msg)

/* terminate the header field name and test */
hdr->hdr_text[hdr->hdr_namelen] = '\0';
status = regexec(hdrtest, (char *) hdr->hdr_text, 0, NULL, 0);
status = regexec(hdrtest, hdr->hdr_text, 0, NULL, 0);

/* restore the character */
hdr->hdr_text[hdr->hdr_namelen] = savechar;
Expand Down
19 changes: 9 additions & 10 deletions libopenarc/arc-dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ arc_res_cancel(void *srv, void *qh)
*/

int
arc_res_query(void *srv,
int type,
const unsigned char *query,
unsigned char *buf,
size_t buflen,
void **qh)
arc_res_query(void *srv,
int type,
const char *query,
unsigned char *buf,
size_t buflen,
void **qh)
{
int n;
int ret;
Expand All @@ -180,11 +180,10 @@ arc_res_query(void *srv,

#ifdef HAVE_RES_NINIT
statp = srv;
n = res_nmkquery(statp, QUERY, (const char *) query, C_IN, type, NULL, 0,
NULL, qbuf, sizeof qbuf);
n = res_nmkquery(statp, QUERY, query, C_IN, type, NULL, 0, NULL, qbuf,
sizeof qbuf);
#else /* HAVE_RES_NINIT */
n = res_mkquery(QUERY, (const char *) query, C_IN, type, NULL, 0, NULL,
qbuf, sizeof qbuf);
n = res_mkquery(QUERY, query, C_IN, type, NULL, 0, NULL, qbuf, sizeof qbuf);
#endif /* HAVE_RES_NINIT */
if (n == (size_t) -1)
{
Expand Down
2 changes: 1 addition & 1 deletion libopenarc/arc-dns.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern void arc_res_close(void *);
extern int arc_res_init(void **);
extern int arc_res_nslist(void *, const char *);
extern int arc_res_query(
void *, int, const unsigned char *, unsigned char *, size_t, void **);
void *, int, const char *, unsigned char *, size_t, void **);
extern int arc_res_waitreply(
void *, void *, struct timeval *, size_t *, int *, int *);

Expand Down
4 changes: 2 additions & 2 deletions libopenarc/arc-keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ arc_get_key_dns(ARC_MESSAGE *msg, char *buf, size_t buflen)
return ARC_STAT_KEYFAIL;
}

status = lib->arcl_dns_start(lib->arcl_dns_service, T_TXT,
(unsigned char *) qname, ansbuf, anslen, &q);
status = lib->arcl_dns_start(lib->arcl_dns_service, T_TXT, qname, ansbuf,
anslen, &q);

if (status != 0)
{
Expand Down
12 changes: 6 additions & 6 deletions libopenarc/arc-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ struct arc_lib
void *arcl_dns_service;
int (*arcl_dns_init)(void **srv);
void (*arcl_dns_close)(void *srv);
int (*arcl_dns_start)(void *srv,
int type,
const unsigned char *query,
unsigned char *buf,
size_t buflen,
void **qh);
int (*arcl_dns_start)(void *srv,
int type,
const char *query,
unsigned char *buf,
size_t buflen,
void **qh);
int (*arcl_dns_cancel)(void *srv, void *qh);
int (*arcl_dns_waitreply)(void *srv,
void *qh,
Expand Down
21 changes: 9 additions & 12 deletions libopenarc/arc-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,14 @@
*/

bool
arc_hdrlist(unsigned char *buf,
size_t buflen,
unsigned char **hdrlist,
bool first)
arc_hdrlist(char *buf, size_t buflen, char **hdrlist, bool first)
{
bool escape = false;
int c;
int len;
unsigned char *p;
unsigned char *q;
unsigned char *end;
bool escape = false;
int c;
int len;
char *p;
char *q;
char *end;

assert(buf != NULL);
assert(hdrlist != NULL);
Expand All @@ -78,15 +75,15 @@ arc_hdrlist(unsigned char *buf,

if (!first)
{
len = strlcat((char *) buf, "|", buflen);
len = strlcat(buf, "|", buflen);
if (len >= buflen)
{
return false;
}
}
else
{
len = strlen((char *) buf);
len = strlen(buf);
}

first = false;
Expand Down
2 changes: 1 addition & 1 deletion libopenarc/arc-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern int arc_check_dns_reply(unsigned char *ansbuf,
int xclass,
int xtype);

extern bool arc_hdrlist(unsigned char *, size_t, unsigned char **, bool);
extern bool arc_hdrlist(char *, size_t, char **, bool);

extern void arc_min_timeval(struct timeval *,
struct timeval *,
Expand Down
Loading

0 comments on commit a2c3fdb

Please sign in to comment.