This commit is contained in:
parent
677add88f0
commit
c92bb5e352
4 changed files with 162 additions and 234 deletions
|
@ -1,102 +1,20 @@
|
|||
#include "eyd.hh"
|
||||
#include "eydrle.hh"
|
||||
|
||||
using namespace std;
|
||||
namespace EydTools {
|
||||
EydRle::EydRle(){
|
||||
_mode_compress = EYDRLE_MODE_UNDEF;
|
||||
_input_file.clear();
|
||||
_output_file.clear();
|
||||
_cellsize = 8; // one octet each time (by default);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv){
|
||||
/*
|
||||
std::string *servermsgold, *usermsg, *userparam;
|
||||
int ret;
|
||||
char * tmp_c_string;
|
||||
ftp_cmd_t ftp_cmd;
|
||||
|
||||
ftp_connection_state_t cnx_state;
|
||||
FtpConfig * client_conf = NULL;
|
||||
|
||||
servermsgold = NULL;
|
||||
usermsg = NULL;
|
||||
userparam = NULL;
|
||||
cnx_state = FTP_STATE_DISCONNECTED;
|
||||
|
||||
client_conf = new FtpConfig();
|
||||
ret = miniftp_args(client_conf, argc, argv);
|
||||
if (ret < 0) { return EXIT_FAILURE; }
|
||||
|
||||
printf("Connecting to %s:%d\n... ",
|
||||
client_conf->server_conf->host->c_str(),
|
||||
client_conf->server_conf->port);
|
||||
fflush(stdout);
|
||||
|
||||
XionFS::XSock *cmdXSock; // *dataXSock;
|
||||
|
||||
cmdXSock = new XionFS::XSock(XionFS::CLIENT,XionFS::TCP);
|
||||
cmdXSock->port(client_conf->server_conf->port);
|
||||
cmdXSock->dns(client_conf->server_conf->host->c_str());
|
||||
|
||||
cmdXSock->launch();
|
||||
printf(" fait\n");
|
||||
client_conf->cmd_xsocket = cmdXSock;
|
||||
|
||||
// init sequence
|
||||
MiniFtp::ServerMsg * servermsg;
|
||||
// ("220 hophop");
|
||||
servermsg = ftp_cmd_recv(client_conf);
|
||||
|
||||
if ((servermsg->getStatus()/10) == 22){
|
||||
cnx_state = FTP_STATE_CONNECTED;
|
||||
void EydRle::run(){
|
||||
if (_mode_compress == EYDRLE_MODE_COMPRESS){
|
||||
this->compress();
|
||||
} else {
|
||||
cout << "ERROR\n";
|
||||
return EXIT_FAILURE; // event system
|
||||
this->uncompress();
|
||||
}
|
||||
delete(servermsg);
|
||||
// init
|
||||
|
||||
cout <<"Auth...\n";
|
||||
while(cnx_state == FTP_STATE_CONNECTED){
|
||||
|
||||
tmp_c_string = readline("Login...: ");
|
||||
usermsg = new std::string(tmp_c_string);
|
||||
ftp_cmd_send(client_conf, FTP_CMD_USER, (char*)usermsg->c_str());
|
||||
free(tmp_c_string);
|
||||
delete(usermsg);
|
||||
|
||||
servermsg = ftp_cmd_recv(client_conf);
|
||||
if (servermsg->getStatus() != 331){
|
||||
continue;
|
||||
}
|
||||
delete(servermsg);
|
||||
|
||||
tmp_c_string = readline("Password: ");
|
||||
usermsg = new std::string(tmp_c_string);
|
||||
ftp_cmd_send(client_conf, FTP_CMD_PASS, (char*)usermsg->c_str());
|
||||
delete(usermsg);
|
||||
|
||||
servermsg = ftp_cmd_recv(client_conf);
|
||||
if ((servermsg->getStatus() / 10) == 23){
|
||||
cnx_state = FTP_STATE_LOGGED_IN;
|
||||
}
|
||||
delete(usermsg);
|
||||
|
||||
}
|
||||
while(cnx_state == FTP_STATE_LOGGED_IN){
|
||||
tmp_c_string = readline("ftp> ");
|
||||
usermsg = new std::string(tmp_c_string);
|
||||
//userparam = (char *) malloc(sizeof(char) * CLIENTQUERY_MAX_LENGTH);
|
||||
ftp_cmd = ftp_cmd_parse(usermsg, &userparam);
|
||||
//Think to keep FTP filesystem tree somewhere
|
||||
ftp_cmd_send(client_conf, ftp_cmd, userparam);
|
||||
if (ftp_cmd == FTP_CMD_QUIT){
|
||||
printf("Disconnecting...\n");
|
||||
cnx_state = FTP_STATE_DISCONNECTED;
|
||||
}
|
||||
free(userparam);
|
||||
delete(usermsg);
|
||||
free(tmp_c_string);
|
||||
}
|
||||
|
||||
// on le garde dans un coin au chaud en attendant
|
||||
// dataXSock->launch();
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,34 +1,18 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <eyd.hh>
|
||||
#include <exception>
|
||||
#include <vector>
|
||||
#include "eydrle.hh"
|
||||
|
||||
void usage(){
|
||||
printf("usage : bitcopy <int> <file>\n");
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv){
|
||||
namespace EydTools {
|
||||
void EydRle::compress(){
|
||||
EydLib::BitGroup data;
|
||||
int cell_size;
|
||||
std::string original;
|
||||
std::string copy;
|
||||
|
||||
if (argc<2){ usage(); exit(-1); }
|
||||
cell_size = atoi(argv[1]);
|
||||
original = argv[2];
|
||||
EydLib::BitReader bitread(_cellsize, 256);
|
||||
bitread.open(_input_file);
|
||||
|
||||
copy = original + ".rl1";
|
||||
|
||||
EydLib::BitReader bitread(cell_size, 256);
|
||||
bitread.open(original);
|
||||
|
||||
EydLib::BitWriter bitwrite(cell_size,256);
|
||||
bitwrite.open(copy);
|
||||
unsigned char c = (unsigned char)cell_size;
|
||||
EydLib::BitWriter bitwrite(_cellsize,256);
|
||||
bitwrite.open(_output_file);
|
||||
unsigned char c = (unsigned char)_cellsize;
|
||||
bitwrite.writeDirect(&c, 1);
|
||||
|
||||
EydLib::BitCompressor compressor(cell_size);
|
||||
EydLib::BitCompressor compressor(_cellsize);
|
||||
|
||||
printf("File opened\n");
|
||||
|
||||
|
@ -50,7 +34,7 @@ int main(int argc, char ** argv){
|
|||
}
|
||||
} catch (EydLib::eBitReaderEndOfFile& e) {
|
||||
done = true;
|
||||
// TODO: on flushe le contenu de record
|
||||
// on flushe le contenu de record
|
||||
compressor.flushRleData();
|
||||
std::list<EydLib::BitGroup> compressedData = compressor.flush();
|
||||
std::list<EydLib::BitGroup>::iterator cmpDataIt;
|
||||
|
@ -70,3 +54,4 @@ int main(int argc, char ** argv){
|
|||
|
||||
printf("file closed\n");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,34 +1,71 @@
|
|||
#include "eyd.hh"
|
||||
#include "eydrle.hh"
|
||||
|
||||
namespace EydTools {
|
||||
|
||||
bool EydRle::init(int argc, char ** argv){
|
||||
_mode_compress = EYDRLE_MODE_UNDEF;
|
||||
|
||||
/*
|
||||
int miniftp_args(MiniFtp::FtpConfig * client_conf, int argc, char ** argv){ // GOOD
|
||||
int i;
|
||||
|
||||
for (i = 1; i + 1 < argc; i = i + 2){
|
||||
char * opt = argv[i]; //GOOD
|
||||
char * val = argv[i+1]; //GOOD
|
||||
if ( (strcmp(opt, "--port") == 0) || (strcmp(opt,"-p") == 0) ){
|
||||
client_conf->setServerPort(atoi(val));
|
||||
if ( (strcmp(opt, "--mode") == 0) || (strcmp(opt,"-m") == 0) ){
|
||||
switch(val[0]){
|
||||
case 'c':
|
||||
case 'C':
|
||||
_mode_compress = EYDRLE_MODE_COMPRESS;
|
||||
break;
|
||||
case 'u':
|
||||
case 'U':
|
||||
_mode_compress = EYDRLE_MODE_UNCOMPRESS;
|
||||
break;
|
||||
default:
|
||||
_mode_compress = EYDRLE_MODE_UNDEF;
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if ( (strcmp(opt, "--host") == 0) || (strcmp(opt,"-h") == 0) ){
|
||||
client_conf->setServerHost(std::string(val));
|
||||
continue;
|
||||
|
||||
if ( (strcmp(opt, "--input") == 0) || (strcmp(opt,"-i") == 0) ){
|
||||
_input_file = val;
|
||||
}
|
||||
|
||||
if ( (strcmp(opt, "--output") == 0) || (strcmp(opt,"-o") == 0) ){
|
||||
_output_file = val;
|
||||
}
|
||||
|
||||
if ( (strcmp(opt, "--cellsize") == 0) || (strcmp(opt,"-c") == 0) ){
|
||||
_cellsize = atoi(val);
|
||||
}
|
||||
|
||||
// printf("Option = %s, ",argv[i]);
|
||||
// printf("value = %s\n",argv[i+1]);
|
||||
}
|
||||
|
||||
if (!client_conf->hasServerHost()
|
||||
|| !client_conf->hasServerPort()) {
|
||||
if ((_mode_compress == EYDRLE_MODE_UNDEF) ||
|
||||
(_input_file.length() == 0)) {
|
||||
printf("\nUsage: %s <options>\n", argv[0]);
|
||||
printf("\nWhere options could be:\n");
|
||||
printf("-p, --port <integer> Port to connect on host\n");
|
||||
printf("-h, --host <string> DNS or IP address of the FTP host\n");
|
||||
return -1;
|
||||
printf("-m, --mode (c|u) Compress or uncompress\n");
|
||||
printf("-i, --input <file> File to compress | uncompress\n");
|
||||
printf("-o, --output <file> Destination file\n");
|
||||
printf("-c, --cellsize <file> Cell size (in bits)\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_output_file.length() == 0){
|
||||
if (_mode_compress == EYDRLE_MODE_COMPRESS){
|
||||
_output_file = _input_file + ".rl1";
|
||||
} else {
|
||||
_output_file = _input_file + ".rl1_orig";
|
||||
}
|
||||
}
|
||||
|
||||
// setting rle
|
||||
EydLib::BitGroup rleFinal(_cellsize);
|
||||
_rle = rleFinal;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -1,36 +1,24 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <eyd.hh>
|
||||
#include <exception>
|
||||
#include <vector>
|
||||
#include "eydrle.hh"
|
||||
|
||||
void usage(){
|
||||
printf("usage : bitcopy <int> <file>\n");
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv){
|
||||
namespace EydTools {
|
||||
void EydRle::uncompress(){
|
||||
EydLib::BitGroup data;
|
||||
int cell_size;
|
||||
std::string original;
|
||||
std::string copy;
|
||||
|
||||
if (argc<2){ usage(); exit(-1); }
|
||||
cell_size = atoi(argv[1]);
|
||||
original = argv[2];
|
||||
|
||||
copy = original + ".rl2";
|
||||
|
||||
EydLib::BitReader bitread(cell_size, 256);
|
||||
bitread.open(original);
|
||||
EydLib::BitReader bitread(_cellsize, 256);
|
||||
bitread.open(_input_file);
|
||||
|
||||
unsigned char c;
|
||||
bitread.readDirect(&c, 1);
|
||||
//TODO: fixer cell_size en fonction de "c";
|
||||
|
||||
EydLib::BitWriter bitwrite(cell_size,256);
|
||||
bitwrite.open(copy);
|
||||
if (c != _cellsize){
|
||||
printf("WARNING : File cellsize is %d, but uncompressing with %d\n",c, _cellsize);
|
||||
}
|
||||
|
||||
EydLib::BitUncompressor uncompressor(cell_size);
|
||||
EydLib::BitWriter bitwrite(_cellsize,256);
|
||||
bitwrite.open(_output_file);
|
||||
|
||||
EydLib::BitUncompressor uncompressor(_cellsize);
|
||||
|
||||
printf("File opened\n");
|
||||
|
||||
|
@ -53,7 +41,6 @@ int main(int argc, char ** argv){
|
|||
} catch (EydLib::eBitReaderEndOfFile& e) {
|
||||
done = true;
|
||||
// on flushe le contenu de record
|
||||
// FIXME: trouver un moyen de flusher la fin du fichier
|
||||
// uncompressor.flushRleData();
|
||||
std::list<EydLib::BitGroup> uncompressedData = uncompressor.flush();
|
||||
std::list<EydLib::BitGroup>::iterator uncmpDataIt;
|
||||
|
@ -73,3 +60,4 @@ int main(int argc, char ** argv){
|
|||
|
||||
printf("file closed\n");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue