aboutsummaryrefslogtreecommitdiffstats
path: root/lib/url.h
blob: e9e1ecfe3876ee57dfffa1191850c22b53ffecee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  /********************************************************************\
  * BitlBee -- An IRC to other IM-networks gateway                     *
  *                                                                    *
  * Copyright 2001-2004 Wilmer van der Gaast and others                *
  \********************************************************************/

/* URL/mirror stuff - Stolen from Axel                                  */

/*
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License with
  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
  if not, write to the Free Software Foundation, Inc., 59 Temple Place,
  Suite 330, Boston, MA  02111-1307  USA
*/

#include "bitlbee.h"

#define PROTO_HTTP		2
#define PROTO_HTTPS		5
#define PROTO_SOCKS4	3
#define PROTO_SOCKS5	4
#define PROTO_DEFAULT	PROTO_HTTP

typedef struct url
{
	int proto;
	int port;
	char host[MAX_STRING];
	char file[MAX_STRING];
	char user[MAX_STRING];
	char pass[MAX_STRING];
} url_t;

int url_set( url_t *url, char *set_url );
='#n318'>318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955
/*
 * libyahoo2 wrapper to BitlBee
 *
 * Mostly Copyright 2004 Wilmer van der Gaast <wilmer@gaast.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <sys/stat.h>
#include <ctype.h>
#include "nogaim.h"
#include "yahoo2.h"
#include "yahoo2_callbacks.h"

#define BYAHOO_DEFAULT_GROUP "Buddies"

/* A hack to handle removal of buddies not in the group "Buddies" correctly */
struct byahoo_buddygroups
{
	char *buddy;
	char *group;
};

struct byahoo_data
{
	int y2_id;
	int current_status;
	gboolean logged_in;
	GSList *buddygroups;
};

struct byahoo_input_data
{
	int h;
	void *d;
};

struct byahoo_conf_invitation
{
	char *name;
	struct conversation *c;
	int yid;
	YList *members;
	struct gaim_connection *gc;
};

static char *yahoo_name()
{
	return "Yahoo";
}

static struct prpl *my_protocol = NULL;
static GSList *byahoo_inputs = NULL;
static int byahoo_chat_id = 0;

static char *byahoo_strip( char *in )
{
	int len;
	
	/* This should get rid of HTML tags at the beginning of the string. */
	while( *in )
	{
		if( g_strncasecmp( in, "<font", 5 ) == 0 ||
		    g_strncasecmp( in, "<fade", 5 ) == 0 ||
		    g_strncasecmp( in, "<alt", 4 ) == 0 )
		{
			char *s = strchr( in, '>' );
			if( !s )
				break;
			
			in = s + 1;
		}
		else if( strncmp( in, "\e[", 2 ) == 0 )
		{
			char *s;
			
			for( s = in + 2; *s && *s != 'm'; s ++ );
			
			if( *s != 'm' )
				break;
			
			in = s + 1;
		}
		else
		{
			break;
		}
	}
	
	/* This is supposed to get rid of the closing HTML tags at the end of the line. */
	len = strlen( in );
	while( len > 0 && in[len-1] == '>' )
	{
		int blen = len;
		
		len --;
		while( len > 0 && ( in[len] != '<' || in[len+1] != '/' ) )
			len --;
		
		if( len == 0 && ( in[len] != '<' || in[len+1] != '/' ) )
		{
			len = blen;
			break;
		}
	}
	
	return( g_strndup( in, len ) );
}

static void byahoo_login( struct aim_user *user )
{
	struct gaim_connection *gc = new_gaim_conn( user );
	struct byahoo_data *yd = gc->proto_data = g_new0( struct byahoo_data, 1 );
	
	yd->logged_in = FALSE;
	yd->current_status = YAHOO_STATUS_AVAILABLE;
	
	set_login_progress( gc, 1, "Connecting" );
	yd->y2_id = yahoo_init( user->username, user->password );
	yahoo_login( yd->y2_id, yd->current_status );
}

