Browse Source

Make the URI parsing function public

Rename the parse_uri function to gfsec_parse_uri and declare it
in the header, so that it could be called from other modules.
develop
Damien Goutte-Gattat 5 years ago
parent
commit
4595a417a6
  1. 15
      src/secretcfg.c
  2. 3
      src/secretcfg.h

15
src/secretcfg.c

@ -253,17 +253,22 @@ get_share_number_from_path(const char *path)
* @param uri The URI to parse.
* @param secret The gfsec_secret_t object to which a share
* will be added if the URI is correctly parsed.
* @param assign If non-zero, the share number will be randomly
* assigned and not extracted from the URI.
*
* @return 0 if the URI was successfully parsed, or one of the
* GFSEC_ERR_* error codes.
*/
static int
parse_uri(const char *uri, gfsec_secret_t *secret)
int
gfsec_parse_uri(const char *uri, gfsec_secret_t *secret, int assign)
{
gfsec_share_t *share;
const char *p = uri;
int rc = 0;
if ( ! uri || ! secret )
return GFSEC_ERR_INVALID_CALL;
if ( ! (share = gfsec_share_new()) )
return GFSEC_ERR_SYSTEM_ERROR;
@ -288,7 +293,9 @@ parse_uri(const char *uri, gfsec_secret_t *secret)
rc = parse_parameter(&p, share);
if ( rc == 0 && ! gfsec_share_is_full(share) ) {
if ( (share->number = get_share_number_from_path(share->path)) == 0 )
if ( assign )
share->number = GFSEC_SHARE_NUMBER_AUTOASSIGN;
else if ( (share->number = get_share_number_from_path(share->path)) == 0 )
rc = GFSEC_ERR_CONFIG_INVALID_URI;
}
@ -375,7 +382,7 @@ gfsec_read_config(gfsec_secret_t **cfg,
(*cfg)->threshold = (unsigned char) l;
}
else if ( strncmp("URI=", buffer, 4) == 0 )
rc = parse_uri(&(buffer[4]), *cfg);
rc = gfsec_parse_uri(&(buffer[4]), *cfg, 0);
}
fclose(f);

3
src/secretcfg.h

@ -25,6 +25,9 @@
extern "C" {
#endif
int
gfsec_parse_uri(const char *, gfsec_secret_t *, int);
int
gfsec_read_config(gfsec_secret_t **, const char *, unsigned int *);

Loading…
Cancel
Save