Commit 5267edac authored by stettberger's avatar stettberger

File transfer recieve geht

parent b94e0ded
......@@ -2,8 +2,7 @@ CC=gcc
TARGET=si
FILES=si.c mit.c
CFLAGS=-I/usr/local/silc/include -Wall -ggdb
LDFLAGS=-L/usr/local/silc/lib -lsilc -lsilcclient -lpthread -ldl
LDFLAGS=-L/usr/local/silc/lib -lsilc -lsilcclient -lpthread -ldl
all: ${TARGET}
${TARGET}: ${TARGET}.o
......
......@@ -184,7 +184,7 @@ void rm_query(Query *peer) {
void add_transfer(int num, SilcUInt32 id, SilcClientEntry sender, int type) {
Transfer *t, *tmp;
t=malloc(sizeof(Transfer));
t=calloc(1, sizeof(Transfer));
NULL_TEST(t);
if(!transfers)
transfers=t;
......@@ -199,7 +199,6 @@ void add_transfer(int num, SilcUInt32 id, SilcClientEntry sender, int type) {
t->silc=sender;
t->type=type;
t->status=FILE_STATUS_WAIT;
t->next=NULL;
}
void rm_transfer(Transfer *t) {
......@@ -211,7 +210,6 @@ void rm_transfer(Transfer *t) {
for (tmp=transfers; tmp; tmp=tmp->next)
if(tmp->id==t->id)
tmp->next=t->next;
free(t->path);
free(t);
}
......
......@@ -82,11 +82,10 @@ struct Transfer {
int number;
int type;
int status;
char *path;
long starttime;
float percent;
SilcUInt32 id;
SilcUInt64 offset;
SilcUInt64 filesize;
SilcClientEntry silc;
Transfer *next;
......@@ -281,37 +280,48 @@ void proc_channels_input(Channel *c, char *buf) {
if (!strncmp("list", &buf[6], 4)){
print_out("", "-?!- Number User Type Status");
for (t=transfers; t; t=t->next) {
print_out("", "-?!- %-5d %-5s %-5s %-5s", t->number, t->silc->nickname,
t->type==FILE_TYPE_IN?"incoming":"outgoing",
t->status==FILE_STATUS_WAIT?"waiting":(t->status==FILE_STATUS_RUN?"running":"complete"));
char *status;
if (t->status == FILE_STATUS_WAIT)
status="waiting";
else if (t->status == FILE_STATUS_RUN)
status="running";
else if (t->status == FILE_STATUS_ERR)
status="error";
else if (t->status == FILE_STATUS_COMP)
status="complete";
print_out("", "-?!- Number User Type Status");
print_out("", "-?!- %-5d %-10s %-10s %-10s", t->number, t->silc->nickname,
t->type==FILE_TYPE_IN?"incoming":"outgoing", status);
}
}
else if(!strncmp("accept ", &buf[6], 7)) {
for(t=transfers; t; t=t->next)
printf("File: %d %ld\n", t->number, t->id);
int num=atoi(&buf[13]);
for(t=transfers; t; t=t->next)
if(num==t->number){
char *path=malloc(strlen(getenv("HOME")+40));
NULL_TEST(path);
sprintf(path, "%s/.silc/incoming/", getenv("HOME"));
create_dirtree(path);
int res=silc_client_file_receive(silc_client->client,silc_client->conn,
file_transfer,NULL,path, t->id, NULL, NULL);
if(res!=SILC_CLIENT_FILE_OK){
DEBUG("Error: %d\n", res);
print_out("", "-!- Error: Couldn't start filetransfer");
return;
}
return;
}
print_out("", "-!- No such File transfer");
if(num==t->number)
break;
if(!t) {
print_out("", "-!- No such File transfer");
return;
}
char *path=malloc(strlen(getenv("HOME"))+40);
NULL_TEST(path);
sprintf(path, "%s/.silc/incoming/", getenv("HOME"));
create_dirtree(path);
int res=silc_client_file_receive(silc_client->client,silc_client->conn,
file_transfer,NULL,path, t->id, NULL, NULL);
if(res!=SILC_CLIENT_FILE_OK){
DEBUG("Error: %d\n", res);
print_out("", "-!- Error: Couldn't start filetransfer");
return;
}
}
else if(!strncmp("close ", &buf[6], 6)) {
int num=atoi(&buf[12]);
for(t=transfers; t; t=t->next)
if(num==t->number){
DEBUG("succes");
silc_client_file_close(silc_client->client,silc_client->conn,t->id);
print_out("", "-!- File: file transfer closed %d", t->number);
rm_transfer(t);
return;
}
print_out("", "-!- No such File transfer");
......@@ -749,16 +759,43 @@ void file_transfer(SilcClient client,
for (t=transfers; t; t=t->next)
if( t->id == session_id )
break;
DEBUG("%d", status);
if ( offset && filesize )
t->percent = (float) ((double)offset / (double)filesize) * (double)100.0;
if (status == SILC_CLIENT_FILE_MONITOR_ERROR) {
print_out("", "-!- Error: Filetransfer with %s (Number: %d) has failed", client_entry->nickname, t->number);
if (error == SILC_CLIENT_FILE_NO_SUCH_FILE)
print_out("", "-!- Error: There is no such file (Number: %d)",t->number);
else if(error == SILC_CLIENT_FILE_PERMISSION_DENIED)
print_out("", "-!- Error: Permission denied (Number: %d)",t->number);
else
print_out("", "-!- Error: File transfer failed (Number: %d)",t->number);
t->status=FILE_STATUS_ERR;
return;
}
if(status==SILC_CLIENT_FILE_MONITOR_CLOSED) {
print_out("", "-!- File: Transfer (%s) with %s (Number %d) was successful", filepath, client_entry->nickname, t->number);
t->status=FILE_STATUS_COMP;
else if (status == SILC_CLIENT_FILE_MONITOR_KEY_AGREEMENT)
print_out("", "-!- File: Negotiating keys for file transfer %d", t->number);
else if (status == SILC_CLIENT_FILE_MONITOR_SEND || status == SILC_CLIENT_FILE_MONITOR_RECEIVE) {
if(offset==0) {
t->starttime=time(NULL);
print_out("", "-!- File: Started file transfer with %d", t->number);
t->status=FILE_STATUS_RUN;
}
else if (offset == filesize) {
unsigned long delta=time(NULL)-t->starttime;
float kps;
if (delta)
kps = (double)((offset / (double)delta) + 1023) / (double)1024;
else
kps = (double)(offset + 1023) / (double)1024;
print_out("", "-!- File: Completed file transfer %d [%.2f kB/s]", t->number, kps);
print_out("", "-!- File: saved to: %s", filepath);
t->status=FILE_STATUS_COMP;
}
}
}
/* }}} */
/* {{{ run_once */
......
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