fix metadata DB insert without trailing pipe character

fixes #374

Change-Id: Ibfe89b7804183ef04eba39d29e01b70160f7c264
pull/402/merge
Richard Fuchs 8 years ago
parent cdb867ded5
commit 5bcbf27fe1

@ -72,6 +72,8 @@ INLINE int str_to_i(str *s, int def);
INLINE uint str_to_ui(str *s, int def);
/* extracts the first/next token into "new_token" and modifies "ori_and_remainer" in place */
INLINE int str_token(str *new_token, str *ori_and_remainder, int sep);
/* same as str_token but allows for a trailing non-empty token (e.g. "foo,bar" -> "foo", "bar" ) */
INLINE int str_token_sep(str *new_token, str *ori_and_remainder, int sep);
/* copy a string to a regular C string buffer, limiting the max size */
INLINE char *str_ncpy(char *dst, size_t bufsize, const str *src);
@ -320,6 +322,17 @@ INLINE int str_token(str *new_token, str *ori_and_remainder, int sep) {
return 0;
}
INLINE int str_token_sep(str *new_token, str *ori_and_remainder, int sep) {
str ori = *ori_and_remainder;
if (!str_token(new_token, ori_and_remainder, sep))
return 0;
// separator not found, use remainder as final token if not empty
if (!ori.len)
return -1;
*new_token = ori;
return 0;
}
INLINE int str_uri_encode(char *out, const str *in) {
return str_uri_encode_len(out, in->s, in->len);
}

@ -219,11 +219,9 @@ static void db_do_call_metadata(metafile_t *mf) {
str_init(&all_meta, mf->metadata);
while (all_meta.len > 1) {
str token;
if (str_token(&token, &all_meta, '|')) {
// separator not found, use remainder as token
token = all_meta;
all_meta.len = 0;
}
if (str_token_sep(&token, &all_meta, '|'))
break;
str key;
if (str_token(&key, &token, ':')) {
// key:value separator not found, skip

Loading…
Cancel
Save