Custom html transfer

* Added special transfer of html forms to/from CUSTOM
    folder.
This commit is contained in:
David Freese 2014-04-01 08:20:47 -05:00
parent 657ba20f71
commit 377261684d
9 changed files with 298 additions and 23 deletions

View file

@ -203,6 +203,7 @@ flmsg_SOURCES += \
$(srcdir)/redx/redx_5739_template.cxx \
$(srcdir)/transfer/transfer.cxx \
$(srcdir)/transfer/transfer_tab.cxx \
$(srcdir)/custom/custom_transfer_tab.cxx \
$(srcdir)/utils/base64.cxx \
$(srcdir)/utils/base128.cxx \
$(srcdir)/utils/base256.cxx \

View file

@ -1137,3 +1137,123 @@ void cb_custom_textout()
}
}
}
//==============================================================================
// Support for transfering / receiving custom FORM, html files
//==============================================================================
string transfer_custom_buffer;
string def_custom_transfer_filename;
string def_custom_rx_filename;
string receive_custom_buffer;
void read_custom_transfer_buffer(string data)
{
const char *xfrstr = "<html_form>\n";
size_t p1 = data.find(xfrstr);
if (p1 != string::npos) p1 += strlen(xfrstr);
data.erase(0, p1);
receive_custom_buffer = data;
read_header(data);
}
void cb_custom_form_wrap_import(string wrapfilename, string inpbuffer)
{
read_custom_transfer_buffer(inpbuffer);
def_custom_rx_filename = CUSTOM_dir;
def_custom_rx_filename.append(wrapfilename);
txt_rcvd_custom_html_filename->value(def_custom_rx_filename.c_str());
btn_save_custom_html_file->color(FL_RED);
}
int eval_transfer_custom_form_fsize()
{
if (transfer_custom_buffer.empty()) return 0;
Ccrc16 chksum;
evalstr.assign("[WRAP:beg][WRAP:lf][WRAP:fn ");
evalstr.append(fl_filename_name(def_custom_transfer_filename.c_str())).append("]");
evalstr.append(header("<html_form>"));
string outbuf(transfer_custom_buffer);
if (outbuf.empty()) return 0;
compress_maybe( outbuf, false );
evalstr.append( outbuf );
string ck = chksum.scrc16(evalstr);
evalstr.append("[WRAP:chksum ").append(ck).append("][WRAP:end]");
return evalstr.length();
}
void load_custom_html_file()
{
string fname = CUSTOM_dir;
fname.append(def_custom_transfer_filename);
transfer_custom_buffer.clear();
FILE *dfile = fopen(fname.c_str(), "rb");
if (!dfile) {
show_filename("ERROR");
transfer_custom_buffer.clear();
return;
}
fseek(dfile, 0, SEEK_END);
size_t fsize = ftell(dfile);
if (fsize <= 0) return;
fseek(dfile, 0, SEEK_SET);
transfer_custom_buffer.resize(fsize);
size_t r = fread((void *)transfer_custom_buffer.c_str(), 1, fsize, dfile);
fclose(dfile);
if (r != fsize) {
show_filename("ERROR");
transfer_custom_buffer.clear();
return;
}
// remove tabs
size_t p = transfer_custom_buffer.find('\t');
while (p != string::npos) {
transfer_custom_buffer.erase(p, 1);
p = transfer_custom_buffer.find('\t');
}
estimate();
}
void cb_transfer_custom_html()
{
if (transfer_custom_buffer.empty()) return;
update_header(FROM);
string fbuff(header("<html_form>"));
string outbuf(transfer_custom_buffer);
compress_maybe(outbuf, false);
fbuff.append(outbuf);
xfr_via_socket(fl_filename_name(def_custom_transfer_filename.c_str()), fbuff);
}
void cb_save_custom_html(Fl_Widget *w, void *d)
{
btn_save_custom_html_file->color(FL_BACKGROUND_COLOR);
if (receive_custom_buffer.empty()) return;
FILE *binfile = fopen(def_custom_rx_filename.c_str(), "wb");
if (binfile) {
fwrite(receive_custom_buffer.c_str(), receive_custom_buffer.length(), 1, binfile);
fclose(binfile);
}
txt_rcvd_custom_html_filename->value("");
update_custom_transfer();
}
void cb_btn_select_custom_html(Fl_Widget *w, void *d)
{
def_custom_transfer_filename = custom_files[custom_selector->index()];
show_filename(def_custom_transfer_filename);
load_custom_html_file();
}

