Update of /cvsroot/gaim/gaim/src/protocols/rendezvous
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1650
Modified Files:
Makefile.am Makefile.mingw direct.c mdns.c rendezvous.c
rendezvous.h
Log Message:
This should make rendezvous compile again. It's back to being able
to somewhat sign on and see other people. Still nowhere near being
able to message.
I think I want to work on messaging, then maybe come back and look
into using a third party lib or maybe just an external mDNS server
for presence.
Index: Makefile.am
===================================================================
RCS file: /cvsroot/gaim/gaim/src/protocols/rendezvous/Makefile.am,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -p -r1.3 -r1.4
--- Makefile.am 10 Jun 2004 02:10:43 -0000 1.3
+++ Makefile.am 27 Jan 2005 05:28:07 -0000 1.4
@@ -4,6 +4,8 @@ EXTRA_DIST = \
pkgdir = $(libdir)/gaim
RENDEZVOUSSOURCES = \
+ direct.c \
+ direct.h \
mdns.c \
mdns.h \
mdns_cache.c \
Index: Makefile.mingw
===================================================================
RCS file: /cvsroot/gaim/gaim/src/protocols/rendezvous/Makefile.mingw,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -p -r1.2 -r1.3
--- Makefile.mingw 21 Apr 2004 03:37:30 -0000 1.2
+++ Makefile.mingw 27 Jan 2005 05:28:08 -0000 1.3
@@ -68,7 +68,8 @@ LIB_PATHS = -L$(GTK_TOP)/lib \
## SOURCES, OBJECTS
##
-C_SRC = mdns.c \
+C_SRC = direct.c \
+ mdns.c \
mdns_cache.c \
rendezvous.c
Index: direct.c
===================================================================
RCS file: /cvsroot/gaim/gaim/src/protocols/rendezvous/direct.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -p -r1.1 -r1.2
--- direct.c 5 Dec 2004 21:25:44 -0000 1.1
+++ direct.c 27 Jan 2005 05:28:08 -0000 1.2
@@ -27,7 +27,7 @@
#include "direct.h"
#include "rendezvous.h"
-/*
+#if 0
gchar *
gaim_network_convert_ipv4_to_string(void *ip)
{
@@ -50,27 +50,31 @@ gaim_network_convert_ipv6_to_string(void
return ret;
}
-*/
-static gboolean rendezvous_find_buddy_by_ip(gpointer key, gpointer value, gpointer user_data)
+static gboolean
+rendezvous_find_buddy_by_ip(gpointer key, gpointer value, gpointer user_data)
{
RendezvousBuddy *rb = value;
-printf("looking at ip=%s\n", rb->ip);
- if ((rb->ip != NULL) && !strcasecmp(rb->ip, user_data))
- return TRUE;
+ if (rb->ipv4 == NULL)
+ return FALSE;
- return FALSE;
+printf("looking at ip=%hu.%hu.%hu.%hu\n", rb->ipv4[0], rb->ipv4[1], rb->ipv4[2], rb->ipv4[3]);
+ return !memcmp(rb->ipv4, user_data, 4);
}
+#endif
-void rendezvous_direct_acceptconnection(gpointer data, gint source, GaimInputCondition condition)
+void
+rendezvous_direct_acceptconnection(gpointer data, gint source, GaimInputCondition condition)
{
GaimConnection *gc = (GaimConnection *)data;
RendezvousData *rd = gc->proto_data;
int fd;
struct sockaddr_in6 addr;
socklen_t addrlen = sizeof(addr);
+#if 0
gchar *ip;
+#endif
RendezvousBuddy *rb;
fd = accept(rd->listener, (struct sockaddr *)&addr, &addrlen);
@@ -78,7 +82,8 @@ void rendezvous_direct_acceptconnection(
gaim_debug_warning("rendezvous", "accept: %s\n", strerror(errno));
return;
}
-/*
+
+#if 0
printf("\nsa_family=%d\n\n", ((struct sockaddr *)&addr)->sa_family);
if (((struct sockaddr *)&addr)->sa_family == AF_INET)
ip = gaim_network_convert_ipv4_to_string((unsigned char *)&ip);
@@ -88,7 +93,8 @@ void rendezvous_direct_acceptconnection(
rb = g_hash_table_find(rd->buddies, rendezvous_find_buddy_by_ip, ip);
g_free(ip);
-*/
+#endif
+
if (rb == NULL) {
/* We don't want to talk to people that don't advertise themselves */
printf("\ndid not find rb\n\n");
@@ -98,5 +104,4 @@ printf("\ndid not find rb\n\n");
printf("\nip belongs to=%s\n\n", rb->aim);
rb->fd = fd;
-
}
Index: mdns.c
===================================================================
RCS file: /cvsroot/gaim/gaim/src/protocols/rendezvous/mdns.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -p -r1.19 -r1.20
--- mdns.c 5 Dec 2004 21:25:44 -0000 1.19
+++ mdns.c 27 Jan 2005 05:28:08 -0000 1.20
@@ -277,7 +277,6 @@ mdns_copy_rr_rdata(unsigned short type,
return ret;
}
-#if 0
ResourceRecord *
mdns_copy_rr(const ResourceRecord *rr)
{
@@ -297,6 +296,7 @@ mdns_copy_rr(const ResourceRecord *rr)
return ret;
}
+#if 0
static GSList *
mdns_copy_rrs(const GSList *rrs)
{
@@ -367,6 +367,7 @@ mdns_socket_establish()
addr.sin_addr.s_addr = INADDR_ANY;
if (bind(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)) < 0) {
gaim_debug_error("mdns", "Unable to bind socket to interface.\n");
+ gaim_debug_error("mdns", "%s\n", strerror(errno));
close(fd);
return -1;
}
Index: rendezvous.c
===================================================================
RCS file: /cvsroot/gaim/gaim/src/protocols/rendezvous/rendezvous.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -p -r1.38 -r1.39
--- rendezvous.c 21 Dec 2004 01:48:27 -0000 1.38
+++ rendezvous.c 27 Jan 2005 05:28:08 -0000 1.39
@@ -82,6 +82,23 @@ rendezvous_extract_name(gchar *domain)
/* Buddy List Functions */
/****************************/
+static RendezvousBuddy *
+rendezvous_find_or_create_rendezvousbuddy(GaimConnection *gc, const char *name)
+{
+ RendezvousData *rd = gc->proto_data;
+ RendezvousBuddy *rb;
+
+ rb = g_hash_table_lookup(rd->buddies, name);
+ if (rb == NULL) {
+ rb = g_malloc0(sizeof(RendezvousBuddy));
+ rb->fd = -1;
+ rb->watcher = -1;
+ g_hash_table_insert(rd->buddies, g_strdup(name), rb);
+ }
+
+ return rb;
+}
+
static void
rendezvous_addtolocal(GaimConnection *gc, const char *name, const char *domain)
{
@@ -100,17 +117,14 @@ rendezvous_addtolocal(GaimConnection *gc
return;
b = gaim_buddy_new(account, name, NULL);
+ gaim_blist_node_set_flags((GaimBlistNode *)b, GAIM_BLIST_NODE_FLAG_NO_SAVE);
/* gaim_blist_node_set_flag(b, GAIM_BLIST_NODE_FLAG_NO_SAVE); */
gaim_blist_add_buddy(b, NULL, g, NULL);
gaim_prpl_got_user_status(account, b->name, "online", NULL);
#if 0
RendezvousBuddy *rb;
- rb = g_hash_table_lookup(rd->buddies, name);
- if (rb == NULL) {
- rb = g_malloc0(sizeof(RendezvousBuddy));
- g_hash_table_insert(rd->buddies, g_strdup(name), rb);
- }
+ rb = rendezvous_find_or_create_rendezvousbuddy(gc, name);
rb->ttltimer = gaim_timeout_add(time * 10000, rendezvous_buddy_timeout, gc);
gaim_timeout_remove(rb->ttltimer);
@@ -177,25 +191,19 @@ rendezvous_removeallfromlocal(GaimConnec
static void
rendezvous_handle_rr_a(GaimConnection *gc, ResourceRecord *rr, const gchar *name)
{
- RendezvousData *rd = gc->proto_data;
RendezvousBuddy *rb;
ResourceRecordRDataSRV *rdata;
rdata = rr->rdata;
- rb = g_hash_table_lookup(rd->buddies, name);
- if (rb == NULL) {
- rb = g_malloc0(sizeof(RendezvousBuddy));
- g_hash_table_insert(rd->buddies, g_strdup(name), rb);
- }
+ rb = rendezvous_find_or_create_rendezvousbuddy(gc, name);
- /* rb->ipv4 = gaim_network_convert_ipv4_to_string((unsigned char *)rdata); */
+ memcpy(rb->ipv4, rdata, 4);
}
static void
rendezvous_handle_rr_txt(GaimConnection *gc, ResourceRecord *rr, const gchar *name)
{
- RendezvousData *rd = gc->proto_data;
GaimAccount *account = gaim_connection_get_account(gc);
RendezvousBuddy *rb;
GSList *rdata;
@@ -208,11 +216,7 @@ rendezvous_handle_rr_txt(GaimConnection
if ((node1 == NULL) || (node1->value == NULL) || (strcmp(node1->value, "1")))
return;
- rb = g_hash_table_lookup(rd->buddies, name);
- if (rb == NULL) {
- rb = g_malloc0(sizeof(RendezvousBuddy));
- g_hash_table_insert(rd->buddies, g_strdup(name), rb);
- }
+ rb = rendezvous_find_or_create_rendezvousbuddy(gc, name);
node1 = mdns_txt_find(rdata, "1st");
node2 = mdns_txt_find(rdata, "last");
@@ -253,7 +257,8 @@ rendezvous_handle_rr_txt(GaimConnection
rb->idle += 978307200; /* convert to seconds-since-epoch */
}
rb->status = UC_IDLE;
- gaim_prpl_got_user_idle(account, name, TRUE, rb->idle);
+ /* TODO: Do this when the user is added to the buddy list? Definitely not here! */
+ /* gaim_prpl_got_user_idle(account, name, TRUE, rb->idle); */
} else if (!strcmp(node1->value, "dnd")) {
/* Away */
rb->status = UC_UNAVAILABLE;
@@ -272,35 +277,25 @@ rendezvous_handle_rr_txt(GaimConnection
static void
rendezvous_handle_rr_aaaa(GaimConnection *gc, ResourceRecord *rr, const gchar *name)
{
- RendezvousData *rd = gc->proto_data;
RendezvousBuddy *rb;
ResourceRecordRDataSRV *rdata;
rdata = rr->rdata;
- rb = g_hash_table_lookup(rd->buddies, name);
- if (rb == NULL) {
- rb = g_malloc0(sizeof(RendezvousBuddy));
- g_hash_table_insert(rd->buddies, g_strdup(name), rb);
- }
+ rb = rendezvous_find_or_create_rendezvousbuddy(gc, name);
- /* rb->ip = gaim_network_convert_ipv6_to_string((unsigned char *)rdata); */
+ memcpy(rb->ipv6, rdata, 16);
}
static void
rendezvous_handle_rr_srv(GaimConnection *gc, ResourceRecord *rr, const gchar *name)
{
- RendezvousData *rd = gc->proto_data;
RendezvousBuddy *rb;
ResourceRecordRDataSRV *rdata;
rdata = rr->rdata;
- rb = g_hash_table_lookup(rd->buddies, name);
- if (rb == NULL) {
- rb = g_malloc0(sizeof(RendezvousBuddy));
- g_hash_table_insert(rd->buddies, g_strdup(name), rb);
- }
+ rb = rendezvous_find_or_create_rendezvousbuddy(gc, name);
rb->p2pjport = rdata->port;
}
@@ -444,6 +439,21 @@ rendezvous_prpl_tooltip_text(GaimBuddy *
return g_string_free(ret, FALSE);
}
+static GList *
+rendezvous_prpl_status_types(GaimAccount *account)
+{
+ GList *status_types = NULL;
+ GaimStatusType *type;
+
+ type = gaim_status_type_new_full(GAIM_STATUS_OFFLINE, "offline", _("Offline"), FALSE, TRUE, FALSE);
+ status_types = g_list_append(status_types, type);
+
+ type = gaim_status_type_new_full(GAIM_STATUS_ONLINE, "online", _("Online"), FALSE, TRUE, FALSE);
+ status_types = g_list_append(status_types, type);
+
+ return status_types;
+}
+
/****************************/
/* Connection Functions */
/****************************/
@@ -556,20 +566,24 @@ rendezvous_send_online(GaimConnection *g
{
RendezvousData *rd = gc->proto_data;
GaimAccount *account = gaim_connection_get_account(gc);
- const gchar *me;
+ const gchar *me, *myip;
gchar *myname, *mycomp, *myport;
+ gchar **mysplitip;
unsigned char myipv4[4];
me = gaim_account_get_username(account);
myname = g_strdup_printf("%s._presence._tcp.local", me);
mycomp = g_strdup_printf("%s.local", strchr(me, '@') + 1);
- /* myipv4 = gaim_network_ip_atoi(gaim_network_get_local_system_ip(-1)); */
- myipv4[0] = 192;
- myipv4[1] = 168;
- myipv4[2] = 1;
- myipv4[3] = 41;
myport = g_strdup_printf("%d", rd->listener_port);
+ myip = gaim_network_get_local_system_ip(-1);
+ mysplitip = g_strsplit(myip, ".", 0);
+ myipv4[0] = atoi(mysplitip[0]);
+ myipv4[1] = atoi(mysplitip[1]);
+ myipv4[2] = atoi(mysplitip[2]);
+ myipv4[3] = atoi(mysplitip[3]);
+ g_strfreev(mysplitip);
+
mdns_advertise_a(rd->fd, mycomp, myipv4);
mdns_advertise_ptr(rd->fd, "_presence._tcp.local", myname);
mdns_advertise_srv(rd->fd, myname, rd->listener_port, mycomp);
@@ -677,8 +691,19 @@ rendezvous_prpl_close(GaimConnection *gc
static int
rendezvous_prpl_send_im(GaimConnection *gc, const char *who, const char *message, GaimConvImFlags flags)
{
+ RendezvousData *rd = gc->proto_data;
+ RendezvousBuddy *rb;
+
gaim_debug_info("rendezvous", "Sending IM\n");
+ rb = g_hash_table_lookup(rd->buddies, who);
+ if (rb == NULL) {
+ /* TODO: Should print an error to the user, here */
+ gaim_debug_error("rendezvous", "Could not send message to %s: Could not find user information.\n", who);
+ }
+
+ /* TODO: Establish a direct connection then send IM. Will need to queue the message somewhere. */
+
return 1;
}
@@ -740,6 +765,7 @@ static void init_plugin(GaimPlugin *plug
prpl_info.list_emblems = rendezvous_prpl_list_emblems;
prpl_info.status_text = rendezvous_prpl_status_text;
prpl_info.tooltip_text = rendezvous_prpl_tooltip_text;
+ prpl_info.status_types = rendezvous_prpl_status_types;
prpl_info.login = rendezvous_prpl_login;
prpl_info.close = rendezvous_prpl_close;
prpl_info.send_im = rendezvous_prpl_send_im;
Index: rendezvous.h
===================================================================
RCS file: /cvsroot/gaim/gaim/src/protocols/rendezvous/rendezvous.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -p -r1.1 -r1.2
--- rendezvous.h 5 Dec 2004 21:25:44 -0000 1.1
+++ rendezvous.h 27 Jan 2005 05:28:08 -0000 1.2
@@ -51,14 +51,14 @@ typedef struct _RendezvousBuddy {
#endif
gchar *firstandlast;
gchar *aim;
- gchar *ipv4; /* String representation of an IPv4 address */
- gchar *ipv6; /* String representation of an IPv6 address */
+ unsigned char ipv4[4]; /**< An IPv4 address */
+ unsigned char ipv6[16]; /**< An IPv6 address */
unsigned short p2pjport;
int status;
- int idle; /**< Current idle time in seconds since the epoch. */
- gchar *msg; /**< Current status message of this buddy. */
- int fd; /**< File descriptor of the P2PJ socket. */
- int watcher; /**< Handle for the watcher of the P2PJ socket. */
+ int idle; /**< Current idle time in seconds since the epoch. */
+ gchar *msg; /**< Current status message of this buddy. */
+ int fd; /**< File descriptor of the P2PJ socket. */
+ int watcher; /**< Handle for the watcher of the P2PJ socket. */
} RendezvousBuddy;
#endif /* _RENDEZVOUS_H_ */
|