time_t created_at;
off_t vendor;
off_t description;
+ off_t license;
// ASes in the database
struct loc_database_as_v0* as_v0;
db->created_at = be64toh(header.created_at);
db->vendor = be32toh(header.vendor);
db->description = be32toh(header.description);
+ db->license = be32toh(header.license);
// Open pool
off_t pool_offset = be32toh(header.pool_offset);
return loc_stringpool_get(db->pool, db->description);
}
+LOC_EXPORT const char* loc_database_get_license(struct loc_database* db) {
+ return loc_stringpool_get(db->pool, db->license);
+}
+
LOC_EXPORT size_t loc_database_count_as(struct loc_database* db) {
return db->as_count;
}
loc_database_created_at;
loc_database_get_as;
loc_database_get_description;
+ loc_database_get_license;
loc_database_get_vendor;
loc_database_lookup;
loc_database_lookup_from_string;
loc_writer_add_as;
loc_writer_add_network;
loc_writer_get_description;
+ loc_writer_get_license;
loc_writer_get_vendor;
loc_writer_new;
loc_writer_ref;
loc_writer_set_description;
+ loc_writer_set_license;
loc_writer_set_vendor;
loc_writer_unref;
loc_writer_write;
time_t loc_database_created_at(struct loc_database* db);
const char* loc_database_get_vendor(struct loc_database* db);
const char* loc_database_get_description(struct loc_database* db);
+const char* loc_database_get_license(struct loc_database* db);
int loc_database_get_as(struct loc_database* db, struct loc_as** as, uint32_t number);
size_t loc_database_count_as(struct loc_database* db);
// Description of the database
uint32_t description;
+ // License of the database
+ uint32_t license;
+
// Tells us where the ASes start
uint32_t as_offset;
uint32_t as_length;
int loc_writer_set_vendor(struct loc_writer* writer, const char* vendor);
const char* loc_writer_get_description(struct loc_writer* writer);
int loc_writer_set_description(struct loc_writer* writer, const char* description);
+const char* loc_writer_get_license(struct loc_writer* writer);
+int loc_writer_set_license(struct loc_writer* writer, const char* license);
int loc_writer_add_as(struct loc_writer* writer, struct loc_as** as, uint32_t number);
int loc_writer_add_network(struct loc_writer* writer, struct loc_network** network, const char* string);
return PyUnicode_FromString(vendor);
}
+static PyObject* Database_get_license(DatabaseObject* self) {
+ const char* license = loc_database_get_license(self->db);
+
+ return PyUnicode_FromString(license);
+}
+
static PyObject* Database_get_created_at(DatabaseObject* self) {
time_t created_at = loc_database_created_at(self->db);
NULL,
NULL,
},
+ {
+ "license",
+ (getter)Database_get_license,
+ NULL,
+ NULL,
+ NULL,
+ },
{
"vendor",
(getter)Database_get_vendor,
return 0;
}
+static PyObject* Writer_get_license(WriterObject* self) {
+ const char* license = loc_writer_get_license(self->writer);
+
+ return PyUnicode_FromString(license);
+}
+
+static int Writer_set_license(WriterObject* self, PyObject* value) {
+ const char* license = PyUnicode_AsUTF8(value);
+
+ int r = loc_writer_set_license(self->writer, license);
+ if (r) {
+ PyErr_Format(PyExc_ValueError, "Could not set license: %s", license);
+ return r;
+ }
+
+ return 0;
+}
+
static PyObject* Writer_add_as(WriterObject* self, PyObject* args) {
struct loc_as* as;
uint32_t number = 0;
NULL,
NULL,
},
+ {
+ "license",
+ (getter)Writer_get_license,
+ (setter)Writer_set_license,
+ NULL,
+ NULL,
+ },
{
"vendor",
(getter)Writer_get_vendor,
"tempor felis enim. Integer congue nisi in maximus pretium. "
"Pellentesque et turpis elementum, luctus mi at, interdum erat. "
"Maecenas ut venenatis nunc.";
+const char* LICENSE = "CC";
int main(int argc, char** argv) {
int err;
exit(EXIT_FAILURE);
}
+ // Set a license
+ err = loc_writer_set_license(writer, LICENSE);
+ if (err) {
+ fprintf(stderr, "Could not set license\n");
+ exit(EXIT_FAILURE);
+ }
+
+ // Retrieve license
+ const char* license = loc_writer_get_license(writer);
+ if (license) {
+ printf("License is: %s\n", license);
+ } else {
+ fprintf(stderr, "Could not retrieve license\n");
+ exit(EXIT_FAILURE);
+ }
+
FILE* f = fopen("test.db", "w");
if (!f) {
fprintf(stderr, "Could not open file for writing: %s\n", strerror(errno));
struct loc_stringpool* pool;
off_t vendor;
off_t description;
+ off_t license;
struct loc_as** as;
size_t as_count;
return 0;
}
+LOC_EXPORT const char* loc_writer_get_license(struct loc_writer* writer) {
+ return loc_stringpool_get(writer->pool, writer->license);
+}
+
+LOC_EXPORT int loc_writer_set_license(struct loc_writer* writer, const char* license) {
+ // Add the string to the string pool
+ off_t offset = loc_stringpool_add(writer->pool, license);
+ if (offset < 0)
+ return offset;
+
+ writer->license = offset;
+ return 0;
+}
+
static int __loc_as_cmp(const void* as1, const void* as2) {
return loc_as_cmp(*(struct loc_as**)as1, *(struct loc_as**)as2);
}
struct loc_database_header_v0 header;
header.vendor = htobe32(writer->vendor);
header.description = htobe32(writer->description);
+ header.license = htobe32(writer->license);
time_t now = time(NULL);
header.created_at = htobe64(now);