View file

@ -0,0 +1,75 @@
// ----------------------------------------------------------------------------
// Copyright (C) 2014
// David Freese, W1HKJ
//
// This file is part of flmsg
//
// flrig is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// flrig 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. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// ----------------------------------------------------------------------------
#include "gettext.h"
#include "status.h"
#include "util.h"
#include "flmsg_dialog.h"
#include "flmsg.h"
#include "combo.h"
Fl_Group *tab_custom_transfer = (Fl_Group *)0;
Fl_ListBox *custom_selector = (Fl_ListBox *)0;
Fl_Output * txt_rcvd_custom_html_filename = (Fl_Output *)0;
Fl_Button * btn_save_custom_html_file = (Fl_Button *)0;
void cb_custom_autosend(Fl_Widget *w, void *d)
{
cb_wrap_autosend();
}
void create_custom_transfer_tab()
{
tab_custom_transfer = new Fl_Group(0, tab_top, 570, 430 - tab_top);
tab_custom_transfer->align(FL_ALIGN_TOP);
Fl_Group *TransmitGroup = new Fl_Group(2, tab_top + 30, 566, 80, _("Transmit Custom FORM"));
TransmitGroup->box(FL_ENGRAVED_BOX);
TransmitGroup->align(FL_ALIGN_TOP | FL_ALIGN_INSIDE);
custom_selector = new Fl_ListBox( 10, tab_top + 65, 200, 24, _("Select custom form"));
load_custom_transfer();
custom_selector->callback((Fl_Callback*)cb_btn_select_custom_html);
Fl_Button *custom_autosend = new Fl_Button( 240, tab_top + 65, 80, 24, _("Autosend"));
custom_autosend->callback(cb_custom_autosend);
TransmitGroup->end();
Fl_Group *ReceiveGroup = new Fl_Group(2, tab_top + 115, 566, 80, _("Receive Custom FORM"));
ReceiveGroup->box(FL_ENGRAVED_BOX);
ReceiveGroup->align(FL_ALIGN_TOP | FL_ALIGN_INSIDE);
txt_rcvd_custom_html_filename = new Fl_Output(10, tab_top + 150, 480, 24, _("Received file:"));
txt_rcvd_custom_html_filename->align(FL_ALIGN_TOP_LEFT);
txt_rcvd_custom_html_filename->tooltip("");
btn_save_custom_html_file = new Fl_Button(495, tab_top + 150, 70, 24, _("Save"));
btn_save_custom_html_file->tooltip(_("Export data to file"));
btn_save_custom_html_file->callback((Fl_Callback*)cb_save_custom_html);
ReceiveGroup->end();
tab_custom_transfer->end();
tab_custom_transfer->hide();
}

View file

@ -797,6 +797,7 @@ int eval_transfer_size()
case CSV: return eval_csv_fsize();
case CUSTOM: return eval_custom_fsize();
case TRANSFER: return eval_transfer_fsize();
case CUSTOM_TRANSFER: return eval_transfer_custom_form_fsize();
case MARSDAILY: return eval_mars_daily_fsize();
case MARSINEEI: return eval_mars_ineei_fsize();
case MARSNET: return eval_mars_net_fsize();
@ -850,7 +851,7 @@ void cb_new()
case REDX5739: cb_redx_5739_new(); break;
case REDX5739A: cb_redx_5739A_new(); break;
case REDX5739B: cb_redx_5739B_new(); break;
default : ;
default : return;
}
clear_estimate();
}
@ -948,7 +949,8 @@ void wrap_import(const char *fname)
}
if (isok) {
if (inpbuffer.find("<transfer>") == string::npos)
if (!(inpbuffer.find("<transfer>") != string::npos &&
inpbuffer.find("<html_file>") != string::npos) )
remove_cr( inpbuffer );
if (inpbuffer.find("<flics") != string::npos ||
inpbuffer.find("<flmsg") != string::npos) {
@ -1051,6 +1053,9 @@ void wrap_import(const char *fname)
} else if (inpbuffer.find("<transfer>") != string::npos) {
selected_form = TRANSFER;
cb_transfer_wrap_import(filename, inpbuffer);
} else if (inpbuffer.find("<html_form>") != string::npos) {
selected_form = CUSTOM_TRANSFER;
cb_custom_form_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)) {
@ -1197,6 +1202,7 @@ void cb_wrap_autosend()
case CSV: cb_csv_wrap_autosend(); break;
case CUSTOM: cb_custom_wrap_autosend(); break;
case TRANSFER: cb_transfer_wrap_autosend(); break;
case CUSTOM_TRANSFER: cb_transfer_custom_html(); 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;
@ -1209,7 +1215,7 @@ void cb_wrap_autosend()
case REDX5739: cb_redx_5739_wrap_autosend(); break;
case REDX5739A: cb_redx_5739A_wrap_autosend(); break;
case REDX5739B: cb_redx_5739B_wrap_autosend(); break;
default: ;
default: return;
}
}
@ -1248,7 +1254,7 @@ void cb_load_template()
case REDX5739: cb_redx_5739_load_template(); break;
case REDX5739A: cb_redx_5739A_load_template(); break;
case REDX5739B: cb_redx_5739B_load_template(); break;
default: ;
default: return;
}
estimate();
}
@ -1288,7 +1294,7 @@ void cb_save_template()
case REDX5739: cb_redx_5739_save_template(); break;
case REDX5739A: cb_redx_5739A_save_template(); break;
case REDX5739B: cb_redx_5739B_save_template(); break;
default: ;
default: return;
}
}
@ -1327,7 +1333,7 @@ void cb_save_as_template()
case REDX5739: cb_redx_5739_save_as_template(); break;
case REDX5739A: cb_redx_5739A_save_as_template(); break;
case REDX5739B: cb_redx_5739B_save_as_template(); break;
default: ;
default: return;
}
}
@ -1366,7 +1372,7 @@ void cb_open()
case REDX5739: cb_redx_5739_open(); break;
case REDX5739A: cb_redx_5739A_open(); break;
case REDX5739B: cb_redx_5739B_open(); break;
default : ;
default : return;
}
estimate();
}
@ -1406,7 +1412,7 @@ void cb_save_as()
case BLANK: cb_blank_save_as(); break;
case CSV: cb_csv_save_as(); break;
case CUSTOM: cb_custom_save_as(); break;
default: ;
default: return;
}
}
@ -1445,7 +1451,7 @@ void cb_save()
case BLANK: cb_blank_save(); break;
case CSV: cb_csv_save(); break;
case CUSTOM: cb_custom_save(); break;
default: ;
default: return;
}
}
@ -1484,7 +1490,7 @@ void cb_html()
case BLANK: cb_blank_html(); break;
case CSV: cb_csv_html(); break;
case CUSTOM: cb_custom_html(); break;
default: ;
default: return;
}
}
@ -1543,8 +1549,8 @@ void cb_text()
case REDX5739B: cb_redx_5739B_textout(); break;
case CSV: cb_csv_textout(); break;
case CUSTOM: cb_custom_textout(); break;
case BLANK:
default: cb_blank_textout();
case BLANK: cb_blank_textout(); break;
default : return;
}
}
@ -1684,6 +1690,8 @@ void show_filename(string p)
case TRANSFER:
base_transfer_filename = fl_filename_name(p.c_str());
break;
case CUSTOM_TRANSFER:
break;
default:
return;
}