static void byahoo_close( struct gaim_connection *gc )
{
	struct byahoo_data *yd = (struct byahoo_data *) gc->proto_data;
	GSList *l;
	
	while( gc->conversations )
		serv_got_chat_left( gc, gc->conversations->id );
	
	for( l = yd->buddygroups; l; l = l->next )
	{
		struct byahoo_buddygroups *bg = l->data;
		
		g_free( bg->buddy );
		g_free( bg->group );
		g_free( bg );
	}
	g_slist_free( yd->buddygroups );
	
	if( yd->logged_in )
		yahoo_logoff( yd->y2_id );
	else
		yahoo_close( yd->y2_id );
	
	g_free( yd );
}

static void byahoo_get_info(struct gaim_connection *gc, char *who) 
{
	/* Just make an URL and let the user fetch the info */
	serv_got_crap(gc, "%s\n%s: %s%s", _("User Info"), 
			_("For now, fetch yourself"), yahoo_get_profile_url(),
			who);
}

static int byahoo_send_im( struct gaim_connection *gc, char *who, char *what, int len, int flags )
{
	struct byahoo_data *yd = gc->proto_data;
	
	yahoo_send_im( yd->y2_id, NULL, who, what, 1 );
	
	return 1;
}

static int byahoo_send_typing( struct gaim_connection *gc, char *who, int typing )
{
	struct byahoo_data *yd = gc->proto_data;
	
	yahoo_send_typing( yd->y2_id, NULL, who, typing );
	
	return 1;
}

static void byahoo_set_away( struct gaim_connection *gc, char *state, char *msg )
{
	struct byahoo_data *yd = (struct byahoo_data *) gc->proto_data;

	gc->away = NULL;

	if (msg)
	{
		yd->current_status = YAHOO_STATUS_CUSTOM;
		gc->away = "";
	}
	else if (state)
	{
		gc->away = "";
		if( g_strcasecmp(state, "Available" ) == 0 )
		{
			yd->current_status = YAHOO_STATUS_AVAILABLE;
			gc->away = NULL;
		}
		else if( g_strcasecmp( state, "Be Right Back" ) == 0 )
			yd->current_status = YAHOO_STATUS_BRB;
		else if( g_strcasecmp( state, "Busy" ) == 0 )
			yd->current_status = YAHOO_STATUS_BUSY;
		else if( g_strcasecmp( state, "Not At Home" ) == 0 )
			yd->current_status = YAHOO_STATUS_NOTATHOME;
		else if( g_strcasecmp( state, "Not At Desk" ) == 0 )
			yd->current_status = YAHOO_STATUS_NOTATDESK;
		else if( g_strcasecmp( state, "Not In Office" ) == 0 )
			yd->current_status = YAHOO_STATUS_NOTINOFFICE;
		else if( g_strcasecmp( state, "On Phone" ) == 0 )
			yd->current_status = YAHOO_STATUS_ONPHONE;
		else if( g_strcasecmp( state, "On Vacation" ) == 0 )
			yd->current_status = YAHOO_STATUS_ONVACATION;
		else if( g_strcasecmp( state, "Out To Lunch" ) == 0 )
			yd->current_status = YAHOO_STATUS_OUTTOLUNCH;
		else if( g_strcasecmp( state, "Stepped Out" ) == 0 )
			yd->current_status = YAHOO_STATUS_STEPPEDOUT;
		else if( g_strcasecmp( state, "Invisible" ) == 0 )
			yd->current_status = YAHOO_STATUS_INVISIBLE;
		else if( g_strcasecmp( state, GAIM_AWAY_CUSTOM ) == 0 )
		{
			if (gc->is_idle)
				yd->current_status = YAHOO_STATUS_IDLE;
			else
				yd->current_status = YAHOO_STATUS_AVAILABLE;
			
			gc->away = NULL;
		}
	}
	else if ( gc->is_idle )
		yd->current_status = YAHOO_STATUS_IDLE;
	else
		yd->current_status = YAHOO_STATUS_AVAILABLE;
	
	yahoo_set_away( yd->y2_id, yd->current_status, msg, gc->away != NULL );
}

static GList *byahoo_away_states( struct gaim_connection *gc )
{
	GList *m = NULL;

	m = g_list_append( m, "Available" );
	m = g_list_append( m, "Be Right Back" );
	m = g_list_append( m, "Busy" );
	m = g_list_append( m, "Not At Home" );
	m = g_list_append( m, "Not At Desk" );
	m = g_list_append( m, "Not In Office" );
	m = g_list_append( m, "On Phone" );
	m = g_list_append( m, "On Vacation" );
	m = g_list_append( m, "Out To Lunch" );
	m = g_list_append( m, "Stepped Out" );
	m = g_list_append( m, "Invisible" );
	m = g_list_append( m, GAIM_AWAY_CUSTOM );
	
	return m;
}

