File transfer

* Added escape encoding for all file types
    - Allows compressed files to transferred using either
      base64, base128 or base256 with escaped control bytes.
  * Added ability to transmit generic files including:
    - jpeg image
    - png images
    - xls, doc and other office documents
  * Transfer time computed for various levels of compression /
    base encoding
This commit is contained in:
David Freese 2012-09-16 18:02:17 -05:00
parent c9d4204eb0
commit d0cd678b40
49 changed files with 1877 additions and 213 deletions

View file

@ -192,7 +192,11 @@ flmsg_SOURCES += \
$(srcdir)/redx/redx_5739B.cxx \
$(srcdir)/redx/redx_5739B_tab.cxx \
$(srcdir)/redx/redx_5739_template.cxx \
$(srcdir)/transfer/transfer.cxx \
$(srcdir)/transfer/transfer_tab.cxx \
$(srcdir)/utils/base64.cxx \
$(srcdir)/utils/base128.cxx \
$(srcdir)/utils/base256.cxx \
$(srcdir)/utils/debug.cxx \
$(srcdir)/utils/parse_xml.cxx \
$(srcdir)/utils/threads.cxx \
@ -229,6 +233,8 @@ EXTRA_DIST = \
$(srcdir)/include/arl_msgs.h \
$(srcdir)/include/ascii.h \
$(srcdir)/include/base64.h \
$(srcdir)/include/base128.h \
$(srcdir)/include/base256.h \
$(srcdir)/include/calendar.h \
$(srcdir)/include/combo.h \
$(srcdir)/include/compat.h \
@ -260,6 +266,7 @@ EXTRA_DIST = \
$(srcdir)/include/status.h \
$(srcdir)/include/threads.h \
$(srcdir)/include/timeops.h \
$(srcdir)/include/transfer.h \
$(srcdir)/include/util.h \
$(srcdir)/include/wrap.h \
$(srcdir)/widgets/Fl_Text_Buffer_mod_1_1.cxx \

View file

@ -159,6 +159,22 @@ void cb_blank_wrap_import(string wrapfilename, string inpbuffer)
using_blank_template = false;
}
int eval_blank_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(base_blank_filename).append("]");
update_blankfields();
update_header(FROM);
fbuff.append(header("<blankform>"));
string outbuf = lineout( blank_msg, blank_field );
if (outbuf.empty()) return 0;
compress_maybe( outbuf );
fbuff.append( outbuf );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void cb_blank_wrap_export()
{
if (check_blankfields()) {

View file

@ -157,6 +157,22 @@ void cb_csv_wrap_import(string wrapfilename, string inpbuffer)
using_csv_template = false;
}
int eval_csv_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(base_csv_filename).append("]");
update_csvfields();
update_header(FROM);
fbuff.append(header("<csvform>"));
string outbuf = lineout( csv_msg, csv_field );
if (outbuf.empty()) return 0;
compress_maybe( outbuf );
fbuff.append( outbuf );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void cb_csv_wrap_export()
{
if (check_csvfields()) {

View file

@ -113,6 +113,7 @@ string ICS_dir = "";
string ICS_msg_dir = "";
string ICS_tmp_dir = "";
string CSV_dir = "";
string XFR_dir = "";
string FLMSG_temp_dir = "";
string cmd_fname = "";
@ -633,11 +634,11 @@ void extract_text(string &buffer, const char *fname)
void read_data_file(string s)
{
long filesize = 0;
char *buff, *buffend;
// char *buff, *buffend;
int retval;
FILE *icsfile;
icsfile = fopen (s.c_str(), "r");
icsfile = fopen (s.c_str(), "rb");// "r");
if (!icsfile)
return;
// determine its size for buffer creation
@ -649,20 +650,55 @@ void read_data_file(string s)
return;
}
buff = new char[filesize + 1];
memset(buff, 0, filesize + 1);
// read the entire file into the buffer
fseek (icsfile, 0, SEEK_SET);
retval = fread (buff, filesize, 1, icsfile);
fclose (icsfile);
buffend = buff + filesize;
string buffer = buff;
delete [] buff;
string buffer;
buffer.resize(filesize);
fseek(icsfile, 0, SEEK_SET);
retval = fread( (void*)buffer.c_str(), 1, filesize, icsfile);
fclose(icsfile);
if (retval != filesize) {
fl_alert2(_("Read error"));
return;
}
extract_text(buffer, s.c_str());
}
int eval_transfer_size()
{
switch (selected_form) {
case ICS203: return eval_203_fsize();
case ICS205: return eval_205_fsize();
case ICS205A: return eval_205a_fsize();
case ICS206: return eval_206_fsize();
case ICS213: return eval_213_fsize();
case ICS214: return eval_214_fsize();
case ICS216: return eval_216_fsize();
case HICS203: return eval_hics203_fsize();
case HICS206: return eval_h206_fsize();
case HICS213: return eval_h213_fsize();
case HICS214: return eval_hics214_fsize();
case RADIOGRAM: return eval_rg_fsize();
case IARU: return eval_iaru_fsize();
case PLAINTEXT: return eval_pt_fsize();
case BLANK: return eval_blank_fsize();
case CSV: return eval_csv_fsize();
case TRANSFER: return eval_transfer_fsize();
case MARSDAILY: return eval_mars_daily_fsize();
case MARSINEEI: return eval_mars_ineei_fsize();
case MARSNET: return eval_mars_net_fsize();
case MARSARMY: return eval_mars_army_fsize();
case MARSNAVY: return eval_mars_navy_fsize();
case WXHC: return eval_wxhc_fsize();
case REDXSNW: return eval_redx_snw_fsize();
case REDX5739: return eval_redx_5739_fsize();
case REDX5739A: return eval_redx_5739A_fsize();
case REDX5739B: return eval_redx_5739B_fsize();
default : ;
}
return 0;
}
void cb_new()
{
switch (selected_form) {
@ -681,6 +717,7 @@ void cb_new()
case IARU: iaru_cb_new(); break;
case PLAINTEXT: cb_pt_new(); break;
case BLANK: cb_blank_new(); break;
case TRANSFER: cb_transfer_new(); break;
case CSV: cb_csv_new(); break;
case MARSDAILY: cb_mars_daily_new(); break;
case MARSINEEI: cb_mars_ineei_new(); break;
@ -694,6 +731,7 @@ void cb_new()
case REDX5739B: cb_redx_5739B_new(); break;
default : ;
}
estimate();
}
void cb_import()
@ -728,6 +766,7 @@ void cb_import()
default:
fl_alert2("Not implemented");
}
estimate();
}
void cb_export()
@ -776,8 +815,8 @@ void wrap_import(const char *fname)
}
if (isok) {
remove_cr( inpbuffer );
if (inpbuffer.find("<transfer>") == string::npos)
remove_cr( inpbuffer );
if (inpbuffer.find("<flics") != string::npos ||
inpbuffer.find("<flmsg") != string::npos) {
if (inpbuffer.find("<ics203>") != string::npos) {
@ -858,6 +897,9 @@ void wrap_import(const char *fname)
} else if (inpbuffer.find("<redx_5739B>") != string::npos) {
selected_form = REDX5739B;
cb_redx_5739B_wrap_import(filename, inpbuffer);
} else if (inpbuffer.find("<transfer>") != string::npos) {
selected_form = TRANSFER;
cb_transfer_wrap_import(filename, inpbuffer);
} else if (!exit_after_print) {
selected_form = NONE;
if (!fl_choice2(_("Cannot identify file type\n\nOpen as text file?"), "yes", "no", NULL)) {
@ -871,6 +913,7 @@ void wrap_import(const char *fname)
}
}
select_form(selected_form);
estimate();
return;
}
@ -902,6 +945,7 @@ void wrap_import(const char *fname)
open_url(badfile_name.c_str());
if (exit_after_print)
return;
estimate();
}
if (!fl_choice2(_("Open as text file?"), "yes", "no", NULL)) {
@ -946,6 +990,7 @@ void cb_wrap_export()
case PLAINTEXT: cb_pt_wrap_export(); break;
case BLANK: cb_blank_wrap_export(); break;
case CSV: cb_csv_wrap_export(); break;
case TRANSFER: cb_transfer_wrap_export(); break;
case MARSDAILY: cb_mars_daily_wrap_export(); break;
case MARSINEEI: cb_mars_ineei_wrap_export(); break;
case MARSNET: cb_mars_net_wrap_export(); break;
@ -988,6 +1033,7 @@ void cb_wrap_autosend()
case PLAINTEXT: cb_pt_wrap_autosend(); break;
case BLANK: cb_blank_wrap_autosend(); break;
case CSV: cb_csv_wrap_autosend(); break;
case TRANSFER: cb_transfer_wrap_autosend(); break;
case MARSDAILY: cb_mars_daily_wrap_autosend(); break;
case MARSINEEI: cb_mars_ineei_wrap_autosend(); break;
case MARSNET: cb_mars_net_wrap_autosend(); break;
@ -1033,6 +1079,7 @@ void cb_load_template()
case REDX5739B: cb_redx_5739B_load_template(); break;
default: ;
}
estimate();
}
void cb_save_template()
@ -1132,6 +1179,7 @@ void cb_open()
case REDX5739B: cb_redx_5739B_open(); break;
default : ;
}
estimate();
}
void cb_save_as()
@ -1392,6 +1440,9 @@ void show_filename(string p)
case CSV:
base_csv_filename = fl_filename_name(p.c_str());
break;
case TRANSFER:
base_transfer_filename = fl_filename_name(p.c_str());
break;
default:
return;
}
@ -1484,6 +1535,7 @@ void after_start(void *)
LOG_INFO("ICS_msg_dir %s", ICS_msg_dir.c_str());
LOG_INFO("ICS_tmp_dir %s", ICS_tmp_dir.c_str());
LOG_INFO("CSV_dir %s", CSV_dir.c_str());
LOG_INFO("Transfer dir %s", XFR_dir.c_str());
LOG_INFO("FLMSG_temp_dir %s", FLMSG_temp_dir.c_str());
def_203_filename = ICS_msg_dir;
@ -1625,6 +1677,7 @@ void after_start(void *)
read_data_file(cmd_fname);
show_filename(cmd_fname);
}
estimate();
} else
default_form();
@ -1669,6 +1722,8 @@ int main(int argc, char *argv[])
if (!(FLMSG_dir[len - 1] == '/' || FLMSG_dir[len-1] == '\\'))
FLMSG_dir += '/';
progStatus.loadLastState();
mainwindow = flmsg_dialog();
mainwindow->callback(exit_main);
@ -1682,10 +1737,24 @@ int main(int argc, char *argv[])
config_radiogram_window = radiogram_dialog();
header_window = headers_dialog();
btn_utc_format0->value(progStatus.UTC == 0);
btn_utc_format1->value(progStatus.UTC == 1);
btn_utc_format2->value(progStatus.UTC == 2);
btn_utc_format3->value(progStatus.UTC == 3);
btn_utc_format4->value(progStatus.UTC == 4);
btn_utc_format5->value(progStatus.UTC == 5);
btn_dtformat0->value(progStatus.dtformat == 0);
btn_dtformat1->value(progStatus.dtformat == 1);
btn_dtformat2->value(progStatus.dtformat == 2);
btn_dtformat3->value(progStatus.dtformat == 3);
cnt_wpl->value(progStatus.wpl);
Fl_File_Icon::load_system_icons();
FSEL::create();
progStatus.loadLastState();
// progStatus.loadLastState();
checkdirectories();
@ -1859,6 +1928,7 @@ void drop_box_changed()
read_data_file(buffer.c_str());
} else // try to extract as a text buffer
extract_text(buffer, NULL);
estimate();
}
void drop_file_changed()
@ -1880,6 +1950,7 @@ void drop_file_changed()
read_data_file(buffer.c_str());
} else // try to extract as a text buffer
extract_text(buffer, NULL);
estimate();
}
void checkdirectories(void)
@ -1903,6 +1974,7 @@ void checkdirectories(void)
{ ICS_msg_dir, "ICS/messages", 0 },
{ ICS_tmp_dir, "ICS/templates", 0 },
{ CSV_dir, "CSV", 0},
{ XFR_dir, "TRANSFERS", 0},
{ FLMSG_temp_dir, "temp_files", 0 },
};
@ -2146,6 +2218,8 @@ int parse_args(int argc, char **argv, int& idx)
fname.find(FREDX5739B_EXT) != string::npos ||
fname.find(TREDX5739B_EXT) != string::npos ||
fname.find(TRANSFER_EXT) != string::npos ||
fname.find(WRAP_EXT) != string::npos ) {
cmd_fname = fname;
}

