From 692bcde085e1cfaf466d4167aa273c0d02daf69d Mon Sep 17 00:00:00 2001 From: Harbour Date: Sun, 6 Apr 2008 12:50:17 +0300 Subject: [PATCH] . --- faraon/faraon.C | 4 +++- include/elements.H | 45 +++++++++++++++++++++++++-------------------- include/network.H | 2 +- lib/misc.C | 2 +- sfinx/sfinx.C | 8 +++++--- 5 files changed, 35 insertions(+), 26 deletions(-) diff --git a/faraon/faraon.C b/faraon/faraon.C index 50c8643..b23c13f 100644 --- a/faraon/faraon.C +++ b/faraon/faraon.C @@ -103,6 +103,7 @@ int main(int argc, char **argv) catch (SockException *s) { app->ui()->log(SFINX_LOG_FATAL, "Socket exception to %s", app->server_name.c_str()); + app->sfinx.disconnect(); Thread::sleep(1000); } catch (Socket *s) { @@ -111,8 +112,9 @@ int main(int argc, char **argv) Thread::sleep(1000); } catch (...) { - app->ui()->log(SFINX_LOG_WARN, "Disconnected from %s", + app->ui()->log(SFINX_LOG_WARN, "Unknown exeption while talking to %s", app->server_name.c_str()); + app->sfinx.disconnect(); Thread::sleep(1000); } } // while(1) diff --git a/include/elements.H b/include/elements.H index 0710751..93d4837 100644 --- a/include/elements.H +++ b/include/elements.H @@ -193,7 +193,7 @@ class sfinx_timestamp_t : public Timestamp { // ËÏÎÓÔÒÕËÔÏÒ ËÏÐÉÒÏ×ÁÎÉÑ ÐÏÄÈÏÄÉÔ ÐÏ ÕÍÏÌÞÁÎÉÀ sfinx_timestamp_t() : Timestamp() { mDate = IBPP::MinDate; mTime = 0; } sfinx_timestamp_t(const Timestamp &t) : Timestamp(t) { } - sfinx_size_t size() { return sizeof(mDate) + sizeof(mTime); } + sfinx_size_t size() { return (sizeof(mDate) + sizeof(mTime)); } sfinx_size_t get(u8_t *buf) { u32_t date, time; memcpy(&date, buf, sizeof(date)); @@ -309,7 +309,7 @@ class sfinx_slice_t : public sfinx_t { buf += obj.get(buf); objs.push_back(obj); } - // hmm, ÐÒÏ×ÅÒËÁ ÌÉÛØ × ËÏÎÃÅ + // hmm, ÐÒÏ×ÅÒËÁ ÌÉÛØ × ËÏÎÃÅ if ((sfinx_size_t)(buf - t) > object_size_in_buf) return 0; return size(); @@ -394,7 +394,7 @@ class sfinx_slice_vector_t : public sfinx_t { clear(); while (object_size_in_buf) { sfinx_slice_t *slice = new sfinx_slice_t; - u32_t res = slice->get(buf + size(), object_size_in_buf); + sfinx_size_t res = slice->get(buf + size(), object_size_in_buf); if (res != slice->size()) { delete slice; return 0; @@ -738,10 +738,13 @@ class sfinx_pair_vector_t : public sfinx_t { class sfinx_file_t : public sfinx_t { sfinx_size_t size() { - return (size_ = sizeof(u32_t) * (4 + 2 * objects.size() + 1) + 2 * sizeof(u64_t) + name.size() + 1 + - orig_name.size() + 1 + title.size() + 1 + authority.size() + 1 + description.size() + 1 + - comments.size() + 1 + ctime.size() + etime.size() + 4 * sizeof(u8_t) + mimetype.size() + 1 + - csum.size() + 1 + compressed_csum.size() + 1); + u32_t objs_size = sizeof(u32_t); // obj counter + for (u32_t i = 0; i < objects.size(); i++) + objs_size += objects[i].size(); + return (size_ = 4 * sizeof(sfinx_id_t) + 2 * sizeof(sfinx_size_t) + objs_size + + name.size() + 1 + orig_name.size() + 1 + title.size() + 1 + authority.size() + 1 + + description.size() + 1 + comments.size() + 1 + ctime.size() + etime.size() + + 4 * sizeof(u8_t) + mimetype.size() + 1 + csum.size() + 1 + compressed_csum.size() + 1); } sfinx_size_t put(u8_t *buf, sfinx_size_t available_buf_space) { if (size() > available_buf_space) @@ -764,6 +767,7 @@ class sfinx_file_t : public sfinx_t { buf += ::put(t, buf); for (u32_t i = 0; i < objects.size(); i++) buf += objects[i].put(buf); + buf += ::put(name, buf); buf += ::put(orig_name, buf); buf += ::put(title, buf); buf += ::put(authority, buf); @@ -1232,7 +1236,7 @@ static sfinx_t *make_sfinx_element(sfinx_tid_t tid) // ÎÅËÉÊ ÂÕÆÅÒ ÉÚ sfinx ÜÌÅÍÅÎÔÏ× class sfinx_elements { - u32_t data_offset_, allocated_size_; + sfinx_size_t data_offset_, allocated_size_; u8_t *buf_; u32_t n_elements, current_element; // tree @@ -1287,8 +1291,8 @@ class sfinx_elements { u32_t len = decode(len_be32, len_size); current_position += len_size; buf_len_ -= (id_len + len_size + len); - //debug("got object id 0x%x, id_len - %d, len_size - %d, object len - %d, buf_len - %d", id, - // id_len, len_size, len, buf_len); + //debug("got object id %s, id_len - %d, len_size - %d, object len - %d, buf_len - %d", + // sfinx_cmd2str(id), id_len, len_size, len, buf_len); if (!len) debug("Obj %s has zero len", sfinx_cmd2str(id)); if (buf_len_ < 0) { @@ -1301,15 +1305,15 @@ class sfinx_elements { if (!el) return 1; if (len) { - u32_t copied = el->get(buf + current_position, len); + sfinx_size_t copied = el->get(buf + current_position, len); if (copied != len) { - debug("%s parsing error, copied %d from %d !", sfinx_cmd2str(id), copied, len); + debug("%s parsing error, copied %lld from %d !", sfinx_cmd2str(id), copied, len); delete el; return 1; } } elements.push_back(el); - debug("parsed ok: object: %s, len - %d", sfinx_cmd2str(id), len); + //debug("parsed ok: object: %s, len - %d", sfinx_cmd2str(id), len); } // else buf_len is ok // data current_position += len; @@ -1376,7 +1380,7 @@ class sfinx_elements { coded_element_length_be32 = code(element->size(), &element_length_size); if ((element_id_size < 0) || (element_length_size < 0)) return -1; - u32_t space = element->size() + data_offset_ + element_id_size + element_length_size; + sfinx_size_t space = element->size() + data_offset_ + element_id_size + element_length_size; if (space > allocated_size_) { space *= 1.2; u8_t *buf = new u8_t[space]; @@ -1396,20 +1400,21 @@ class sfinx_elements { element_length_size), element_length_size); data_offset_ += element_length_size; // add element data - u32_t res = element->put(buf_ + data_offset_, allocated_size_ - data_offset_); + sfinx_size_t res = element->put(buf_ + data_offset_, allocated_size_ - data_offset_); if (res != element->size()) { - debug("%s data copy error: buf_size - %d, el_size - %d, copied - %d", + debug("%s data copy error: buf_size - %lld, el_size - %lld, copied - %lld", sfinx_cmd2str(element->tid()), allocated_size_ - data_offset_, element->size(), res); return -3; } data_offset_ += element->size(); - debug("added %s, el_id_size - %d, el_len - %d (be_len 0x%x), el_len_size - %d, " - "copied - %d, data_size in tx_buf - %d", sfinx_cmd2str(element->tid()), element_id_size, - element->size(), coded_element_length_be32, element_length_size, res, data_offset_); +// debug("added %s, el_id_size - %d, el_len - %lld (be_len 0x%x), el_len_size - %d, " +// "copied - %lld, data_size in tx_buf - %lld", sfinx_cmd2str(element->tid()), +// element_id_size, element->size(), coded_element_length_be32, element_length_size, +// res, data_offset_); n_elements++; return 0; } - u32_t size() { return data_offset_; } + sfinx_size_t size() { return data_offset_; } u8_t *buf() { return buf_; } }; diff --git a/include/network.H b/include/network.H index 1351c41..5be2276 100644 --- a/include/network.H +++ b/include/network.H @@ -83,7 +83,7 @@ class sfinx_stream { memcpy(((u8_t *)&data_len_be32) + (sizeof(u32_t) - len_bytes_to_read), packet_buf + 6, len_bytes_to_read); u32_t data_len = sfinx_elements::decode(data_len_be32, len_bytes_to_read); - // debug("got packet header: type 0x%x, len - %d", packet_type, data_len); + //debug("got packet header: type 0x%x, len - %d", packet_type, data_len); u8_t *data_buf = new u8_t[data_len]; bool res; if (!data_buf) { diff --git a/lib/misc.C b/lib/misc.C index f4e39e2..7c8fd80 100644 --- a/lib/misc.C +++ b/lib/misc.C @@ -21,7 +21,7 @@ sfinx_size_t get(sfinx_type_t *v, u8_t *buf) sfinx_size_t get(string *v, u8_t *buf) { *v = (char *)(buf); - return v->size(); + return (v->size() + 1); } sfinx_size_t get(u8_t *v, u8_t *buf) diff --git a/sfinx/sfinx.C b/sfinx/sfinx.C index 317e59c..1f03532 100644 --- a/sfinx/sfinx.C +++ b/sfinx/sfinx.C @@ -70,7 +70,7 @@ sfinx_id_t sfinx_app::parent_slice_id(sfinx_id_t slice_id) st->Prepare("select parent_id from slices where id = ?"); st->Set(1, (int64_t)slice_id); st->Execute(); - int32_t p_id = 0; + int64_t p_id = 0; if (st->Fetch()) st->Get(1, &p_id); else @@ -115,6 +115,7 @@ string sfinx_app::slice_directory(sfinx_id_t slice_id) bool sfinx_app::parent_object(sfinx_object_t &src, sfinx_object_t *dst) { + debug("par_obj"); switch (src.type) { case SFINX_SLICE_OBJECT: *dst = src; @@ -123,7 +124,7 @@ bool sfinx_app::parent_object(sfinx_object_t &src, sfinx_object_t *dst) default: break; } - return false; + return false; } // for objects other than slices if the main_obj_id == SFINX_SLICE_OBJECT @@ -145,6 +146,7 @@ bool sfinx_app::set_sorted_path(sfinx_object_t &obj) } if (!parent_object(obj, &t)) return false; + obj = t; } obj.path_name += path; return true; @@ -636,7 +638,7 @@ void faraon_session::relink_slice(sfinx_slice_t *slice) to = o_to.path_name; sfinx->sorted_path_mkdir(SFINX_SLICE_OBJECT, slice->parent_id, slice->parent_id); move(from, to); - // relink +// relink IBPP::Transaction tr = sfinx->driver_->TransactionFactory(sfinx->db_, IBPP::amWrite, IBPP::ilConcurrency, IBPP::lrWait); tr->Start(); -- 2.11.4.GIT