static void byahoo_keepalive( struct gaim_connection *gc )
{
	struct byahoo_data *yd = gc->proto_data;
	
	yahoo_keepalive( yd->y2_id );
}

static void byahoo_add_buddy( struct gaim_connection *gc, char *who )
{
	struct byahoo_data *yd = (struct byahoo_data *) gc->proto_data;
	
	yahoo_add_buddy( yd->y2_id, who, BYAHOO_DEFAULT_GROUP );
}

static void byahoo_remove_buddy( struct gaim_connection *gc, char *who, char *group )
{
	struct byahoo_data *yd = (struct byahoo_data *) gc->proto_data;
	GSList *bgl;
	
	yahoo_remove_buddy( yd->y2_id, who, BYAHOO_DEFAULT_GROUP );
	
	for( bgl = yd->buddygroups; bgl; bgl = bgl->next )
	{
		struct byahoo_buddygroups *bg = bgl->data;
		
		if( g_strcasecmp( bg->buddy, who ) == 0 )
			yahoo_remove_buddy( yd->y2_id, who, bg->group );
	}
}

static char *byahoo_get_status_string( struct gaim_connection *gc, int stat )
{
	enum yahoo_status a = stat >> 1;
	
	switch (a)
	{
	case YAHOO_STATUS_BRB:
		return "Be Right Back";
	case YAHOO_STATUS_BUSY:
		return "Busy";
	case YAHOO_STATUS_NOTATHOME:
		return "Not At Home";
	case YAHOO_STATUS_NOTATDESK:
		return "Not At Desk";
	case YAHOO_STATUS_NOTINOFFICE:
		return "Not In Office";
	case YAHOO_STATUS_ONPHONE:
		return "On Phone";
	case YAHOO_STATUS_ONVACATION:
		return "On Vacation";
	case YAHOO_STATUS_OUTTOLUNCH:
		return "Out To Lunch";
	case YAHOO_STATUS_STEPPEDOUT:
		return "Stepped Out";
	case YAHOO_STATUS_INVISIBLE:
		return "Invisible";
	case YAHOO_STATUS_CUSTOM:
		return "Away";
	case YAHOO_STATUS_IDLE:
		return "Idle";
	case YAHOO_STATUS_OFFLINE:
		return "Offline";
	case YAHOO_STATUS_NOTIFY:
		return "Notify";
	default:
		return "Away";
	}
}

static int byahoo_chat_send( struct gaim_connection *gc, int id, char *message )
{
	struct byahoo_data *yd = (struct byahoo_data *) gc->proto_data;
	struct conversation *c;
	
	for( c = gc->conversations; c && c->id != id; c = c->next );

	yahoo_conference_message( yd->y2_id, NULL, c->data, c->title, message, 1 );
	
	return( 0 );
}

static void byahoo_chat_invite( struct gaim_connection *gc, int id, char *msg, char *who )
{
	struct byahoo_data *yd = (struct byahoo_data *) gc->proto_data;
	struct conversation *c;
	
	for( c = gc->conversations; c && c->id != id; c = c->next );
	
	yahoo_conference_invite( yd->y2_id, NULL, c->data, c->title, msg );
}

static void byahoo_chat_leave( struct gaim_connection *gc, int id )
{
	struct byahoo_data *yd = (struct byahoo_data *) gc->proto_data;
	struct conversation *c;
	
	for( c = gc->conversations; c && c->id != id; c = c->next );
	
	yahoo_conference_logoff( yd->y2_id, NULL, c->data, c->title );
	serv_got_chat_left( gc, c->id );
}

