<pre style='margin:0'>
Umesh Singla (umeshksingla) pushed a commit to branch gsoc17-migrate
in repository macports-base.
</pre>
<p><a href="https://github.com/macports/macports-base/commit/13753c6e71f2b09820d3cc5553879e6383a6a056">https://github.com/macports/macports-base/commit/13753c6e71f2b09820d3cc5553879e6383a6a056</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit 13753c6e71f2b09820d3cc5553879e6383a6a056
</span>Author: Umesh Singla <umeshksingla@macports.org>
AuthorDate: Mon Aug 14 22:19:40 2017 +0530
<span style='display:block; white-space:pre;color:#404040;'> WIP: snapshot migration
</span>---
src/cregistry/entry.c | 438 -------------------------------------------
src/cregistry/snapshot.c | 475 +++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 475 insertions(+), 438 deletions(-)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/cregistry/entry.c b/src/cregistry/entry.c
</span><span style='display:block; white-space:pre;color:#808080;'>index 76a66a9..7c6f3f0 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/cregistry/entry.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/cregistry/entry.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1310,444 +1310,6 @@ int reg_entry_depends(reg_entry* entry, char* name, reg_error* errPtr) {
</span> return result;
}
<span style='display:block; white-space:pre;background:#ffe0e0;'>-reg_entry* reg_snapshot_create(reg_registry* reg, char* note, reg_error* errPtr) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- printf("inside cregsitry sn cr\n");
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- sqlite3_stmt* stmt = NULL;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_entry* entry = NULL;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- char* query = "INSERT INTO registry.snapshots (note) VALUES (?)";
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- && (sqlite3_bind_text(stmt, 1, note, -1, SQLITE_STATIC)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- == SQLITE_OK)) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int r;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- do {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- r = sqlite3_step(stmt);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- switch (r) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- case SQLITE_DONE:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- entry = malloc(sizeof(reg_entry));
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (entry) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- entry->id = sqlite3_last_insert_rowid(reg->db);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- entry->reg = reg;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- entry->proc = NULL;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- printf("snapshot id: %lld\n", entry->id);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- // TODO: move this functions to a different file
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int ports_saved = snapshot_store_ports(reg, entry, errPtr);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- switch (ports_saved) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- case 1:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- // TODO: pass the custom SUCCESS messages
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- break;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- case 0:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- break;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- break;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- case SQLITE_BUSY:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- break;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- default:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- break;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- } while (r == SQLITE_BUSY);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- } else {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (stmt) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- sqlite3_finalize(stmt);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- printf("done with the snapshot\n");
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return entry;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-}
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-int snapshot_store_ports(reg_registry* reg, reg_entry* snap_entry, reg_error* errPtr){
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_entry** entries;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_error error;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int i, entry_count;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int result = 1;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- entry_count = reg_entry_imaged(reg, NULL, NULL, NULL, NULL,
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- &entries, &error);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- printf("entry count: %d\n", entry_count);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- char* key1 = "name";
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- char* key2 = "requested";
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- char* key3 = "state";
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (entry_count >= 0) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- for ( i = 0; i < entry_count; i++) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- char* port_name;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- char* requested;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- char* state;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- sqlite3_stmt* stmt = NULL;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_entry* entry = NULL;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (reg_entry_propget(entries[i], key1, &port_name, &error)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- && reg_entry_propget(entries[i], key2, &requested, &error)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- && reg_entry_propget(entries[i], key3, &state, &error)) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- char* query = "INSERT INTO registry.snapshot_ports "
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- "(snapshots_id, port_name, requested, state) "
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- "VALUES (?, ?, ?, ?)";
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- && (sqlite3_bind_int64(stmt, 1, snap_entry->id) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- && (sqlite3_bind_text(stmt, 2, port_name, -1, SQLITE_STATIC) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- && (sqlite3_bind_int64(stmt, 3, atoi(requested)) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- && (sqlite3_bind_text(stmt, 4, state, -1, SQLITE_STATIC) == SQLITE_OK)) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int r;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- do {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- r = sqlite3_step(stmt);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- switch (r) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- case SQLITE_DONE:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- // store variants for entries[i]
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- entry = malloc(sizeof(reg_entry));
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (entry) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- entry->id = sqlite3_last_insert_rowid(reg->db);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- entry->reg = reg;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- entry->proc = NULL;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- printf("port id: %lld, ", entry->id);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- // TODO: move this function to a different file
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int port_variants_saved = snapshot_store_port_variants(
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg, entries[i], entry->id, errPtr);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- switch (port_variants_saved) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- case 1:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- // TODO: pass the custom SUCCESS messages
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- break;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- case 0:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- result = 0;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- break;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- printf("\ndone with *%s* port\n\n", port_name);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- break;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- case SQLITE_BUSY:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- break;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- default:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- result = 0;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- break;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- } while (r == SQLITE_BUSY);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- } else {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- result = 0;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (stmt) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- sqlite3_finalize(stmt);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- free(entry);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return result;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-}
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-int snapshot_store_port_variants(reg_registry* reg, reg_entry* port_entry,
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int snapshot_ports_id, reg_error* errPtr) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_error error;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int i, result = 1;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- char* key1 = "variants";
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- char* key2 = "negated_variants";
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- char* positive_variants_str;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- char* negative_variants_str;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if(reg_entry_propget(port_entry, key1, &positive_variants_str, &error)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- && reg_entry_propget(port_entry, key2, &negative_variants_str, &error)) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- printf("+ve .. %s, ", positive_variants_str);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- printf("-ve .. %s ", negative_variants_str);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- //return 1;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int variant_space = 10;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- variant* all_variants = (variant*) malloc(variant_space * sizeof(variant));
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (all_variants == NULL) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return 0;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- char* pos_delim = "+";
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- char* neg_delim = "-";
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int variant_count = 0;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int p = get_parsed_variants(positive_variants_str, all_variants, pos_delim, &variant_count);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (p < 0) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return 0;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int n = get_parsed_variants(negative_variants_str, all_variants, neg_delim, &variant_count);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (n < 0) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return 0;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- printf("total var count: %d, ", variant_count);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- for ( i = 0; i < variant_count; i++){
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- sqlite3_stmt* stmt = NULL;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- char* query = "INSERT INTO registry.snapshot_port_variants "
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- "(snapshot_ports_id, variant_name, variant_sign) "
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- "VALUES (?, ?, ?)";
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- variant v = *(all_variants + i);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- && (sqlite3_bind_int64(stmt, 1, snapshot_ports_id) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- && (sqlite3_bind_text(stmt, 2, v.variant_name, -1, SQLITE_STATIC) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- && (sqlite3_bind_text(stmt, 3, v.variant_sign, -1, SQLITE_STATIC) == SQLITE_OK)) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int r;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- do {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- r = sqlite3_step(stmt);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- switch (r) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- case SQLITE_DONE:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- printf("\nvariant stored: %s with sign: %s",
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- v.variant_name, v.variant_sign);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- break;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- case SQLITE_BUSY:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- break;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- default:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- result = 0;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- break;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- } while (r == SQLITE_BUSY);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- } else {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- result = 0;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- free(all_variants);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return result;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-}
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-int get_parsed_variants(char* variants_str, variant* all_variants, char* delim, int* variant_count) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- printf("var count yet %d, ", *variant_count);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- char *token;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- char *rest = variants_str;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- while ((token = strtok_r(rest, delim, &rest))) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- printf("%s\n", token);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- variant v;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- v.variant_name = token;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- v.variant_sign = delim;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- *(all_variants + *variant_count) = v;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- *variant_count = *variant_count + 1;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- // all_variants = (variant*) realloc(all_variants, sizeof(variant));
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- // if(!all_variants) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- // return -1;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- // }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return 0;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-}
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-char* reg_snapshot_get_id(reg_registry* reg, reg_error* errPtr) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- printf("inside cregistry get snapshot..\n");
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- sqlite3_stmt* stmt = NULL;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_entry* entry = NULL;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- char* query = "SELECT id FROM registry.snapshots ORDER BY id DESC LIMIT 1";
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-}
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-int reg_snapshot_port_variants_get(reg_registry* reg, sqlite_int64 snapshot_port_id, variant** variants, reg_error* errPtr) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- printf("inside getting variants\n");
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- sqlite3_stmt* stmt = NULL;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- char* query = "SELECT * FROM registry.snapshot_port_variants WHERE snapshot_ports_id=?";
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- && (sqlite3_bind_int64(stmt, 1, snapshot_port_id) == SQLITE_OK )) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- variant* result = malloc(10 * sizeof(variant));
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (!result) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return -1;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int result_count = 0;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int result_space = 10;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int r;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- const char* variant_name;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- const char* variant_sign;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- do {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- r = sqlite3_step(stmt);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- switch (r) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- case SQLITE_ROW:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- variant_name = sqlite3_column_text(stmt, 2);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- variant_sign = sqlite3_column_text(stmt, 3);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- variant* element = malloc(10 * sizeof(variant));
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (!element) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return -1;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- element->variant_name = variant_name;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- element->variant_sign = variant_sign;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (!reg_listcat((void***)&result, &result_count, &result_space, element)) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- r = SQLITE_ERROR;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- break;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- case SQLITE_DONE:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- case SQLITE_BUSY:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- continue;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- default:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- break;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- } while (r == SQLITE_ROW || r == SQLITE_BUSY);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- sqlite3_finalize(stmt);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (r == SQLITE_DONE) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- *variants = result;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return result_count;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- } else {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int i;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- for (i = 0; i < result_count; i++) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- free(result[i].variant_name);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- free(result[i].variant_sign);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- free(result);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return -1;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- } else {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (stmt) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- sqlite3_finalize(stmt);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return -1;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-}
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-int reg_snapshot_get(reg_registry* reg, char* id, reg_snapshot* snapshot, reg_error* errPtr) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- printf("inside cregistry get snapshot..\n");
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- sqlite3_stmt* stmt = NULL;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- char* query = "SELECT * FROM registry.snapshot_ports WHERE snapshots_id=?";
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- const char* port_name;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- const char* state;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- && (sqlite3_bind_int64(stmt, 1, (sqlite_int64)id) == SQLITE_OK )) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- port** result = malloc(10 * sizeof(port*));
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (!result) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return -1;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int result_count = 0;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int result_space = 10;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int r;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- sqlite_int64 snapshot_port_id;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int requested;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- do {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- r = sqlite3_step(stmt);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- switch (r) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- case SQLITE_ROW:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- snapshot_port_id = sqlite3_column_int64(stmt, 0);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- port_name = (const char*) sqlite3_column_text(stmt, 2);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- requested = (int) sqlite3_column_int64(stmt, 3);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- state = (const char*) sqlite3_column_text(stmt, 4);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- port* current_port;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- current_port = (port*) malloc(sizeof(port*));
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (!current_port) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return -1;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- current_port->name = port_name;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- current_port->requested = requested;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- current_port->state = state;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- current_port->variants = NULL;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- // get variants for the current port using its id
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- variant* variants;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int variant_count = reg_snapshot_port_variants_get(reg, snapshot_port_id, &variants, errPtr);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (!variants) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return -1;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (variant_count > 0) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- current_port->variants = variants;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (!reg_listcat((void***)&result, &result_count, &result_space, current_port)) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- r = SQLITE_ERROR;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- break;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- case SQLITE_DONE:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- break;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- case SQLITE_BUSY:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- continue;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- default:
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- break;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- } while (r == SQLITE_ROW || r == SQLITE_BUSY);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- sqlite3_finalize(stmt);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (r == SQLITE_DONE) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_snapshot* s = malloc(sizeof(reg_snapshot*));
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (!s) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return -1;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- s->id = NULL;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- s->note = NULL;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- s->proc = NULL;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- s->ports = result;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- *snapshot = *s;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return result_count;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- } else {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int i;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- for (i=0; i<result_count; i++) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- free(result[i]);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- free(result);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return -1;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- } else {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (stmt) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- sqlite3_finalize(stmt);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-}
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span> /**
* Fetches a list of all open entries.
*
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/cregistry/snapshot.c b/src/cregistry/snapshot.c
</span><span style='display:block; white-space:pre;color:#808080;'>index e69de29..a6fdef7 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/cregistry/snapshot.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/cregistry/snapshot.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -0,0 +1,475 @@
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+/*
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * snapshot.c
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * vim:tw=80:expandtab
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * Copyright (c) 2017 The MacPorts Project
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * All rights reserved.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * Redistribution and use in source and binary forms, with or without
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * modification, are permitted provided that the following conditions
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * are met:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * 1. Redistributions of source code must retain the above copyright
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * notice, this list of conditions and the following disclaimer.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * 2. Redistributions in binary form must reproduce the above copyright
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * notice, this list of conditions and the following disclaimer in the
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * documentation and/or other materials provided with the distribution.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#if HAVE_CONFIG_H
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <config.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#endif
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include "snapshot.h"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include "registry.h"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include "sql.h"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include "util.h"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <sqlite3.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <stdlib.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#include <string.h>
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int get_parsed_variants(char* variants_str, variant* all_variants, char* delim, int* variant_count) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("var count yet %d, ", *variant_count);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char *token;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char *rest = variants_str;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ while ((token = strtok_r(rest, delim, &rest))) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("%s\n", token);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ variant v;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ v.variant_name = token;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ v.variant_sign = delim;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *(all_variants + *variant_count) = v;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *variant_count = *variant_count + 1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // all_variants = (variant*) realloc(all_variants, sizeof(variant));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // if(!all_variants) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // return -1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+reg_entry* reg_snapshot_create(reg_registry* reg, char* note, reg_error* errPtr) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("inside cregsitry sn cr\n");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite3_stmt* stmt = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_entry* entry = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* query = "INSERT INTO registry.snapshots (note) VALUES (?)";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ && (sqlite3_bind_text(stmt, 1, note, -1, SQLITE_STATIC)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ == SQLITE_OK)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int r;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ do {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ r = sqlite3_step(stmt);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ switch (r) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ case SQLITE_DONE:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ entry = malloc(sizeof(reg_entry));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (entry) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ entry->id = sqlite3_last_insert_rowid(reg->db);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ entry->reg = reg;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ entry->proc = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("snapshot id: %lld\n", entry->id);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // TODO: move this functions to a different file
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int ports_saved = snapshot_store_ports(reg, entry, errPtr);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ switch (ports_saved) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ case 1:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // TODO: pass the custom SUCCESS messages
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ case 0:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ case SQLITE_BUSY:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ default:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } while (r == SQLITE_BUSY);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (stmt) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite3_finalize(stmt);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("done with the snapshot\n");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return entry;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int snapshot_store_ports(reg_registry* reg, reg_entry* snap_entry, reg_error* errPtr){
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_entry** entries;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_error error;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int i, entry_count;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int result = 1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ entry_count = reg_entry_imaged(reg, NULL, NULL, NULL, NULL,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ &entries, &error);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("entry count: %d\n", entry_count);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* key1 = "name";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* key2 = "requested";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* key3 = "state";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (entry_count >= 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ for ( i = 0; i < entry_count; i++) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* port_name;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* requested;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* state;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite3_stmt* stmt = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_entry* entry = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (reg_entry_propget(entries[i], key1, &port_name, &error)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ && reg_entry_propget(entries[i], key2, &requested, &error)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ && reg_entry_propget(entries[i], key3, &state, &error)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* query = "INSERT INTO registry.snapshot_ports "
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ "(snapshots_id, port_name, requested, state) "
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ "VALUES (?, ?, ?, ?)";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ && (sqlitse3_bind_int64(stmt, 1, snap_entry->id) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ && (sqlite3_bind_text(stmt, 2, port_name, -1, SQLITE_STATIC) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ && (sqlite3_bind_int64(stmt, 3, atoi(requested)) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ && (sqlite3_bind_text(stmt, 4, state, -1, SQLITE_STATIC) == SQLITE_OK)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int r;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ do {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ r = sqlite3_step(stmt);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ switch (r) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ case SQLITE_DONE:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // store variants for entries[i]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ entry = malloc(sizeof(reg_entry));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (entry) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ entry->id = sqlite3_last_insert_rowid(reg->db);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ entry->reg = reg;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ entry->proc = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("port id: %lld, ", entry->id);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // TODO: move this function to a different file
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int port_variants_saved = snapshot_store_port_variants(
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg, entries[i], entry->id, errPtr);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ switch (port_variants_saved) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ case 1:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // TODO: pass the custom SUCCESS messages
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ case 0:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ result = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("\ndone with *%s* port\n\n", port_name);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ case SQLITE_BUSY:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ default:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ result = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } while (r == SQLITE_BUSY);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ result = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (stmt) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite3_finalize(stmt);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ free(entry);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return result;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int snapshot_store_port_variants(reg_registry* reg, reg_entry* port_entry,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int snapshot_ports_id, reg_error* errPtr) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_error error;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int i, result = 1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* key1 = "variants";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* key2 = "negated_variants";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* positive_variants_str;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* negative_variants_str;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if(reg_entry_propget(port_entry, key1, &positive_variants_str, &error)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ && reg_entry_propget(port_entry, key2, &negative_variants_str, &error)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("+ve .. %s, ", positive_variants_str);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("-ve .. %s ", negative_variants_str);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int variant_space = 10;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ variant* all_variants = (variant*) malloc(variant_space * sizeof(variant));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (all_variants == NULL) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* pos_delim = "+";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* neg_delim = "-";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int variant_count = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int p = get_parsed_variants(positive_variants_str, all_variants, pos_delim, &variant_count);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (p < 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int n = get_parsed_variants(negative_variants_str, all_variants, neg_delim, &variant_count);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (n < 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("total var count: %d, ", variant_count);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ for ( i = 0; i < variant_count; i++){
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite3_stmt* stmt = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* query = "INSERT INTO registry.snapshot_port_variants "
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ "(snapshot_ports_id, variant_name, variant_sign) "
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ "VALUES (?, ?, ?)";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ variant v = *(all_variants + i);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ && (sqlite3_bind_int64(stmt, 1, snapshot_ports_id) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ && (sqlite3_bind_text(stmt, 2, v.variant_name, -1, SQLITE_STATIC) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ && (sqlite3_bind_text(stmt, 3, v.variant_sign, -1, SQLITE_STATIC) == SQLITE_OK)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int r;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ do {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ r = sqlite3_step(stmt);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ switch (r) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ case SQLITE_DONE:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("\nvariant stored: %s with sign: %s",
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ v.variant_name, v.variant_sign);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ case SQLITE_BUSY:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ default:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ result = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } while (r == SQLITE_BUSY);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ result = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ free(all_variants);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return result;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+char* reg_snapshot_get_id(reg_registry* reg, reg_error* errPtr) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("inside cregistry get snapshot..\n");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite3_stmt* stmt = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_entry* entry = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* query = "SELECT id FROM registry.snapshots ORDER BY id DESC LIMIT 1";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int reg_snapshot_get(reg_registry* reg, char* id, reg_snapshot* snapshot, reg_error* errPtr) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("inside cregistry get snapshot..\n");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite3_stmt* stmt = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* query = "SELECT * FROM registry.snapshot_ports WHERE snapshots_id=?";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ const char* port_name;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ const char* state;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ && (sqlite3_bind_int64(stmt, 1, (sqlite_int64)id) == SQLITE_OK )) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ port** result = malloc(10 * sizeof(port*));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (!result) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return -1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int result_count = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int result_space = 10;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int r;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite_int64 snapshot_port_id;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int requested;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ do {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ r = sqlite3_step(stmt);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ switch (r) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ case SQLITE_ROW:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ snapshot_port_id = sqlite3_column_int64(stmt, 0);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ port_name = (const char*) sqlite3_column_text(stmt, 2);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ requested = (int) sqlite3_column_int64(stmt, 3);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ state = (const char*) sqlite3_column_text(stmt, 4);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ port* current_port;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ current_port = (port*) malloc(sizeof(port*));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (!current_port) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return -1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ current_port->name = port_name;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ current_port->requested = requested;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ current_port->state = state;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ current_port->variants = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // get variants for the current port using its id
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ variant* variants;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int variant_count = reg_snapshot_port_variants_get(reg, snapshot_port_id, &variants, errPtr);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (!variants) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return -1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (variant_count > 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ current_port->variants = variants;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (!reg_listcat((void***)&result, &result_count, &result_space, current_port)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ r = SQLITE_ERROR;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ case SQLITE_DONE:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ case SQLITE_BUSY:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ continue;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ default:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } while (r == SQLITE_ROW || r == SQLITE_BUSY);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite3_finalize(stmt);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (r == SQLITE_DONE) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_snapshot* s = malloc(sizeof(reg_snapshot*));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (!s) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return -1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ s->id = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ s->note = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ s->proc = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ s->ports = result;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *snapshot = *s;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return result_count;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int i;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ for (i=0; i<result_count; i++) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ free(result[i]);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ free(result);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return -1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (stmt) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite3_finalize(stmt);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int reg_snapshot_port_variants_get(reg_registry* reg, sqlite_int64 snapshot_port_id, variant** variants, reg_error* errPtr) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("inside getting variants\n");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite3_stmt* stmt = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* query = "SELECT * FROM registry.snapshot_port_variants WHERE snapshot_ports_id=?";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ && (sqlite3_bind_int64(stmt, 1, snapshot_port_id) == SQLITE_OK )) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ variant* result = malloc(10 * sizeof(variant));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (!result) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return -1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int result_count = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int result_space = 10;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int r;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ const char* variant_name;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ const char* variant_sign;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ do {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ r = sqlite3_step(stmt);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ switch (r) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ case SQLITE_ROW:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ variant_name = sqlite3_column_text(stmt, 2);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ variant_sign = sqlite3_column_text(stmt, 3);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ variant* element = malloc(10 * sizeof(variant));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (!element) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return -1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ element->variant_name = variant_name;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ element->variant_sign = variant_sign;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (!reg_listcat((void***)&result, &result_count, &result_space, element)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ r = SQLITE_ERROR;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ case SQLITE_DONE:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ case SQLITE_BUSY:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ continue;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ default:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } while (r == SQLITE_ROW || r == SQLITE_BUSY);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite3_finalize(stmt);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (r == SQLITE_DONE) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *variants = result;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return result_count;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int i;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ for (i = 0; i < result_count; i++) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ free(result[i].variant_name);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ free(result[i].variant_sign);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ free(result);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return -1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (stmt) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite3_finalize(stmt);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return -1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span></pre><pre style='margin:0'>
</pre>