From 246e80ad159ab1a2958a56b91af9df81c5ea73f0 Mon Sep 17 00:00:00 2001
From: "Dmitriy A. Gerasimov" <dmitriy.gerasimov@demlabs.net>
Date: Sun, 27 Sep 2020 01:54:19 +0700
Subject: [PATCH] [*] Some fixes

---
 .../http_server/http_client/dap_http_client.c |  2 +-
 modules/type/blocks/dap_chain_block.c         | 26 +++++--------------
 modules/type/blocks/dap_chain_block_cache.c   | 14 +++++++++-
 .../blocks/include/dap_chain_block_cache.h    |  3 ++-
 4 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/dap-sdk/net/server/http_server/http_client/dap_http_client.c b/dap-sdk/net/server/http_server/http_client/dap_http_client.c
index 59f30cf660..8ee096e68d 100644
--- a/dap-sdk/net/server/http_server/http_client/dap_http_client.c
+++ b/dap-sdk/net/server/http_server/http_client/dap_http_client.c
@@ -369,7 +369,7 @@ void dap_http_client_read( dap_events_socket_t *a_esocket, void *arg )
 
                 char *l_query_string;
                 if( (l_query_string = strchr(l_http_client->url_path, '?')) != NULL ) {
-                    size_t len_after = strlen( l_query_string + 1 );
+                    size_t len_after = MIN(strlen( l_query_string + 1 ), sizeof (l_http_client->url_path)-1);
 
                     if ( len_after ) {
                         if( len_after > (sizeof(l_http_client->in_query_string) - 1) ){
diff --git a/modules/type/blocks/dap_chain_block.c b/modules/type/blocks/dap_chain_block.c
index 11ea5fef6d..daee181c47 100644
--- a/modules/type/blocks/dap_chain_block.c
+++ b/modules/type/blocks/dap_chain_block.c
@@ -63,8 +63,9 @@ dap_chain_block_t * dap_chain_block_new(dap_chain_hash_fast_t * a_prev_block )
         l_block->hdr.signature = DAP_CHAIN_BLOCK_SIGNATURE;
         l_block->hdr.version = 1;
         l_block->hdr.ts_created = time(NULL);
+        size_t l_block_size = sizeof (l_block->hdr);
         if( a_prev_block ){
-            dap_chain_block_meta_add(l_block, DAP_CHAIN_BLOCK_META_PREV,a_prev_block,sizeof (*a_prev_block) );
+            l_block_size = dap_chain_block_meta_add(l_block, l_block_size, DAP_CHAIN_BLOCK_META_PREV,a_prev_block,sizeof (*a_prev_block) );
         }else{
             log_it(L_INFO, "Genesis block produced");
         }
@@ -77,37 +78,22 @@ dap_chain_block_t * dap_chain_block_new(dap_chain_hash_fast_t * a_prev_block )
 // Add metadata in block
 size_t dap_chain_block_meta_add(dap_chain_block_t * a_block, size_t a_block_size, uint8_t a_meta_type, const void * a_data, size_t a_data_size)
 {
-
+    return a_block_size;
 }
 
 
 size_t dap_chain_block_datum_add(dap_chain_block_t * a_block, size_t a_block_size, dap_chain_datum_t * a_datum, size_t a_datum_size)
 {
     if ( a_block) {
-        dap_chain_block_cache_t * l_block_cache = dap_chain_block_cache_get(a_block, )
-        uint32_t l_sections_size = ( a_block->hdr.size - sizeof(a_block->hdr) );
-        if(   l_sections_size > a_section_offset ){
-            if( l_sections_size > (a_section_offset + a_section_data_size ) ) {
-                dap_chain_datum_t * l_section = (dap_chain_datum_t *) ( a_block->datums +a_section_offset) ;
-                l_section->header.type_id = a_section_type;
-                return l_section;
-            }else{
-                log_it(L_ERROR, "Section data size %lu is bigger then left for sections in block (%lu)"
-                       ,a_section_data_size,l_sections_size - a_section_offset );
-                return NULL;
-            }
-        }else{
-            log_it(L_ERROR, "Section offset %lu is bigger then section size %lu",a_section_offset,l_sections_size);
-            return NULL;
-        }
+        //
     }else{
         log_it(L_ERROR, "Block is NULL");
-        return NULL;
+        return a_block_size;
     }
 }
 
 size_t dap_chain_block_datum_del_by_hash(dap_chain_block_t * a_block, size_t a_block_size, dap_chain_hash_fast_t* a_datum_hash)
 {
-
+    return a_block_size;
 }
 
diff --git a/modules/type/blocks/dap_chain_block_cache.c b/modules/type/blocks/dap_chain_block_cache.c
index 183d9d8514..cf55de237f 100644
--- a/modules/type/blocks/dap_chain_block_cache.c
+++ b/modules/type/blocks/dap_chain_block_cache.c
@@ -53,18 +53,30 @@ void dap_chain_block_cache_deinit()
  * @param a_block_size
  * @return
  */
-dap_chain_block_cache_t * dap_chain_block_cache_get(dap_chain_block_t * a_block, size_t a_block_size)
+dap_chain_block_cache_t * dap_chain_block_cache_new(dap_chain_block_t * a_block, size_t a_block_size)
 {
     if (! a_block)
         return NULL;
 
     dap_chain_block_cache_t * l_block_cache = DAP_NEW_Z(dap_chain_block_cache_t);
     l_block_cache->block = a_block;
+    l_block_cache->block_size= a_block_size;
     dap_chain_block_cache_update(l_block_cache);
+
     log_it(L_DEBUG,"Block cache created");
     return l_block_cache;
 }
 
+/**
+ * @brief dap_chain_block_cache_get_by_hash
+ * @param a_block_hash
+ * @return
+ */
+dap_chain_block_cache_t * dap_chain_block_cache_get_by_hash(dap_chain_hash_fast_t a_block_hash)
+{
+    return NULL;
+}
+
 /**
  * @brief dap_chain_block_cache_update
  * @param a_block_cache
diff --git a/modules/type/blocks/include/dap_chain_block_cache.h b/modules/type/blocks/include/dap_chain_block_cache.h
index 890accd18a..35f115cdd3 100644
--- a/modules/type/blocks/include/dap_chain_block_cache.h
+++ b/modules/type/blocks/include/dap_chain_block_cache.h
@@ -60,6 +60,7 @@ typedef struct dap_chain_block_cache{
 int dap_chain_block_cache_init();
 void dap_chain_block_cache_deinit();
 
-dap_chain_block_cache_t * dap_chain_block_cache_get(dap_chain_block_t * a_block, size_t a_block_size);
+dap_chain_block_cache_t * dap_chain_block_cache_get_by_hash(dap_chain_hash_fast_t a_block_hash);
+dap_chain_block_cache_t * dap_chain_block_cache_new(dap_chain_block_t * a_block, size_t a_block_size);
 void dap_chain_block_cache_update(dap_chain_block_cache_t * a_block_cache);
 void dap_chain_block_cache_delete(dap_chain_block_cache_t * a_block_cache);
-- 
GitLab