comparison src/protocols/rendezvous/rendezvous.c @ 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 3e4ecbdf8d0a
children 0f7452b1f777
comparison
equal deleted inserted replaced
10548:1596ade00664 10549:8bc7ba019e96
80 80
81 /****************************/ 81 /****************************/
82 /* Buddy List Functions */ 82 /* Buddy List Functions */
83 /****************************/ 83 /****************************/
84 84
85 static RendezvousBuddy *
86 rendezvous_find_or_create_rendezvousbuddy(GaimConnection *gc, const char *name)
87 {
88 RendezvousData *rd = gc->proto_data;
89 RendezvousBuddy *rb;
90
91 rb = g_hash_table_lookup(rd->buddies, name);
92 if (rb == NULL) {
93 rb = g_malloc0(sizeof(RendezvousBuddy));
94 rb->fd = -1;
95 rb->watcher = -1;
96 g_hash_table_insert(rd->buddies, g_strdup(name), rb);
97 }
98
99 return rb;
100 }
101
85 static void 102 static void
86 rendezvous_addtolocal(GaimConnection *gc, const char *name, const char *domain) 103 rendezvous_addtolocal(GaimConnection *gc, const char *name, const char *domain)
87 { 104 {
88 GaimAccount *account = gaim_connection_get_account(gc); 105 GaimAccount *account = gaim_connection_get_account(gc);
89 GaimBuddy *b; 106 GaimBuddy *b;
98 b = gaim_find_buddy_in_group(account, name, g); 115 b = gaim_find_buddy_in_group(account, name, g);
99 if (b != NULL) 116 if (b != NULL)
100 return; 117 return;
101 118
102 b = gaim_buddy_new(account, name, NULL); 119 b = gaim_buddy_new(account, name, NULL);
120 gaim_blist_node_set_flags((GaimBlistNode *)b, GAIM_BLIST_NODE_FLAG_NO_SAVE);
103 /* gaim_blist_node_set_flag(b, GAIM_BLIST_NODE_FLAG_NO_SAVE); */ 121 /* gaim_blist_node_set_flag(b, GAIM_BLIST_NODE_FLAG_NO_SAVE); */
104 gaim_blist_add_buddy(b, NULL, g, NULL); 122 gaim_blist_add_buddy(b, NULL, g, NULL);
105 gaim_prpl_got_user_status(account, b->name, "online", NULL); 123 gaim_prpl_got_user_status(account, b->name, "online", NULL);
106 124
107 #if 0 125 #if 0
108 RendezvousBuddy *rb; 126 RendezvousBuddy *rb;
109 rb = g_hash_table_lookup(rd->buddies, name); 127 rb = rendezvous_find_or_create_rendezvousbuddy(gc, name);
110 if (rb == NULL) {
111 rb = g_malloc0(sizeof(RendezvousBuddy));
112 g_hash_table_insert(rd->buddies, g_strdup(name), rb);
113 }
114 rb->ttltimer = gaim_timeout_add(time * 10000, rendezvous_buddy_timeout, gc); 128 rb->ttltimer = gaim_timeout_add(time * 10000, rendezvous_buddy_timeout, gc);
115 129
116 gaim_timeout_remove(rb->ttltimer); 130 gaim_timeout_remove(rb->ttltimer);
117 rb->ttltimer = 0; 131 rb->ttltimer = 0;
118 #endif 132 #endif
175 } 189 }
176 190
177 static void 191 static void
178 rendezvous_handle_rr_a(GaimConnection *gc, ResourceRecord *rr, const gchar *name) 192 rendezvous_handle_rr_a(GaimConnection *gc, ResourceRecord *rr, const gchar *name)
179 { 193 {
180 RendezvousData *rd = gc->proto_data;
181 RendezvousBuddy *rb; 194 RendezvousBuddy *rb;
182 ResourceRecordRDataSRV *rdata; 195 ResourceRecordRDataSRV *rdata;
183 196
184 rdata = rr->rdata; 197 rdata = rr->rdata;
185 198
186 rb = g_hash_table_lookup(rd->buddies, name); 199 rb = rendezvous_find_or_create_rendezvousbuddy(gc, name);
187 if (rb == NULL) { 200
188 rb = g_malloc0(sizeof(RendezvousBuddy)); 201 memcpy(rb->ipv4, rdata, 4);
189 g_hash_table_insert(rd->buddies, g_strdup(name), rb);
190 }
191
192 /* rb->ipv4 = gaim_network_convert_ipv4_to_string((unsigned char *)rdata); */
193 } 202 }
194 203
195 static void 204 static void
196 rendezvous_handle_rr_txt(GaimConnection *gc, ResourceRecord *rr, const gchar *name) 205 rendezvous_handle_rr_txt(GaimConnection *gc, ResourceRecord *rr, const gchar *name)
197 { 206 {
198 RendezvousData *rd = gc->proto_data;
199 GaimAccount *account = gaim_connection_get_account(gc); 207 GaimAccount *account = gaim_connection_get_account(gc);
200 RendezvousBuddy *rb; 208 RendezvousBuddy *rb;
201 GSList *rdata; 209 GSList *rdata;
202 ResourceRecordRDataTXTNode *node1, *node2; 210 ResourceRecordRDataTXTNode *node1, *node2;
203 211
206 /* Don't do a damn thing if the version is greater than 1 */ 214 /* Don't do a damn thing if the version is greater than 1 */
207 node1 = mdns_txt_find(rdata, "version"); 215 node1 = mdns_txt_find(rdata, "version");
208 if ((node1 == NULL) || (node1->value == NULL) || (strcmp(node1->value, "1"))) 216 if ((node1 == NULL) || (node1->value == NULL) || (strcmp(node1->value, "1")))
209 return; 217 return;
210 218
211 rb = g_hash_table_lookup(rd->buddies, name); 219 rb = rendezvous_find_or_create_rendezvousbuddy(gc, name);
212 if (rb == NULL) {
213 rb = g_malloc0(sizeof(RendezvousBuddy));
214 g_hash_table_insert(rd->buddies, g_strdup(name), rb);
215 }
216 220
217 node1 = mdns_txt_find(rdata, "1st"); 221 node1 = mdns_txt_find(rdata, "1st");
218 node2 = mdns_txt_find(rdata, "last"); 222 node2 = mdns_txt_find(rdata, "last");
219 g_free(rb->firstandlast); 223 g_free(rb->firstandlast);
220 rb->firstandlast = g_strdup_printf("%s%s%s", 224 rb->firstandlast = g_strdup_printf("%s%s%s",
251 /* Time is seconds since January 1st 2001 GMT */ 255 /* Time is seconds since January 1st 2001 GMT */
252 rb->idle = atoi(node2->value); 256 rb->idle = atoi(node2->value);
253 rb->idle += 978307200; /* convert to seconds-since-epoch */ 257 rb->idle += 978307200; /* convert to seconds-since-epoch */
254 } 258 }
255 rb->status = UC_IDLE; 259 rb->status = UC_IDLE;
256 gaim_prpl_got_user_idle(account, name, TRUE, rb->idle); 260 /* TODO: Do this when the user is added to the buddy list? Definitely not here! */
261 /* gaim_prpl_got_user_idle(account, name, TRUE, rb->idle); */
257 } else if (!strcmp(node1->value, "dnd")) { 262 } else if (!strcmp(node1->value, "dnd")) {
258 /* Away */ 263 /* Away */
259 rb->status = UC_UNAVAILABLE; 264 rb->status = UC_UNAVAILABLE;
260 } 265 }
261 gaim_prpl_got_user_status(account, name, "online", NULL); 266 gaim_prpl_got_user_status(account, name, "online", NULL);
270 } 275 }
271 276
272 static void 277 static void
273 rendezvous_handle_rr_aaaa(GaimConnection *gc, ResourceRecord *rr, const gchar *name) 278 rendezvous_handle_rr_aaaa(GaimConnection *gc, ResourceRecord *rr, const gchar *name)
274 { 279 {
275 RendezvousData *rd = gc->proto_data;
276 RendezvousBuddy *rb; 280 RendezvousBuddy *rb;
277 ResourceRecordRDataSRV *rdata; 281 ResourceRecordRDataSRV *rdata;
278 282
279 rdata = rr->rdata; 283 rdata = rr->rdata;
280 284
281 rb = g_hash_table_lookup(rd->buddies, name); 285 rb = rendezvous_find_or_create_rendezvousbuddy(gc, name);
282 if (rb == NULL) { 286
283 rb = g_malloc0(sizeof(RendezvousBuddy)); 287 memcpy(rb->ipv6, rdata, 16);
284 g_hash_table_insert(rd->buddies, g_strdup(name), rb);
285 }
286
287 /* rb->ip = gaim_network_convert_ipv6_to_string((unsigned char *)rdata); */
288 } 288 }
289 289
290 static void 290 static void
291 rendezvous_handle_rr_srv(GaimConnection *gc, ResourceRecord *rr, const gchar *name) 291 rendezvous_handle_rr_srv(GaimConnection *gc, ResourceRecord *rr, const gchar *name)
292 { 292 {
293 RendezvousData *rd = gc->proto_data;
294 RendezvousBuddy *rb; 293 RendezvousBuddy *rb;
295 ResourceRecordRDataSRV *rdata; 294 ResourceRecordRDataSRV *rdata;
296 295
297 rdata = rr->rdata; 296 rdata = rr->rdata;
298 297
299 rb = g_hash_table_lookup(rd->buddies, name); 298 rb = rendezvous_find_or_create_rendezvousbuddy(gc, name);
300 if (rb == NULL) {
301 rb = g_malloc0(sizeof(RendezvousBuddy));
302 g_hash_table_insert(rd->buddies, g_strdup(name), rb);
303 }
304 299
305 rb->p2pjport = rdata->port; 300 rb->p2pjport = rdata->port;
306 } 301 }
307 302
308 /* 303 /*
442 } 437 }
443 438
444 return g_string_free(ret, FALSE); 439 return g_string_free(ret, FALSE);
445 } 440 }
446 441
442 static GList *
443 rendezvous_prpl_status_types(GaimAccount *account)
444 {
445 GList *status_types = NULL;
446 GaimStatusType *type;
447
448 type = gaim_status_type_new_full(GAIM_STATUS_OFFLINE, "offline", _("Offline"), FALSE, TRUE, FALSE);
449 status_types = g_list_append(status_types, type);
450
451 type = gaim_status_type_new_full(GAIM_STATUS_ONLINE, "online", _("Online"), FALSE, TRUE, FALSE);
452 status_types = g_list_append(status_types, type);
453
454 return status_types;
455 }
456
447 /****************************/ 457 /****************************/
448 /* Connection Functions */ 458 /* Connection Functions */
449 /****************************/ 459 /****************************/
450 static void 460 static void
451 rendezvous_callback(gpointer data, gint source, GaimInputCondition condition) 461 rendezvous_callback(gpointer data, gint source, GaimInputCondition condition)
554 static void 564 static void
555 rendezvous_send_online(GaimConnection *gc) 565 rendezvous_send_online(GaimConnection *gc)
556 { 566 {
557 RendezvousData *rd = gc->proto_data; 567 RendezvousData *rd = gc->proto_data;
558 GaimAccount *account = gaim_connection_get_account(gc); 568 GaimAccount *account = gaim_connection_get_account(gc);
559 const gchar *me; 569 const gchar *me, *myip;
560 gchar *myname, *mycomp, *myport; 570 gchar *myname, *mycomp, *myport;
571 gchar **mysplitip;
561 unsigned char myipv4[4]; 572 unsigned char myipv4[4];
562 573
563 me = gaim_account_get_username(account); 574 me = gaim_account_get_username(account);
564 myname = g_strdup_printf("%s._presence._tcp.local", me); 575 myname = g_strdup_printf("%s._presence._tcp.local", me);
565 mycomp = g_strdup_printf("%s.local", strchr(me, '@') + 1); 576 mycomp = g_strdup_printf("%s.local", strchr(me, '@') + 1);
566 /* myipv4 = gaim_network_ip_atoi(gaim_network_get_local_system_ip(-1)); */
567 myipv4[0] = 192;
568 myipv4[1] = 168;
569 myipv4[2] = 1;
570 myipv4[3] = 41;
571 myport = g_strdup_printf("%d", rd->listener_port); 577 myport = g_strdup_printf("%d", rd->listener_port);
578
579 myip = gaim_network_get_local_system_ip(-1);
580 mysplitip = g_strsplit(myip, ".", 0);
581 myipv4[0] = atoi(mysplitip[0]);
582 myipv4[1] = atoi(mysplitip[1]);
583 myipv4[2] = atoi(mysplitip[2]);
584 myipv4[3] = atoi(mysplitip[3]);
585 g_strfreev(mysplitip);
572 586
573 mdns_advertise_a(rd->fd, mycomp, myipv4); 587 mdns_advertise_a(rd->fd, mycomp, myipv4);
574 mdns_advertise_ptr(rd->fd, "_presence._tcp.local", myname); 588 mdns_advertise_ptr(rd->fd, "_presence._tcp.local", myname);
575 mdns_advertise_srv(rd->fd, myname, rd->listener_port, mycomp); 589 mdns_advertise_srv(rd->fd, myname, rd->listener_port, mycomp);
576 590
675 } 689 }
676 690
677 static int 691 static int
678 rendezvous_prpl_send_im(GaimConnection *gc, const char *who, const char *message, GaimConvImFlags flags) 692 rendezvous_prpl_send_im(GaimConnection *gc, const char *who, const char *message, GaimConvImFlags flags)
679 { 693 {
694 RendezvousData *rd = gc->proto_data;
695 RendezvousBuddy *rb;
696
680 gaim_debug_info("rendezvous", "Sending IM\n"); 697 gaim_debug_info("rendezvous", "Sending IM\n");
698
699 rb = g_hash_table_lookup(rd->buddies, who);
700 if (rb == NULL) {
701 /* TODO: Should print an error to the user, here */
702 gaim_debug_error("rendezvous", "Could not send message to %s: Could not find user information.\n", who);
703 }
704
705 /* TODO: Establish a direct connection then send IM. Will need to queue the message somewhere. */
681 706
682 return 1; 707 return 1;
683 } 708 }
684 709
685 static void 710 static void
738 prpl_info.icon_spec.scale_rules = 0; 763 prpl_info.icon_spec.scale_rules = 0;
739 prpl_info.list_icon = rendezvous_prpl_list_icon; 764 prpl_info.list_icon = rendezvous_prpl_list_icon;
740 prpl_info.list_emblems = rendezvous_prpl_list_emblems; 765 prpl_info.list_emblems = rendezvous_prpl_list_emblems;
741 prpl_info.status_text = rendezvous_prpl_status_text; 766 prpl_info.status_text = rendezvous_prpl_status_text;
742 prpl_info.tooltip_text = rendezvous_prpl_tooltip_text; 767 prpl_info.tooltip_text = rendezvous_prpl_tooltip_text;
768 prpl_info.status_types = rendezvous_prpl_status_types;
743 prpl_info.login = rendezvous_prpl_login; 769 prpl_info.login = rendezvous_prpl_login;
744 prpl_info.close = rendezvous_prpl_close; 770 prpl_info.close = rendezvous_prpl_close;
745 prpl_info.send_im = rendezvous_prpl_send_im; 771 prpl_info.send_im = rendezvous_prpl_send_im;
746 prpl_info.set_status = rendezvous_prpl_set_status; 772 prpl_info.set_status = rendezvous_prpl_set_status;
747 773