Commit 30268905 authored by rswindell's avatar rswindell
Browse files

Created sbbs_t::sendfile() and recvfile(), exposed via JS as bbs.send_file()

and receive_file() - so str_cmds.js may now support ;GET and ;PUT.
parent 77c9cc8b
...@@ -614,8 +614,7 @@ function str_cmds(str) ...@@ -614,8 +614,7 @@ function str_cmds(str)
if(str=="HELP") { if(str=="HELP") {
writeln("GET [path]"); writeln("GET [path]");
writeln("\tToDo: This *should* download the specified file"); writeln("\tDownload the specified file");
writeln("\tThis is not currently possible from JS however.");
} }
if(word=="GET") { if(word=="GET") {
str=str.substr(3); str=str.substr(3);
...@@ -633,15 +632,13 @@ function str_cmds(str) ...@@ -633,15 +632,13 @@ function str_cmds(str)
if(!bbs.check_syspass()) if(!bbs.check_syspass())
return; return;
// ToDo "GET" not implemented bbs.send_file(str);
writeln("\r\nFILE_GET not implemented!");
return; return;
} }
if(str=="HELP") { if(str=="HELP") {
writeln("PUT [path]"); writeln("PUT [path]");
writeln("\tToDo: This *should* upload the specified file"); writeln("\tUpload the specified file");
writeln("\tThis is not currently possible from JS however.");
} }
if(word=="PUT") { if(word=="PUT") {
str=str.substr(3); str=str.substr(3);
...@@ -659,8 +656,7 @@ function str_cmds(str) ...@@ -659,8 +656,7 @@ function str_cmds(str)
if(!bbs.check_syspass()) if(!bbs.check_syspass())
return; return;
// ToDo "PUT" not implemented bbs.receive_file(str);
writeln("\r\nPUT not implemented!");
return; return;
} }
} }
......
...@@ -449,3 +449,34 @@ void sbbs_t::seqwait(uint devnum) ...@@ -449,3 +449,34 @@ void sbbs_t::seqwait(uint devnum)
} }
} }
bool sbbs_t::sendfile(char* fname)
{
char keys[128];
char ch;
size_t i;
bool result=false;
xfer_prot_menu(XFER_DOWNLOAD);
mnemonics(text[ProtocolOrQuit]);
strcpy(keys,"Q");
for(i=0;i<cfg.total_prots;i++)
if(cfg.prot[i]->dlcmd[0] && chk_ar(cfg.prot[i]->ar,&useron))
sprintf(keys+strlen(keys),"%c",cfg.prot[i]->mnemonic);
ch=(char)getkeys(keys,0);
if(ch=='Q' || sys_status&SS_ABORT)
return(false);
for(i=0;i<cfg.total_prots;i++)
if(cfg.prot[i]->mnemonic==ch && chk_ar(cfg.prot[i]->ar,&useron))
break;
if(i<cfg.total_prots) {
if(protocol(cfg.prot[i],XFER_DOWNLOAD,fname,fname,false)==0)
result=true;
autohangup();
}
return(result);
}
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) * * @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) * * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* * * *
* Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html * * Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html *
* * * *
* This program is free software; you can redistribute it and/or * * This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License * * modify it under the terms of the GNU General Public License *
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
int sbbs_t::exec_function(csi_t *csi) int sbbs_t::exec_function(csi_t *csi)
{ {
char str[256],ch; char str[256];
char tmp[512]; char tmp[512];
uchar* p; uchar* p;
int s; int s;
...@@ -357,25 +357,7 @@ int sbbs_t::exec_function(csi_t *csi) ...@@ -357,25 +357,7 @@ int sbbs_t::exec_function(csi_t *csi)
case CS_FILE_SEND: case CS_FILE_SEND:
csi->logic=LOGIC_FALSE; csi->logic=sendfile(csi->str) ? LOGIC_TRUE:LOGIC_FALSE;
xfer_prot_menu(XFER_DOWNLOAD);
mnemonics(text[ProtocolOrQuit]);
strcpy(str,"Q");
for(i=0;i<cfg.total_prots;i++)
if(cfg.prot[i]->dlcmd[0] && chk_ar(cfg.prot[i]->ar,&useron)) {
sprintf(tmp,"%c",cfg.prot[i]->mnemonic);
strcat(str,tmp); }
ch=(char)getkeys(str,0);
if(ch=='Q' || sys_status&SS_ABORT) {
return(0); }
for(i=0;i<cfg.total_prots;i++)
if(cfg.prot[i]->mnemonic==ch && chk_ar(cfg.prot[i]->ar,&useron))
break;
if(i<cfg.total_prots) {
if(protocol(cfg.prot[i],XFER_DOWNLOAD,csi->str,csi->str,false)==0)
csi->logic=LOGIC_TRUE;
autohangup();
}
return(0); return(0);
case CS_FILE_PUT: case CS_FILE_PUT:
...@@ -384,26 +366,7 @@ int sbbs_t::exec_function(csi_t *csi) ...@@ -384,26 +366,7 @@ int sbbs_t::exec_function(csi_t *csi)
return(0); return(0);
case CS_FILE_RECEIVE: case CS_FILE_RECEIVE:
csi->logic=LOGIC_FALSE; csi->logic=recvfile(csi->str) ? LOGIC_TRUE:LOGIC_FALSE;
xfer_prot_menu(XFER_UPLOAD);
mnemonics(text[ProtocolOrQuit]);
strcpy(str,"Q");
for(i=0;i<cfg.total_prots;i++)
if(cfg.prot[i]->ulcmd[0] && chk_ar(cfg.prot[i]->ar,&useron)) {
sprintf(tmp,"%c",cfg.prot[i]->mnemonic);
strcat(str,tmp); }
ch=(char)getkeys(str,0);
if(ch=='Q' || sys_status&SS_ABORT) {
lncntr=0;
return(0); }
for(i=0;i<cfg.total_prots;i++)
if(cfg.prot[i]->mnemonic==ch && chk_ar(cfg.prot[i]->ar,&useron))
break;
if(i<cfg.total_prots) {
if(protocol(cfg.prot[i],XFER_UPLOAD,csi->str,csi->str,true)==0)
csi->logic=LOGIC_TRUE;
autohangup();
}
return(0); return(0);
case CS_FILE_UPLOAD_BULK: case CS_FILE_UPLOAD_BULK:
......
...@@ -1578,6 +1578,32 @@ js_batchaddlist(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rv ...@@ -1578,6 +1578,32 @@ js_batchaddlist(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rv
return(JS_TRUE); return(JS_TRUE);
} }
static JSBool
js_sendfile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
sbbs_t* sbbs;
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
*rval = BOOLEAN_TO_JSVAL(sbbs->sendfile(JS_GetStringBytes(JS_ValueToString(cx, argv[0]))));
return(JS_TRUE);
}
static JSBool
js_recvfile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
sbbs_t* sbbs;
if((sbbs=(sbbs_t*)JS_GetContextPrivate(cx))==NULL)
return(JS_FALSE);
*rval = BOOLEAN_TO_JSVAL(sbbs->recvfile(JS_GetStringBytes(JS_ValueToString(cx, argv[0]))));
return(JS_TRUE);
}
static JSBool static JSBool
js_temp_xfer(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) js_temp_xfer(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{ {
...@@ -2626,7 +2652,15 @@ static jsSyncMethodSpec js_bbs_functions[] = { ...@@ -2626,7 +2652,15 @@ static jsSyncMethodSpec js_bbs_functions[] = {
{"batch_add_list", js_batchaddlist, 1, JSTYPE_VOID, JSDOCSTR("list_filename") {"batch_add_list", js_batchaddlist, 1, JSTYPE_VOID, JSDOCSTR("list_filename")
,JSDOCSTR("add file list to batch download queue") ,JSDOCSTR("add file list to batch download queue")
,310 ,310
}, },
{"send_file", js_sendfile, 1, JSTYPE_BOOLEAN, JSDOCSTR("filename")
,JSDOCSTR("send specified filename (complete path) to user via user-prompted protocol")
,31301
},
{"receive_file", js_recvfile, 1, JSTYPE_BOOLEAN, JSDOCSTR("filename")
,JSDOCSTR("received specified filename (complete path) frome user via user-prompted protocol")
,31301
},
{"temp_xfer", js_temp_xfer, 0, JSTYPE_VOID, JSDOCSTR("") {"temp_xfer", js_temp_xfer, 0, JSTYPE_VOID, JSDOCSTR("")
,JSDOCSTR("enter the temporary file tranfer menu") ,JSDOCSTR("enter the temporary file tranfer menu")
,310 ,310
......
...@@ -608,6 +608,8 @@ public: ...@@ -608,6 +608,8 @@ public:
void autohangup(void); void autohangup(void);
bool checkdszlog(file_t*); bool checkdszlog(file_t*);
bool checkprotresult(prot_t*, int error, file_t*); bool checkprotresult(prot_t*, int error, file_t*);
bool sendfile(char* fname);
bool recvfile(char* fname);
/* file.cpp */ /* file.cpp */
void fileinfo(file_t* f); void fileinfo(file_t* f);
......
...@@ -599,3 +599,33 @@ bool sbbs_t::bulkupload(uint dirnum) ...@@ -599,3 +599,33 @@ bool sbbs_t::bulkupload(uint dirnum)
return(false); return(false);
} }
bool sbbs_t::recvfile(char *fname)
{
char keys[32];
char ch;
size_t i;
bool result=false;
xfer_prot_menu(XFER_UPLOAD);
mnemonics(text[ProtocolOrQuit]);
strcpy(keys,"Q");
for(i=0;i<cfg.total_prots;i++)
if(cfg.prot[i]->ulcmd[0] && chk_ar(cfg.prot[i]->ar,&useron))
sprintf(keys+strlen(keys),"%c",cfg.prot[i]->mnemonic);
ch=(char)getkeys(keys,0);
if(ch=='Q' || sys_status&SS_ABORT)
return(false);
for(i=0;i<cfg.total_prots;i++)
if(cfg.prot[i]->mnemonic==ch && chk_ar(cfg.prot[i]->ar,&useron))
break;
if(i<cfg.total_prots) {
if(protocol(cfg.prot[i],XFER_UPLOAD,fname,fname,true)==0)
result=true;
autohangup();
}
return(result);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment