From 512126d4df10f603425b39a97c7e6a9275a005a7 Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 19 Mar 2009 15:50:04 +0000 Subject: [PATCH] Patch level : 10.0 Files correlati : agalib Ricompilazione Demo : [ ] Commento : Aggiunto supporto per firma digitale git-svn-id: svn://10.65.10.50/trunk@18571 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- include/isam.cpp | 5 +-- include/maskfld.cpp | 18 ++++------ include/prefix.cpp | 84 +++++++++++++++++++++++++++++++++++++-------- include/prefix.h | 9 +++-- include/report.cpp | 13 +++++-- include/report.h | 3 +- include/reprint.cpp | 34 ++++++++++++------ include/reprint.h | 10 +++--- 8 files changed, 123 insertions(+), 53 deletions(-) diff --git a/include/isam.cpp b/include/isam.cpp index 219ccc787..425ae0c99 100755 --- a/include/isam.cpp +++ b/include/isam.cpp @@ -3544,11 +3544,12 @@ const TString& TRectype::get(const char* fieldname) const const int index = findfld(&recd, fieldname); if ( _memo_data->objptr( index )) return _memo_data->row( index ); - if(_memo_data->recno() >= 0L) + if (_memo_data->recno() >= 0L) { - const int orig = _memo_data->file(); + const TIsam_handle orig = _memo_data->file(); if (orig) { + CHECKD(orig >= LF_EXTERNAL || orig == num(), "Invalid isam handle ", orig); TCodeb_handle cb_handle = prefix().get_handle(orig, -1); CHECKD(cb_handle >= 0, "Can't read memo from file ", orig); if (DB_recno(cb_handle) != _memo_data->recno()) diff --git a/include/maskfld.cpp b/include/maskfld.cpp index 45c19bb7f..3b3d7a540 100755 --- a/include/maskfld.cpp +++ b/include/maskfld.cpp @@ -2839,26 +2839,20 @@ KEY TFile_select::run() { TFilename path; path.add(field().get()); - path.ext(_filter.ext()); + if (_filter.find('.') > 0 && !_filter.ends_with(".*")) + path.ext(_filter.ext()); - FILE_SPEC fs; - xvt_fsys_convert_str_to_fspec(path, &fs); + FILE_SPEC fs; xvt_fsys_convert_str_to_fspec(path, &fs); - DIRECTORY savedir; xvt_fsys_get_dir(&savedir); bool good = xvt_dm_post_file_open(&fs, field().prompt()) == FL_OK; - xvt_fsys_set_dir(&savedir); - if (good) { - good = _filter.blank() || xvt_str_match(fs.name, _filter, false); + xvt_fsys_convert_fspec_to_str(&fs, path.get_buffer(), path.size()); + good = _filter.blank() || xvt_str_match(path.name(), _filter, false); if (good) - { - xvt_fsys_convert_dir_to_str(&fs.dir, path.get_buffer(), path.size()); - path.add(fs.name); field().set(path); - } else - field().error_box(FR("Il nome non corrisponde a %s"), _filter.get_buffer()); + field().error_box(FR("Il nome del file non corrisponde a %s"), _filter.get_buffer()); } return good ? K_ENTER : K_ESC; } diff --git a/include/prefix.cpp b/include/prefix.cpp index aed55d0e1..85e5aa713 100755 --- a/include/prefix.cpp +++ b/include/prefix.cpp @@ -434,7 +434,7 @@ int TFile_info::close() { // Chiudi fisicamente solo se necessario if (_locked || _exclusive || dir_type() == _extdir) - err = close_low(); + err = close_low(); // Chiudo fisicamente il file per eliminare i lock } _locked = _exclusive = false; } @@ -454,7 +454,7 @@ void TFile_info::auto_close() int TFile_info::auto_open(int key) { if (_handle < 0) - open_low(FALSE, TRUE); + open_low(false, true); if (_handle >= 0) { @@ -715,8 +715,14 @@ void TFile_manager::destroy_info(int logicnum) TCodeb_handle TFile_manager::get_handle(TIsam_handle name, int key) { TFile_info& i = fileinfo(name); + +#ifdef DBG if (i.ref_count() == 0) - NFCHECK("Can't use closed file %d", i.num()); + { + NFCHECK("Sarebbe bene aggiungere una bella open_files(%d, ...) in TYour_app::create()", i.num()); + i.open(false, true); + } +#endif TCodeb_handle handle = i.handle(); if (handle < 0) @@ -879,7 +885,7 @@ bool TFirm::read(long cod) int err = NOERR; if (cod < 0L) cod = prefix().get_codditta(); - _rec.destroy(); + destroy(); TLocalisamfile ditte(LF_NDITTE); if (cod > 0L) { @@ -894,18 +900,18 @@ bool TFirm::read(long cod) for (int f = ditta.items()-1; f >= 0; f--) { const char* name = ditta.fieldname(f); - _rec.add(name, ditta.get(name)); + add(name, ditta.get(name)); } } else NFCHECK("Can't read firm %ld: error %d", cod, err); - return _rec.items() > 0; + return items() > 0; } const TString& TFirm::get(const char* attr) const { - const TString* str = (const TString*)_rec.objptr(attr); + const TString* str = (const TString*)objptr(attr); if (str == NULL) str = &EMPTY_STRING; return *str; @@ -1069,7 +1075,7 @@ bool TPrefix::exist(long codditta) const { if (codditta > 0L && codditta < 100000L) { - TFilename s(firm2dir(codditta)); + TFilename s = firm2dir(codditta); s.add("dir.gen"); if (s.exist()) { @@ -1134,10 +1140,14 @@ bool TPrefix::set_codditta(long codditta, bool force) s.format("%05lda", codditta); set(s, force); CPutPref(_prefix); - if (_firm) + if (_firm && _firm->read(codditta)) { - _firm->read(codditta); - xvt_sys_set_profile_string(NULL, "Main", "Company", _firm->get(NDT_RAGSOC)); + TConfig ini(CONFIG_DITTA, "Main"); + FOR_EACH_ASSOC_STRING((*_firm), h, key, str) + { + if (*str > ' ') + ini.set(key, str); + } } return true; } @@ -1257,6 +1267,12 @@ const char* firm2dir(long codditta) firm.format("%05lda", codditta); break; } + if (__ptprf[0] == '\0') + { + CGetPref(); + CHECK(__ptprf[0], "Invalid prefix"); + } + TString& path = get_tmp_string(_MAX_PATH); xvt_fsys_build_pathname(path.get_buffer(), "", __ptprf, firm, NULL, NULL); return path; @@ -1383,7 +1399,7 @@ bool TPrefix::build_firm_data(long codditta, bool flagcom) return true; } -int TPrefix::firms(TString_array& codes) const +int TPrefix::firms(TString_array& codes) { codes.destroy(); TFilename n = __ptprf; n.add("?????A"); @@ -1392,14 +1408,16 @@ int TPrefix::firms(TString_array& codes) const { n = xvt_slist_get(dirs, e, NULL); const TString& code = n.name_only(); - if (exist(atol(code))) + TFilename s = firm2dir(atol(code)); + s.add("dir.gen"); + if (s.exist()) codes.add(code); } xvt_slist_destroy(dirs); return codes.items(); } -int TPrefix::firms(TPointer_array& codes) const +int TPrefix::firms(TPointer_array& codes) { TString_array strcodes; firms(strcodes); FOR_EACH_ARRAY_ROW(strcodes, t, row) @@ -1407,6 +1425,44 @@ int TPrefix::firms(TPointer_array& codes) const return codes.items(); } +int TPrefix::firms(TArray& ditte) +{ + ditte.destroy(); + TPointer_array codes; firms(codes); + for (int i = 0; i < codes.items(); i++) + { + const long codditta = codes.get_long(i); + TFilename ininame = firm2dir(codditta); + ininame.add("ditta.ini"); + TConfig ini(ininame, "Main"); + TAssoc_array& fields = ini.list_variables(); + if (fields.empty() && prefix_valid()) + { + TLocalisamfile nditte(LF_NDITTE); + TRectype& ditta = nditte.curr(); + ditta.put(NDT_CODDITTA, codditta); + if (nditte.read() == NOERR) + { + for (int f = 0; f < ditta.items(); f++) + { + const char* fname = ditta.fieldname(f); + const TString& value = ditta.get(fname); + if (!value.blank()) + ini.set(fname, value); + } + } + } + if (fields.empty()) + { + ini.set(NDT_CODDITTA, codditta); + CHECK(!fields.empty(), "Can't genenerate firm data"); + } + ditte.add(fields); + } + return ditte.items(); +} + + /////////////////////////////////////////////////////////// // TTable name converter /////////////////////////////////////////////////////////// diff --git a/include/prefix.h b/include/prefix.h index d23301662..c05b9f9f7 100755 --- a/include/prefix.h +++ b/include/prefix.h @@ -67,10 +67,8 @@ public: // @class TFirm | Classe contenente le informazioni sulla ditta correntemente in uso // // @base public | TObject -class TFirm : public TObject +class TFirm : public TAssoc_array { - TAssoc_array _rec; - public: bool read(long code); TFirm& operator=(long code) { read(code); return *this; } @@ -220,8 +218,9 @@ public: { _manager.destroy_info(logicnum); } const TFirm& firm(); - int firms(TString_array& codes) const; - int firms(TPointer_array& codes) const; // calls above method! + static int firms(TString_array& codes); + static int firms(TPointer_array& codes); // calls above method! + static int firms(TArray& data); // calls above method! // @cmember Costruttore TPrefix(); diff --git a/include/report.cpp b/include/report.cpp index 714d24c3e..cfa5225c5 100755 --- a/include/report.cpp +++ b/include/report.cpp @@ -11,7 +11,7 @@ #include #include -static const char MAX_STRING[2] = {(char) 255, 0}; +static const char MAX_STRING[2] = { (char)255, 0 }; /////////////////////////////////////////////////////////// // TReport_font @@ -3128,6 +3128,13 @@ bool TReport::print_or_preview() return book.print_or_preview(); } +bool TReport::print() +{ + TReport_book book; + book.add(*this); + return book.print(); +} + bool TReport::preview() { TReport_book book; @@ -3135,11 +3142,11 @@ bool TReport::preview() return book.preview(); } -bool TReport::archive() +bool TReport::archive(bool signature) { TReport_book book; book.add(*this); - return book.archive(); + return book.archive(NULL, signature); } TReport::TReport() diff --git a/include/report.h b/include/report.h index ca9364a9e..4f7f032b9 100755 --- a/include/report.h +++ b/include/report.h @@ -582,8 +582,9 @@ public: void destroy(); bool print_or_preview(); + bool print(); bool preview(); - bool archive(); + bool archive(bool signature); TReport(); virtual ~TReport(); diff --git a/include/reprint.cpp b/include/reprint.cpp index d30382129..2815d3fd0 100755 --- a/include/reprint.cpp +++ b/include/reprint.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -1494,7 +1495,7 @@ bool TBook::print_page(TWindow& win, size_t page) return true; } -bool TBook::export_text(const TFilename& fname, bool signature) +bool TBook::export_text(TFilename& fname, bool signature) { if (fname.ends_with(".pdf", true)) return export_pdf(fname, signature); @@ -1631,6 +1632,13 @@ bool TBook::export_text(const TFilename& fname, bool signature) _vertical_alignment = str.get_char(); } } + ofs.close(); + if (signature && main_app().has_module(FDAUT)) + { + char outfile[_MAX_PATH] = ""; + if (xvt_sign_file(fname, outfile)) + fname = outfile; + } return true; } @@ -1922,9 +1930,9 @@ bool TBook::print(size_t pagefrom, size_t pageto, word copies) return xvt_print_start_thread(main_loop_callback, (long)this) != 0; } -bool TBook::export_pdf(const TFilename& filename, bool certified) +bool TBook::export_pdf(TFilename& filename, bool signature) { - bool ok = (pages() > 0) && dongle().active(RSAUT); + bool ok = (pages() > 0) && main_app().has_module(RSAUT); // Controllo paranoico dei permessi if (ok) { _pdf_file = filename; @@ -1932,10 +1940,14 @@ bool TBook::export_pdf(const TFilename& filename, bool certified) _pageto = 0; _copies = 1; ok = xvt_print_start_thread(main_loop_callback, (long)this) != 0; - if (ok && certified) + if (ok && signature && main_app().has_module(FDAUT)) // Controllo paranoico dei permessi { - if (!xvt_pdf_sign(filename)) - error_box(TR("Impossibile apporre la firma digitale al documento")); + char outfile[_MAX_PATH] = ""; + if (xvt_sign_file(filename, outfile)) + { + xvt_fsys_remove_file(filename); // Sbatto via il documento originale non firmato + filename = outfile; + } } } return ok; @@ -1993,7 +2005,7 @@ bool TBook::archive(const char* repname, bool signature) return ok; } -bool TBook::send_mail(const TFilename& file, bool signature) +bool TBook::send_mail(TFilename& file, bool signature) { bool ok = export_pdf(file, signature); if (ok) @@ -2033,8 +2045,8 @@ bool TBook::print_or_preview() break; case exportprinter: { - const TFilename f = printer().get_export_file(); - ok = export_text(f, false); + TFilename f = printer().get_export_file(); + ok = export_text(f, NULL); if (ok) xvt_sys_goto_url(f, "open"); } @@ -2720,7 +2732,7 @@ bool TReport_book::print(size_t pagefrom, size_t pageto, word copies) return TBook::print(pagefrom, pageto, copies); } -bool TReport_book::archive(const char* repname) +bool TReport_book::archive(const char* repname, bool signature) { TFilename n = repname; if (n.blank() && _report != NULL) @@ -2728,7 +2740,7 @@ bool TReport_book::archive(const char* repname) n = _report->filename().name(); n.ext(""); } - return TBook::archive(n); + return TBook::archive(n, signature); } diff --git a/include/reprint.h b/include/reprint.h index 864178d89..14e1f6d1c 100755 --- a/include/reprint.h +++ b/include/reprint.h @@ -86,12 +86,12 @@ public: virtual bool on_link(const TReport_link&) { return false; } virtual bool print(size_t pagefrom = 0, size_t pageto = 0, word copies = 0); - virtual bool archive(const char* repname = NULL, bool certified = false); + virtual bool archive(const char* repname, bool signature); virtual bool preview(); - virtual bool export_pdf(const TFilename& fname, bool certified); - virtual bool export_text(const TFilename& fname, bool certified); - virtual bool send_mail(const TFilename& fname, bool certified); + virtual bool export_pdf(TFilename& fname, bool signature); + virtual bool export_text(TFilename& fname, bool signature); + virtual bool send_mail(TFilename& fname, bool signature); virtual bool esporta(); bool print_or_preview(); // Calls one of the above @@ -132,7 +132,7 @@ public: virtual int logical_page_width() const { return _logical_page_width; } virtual int logical_page_height() const { return _logical_page_height; } virtual bool print(size_t pagefrom = 0, size_t pageto = 0, word copies = 0); - virtual bool archive(const char* repname = NULL); + virtual bool archive(const char* repname, bool signature); TReport_book(const char* name = NULL); };