diff --git a/include/date.cpp b/include/date.cpp index 9350c7ae9..19e581805 100755 --- a/include/date.cpp +++ b/include/date.cpp @@ -129,7 +129,7 @@ void TDate::set_end_month() _val = makedata(last_day(month(),year()),month(),year()); } -bool TDate::is_end_month() +bool TDate::is_end_month() const { return day() == last_day(month(),year()); } diff --git a/include/date.h b/include/date.h index ed7be0316..5051303bd 100755 --- a/include/date.h +++ b/include/date.h @@ -107,7 +107,7 @@ public: // @cmember Ritorna l'ultimo giorno possibile del mese static int last_day(int month, int year); // @cmember Controlla se il giorno e' l'ultimo del mese - bool is_end_month(); + bool is_end_month() const; // @cmember Setta il giorno del mese all'ultimo possibile void set_end_month(); // @cmember Controlla se la data è nulla diff --git a/include/isam.cpp b/include/isam.cpp index f2877d59b..14991af9e 100755 --- a/include/isam.cpp +++ b/include/isam.cpp @@ -1087,6 +1087,26 @@ int TBaseisamfile::write() return TBaseisamfile::write(curr()); } +int TBaseisamfile::write_rewrite(const TRectype& rec) +{ + return rec.write_rewrite(*this); +} + +int TBaseisamfile::write_rewrite() +{ + return TBaseisamfile::write_rewrite(curr()); +} + +int TBaseisamfile::rewrite_write(const TRectype& rec) +{ + return rec.rewrite_write(*this); +} + +int TBaseisamfile::rewrite_write() +{ +return TBaseisamfile::rewrite_write(curr()); +} + int TBaseisamfile::_rewrite(const TRectype& rec) { CHECK(!rec.empty(), "Can't write an empty record"); @@ -3926,6 +3946,22 @@ int TRectype::rewrite(TBaseisamfile& f) const return f._rewrite(*this); } +int TRectype::write_rewrite(TBaseisamfile& f) const +{ + int err = write(f); + if (err != NOERR) + err = rewrite(f); + return err; +} + +int TRectype::rewrite_write(TBaseisamfile& f) const +{ + int err = rewrite(f); +if (err != NOERR) + err = write(f); +return err; +} + // Certified ??% int TRectype::remove(TBaseisamfile& f) const { diff --git a/include/isam.h b/include/isam.h index 091edcbf7..881ef2ee9 100755 --- a/include/isam.h +++ b/include/isam.h @@ -44,7 +44,7 @@ public: TIsam_handle file() const { return _isamfile; } void copy(const TMemo_data& m); bool is_dirty(int i) const { return _dirty[i]; } - void set_dirty(int i, bool d = TRUE) { _dirty.set(i, d); } + void set_dirty(int i, bool d = true) { _dirty.set(i, d); } TMemo_data& operator=(const TMemo_data& m) { copy(m); return *this; } TMemo_data(const TMemo_data& m) { copy(m); } @@ -118,6 +118,10 @@ public: virtual int write(TBaseisamfile& f) const; // @cmember Riscrive il record sul file virtual int rewrite(TBaseisamfile& f) const; + // @cmember Aggiunge/Aggiorna il record + virtual int write_rewrite(TBaseisamfile& f) const; + // @cmember Aggiorna/Aggiunge il record + virtual int rewrite_write(TBaseisamfile& f) const; // @cmember Elimina il record dal file virtual int remove(TBaseisamfile& f) const; // @cmember Cambia il campo

della chiave principale con il valore

