int main(int argc, char *argv[]) { if (argc < 3) { usage(argv[0]); return 1; } struct db_conn conn = { .host = DB_HOST, .port = DB_PORT, }; strncpy(conn.db_name, argv[1], sizeof(conn.db_name)); size_t dsize = 0; unsigned char *data = fetch_data_from_db(&conn, argv[2], &dsize); if (data) { printf("%s", data); free(data); } else { printf("No such key."); } return 0; }
#include <38-moths/logging.h> #include "db.h" #include "benchmark.h" #include "http.h" #include "models.h" #include "parse.h" #include "utils.h" /* Webm get/set stuff */ webm *get_image(const char image_hash[static HASH_ARRAY_SIZE], char out_key[static MAX_KEY_SIZE]) { create_webm_key(image_hash, out_key); size_t json_size = 0; char *json = (char *)fetch_data_from_db(&oleg_conn, out_key, &json_size); /* m38_log_msg(LOG_INFO, "Json from DB: %s", json); */ if (json == NULL) return NULL; webm *deserialized = deserialize_webm(json); free(json); return deserialized; } int set_image(const webm *webm) { char key[MAX_KEY_SIZE] = {0}; create_webm_key(webm->file_hash, key); char *serialized = serialize_webm(webm);