static int byahoo_chat_open( struct gaim_connection *gc, char *who )
{
	struct byahoo_data *yd = (struct byahoo_data *) gc->proto_data;
	struct conversation *c;
	char *roomname;
	YList *members;
	
	roomname = g_new0( char, strlen( gc->username ) + 16 );
	g_snprintf( roomname, strlen( gc->username ) + 16, "%s-Bee-%d", gc->username, byahoo_chat_id );
	
	c = serv_got_joined_chat( gc, ++byahoo_chat_id, roomname );
	add_chat_buddy( c, gc->username );
	
	/* FIXME: Free this thing when the chat's destroyed. We can't *always*
	          do this because it's not always created here. */
	c->data = members = g_new0( YList, 1 );
	members->data = g_strdup( who );
	
	yahoo_conference_invite( yd->y2_id, NULL, members, roomname, "Please join my groupchat..." );
	
	g_free( roomname );
	
	return( 1 );
}

void byahoo_init( struct prpl *ret )
{
	ret->protocol = PROTO_YAHOO;
	ret->name = yahoo_name;
	
	ret->login = byahoo_login;
	ret->close = byahoo_close;
	ret->send_im = byahoo_send_im;
	ret->send_typing = byahoo_send_typing;
	ret->get_info = byahoo_get_info;
	ret->away_states = byahoo_away_states;
	ret->set_away = byahoo_set_away;
	ret->keepalive = byahoo_keepalive;
	ret->add_buddy = byahoo_add_buddy;
	ret->remove_buddy = byahoo_remove_buddy;
	ret->get_status_string = byahoo_get_status_string;
	
	ret->chat_send = byahoo_chat_send;
	ret->chat_invite = byahoo_chat_invite;
	ret->chat_leave = byahoo_chat_leave;
	ret->chat_open = byahoo_chat_open;
	ret->cmp_buddynames = g_strcasecmp;
	
	my_protocol = ret;
}

static struct gaim_connection *byahoo_get_gc_by_id( int id )
{
	GSList *l;
	struct gaim_connection *gc;
	struct byahoo_data *yd;
	
	for( l = get_connections(); l; l = l->next )
	{
		gc = l->data;
		yd = gc->proto_data;
		
		if( gc->protocol == PROTO_YAHOO && yd->y2_id == id )
			return( gc );
	}
	
	return( NULL );
}


/* Now it's callback time! */

struct byahoo_connect_callback_data
{
	int fd;
	yahoo_connect_callback callback;
	gpointer data;
	int id;
};

void byahoo_connect_callback( gpointer data, gint source, GaimInputCondition cond )
{
	struct byahoo_connect_callback_data *d = data;
	
	if( !byahoo_get_gc_by_id( d->id ) )
	{
		g_free( d );
		return;
	}
	
	d->callback( d->fd, 0, d->data );
	g_free( d );
}

struct byahoo_read_ready_data
{
	int id;
	int fd;
	int tag;
	gpointer data;
};

void byahoo_read_ready_callback( gpointer data, gint source, GaimInputCondition cond )
{
	struct byahoo_read_ready_data *d = data;
	
	if( !byahoo_get_gc_by_id( d->id ) )
	{
		/* WTF doesn't libyahoo clean this up? */
		ext_yahoo_remove_handler( d->id, d->tag );
		return;
	}
	
	yahoo_read_ready( d->id, d->fd, d->data );
}

struct byahoo_write_ready_data
{
	int id;
	int fd;
	int tag;
	gpointer data;
};

void byahoo_write_ready_callback( gpointer data, gint source, GaimInputCondition cond )
{
	struct byahoo_write_ready_data *d = data;
	
	if( !byahoo_get_gc_by_id( d->id ) )
	{
		/* WTF doesn't libyahoo clean this up? */
		ext_yahoo_remove_handler( d->id, d->tag );
		return;
	}
	
	yahoo_write_ready( d->id, d->fd, d->data );
}

