From f4ddc078838b876199a762255c632424a6f0132d Mon Sep 17 00:00:00 2001 From: Miika Turkia Date: Sun, 24 Apr 2016 21:11:23 +0300 Subject: Grab the payload of DL7 file This allows us to parse the DL7 profile data (skipping the header and footer) Signed-off-by: Miika Turkia Signed-off-by: Dirk Hohndel --- core/file.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/core/file.c b/core/file.c index 52c93a719..b00e0e8a9 100644 --- a/core/file.c +++ b/core/file.c @@ -928,6 +928,43 @@ int parse_csv_file(const char *filename, char **params, int pnr, const char *csv params[pnr++] = NULL; mem.size = 0; + + if (!strcmp("DL7", csvtemplate)) { + char *ptr = NULL; + char *NL = NULL; + + csvtemplate = "csv"; + if (readfile(filename, &mem) < 0) + return report_error(translate("gettextFromC", "Failed to read '%s'"), filename); + + /* Determine NL (new line) character and the start of CSV data */ + if ((ptr = strstr(mem.buffer, "\r\n")) != NULL) { + NL = "\r\n"; + } else if ((ptr = strstr(mem.buffer, "\n")) != NULL) { + NL = "\n"; + } else { + fprintf(stderr, "DEBUG: failed to detect NL\n"); + return -1; + } + + ptr = strstr(mem.buffer, "ZDP"); + if (ptr) + ptr = strstr(ptr, NL); + if (ptr) + ptr + strlen(NL); + + /* Move the CSV data to the start of mem buffer */ + memmove(mem.buffer, ptr, mem.size - (ptr - (char*)mem.buffer)); + ptr = strstr(mem.buffer, "ZDP"); + if (ptr) { + *ptr = 0; + } else { + fprintf(stderr, "DEBUG: failed to find end ZDP\n"); + return -1; + } + mem.size = ptr - (char*)mem.buffer; + } + if (try_to_xslt_open_csv(filename, &mem, csvtemplate)) return -1; -- cgit v1.2.3-70-g09d2