Skip to content

Commit

Permalink
modified template
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoLassmann committed Oct 3, 2024
1 parent af1b219 commit 701ce8d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/template/template.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ static unsigned int str_hash(char *str, int table_size)
int tld_template_add(tld_template_hash **hash, char *key, char *val)
{
tld_template_hash* h = NULL;

if(*hash){
h = *hash;
}else{
Expand All @@ -55,8 +54,20 @@ int tld_template_add(tld_template_hash **hash, char *key, char *val)

unsigned int index = str_hash(key, h->table_size);

// Create a new entry
tld_template_hash_entry* new_entry = NULL;//(tld_template_hash_entry*)malloc(sizeof(tld_template_hash_entry));
// Check if key already exists
tld_template_hash_entry* current = h->table[index];
while (current) {
if (strcmp(TLD_STR(current->key), key) == 0) {
// Key exists, replace the value
tld_strbuf_clear(current->value);
tld_append(current->value, val);
return OK;
}
current = current->next;
}

// Key does not exist, create a new entry
tld_template_hash_entry* new_entry = NULL;
MMALLOC(new_entry, sizeof(tld_template_hash_entry));
tld_strbuf_alloc(&new_entry->key, 16);
tld_strbuf_alloc(&new_entry->value, 16);
Expand Down

0 comments on commit 701ce8d

Please sign in to comment.