void ext_yahoo_login_response( int id, int succ, char *url )
{
	struct gaim_connection *gc = byahoo_get_gc_by_id( id );
	struct byahoo_data *yd = NULL;
	
	if( gc == NULL )
	{
		/* libyahoo2 seems to call this one twice when something
		   went wrong sometimes. Don't know why. Because we clean
		   up the connection on the first failure, the second
		   should be ignored. */
		
		return;
	}
	
	yd = (struct byahoo_data *) gc->proto_data;
	
	if( succ == YAHOO_LOGIN_OK )
	{
		account_online( gc );
		
		yd->logged_in = TRUE;
	}
	else
	{
		char *errstr;
		char *s;
		
		yd->logged_in = FALSE;
		
		if( succ == YAHOO_LOGIN_UNAME )
			errstr = "Incorrect Yahoo! username";
		else if( succ == YAHOO_LOGIN_PASSWD )
			errstr = "Incorrect Yahoo! password";
		else if( succ == YAHOO_LOGIN_LOCK )
			errstr = "Yahoo! account locked";
		else if( succ == YAHOO_LOGIN_DUPL )
		{
			errstr = "Logged in on a different machine or device";
			gc->wants_to_die = TRUE;
		}
		else if( succ == YAHOO_LOGIN_SOCK )
			errstr = "Socket problem";
		else
			errstr = "Unknown error";
		
		if( url && *url )
		{
			s = g_malloc( strlen( "Error %d (%s). See %s for more information." ) + strlen( url ) + strlen( errstr ) + 16 );
			sprintf( s, "Error %d (%s). See %s for more information.", succ, errstr, url );
		}
		else
		{
			s = g_malloc( strlen( "Error %d (%s)" ) + strlen( errstr ) + 16 );
			sprintf( s, "Error %d (%s)", succ, errstr );
		}
		
		if( yd->logged_in )
			hide_login_progress_error( gc, s );
		else
			hide_login_progress( gc, s );
		
		g_free( s );
		
		signoff( gc );
	}
}

void ext_yahoo_got_buddies( int id, YList *buds )
{
	struct gaim_connection *gc = byahoo_get_gc_by_id( id );
	struct byahoo_data *yd = gc->proto_data;
	YList *bl = buds;
	
	while( bl )
	{
		struct yahoo_buddy *b = bl->data;
		struct byahoo_buddygroups *bg;
		
		if( strcmp( b->group, BYAHOO_DEFAULT_GROUP ) != 0 )
		{
			bg = g_new0( struct byahoo_buddygroups, 1 );
			
			bg->buddy = g_strdup( b->id );
			bg->group = g_strdup( b->group );
			yd->buddygroups = g_slist_append( yd->buddygroups, bg );
		}
		
		add_buddy( gc, b->group, b->id, b->real_name );
		bl = bl->next;
	}
}

void ext_yahoo_got_ignore( int id, YList *igns )
{
}

void ext_yahoo_got_identities( int id, YList *ids )
{
}

void ext_yahoo_got_cookies( int id )
{
}

void ext_yahoo_status_changed( int id, char *who, int stat, char *msg, int away )
{
	struct gaim_connection *gc = byahoo_get_gc_by_id( id );
	
	serv_got_update( gc, who, stat != YAHOO_STATUS_OFFLINE, 0, 0, 0,
	                 ( stat != YAHOO_STATUS_AVAILABLE ) | ( stat << 1 ), 0 );
}

void ext_yahoo_got_im( int id, char *who, char *msg, long tm, int stat, int utf8 )
{
	struct gaim_connection *gc = byahoo_get_gc_by_id( id );
	char *m = byahoo_strip( msg );
	
	serv_got_im( gc, who, m, 0, 0, strlen( m ) );
	g_free( m );
}

void ext_yahoo_got_file( int id, char *who, char *url, long expires, char *msg, char *fname, unsigned long fesize )
{
	struct gaim_connection *gc = byahoo_get_gc_by_id( id );
	
	serv_got_crap( gc, "Got a file transfer (file = %s) from %s. Ignoring for now due to lack of support.", fname, who );
}

void ext_yahoo_typing_notify( int id, char *who, int stat )
{
	struct gaim_connection *gc = byahoo_get_gc_by_id( id );
	
	serv_got_typing( gc, who, 1 );
}

void ext_yahoo_system_message( int id, char *msg )
{
	struct gaim_connection *gc = byahoo_get_gc_by_id( id );
	
	serv_got_crap( gc, "Yahoo! system message: %s", msg );
}

void ext_yahoo_webcam_invite( int id, char *from )
{
	struct gaim_connection *gc = byahoo_get_gc_by_id( id );
	
	serv_got_crap( gc, "Got a webcam invitation from %s. IRC+webcams is a no-no though...", from );
}

void ext_yahoo_error( int id, char *err, int fatal )
{
	struct gaim_connection *gc = byahoo_get_gc_by_id( id );
	
	if( fatal )
	{
		hide_login_progress_error( gc, err );
		signoff( gc );
	}
	else
	{
		do_error_dialog( gc, err, "Yahoo! error" );
	}
}