@@ -127,7 +131,7 @@ public: int items() const; // @cmember Setta il record come non vuoto (chiama ) void setdirty() - { setempty(FALSE); } + { setempty(false); } // @cmember Setta il codice della tabella utilizzata void settab(const char *tab); // @cmember Ritorna il puntatore all'inizio del record. NON dovrebbe essere usata! @@ -161,7 +165,7 @@ public: const char* build_key(int key = 1) const; // @cmember Confronta le chiavi di due record int compare_key(const TRectype& rec, int key = 1, int skip_last = 0) const; - // @cmember Ritorna TRUE se le chiavi di due record sono uguali (vedi ) + // @cmember Ritorna true se le chiavi di due record sono uguali (vedi ) bool same_key(const TRectype& rec, int key = 1, int skip_last = 0) const { return compare_key(rec, key, skip_last) == 0; } @@ -241,7 +245,7 @@ public: // @cmember Ritorna se si tratta di un record valido virtual bool ok() const { return _rec != NULL; } - // @cmember Ritorna TRUE se sono uguali + // @cmember Ritorna true se sono uguali bool is_equal(const TRectype& r) const; virtual void init_memo(const TRecnotype recno = RECORD_NON_FISICO, TIsam_handle file = 0); @@ -320,8 +324,8 @@ protected: // @cmember UNUSED void recover(); // @cmember Apre il file isam di base con lock, permettendo di specificare se usare gli indici o no - int _open(unsigned int mode = _manulock, bool index = TRUE); - int _open_ex(unsigned int mode = _manulock, bool index = TRUE); + int _open(unsigned int mode = _manulock, bool index = true); + int _open_ex(unsigned int mode = _manulock, bool index = true); // @cmember Chiude il file isam di base int _close(); @@ -375,6 +379,12 @@ public: virtual int rewrite(); // @cmember Riscrive un record (il record

) virtual int rewrite(const TRectype& rec); + // @cmember Tenta di aggiungere un record ma se esiste gia' lo aggiorna + virtual int write_rewrite(const TRectype& rec); + virtual int write_rewrite(); + // @cmember Tenta di aggiornare un record ma se non esiste lo crea + virtual int rewrite_write(const TRectype& rec); + virtual int rewrite_write(); // @cmember Riscrive un record alla posizione

virtual int rewriteat(TRecnotype nrec); // @cmember Riscrive un record alla posizione

copiando da

@@ -402,27 +412,27 @@ public: { return _lasterr; } // @cmember Controlla se il file e' valido (ritorna 0 se il file e' valido) int is_valid(bool exclusive); - // @cmember Restituisce se il file è ordinato con indice esterno (default:FALSE) + // @cmember Restituisce se il file è ordinato con indice esterno (default:false) virtual bool is_sorted() - {return FALSE;} + {return false;} // @cmember Ritorna il puntatore al record corrente virtual TRectype& curr() const {return *_current;} - // @cmember Controlla se e' stata raggiunta la fine del file (TRUE se EOF) + // @cmember Controlla se e' stata raggiunta la fine del file (true se EOF) bool eof() const { return status() == _iseof || status() == _isemptyfile;} - // @cmember Controlla se e' stato raggiunto l'inizio del file (TRUE se BOF) + // @cmember Controlla se e' stato raggiunto l'inizio del file (true se BOF) bool bof() const { return status() == _isbof || status() == _isemptyfile;} // @cmember Controlla se l'ultima operazione sul file e' stata effettuata correttamente - // (TRUE se

non contiene codici di errore) + // (true se

non contiene codici di errore) bool good() const { return status() == NOERR;} // @cmember Controlla se l'ultima operazione sul file ha generato un errore - // (TRUE se

contiene codici di errore) + // (true se

contiene codici di errore) bool bad() const { return status() != NOERR;} - // @cmember Controlla se il file e' vuoto (TRUE se vuoto) + // @cmember Controlla se il file e' vuoto (true se vuoto) virtual bool empty(); // @cmember Ritorna il numero logico del record corrente int num() const @@ -540,13 +550,13 @@ class TIsamfile : public TBaseisamfile // @access Public Member public: // @cmember Aggiorna i flags associati al file - // int flags(bool updateeod = FALSE); + // int flags(bool updateeod = false); // @cmember Apre un file di isam con lock (vedi ) - int open(unsigned int mode = _manulock, bool index = TRUE) + int open(unsigned int mode = _manulock, bool index = true) { return _open(mode, index); } - int open_ex(unsigned int mode = _manulock, bool index = TRUE) + int open_ex(unsigned int mode = _manulock, bool index = true) { return _open_ex(mode, index); } // @cmember Chiude il file di isam @@ -600,14 +610,14 @@ public: // @cmember Calcola lo spazio che il file occuperebbe se venisse esteso a

