Commit 002285c1 authored by stettberger's avatar stettberger

Buddylist

parent 12d965b1
......@@ -22,6 +22,8 @@
/* Buddylist stuff */
SILC_TASK_CALLBACK(si_handle_buddyfd_input);
SILC_TASK_CALLBACK(si_handle_buddy_conn_input);
void add_pubkey_callback(SilcClient client, SilcClientConnection conn,
SilcClientEntry *clients, SilcUInt32 clients_count,
void *context);
......@@ -103,6 +105,10 @@ void init_buddylist() {
DIR *dir;
char *pubkey, *path;
struct dirent *entry;
struct sockaddr_un strAddr;
socklen_t lenAddr;
int yes=1;
/* Init the buddylist itself */
path=malloc(strlen(getenv("HOME"))+40);
NULL_TEST(path);
sprintf(path, "%s/.silc/buddylist", (char *)getenv("HOME"));
......@@ -119,4 +125,49 @@ void init_buddylist() {
}
closedir(dir);
free(path);
/* Buddyfd */
path=malloc(strlen(ircdir)+20);
NULL_TEST(path);
sprintf(path,"%s/buddylist", ircdir);
if ((buddyfd=socket(PF_UNIX, SOCK_STREAM,0))==-1) {
perror("si: couldn't initalize buddy socket (socket)");
return;
}
if (setsockopt(buddyfd, SOL_SOCKET, SO_REUSEADDR,
(char *) &yes, sizeof(yes)) < 0) {
perror("si: couldn't initalize buddy socket (setsockopt)");
return;
}
strAddr.sun_family=AF_UNIX; /* Unix Domain */
strcpy(strAddr.sun_path, path);
lenAddr=sizeof(strAddr.sun_family)+strlen(strAddr.sun_path);
if (bind(buddyfd, (struct sockaddr*)&strAddr, lenAddr) < 0) {
perror("si: couldn't initalize buddy socket (bind)");
return;
}
if (listen(buddyfd, 20) != 0){
perror("si: couldn't initalize buddy socket (listen)");
return;
}
silc_schedule_task_add(silc_client->client->schedule, buddyfd,
si_handle_buddyfd_input, &strAddr, 0, 0,
SILC_TASK_FD, SILC_TASK_PRI_NORMAL);
}
SILC_TASK_CALLBACK(si_handle_buddyfd_input) {
int conn=0;
socklen_t lenAddr;
struct sockaddr_un *addr=context;
lenAddr=sizeof(addr->sun_family)+strlen(addr->sun_path);
if((conn=accept(fd, addr, &lenAddr))<0) {
perror("si: couldn't accept connection on buddylist");
return;
}
silc_schedule_task_add(silc_client->client->schedule, conn,
si_handle_buddy_conn_input, NULL, 0, 0,
SILC_TASK_FD, SILC_TASK_PRI_NORMAL);
}
SILC_TASK_CALLBACK(si_handle_buddy_conn_input) {
DEBUG("Data");
}
......@@ -52,12 +52,12 @@ static void create_dirtree(const char *dir) {
static int get_filepath(char *filepath, size_t len, char *channel, char *file)
{
if(strlen(channel)!=0) {
if(!snprintf(filepath, len, "%s/%s", path, lower(channel)))
if(!snprintf(filepath, len, "%s/%s", ircdir, lower(channel)))
return 0;
create_dirtree(filepath);
return snprintf(filepath, len, "%s/%s/%s", path,lower(channel), file);
return snprintf(filepath, len, "%s/%s/%s", ircdir,lower(channel), file);
}
return snprintf(filepath, len, "%s/%s", path, file);
return snprintf(filepath, len, "%s/%s", ircdir, file);
}
static void create_filepath(char *filepath, size_t len, char *channel, char *suffix)
......
......@@ -36,6 +36,8 @@
#include <getopt.h>
#include <dirent.h>
#include <time.h>
#include <sys/socket.h>
#include <sys/un.h>
/* {{{ Structs, Globals Declarations */
......@@ -127,7 +129,7 @@ char *realname = NULL;
char *host = "sauna.silcnet.org";
char *init_script=NULL;
int port=706;
char path[1024];
char ircdir[1024];
Channel *channels=NULL;
Query *queries=NULL;
Transfer *transfers=NULL;
......@@ -138,6 +140,7 @@ SilcClientOperations ops;
Silc silc_client;
time_t last_input;
int transfer_count=1;
int buddyfd=0;
void DEBUG(char *fmt, ...);
int LocalToUtf8 (char *from, char **to);
......@@ -1041,11 +1044,11 @@ int run(void)
}
}
/* create path */
if(!snprintf(path, sizeof(path), "%s/%s", prefix, host)) {
if(!snprintf(ircdir, sizeof(ircdir), "%s/%s", prefix, host)) {
fprintf(stderr, "%s", "si: path to irc directory too long\n");
exit(EXIT_FAILURE);
}
create_dirtree(path);
create_dirtree(ircdir);
/* Maser Channel */
SilcChannelEntry master;
......@@ -1790,16 +1793,18 @@ 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);
NULL_TEST(path);
NULL_TEST(ircdir);
sprintf(filename, "%s/.silc/session.%s", getenv("HOME"), host);
silc_file_writefile(filename, (char *)detach_data, detach_data_len);
free(filename);
DEBUG("Detach: Success");
}
/* }}} */
/* {{{ verify_public_key */
int verify_public_key(SilcPublicKey key, int remote) {
......
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