summaryrefslogtreecommitdiff
path: root/src/administration_reader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/administration_reader.cpp')
-rw-r--r--src/administration_reader.cpp46
1 files changed, 39 insertions, 7 deletions
diff --git a/src/administration_reader.cpp b/src/administration_reader.cpp
index fdbe8b6..91325ea 100644
--- a/src/administration_reader.cpp
+++ b/src/administration_reader.cpp
@@ -75,13 +75,15 @@ bool administration_reader::open_existing(char* file_path)
const char *name = zip_entry_name(zip);
int isdir = zip_entry_isdir(zip);
if (isdir) continue;
- unsigned long long size = zip_entry_size(zip);
-
- char* buffer = (char*)memops::alloc(size+1);
- memops::zero(buffer, size+1);
+
+ char* buffer;
+ unsigned long long size;
zip_entry_read(zip, (void**)&buffer, (size_t*)&size);
- if (strops::empty(name)) continue;
+ if (strops::empty(name)) {
+ memops::unalloc(buffer);
+ continue;
+ }
if (strops::equals(name, ADMIN_FILE_INFO))
{
@@ -107,7 +109,6 @@ bool administration_reader::open_existing(char* file_path)
{
administration_reader::import_invoice(buffer, (size_t)size);
}
-
memops::unalloc(buffer);
}
zip_entry_close(zip);
@@ -129,7 +130,10 @@ bool administration_reader::read_invoice_from_xml(invoice* result, char* buffer,
if (!document) return false;
struct xml_node* root = xml_document_root(document);
- if (!root) return false;
+ if (!root) {
+ xml_document_free(document, false);
+ return false;
+ }
invoice data = administration::invoice_create_empty();
xml_get_str(root, data.id, MAX_LEN_ID, "cbc:ID");
@@ -238,6 +242,8 @@ bool administration_reader::read_invoice_from_xml(invoice* result, char* buffer,
memops::unalloc(child_name);
}
+ xml_document_free(document, false);
+
*result = data;
return true;
}
@@ -257,6 +263,7 @@ bool administration_reader::import_invoice(char* buffer, size_t buffer_size)
logger::aerr(result);
logger::error("ERROR loading invoice '%s'.", data.sequential_number);
}
+ administration::invoice_destroy(&data);
return result == A_ERR_SUCCESS;
}
@@ -269,6 +276,10 @@ bool administration_reader::import_contact(char* buffer, size_t buffer_size)
if (!document) return false;
struct xml_node* root = xml_document_root(document);
+ if (!root) {
+ xml_document_free(document, false);
+ return false;
+ }
contact data = {0};
xml_get_str(root, data.id, MAX_LEN_ID, "Id");
@@ -297,6 +308,7 @@ bool administration_reader::import_contact(char* buffer, size_t buffer_size)
logger::error("ERROR loading contact '%s'.", data.name);
}
+ xml_document_free(document, false);
return result;
}
@@ -308,6 +320,10 @@ bool administration_reader::import_project(char* buffer, size_t buffer_size)
if (!document) return false;
struct xml_node* root = xml_document_root(document);
+ if (!root) {
+ xml_document_free(document, false);
+ return false;
+ }
project data = {0};
xml_get_str(root, data.id, MAX_LEN_ID, "Id");
@@ -326,6 +342,7 @@ bool administration_reader::import_project(char* buffer, size_t buffer_size)
logger::error("ERROR loading project '%s'.", data.id);
}
+ xml_document_free(document, false);
return result;
}
@@ -337,6 +354,10 @@ bool administration_reader::import_cost_center(char* buffer, size_t buffer_size)
if (!document) return false;
struct xml_node* root = xml_document_root(document);
+ if (!root) {
+ xml_document_free(document, false);
+ return false;
+ }
cost_center data = {0};
xml_get_str(root, data.id, MAX_LEN_ID, "Id");
@@ -353,6 +374,7 @@ bool administration_reader::import_cost_center(char* buffer, size_t buffer_size)
logger::error("ERROR loading cost center '%s'.", data.id);
}
+ xml_document_free(document, false);
return result;
}
@@ -364,6 +386,10 @@ bool administration_reader::import_tax_rate(char* buffer, size_t buffer_size)
if (!document) return false;
struct xml_node* root = xml_document_root(document);
+ if (!root) {
+ xml_document_free(document, false);
+ return false;
+ }
tax_rate data = {0};
xml_get_str(root, data.internal_code, MAX_LEN_SHORT_DESC, "Id");
@@ -390,6 +416,7 @@ bool administration_reader::import_tax_rate(char* buffer, size_t buffer_size)
logger::error("ERROR loading tax rate '%s'.", data.internal_code);
}
+ xml_document_free(document, false);
return result;
}
@@ -401,6 +428,10 @@ bool administration_reader::import_administration_info(char* buffer, size_t buff
if (!document) return false;
struct xml_node* root = xml_document_root(document);
+ if (!root) {
+ xml_document_free(document, false);
+ return false;
+ }
administration::set_next_id(xml_get_s32(root, "NextId"));
administration::set_next_sequence_number(xml_get_s32(root, "NextSequenceNumber"));
@@ -414,5 +445,6 @@ bool administration_reader::import_administration_info(char* buffer, size_t buff
logger::info("Loaded administration info in %.3fms. next_id=%d next_sequence_number=%d",
STOPWATCH_TIME, administration::get_next_id(), administration::get_next_sequence_number());
+ xml_document_free(document, false);
return true;
} \ No newline at end of file