long size(TRecnotype eox); // @cmember Esegue la conversione del tracciato record del file - int update(const TTrec& newrec, bool interactive = FALSE); + int update(const TTrec& newrec, bool interactive = false); // @cmember Esegue sia e - int pack(bool vis = FALSE, bool ask = TRUE); + int pack(bool vis = false, bool ask = true); // @cmember Rimuove fisicamente i record cancellati - int packfile(bool vis = FALSE, bool zap = FALSE); + int packfile(bool vis = false, bool zap = false); // @cmember Rimuove fisicamente gli indici cancellati - int packindex(bool vis = FALSE, bool ask = TRUE); + int packindex(bool vis = false, bool ask = true); // @cmember Rimuove fisicamente tutti i records e gli indici int zap(); @@ -661,9 +671,9 @@ public: virtual int operator ++(); // @cmember Indietreggia al record precedente virtual int operator --(); - // @cmember Ritorna TRUE se tabella + // @cmember Ritorna true se tabella virtual bool tab() const - { return FALSE;} + { return false;} virtual word class_id() const { return CLASS_LOCALISAMFILE; } virtual bool is_kind_of(word id) const { return id == class_id() || TBaseisamfile::is_kind_of(id); } @@ -700,14 +710,14 @@ protected: // @access Public Member public: // @cmember Setta il valore di

a

- void set_autodel(bool val=TRUE) + void set_autodel(bool val = true) {_autodel = val;} virtual word class_id() const { return CLASS_ISAMTEMPFILE; } virtual bool is_kind_of(word id) const { return id == class_id() || TLocalisamfile::is_kind_of(id); } // @cmember Costruttore - TIsamtempfile(int logicnum, const char* radix, bool create=TRUE, bool autodel=FALSE); + TIsamtempfile(int logicnum, const char* radix, bool create = true, bool autodel = false); // @cmember Distruttore virtual ~TIsamtempfile(); }; @@ -730,7 +740,7 @@ protected: // @cmember inizializza il file.

indica se aprire il file in modo esclusivo void init(const char* name, bool exclusive, bool index); // @cmember Apre il file.

indica se aprire il file in modo esclusivo - int open(bool exclusive, bool index = TRUE); + int open(bool exclusive, bool index = true); // @cmember Chiude il file int close(); @@ -747,12 +757,12 @@ public: // @cmember Costruttore.

indica se aprire il file in modo esclusivo. //

indica se aprire il file con indici o meno - TExternisamfile(const char* name, bool exclusive = FALSE, bool index = TRUE); + TExternisamfile(const char* name, bool exclusive = false, bool index = true); // @cmember Costruttore.

é il nome del file che contiene la descrizione del file (estensione trr). //

indica se aprire il file in modo esclusivo. //