/* TODO: Clear up the mess of inp and d structures */
int ext_yahoo_add_handler( int id, int fd, yahoo_input_condition cond, void *data )
{
	struct byahoo_input_data *inp = g_new0( struct byahoo_input_data, 1 );
	
	if( cond == YAHOO_INPUT_READ )
	{
		struct byahoo_read_ready_data *d = g_new0( struct byahoo_read_ready_data, 1 );
		
		d->id = id;
		d->fd = fd;
		d->data = data;
		
		inp->d = d;
		d->tag = inp->h = gaim_input_add( fd, GAIM_INPUT_READ, (GaimInputFunction) byahoo_read_ready_callback, (gpointer) d );
	}
	else if( cond == YAHOO_INPUT_WRITE )
	{
		struct byahoo_write_ready_data *d = g_new0( struct byahoo_write_ready_data, 1 );
		
		d->id = id;
		d->fd = fd;
		d->data = data;
		
		inp->d = d;
		d->tag = inp->h = gaim_input_add( fd, GAIM_INPUT_WRITE, (GaimInputFunction) byahoo_write_ready_callback, (gpointer) d );
	}
	else
	{
		g_free( inp );
		return( -1 );
		/* Panic... */
	}
	
	byahoo_inputs = g_slist_append( byahoo_inputs, inp );
	return( inp->h );
}

void ext_yahoo_remove_handler( int id, int tag )
{
	struct byahoo_input_data *inp;
	GSList *l = byahoo_inputs;
	
	while( l )
	{
		inp = l->data;
		if( inp->h == tag )
		{
			g_free( inp->d );
			g_free( inp );
			byahoo_inputs = g_slist_remove( byahoo_inputs, inp );
			break;
		}
		l = l->next;
	}
	
	gaim_input_remove( tag );
}

int ext_yahoo_connect_async( int id, char *host, int port, yahoo_connect_callback callback, void *data )
{
	struct byahoo_connect_callback_data *d;
	int fd;
	
	d = g_new0( struct byahoo_connect_callback_data, 1 );
	if( ( fd = proxy_connect( host, port, (GaimInputFunction) byahoo_connect_callback, (gpointer) d ) ) < 0 )
	{
		g_free( d );
		return( fd );
	}
	d->fd = fd;
	d->callback = callback;
	d->data = data;
	d->id = id;
	
	return( fd );
}

/* Because we don't want asynchronous connects in BitlBee, and because
   libyahoo doesn't seem to use this one anyway, this one is now defunct. */