View file

@ -25,6 +25,8 @@
#include "fileselect.h"
#include "debug.h"
#include "transfer.h"
//======================================================================
Fl_Browser *brwsOptions = (Fl_Browser *)0;
@ -35,13 +37,15 @@ Fl_Output *txt_formname = (Fl_Output *)0;
Fl_Output *txt_filename = (Fl_Output *)0;
Fl_Input *drop_file = (Fl_Input *)0;
Fl_Group *controls = (Fl_Group *)0;
int tab_top;
Fl_Browser *select_arl = (Fl_Browser *)0;
Fl_Input *txt_arl_fill1 = (Fl_Input *)0;
Fl_Input *txt_arl_fill2 = (Fl_Input *)0;
Fl_Input *txt_arl_fill3 = (Fl_Input *)0;
Fl_Input *txt_arl_fill4 = (Fl_Input *)0;
Fl_Input2 *txt_arl_fill1 = (Fl_Input2 *)0;
Fl_Input2 *txt_arl_fill2 = (Fl_Input2 *)0;
Fl_Input2 *txt_arl_fill3 = (Fl_Input2 *)0;
Fl_Input2 *txt_arl_fill4 = (Fl_Input2 *)0;
Fl_Button *btn_arl_cancel = (Fl_Button *)0;
Fl_Button *btn_arl_add = (Fl_Button *)0;
FTextEdit *arl_text = (FTextEdit *)0;
@ -58,32 +62,120 @@ Fl_Round_Button *btn_utc_format3 = (Fl_Round_Button *)0;
Fl_Round_Button *btn_utc_format4 = (Fl_Round_Button *)0;
Fl_Round_Button *btn_utc_format5 = (Fl_Round_Button *)0;
Fl_Input *txt_my_call = (Fl_Input *)0;
Fl_Input *txt_my_tel = (Fl_Input *)0;
Fl_Input *txt_my_name = (Fl_Input *)0;
Fl_Input *txt_my_addr = (Fl_Input *)0;
Fl_Input *txt_my_city = (Fl_Input *)0;
Fl_Input2 *txt_my_call = (Fl_Input2 *)0;
Fl_Input2 *txt_my_tel = (Fl_Input2 *)0;
Fl_Input2 *txt_my_name = (Fl_Input2 *)0;
Fl_Input2 *txt_my_addr = (Fl_Input2 *)0;
Fl_Input2 *txt_my_city = (Fl_Input2 *)0;
Fl_Spinner *cnt_wpl = (Fl_Spinner *)0;
Fl_Check_Button *btn_rgnbr_fname = (Fl_Check_Button *)0;
Fl_Check_Button *btn_arl_desc = (Fl_Check_Button *)0;
Fl_Input *txt_rgnbr = (Fl_Input *)0;
Fl_Input2 *txt_rgnbr = (Fl_Input2 *)0;
Fl_Check_Button *btn_open_on_export = (Fl_Check_Button *)0;
Fl_Check_Button *btn_call_fname = (Fl_Check_Button *)0;
Fl_Check_Button *btn_dt_fname = (Fl_Check_Button *)0;
Fl_Check_Button *btn_sernbr_fname = (Fl_Check_Button *)0;
Fl_Input *txt_sernbr = (Fl_Input *)0;
Fl_Input2 *txt_sernbr = (Fl_Input2 *)0;
Fl_Input2 *txt_mars_roster_file = (Fl_Input2 *)0;
Fl_Input2* txt_hdr_from = (Fl_Input2 *)0;
Fl_Input2* txt_hdr_edit = (Fl_Input2 *)0;
Fl_Input2 * txt_socket_addr = (Fl_Input2 *)0;
Fl_Input2 * txt_socket_port = (Fl_Input2 *)0;
Fl_Button * btn_close_socket_dialog = (Fl_Button *)0;
Fl_Check_Button *btnAutoWordWrap = 0;
Fl_Check_Button *btn_use_compression = 0;
Fl_ComboBox *encoders = 0;
Fl_Counter *cntCharCount = 0;
Fl_ComboBox *cbo_modes = 0;
Fl_Output *txt_transfer_size = 0;
Fl_Output *txt_transfer_time = 0;
int transfer_size;
void cb_btn_transfer_size(Fl_Button *, void*);
struct st_modes {const char *s_mode; float f_cps;};
static st_modes s_modes[] = {
{"DOMX22", 16.0}, {"DOMX44", 31.2}, {"DOMX88", 61.4},
{"MFSK16", 5.8}, {"MFSK22", 8.0}, {"MFSK31", 5.5},
{"MFSK32", 12.0}, {"MFSK64", 24.0}, {"MFSK128", 48.0},
{"MT63-500", 5.0}, {"MT63-1K", 10.0}, {"MT63-2K", 20.0},
{"PSK63RC4", 15.0}, {"PSK63RC5", 19.0}, {"PSK63RC10", 38.0},
{"PSK63RC20", 74.0}, {"PSK63RC32", 120.0},
{"PSK125R", 7.0}, {"PSK125RC4", 28.0}, {"PSK125RC5", 35.0},
{"PSK125RC10", 70.0}, {"PSK125RC16", 112.0},
{"PSK250R", 15.0}, {"PSK250RC2", 30.0}, {"PSK250RC3", 45.0},
{"PSK250RC5", 75.0}, {"PSK250RC7", 105.0},
{"PSK500", 48.0}, {"PSK500C2", 96.0}, {"PSK500C4", 192.0},
{"PSK500R", 29.0}, {"PSK500RC2", 58.0}, {"PSK500RC3", 85.8},
{"PSK500RC4", 114.4},
{"PSK800RC2", 80.0},
{"PSK1000", 96.0}, {"PSK1000C2", 192.0}, {"PSK1000R", 60.0},
{"PSK1000RC2", 120.0},
{ "OL 4-250", 3.0 }, { "OL 8-250", 1.5 }, { "OL 4-500", 6.0 },
{ "OL 8-500", 3.0 }, { "OL 16-500", 1.5 }, { "OL 8-1K", 6.0 },
{ "OL 16-1K", 4.0 }, { "OL 32-1K", 2.0 }, { "OL 64-2K", 2.0 },
{"THOR16", 3.5}, {"THOR22", 4.7}, {"THOR22Q", 4.7},
{"THOR32", 6.7}, {"THOR44", 12.5}, {"THOR64", 13.3},
{"THOR88", 25.0}, {NULL, 0} };
void init_cbo_modes()
{
int i = 0;
cbo_modes->clear();
while (s_modes[i].s_mode != NULL) { cbo_modes->add(s_modes[i].s_mode); i++; }
cbo_modes->index(progStatus.selected_mode);
}
void init_encoders()
{
encoders->clear();
encoders->add("base64");
encoders->add("base128");
encoders->add("base256");
encoders->index(progStatus.encoder);
}
void estimate() {
static char sz_xfr_size[20];
static char sz_xfr_time[20];
float cps = 0, xfr_time = 0;
transfer_size = eval_transfer_size();
if (transfer_size == 0) {
txt_transfer_size->value("");
txt_transfer_time->value("");
return;
}
snprintf(sz_xfr_size, sizeof(sz_xfr_size), "%d bytes", transfer_size);
txt_transfer_size->value(sz_xfr_size);
cps = s_modes[cbo_modes->index()].f_cps;
if (transfer_size <= 0) return;
xfr_time = transfer_size / cps;
snprintf(sz_xfr_time, sizeof(sz_xfr_time), " %.1f secs", xfr_time);
txt_transfer_time->value(sz_xfr_time);
}
//======================================================================
static void cb_mnu_folders(Fl_Menu_*, void*) {
@ -223,6 +315,7 @@ int mREDX5739 = REDX5739;
int mREDX5739A = REDX5739A;
int mREDX5739B = REDX5739B;
int mWXHC = WXHC;
int mTRANSFER = TRANSFER;
Fl_Group *oldtab = (Fl_Group *)0;
@ -385,6 +478,12 @@ void select_form(int form)
txt_formname->value(_("CSV spreadsheet"));
show_filename(def_csv_filename);
break;
case TRANSFER:
oldtab = tab_transfer;
tab_transfer->show();
txt_formname->value(_("File transfer"));
show_filename(def_transfer_filename);
break;
case BLANK:
case NONE:
default:
@ -394,6 +493,7 @@ void select_form(int form)
show_filename(def_blank_filename);
break;
}
eval_transfer_size();
}
static void cb_mnuFormSelect(Fl_Menu_*, void *d) {
@ -471,6 +571,7 @@ Fl_Menu_Item menu_[] = {
{_("Plaintext"), 0, (Fl_Callback*)cb_mnuFormSelect, &mPLAINTEXT, 0, FL_NORMAL_LABEL, 0, 14, 0},
{_("CSV"), 0, (Fl_Callback*)cb_mnuFormSelect, &mCSV, 0, FL_NORMAL_LABEL, 0, 14, 0},
{_("Blank"), 0, (Fl_Callback*)cb_mnuFormSelect, &mBLANK, 0, FL_NORMAL_LABEL, 0, 14, 0},
{_("Transfer"), 0, (Fl_Callback*)cb_mnuFormSelect, &mTRANSFER, 0, FL_NORMAL_LABEL, 0, 14, 0},
{0,0,0,0,0,0,0,0,0},
{_("&Template"), 0, 0, 0, 64, FL_NORMAL_LABEL, 0, 14, 0},
{_("Load"), 0, (Fl_Callback*)cb_mnu_load_template, 0, 128, FL_NORMAL_LABEL, 0, 14, 0},
@ -503,12 +604,30 @@ static void cb_drop_file(Fl_Input*, void*) {
drop_file_changed();
}
void cb_use_compression()
{
progStatus.use_compression = btn_use_compression->value();
estimate();
}
void cb_use_encoder()
{
progStatus.encoder = encoders->index();
estimate();
}
void cb_cbo_modes()
{
estimate();
}
Fl_Double_Window* flmsg_dialog() {
Fl_Double_Window* w = new Fl_Double_Window(570, 430, _("Standard Message Generator"));;
int W = 570, H = 465;
Fl_Double_Window* w = new Fl_Double_Window(570, 465, "");;
w->begin();
Fl_Menu_Bar* mb = new Fl_Menu_Bar(0, 0, 570, 22);
mb->menu(menu_);
Fl_Menu_Bar* mb = new Fl_Menu_Bar(0, 0, W, 22);
mb->menu(menu_);
txt_formname = new Fl_Output(4, 26, 220, 20);
txt_formname->box(FL_FLAT_BOX);
@ -519,7 +638,7 @@ Fl_Double_Window* flmsg_dialog() {
txt_filename->align(FL_ALIGN_LEFT);
txt_filename->color(fl_rgb_color(245, 245, 245));
drop_file = new Fl_Input(535, 22, 28, 28);
drop_file = new Fl_Input2(535, 22, 28, 28);
drop_file->box(FL_OVAL_BOX);
drop_file->align(FL_ALIGN_CENTER | FL_ALIGN_INSIDE);
drop_file->value("");
@ -544,8 +663,55 @@ Fl_Double_Window* flmsg_dialog() {
create_csv_tab();
create_dnd_tab();
create_wxhc_tab();
create_transfer_tab();
controls = new Fl_Group(2, 465 - 28, 566, 26, "");
controls->box(FL_NO_BOX);//DOWN_BOX);
controls->begin();
btn_use_compression = new Fl_Check_Button(10, H-28+4, 60, 18, _("Comp"));
btn_use_compression->tooltip(_("Data will be sent compressed\nif file size is reduced"));
btn_use_compression->down_box(FL_DOWN_BOX);
btn_use_compression->callback((Fl_Callback*)cb_use_compression);
btn_use_compression->value(progStatus.use_compression);
encoders = new Fl_ComboBox(74, H-28+2, 100, 22, "");
encoders->begin();
encoders->when(FL_WHEN_RELEASE);
encoders->tooltip(_("Encode after compression"));
encoders->callback((Fl_Callback*)cb_use_encoder);
encoders->end();
cbo_modes = new Fl_ComboBox(190, H-28+2, 120, 22, _("Mode"));
cbo_modes->begin();
cbo_modes->align(FL_ALIGN_RIGHT);
cbo_modes->when(FL_WHEN_RELEASE);
cbo_modes->tooltip(_("fldigi modem type"));
cbo_modes->box(FL_DOWN_BOX);
cbo_modes->color(FL_BACKGROUND2_COLOR);
cbo_modes->selection_color(FL_BACKGROUND_COLOR);
cbo_modes->labeltype(FL_NORMAL_LABEL);
cbo_modes->labelfont(0);
cbo_modes->labelsize(14);
cbo_modes->labelcolor(FL_FOREGROUND_COLOR);
cbo_modes->callback((Fl_Callback*)cb_cbo_modes);
cbo_modes->end();
txt_transfer_size = new Fl_Output(360, H-28+2, 100, 22, "");
txt_transfer_size->tooltip(_("Transfer size in bytes"));
txt_transfer_size->value("");
txt_transfer_time = new Fl_Output(465, H-28+2, 100, 22, "");
txt_transfer_time->tooltip(_("Transfer time in seconds"));
txt_transfer_time->value("");
controls->end();
w->end();
init_cbo_modes();
init_encoders();
return w;
}
@ -553,23 +719,21 @@ static void cb_btnCloseOptions(Fl_Return_Button*, void*) {
closeoptions();
}
static int opt_col_sizes[] = {200, 0};
Fl_Double_Window* optionsdialog() {
Fl_Double_Window* w;
{ Fl_Double_Window* o = new Fl_Double_Window(410, 260, _("Command Line Options"));
w = o;
{ brwsOptions = new Fl_Browser(3, 31, 405, 202);
} // Fl_Browser* brwsOptions
{ btnCloseOptions = new Fl_Return_Button(329, 239, 72, 20, _("OK"));
btnCloseOptions->callback((Fl_Callback*)cb_btnCloseOptions);
} // Fl_Return_Button* btnCloseOptions
{ Fl_Box* o = new Fl_Box(4, 7, 401, 21, _("usage: flics -<option> [filename]"));
o->box(FL_FLAT_BOX);
o->color((Fl_Color)FL_LIGHT3);
o->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
} // Fl_Box* o
o->end();
} // Fl_Double_Window* o
return w;
int H = 300, W = 560;
Fl_Double_Window* w = new Fl_Double_Window(W, H, _("Command Line Options"));
brwsOptions = new Fl_Browser(2, 2, W - 4, H - 4 - 5 - 20);
brwsOptions->column_widths(opt_col_sizes);
btnCloseOptions = new Fl_Return_Button(W - 4 - 72, H - 5 - 20, 72, 20, _("OK"));
btnCloseOptions->callback((Fl_Callback*)cb_btnCloseOptions);
w->end();
return w;
}
static void cb_select_arl(Fl_Browser* o, void*) {
@ -610,13 +774,13 @@ Fl_Double_Window* arl_dialog() {
select_arl->callback((Fl_Callback*)cb_select_arl);
select_arl->align(FL_ALIGN_TOP);
txt_arl_fill1 = new Fl_Input(48, 131, 465, 22, _("fill 1:"));
txt_arl_fill1 = new Fl_Input2(48, 131, 465, 22, _("fill 1:"));
txt_arl_fill2 = new Fl_Input(48, 155, 465, 22, _("fill 2:"));
txt_arl_fill2 = new Fl_Input2(48, 155, 465, 22, _("fill 2:"));
txt_arl_fill3 = new Fl_Input(48, 179, 465, 22, _("fill 3:"));
txt_arl_fill3 = new Fl_Input2(48, 179, 465, 22, _("fill 3:"));
txt_arl_fill4 = new Fl_Input(48, 204, 465, 22, _("fill 4:"));
txt_arl_fill4 = new Fl_Input2(48, 204, 465, 22, _("fill 4:"));
btn_arl_cancel = new Fl_Button(362, 232, 70, 20, _("Cancel"));
btn_arl_cancel->callback((Fl_Callback*)cb_btn_arl_cancel);
@ -880,23 +1044,23 @@ Fl_Double_Window* personal_dialog()
w->begin();
txt_my_call = new Fl_Input(90, 6, 77, 24, _("Call:"));
txt_my_call = new Fl_Input2(90, 6, 77, 24, _("Call:"));
txt_my_call->callback((Fl_Callback*)cb_txt_my_call);
txt_my_call->value(progStatus.my_call.c_str());
txt_my_tel = new Fl_Input(90, 32, 130, 24, _("Tel:"));
txt_my_tel = new Fl_Input2(90, 32, 130, 24, _("Tel:"));
txt_my_tel->callback((Fl_Callback*)cb_txt_my_tel);
txt_my_tel->value(progStatus.my_tel.c_str());
txt_my_name = new Fl_Input(90, 58, 235, 24, _("Name:"));
txt_my_name = new Fl_Input2(90, 58, 235, 24, _("Name:"));
txt_my_name->callback((Fl_Callback*)cb_txt_my_name);
txt_my_name->value(progStatus.my_name.c_str());
txt_my_addr = new Fl_Input(90, 84, 235, 24, _("Addr:"));
txt_my_addr = new Fl_Input2(90, 84, 235, 24, _("Addr:"));
txt_my_addr->callback((Fl_Callback*)cb_txt_my_addr);
txt_my_addr->value(progStatus.my_addr.c_str());
txt_my_city = new Fl_Input(90, 110, 200, 24, _("City/St/Zip:"));
txt_my_city = new Fl_Input2(90, 110, 200, 24, _("City/St/Zip:"));
txt_my_city->callback((Fl_Callback*)cb_txt_my_city);
txt_my_city->value(progStatus.my_city.c_str());
@ -932,7 +1096,7 @@ Fl_Double_Window* radiogram_dialog()
btn_rgnbr_fname->callback((Fl_Callback*)cb_btn_rgnbr_fname);
btn_rgnbr_fname->value(progStatus.rgnbr_fname);
Y += 30;
txt_rgnbr = new Fl_Input(60, Y, 66, 24, _("Next #"));
txt_rgnbr = new Fl_Input2(60, Y, 66, 24, _("Next #"));
txt_rgnbr->tooltip(_("next number in auto-increment sequence"));
txt_rgnbr->type(2);
txt_rgnbr->callback((Fl_Callback*)cb_txt_rgnbr);
@ -973,11 +1137,6 @@ void cb_autowordwrap()
progStatus.autowordwrap = btnAutoWordWrap->value();
}
void cb_use_compression()
{
progStatus.use_compression = btn_use_compression->value();
}
void cb_charcount()
{
progStatus.charcount = cntCharCount->value();
@ -1002,12 +1161,6 @@ Fl_Double_Window* config_files_dialog() {
btn_open_on_export->callback((Fl_Callback*)cb_btn_open_on_export);
btn_open_on_export->value(progStatus.open_on_export);
btn_use_compression = new Fl_Check_Button(10, 46, 18, 18, _("Use data compression"));
btn_use_compression->tooltip(_("data will be sent compressed (if file size is reduced)"));
btn_use_compression->down_box(FL_DOWN_BOX);
btn_use_compression->callback((Fl_Callback*)cb_use_compression);
btn_use_compression->value(progStatus.use_compression);
group1->end();
Fl_Group* group2 = new Fl_Group(2, 74, 444, 74, _("Naming Files"));
@ -1029,7 +1182,7 @@ Fl_Double_Window* config_files_dialog() {
btn_sernbr_fname->callback((Fl_Callback*)cb_btn_sernbr_fname);
btn_sernbr_fname->value(progStatus.sernbr_fname);
txt_sernbr = new Fl_Input(100, 116, 66, 22, _("Next #"));
txt_sernbr = new Fl_Input2(100, 116, 66, 22, _("Next #"));
txt_sernbr->type(2);
txt_sernbr->callback((Fl_Callback*)cb_txt_sernbr);
txt_sernbr->align(FL_ALIGN_RIGHT);
@ -1156,4 +1309,3 @@ Fl_Double_Window* headers_dialog() {
return w;
}

View file

@ -600,6 +600,23 @@ void cb_hics203_wrap_import(string wrapfilename, string inpbuffer)
using_hics203_template = false;
}
int eval_hics203_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(base_hics203_filename).append("]");
update_hics203fields();
update_header(FROM);
fbuff.append(header("<hics203>"));
hics_buff203.clear();
make_hics_buff203(true);
if (hics_buff203.empty()) return 0;
compress_maybe( hics_buff203 );
fbuff.append( hics_buff203 );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void cb_hics203_wrap_export()
{
if (check_hics203fields()) {

View file

@ -686,6 +686,23 @@ void h206_cb_wrap_import(string wrapfilename, string inpbuffer)
h206_using206_template = false;
}
int eval_h206_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(h206_base_filename).append("]");
h206_update_fields();
update_header(FROM);
fbuff.append(header("<hics206>"));
h206_buff.clear();
h206_make_buff(true);
if (h206_buff.empty()) return 0;
compress_maybe( h206_buff );
fbuff.append( h206_buff );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void h206_cb_wrap_export()
{
if (check_hics206fields()) {

View file

@ -286,6 +286,23 @@ void h213_cb_wrap_import(string wrapfilename, string inpbuffer)
h213_using_template = false;
}
int eval_h213_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(h213_base_filename).append("]");
h213_update_fields();
update_header(FROM);
fbuff.append(header("<hics213>"));
h213_buffer.clear();
h213_make_buffer(true);
if (h213_buffer.empty()) return 0;
compress_maybe( h213_buffer );
fbuff.append( h213_buffer );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void h213_cb_wrap_export()
{
if (check_hics213fields()) {

View file

@ -296,6 +296,23 @@ void hics214_cb_wrap_import(string wrapfilename, string inpbuffer)
hics214_using_template = false;
}
int eval_hics214_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(hics214_base_filename).append("]");
hics214_update_fields();
update_header(FROM);
fbuff.append(header("<hics214>"));
hics214_buff.clear();
hics214_make_buff(true);
if (hics214_buff.empty()) return 0;
compress_maybe( hics214_buff );
fbuff.append( hics214_buff );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void hics214_cb_wrap_export()
{
if (check_hics214fields()) {

View file

@ -353,6 +353,22 @@ void iaru_cb_wrap_import(string wrapfilename, string inpbuffer)
iaru_using_template = false;
}
int eval_iaru_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(iaru_base_filename).append("]");
iaru_update_fields();
update_header(FROM);
fbuff.append(header("<iaru>"));
iaru_buffer.clear();
iaru_make_buffer(true);
if (iaru_buffer.empty()) return 0;
fbuff.append( iaru_buffer );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void iaru_cb_wrap_export()
{
if (iaru_check_fields()) {
@ -377,11 +393,11 @@ void iaru_cb_wrap_export()
wrapfilename = p;
update_header(FROM);
buffer.assign(header("<iaru>"));
iaru_buffer.assign(header("<iaru>"));
iaru_make_buffer(true);
export_wrapfile(iaru_base_filename, wrapfilename, iaru_buffer, pext != WRAP_EXT);
buffer.assign(header("<iaru>"));
iaru_buffer.assign(header("<iaru>"));
iaru_make_buffer(false);
iaru_write(iaru_def_filename);
}
@ -400,11 +416,11 @@ void iaru_cb_wrap_autosend()
if (!iaru_cb_save_as()) return;
update_header(FROM);
buffer.assign(header("<iaru>"));
iaru_buffer.assign(header("<iaru>"));
iaru_make_buffer(true);
xfr_via_socket(iaru_base_filename, iaru_buffer);
buffer.assign(header("<iaru>"));
iaru_buffer.assign(header("<iaru>"));
iaru_make_buffer(false);
iaru_write(iaru_def_filename);
}
@ -439,7 +455,7 @@ void iaru_cb_save_template()
if (p) {
update_header(CHANGED);
iaru_update_fields();
buffer.assign(header("<iaru>"));
iaru_buffer.assign(header("<iaru>"));
iaru_make_buffer();
iaru_write(p);
}
@ -461,7 +477,7 @@ void iaru_cb_save_as_template()
clear_header();
update_header(CHANGED);
iaru_update_fields();
buffer.assign(header("<iaru>"));
iaru_buffer.assign(header("<iaru>"));
iaru_make_buffer();
iaru_write(iaru_def_template_name);

View file

@ -773,6 +773,23 @@ void cb_203_wrap_import(string wrapfilename, string inpbuffer)
using_ics203_template = false;
}
int eval_203_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(base_203_filename).append("]");
update_203fields();
update_header(FROM);
fbuff.append(header("<ics203>"));
buff203.clear();
make_buff203(true);
if (buff203.empty()) return 0;
compress_maybe( buff203 );
fbuff.append( buff203 );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void cb_203_wrap_export()
{
if (check_203fields()) {

View file

@ -336,6 +336,23 @@ void cb_205_wrap_import(string wrapfilename, string inpbuffer)
using_ics205_template = false;
}
int eval_205_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(base_205_filename).append("]");
update_205fields();
update_header(FROM);
fbuff.append(header("<ics205>"));
buff205.clear();
make_buff205(true);
if (buff205.empty()) return 0;
compress_maybe( buff205 );
fbuff.append( buff205 );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void cb_205_wrap_export()
{
if (check_205fields()) {

View file

@ -319,6 +319,23 @@ void cb_205a_wrap_import(string wrapfilename, string inpbuffer)
using_ics205a_template = false;
}
int eval_205a_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(base_205a_filename).append("]");
update_205afields();
update_header(FROM);
fbuff.append(header("<ics205a>"));
buff205a.clear();
make_buff205a(true);
if (buff205a.empty()) return 0;
compress_maybe( buff205a );
fbuff.append( buff205a );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void cb_205a_wrap_export()
{
if (check_205afields()) {

View file

@ -524,6 +524,23 @@ void cb_206_wrap_import(string wrapfilename, string inpbuffer)
using_ics206_template = false;
}
int eval_206_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(base_206_filename).append("]");
update_206fields();
update_header(FROM);
fbuff.append(header("<ics206>"));
buff206.clear();
make_buff206(true);
if (buff206.empty()) return 0;
compress_maybe( buff206 );
fbuff.append( buff206 );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void cb_206_wrap_export()
{
if (check_206fields()) {

View file

@ -341,6 +341,23 @@ void cb_213_wrap_import(string wrapfilename, string inpbuffer)
show_filename(def_213_filename);
}
int eval_213_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(base_213_filename).append("]");
update_fields();
update_header(FROM);
fbuff.append(header("<ics213>"));
buffer.clear();
make_buffer(true);
if (buffer.empty()) return 0;
compress_maybe( buffer );
fbuff.append( buffer );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void cb_213_wrap_export()
{
if (check_fields()) {

View file

@ -325,6 +325,23 @@ void cb_214_wrap_import(string wrapfilename, string inpbuffer)
using_ics214_template = false;
}
int eval_214_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(base_214_filename).append("]");
update_214fields();
update_header(FROM);
fbuff.append(header("<ics214>"));
buff214.clear();
make_buff214(true);
if (buff214.empty()) return 0;
compress_maybe( buff214 );
fbuff.append( buff214 );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void cb_214_wrap_export()
{
if (check_214fields()) {

View file

@ -351,6 +351,23 @@ void cb_216_wrap_import(string wrapfilename, string inpbuffer)
using_ics216_template = false;
}
int eval_216_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(base_216_filename).append("]");
update_216fields();
update_header(FROM);
fbuff.append(header("<ics216>"));
buff216.clear();
make_buff216(true);
if (buff216.empty()) return 0;
compress_maybe( buff216 );
fbuff.append( buff216 );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void cb_216_wrap_export()
{
if (check_216fields()) {

49
src/include/base128.h Normal file
View file

@ -0,0 +1,49 @@
// =====================================================================
//
// base128.h
//
// Author: Dave Freese, W1HKJ
// Copyright: 2012
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. It is
// copyright under the GNU General Public License.
//
// You should have received a copy of the GNU General Public License
// along with the program; if not, write to the Free Software
// Foundation, Inc.
// 59 Temple Place, Suite 330
// Boston, MA 02111-1307 USA
//
// =====================================================================
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string>
using namespace std;
typedef unsigned char byte;
class base128 {
#define LINELEN 64
private:
string output;
size_t iolen;
size_t iocp;
bool ateof;
int linelength;
void init();
void escape(string &, bool encode = true);
void addlf(string &);
void remlf(string &);
public:
base128() { init(); };
~base128() {};
string encode(string &in);
string decode(string &in);
};

46
src/include/base256.h Normal file
View file

@ -0,0 +1,46 @@
// =====================================================================
//
// base256.h
//
// Author: Dave Freese, W1HKJ
// Copyright: 2012
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. It is
// copyright under the GNU General Public License.
//
// You should have received a copy of the GNU General Public License
// along with the program; if not, write to the Free Software
// Foundation, Inc.
// 59 Temple Place, Suite 330
// Boston, MA 02111-1307 USA
//
// =====================================================================
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string>
using namespace std;
class base256 {
#define LINELEN 64
private:
string output;
size_t iolen;
size_t iocp;
bool ateof;
int linelength;
void init();
void escape(string &, bool encode = true);
void addlf(string &);
void remlf(string &);
public:
base256() { init(); };
~base256() {};
string encode(string &in);
string decode(string &in);
};

View file

@ -29,7 +29,7 @@ using namespace std;
typedef unsigned char byte;
class base64 {
#define LINELEN 72
#define LINELEN 64
private:
string output;
size_t iolen;

View file

@ -18,6 +18,9 @@
//
// =====================================================================
#ifndef _CCRC16_
#define _CCRC16_
#include <string>
#include "debug.h"
@ -61,3 +64,4 @@ public:
}
};
#endif

View file

@ -29,6 +29,7 @@
#include "arl_msgs.h"
#include "hx_msgs.h"
#include "crc16.h"
#define DEBUG 1
@ -40,7 +41,7 @@ HICS203, HICS206, HICS213, HICS214, IARU,
RADIOGRAM, PLAINTEXT, BLANK, CSV,
MARSDAILY, MARSINEEI, MARSNET, MARSARMY, MARSNAVY,
REDXSNW, REDX5739, REDX5739A, REDX5739B,
WXHC };
WXHC, TRANSFER };
struct FIELD { string f_type; string f_data; void **w; char w_type; };
extern FIELD fields[];
@ -59,6 +60,7 @@ extern Fl_Double_Window *arlwindow;
extern Fl_Double_Window *config_files_window;
extern Fl_Double_Window *hxwindow;
extern Fl_Double_Window *header_window;
extern Fl_Double_Window *time_estimate_window;
extern string flmsgHomeDir;
extern string IcsHomeDir;
@ -79,6 +81,7 @@ extern string ICS_dir;
extern string ICS_msg_dir;
extern string ICS_tmp_dir;
extern string CSV_dir;
extern string XFR_dir;
extern string FLMSG_temp_dir;
@ -144,6 +147,8 @@ extern void fm_html(string &html);
extern void drop_box_changed();
extern int eval_transfer_size();
// used by all form management
extern string lineout( string &, string & );
@ -196,6 +201,7 @@ extern void cb_205_save();
extern void cb_205_html();
extern void cb_205_msg_type();
extern void cb_205_textout();
extern int eval_205_fsize();
// ics205a
extern string base_205a_filename;
@ -228,6 +234,7 @@ extern void cb_205a_save();
extern void cb_205a_html();
extern void cb_205a_msg_type();
extern void cb_205a_textout();
extern int eval_205a_fsize();
// ics203
extern string yes;
@ -261,6 +268,7 @@ extern void cb_203_save();
extern void cb_203_html();
extern void cb_203_msg_type();
extern void cb_203_textout();
extern int eval_203_fsize();
// ics206
extern string yes;
@ -294,6 +302,7 @@ extern void cb_206_save();
extern void cb_206_html();
extern void cb_206_msg_type();
extern void cb_206_textout();
extern int eval_206_fsize();
// ics213
extern bool using_213Template;
@ -325,6 +334,7 @@ extern void cb_SetDate1();
extern void cb_SetDate2();
extern void cb_SetTime1();
extern void cb_SetTime2();
extern int eval_213_fsize();
// ics214
@ -356,6 +366,7 @@ extern void cb_214_save();
extern void cb_214_html();
extern void cb_214_msg_type();
extern void cb_214_textout();
extern int eval_214_fsize();
// ics216
@ -387,6 +398,7 @@ extern void cb_216_save();
extern void cb_216_html();
extern void cb_216_msg_type();
extern void cb_216_textout();
extern int eval_216_fsize();
// radiogram
extern bool using_rg_template;
@ -431,6 +443,7 @@ extern void set_rg_choices();
extern void cb_rg_check();
extern void cb_rg_nbr(Fl_Widget *);
extern void cb_rg_filter_input(Fl_Widget *);
extern int eval_rg_fsize();
extern void read_data_file(string);
@ -463,6 +476,7 @@ extern void cb_pt_save();
extern void cb_pt_html();
extern void cb_pt_msg_type();
extern void cb_pt_textout();
extern int eval_pt_fsize();
// blank form
extern bool using_blank_template;
@ -494,6 +508,7 @@ extern void cb_blank_save();
extern void cb_blank_html();
extern void cb_blank_msg_type();
extern void cb_blank_textout();
extern int eval_blank_fsize();
// csv form
extern bool using_csv_template;
@ -525,6 +540,7 @@ extern void cb_csv_textout();
extern void cb_csv_export_data(bool);
extern void cb_csv_import_data();
extern void csv_set_fname(const char *);
extern int eval_csv_fsize();
// mars daily
extern string def_mars_daily_filename;
@ -552,6 +568,7 @@ extern void cb_mars_daily_save();
extern void cb_mars_daily_html();
extern void cb_mars_daily_msg_type();
extern void cb_mars_daily_textout();
extern int eval_mars_daily_fsize();
// mars ineei
extern string def_mars_ineei_filename;
@ -581,6 +598,7 @@ extern void cb_mars_ineei_html();
extern void cb_mars_ineei_textout();
extern void cb_mars_ineei_html();
extern void cb_mars_ineei_textout();
extern int eval_mars_ineei_fsize();
// mars net
extern string def_mars_net_filename;
@ -610,6 +628,7 @@ extern bool cb_mars_net_save_as();
extern void cb_mars_net_save();
extern void cb_mars_net_html();
extern void cb_mars_net_textout();
extern int eval_mars_net_fsize();
// mars army
extern bool using_mars_army_template;
@ -638,6 +657,7 @@ extern void cb_mars_army_save();
extern void cb_mars_army_html();
extern void cb_mars_army_msg_type();
extern void cb_mars_army_textout();
extern int eval_mars_army_fsize();
// mars navy
extern bool using_mars_navy_template;
@ -666,6 +686,7 @@ extern void cb_mars_navy_save();
extern void cb_mars_navy_html();
extern void cb_mars_navy_msg_type();
extern void cb_mars_navy_textout();
extern int eval_mars_navy_fsize();
// hics203
extern string hics_buff203;
@ -696,6 +717,7 @@ extern void cb_hics203_save();
extern void cb_hics203_html();
extern void cb_hics203_msg_type();
extern void cb_hics203_textout();
extern int eval_hics203_fsize();
// ics_h206
extern string h206_buff;
@ -725,6 +747,7 @@ extern bool h206_cb_save_as();
extern void h206_cb_save();
extern void h206_cb_html();
extern void h206_cb_textout();
extern int eval_h206_fsize();
// ics_h213
@ -758,6 +781,7 @@ extern bool h213_cb_save_as();
extern void h213_cb_save();
extern void h213_cb_html();
extern void h213_cb_textout();
extern int eval_h213_fsize();
// hics 214 variables and functions
@ -800,6 +824,7 @@ extern bool hics214_cb_save_as();
extern void hics214_cb_save();
extern void hics214_cb_html();
extern void hics214_cb_textout();
extern int eval_hics214_fsize();
// IARU form
@ -836,6 +861,7 @@ extern void iaru_cb_save();
extern void iaru_cb_check();
extern void iaru_cb_html();
extern void iaru_cb_textout();
extern int eval_iaru_fsize();
extern string iaru_base_filename;
extern string iaru_def_filename;
@ -871,6 +897,7 @@ extern void cb_redx_snw_save();
extern void cb_redx_snw_html();
extern void cb_snw_msg_type();
extern void cb_redx_snw_textout();
extern int eval_redx_snw_fsize();
// Form 5739
@ -899,6 +926,7 @@ extern void cb_redx_5739_save();
extern void cb_redx_5739_html();
extern void cb_5739_msg_type();
extern void cb_redx_5739_textout();
extern int eval_redx_5739_fsize();
// Form 5739A
@ -927,6 +955,7 @@ extern void cb_redx_5739A_save();
extern void cb_redx_5739A_html();
extern void cb_5739A_msg_type();
extern void cb_redx_5739A_textout();
extern int eval_redx_5739A_fsize();
// Form 5739B
@ -955,6 +984,7 @@ extern void cb_redx_5739B_save();
extern void cb_redx_5739B_html();
extern void cb_5739B_msg_type();
extern void cb_redx_5739B_textout();
extern int eval_redx_5739B_fsize();
//======================================================================
// National Hurricane Center, Hurricane Weather Report Form
@ -987,5 +1017,36 @@ extern bool cb_wxhc_save_as();
extern void cb_wxhc_save();
extern void cb_wxhc_html();
extern void cb_wxhc_textout();
extern int eval_wxhc_fsize();
//======================================================================
// generic file transfer
//======================================================================
extern string transfer_buffer;
extern string def_transfer_filename;
extern string base_transfer_filename;
extern void clear_transfer_form();
extern void read_transfer_buffer(string data);
extern void cb_transfer_new();
extern void cb_transfer_import();
extern void cb_transfer_export();
extern void cb_transfer_wrap_import(string wrapfilename, string inpbuffer);
extern int eval_transfer_fsize();
extern void cb_transfer_wrap_export();
extern void cb_transfer_wrap_autosend();
extern void cb_transfer_load_template();
extern void cb_transfer_save_template();
extern void cb_transfer_save_as_template();
extern void cb_transfer_open();
extern void write_transfer(string s);
extern bool cb_transfer_save_as();
extern void cb_transfer_save();
extern void cb_transfer_msg_type();
extern void cb_transfer_html();
extern void cb_transfer_textout();
extern void cb_transfer_import_data();
extern void cb_transfer_export_data();
#endif

View file

@ -82,6 +82,8 @@
#define FWXHC_EXT ".w2s"
#define TWXHC_EXT ".w2t"
#define TRANSFER_EXT ".xfr"
#define WRAP_EXT ".wrap"
#endif

View file

@ -68,10 +68,10 @@ extern Fl_Return_Button *btnCloseOptions;
extern Fl_Double_Window* arl_dialog();
extern Fl_Browser *select_arl;
extern Fl_Input *txt_arl_fill1;
extern Fl_Input *txt_arl_fill2;
extern Fl_Input *txt_arl_fill3;
extern Fl_Input *txt_arl_fill4;
extern Fl_Input2 *txt_arl_fill1;
extern Fl_Input2 *txt_arl_fill2;
extern Fl_Input2 *txt_arl_fill3;
extern Fl_Input2 *txt_arl_fill4;
extern Fl_Button *btn_arl_cancel;
extern Fl_Button *btn_arl_add;
extern FTextEdit *arl_text;
@ -91,11 +91,11 @@ extern Fl_Round_Button *btn_utc_format5;
extern Fl_Button *btn_close_date_time_dialog;
extern Fl_Double_Window* personal_dialog();
extern Fl_Input *txt_my_call;
extern Fl_Input *txt_my_tel;
extern Fl_Input *txt_my_name;
extern Fl_Input *txt_my_addr;
extern Fl_Input *txt_my_city;
extern Fl_Input2 *txt_my_call;
extern Fl_Input2 *txt_my_tel;
extern Fl_Input2 *txt_my_name;
extern Fl_Input2 *txt_my_addr;
extern Fl_Input2 *txt_my_city;
extern Fl_Double_Window* headers_dialog();
extern Fl_Input2* txt_hdr_from;
@ -107,7 +107,7 @@ extern Fl_Input2* txt_socket_port;
extern Fl_Double_Window* radiogram_dialog();
extern Fl_Spinner *cnt_wpl;
extern Fl_Check_Button *btn_rgnbr_fname;
extern Fl_Input *txt_rgnbr;
extern Fl_Input2 *txt_rgnbr;
extern Fl_Double_Window* config_files_dialog();
extern Fl_Check_Button *btn_open_on_export;
@ -115,7 +115,7 @@ extern Fl_Check_Button *btn_use_compression;
extern Fl_Check_Button *btn_call_fname;
extern Fl_Check_Button *btn_dt_fname;
extern Fl_Check_Button *btn_sernbr_fname;
extern Fl_Input *txt_sernbr;
extern Fl_Input2 *txt_sernbr;
extern Fl_Input2 *txt_mars_roster_file;
extern Fl_Double_Window* hx_dialog();
@ -128,6 +128,13 @@ extern Fl_Output *txt_hx_instructions;
extern void select_form(int form);
extern Fl_Output *txt_transfer_size;
extern int transfer_size;
extern Fl_ComboBox *cbo_modes;
extern void estimate();
//======================================================================
// ICS
//======================================================================

View file

@ -57,6 +57,8 @@ struct status {
string socket_port;
bool use_compression;
int encoder;
int selected_mode;
};
extern status progStatus;

18
src/include/transfer.h Normal file
View file

@ -0,0 +1,18 @@
#ifndef _TRANSFER_
#define _TRANSFER_
#include <FL/Fl_Output.H>
#include <FL/Fl_Button.H>
extern Fl_Group *tab_transfer;
extern Fl_Output *txt_send_filename;
extern Fl_Output *txt_rcvd_filename;
extern Fl_Button *btn_select_send;
extern Fl_Button *btn_save_rcvd;
extern string def_transfer_filename;
extern void create_transfer_tab();
extern void clear_transfer_form();
#endif

View file

@ -26,7 +26,9 @@
using namespace std;
extern void compress_maybe(string& input);
enum {BASE64, BASE128, BASE256};
extern void compress_maybe(string& input, bool file_transfer = false);
extern void decompress_maybe(string& input);
extern void export_wrapfile(string, string, string, bool with_ext);

View file

@ -113,6 +113,24 @@
StopCompilingDueBUG
#endif
const char *LZMA_ERRORS[] = {
"SZ_OK",
"SZ_ERROR_DATA",
"SZ_ERROR_MEM",
"SZ_ERROR_CRC",
"SZ_ERROR_UNSUPPORTED",
"SZ_ERROR_PARAM",
"SZ_ERROR_INPUT_EOF",
"SZ_ERROR_OUTPUT_EOF",
"SZ_ERROR_READ",
"SZ_ERROR_WRITE",
"SZ_ERROR_PROGRESS",
"SZ_ERROR_FAIL",
"SZ_ERROR_THREAD",
"n/a", "n/a", "n/a",
"SZ_ERROR_ARCHIVE",
"SZ_ERROR_NO_ARCHIVE"};
static const Byte kLiteralNextStates[kNumStates * 2] =
{
0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5,

View file

@ -28,6 +28,8 @@
#define SZ_ERROR_ARCHIVE 16
#define SZ_ERROR_NO_ARCHIVE 17
extern const char *LZMA_ERRORS[];
typedef int SRes;
#ifdef _WIN32

View file

@ -255,6 +255,23 @@ void cb_mars_army_wrap_import(string wrapfilename, string inpbuffer)
using_mars_army_template = false;
}
int eval_mars_army_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(base_mars_army_filename).append("]");
update_mars_armyfields();
update_header(FROM);
fbuff.append(header("<mars_army>"));
buffmars_army.clear();
make_buffmars_army(true);
if (buffmars_army.empty()) return 0;
compress_maybe( buffmars_army );
fbuff.append( buffmars_army );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void cb_mars_army_wrap_export()
{
if (check_mars_armyfields()) {

View file

@ -468,6 +468,23 @@ void cb_mars_daily_wrap_import(string wrapfilename, string inpbuffer)
using_mars_daily_template = false;
}
int eval_mars_daily_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(base_mars_daily_filename).append("]");
update_mars_dailyfields();
update_header(FROM);
fbuff.append(header("<mars_daily>"));
buffmars_daily.clear();
make_buffmars_daily(true);
if (buffmars_daily.empty()) return 0;
compress_maybe( buffmars_daily );
fbuff.append( buffmars_daily );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void cb_mars_daily_wrap_export()
{
if (check_mars_dailyfields()) {

View file

@ -469,6 +469,23 @@ void cb_mars_ineei_wrap_import(string wrapfilename, string inpbuffer)
using_mars_ineei_template = false;
}
int eval_mars_ineei_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(base_mars_ineei_filename).append("]");
update_mars_ineei_fields();
update_header(FROM);
fbuff.append(header("<mars_ineei>"));
ineei_buff.clear();
make_mars_ineei_buff(true);
if (ineei_buff.empty()) return 0;
compress_maybe( ineei_buff );
fbuff.append( ineei_buff );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void cb_mars_ineei_wrap_export()
{
if (check_mars_ineei_fields()) {

View file

@ -226,6 +226,23 @@ void cb_mars_navy_wrap_import(string wrapfilename, string inpbuffer)
using_mars_navy_template = false;
}
int eval_mars_navy_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(base_mars_navy_filename).append("]");
update_mars_navyfields();
update_header(FROM);
fbuff.append(header("<mars_navy>"));
buffmars_navy.clear();
make_buffmars_navy(true);
if (buffmars_navy.empty()) return 0;
compress_maybe( buffmars_navy );
fbuff.append( buffmars_navy );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void cb_mars_navy_wrap_export()
{
if (check_mars_navyfields()) {

View file

@ -398,6 +398,23 @@ void cb_mars_net_wrap_import(string wrapfilename, string inpbuffer)
using_mars_net_template = false;
}
int eval_mars_net_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(base_mars_net_filename).append("]");
update_mars_net_fields();
update_header(FROM);
fbuff.append(header("<mars_net>"));
buffnet.clear();
make_mars_buffnet(true);
if (buffnet.empty()) return 0;
compress_maybe( buffnet );
fbuff.append( buffnet );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void cb_mars_net_wrap_export()
{
if (check_mars_net_fields()) {

View file

@ -547,6 +547,23 @@ void cb_wxhc_wrap_import(string wrapfilename, string inpbuffer)
using_wxhc_template = false;
}
int eval_wxhc_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(base_wxhc_filename).append("]");
update_wxhcfields();
update_header(FROM);
fbuff.append(header("<nhc_wx>"));
buffwxhc.clear();
make_buffwxhc(true);
if (buffwxhc.empty()) return 0;
compress_maybe( buffwxhc );
fbuff.append( buffwxhc );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void cb_wxhc_wrap_export()
{
if (check_wxhcfields()) {

View file

@ -254,6 +254,23 @@ void cb_pt_wrap_import(string wrapfilename, string inpbuffer)
using_pt_template = false;
}
int eval_pt_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(base_pt_filename).append("]");
update_ptfields();
update_header(FROM);
fbuff.append(header("<plaintext>"));
ptbuffer.clear();
make_ptbuffer(true);
if (ptbuffer.empty()) return 0;
compress_maybe( ptbuffer );
fbuff.append( ptbuffer );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void cb_pt_wrap_export()
{
if (check_ptfields()) {

View file

@ -485,6 +485,22 @@ void cb_rg_wrap_import(string wrapfilename, string inpbuffer)
using_rg_template = false;
}
int eval_rg_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(base_rg_filename).append("]");
update_rgfields();
update_header(FROM);
fbuff.append(header("<radiogram>"));
buffer.clear();
make_rg_buffer(true);
if (buffer.empty()) return 0;
fbuff.append( buffer );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void cb_rg_wrap_export()
{
if (btn_rg_check->labelcolor() == FL_RED)

View file

@ -736,6 +736,23 @@ void cb_redx_5739_wrap_import(string wrapfilename, string inpbuffer)
using_redx_5739_template = false;
}
int eval_redx_5739_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(base_redx_5739_filename).append("]");
update_redx_5739fields();
update_header(FROM);
fbuff.append(header("<redx_5739>"));
buffredx_5739.clear();
make_buffredx_5739(true);
if (buffredx_5739.empty()) return 0;
compress_maybe( buffredx_5739 );
fbuff.append( buffredx_5739 );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void cb_redx_5739_wrap_export()
{
if (check_redx_5739fields()) {

View file

@ -511,6 +511,23 @@ void cb_redx_5739A_wrap_import(string wrapfilename, string inpbuffer)
using_redx_5739A_template = false;
}
int eval_redx_5739A_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(base_redx_5739A_filename).append("]");
update_redx_5739Afields();
update_header(FROM);
fbuff.append(header("<redx_5739A>"));
buffredx_5739A.clear();
make_buffredx_5739A(true);
if (buffredx_5739A.empty()) return 0;
compress_maybe( buffredx_5739A );
fbuff.append( buffredx_5739A );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void cb_redx_5739A_wrap_export()
{
if (check_redx_5739Afields()) {

View file

@ -493,6 +493,23 @@ void cb_redx_5739B_wrap_import(string wrapfilename, string inpbuffer)
using_redx_5739B_template = false;
}
int eval_redx_5739B_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(base_redx_5739B_filename).append("]");
update_redx_5739Bfields();
update_header(FROM);
fbuff.append(header("<redx_5739B>"));
buffredx_5739B.clear();
make_buffredx_5739B(true);
if (buffredx_5739B.empty()) return 0;
compress_maybe( buffredx_5739B );
fbuff.append( buffredx_5739B );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void cb_redx_5739B_wrap_export()
{
if (check_redx_5739Bfields()) {

View file

@ -357,6 +357,23 @@ void cb_redx_snw_wrap_import(string wrapfilename, string inpbuffer)
using_redx_snw_template = false;
}
int eval_redx_snw_fsize()
{
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(base_redx_snw_filename).append("]");
update_redx_snwfields();
update_header(FROM);
fbuff.append(header("<redx_snw>"));
buffredx_snw.clear();
make_buffredx_snw(true);
if (buffredx_snw.empty()) return 0;
compress_maybe( buffredx_snw );
fbuff.append( buffredx_snw );
fbuff.append("[WRAP:chksum ").append(chksum.scrc16(fbuff)).append("][WRAP:end]");
return fbuff.length();
}
void cb_redx_snw_wrap_export()
{
if (check_redx_snwfields()) {

295
src/transfer/transfer.cxx Normal file
View file

@ -0,0 +1,295 @@
// =====================================================================
//
// transfer.cxx
//
// Author: Dave Freese, W1HKJ
// Copyright: 2010
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. It is
// copyright under the GNU General Public License.
//
// You should have received a copy of the GNU General Public License
// along with the program; if not, write to the Free Software
// Foundation, Inc.
// 59 Temple Place, Suite 330
// Boston, MA 02111-1307 USA
//
// =====================================================================
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <ctime>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>
#include <FL/Fl.H>
#include <FL/Enumerations.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Sys_Menu_Bar.H>
#include <FL/x.H>
#include <FL/Fl_Help_Dialog.H>
#include <FL/Fl_Menu_Item.H>
#include <FL/Fl_File_Icon.H>
#include "config.h"
#include "flmsg_config.h"
#include "flmsg.h"
#include "templates.h"
#include "debug.h"
#include "util.h"
#include "gettext.h"
#include "flmsg_dialog.h"
#include "flinput2.h"
#include "date.h"
#include "calendar.h"
#include "icons.h"
#include "fileselect.h"
#include "wrap.h"
#include "status.h"
#include "parse_xml.h"
#include "icons.h"
#ifdef WIN32
# include "flmsgrc.h"
# include "compat.h"
# define dirent fl_dirent_no_thanks
#endif
#include <FL/filename.H>
#include "dirent-check.h"
#include <FL/x.H>
#include "transfer.h"
using namespace std;
string transfer_buffer = "";
string def_transfer_filename = "";
string base_transfer_filename = "";
const char xfrstr[] = "<transfer>\n";
void clear_transfer_form()
{
txt_send_filename->value("");
txt_rcvd_filename->value("");
show_filename("");
transfer_buffer.clear();
btn_save_rcvd->color(FL_BACKGROUND_COLOR);
}
void read_transfer_buffer(string data)
{
size_t p1 = data.find(xfrstr);
if (p1 != string::npos) p1 += strlen(xfrstr);
data.erase(0, p1);
transfer_buffer = data;
read_header(data);
}
void cb_transfer_new()
{
clear_transfer_form();
def_transfer_filename = XFR_dir;
show_filename(def_transfer_filename);
estimate();
}
void cb_transfer_import()
{
fl_alert2("Not implemented");
}
void cb_transfer_export()
{
fl_alert2("Not implemented");
}
void cb_transfer_wrap_import(string wrapfilename, string inpbuffer)
{
clear_transfer_form();
read_transfer_buffer(inpbuffer);
def_transfer_filename = XFR_dir;
def_transfer_filename.append(wrapfilename);
txt_rcvd_filename->value(def_transfer_filename.c_str());
btn_save_rcvd->color(FL_RED);
}
int eval_transfer_fsize()
{
if (transfer_buffer.empty()) return 0;
Ccrc16 chksum;
string fbuff("[WRAP:beg][WRAP:lf][WRAP:fn ");
fbuff.append(fl_filename_name(def_transfer_filename.c_str())).append("]");
fbuff.append(header("<transfer>"));
string outbuf(transfer_buffer);
if (outbuf.empty()) return 0;
compress_maybe( outbuf, true );
fbuff.append( outbuf );
string ck = chksum.scrc16(fbuff);
fbuff.append("[WRAP:chksum ").append(ck).append("][WRAP:end]");
return fbuff.length();
}
void cb_transfer_wrap_export()
{
if (transfer_buffer.empty()) return;
string wrapfilename = WRAP_send_dir;
base_transfer_filename = fl_filename_name(def_transfer_filename.c_str());
wrapfilename.append(base_transfer_filename);
wrapfilename.append(WRAP_EXT);
const char *p = FSEL::saveas(
"Save as wrap file",
"Wrap file\t*.{wrap,WRAP}",
wrapfilename.c_str());
if (p) {
string pext = fl_filename_ext(p);
wrapfilename = p;
update_header(FROM);
string fbuff(header("<transfer>"));
string outbuf(transfer_buffer);
compress_maybe(outbuf, true);
fbuff.append(outbuf);
export_wrapfile(base_transfer_filename, wrapfilename, fbuff, pext != WRAP_EXT);
}
}
void cb_transfer_wrap_autosend()
{
if (transfer_buffer.empty()) return;
update_header(FROM);
string fbuff(header("<transfer>"));
string outbuf(transfer_buffer);
compress_maybe(outbuf, true);
fbuff.append(outbuf);
xfr_via_socket(fl_filename_name(def_transfer_filename.c_str()), fbuff);
}
void cb_transfer_load_template()
{
fl_alert2("Not implemented");
}
void cb_transfer_save_template()
{
fl_alert2("Not implemented");
}
void cb_transfer_save_as_template()
{
fl_alert2("Not implemented");
}
void cb_transfer_open()
{
const char *p = FSEL::select(_("Open file"), "transfer\t*",
def_transfer_filename.c_str());
if (!p) return;
if (strlen(p) == 0) return;
clear_transfer_form();
def_transfer_filename = p;
txt_send_filename->value(def_transfer_filename.c_str());
transfer_buffer.clear();
FILE *dfile = fopen(p, "rb");
if (!dfile) {
txt_send_filename->value("");
transfer_buffer.clear();
return;
}
fseek(dfile, 0, SEEK_END);
size_t fsize = ftell(dfile);
if (fsize <= 0) return;
fseek(dfile, 0, SEEK_SET);
transfer_buffer.resize(fsize);
size_t r = fread((void *)transfer_buffer.c_str(), 1, fsize, dfile);
fclose(dfile);
if (r != fsize) {
txt_send_filename->value("");
transfer_buffer.clear();
return;
}
estimate();
}
void write_transfer(string s)
{
return;
}
bool cb_transfer_save_as()
{
if (transfer_buffer.empty()) return false;
const char *p;
btn_save_rcvd->color(FL_BACKGROUND_COLOR);
p = FSEL::saveas(_("Save file"), "received\t*",
def_transfer_filename.c_str());
if (!p) return false;
FILE *binfile = fopen(p, "wb");
if (binfile) {
fwrite(transfer_buffer.c_str(), transfer_buffer.length(), 1, binfile);
fclose(binfile);
}
cb_transfer_new();
return true;
}
void cb_transfer_save()
{
cb_transfer_save_as();
}
void cb_transfer_msg_type()
{
if (tabs_msg_type->value() == tab_transfer ) {
show_filename(def_transfer_filename);
} else {
show_filename(def_rg_filename);
}
}
void cb_transfer_html()
{
fl_alert2("Not implemented");
}
void cb_transfer_textout()
{
fl_alert2("Not implemented");
}
void cb_transfer_import_data()
{
fl_alert2("Not implemented");
}
void cb_transfer_export_data()
{
fl_alert2("Not implemented");
}

View file

@ -0,0 +1,51 @@
//======================================================================
// file transfer tab
//======================================================================
#include "gettext.h"
#include "status.h"
#include "util.h"
#include "flmsg_dialog.h"
#include "flmsg.h"
#include "transfer.h"
Fl_Group *tab_transfer = (Fl_Group *)0;
Fl_Button *btn_select_send = (Fl_Button *)0;
Fl_Button *btn_save_rcvd = (Fl_Button *)0;
Fl_Output *txt_send_filename = (Fl_Output *)0;
Fl_Output *txt_rcvd_filename = (Fl_Output *)0;
static void cb_btn_select_send(Fl_Button*, void*) {
cb_transfer_open();
}
static void cb_btn_save_rcvd(Fl_Button*, void*) {
cb_transfer_save_as();
}
void create_transfer_tab()
{
tab_transfer = new Fl_Group(0, tab_top, 570, 430 - tab_top);
tab_transfer->align(FL_ALIGN_TOP);
txt_send_filename = new Fl_Output(5, tab_top + 50, 485, 24, _("Transmit file:"));
txt_send_filename->align(FL_ALIGN_TOP_LEFT);
txt_send_filename->tooltip("");
btn_select_send = new Fl_Button(495, tab_top + 50, 70, 24, _("Select"));
btn_select_send->tooltip(_("Select data file to transfer"));
btn_select_send->callback((Fl_Callback*)cb_btn_select_send);
txt_rcvd_filename = new Fl_Output(5, tab_top + 120, 485, 24, _("Received file:"));
txt_rcvd_filename->align(FL_ALIGN_TOP_LEFT);
txt_rcvd_filename->tooltip("");
btn_save_rcvd = new Fl_Button(495, tab_top + 120, 70, 24, _("Save"));
btn_save_rcvd->tooltip(_("Export data to file"));
btn_save_rcvd->callback((Fl_Callback*)cb_btn_save_rcvd);
tab_transfer->end();
tab_transfer->hide();
}

View file

@ -0,0 +1,21 @@
//======================================================================
// blank form template
//======================================================================
#include "templates.h"
const char blank_html_template[] =
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\
<html><head><meta content=\"text/html; charset=ISO-8859-1\" http-equiv=\"content-type\">\
<title>:TITLE:</title></head><body>\
<table WIDTH=1000px BORDER=1 CELLPADDING=0 CELLSPACING=0>\
<tbody>\
<tr>\
<td COLSPAN=3 VALIGN=top>:bin:<br>\
</td>\
</tr>\
</table>\
</body></html>";
const char blank_txt_template[] =
":bin:";

191
src/utils/base128.cxx Normal file
View file

@ -0,0 +1,191 @@
// =====================================================================
//
// base128 and base256 text encoding
//
// Author: Dave Freese, W1HKJ
// Copyright: 2010
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. It is
// copyright under the GNU General Public License.
//
// You should have received a copy of the GNU General Public License
// along with the program; if not, write to the Free Software
// Foundation, Inc.
// 59 Temple Place, Suite 330
// Boston, MA 02111-1307 USA
//
// =====================================================================
#include <stdlib.h>
#include "base128.h"
//----------------------------------------------------------------------
// base 128 class
//----------------------------------------------------------------------
void base128::init()
{
iolen = 0;
iocp = 0;
ateof = false;
linelength = 0;
}
void base128::escape(string &in, bool encode)
{
string out;
if (encode) {
for( size_t i = 0; i < in.length(); i++) {
switch ((in[i] & 0xFF)) {
case ':' : out.append("::"); break;
case 0x00 : out.append(":0"); break;
case 0x02 : out.append(":2"); break;
case 0x03 : out.append(":3"); break;
case 0x04 : out.append(":4"); break;
case 0x05 : out.append(":5"); break;
case '\r' : out.append(":A"); break;
case '\n' : out.append(":B"); break;
case '\b' : out.append(":C"); break;
case '\t' : out.append(":D"); break;
case '^' : out.append(":E"); break;
default: out += in[i];
}
}
} else {
unsigned char ch = 0;
for (size_t i = 0; i < in.length(); i++) {
ch = in[i] & 0xFF;
if (ch == ':') {
i++;
ch = in[i] & 0xFF;
switch (ch) {
case ':' : out += ':'; break;
case '0' : out += ' '; out[out.length() - 1] = 0x00; break;
case '2' : out += 0x02; break;
case '3' : out += 0x03; break;
case '4' : out += 0x04; break;
case '5' : out += 0x05; break;
case 'A' : out += '\r'; break;
case 'B' : out += '\n'; break;
case 'C' : out += '\b'; break;
case 'D' : out += '\t'; break;
case 'E' : out += '^'; break;
}
} else out += ch;
}
}
in = out;
}
void base128::addlf(string &in)
{
string out;
int len = 0;
for (size_t n = 0; n < in.length(); n++) {
if (len < LINELEN) {out += in[n]; len++;}
else {out += '\n'; out += in[n]; len = 0;}
}
in.assign(out);
}
void base128::remlf(string &in)
{
string out;
for (size_t n = 0; n < in.length(); n++) {
if (in[n] != '\n') out += in[n];
}
in.assign(out);
}
string base128::encode(string &in)
{
size_t n;
byte igroup[7], ogroup[8];
char insize[20];
snprintf(insize, sizeof(insize), "%d\n", in.length());
output.assign(insize);
iocp = 0;
ateof = false;
iolen = in.length();
string temp;
while (!ateof) {
igroup[0] = igroup[1] = igroup[2] =
igroup[3] = igroup[4] = igroup[5] = igroup[6] = 0;
for (n = 0; n < 7; n++) {
if (iocp == iolen) {
ateof = true;
break;
}
igroup[n] = (byte)in[iocp];
iocp++;
}
if (n > 0) {
ogroup[0] = (igroup[0] >> 1) & 0x7F;
ogroup[1] = ((igroup[0] << 6) & 0x40) | ((igroup[1] >> 2) & 0x3F);
ogroup[2] = ((igroup[1] << 5) & 0x60) | ((igroup[2] >> 3) & 0x1F);
ogroup[3] = ((igroup[2] << 4) & 0x70) | ((igroup[3] >> 4) & 0x0F);
ogroup[4] = ((igroup[3] << 3) & 0x78) | ((igroup[4] >> 5) & 0x07);
ogroup[5] = ((igroup[4] << 2) & 0x7C) | ((igroup[5] >> 6) & 0x03);
ogroup[6] = ((igroup[5] << 1) & 0x7E) | ((igroup[6] >> 7) & 0x01);
ogroup[7] = (igroup[6] & 0x7F);
for (int i = 0; i < 8; i++) temp += (byte)ogroup[i];
}
}
escape (temp);
addlf(temp);
output.append(temp);
return output;
}
string base128::decode(string &in)
{
int i;
size_t nbr = 0;
string temp = in;
size_t p = temp.find("\n");
if (p == string::npos)
return "ERROR: b128 missing character count";
sscanf(temp.substr(0, p).c_str(), "%d", &nbr);
temp.erase(0, p+1);
remlf(temp);
escape(temp, false);
output.clear();
if (temp.length() % 8)
return "ERROR: b128 file length error.\n";
iocp = 0;
iolen = temp.length();
byte b[8], o[7];
int k = 0;
while (iocp < nbr) {
for (i = 0; i < 7; i++) o[i] = 0;
for (i = 0; i < 8; i++) b[i] = temp[k + i];
k += 8;
o[0] = ((b[0] << 1) & 0xFE) | ((b[1] >> 6) & 0x01);
o[1] = ((b[1] << 2) & 0xFC) | ((b[2] >> 5) & 0x03);
o[2] = ((b[2] << 3) & 0xF8) | ((b[3] >> 4) & 0x07);
o[3] = ((b[3] << 4) & 0xF0) | ((b[4] >> 3) & 0x0F);
o[4] = ((b[4] << 5) & 0xE0) | ((b[5] >> 2) & 0x1F);
o[5] = ((b[5] << 6) & 0xC0) | ((b[6] >> 1) & 0x3F);
o[6] = ((b[6] << 7) & 0x80) | (b[7] & 0x7F);
for (i = 0; i < 7; i++) {
if (iocp++ < nbr)
output += o[i];
}
}
return output;
}

130
src/utils/base256.cxx Normal file
View file

@ -0,0 +1,130 @@
// =====================================================================
//
// base256 text encoding
//
// Author: Dave Freese, W1HKJ
// Copyright: 2010
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. It is
// copyright under the GNU General Public License.
//
// You should have received a copy of the GNU General Public License
// along with the program; if not, write to the Free Software
// Foundation, Inc.
// 59 Temple Place, Suite 330
// Boston, MA 02111-1307 USA
//
// =====================================================================
#include <stdlib.h>
#include "base256.h"
void base256::init()
{
iolen = 0;
iocp = 0;
ateof = false;
linelength = 0;
}
void base256::escape(string &in, bool encode)
{
string out;
if (encode) {
for( size_t i = 0; i < in.length(); i++) {
switch ((in[i] & 0xFF)) {
case ':' : out.append("::"); break;
case 0x00 : out.append(":0"); break;
case 0x02 : out.append(":2"); break;
case 0x03 : out.append(":3"); break;
case 0x04 : out.append(":4"); break;
case 0x05 : out.append(":5"); break;
case '\r' : out.append(":A"); break;
case '\n' : out.append(":B"); break;
case '\b' : out.append(":C"); break;
case '\t' : out.append(":C"); break;
case '^' : out.append(":E"); break;
case 0xFF : out.append(":F"); break;
default: out += in[i];
}
}
} else {
unsigned char ch = 0;
for (size_t i = 0; i < in.length(); i++) {
ch = in[i] & 0xFF;
if (ch == ':') {
i++;
ch = in[i] & 0xFF;
switch (ch) {
case ':' : out += ':'; break;
case '0' : out += ' '; out[out.length() - 1] = 0x00; break;
case '2' : out += 0x02; break;
case '3' : out += 0x03; break;
case '4' : out += 0x04; break;
case '5' : out += 0x05; break;
case 'A' : out += '\r'; break;
case 'B' : out += '\n'; break;
case 'C' : out += '\b'; break;
case 'D' : out += '\t'; break;
case 'E' : out += '^'; break;
case 'F' : out += 0xFF; break;
}
} else out += ch;
}
}
in = out;
}
void base256::addlf(string &in)
{
string out;
int len = 0;
for (size_t n = 0; n < in.length(); n++) {
if (len < LINELEN) {out += in[n]; len++;}
else {out += '\n'; out += in[n]; len = 0;}
}
in.assign(out);
}
void base256::remlf(string &in)
{
string out;
for (size_t n = 0; n < in.length(); n++) {
if (in[n] != '\n') out += in[n];
}
in.assign(out);
}
string base256::encode(string &in)
{
char insize[20];
snprintf(insize, sizeof(insize), "%d\n", in.length());
output.assign(insize);
iocp = 0;
ateof = false;
string temp (in);
escape (temp);
addlf(temp);
output.append(temp);
return output;
}
string base256::decode(string &in)
{
size_t nbr = 0;
string output = in;
size_t p = output.find("\n");
if (p == string::npos)
return "ERROR: base256 missing character count";
sscanf(output.substr(0, p).c_str(), "%d", &nbr);
output.erase(0, p+1);
remlf(output);
escape(output, false);
return output;
}

View file

@ -70,7 +70,7 @@ string base64::encode(string in)
int n;
byte igroup[3], ogroup[4];
output = "";
output = "\n";
iocp = 0;
ateof = false;
if (crlf)

View file

@ -29,6 +29,7 @@
#include "config.h"
#include "flmsg.h"
#include "flmsg_dialog.h"
#include "wrap.h"
status progStatus = {
50, // int mainX;
@ -60,7 +61,9 @@ status progStatus = {
true, // autowordwrap
"127.0.0.1", // fldigi socket address
"7322", // fldigi socket port
false // use_compression
false, // use_compression
BASE64, // encoder
0 // selected_mode
};
void status::saveLastState()
@ -73,6 +76,7 @@ void status::saveLastState()
mainX = mX;
mainY = mY;
}
selected_mode = cbo_modes->index();
flmsgpref.set("version", PACKAGE_VERSION);
flmsgpref.set("mainx", mX);
@ -109,6 +113,8 @@ void status::saveLastState()
flmsgpref.set("fldigi_socket_port", socket_port.c_str());
flmsgpref.set("use_compression", use_compression);
flmsgpref.set("encoder", encoder);
flmsgpref.set("selected_mode", selected_mode);
}
void status::loadLastState()
@ -123,23 +129,12 @@ void status::loadLastState()
flmsgpref.get("mainy", mainY, mainY);
flmsgpref.get("wpl", wpl, wpl);
cnt_wpl->value(wpl);
if (flmsgpref.get("open_on_export", i, i)) open_on_export = i;
flmsgpref.get("utc", UTC, UTC);
btn_utc_format0->value(UTC == 0);
btn_utc_format1->value(UTC == 1);
btn_utc_format2->value(UTC == 2);
btn_utc_format3->value(UTC == 3);
btn_utc_format4->value(UTC == 4);
btn_utc_format5->value(UTC == 5);
flmsgpref.get("dtformat", dtformat, dtformat);
btn_dtformat0->value(dtformat == 0);
btn_dtformat1->value(dtformat == 1);
btn_dtformat2->value(dtformat == 2);
btn_dtformat3->value(dtformat == 3);
flmsgpref.get("mycall", defbuffer, "");
my_call = defbuffer; free(defbuffer);
@ -192,6 +187,10 @@ void status::loadLastState()
if (flmsgpref.get("use_compression", i, use_compression)) use_compression = i;
flmsgpref.get("encoder", encoder, encoder);
flmsgpref.get("selected_mode", selected_mode, selected_mode);
}
}

View file

@ -4,9 +4,6 @@
// Stelios Bounanos, M0GLD
//
// Modified from original wrap program source
// removed all image, binary - base64 conversions
// This modified wrap is specifically aimed at wrapping an flmsg
// text file!
//
// wrap surrounds critical text with markers and adds a checksum to the
// resulting file. It unwraps a file that has been previously wrapped. The
@ -76,7 +73,8 @@
#include "pixmaps.h"
#include "base64.h"
#include "crc16.h"
#include "base128.h"
#include "base256.h"
#include "lzma/LzmaLib.h"
#include "status.h"
#include "flmsg_config.h"
@ -115,6 +113,11 @@ const char *wrap_chksum = "[WRAP:chksum ";
const char *b64_start = "[b64:start]";
const char *b64_end = "[b64:end]";
const char *b128_start = "[b128:start]\n";
const char *b128_end = "\n[b128:end]";
const char *b256_start = "[b256:start]";
const char *b256_end = "\n[b256:end]";
const char *wrap_fn = "[WRAP:fn ";
const char *dashes = "\n====================\n";
@ -122,8 +125,13 @@ const char *dashes = "\n====================\n";
//const char *binaryfile[] = {
// ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".ico", ".zip", ".gz", ".tgz", ".bz2", 0 };
string test_version = "1.1.23A";
bool old_version = false;
Ccrc16 chksum;
base64 b64(1); // insert lf for ease of viewing
base128 b128;
base256 b256;
string inptext = "";
string wtext = "";
@ -134,6 +142,52 @@ string wrap_inpshortname = "";
string wrap_outshortname = "";
string wrap_foldername = "";
bool isExtension(const char *s1, const char *s2)
{
#ifdef WIN32
char *sz1 = new char[strlen(s1) + 1];
char *sz2 = new char[strlen(s2) + 1];
char *p = 0;
strcpy(sz1, s1);
strcpy(sz2, s2);
for (size_t i = 0; i < strlen(sz1); i++) sz1[i] = toupper(sz1[i]);
for (size_t i = 0; i < strlen(sz2); i++) sz2[i] = toupper(sz2[i]);
p = strstr(sz1, sz2);
delete [] sz1;
delete [] sz2;
return (p != 0);
#else
const char *p = strcasestr(s1, s2);
#endif
return (p != 0);
}
void base64encode(string &inptext)
{
string outtext;
outtext = b64.encode(inptext);
inptext = b64_start;
inptext.append(outtext);
inptext.append(b64_end);
}
void base128encode(string &inptext)
{
string outtext;
outtext = b128.encode(inptext);
inptext = b128_start;
inptext.append(outtext);
inptext.append(b128_end);
}
void base256encode(string &inptext)
{
string outtext = b256.encode(inptext);
inptext = b256_start;
inptext.append(outtext);
inptext.append(b256_end);
}
// escape chars that cause transmission problems
// compabible with flwrap
@ -147,18 +201,17 @@ void dress(string &str)
for (p = 0; p < str.length(); p++) {
ch = str[p] & 0xFF;
rpl = ch;
if ( ch == '|')
if (ch == ' ') rpl = " ";
else if ( ch == '|')
rpl = "||";
else if (ch >= 0x80 && ch < 0xC0) {
rpl = "|-"; rpl += (ch - 0x60);
}
else if (ch >= 0xC0) {
rpl = "|_"; rpl += (ch - 0xA0);
rpl = "|"; rpl += (ch - 0xA0);
}
else if (ch < ' ') {
if (ch != 0x09 && ch != 0x0A && ch != 0x0D) {
rpl = "|+"; rpl += (ch + ' ');
}
rpl = " "; rpl += (ch + '0');
}
s.append(rpl);
}
@ -194,90 +247,84 @@ void strip(string &s)
s = str;
}
bool isExtension(const char *s1, const char *s2)
{
#ifdef WIN32
char *sz1 = new char[strlen(s1) + 1];
char *sz2 = new char[strlen(s2) + 1];
char *p = 0;
strcpy(sz1, s1);
strcpy(sz2, s2);
for (size_t i = 0; i < strlen(sz1); i++) sz1[i] = toupper(sz1[i]);
for (size_t i = 0; i < strlen(sz2); i++) sz2[i] = toupper(sz2[i]);
p = strstr(sz1, sz2);
delete [] sz1;
delete [] sz2;
return (p != 0);
#else
const char *p = strcasestr(s1, s2);
#endif
return (p != 0);
}
void base64encode(string &inptext)
{
string outtext;
outtext = b64.encode(inptext);
inptext = b64_start;
inptext.append(outtext);
inptext.append(b64_end);
}
void convert2crlf(string &s)
{
if (s.find('\r') != string::npos) return;
size_t p = s.find('\n');
size_t p = s.find('\n', 0);
while (p != string::npos) {
s.replace(p, 1, "\r\n");
p = s.find('\n', p + 2);
}
}
void convert2lf(string &s)
bool convert2lf(string &s)
{
size_t p = s.find("\r\n");
bool converted = false;
size_t p = s.find("\r\n", 0);
while (p != string::npos) {
s.replace(p, 2, "\n");
p = s.find("\r\n");
p = s.find("\r\n", p + 1);
converted = true;
}
return converted;
}
#define LZMA_STR "\1LZMA"
void compress_maybe(string& input)
void compress_maybe(string& input, bool file_transfer)
{
if (!progStatus.use_compression) return;
if (!progStatus.use_compression && !file_transfer) return;
// allocate 105% of the original size for the output buffer
size_t outlen = (size_t)ceil(input.length() * 1.05);
// allocate 110% of the original size for the output buffer
size_t outlen = (size_t)ceil(input.length() * 1.1);
unsigned char* buf = new unsigned char[outlen];
size_t plen = LZMA_PROPS_SIZE;
unsigned char outprops[LZMA_PROPS_SIZE];
uint32_t origlen = htonl(input.length());
int r;
if ((r = LzmaCompress(buf, &outlen, (const unsigned char*)input.data(), input.length(),
outprops, &plen, 9, 0, -1, -1, -1, -1, -1)) != SZ_OK) {
LOG_ERROR("LzmaCompress failed with error code %d", r);
return;
}
string bufstr;
if (progStatus.use_compression || file_transfer) {
// replace input with: LZMA_STR + original size (in network byte order) + props + data
bufstr.assign(LZMA_STR);
bufstr.append((const char*)&origlen, sizeof(origlen));
bufstr.append((const char*)&outprops, sizeof(outprops));
bufstr.append((const char*)buf, outlen);
base64encode(bufstr);
if (bufstr.length() >= input.length()) {
LOG_INFO("%s", "LZMA/B64 larger than input string");
return;
int r;
bufstr.assign(LZMA_STR);
if ((r = LzmaCompress(
buf, &outlen,
(const unsigned char*)input.data(), input.length(),
outprops, &plen, 9, 0, -1, -1, -1, -1, -1)) == SZ_OK) {
bufstr.append((const char*)&origlen, sizeof(origlen));
bufstr.append((const char*)&outprops, sizeof(outprops));
bufstr.append((const char*)buf, outlen);
if (file_transfer && input.length() < bufstr.length())
bufstr.assign(input);
} else {
LOG_ERROR("Lzma Compress failed: %s", LZMA_ERRORS[r]);
bufstr.assign(input);
}
// if (progStatus.use_b64)
// base64encode(bufstr);
// base128encode(bufstr);
// else
// base128encode(bufstr);
// base256encode(bufstr);
if (progStatus.encoder == BASE128)
base128encode(bufstr);
else if (progStatus.encoder == BASE256)
base256encode(bufstr);
else
base64encode(bufstr);
}
LOG_INFO("Input size %d, Compressed size %d", input.length(), bufstr.length());
//printf("original %d\n%s\n, compb64 %d\n%s\n", input.length(), input.c_str(), bufstr.length(), bufstr.c_str());
input = bufstr;
delete [] buf;
if (file_transfer || bufstr.length() < input.length()) {
LOG_INFO("Input size %d, Compressed size %d", input.length(), bufstr.length());
input = bufstr;
}
return;
}
void decompress_maybe(string& input)
@ -286,50 +333,85 @@ void decompress_maybe(string& input)
// if (input.find(LZMA_STR) == string::npos)
// return;
printf("source:\n%s\n\n", input.c_str());
int encode = BASE64;
size_t p0 = string::npos,
p1 = string::npos,
p2 = string::npos,
p3 = string::npos;
if ((p0 = p1 = input.find(b64_start)) != string::npos) {
p1 += strlen(b64_start);
p2 = input.find(b64_end, p1);
} else if ((p0 = p1 = input.find(b128_start)) != string::npos) {
p1 += strlen(b128_start);
p2 = input.find(b128_end, p1);
encode = BASE128;
} else if ((p0 = p1 = input.find(b256_start)) != string::npos) {
p1 += strlen(b256_start);
p2 = input.find(b256_end, p1);
encode = BASE256;
}
size_t p0, p1, p2, p3;
p0 = p1 = input.find(b64_start);
if (p1 == string::npos) return;
p1 += strlen(b64_start);
p2 = input.find(b64_end, p1);
if (p2 == string::npos) {
LOG_ERROR("%s", "Base 64 decode failed");
if (encode == BASE256)
LOG_ERROR("%s", "Base 256 decode failed");
else if (encode == BASE128)
LOG_ERROR("%s", "Base 128 decode failed");
else if (encode == BASE64)
LOG_ERROR("%s", "Base 64 decode failed");
return;
}
p3 = p2 + strlen(b64_end);
switch (encode) {
case BASE128 :
p3 = p2 + strlen(b128_end); break;
case BASE256 :
p3 = p2 + strlen(b256_end); break;
case BASE64 :
default :
p3 = p2 + strlen(b64_end);
}
printf("[b64]:\n%s\n\n", input.substr(p1, p2-p1).c_str());
string cmpstr = input.substr(p1, p2-p1);
string cmpstr = b64.decode(input.substr(p1, p2-p1));
switch (encode) {
case BASE128 :
cmpstr = b128.decode(cmpstr); break;
case BASE256 :
cmpstr = b256.decode(cmpstr); break;
case BASE64 :
default:
cmpstr = b64.decode(cmpstr);
}
printf("LZMA:\n%s\n\n", cmpstr.c_str());
if (cmpstr.find("ERROR") != string::npos) {
LOG_ERROR("%s", cmpstr.c_str());
return;
}
if (cmpstr.find(LZMA_STR) == string::npos) {
input.replace(p0, p3 - p0, cmpstr);
return;
}
const char* in = cmpstr.data();
size_t outlen = ntohl(*reinterpret_cast<const uint32_t*>(in + strlen(LZMA_STR)));
if (outlen > 1 << 25) {
LOG_ERROR("%s", "Refusing to decompress data (> 32MiB)");
return;
}
LOG_ERROR("%s", "Refusing to decompress data (> 32 MiB)");
return;
}
unsigned char* buf = new unsigned char[outlen];
unsigned char inprops[LZMA_PROPS_SIZE];
memcpy(inprops, in + strlen(LZMA_STR) + sizeof(uint32_t), LZMA_PROPS_SIZE);
size_t inlen = cmpstr.length() - strlen(LZMA_STR) - sizeof(uint32_t) - LZMA_PROPS_SIZE;
int r;
if ((r = LzmaUncompress(buf, &outlen, (const unsigned char*)in + cmpstr.length() - inlen, &inlen,
inprops, LZMA_PROPS_SIZE)) != SZ_OK)
LOG_ERROR("LzmaUncompress failed with error code %d", r);
inprops, LZMA_PROPS_SIZE)) != SZ_OK)
LOG_ERROR("Lzma Uncompress failed: %s", LZMA_ERRORS[r]);
else {
LOG_INFO("Decompress: in = %ld, out = %ld", (long int)inlen, (long int)outlen);
cmpstr.assign((const char*)buf, outlen);
input.replace(p0, p3 - p0, cmpstr);
printf("Uncompressed:\n%s\n\n", cmpstr.c_str());
}
delete [] buf;
}
@ -340,14 +422,9 @@ bool wrapfile(bool with_ext)
wrap_outfilename.append(WRAP_EXT);
wrap_outshortname = fl_filename_name(wrap_outfilename.c_str());
dress(inptext);
// compress_maybe(inptext);
if (inptext.find("\r\n") != string::npos) {
iscrlf = true;
convert2lf(inptext); // checksum & data transfer always based on Unix end-of-line char
}
// checksum & data transfer always based on Unix end-of-line char
iscrlf = convert2lf(inptext);
string originalfilename = wrap_fn;
originalfilename.append(wrap_inpshortname);
@ -357,10 +434,15 @@ bool wrapfile(bool with_ext)
check = chksum.scrc16(inptext);
string ostr(wrap_beg);
ostr.append(iscrlf ? wrap_crlf : wrap_lf);
ostr.append(inptext).append(wrap_chksum).append(check).append("]");
ostr.append(wrap_end);
ofstream wrapstream(wrap_outfilename.c_str(), ios::binary);
if (wrapstream) {
LOG_INFO("Writing wrapfile: %s", wrap_outfilename.c_str());
wrapstream << wrap_beg << (iscrlf ? wrap_crlf : wrap_lf) << inptext << wrap_chksum << check << ']' << wrap_end;
wrapstream << ostr;
wrapstream.close();
} else {
LOG_INFO("Cannot write to: %s", wrap_outfilename.c_str());
@ -421,9 +503,6 @@ bool unwrapfile()
return false;
}
if (wtext.find("\r\n") != string::npos)
convert2lf(wtext);
testsum = chksum.scrc16(wtext);
if (inpsum != testsum) {
@ -443,12 +522,12 @@ bool unwrapfile()
wrap_outshortname.erase(0, strlen(wrap_fn));
wtext.erase(0,p+1);
// check for protocol abuse
bool t1 = (wrap_outshortname.find('/') != string::npos);
bool t2 = (wrap_outshortname.find('\\') != string::npos);
bool t3 = (wrap_outshortname == ".");
bool t4 = (wrap_outshortname == "..");
bool t5 = (wrap_outshortname.find(":") != string::npos);
bool t6 = wrap_outshortname.empty();
bool t1 = (wrap_outshortname.find('/') != string::npos);
bool t2 = (wrap_outshortname.find('\\') != string::npos);
bool t3 = (wrap_outshortname == ".");
bool t4 = (wrap_outshortname == "..");
bool t5 = (wrap_outshortname.find(":") != string::npos);
bool t6 = wrap_outshortname.empty();
if (t1 || t2 || t3 || t4 || t5 || t6) {
errtext = "Filename corrupt, possible protocol abuse\n";
if (t1) errtext.append("Filename contains '/' character\n");
@ -470,17 +549,26 @@ bool t6 = wrap_outshortname.empty();
if (iscrlf)
convert2crlf(wtext);
decompress_maybe(wtext);
strip(wtext);
if (old_version) strip(wtext);
return true;
}
void check_version()
{
size_t p = inptext.find("<flmsg>");
if (p == string::npos) return;
p += 7;
size_t p1 = inptext.find("\n", p);
if (p1 == string::npos) return;
if (inptext.substr(p, p1 - p) < test_version) old_version = true;
}
bool readfile()
{
old_version = false;
char cin;
ifstream textfile;
textfile.open(wrap_inpfilename.c_str(), ios::binary);
@ -489,6 +577,7 @@ bool readfile()
while (textfile.get(cin))
inptext += cin;
textfile.close();
check_version();
return true;
}
return false;
@ -514,12 +603,8 @@ void xfr_via_socket(string basename, string inptext)
{
bool iscrlf = false;
dress(inptext);
if (inptext.find("\r\n") != string::npos) {
iscrlf = true;
convert2lf(inptext); // checksum & data transfer always based on Unix end-of-line char
}
// checksum & data transfer always based on Unix end-of-line char
iscrlf = convert2lf(inptext);
string payload = wrap_fn;
payload.assign(wrap_fn).append(basename).append("]");
@ -535,6 +620,16 @@ void xfr_via_socket(string basename, string inptext)
autosend.append(wrap_chksum).append(check).append("]");
autosend.append(wrap_end).append("\n... end\n");
#ifdef DEBUG
FILE *wrap = fopen("wrap.wrap", "wb");
string wstr;
wstr.assign(wrap_beg).append(iscrlf ? wrap_crlf : wrap_lf);
wstr.append(payload);
wstr.append(wrap_chksum).append(check).append("]").append(wrap_end);
fwrite(wstr.c_str(), wstr.length(), 1, wrap);
fclose(wrap);
#endif
bool xfrOK = false;
try {
localaddr = new Address(progStatus.socket_addr.c_str(), progStatus.socket_port.c_str());