]> git.ipfire.org Git - location/libloc.git/blobdiff - src/writer.c
location-importer.in: skip networks with unknown country codes
[location/libloc.git] / src / writer.c
index db9ec1a1561c23048f8e5e00e74bbf5428f2ddb4..c61a6dfc657e92c1f552207f9af81cf671cb38da 100644 (file)
@@ -147,8 +147,19 @@ static void loc_writer_free(struct loc_writer* writer) {
                EVP_PKEY_free(writer->private_key2);
 
        // Unref all AS
-       for (unsigned int i = 0; i < writer->as_count; i++) {
-               loc_as_unref(writer->as[i]);
+       if (writer->as) {
+               for (unsigned int i = 0; i < writer->as_count; i++) {
+                       loc_as_unref(writer->as[i]);
+               }
+               free(writer->as);
+       }
+
+       // Unref all countries
+       if (writer->countries) {
+               for (unsigned int i = 0; i < writer->countries_count; i++) {
+                       loc_country_unref(writer->countries[i]);
+               }
+               free(writer->countries);
        }
 
        // Release network tree
@@ -531,7 +542,7 @@ static int loc_database_write_countries(struct loc_writer* writer,
 static int loc_writer_create_signature(struct loc_writer* writer,
                struct loc_database_header_v1* header, FILE* f, EVP_PKEY* private_key,
                char* signature, size_t* length) {
-       DEBUG(writer->ctx, "Signing database...\n");
+       DEBUG(writer->ctx, "Creating signature...\n");
 
        // Read file from the beginning
        rewind(f);
@@ -601,7 +612,7 @@ static int loc_writer_create_signature(struct loc_writer* writer,
                goto END;
        }
 
-       DEBUG(writer->ctx, "Successfully generated signature of %lu bytes\n", *length);
+       DEBUG(writer->ctx, "Successfully generated signature of %zu bytes\n", *length);
        r = 0;
 
        // Dump signature
@@ -649,8 +660,7 @@ LOC_EXPORT int loc_writer_write(struct loc_writer* writer, FILE* f, enum loc_dat
        header.signature2_length = 0;
 
        // Clear the padding
-       memset(header.padding1, '\0', sizeof(header.padding1));
-       memset(header.padding2, '\0', sizeof(header.padding2));
+       memset(header.padding, '\0', sizeof(header.padding));
 
        int r;
        off_t offset = 0;
@@ -718,13 +728,19 @@ LOC_EXPORT int loc_writer_write(struct loc_writer* writer, FILE* f, enum loc_dat
 
        // Copy the signatures into the header
        if (writer->signature1_length) {
+               DEBUG(writer->ctx, "Copying first signature of %zu byte(s)\n",
+                       writer->signature1_length);
+
                memcpy(header.signature1, writer->signature1, writer->signature1_length);
-               header.signature1_length = htobe32(writer->signature1_length);
+               header.signature1_length = htobe16(writer->signature1_length);
        }
 
        if (writer->signature2_length) {
+               DEBUG(writer->ctx, "Copying second signature of %zu byte(s)\n",
+                       writer->signature1_length);
+
                memcpy(header.signature2, writer->signature2, writer->signature2_length);
-               header.signature2_length = htobe32(writer->signature2_length);
+               header.signature2_length = htobe16(writer->signature2_length);
        }
 
        // Write the header