diff options
author | Miika Pekkarinen <miipekk@ihme.org> | 2011-06-20 15:53:33 +0000 |
---|---|---|
committer | Miika Pekkarinen <miipekk@ihme.org> | 2011-06-20 15:53:33 +0000 |
commit | f2ef42c1da977402e19e6ac77165f9cd0fd25643 (patch) | |
tree | e754ee56e727aa3f2741f820ffc3f6a22aa368ca | |
parent | c56cca261a4e8a72443a3fdf79152782c7c731e5 (diff) | |
download | rockbox-f2ef42c1da977402e19e6ac77165f9cd0fd25643.tar.gz rockbox-f2ef42c1da977402e19e6ac77165f9cd0fd25643.zip |
Fixed a changelog export/import problem with tagcache where <CR> or <LF>
characters in a tag could cause the parser fail to import a track
statistics correctly. Now line feeds are escaped properly and carriage
returns ignored on import.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30021 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/misc.c | 10 | ||||
-rw-r--r-- | apps/tagcache.c | 34 |
2 files changed, 23 insertions, 21 deletions
diff --git a/apps/misc.c b/apps/misc.c index 12aaf08c7b..68775b36f5 100644 --- a/apps/misc.c +++ b/apps/misc.c | |||
@@ -184,15 +184,7 @@ int fast_readline(int fd, char *buf, int buf_size, void *parameters, | |||
184 | if (rc >= 0) | 184 | if (rc >= 0) |
185 | buf[pos+rc] = '\0'; | 185 | buf[pos+rc] = '\0'; |
186 | 186 | ||
187 | if ( (p = strchr(buf, '\r')) != NULL) | 187 | if ( (p = strchr(buf, '\n')) != NULL) |
188 | { | ||
189 | *p = '\0'; | ||
190 | next = ++p; | ||
191 | } | ||
192 | else | ||
193 | p = buf; | ||
194 | |||
195 | if ( (p = strchr(p, '\n')) != NULL) | ||
196 | { | 188 | { |
197 | *p = '\0'; | 189 | *p = '\0'; |
198 | next = ++p; | 190 | next = ++p; |
diff --git a/apps/tagcache.c b/apps/tagcache.c index 6ad8f118a1..0c85fc5957 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c | |||
@@ -3278,6 +3278,13 @@ static bool write_tag(int fd, const char *tagstr, const char *datastr) | |||
3278 | if (*datastr == '"' || *datastr == '\\') | 3278 | if (*datastr == '"' || *datastr == '\\') |
3279 | buf[i++] = '\\'; | 3279 | buf[i++] = '\\'; |
3280 | 3280 | ||
3281 | else if (*datastr == '\n') | ||
3282 | { | ||
3283 | buf[i++] = '\\'; | ||
3284 | buf[i] = 'n'; | ||
3285 | continue; | ||
3286 | } | ||
3287 | |||
3281 | buf[i] = *(datastr++); | 3288 | buf[i] = *(datastr++); |
3282 | } | 3289 | } |
3283 | 3290 | ||
@@ -3335,12 +3342,18 @@ static bool read_tag(char *dest, long size, | |||
3335 | 3342 | ||
3336 | if (*src == '\\') | 3343 | if (*src == '\\') |
3337 | { | 3344 | { |
3338 | dest[pos] = *(src+1); | 3345 | src++; |
3339 | src += 2; | 3346 | if (*src == 'n') |
3347 | dest[pos] = '\n'; | ||
3348 | else | ||
3349 | dest[pos] = *src; | ||
3350 | |||
3351 | src++; | ||
3340 | continue; | 3352 | continue; |
3341 | } | 3353 | } |
3342 | 3354 | ||
3343 | dest[pos] = *src; | 3355 | if (*src == '\0') |
3356 | break; | ||
3344 | 3357 | ||
3345 | if (*src == '"') | 3358 | if (*src == '"') |
3346 | { | 3359 | { |
@@ -3348,10 +3361,7 @@ static bool read_tag(char *dest, long size, | |||
3348 | break; | 3361 | break; |
3349 | } | 3362 | } |
3350 | 3363 | ||
3351 | if (*src == '\0') | 3364 | dest[pos] = *(src++); |
3352 | break; | ||
3353 | |||
3354 | src++; | ||
3355 | } | 3365 | } |
3356 | 3366 | ||
3357 | dest[pos] = '\0'; | 3367 | dest[pos] = '\0'; |
@@ -3377,10 +3387,10 @@ static int parse_changelog_line(int line_n, const char *buf, void *parameters) | |||
3377 | if (*buf == '#') | 3387 | if (*buf == '#') |
3378 | return 0; | 3388 | return 0; |
3379 | 3389 | ||
3380 | logf("%d/%s", line_n, buf); | 3390 | /* logf("%d/%s", line_n, buf); */ |
3381 | if (!read_tag(tag_data, sizeof tag_data, buf, "filename")) | 3391 | if (!read_tag(tag_data, sizeof tag_data, buf, "filename")) |
3382 | { | 3392 | { |
3383 | logf("filename missing"); | 3393 | logf("%d/filename missing", line_n); |
3384 | logf("-> %s", buf); | 3394 | logf("-> %s", buf); |
3385 | return 0; | 3395 | return 0; |
3386 | } | 3396 | } |
@@ -3388,13 +3398,13 @@ static int parse_changelog_line(int line_n, const char *buf, void *parameters) | |||
3388 | idx_id = find_index(tag_data); | 3398 | idx_id = find_index(tag_data); |
3389 | if (idx_id < 0) | 3399 | if (idx_id < 0) |
3390 | { | 3400 | { |
3391 | logf("entry not found"); | 3401 | logf("%d/entry not found", line_n); |
3392 | return 0; | 3402 | return 0; |
3393 | } | 3403 | } |
3394 | 3404 | ||
3395 | if (!get_index(masterfd, idx_id, &idx, false)) | 3405 | if (!get_index(masterfd, idx_id, &idx, false)) |
3396 | { | 3406 | { |
3397 | logf("failed to retrieve index entry"); | 3407 | logf("%d/failed to retrieve index entry", line_n); |
3398 | return 0; | 3408 | return 0; |
3399 | } | 3409 | } |
3400 | 3410 | ||
@@ -3402,7 +3412,7 @@ static int parse_changelog_line(int line_n, const char *buf, void *parameters) | |||
3402 | if (idx.flag & FLAG_DIRTYNUM) | 3412 | if (idx.flag & FLAG_DIRTYNUM) |
3403 | return 0; | 3413 | return 0; |
3404 | 3414 | ||
3405 | logf("import: %s", tag_data); | 3415 | logf("%d/import: %s", line_n, tag_data); |
3406 | 3416 | ||
3407 | idx.flag |= FLAG_DIRTYNUM; | 3417 | idx.flag |= FLAG_DIRTYNUM; |
3408 | for (i = 0; i < (long)(sizeof(import_tags)/sizeof(import_tags[0])); i++) | 3418 | for (i = 0; i < (long)(sizeof(import_tags)/sizeof(import_tags[0])); i++) |