}
LOC_EXPORT int loc_as_set_name(struct loc_as* as, const char* name) {
- as->name = strdup(name);
+ if (as->name)
+ free(as->name);
+
+ if (name)
+ as->name = strdup(name);
+ else
+ as->name = NULL;
return 0;
}
return 0;
}
-int loc_as_new_from_database_v0(struct loc_ctx* ctx, struct loc_stringpool* pool,
- struct loc_as** as, const struct loc_database_as_v0* dbobj) {
+int loc_as_new_from_database_v1(struct loc_ctx* ctx, struct loc_stringpool* pool,
+ struct loc_as** as, const struct loc_database_as_v1* dbobj) {
uint32_t number = be32toh(dbobj->number);
int r = loc_as_new(ctx, as, number);
return 0;
}
-int loc_as_to_database_v0(struct loc_as* as, struct loc_stringpool* pool,
- struct loc_database_as_v0* dbobj) {
+int loc_as_to_database_v1(struct loc_as* as, struct loc_stringpool* pool,
+ struct loc_database_as_v1* dbobj) {
dbobj->number = htobe32(as->number);
// Save the name string in the string pool
}
int loc_as_match_string(struct loc_as* as, const char* string) {
+ // Match all AS when no search string is set
+ if (!string)
+ return 1;
+
+ // Cannot match anything when name is not set
+ if (!as->name)
+ return 1;
+
// Search if string is in name
if (strcasestr(as->name, string) != NULL)
return 1;