summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorjobol <jose.bollo@iot.bzh>2018-04-03 15:10:28 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2018-06-14 15:19:08 +0200
commit1bb3f2601e862b72cbc6c6dabf515ad9f2f6ad1e (patch)
tree3070c22725f1e0658eabf808379d80e429dab4d6 /src
parente29f9aa18cc1b6f95a50d38c9a83294e0995b497 (diff)
afm-udb: refactor add_fields_of_content
Change-Id: Id59c92e18c7d3ed3fdd0df6dc2d46f64d58bdeee Signed-off-by: jobol <jose.bollo@iot.bzh>
Diffstat (limited to 'src')
-rw-r--r--src/afm-udb.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/afm-udb.c b/src/afm-udb.c
index 638387e..7f4a16e 100644
--- a/src/afm-udb.c
+++ b/src/afm-udb.c
@@ -182,17 +182,25 @@ static int add_fields_of_content(
{
char *name, *value, *read, *write;
- read = strstr(content, x_afm_prefix);
- while (read) {
+ /* start at the beginning */
+ read = content;
+ for (;;) {
+ /* search the next key */
+ read = strstr(read, x_afm_prefix);
+ if (!read)
+ return 0;
+
+ /* search to equal */
name = read + x_afm_prefix_length;
value = strchr(name, '=');
if (value == NULL)
- read = strstr(name, x_afm_prefix);
+ read = name; /* not found */
else {
+ /* get the value (translate it) */
*value++ = 0;
read = write = value;
while(*read && *read != '\n') {
- if (read[0] != '\\')
+ if (*read != '\\')
*write++ = *read++;
else {
switch(*++read) {
@@ -203,13 +211,14 @@ static int add_fields_of_content(
read += !!*read;
}
}
- read = strstr(read, x_afm_prefix);
+ read += !!*read;
*write = 0;
+
+ /* add the found field now */
if (add_field(priv, pub, name, value) < 0)
return -1;
}
}
- return 0;
}
/*