View file

@ -22,6 +22,7 @@
#include <dirent.h>
#include <iostream>
#include <fstream>
#include <vector>
#include "gettext.h"
#include "flmsg_dialog.h"
@ -34,6 +35,7 @@
#include "transfer.h"
#include "time_table.h"
#include "xml_io.h"
#include "combo.h"
//======================================================================
@ -253,7 +255,7 @@ void clear_estimate() {
}
void estimate() {
static char sz_xfr_size[20];
static char sz_xfr_size[30];
float xfr_time = 0, overhead;
transfer_size = eval_transfer_size();
@ -635,6 +637,13 @@ void select_form(int form)
txt_formname->value(_("File transfer"));
show_filename(def_transfer_filename);
break;
case CUSTOM_TRANSFER:
oldtab = tab_custom_transfer;
tab_custom_transfer->show();
txt_formname->value(_("FORM transfer"));
show_filename(def_custom_transfer_filename);
load_custom_html_file();
break;
case BLANK:
case NONE:
default:
@ -804,6 +813,11 @@ extern string edit_txt;
txt_custom_msg->add(edit_txt.c_str());
}
static void cb_open_custom_transfer_tab(Fl_Menu_ *, void *d) {
selected_form = CUSTOM_TRANSFER;
select_form(selected_form);
}
void init_custom_menu()
{
for (int i = 0; i < NBR_CUSTOM_MENUS; i++) {
@ -830,9 +844,15 @@ static const string key2 = "<META NAME=\"MENU_ITEM\" CONTENT=";
for (int i = 0; i < NBR_CUSTOM_MENUS; i++) {
custom_menu[i].text = 0;
custom_menu[i].shortcut_ = 0;
custom_menu[i].callback_ = (Fl_Callback*)cb_mnuCustomFormSelect;
custom_menu[i].user_data_ = 0,
custom_menu[i].flags = 0;
if (i)
custom_menu[i].callback_ = (Fl_Callback*)cb_mnuCustomFormSelect;
else
custom_menu[i].callback_ = (Fl_Callback*)cb_open_custom_transfer_tab;
custom_menu[i].user_data_ = 0;
if (i)
custom_menu[i].flags = 0;
else
custom_menu[i].flags = FL_MENU_DIVIDER;
custom_menu[i].labeltype_ = FL_NORMAL_LABEL;
custom_menu[i].labelfont_ = 0;
custom_menu[i].labelsize_ = 14;
@ -905,15 +925,44 @@ static const string key2 = "<META NAME=\"MENU_ITEM\" CONTENT=";
custom_pairs[i] = temp;
}
custom_menu[0].text = "Transfer FORM";
custom_menu[0].user_data_ = 0;
for (int i = 0; i < num_custom_entries; i++) {
// custom menu item
custom_menu[i].text =
custom_menu[i+1].text =
custom_pairs[i].mnu_name;
custom_menu[i].user_data_ =
custom_menu[i+1].user_data_ =
(void *)i;
}
update_custom_transfer();
}
vector<string> custom_files;
void update_custom_transfer()
{
custom_files.clear();
custom_selector->clear();
if (num_custom_entries == 0) return;
for (int i = 0; i < num_custom_entries; i++) {
custom_selector->add(custom_pairs[i].mnu_name);
custom_files.push_back(custom_pairs[i].file_name);
}
custom_selector->index(0);
def_custom_transfer_filename = custom_pairs[0].file_name;
}
void load_custom_transfer()
{
if (tab_custom_transfer->visible()) return;
update_custom_transfer();
}
//------------------------------------------------------------------------------
extern void drop_file_changed();
static void cb_drop_file(Fl_Input*, void*) {
drop_file_changed();
@ -994,6 +1043,7 @@ Fl_Double_Window* flmsg_dialog() {
create_severe_wx_tab();
create_storm_tab();
create_transfer_tab();
create_custom_transfer_tab();
controls = new Fl_Group(2, 465 - 28, 566, 26, "controls");
controls->begin();
@ -1038,7 +1088,7 @@ Fl_Double_Window* flmsg_dialog() {
txt_xfr_size_time = new Fl_Output(330, H-28+2, 230, 22, "");
txt_xfr_size_time->tooltip(_("Transfer size / time"));
txt_xfr_size_time->value("");
// txt_xfr_size_time->value("");
controls->end();

View file

@ -42,7 +42,7 @@ HICS203, HICS206, HICS213, HICS214, IARU,
RADIOGRAM, PLAINTEXT, BLANK, CSV, CUSTOM,
MARSDAILY, MARSINEEI, MARSNET, MARSARMY, MARSNAVY,
REDXSNW, REDX5739, REDX5739A, REDX5739B,
WXHC, SEVEREWX, STORMREP, CAP105, CAP110, TRANSFER };
WXHC, SEVEREWX, STORMREP, CAP105, CAP110, TRANSFER, CUSTOM_TRANSFER };
struct FIELD { string f_type; string f_data; void **w; char w_type; };
extern FIELD fields[];
@ -1220,6 +1220,17 @@ extern void cb_transfer_textout();
extern void cb_transfer_import_data();
extern void cb_transfer_export_data();
extern string def_custom_transfer_filename;
extern void load_custom_html_file();
extern void load_custom_transfer();
extern void update_custom_transfer();
extern void cb_custom_form_wrap_import(string s1, string s2);
extern int eval_transfer_custom_form_fsize();
extern void cb_transfer_custom_html();
extern void cb_save_custom_html(Fl_Widget *w, void *d);
extern void cb_btn_select_custom_html(Fl_Widget *w, void *d);
//=====================================================================
// CAP 105
//=====================================================================

View file

@ -22,6 +22,7 @@
#define FLMSG_DIALOG_H
#include <string>
#include <vector>
#include <FL/Fl.H>
#include <FL/Fl_Pixmap.H>
@ -756,7 +757,6 @@ extern int num_custom_entries;
extern int custom_select;
extern void create_custom_tab();
extern Fl_Group *tab_custom;
extern FTextView *txt_custom_msg;
@ -764,6 +764,14 @@ extern void get_html_vars(struct mg_connection *conn);
extern void custom_editor(struct mg_connection *conn);
extern void custom_viewer(struct mg_connection *conn);
extern void create_custom_transfer_tab();
extern Fl_Group *tab_custom_transfer;
extern Fl_ListBox *custom_selector;
extern Fl_Output * txt_rcvd_custom_html_filename;
extern Fl_Button * btn_save_custom_html_file;
extern vector<string> custom_files;
//======================================================================
// Drag-n-Drop
//======================================================================

View file

@ -25,6 +25,7 @@
#include "flmsg_dialog.h"
#include "flmsg.h"
#include "transfer.h"
#include "combo.h"
Fl_Group *tab_transfer = (Fl_Group *)0;
@ -65,3 +66,4 @@ void create_transfer_tab()
tab_transfer->end();
tab_transfer->hide();
}

View file

@ -689,11 +689,11 @@ void xfr_via_socket(string basename, string inptext)
// socket interface
string autosend;
autosend.assign("... start\n").append(wrap_beg);
autosend.assign("\n\n\n... start\n").append(wrap_beg);
autosend.append(iscrlf ? wrap_crlf : wrap_lf);
autosend.append(payload);
autosend.append(wrap_chksum).append(check).append("]");
autosend.append(wrap_end).append("\n... end\n");
autosend.append(wrap_end).append("\n... end\n\n\n");
try {
if (!tcpip) connect_to_fldigi();