Commit bc338540 authored by stettberger's avatar stettberger

Update to toolkit 1.1, a few code cleanups

parent 6d4c776f
......@@ -5,8 +5,8 @@ TARGET=si
SILCINCLUDE=/usr/include/silc-toolkit
SILCLIB=/usr/lib/silc-toolkit
FILES=si.c mit.c mm.c buddylist.c
CFLAGS=-I${SILCINCLUDE} -Wall -ggdb
LDFLAGS=-L${SILCLIB} -lsilc -lsilcclient -lpthread -ldl
CFLAGS=`pkg-config --cflags silcclient` -Wall -ggdb
LDFLAGS=`pkg-config --libs silcclient` -lpthread -ldl
all: ${TARGET}
......
......@@ -37,7 +37,7 @@ SILC_TASK_CALLBACK(si_handle_buddyfd_input);
void send_buddy_list(int fd);
void add_pubkey_callback(SilcClient client, SilcClientConnection conn,
SilcClientEntry *clients, SilcUInt32 clients_count,
SilcStatus status, SilcDList clients,
void *context);
void refresh_buddylist() {
......@@ -52,36 +52,37 @@ void refresh_buddylist() {
void
add_buddy(SilcClientEntry client) {
Buddy new=calloc(1, sizeof (Buddy)), tmp;
Buddy new = calloc(1, sizeof (Buddy)), tmp;
NULL_TEST(new);
new->client=client;
for (tmp=buddies; tmp; tmp=tmp->next)
if (tmp->client==client)
new->client = client;
for (tmp = buddies; tmp; tmp = tmp->next)
if (tmp->client == client)
return;
DEBUG("New Buddy on List: %s", client->nickname);
if(buddies) {
for (tmp=buddies; tmp->next; tmp=tmp->next);
tmp->next=new;
for (tmp = buddies; tmp->next; tmp = tmp->next);
tmp->next = new;
}
else
buddies=new;
buddies = new;
}
void rm_buddy(SilcClientEntry client){
Buddy del, tmp;
if (buddies && buddies->client==client){
buddies=buddies->next;
if (buddies && buddies->client == client){
buddies = buddies->next;
return;
}
for(del=buddies; del && del->next; del=del->next)
if(del->next->client==client){
tmp=del->next;
del->next=del->next->next;
for(del = buddies; del && del->next; del = del->next)
if(del->next->client == client){
tmp = del->next;
del->next = del->next->next;
free(tmp);
return;
}
}
void add_pubkey(char *pubkey) {
//FIXME
SilcBuffer attr=NULL;
SilcAttributeObjPk obj;
SilcPublicKey pk;
......@@ -98,11 +99,10 @@ void add_pubkey(char *pubkey) {
SILC_ATTRIBUTE_DEVICE_INFO, 0);
/* Load the Public Key */
if (!silc_pkcs_load_public_key(pubkey, &pk, SILC_PKCS_FILE_PEM))
if (!silc_pkcs_load_public_key(pubkey, &pk, SILC_PKCS_FILE_BIN)) {
print_out("", "-!- Couldn't load public key: %s", pubkey);
return;
}
if (!silc_pkcs_load_public_key(pubkey, &pk)) {
print_out("", "-!- Couldn't load public key: %s", pubkey);
return;
}
obj.type = "silc-rsa";
obj.data = silc_pkcs_public_key_encode(pk, &obj.data_len);
......@@ -110,42 +110,40 @@ void add_pubkey(char *pubkey) {
SILC_ATTRIBUTE_USER_PUBLIC_KEY,
SILC_ATTRIBUTE_FLAG_VALID,
&obj, sizeof(obj));
silc_client_get_clients_whois(silc_client->client,silc_client->conn,
NULL, NULL, attr, add_pubkey_callback, pubkey);
silc_client_get_clients_whois(silc_client->client, silc_client->conn,
NULL, NULL, attr, add_pubkey_callback, NULL);
/* Add a watch */
char *tmp=malloc(strlen(pubkey)+2);
sprintf(tmp, "+%s", pubkey);
silc_client_command_call(silc_client->client, silc_client->conn, NULL, "WATCH", "-add", tmp, NULL);
free(tmp);
char *tmp;
silc_asprintf(&tmp, "+%s", pubkey);
silc_client_command_call(silc_client->client, silc_client->conn, NULL,
"WATCH", "-add", tmp, NULL);
silc_free(tmp);
}
void add_pubkey_callback(SilcClient client, SilcClientConnection conn,
SilcClientEntry *clients, SilcUInt32 clients_count,
SilcStatus status, SilcDList clients,
void *context){
if (clients_count!=0) {
int i;
for (i=0; i<clients_count; i++){
add_buddy(clients[i]);
}
}
SilcClientEntry entry;
silc_dlist_start(clients);
while ((entry = (SilcClientEntry)silc_dlist_get(clients))
!= SILC_LIST_END)
add_buddy(entry);
}
void update_buddylist() {
/* Update the buddylist itself by the Pubkey's in $HOME/.silc/buddylist*/
struct dirent *entry;
char *path=malloc(strlen(getenv("HOME"))+40);
NULL_TEST(path);
sprintf(path, "%s/.silc/buddylist", (char *)getenv("HOME"));
char *path;
silc_asprintf(&path, "%s/.silc/buddylist", (char *)getenv("HOME"));
create_dirtree(path);
DIR *dir=opendir(path);
while((entry=readdir(dir))) {
if(entry->d_name[0]=='.')
continue;
char *pubkey=malloc(strlen(path)+strlen(entry->d_name)+2);
NULL_TEST(pubkey);
sprintf(pubkey, "%s/%s", path, entry->d_name);
char *pubkey;
silc_asprintf(&pubkey, "%s/%s", path, entry->d_name);
add_pubkey(pubkey);
free(pubkey);
silc_free(pubkey);
}
closedir(dir);
free(path);
......@@ -165,11 +163,10 @@ void init_buddylist() {
update_buddylist();
/* Buddyfd */
char *path=malloc(strlen(ircdir)+20);
NULL_TEST(path);
sprintf(path,"%s/buddylist", ircdir);
char *path;
silc_asprintf(&path,"%s/buddylist", ircdir);
unlink(path);
if ((buddyfd=socket(PF_UNIX, SOCK_STREAM,0))==-1) {
if ((buddyfd = socket(PF_UNIX, SOCK_STREAM,0)) == -1) {
perror("si: couldn't initalize buddy socket (socket)");
return;
}
......@@ -178,9 +175,10 @@ void init_buddylist() {
perror("si: couldn't initalize buddy socket (setsockopt)");
return;
}
strAddr.sun_family=AF_UNIX; /* Unix Domain */
strAddr.sun_family = AF_UNIX; /* Unix Domain */
strcpy(strAddr.sun_path, path);
lenAddr=sizeof(strAddr.sun_family)+strlen(strAddr.sun_path);
lenAddr = sizeof(strAddr.sun_family)+strlen(strAddr.sun_path);
silc_free(path);
if (bind(buddyfd, (struct sockaddr*)&strAddr, lenAddr) < 0) {
perror("si: couldn't initalize buddy socket (bind)");
......@@ -190,28 +188,28 @@ void init_buddylist() {
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_schedule_task_add_fd(silc_client->client->schedule, buddyfd,
si_handle_buddyfd_input, &strAddr);
}
SILC_TASK_CALLBACK(si_handle_buddyfd_input) {
int conn=0;
int conn=0;
socklen_t lenAddr;
int i;
struct sockaddr_un *addr=context;
lenAddr=sizeof(addr->sun_family)+strlen(addr->sun_path);
if((conn=accept(fd, addr, &lenAddr))<0) {
struct sockaddr_un *addr = context;
lenAddr = sizeof(addr->sun_family) + strlen(addr->sun_path);
if((conn = accept(fd, (struct sockaddr *) addr, &lenAddr))<0) {
perror("si: couldn't accept connection on buddylist");
return;
}
for(i=0; i < MAX_CONNS; i++)
if(!buddy_conns[i]){
buddy_conns[i]=conn;
buddy_conns[i] = conn;
break;
}
DEBUG("New Connection on Buddylist");
}
void si_handle_buddy_conn_input(int fd) {
int pos=0, len=1;
char buf[1], *data=malloc(len);
......
......@@ -155,7 +155,8 @@ void rm_query(Query *peer) {
}
else
for (q=queries; q; q=q->next)
if (SILC_ID_CLIENT_COMPARE(peer->silc->id, q->next->silc->id)) {
if (SILC_ID_CLIENT_COMPARE(&peer->silc->id,
&q->next->silc->id)) {
q->silc->context = NULL;
q->next=peer->next;
}
......
......@@ -211,9 +211,8 @@ static int si_open_data_fifo(char *path, char *suffix, void *context)
/* Add to scheduler */
if (fd != -1)
silc_schedule_task_add(silc_client->client->schedule, fd,
si_handle_data_input, context, 0, 0,
SILC_TASK_FD, SILC_TASK_PRI_NORMAL);
silc_schedule_task_add_fd(silc_client->client->schedule, fd,
si_handle_data_input, context);
return fd;
}
......@@ -266,15 +265,15 @@ SILC_TASK_CALLBACK(si_handle_data_input)
c = simime->context;
silc_client_send_channel_message(silc_client->client,
silc_client->conn, c->silc,
c->silc->curr_key,
SILC_MESSAGE_FLAG_DATA,
data, data_len, TRUE);
NULL, SILC_MESSAGE_FLAG_DATA,
silc_client->hash, data, data_len);
} else {
q = simime->context;
silc_client_send_private_message(silc_client->client,
silc_client->conn, q->silc,
SILC_MESSAGE_FLAG_DATA,
data, data_len, TRUE);
SILC_MESSAGE_FLAG_DATA,
silc_client->hash,
data, data_len);
}
silc_free(data);
......
This diff is collapsed.
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