Skip to content

Commit

Permalink
Removed unused code from H5FDs3comms.c
Browse files Browse the repository at this point in the history
* H5FD_s3comms_nlowercase()
* H5FD_s3comms_trim()
* H5FD_s3comms_uriencode()
  • Loading branch information
derobins committed Jun 19, 2024
1 parent a229778 commit 360ebb7
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 504 deletions.
199 changes: 0 additions & 199 deletions src/H5FDs3comms.c
Original file line number Diff line number Diff line change
Expand Up @@ -1967,51 +1967,6 @@ H5FD_s3comms_load_aws_profile(const char *profile_name, char *key_id_out, char *
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_s3comms_load_aws_profile() */

/*----------------------------------------------------------------------------
*
* Function: H5FD_s3comms_nlowercase()
*
* Purpose:
*
* From string starting at `s`, write `len` characters to `dest`,
* converting all to lowercase.
*
* Behavior is undefined if `s` is NULL or `len` overruns the allocated
* space of either `s` or `dest`.
*
* Provided as convenience.
*
* Return:
*
* - SUCCESS: `SUCCEED`
* - upon completion, `dest` is populated
* - FAILURE: `FAIL`
* - `dest == NULL`
*
*----------------------------------------------------------------------------
*/
herr_t
H5FD_s3comms_nlowercase(char *dest, const char *s, size_t len)
{
herr_t ret_value = SUCCEED;

FUNC_ENTER_NOAPI_NOINIT

if (dest == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "destination cannot be null.");

if (len > 0) {
H5MM_memcpy(dest, s, len);
do {
len--;
dest[len] = (char)tolower((int)dest[len]);
} while (len > 0);
}

done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_s3comms_nlowercase() */

/*----------------------------------------------------------------------------
*
* Function: H5FD_s3comms_parse_url()
Expand Down Expand Up @@ -2511,158 +2466,4 @@ H5FD_s3comms_tostringtosign(char *dest, const char *req, const char *now, const
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5ros3_tostringtosign() */

/*----------------------------------------------------------------------------
*
* Function: H5FD_s3comms_trim()
*
* Purpose:
*
* Remove all whitespace characters from start and end of a string `s`
* of length `s_len`, writing trimmed string copy to `dest`.
* Stores number of characters remaining at `n_written`.
*
* Destination for trimmed copy `dest` cannot be null.
* `dest` must have adequate space allocated for trimmed copy.
* If inadequate space, behavior is undefined, possibly resulting
* in segfault or overwrite of other data.
*
* If `s` is NULL or all whitespace, `dest` is untouched and `n_written`
* is set to 0.
*
* Return:
*
* - SUCCESS: `SUCCEED`
* - FAILURE: `FAIL`
* - `dest == NULL`
*
*----------------------------------------------------------------------------
*/
herr_t
H5FD_s3comms_trim(char *dest, char *s, size_t s_len, size_t *n_written)
{
herr_t ret_value = SUCCEED;

FUNC_ENTER_NOAPI_NOINIT

if (dest == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "destination cannot be null.");
if (s == NULL)
s_len = 0;

if (s_len > 0) {
/* Find first non-whitespace character from start;
* reduce total length per character.
*/
while (s_len > 0 && isspace((unsigned char)s[0])) {
s++;
s_len--;
}

/* Find first non-whitespace character from tail;
* reduce length per-character.
* If length is 0 already, there is no non-whitespace character.
*/
if (s_len > 0) {
do {
s_len--;
} while (isspace((unsigned char)s[s_len]));
s_len++;

/* write output into dest */
H5MM_memcpy(dest, s, s_len);
}
}

*n_written = s_len;

done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5FD_s3comms_trim() */

/*----------------------------------------------------------------------------
*
* Function: H5FD_s3comms_uriencode()
*
* Purpose:
*
* URIencode (percent-encode) every byte except "[a-zA-Z0-9]-._~".
*
* For each character in source string `_s` from `s[0]` to `s[s_len-1]`,
* writes to `dest` either the raw character or its percent-encoded
* equivalent.
*
* See `H5FD_s3comms_bytes_to_hex` for information on percent-encoding.
*
* Space (' ') character encoded as "%20" (not "+")
*
* Forward-slash ('/') encoded as "%2F" only when `encode_slash == true`.
*
* Records number of characters written at `n_written`.
*
* Assumes that `dest` has been allocated with enough space.
*
* Neither `dest` nor `s` can be NULL.
*
* `s_len == 0` will have no effect.
*
* Return:
*
* - SUCCESS: `SUCCEED`
* - FAILURE: `FAIL`
* - source strings `s` or destination `dest` are NULL
* - error while attempting to percent-encode a character
*
*----------------------------------------------------------------------------
*/
herr_t
H5FD_s3comms_uriencode(char *dest, const char *s, size_t s_len, bool encode_slash, size_t *n_written)
{
char c = 0;
size_t dest_off = 0;
char hex_buffer[13];
size_t hex_off = 0;
size_t hex_len = 0;
herr_t ret_value = SUCCEED;
size_t s_off = 0;

FUNC_ENTER_NOAPI_NOINIT

if (s == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "source string cannot be NULL");
if (dest == NULL)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "destination cannot be NULL");

/* Write characters to destination, converting to percent-encoded
* "hex-utf-8" strings if necessary.
* e.g., '$' -> "%24"
*/
for (s_off = 0; s_off < s_len; s_off++) {
c = s[s_off];
if (isalnum(c) || c == '.' || c == '-' || c == '_' || c == '~' || (c == '/' && encode_slash == false))
dest[dest_off++] = c;
else {
hex_off = 0;
if (H5FD_s3comms_percent_encode_char(hex_buffer, (const unsigned char)c, &hex_len) == FAIL) {
hex_buffer[0] = c;
hex_buffer[1] = 0;
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL,
"unable to percent-encode character \'%s\' "
"at %d in \"%s\"",
hex_buffer, (int)s_off, s);
}

for (hex_off = 0; hex_off < hex_len; hex_off++)
dest[dest_off++] = hex_buffer[hex_off];
} /* end else (not a regular character) */
} /* end for each character */

if (dest_off < s_len)
HGOTO_ERROR(H5E_ARGS, H5E_BADVALUE, FAIL, "buffer overflow");

*n_written = dest_off;

done:
FUNC_LEAVE_NOAPI(ret_value)
} /* H5FD_s3comms_uriencode */

#endif /* H5_HAVE_ROS3_VFD */
8 changes: 0 additions & 8 deletions src/H5FDs3comms.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,6 @@ H5_DLL herr_t H5FD_s3comms_HMAC_SHA256(const unsigned char *key, size_t key_len,
H5_DLL herr_t H5FD_s3comms_load_aws_profile(const char *name, char *key_id_out, char *secret_access_key_out,
char *aws_region_out);

H5_DLL herr_t H5FD_s3comms_nlowercase(char *dest, const char *s, size_t len);

H5_DLL herr_t H5FD_s3comms_parse_url(const char *str, parsed_url_t **purl);

H5_DLL herr_t H5FD_s3comms_percent_encode_char(char *repr, const unsigned char c, size_t *repr_len);
Expand All @@ -544,12 +542,6 @@ H5_DLL herr_t H5FD_s3comms_signing_key(unsigned char *md, const char *secret, co

H5_DLL herr_t H5FD_s3comms_tostringtosign(char *dest, const char *req_str, const char *now,
const char *region);

H5_DLL herr_t H5FD_s3comms_trim(char *dest, char *s, size_t s_len, size_t *n_written);

H5_DLL herr_t H5FD_s3comms_uriencode(char *dest, const char *s, size_t s_len, bool encode_slash,
size_t *n_written);

#ifdef __cplusplus
}
#endif
Expand Down
Loading

0 comments on commit 360ebb7

Please sign in to comment.