Skip to content

Commit

Permalink
* src/ne_uri.h: Add "nonnull" attribute throughout. (closes #134)
Browse files Browse the repository at this point in the history
  • Loading branch information
notroj committed Nov 23, 2023
1 parent d85b401 commit b4cafc3
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions src/ne_uri.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
URI manipulation routines.
Copyright (C) 1999-2021, Joe Orton <joe@manyfish.co.uk>
Copyright (C) 1999-2023, Joe Orton <joe@manyfish.co.uk>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -30,7 +30,8 @@ NE_BEGIN_DECLS
* "unreserved" and the forward-slash character percent-encoded
* according to the URI encoding rules. Returns a malloc-allocated
* string and never NULL. */
char *ne_path_escape(const char *path);
char *ne_path_escape(const char *path)
ne_attribute((nonnull));

/* NE_PATH_NONRES - anything other than "unreserved" and the
* forward-slash character percent-encoded according to the URI
Expand All @@ -42,30 +43,37 @@ char *ne_path_escape(const char *path);
/* Return a copy of a path string with escaping applied per rules
* determined by any combination of NE_PATH_* flags given. Returns a
* malloc-allocated string and never NULL. */
char *ne_path_escapef(const char *path, unsigned int flags);
char *ne_path_escapef(const char *path, unsigned int flags)
ne_attribute((nonnull));

/* Return a decoded copy of a percent-encoded path string. Returns
* malloc-allocated path on success, or NULL if the string contained
* any syntactically invalid percent-encoding sequences. */
char *ne_path_unescape(const char *epath);
char *ne_path_unescape(const char *epath)
ne_attribute((nonnull));

/* Returns malloc-allocated parent of path, or NULL if path has no
* parent (such as "/"). */
char *ne_path_parent(const char *path);
char *ne_path_parent(const char *path)
ne_attribute((nonnull));

/* Returns strcmp-like value giving comparison between p1 and p2,
* ignoring trailing-slashes. */
int ne_path_compare(const char *p1, const char *p2);
int ne_path_compare(const char *p1, const char *p2)
ne_attribute((nonnull));

/* Returns non-zero if child is a child of parent */
int ne_path_childof(const char *parent, const char *child);
/* Returns non-zero if child is a child of parent. */
int ne_path_childof(const char *parent, const char *child)
ne_attribute((nonnull));

/* Returns non-zero if path has a trailing slash character */
int ne_path_has_trailing_slash(const char *path);
/* Returns non-zero if path has a trailing slash character. */
int ne_path_has_trailing_slash(const char *path)
ne_attribute((nonnull));

/* Return the default port for the given scheme, or 0 if none is
* known. */
unsigned int ne_uri_defaultport(const char *scheme);
unsigned int ne_uri_defaultport(const char *scheme)
ne_attribute((nonnull));

typedef struct {
char *scheme;
Expand All @@ -80,11 +88,13 @@ typedef struct {
* NULL, or point to malloc-allocated NUL-terminated strings;
* ne_uri_free can be used to free any set fields. On success,
* parsed->path is guaranteed to be non-NULL. */
int ne_uri_parse(const char *uri, ne_uri *parsed);
int ne_uri_parse(const char *uri, ne_uri *parsed)
ne_attribute((nonnull));

/* Turns a URI structure back into a string. The returned string is
* malloc-allocated, and must be freed by the caller. */
char *ne_uri_unparse(const ne_uri *uri);
char *ne_uri_unparse(const ne_uri *uri)
ne_attribute((nonnull));

/* Resolve a relative URI 'relative', with respect to base URI 'base',
* placing the resultant URI in '*result'. At least both base->path
Expand All @@ -94,20 +104,24 @@ char *ne_uri_unparse(const ne_uri *uri);
* guaranteed to be non-NULL. ne_uri_free can be used to free the
* result structure after use. Returns 'result'. */
ne_uri *ne_uri_resolve(const ne_uri *base, const ne_uri *relative,
ne_uri *result);
ne_uri *result)
ne_attribute((nonnull));

/* Compares URIs u1 and u2, returns non-zero if they are found to be
* non-equal. The sign of the return value is <0 if 'u1' is less than
* 'u2', or >0 if 'u2' is greater than 'u1'. */
int ne_uri_cmp(const ne_uri *u1, const ne_uri *u2);
int ne_uri_cmp(const ne_uri *u1, const ne_uri *u2)
ne_attribute((nonnull));

/* Copy components of URI 'src' to destination 'dest'. Returns
* 'dest'. */
ne_uri *ne_uri_copy(ne_uri *dest, const ne_uri *src);
ne_uri *ne_uri_copy(ne_uri *dest, const ne_uri *src)
ne_attribute((nonnull));

/* Frees any non-NULL fields of parsed URI structure *parsed. All
* fields are then zero-initialized. */
void ne_uri_free(ne_uri *parsed);
void ne_uri_free(ne_uri *parsed)
ne_attribute((nonnull));

NE_END_DECLS

Expand Down

0 comments on commit b4cafc3

Please sign in to comment.