Commit 561453a1 authored by stettberger's avatar stettberger

* Detach Stuff:

- after a /detach, the session is restored correctly
- Option: signal_detach (detach_on_signal)
parent b5377121
......@@ -75,8 +75,8 @@ static int open_channel(char *name)
if(access(infile, F_OK) == -1)
mkfifo(infile, S_IRWXU);
return open(infile, O_RDONLY | O_NONBLOCK, 0);
}
static void add_channel(SilcChannelEntry channel) {
Channel *c;
int fd;
......
......@@ -39,6 +39,7 @@ typedef struct {
SilcClientConnection conn; /* Connection to the server */
/* Config */
int sign:1;
int detach_on_signal:1;
} *Silc;
typedef struct Channel Channel;
......@@ -153,8 +154,12 @@ void print_users(SilcClient client,
/* }}} */
/* {{{ sig_handler */
void sig_handler(int sig){
if(sig==SIGINT || sig==SIGTERM )
silc_client_command_call(silc_client->client, silc_client->conn, "quit Leaving", NULL);
if(sig==SIGINT || sig==SIGTERM ){
if(silc_client->detach_on_signal)
silc_client_command_call(silc_client->client, silc_client->conn, "detach", NULL);
else
silc_client_command_call(silc_client->client, silc_client->conn, "quit Leaving", NULL);
}
}
/* }}} */
......@@ -296,13 +301,23 @@ void proc_channels_input(Channel *c, char *buf) {
silc_client->sign=FALSE;
print_out(c->silc->channel_name, "-!- Signing Messages: off");
}
else {
else
print_out(c->silc->channel_name, "-!- Error: False Argument");
}
else if (!strncmp("signal_detach ", &buf[5], 14)) {
if (!strncmp("on", &buf[19], 2)){
silc_client->detach_on_signal=TRUE;
print_out(c->silc->channel_name, "-!- Detach on Signal: on");
}
else if (!strncmp("off", &buf[19], 3)){
silc_client->detach_on_signal=FALSE;
print_out(c->silc->channel_name, "-!- Detach on Signal: off");
}
else
print_out(c->silc->channel_name, "-!- Error: False Argument");
}
else {
else
print_out(c->silc->channel_name, "-!- Error: False Argument");
}
}
else {
DEBUG("Input: SENT_COMMAND");
......@@ -601,6 +616,7 @@ int run(void)
{
int fd;
SilcClientParams params;
SilcClientConnectionParams conn_params;
silc_client = silc_calloc(1, sizeof(*silc_client));
if (!silc_client) {
perror("si: Could not allocate memory!");
......@@ -662,14 +678,41 @@ int run(void)
return 1;
}
}
/* create path */
if(!snprintf(path, sizeof(path), "%s/%s", prefix, host)) {
fprintf(stderr, "%s", "si: path to irc directory too long\n");
exit(EXIT_FAILURE);
}
create_dirtree(path);
/* Maser Channel */
SilcChannelEntry master;
master=silc_calloc(1, sizeof(*master));
if(!master){
perror("si: Could not allocate memory!");
exit(1);
}
master->channel_name="";
add_channel(master);
/* Restoring Detached data */
char *filename;
filename=malloc(strlen(getenv("HOME"))+strlen(host)+30);
if(!filename){
perror("si: Couldn't allocate memory");
return 1;
}
sprintf(filename, "%s/.silc/session.%s", getenv("HOME"), host);
conn_params.detach_data_len=0;
conn_params.detach_data=(unsigned char *)silc_file_readfile(filename, &conn_params.detach_data_len);
free(filename);
/* Start connecting to server. This is asynchronous connecting so the
connection is actually created later after we run the client. */
silc_client_connect_to_server(silc_client->client, NULL, port,
silc_client_connect_to_server(silc_client->client, &conn_params, port,
host, silc_client);
/* Run it one time */
while(!connected)
silc_client_run_one(silc_client->client);
......@@ -1032,6 +1075,7 @@ silc_connected(SilcClient si, SilcClientConnection conn,
SilcClientConnectionStatus status)
{
DEBUG("Connected: EVENT");
SilcChannelEntry channel;
Silc client = si->application;
if (status == SILC_CLIENT_CONN_ERROR) {
......@@ -1043,23 +1087,24 @@ silc_connected(SilcClient si, SilcClientConnection conn,
/* Save the connection context */
client->conn = conn;
/* create path */
if(!snprintf(path, sizeof(path), "%s/%s", prefix, host)) {
fprintf(stderr, "%s", "si: path to irc directory too long\n");
exit(EXIT_FAILURE);
}
create_dirtree(path);
/* Maser Channel */
SilcChannelEntry master;
master=silc_calloc(1, sizeof(*master));
if(!master){
perror("si: Could not allocate memory!");
exit(1);
/* Resuming old session */
if(status==SILC_CLIENT_CONN_SUCCESS_RESUME) {
DEBUG("Connect: RESUME");
SilcHashTableList ch;
silc_hash_table_list(silc_client->conn->local_entry->channels, &ch);
while (silc_hash_table_get(&ch, (void *)&channel, NULL))
add_channel(channel);
silc_hash_table_list_reset(&ch);
char *filename=malloc(strlen(getenv("HOME"))+strlen(host)+30);
if(!filename){
perror("si: Couldn't allocate memory");
return;
}
sprintf(filename, "%s/.silc/session.%s", getenv("HOME"), host);
unlink(filename);
free(filename);
print_out("", "-!- Resumed old session");
}
master->channel_name="";
add_channel(master);
connected=1;
DEBUG("Connect: Connection succsessful");
}
......@@ -1331,6 +1376,22 @@ silc_private_message(SilcClient client, SilcClientConnection conn,
}
/* }}} */
/* {{{ silc_detach */
void silc_detach(SilcClient client, SilcClientConnection conn,
const unsigned char *detach_data, SilcUInt32 detach_data_len) {
char *filename;
filename=malloc(strlen(getenv("HOME"))+strlen(host)+30);
if(!filename){
perror("si: Couldn't allocate memory");
return;
}
sprintf(filename, "%s/.silc/session.%s", getenv("HOME"), host);
silc_file_writefile(filename, (char *)detach_data, detach_data_len);
free(filename);
DEBUG("Detach: Success");
}
/* }}} */
/* {{{ Empty and unused, but required Functions */
static void
......@@ -1395,14 +1456,6 @@ silc_ftp(SilcClient client, SilcClientConnection conn,
const char *hostname, SilcUInt16 port)
{
}
static void
silc_detach(SilcClient client, SilcClientConnection conn,
const unsigned char *detach_data, SilcUInt32 detach_data_len)
{
}
/* }}} */
/* {{{ Client-Ops and main() */
SilcClientOperations ops = {
......
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