int ext_yahoo_connect(char *host, int port)
{
#if 0
	struct sockaddr_in serv_addr;
	static struct hostent *server;
	static char last_host[256];
	int servfd;
	char **p;

	if(last_host[0] || g_strcasecmp(last_host, host)!=0) {
		if(!(server = gethostbyname(host))) {
			return -1;
		}
		strncpy(last_host, host, 255);
	}

	if((servfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
		return -1;
	}

	for (p = server->h_addr_list; *p; p++)
	{
		memset(&serv_addr, 0, sizeof(serv_addr));
		serv_addr.sin_family = AF_INET;
		memcpy(&serv_addr.sin_addr.s_addr, *p, server->h_length);
		serv_addr.sin_port = htons(port);

		if(connect(servfd, (struct sockaddr *) &serv_addr, 
					sizeof(serv_addr)) == -1) {
			return -1;
		} else {
			return servfd;
		}
	}

	closesocket(servfd);
#endif
	return -1;
}

static void byahoo_accept_conf( gpointer w, struct byahoo_conf_invitation *inv )
{
	yahoo_conference_logon( inv->yid, NULL, inv->members, inv->name );
	add_chat_buddy( inv->c, inv->gc->username );
	g_free( inv->name );
	g_free( inv );
}

static void byahoo_reject_conf( gpointer w, struct byahoo_conf_invitation *inv )
{
	yahoo_conference_decline( inv->yid, NULL, inv->members, inv->name, "User rejected groupchat" );
	serv_got_chat_left( inv->gc, inv->c->id );
	g_free( inv->name );
	g_free( inv );
}

void ext_yahoo_got_conf_invite( int id, char *who, char *room, char *msg, YList *members )
{
	struct gaim_connection *gc = byahoo_get_gc_by_id( id );
	struct byahoo_conf_invitation *inv;
	char txt[1024];
	YList *m;
	
	inv = g_malloc( sizeof( struct byahoo_conf_invitation ) );
	memset( inv, 0, sizeof( struct byahoo_conf_invitation ) );
	inv->name = g_strdup( room );
	inv->c = serv_got_joined_chat( gc, ++byahoo_chat_id, room );
	inv->c->data = members;
	inv->yid = id;
	inv->members = members;
	inv->gc = gc;
	
	for( m = members; m; m = m->next )
		if( g_strcasecmp( m->data, gc->username ) != 0 )
			add_chat_buddy( inv->c, m->data );
	
	g_snprintf( txt, 1024, "Got an invitation to chatroom %s from %s: %s", room, who, msg );
	
	do_ask_dialog( gc, txt, inv, byahoo_accept_conf, byahoo_reject_conf );
}

void ext_yahoo_conf_userdecline( int id, char *who, char *room, char *msg )
{
	struct gaim_connection *gc = byahoo_get_gc_by_id( id );
	
	serv_got_crap( gc, "Invite to chatroom %s rejected by %s: %s", room, who, msg );
}

void ext_yahoo_conf_userjoin( int id, char *who, char *room )
{
	struct gaim_connection *gc = byahoo_get_gc_by_id( id );
	struct conversation *c;
	
	for( c = gc->conversations; c && strcmp( c->title, room ) != 0; c = c->next );
	
	if( c )
		add_chat_buddy( c, who );
}

void ext_yahoo_conf_userleave( int id, char *who, char *room )
{
	struct gaim_connection *gc = byahoo_get_gc_by_id( id );
	struct conversation *c;
	
	for( c = gc->conversations; c && strcmp( c->title, room ) != 0; c = c->next );
	
	if( c )
		remove_chat_buddy( c, who, "" );
}

void ext_yahoo_conf_message( int id, char *who, char *room, char *msg, int utf8 )
{
	struct gaim_connection *gc = byahoo_get_gc_by_id( id );
	char *m = byahoo_strip( msg );
	struct conversation *c;
	
	for( c = gc->conversations; c && strcmp( c->title, room ) != 0; c = c->next );
	
	serv_got_chat_in( gc, c ? c->id : 0, who, 0, m, 0 );
	g_free( m );
}

void ext_yahoo_chat_cat_xml( int id, char *xml )
{
}

void ext_yahoo_chat_join( int id, char *room, char *topic, YList *members, int fd )
{
}

void ext_yahoo_chat_userjoin( int id, char *room, struct yahoo_chat_member *who )
{
}

void ext_yahoo_chat_userleave( int id, char *room, char *who )
{
}

void ext_yahoo_chat_message( int id, char *who, char *room, char *msg, int msgtype, int utf8 )
{
}

void ext_yahoo_chat_yahoologout( int id )
{
}

void ext_yahoo_chat_yahooerror( int id )
{
}

void ext_yahoo_contact_added( int id, char *myid, char *who, char *msg )
{
}

void ext_yahoo_rejected( int id, char *who, char *msg )
{
}

void ext_yahoo_game_notify( int id, char *who, int stat )
{
}

void ext_yahoo_mail_notify( int id, char *from, char *subj, int cnt )
{
	struct gaim_connection *gc = byahoo_get_gc_by_id( id );
	
	if( from && subj )
		serv_got_crap( gc, "Received e-mail message from %s with subject `%s'", from, subj );
	else if( cnt > 0 )
		serv_got_crap( gc, "Received %d new e-mails", cnt );
}

void ext_yahoo_webcam_invite_reply( int id, char *from, int accept )
{
}

void ext_yahoo_webcam_closed( int id, char *who, int reason )
{
}

void ext_yahoo_got_search_result( int id, int found, int start, int total, YList *contacts )
{
}

void ext_yahoo_webcam_viewer( int id, char *who, int connect )
{
}

void ext_yahoo_webcam_data_request( int id, int send )
{
}

int ext_yahoo_log( char *fmt, ... )
{
	return( 0 );
}

void ext_yahoo_got_webcam_image( int id, const char * who, const unsigned char *image, unsigned int image_size, unsigned int real_size, unsigned int timestamp )
{
}