indica se aprire il file con indici o meno - TExternisamfile(const char* name, const char * descname, bool exclusive = FALSE, - bool index = TRUE); + TExternisamfile(const char* name, const char * descname, bool exclusive = false, + bool index = true); // @cmember Distruttore virtual ~TExternisamfile(); }; diff --git a/include/netsock.cpp b/include/netsock.cpp index d6dcf3909..83b78e2a7 100755 --- a/include/netsock.cpp +++ b/include/netsock.cpp @@ -1095,6 +1095,92 @@ bool TSocketClient::HttpPostFile(CONNID id, const char* remote, const char* loca return ok; } +static bool FtpSendCommand(TSocket_connection& conn, const char* cmd, const char* param, TString* line) +{ + TString command = cmd; + if (param && *param) + command << ' ' << param; + command << "\r\n"; + + if (!conn.WriteLine(command)) + return false; + + if (line != NULL) + { + line->cut(0); + if (!conn.ReadLine(*line)) + return false; + line->rtrim(); + } + + return true; +} + +bool TSocketClient::FtpSendFile(CONNID id, const char* remote, const char* local, const char* user, const char* pass) +{ + bool ok = false; + + if (!fexist(local)) + return ok; + + TString response; + if (!ReadLine(id, response)) // 220 Welcome + return ok; + + TSocket_connection& conn = *(TSocket_connection*)GetConnection(id); + if (user==NULL || !*user) + user = "anonimous"; + ok = FtpSendCommand(conn, "USER", user, &response); // 331 Please specify the password. + if (!ok || response[0] != '3') + return false; + + if (pass==NULL || !*pass) + pass = "user@campo.it"; + + ok = FtpSendCommand(conn, "PASS", pass, &response); // 230 Login successful. + if (!ok || response[0] != '2') + return false; + + ok = FtpSendCommand(conn, "TYPE", "I", &response); // 200 Switching to Binary mode. + if (!ok || response[0] != '2') + return false; + + FtpSendCommand(conn, "PASV", NULL, &response); // 227 Entering Passive Mode (192,168,4,3,4,82) + const TString& address = response.after("(").before(")"); + int a[6]; + if (sscanf(address, "%d,%d,%d,%d,%d,%d", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]) != 6) + return false; + + ok = FtpSendCommand(conn, "STOR", remote, NULL); + if (!ok) + return false; + + TString16 addr; addr.format("%d.%d.%d.%d", a[0], a[1], a[2], a[3]); + const skstream::service port = skstream::service((a[4] << 8) | a[5]); + skstream outstream(addr, port) ; + + ifstream input(local, ios::binary); + while (!input.eof()) + { + input.read(response.get_buffer(), 1024*4); + const size_t count = input.gcount(); + if (count > 0) + { + outstream.sync(); + outstream.write(response, count); + outstream.flush(); + } + else + break; + } + ok = conn.ReadLine(response); // 150 Ok to send data. + if (ok) + ok = response[0] == '1'; + + FtpSendCommand(conn, "QUIT", NULL, NULL); + return ok; +} + /////////////////////////////////////////////////////////// // TDDEClient /////////////////////////////////////////////////////////// diff --git a/include/netsock.h b/include/netsock.h index aa03edc5b..83c678a68 100755 --- a/include/netsock.h +++ b/include/netsock.h @@ -53,6 +53,8 @@ public: bool HttpGetDir(CONNID id, const char* remote, TString_array& list); bool HttpSoap(CONNID id, const char* query); bool HttpPostFile(CONNID id, const char* remote, const char* local, const char* authorization = NULL); + bool HttpPutFile(CONNID id, const char* remote, const char* local); + bool FtpSendFile(CONNID id, const char* remote, const char* local, const char* user, const char* pass); TSocketClient(); virtual ~TSocketClient(); diff --git a/include/xml.cpp b/include/xml.cpp index 8de971fc7..fd746448c 100755 --- a/include/xml.cpp +++ b/include/xml.cpp @@ -301,7 +301,7 @@ int TXmlItem::ReadTag(istream& inf) if (name[0] == '>') return bChildrenFollow ? +1 : 0; - if (name[0] == '/') + if (name[0] == '/' || name[0] == '?') // Gestisce i casi "/>" e "?>") { bChildrenFollow = false; continue; @@ -367,7 +367,15 @@ void TXmlItem::RemoveLastChild() bool TXmlItem::Read(istream& inf) { Destroy(); - const int res = ReadTag(inf); + int res = ReadTag(inf); + + // Ignora la eventuale riga + if (res == 0 && GetTag()[0] == '?') + { + Destroy(); + res = ReadTag(inf); + } + if (res > 0) // There are children ahead { while (!inf.eof()) @@ -444,6 +452,9 @@ TXmlItem& operator<<(TXmlItem& item, const char* str) void TXmlItem::Write(ostream& outf, int tab) const { + if (tab == 0) + outf << ""; + if (!GetTag().empty()) { Spaces(outf, tab);