Skip to content

Commit

Permalink
feature flags
Browse files Browse the repository at this point in the history
  • Loading branch information
juliocavalin-lp committed Apr 8, 2024
1 parent 01ff5fd commit 54b3883
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion feature-flag.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,19 @@
*/
#include "xml.h"
#include "util.h"
#include "config.h"
#include <string.h>

void feature_flag_load_xml_attr(struct feature_flag *feature_flag, xmlDoc *doc, xmlAttrPtr attr) {
if (!xmlStrcmp(attr->name, BAD_CAST "url_encryptiona")) {
if (!xmlStrcmp(attr->name, BAD_CAST "url_encryption")) {
feature_flag->url_encryption_enabled = !strcmp((char *)xmlNodeListGetString(doc, attr->children, 1), "1");
}
}

void feature_flag_save(const struct feature_flag *feature_flag, unsigned const char key[KDF_HASH_LEN]) {
config_write_encrypted_string("session_ff_url_encryption", feature_flag->url_encryption_enabled ? "1" : "0", key);
}

void feature_flag_load(struct feature_flag *feature_flag, unsigned const char key[KDF_HASH_LEN]) {
feature_flag->url_encryption_enabled = !strcmp(config_read_encrypted_string("session_ff_url_encryption", key), "1");
}
2 changes: 2 additions & 0 deletions feature-flag.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ struct feature_flag {
};

void feature_flag_load_xml_attr(struct feature_flag *feature_flag, xmlDoc *doc, xmlAttrPtr attr);
void feature_flag_save(const struct feature_flag *feature_flag, unsigned const char key[KDF_HASH_LEN]);
void feature_flag_load(struct feature_flag *feature_flag, unsigned const char key[KDF_HASH_LEN]);

#endif
2 changes: 2 additions & 0 deletions session.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ void session_save(struct session *session, unsigned const char key[KDF_HASH_LEN]
config_write_encrypted_string("session_sessionid", session->sessionid, key);
config_write_encrypted_string("session_token", session->token, key);
config_write_encrypted_buffer("session_privatekey", (char *)session->private_key.key, session->private_key.len, key);
feature_flag_save(&session->feature_flag, key);

/*
* existing sessions may not have a server yet; they will fall back
Expand All @@ -90,6 +91,7 @@ struct session *session_load(unsigned const char key[KDF_HASH_LEN])
session->server = config_read_string("session_server");
session->private_key.len = config_read_encrypted_buffer("session_privatekey", &session->private_key.key, key);
mlock(session->private_key.key, session->private_key.len);
feature_flag_load(&session->feature_flag, key);

if (session_is_valid(session))
return session;
Expand Down

0 comments on commit 54b3883

Please sign in to comment.