Mercurial > pidgin
changeset 10549:8bc7ba019e96
[gaim-migrate @ 11919]
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.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Thu, 27 Jan 2005 05:28:08 +0000 |
parents | 1596ade00664 |
children | 522cd02f235f |
files | src/protocols/rendezvous/Makefile.am src/protocols/rendezvous/Makefile.mingw src/protocols/rendezvous/direct.c src/protocols/rendezvous/mdns.c src/protocols/rendezvous/rendezvous.c src/protocols/rendezvous/rendezvous.h |
diffstat | 6 files changed, 92 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/src/protocols/rendezvous/Makefile.am Thu Jan 27 05:24:26 2005 +0000 +++ b/src/protocols/rendezvous/Makefile.am Thu Jan 27 05:28:08 2005 +0000 @@ -4,6 +4,8 @@ pkgdir = $(libdir)/gaim RENDEZVOUSSOURCES = \ + direct.c \ + direct.h \ mdns.c \ mdns.h \ mdns_cache.c \
--- a/src/protocols/rendezvous/Makefile.mingw Thu Jan 27 05:24:26 2005 +0000 +++ b/src/protocols/rendezvous/Makefile.mingw Thu Jan 27 05:28:08 2005 +0000 @@ -68,7 +68,8 @@ ## SOURCES, OBJECTS ## -C_SRC = mdns.c \ +C_SRC = direct.c \ + mdns.c \ mdns_cache.c \ rendezvous.c
--- a/src/protocols/rendezvous/direct.c Thu Jan 27 05:24:26 2005 +0000 +++ b/src/protocols/rendezvous/direct.c Thu Jan 27 05:28:08 2005 +0000 @@ -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 @@ 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 @@ 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 @@ 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("\nip belongs to=%s\n\n", rb->aim); rb->fd = fd; - }
--- a/src/protocols/rendezvous/mdns.c Thu Jan 27 05:24:26 2005 +0000 +++ b/src/protocols/rendezvous/mdns.c Thu Jan 27 05:28:08 2005 +0000 @@ -277,7 +277,6 @@ return ret; } -#if 0 ResourceRecord * mdns_copy_rr(const ResourceRecord *rr) { @@ -297,6 +296,7 @@ return ret; } +#if 0 static GSList * mdns_copy_rrs(const GSList *rrs) { @@ -367,6 +367,7 @@ 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; }
--- a/src/protocols/rendezvous/rendezvous.c Thu Jan 27 05:24:26 2005 +0000 +++ b/src/protocols/rendezvous/rendezvous.c Thu Jan 27 05:28:08 2005 +0000 @@ -82,6 +82,23 @@ /* 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ { 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 @@ 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 @@ 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;
--- a/src/protocols/rendezvous/rendezvous.h Thu Jan 27 05:24:26 2005 +0000 +++ b/src/protocols/rendezvous/rendezvous.h Thu Jan 27 05:28:08 2005 +0000 @@ -51,14 +51,14 @@ #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_ */