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
This commit is contained in:
guy 2009-03-19 15:50:04 +00:00
parent 89aad9db2e
commit 512126d4df
8 changed files with 123 additions and 53 deletions

View File

@ -3546,9 +3546,10 @@ const TString& TRectype::get(const char* fieldname) const
return _memo_data->row( 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) if (orig)
{ {
CHECKD(orig >= LF_EXTERNAL || orig == num(), "Invalid isam handle ", orig);
TCodeb_handle cb_handle = prefix().get_handle(orig, -1); TCodeb_handle cb_handle = prefix().get_handle(orig, -1);
CHECKD(cb_handle >= 0, "Can't read memo from file ", orig); CHECKD(cb_handle >= 0, "Can't read memo from file ", orig);
if (DB_recno(cb_handle) != _memo_data->recno()) if (DB_recno(cb_handle) != _memo_data->recno())

View File

@ -2839,26 +2839,20 @@ KEY TFile_select::run()
{ {
TFilename path; TFilename path;
path.add(field().get()); path.add(field().get());
if (_filter.find('.') > 0 && !_filter.ends_with(".*"))
path.ext(_filter.ext()); path.ext(_filter.ext());
FILE_SPEC fs; FILE_SPEC fs; xvt_fsys_convert_str_to_fspec(path, &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; bool good = xvt_dm_post_file_open(&fs, field().prompt()) == FL_OK;
xvt_fsys_set_dir(&savedir);
if (good) 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) if (good)
{
xvt_fsys_convert_dir_to_str(&fs.dir, path.get_buffer(), path.size());
path.add(fs.name);
field().set(path); field().set(path);
}
else 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; return good ? K_ENTER : K_ESC;
} }

View File

@ -434,7 +434,7 @@ int TFile_info::close()
{ {
// Chiudi fisicamente solo se necessario // Chiudi fisicamente solo se necessario
if (_locked || _exclusive || dir_type() == _extdir) if (_locked || _exclusive || dir_type() == _extdir)
err = close_low(); err = close_low(); // Chiudo fisicamente il file per eliminare i lock
} }
_locked = _exclusive = false; _locked = _exclusive = false;
} }
@ -454,7 +454,7 @@ void TFile_info::auto_close()
int TFile_info::auto_open(int key) int TFile_info::auto_open(int key)
{ {
if (_handle < 0) if (_handle < 0)
open_low(FALSE, TRUE); open_low(false, true);
if (_handle >= 0) 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) TCodeb_handle TFile_manager::get_handle(TIsam_handle name, int key)
{ {
TFile_info& i = fileinfo(name); TFile_info& i = fileinfo(name);
#ifdef DBG
if (i.ref_count() == 0) 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(); TCodeb_handle handle = i.handle();
if (handle < 0) if (handle < 0)
@ -879,7 +885,7 @@ bool TFirm::read(long cod)
int err = NOERR; int err = NOERR;
if (cod < 0L) if (cod < 0L)
cod = prefix().get_codditta(); cod = prefix().get_codditta();
_rec.destroy(); destroy();
TLocalisamfile ditte(LF_NDITTE); TLocalisamfile ditte(LF_NDITTE);
if (cod > 0L) if (cod > 0L)
{ {
@ -894,18 +900,18 @@ bool TFirm::read(long cod)
for (int f = ditta.items()-1; f >= 0; f--) for (int f = ditta.items()-1; f >= 0; f--)
{ {
const char* name = ditta.fieldname(f); const char* name = ditta.fieldname(f);
_rec.add(name, ditta.get(name)); add(name, ditta.get(name));
} }
} }
else else
NFCHECK("Can't read firm %ld: error %d", cod, err); 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& TFirm::get(const char* attr) const
{ {
const TString* str = (const TString*)_rec.objptr(attr); const TString* str = (const TString*)objptr(attr);
if (str == NULL) if (str == NULL)
str = &EMPTY_STRING; str = &EMPTY_STRING;
return *str; return *str;
@ -1069,7 +1075,7 @@ bool TPrefix::exist(long codditta) const
{ {
if (codditta > 0L && codditta < 100000L) if (codditta > 0L && codditta < 100000L)
{ {
TFilename s(firm2dir(codditta)); TFilename s = firm2dir(codditta);
s.add("dir.gen"); s.add("dir.gen");
if (s.exist()) if (s.exist())
{ {
@ -1134,10 +1140,14 @@ bool TPrefix::set_codditta(long codditta, bool force)
s.format("%05lda", codditta); s.format("%05lda", codditta);
set(s, force); set(s, force);
CPutPref(_prefix); CPutPref(_prefix);
if (_firm) if (_firm && _firm->read(codditta))
{ {
_firm->read(codditta); TConfig ini(CONFIG_DITTA, "Main");
xvt_sys_set_profile_string(NULL, "Main", "Company", _firm->get(NDT_RAGSOC)); FOR_EACH_ASSOC_STRING((*_firm), h, key, str)
{
if (*str > ' ')
ini.set(key, str);
}
} }
return true; return true;
} }
@ -1257,6 +1267,12 @@ const char* firm2dir(long codditta)
firm.format("%05lda", codditta); break; firm.format("%05lda", codditta); break;
} }
if (__ptprf[0] == '\0')
{
CGetPref();
CHECK(__ptprf[0], "Invalid prefix");
}
TString& path = get_tmp_string(_MAX_PATH); TString& path = get_tmp_string(_MAX_PATH);
xvt_fsys_build_pathname(path.get_buffer(), "", __ptprf, firm, NULL, NULL); xvt_fsys_build_pathname(path.get_buffer(), "", __ptprf, firm, NULL, NULL);
return path; return path;
@ -1383,7 +1399,7 @@ bool TPrefix::build_firm_data(long codditta, bool flagcom)
return true; return true;
} }
int TPrefix::firms(TString_array& codes) const int TPrefix::firms(TString_array& codes)
{ {
codes.destroy(); codes.destroy();
TFilename n = __ptprf; n.add("?????A"); TFilename n = __ptprf; n.add("?????A");
@ -1392,14 +1408,16 @@ int TPrefix::firms(TString_array& codes) const
{ {
n = xvt_slist_get(dirs, e, NULL); n = xvt_slist_get(dirs, e, NULL);
const TString& code = n.name_only(); 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); codes.add(code);
} }
xvt_slist_destroy(dirs); xvt_slist_destroy(dirs);
return codes.items(); return codes.items();
} }
int TPrefix::firms(TPointer_array& codes) const int TPrefix::firms(TPointer_array& codes)
{ {
TString_array strcodes; firms(strcodes); TString_array strcodes; firms(strcodes);
FOR_EACH_ARRAY_ROW(strcodes, t, row) FOR_EACH_ARRAY_ROW(strcodes, t, row)
@ -1407,6 +1425,44 @@ int TPrefix::firms(TPointer_array& codes) const
return codes.items(); 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 // TTable name converter
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////

View File

@ -67,10 +67,8 @@ public:
// @class TFirm | Classe contenente le informazioni sulla ditta correntemente in uso // @class TFirm | Classe contenente le informazioni sulla ditta correntemente in uso
// //
// @base public | TObject // @base public | TObject
class TFirm : public TObject class TFirm : public TAssoc_array
{ {
TAssoc_array _rec;
public: public:
bool read(long code); bool read(long code);
TFirm& operator=(long code) { read(code); return *this; } TFirm& operator=(long code) { read(code); return *this; }
@ -220,8 +218,9 @@ public:
{ _manager.destroy_info(logicnum); } { _manager.destroy_info(logicnum); }
const TFirm& firm(); const TFirm& firm();
int firms(TString_array& codes) const; static int firms(TString_array& codes);
int firms(TPointer_array& codes) const; // calls above method! static int firms(TPointer_array& codes); // calls above method!
static int firms(TArray& data); // calls above method!
// @cmember Costruttore // @cmember Costruttore
TPrefix(); TPrefix();

View File

@ -3128,6 +3128,13 @@ bool TReport::print_or_preview()
return book.print_or_preview(); return book.print_or_preview();
} }
bool TReport::print()
{
TReport_book book;
book.add(*this);
return book.print();
}
bool TReport::preview() bool TReport::preview()
{ {
TReport_book book; TReport_book book;
@ -3135,11 +3142,11 @@ bool TReport::preview()
return book.preview(); return book.preview();
} }
bool TReport::archive() bool TReport::archive(bool signature)
{ {
TReport_book book; TReport_book book;
book.add(*this); book.add(*this);
return book.archive(); return book.archive(NULL, signature);
} }
TReport::TReport() TReport::TReport()

View File

@ -582,8 +582,9 @@ public:
void destroy(); void destroy();
bool print_or_preview(); bool print_or_preview();
bool print();
bool preview(); bool preview();
bool archive(); bool archive(bool signature);
TReport(); TReport();
virtual ~TReport(); virtual ~TReport();

View File

@ -1,3 +1,4 @@
#include <applicat.h>
#include <automask.h> #include <automask.h>
#include <colors.h> #include <colors.h>
#include <config.h> #include <config.h>
@ -1494,7 +1495,7 @@ bool TBook::print_page(TWindow& win, size_t page)
return true; 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)) if (fname.ends_with(".pdf", true))
return export_pdf(fname, signature); return export_pdf(fname, signature);
@ -1631,6 +1632,13 @@ bool TBook::export_text(const TFilename& fname, bool signature)
_vertical_alignment = str.get_char(); _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; 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; 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) if (ok)
{ {
_pdf_file = filename; _pdf_file = filename;
@ -1932,10 +1940,14 @@ bool TBook::export_pdf(const TFilename& filename, bool certified)
_pageto = 0; _pageto = 0;
_copies = 1; _copies = 1;
ok = xvt_print_start_thread(main_loop_callback, (long)this) != 0; 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)) char outfile[_MAX_PATH] = "";
error_box(TR("Impossibile apporre la firma digitale al documento")); if (xvt_sign_file(filename, outfile))
{
xvt_fsys_remove_file(filename); // Sbatto via il documento originale non firmato
filename = outfile;
}
} }
} }
return ok; return ok;
@ -1993,7 +2005,7 @@ bool TBook::archive(const char* repname, bool signature)
return ok; 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); bool ok = export_pdf(file, signature);
if (ok) if (ok)
@ -2033,8 +2045,8 @@ bool TBook::print_or_preview()
break; break;
case exportprinter: case exportprinter:
{ {
const TFilename f = printer().get_export_file(); TFilename f = printer().get_export_file();
ok = export_text(f, false); ok = export_text(f, NULL);
if (ok) if (ok)
xvt_sys_goto_url(f, "open"); 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); 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; TFilename n = repname;
if (n.blank() && _report != NULL) if (n.blank() && _report != NULL)
@ -2728,7 +2740,7 @@ bool TReport_book::archive(const char* repname)
n = _report->filename().name(); n = _report->filename().name();
n.ext(""); n.ext("");
} }
return TBook::archive(n); return TBook::archive(n, signature);
} }

View File

@ -86,12 +86,12 @@ public:
virtual bool on_link(const TReport_link&) { return false; } 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 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 preview();
virtual bool export_pdf(const TFilename& fname, bool certified); virtual bool export_pdf(TFilename& fname, bool signature);
virtual bool export_text(const TFilename& fname, bool certified); virtual bool export_text(TFilename& fname, bool signature);
virtual bool send_mail(const TFilename& fname, bool certified); virtual bool send_mail(TFilename& fname, bool signature);
virtual bool esporta(); virtual bool esporta();
bool print_or_preview(); // Calls one of the above 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_width() const { return _logical_page_width; }
virtual int logical_page_height() const { return _logical_page_height; } 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 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); TReport_book(const char* name = NULL);
}; };