Fwd: Re: Error in compiling Alpha-5

[email protected]
Newsgroups gmane.network.everybuddy.user
Message-ID <[email protected]>
Oops, of course this message was intended to go to the list instead of Matt ;)

Jeroen

----------  Forwarded Message  ----------

Subject: Re: [Everybuddy] Error in compiling Alpha-5
Date: Sun, 16 Mar 2003 11:39:13 +0100
From: [email protected]
To: "Matt Lewandowsky" <[email protected]>

Thanks, found it.
Attached the edited file.

Jeroen

On Sunday 16 March 2003 09:40, you wrote:
> I found the same. Edit yahoo.c (around the referenced line number) to
> fix it. This should have been on the list a couple of days ago...
>
> --Matt

-------------------------------------------------------
yahoo.c (text/x-csrc, 26.1 KB)
/*
 * Yahoo Extension for eb-lite 
 *
 * Copyright (C) 2002-2003, Philip Tellis <philip.tellis AT iname.com>
 *
 * 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
 *
 */

/*
 * yahoo.c
 */

#if HAVE_CONFIG_H
# include <config.h>
#endif
#include <netdb.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>


#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <time.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>


#include "yahoo2.h"
#include "yahoo2_callbacks.h"
#include "yahoo_util.h"

#include "elist.h"
#include "services.h"
#include "plugin_api.h"
#include "debug.h"
#include "prefs.h"
#include "message_parse.h"
#include "dialog.h"
#include "gui_comms.h"
#include "util.h"

/*******************************************************************************
 *                             Begin Module Code
 ******************************************************************************/
/*  Module defines */
#define service_info yahoo_LTX_service_info
#define plugin_info yahoo_LTX_plugin_info

/* Function Prototypes */
#ifndef STATIC_YAHOO
# define plugin_scope	static
#else
# define plugin_scope
#endif

/* Meredydd added this for ABS support */
//#ifdef STATIC_yahoo
//# define plugin_scope static
//# define USE_STRUCT_CALLBACKS 1
//#endif
/* End Meredydd's interference */

int yahoo_plugin_init();
int yahoo_plugin_finish();
static eb_service_callbacks *query_callbacks();
static EList *eb_yahoo_get_states();
static void eb_yahoo_logout(eb_local_account * ela);
static void register_callbacks();

//static int ref_count = 0;

char pager_host[]="scs.yahoo.com";
char pager_port[]="5050";
char filetransfer_host[]="filetransfer.msg.yahoo.com";
char filetransfer_port[]="80";


/*  Module Exports */
eb_service service_info={ 
	"Yahoo", 
	"Philip's libyahoo2", 
	NULL,
	SERVICE_CAN_OFFLINE,
//	0x0f,		/* SERVICE_CAN_EVERYTHING */
	"#d08020",
	NULL,
	NULL,
	NULL
};

eb_plugin_info plugin_info = {
	"Yahoo! Pager",
	"Philip's libyahoo2 plugin",
	"$Revision: 1.14 $",
	"$Date: 2002/12/28 09:50:43 $",
	yahoo_plugin_init,
	yahoo_plugin_finish
};

/* End Module Exports */

int yahoo_plugin_init()
{
	eb_debug(DBG_MOD, "Yahoo init\n");

	eb_put_default(registry, "config/services/yahoo/pager_host",
			"scs.yahoo.com");
	eb_put_default(registry, "config/services/yahoo/pager_port", "5050");
	eb_put_default(registry, "config/services/yahoo/file_host",
			"filetransfer.msg.yahoo.com");
	eb_put_default(registry, "config/services/yahoo/file_port", "80");

	service_info.sc=query_callbacks();
	
	service_info.states=eb_yahoo_get_states();
	
	eb_load_service(&service_info);

	register_callbacks();

	return 0;
}

int yahoo_plugin_finish()
{
//	eb_debug(DBG_MOD, "Returning the ref_count: %i\n", ref_count);
//	return (ref_count);
	e_list_free(service_info.states);
	return 0;
}

/*******************************************************************************
 *                             End Module Code
 ******************************************************************************/

#define YAHOO_FONT_SIZE "size=\""

typedef struct {
	int status;
	int away;
	char *status_message;
	int typing_timeout_tag;
} yahoo_buddy_account;

typedef struct {
	char password[255];
	int fd;
	int id;
	int input;
	int status;
	int wanted_status;
	int login_invisible;
	int mail;
	char *status_message;
	eb_pref_page *prefs;
} yahoo_local_account;

static YList * y_local_accounts = NULL;

typedef struct {
	int id;
	char *label;
} yahoo_idlabel;

static yahoo_idlabel eb_yahoo_status_codes[] = {
	{YAHOO_STATUS_AVAILABLE, "Available"},
	{YAHOO_STATUS_BRB, "Be Right Back"},
	{YAHOO_STATUS_BUSY, "Busy"},
	{YAHOO_STATUS_NOTATHOME, "Not Home"},
	{YAHOO_STATUS_NOTATDESK, "Not at Desk"},
	{YAHOO_STATUS_NOTINOFFICE, "Not in Office"},
	{YAHOO_STATUS_ONPHONE, "On Phone"},
	{YAHOO_STATUS_ONVACATION, "On Vacation"},
	{YAHOO_STATUS_OUTTOLUNCH, "Out to Lunch"},
	{YAHOO_STATUS_STEPPEDOUT, "Stepped Out"},
	{YAHOO_STATUS_INVISIBLE, "Invisible"},
	{YAHOO_STATUS_IDLE, "Idle"},
	{YAHOO_STATUS_OFFLINE, "Offline"},
	{YAHOO_STATUS_CUSTOM, ""},
	{0, NULL}
};

static const char * yahoo_status_string(enum yahoo_status code)
{
	int i;
	for(i=0; eb_yahoo_status_codes[i].label; i++)
		if(eb_yahoo_status_codes[i].id == code)
			return eb_yahoo_status_codes[i].label;

	return NULL;
}

#define YAHOO_DEBUGLOG ext_yahoo_log

static int do_yahoo_debug = 0;
int ext_yahoo_log(char *fmt,...)
{
	if(do_yahoo_debug) {
		va_list ap;

		va_start(ap, fmt);

		vfprintf(stderr, fmt, ap);
		fflush(stderr);
		va_end(ap);
	}
	return 0;
}


#define LOG(x) if(do_yahoo_debug) { YAHOO_DEBUGLOG("%s:%d: ", __FILE__, __LINE__); \
	YAHOO_DEBUGLOG x; \
	YAHOO_DEBUGLOG("\n"); }

#define WARNING(x) if(do_yahoo_debug) { YAHOO_DEBUGLOG("%s:%d: warning: ", __FILE__, __LINE__); \
	YAHOO_DEBUGLOG x; \
	YAHOO_DEBUGLOG("\n"); }


/*
static int match_la(const void * a, const void * b)
{
	const eb_local_account *ela = a, *elb = b;
	yahoo_local_account *yla = ela->protocol_account_data,
			*ylb = elb->protocol_account_data;
	
	return yla->id - ylb->id;
}
*/
static eb_local_account * eb_yahoo_find_local_account_by_id(int id)
{
	YList * l;
	for(l = y_local_accounts; l; l = l->next) {
		eb_local_account * ela = l->data;
		yahoo_local_account *yla = ela->protocol_account_data;
		if(yla->id == id)
			return ela;
	}

	return NULL;
}

static eb_account * eb_yahoo_get_remote_account(eb_local_account * la, char * handle)
{
	EList * n;

	for(n=la->buddies; n!=NULL; n=n->next) {
		eb_account * account=n->data;

		if(!strcmp(account->handle, handle))
			return account;
	}
	return NULL;
}

static int eb_yahoo_ping_timeout_callback(void * data)
{
	yahoo_local_account *yla = data;
	if(yla == NULL || yla->id < 0)
		return 0;
	yahoo_keepalive(yla->id);
	eb_set_timer((void *) eb_yahoo_ping_timeout_callback, 3000 * 1000, yla);
	return 1;
}

static void eb_yahoo_decode_yahoo_colors(char *buffer, char *msg)
{
	char *yahoo_colors[] =
	{
		YAHOO_COLOR_BLACK,
		YAHOO_COLOR_BLUE,
		YAHOO_COLOR_LIGHTBLUE,
		YAHOO_COLOR_GRAY,
		YAHOO_COLOR_GREEN,
		YAHOO_COLOR_PINK,
		YAHOO_COLOR_PURPLE,
		YAHOO_COLOR_ORANGE,
		YAHOO_COLOR_RED,
		YAHOO_COLOR_OLIVE
	};
	char *html_colors[] =
	{"<FONT COLOR=\"#000000\">",	/* 30 - Black */
	 "<FONT COLOR=\"#000080\">",	/* 31 - Blue */
	 "<FONT COLOR=\"#0000C0\">",	/* 32 - Light Blue */
	 "<FONT COLOR=\"#808080\">",	/* 33 - Gray */
	 "<FONT COLOR=\"#008000\">",	/* 34 - Green */
	 "<FONT COLOR=\"#C000C0\">",	/* 35 - Pink */
	 "<FONT COLOR=\"#800080\">",	/* 36 - Purple */
	 "<FONT COLOR=\"#F95002 \">",	/* 37 - Orange */
	 "<FONT COLOR=\"#800000\">",	/* 38 - Red */
	 "<FONT COLOR=\"#00C000\">"	/* 39 - Olive */
	};
	int num_colors = sizeof(yahoo_colors) / sizeof(char *);

	char *yahoo_styles[] =
	{
		YAHOO_STYLE_ITALICON,
		YAHOO_STYLE_ITALICOFF,
		YAHOO_STYLE_BOLDON,
		YAHOO_STYLE_BOLDOFF,
		YAHOO_STYLE_UNDERLINEON,
		YAHOO_STYLE_UNDERLINEOFF
	};
	char *html_styles[] =
	{
		"<I>",
		"</I>",
		"<B>",
		"</B>",
		"<U>",
		"</U>"
	};
	int num_styles = sizeof(yahoo_styles) / sizeof(char *);

	int string_index;
	int color_index;
	int style_index;
	int in_color = 0;
	int match = 0;
	char tmp[2];

	tmp[1] = '\0';
	buffer[0] = '\0';

	for (string_index = 0; msg[string_index]; string_index++) {
		match = 0;
		for (color_index = 0; color_index < num_colors; color_index++) {
			if (!strncmp(yahoo_colors[color_index],
				     &msg[string_index],
				     strlen(yahoo_colors[color_index]))) {
				if (in_color) {
					strcat(buffer, "</FONT>");
				}
				strcat(buffer, html_colors[color_index]);
				string_index += (strlen(
					 yahoo_colors[color_index]) - 1);
				in_color = 1;
				match = 1;
			}
		}
		for (style_index = 0; style_index < num_styles; style_index++) {
			if (!strncmp(yahoo_styles[style_index],
				     &msg[string_index],
				     strlen(yahoo_styles[style_index]))) {
				strcat(buffer, html_styles[style_index]);
				string_index += (strlen(
					 yahoo_styles[style_index]) - 1);
				match = 1;
			}
		}
		if (!strncmp(YAHOO_STYLE_URLON, &msg[string_index],
			     strlen(YAHOO_STYLE_URLON))) {
			char *end_of_url;
			int length_of_url;

			string_index += (strlen(YAHOO_STYLE_URLON));
			end_of_url = strstr(&msg[string_index],
					    YAHOO_STYLE_URLOFF);
			length_of_url = end_of_url - &msg[string_index];
			if (end_of_url != NULL) {
				strcat(buffer, "<A HREF=\"");
				strncat(buffer, &msg[string_index],
					length_of_url);
				strcat(buffer, "\">");
				match = 1;
			}
			string_index--;
		}
		if (!strncmp(YAHOO_STYLE_URLOFF, &msg[string_index],
			     strlen(YAHOO_STYLE_URLOFF))) {
			strcat(buffer, "</A>");
			string_index += (strlen(YAHOO_STYLE_URLOFF) - 1);
			match = 1;
		}
		if (!strncmp(YAHOO_FONT_SIZE, &msg[string_index],
			     strlen(YAHOO_FONT_SIZE))) {
			strcat(buffer, "PTSIZE=\"");
			string_index += (strlen(YAHOO_FONT_SIZE) - 1);
			match = 1;
		}
		if (!match) {
			tmp[0] = msg[string_index];
			strcat(buffer, tmp);
		}
	}
	if (in_color) {
		strcat(buffer, "</FONT>");
	}
	LOG(("post-color buffer: %s", buffer));
}

void ext_yahoo_status_changed(int id, char *who, int stat, char *msg, int away)
{
	eb_local_account *ela = eb_yahoo_find_local_account_by_id(id);
	eb_account * acc;
	int was_offline;

	if(ela==NULL) { return; }

	acc = eb_get_account(ela->handle, "Yahoo", who);

	if(acc==NULL)
	{ LOG(("No account match for status notify %s!", who)); }

	free(acc->status_string);
	was_offline=(acc->status==EB_ACCOUNT_OFFLINE);
	acc->status=(away)?(EB_ACCOUNT_AWAY):(EB_ACCOUNT_ONLINE);

	if(stat==YAHOO_STATUS_CUSTOM)
	{
		acc->status_string=strdup(msg);
	} else if(stat==YAHOO_STATUS_AVAILABLE) {
		acc->status_string=strdup("");
	} else if(stat==YAHOO_STATUS_OFFLINE) {
		acc->status_string=strdup("Offline");
		acc->status=EB_ACCOUNT_OFFLINE;
		eb_buddy_logout(acc);
		return;
	} else {
		acc->status_string=strdup(yahoo_status_string(stat));
	}
	if(was_offline) { eb_buddy_login(acc); }
	eb_buddy_update_status(acc);
}

void ext_yahoo_got_buddies(int id, YList * buds)
{
	eb_local_account *ela = eb_yahoo_find_local_account_by_id(id);
	YList * l;

	if(ela==NULL) { return; }

	for(l = buds; l; l=l->next) {
		struct yahoo_buddy *bud = l->data;

		eb_account * ea = eb_get_account(ela->handle, ela->service_name, bud->id);
		char * contact_name = bud->real_name?bud->real_name:bud->id;
		if(!ea) {
			eb_contact * c;
			eb_group * g = eb_get_group(bud->group);
			if(!g)
				g = eb_add_group(bud->group);
			c = eb_get_contact(bud->group, contact_name);
			if(!c)
				c = eb_add_contact(g, contact_name);

			ea = y_new0(eb_account, 1);
			ea->handle = strdup(bud->id);
			ea->status_string = strdup("Offline");
			eb_add_account(c, ela, ea);
		} else {
			if(!strcmp(ea->contact->name, ea->handle) 
					&& strcmp(ea->contact->name, contact_name))
				eb_rename_contact(ea->contact, contact_name);
		}
	}
}

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

void ext_yahoo_got_im(int id, char *who, char *msg, long tm, int stat, int utf8)
{
	if(stat == 2) {
		LOG(("Error sending message to %s", who));
		return;
	}

	if(msg) {
		eb_local_account *ela = eb_yahoo_find_local_account_by_id(id);
		eb_account *sender;
		char buff[2048];

		if(ela==NULL) { return; }
		
		sender = eb_yahoo_get_remote_account(ela, who);
		
		if(sender==NULL)
		{
			char * buf=(char *)malloc(strlen(who)+128);
			eb_group * group=eb_get_group("Buddies");
			eb_contact * cont;
			if(group==NULL)
			{ group=eb_add_group("Buddies"); }

			cont=eb_get_contact("Buddies", who);
			if(cont==NULL)
			{ cont=eb_add_contact(group, who); }

			sender=(eb_account *)malloc(sizeof(eb_account));
			sender->handle=strdup(who);
			sender->status_string=strdup("(Offline)");
			sender->contact=cont;
			eb_yahoo_add_user(sender, ela);
			
			sprintf(buf, "<font color=#555555><i>The user <b>%s</b> has just sent you a message for the first time. They have been added to your <b>Unknown</b> group</i></font>", who);
			eb_notify_3rdperson(cont, buf);
			free(buf);
		}

		if(tm) {
			char newmessage[4096];
			char timestr[2048];

			strncpy(timestr, ctime(&tm), sizeof(timestr));
			timestr[strlen(timestr) - 1] = '\0';

			snprintf(newmessage, sizeof(newmessage), "<FONT COLOR=\"#0000FF\">[Offline message at %s]</FONT><BR>%s", timestr, msg);

			LOG(("<incoming offline message: %s: %s>", who, msg));
		} else {
			LOG(("<incoming message: %s: %s>", who, msg));
		}

		eb_yahoo_decode_yahoo_colors(buff, msg);
		eb_incoming_message(sender, buff);
	}
}

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

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

int eb_yahoo_send_typing(eb_account *acc)
{
	return 0;
}

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

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

void ext_yahoo_mail_notify(int id, char *from, char *subj, int cnt)
{
}

void ext_yahoo_system_message(int id, char *msg)
{
  eb_local_account * ela=eb_yahoo_find_local_account_by_id(id);
  char * buf;
  if(ela==NULL) { return; }

  buf=(char *)malloc(strlen(msg)+strlen(ela->handle)+16);
  sprintf(buf, "Received by %s:\n%s", ela->handle, msg);
  eb_show_error(buf, "Yahoo System Message");
  free(buf);
}

void ext_yahoo_error(int id, char *err, int fatal)
{
  eb_local_account * ela=eb_yahoo_find_local_account_by_id(id);
  char * buf;
  if(ela==NULL) { return; }

  buf=(char *)malloc(strlen(err)+strlen(ela->handle)+16);
  sprintf(buf, "%s: %s", ela->handle, err);
  eb_show_error(buf, "Yahoo error");
  free(buf);
}

void eb_yahoo_login_with_state(eb_local_account * ela, int state)
{
	yahoo_local_account *yla = ela->protocol_account_data;
	strncpy(yla->password, eb_get_value(ela->config_key, "password"), 
			sizeof(yla->password));

	if(atoi(eb_get_value(ela->config_key, "excl_soa")))
		return;

//	yahoo_set_log_level(do_yahoo_debug?YAHOO_LOG_DEBUG:YAHOO_LOG_NONE);

	ela->connected = 0;
	yla->id = yahoo_login(ela->handle, yla->password, state);
	yla->status = YAHOO_STATUS_OFFLINE;

	if (yla->id <= 0) {
		fprintf(stderr, "Could not connect to Yahoo server.  Please verify that you are connected to the net and the pager host and port are correctly entered.");
		return;
	}

	ela->connected=1;
	eb_local_account_update(ela);

//	ref_count++;
}

void eb_yahoo_login(eb_local_account * ela)
{
	yahoo_local_account * yla = ela->protocol_account_data;

	yla->login_invisible = atoi(eb_get_value(ela->config_key, "invisible"));

	if(atoi(eb_get_value(ela->config_key, "excl_soa")))
		return;

	eb_yahoo_login_with_state(ela, 
			yla->login_invisible?YAHOO_STATUS_INVISIBLE:YAHOO_STATUS_AVAILABLE);
}

void ext_yahoo_login_response(int id, int succ, char *url)
{
	eb_local_account *ela = eb_yahoo_find_local_account_by_id(id);
	yahoo_local_account *yla;

	char buff[1024];

	if(ela==NULL) { return; }

	yla = ela->protocol_account_data;

	if(succ == YAHOO_LOGIN_OK) {
		yla->status = yahoo_current_status(id);
		ela->ready = 1;
		yahoo_get_yab(id);
		FREE(ela->status_string);
		ela->status_string = strdup(yahoo_status_string(yahoo_current_status(id)));
		eb_local_account_update(ela);
		eb_yahoo_ping_timeout_callback(yla);
		return;
		
	} else if(succ == YAHOO_LOGIN_PASSWD) {

		snprintf(buff,sizeof(buff),"Could not log into Yahoo service.  "
				"Please verify that your username and "
				"password are correctly typed.");

	} else if(succ == YAHOO_LOGIN_LOCK) {
		
		snprintf(buff,sizeof(buff),"Could not log into Yahoo service. "
				"Your account has been locked.\n"
				"Visit %s to reactivate it.", url);

	} else if(succ == YAHOO_LOGIN_DUPL) {
		snprintf(buff,sizeof(buff),"You have been logged out of the "
				"yahoo service, "
				"possibly due to a duplicate login.");
	}

	ela->connected=0;
	ela->ready=0;
	yla->status = YAHOO_STATUS_OFFLINE;
	eb_show_error(buff, "Yahoo login error");
	eb_yahoo_logout(ela);
	eb_local_account_update(ela);
}

static void eb_yahoo_logout(eb_local_account * ela)
{
	yahoo_local_account *yla = ela->protocol_account_data;

	LOG(("eb_yahoo_logout"));

	if(yla == NULL || yla->id < 0)
		return;
	if(!ela->connected)
		return;
	ela->ready = ela->connected = 0;
	FREE(ela->status_string);
	yla->status = YAHOO_STATUS_OFFLINE;
	ela->status_string = strdup(yahoo_status_string(yla->status));

	yahoo_logoff(yla->id);
	yla->id = 0;

	eb_local_account_update(ela);
//	ref_count--;
}

static char * eb_yahoo_send_im(eb_account * to, char * msg)
{
	eb_local_account * from=to->buddy_of;
	yahoo_local_account * yla=from->protocol_account_data;

	if(!from->ready) {
		eb_show_error("Cannot send instant messages from an offline account", "Yahoo Error");
		free(msg);
		return NULL;
	}

	yahoo_send_im(yla->id, NULL, to->handle, msg, 0);

	return msg;
}

static void eb_yahoo_set_mailnotify(eb_pref * pref, void * tag)
{
	eb_local_account * ela=tag;
	yahoo_local_account * yla=ela->protocol_account_data;
	char * mail=eb_get_value(ela->config_key, "mail");

	yla->mail = atoi(mail);

}

static void eb_yahoo_setup_local_account(eb_local_account *ela)
{
	yahoo_local_account *yla = y_new0(yahoo_local_account, 1);
	char *tmp = y_new0(char, strlen(ela->handle)+10);
	char *tmp2 = y_new0(char, strlen(ela->handle)+10);
	strcpy(tmp, ela->handle);
	strcpy(tmp2, ela->handle);
	strcat(tmp, " (Yahoo)");
	strcat(tmp2, "_Yahoo");
	ela->protocol_account_data = yla;
	yla->status = YAHOO_STATUS_OFFLINE;
	strncpy(yla->password, eb_get_value(ela->config_key, "password"), 
			sizeof(yla->password));

	y_local_accounts = y_list_append(y_local_accounts, ela);
	
	yla->prefs=eb_make_pref_page(account_prefs, tmp2, tmp);
	free(tmp); free(tmp2);

	eb_add_component(yla->prefs, EB_PREF_TOGGLE, "excl_soa", 
			"Exclude from \"Sign On All\"", ela->config_key, 
			"excl_soa", NULL, NULL);
	eb_add_component(yla->prefs, EB_PREF_PASSWORD, "password", 
			"Password:", ela->config_key, 
			"password", NULL, NULL);
	eb_add_component(yla->prefs, EB_PREF_TOGGLE, "invisible", 
			"Login Invisible:", ela->config_key, 
			"invisible", NULL, NULL);
	eb_add_component(yla->prefs, EB_PREF_TOGGLE, "mail", 
			"New Mail Notification:", ela->config_key, 
			"mail", eb_yahoo_set_mailnotify, ela);
}

static void eb_yahoo_release_local_account(eb_local_account * ela)
{
	yahoo_local_account *yla = ela->protocol_account_data;
	FREE(yla->status_message);
	FREE(yla->prefs);
	FREE(yla);

	y_local_accounts = y_list_remove(y_local_accounts, ela);
}

static EList *eb_yahoo_get_states()
{
	static EList *states;
	int i;

	if(!states)
		for(i=0; eb_yahoo_status_codes[i].label; i++)
			states = e_list_append(states, 
					eb_yahoo_status_codes[i].label);

	return states;
}

static char * eb_yahoo_check_login(char * user, char * pass)
{
	return NULL;
}

static void eb_yahoo_set_current_state(eb_local_account * ela, char * state)
{
	yahoo_local_account * yla = ela->protocol_account_data;
	int i;

	if(!strcmp(state, "Offline")) {
		yla->status = YAHOO_STATUS_OFFLINE;
		eb_log_out_account(ela);
		return;
	}

	for(i=0; eb_yahoo_status_codes[i].label; i++)
		if(!strcmp(eb_yahoo_status_codes[i].label, state)) {
			yla->status = eb_yahoo_status_codes[i].id;
			break;
		}
	if(!eb_yahoo_status_codes[i].label) {
		yla->status = YAHOO_STATUS_CUSTOM;
		FREE(yla->status_message);
		yla->status_message = strdup(state);
	}

	if(!ela->connected) {
		strncpy(yla->password, eb_get_value(ela->config_key, "password"), 
			sizeof(yla->password));
		eb_yahoo_login_with_state(ela, yla->status);
		return;
	}

	if(yla->status == YAHOO_STATUS_CUSTOM) {
		if(yla->status_message)
			yahoo_set_away(yla->id, yla->status, yla->status_message, 0);
		else
			yahoo_set_away(yla->id, yla->status, "delta p * delta x too large", 0);
        } else
		yahoo_set_away(yla->id, yla->status, NULL, 1);

	
	ela->ready = 1;
	FREE(ela->status_string);
	ela->status_string = strdup(yahoo_status_string(yla->status));
	eb_local_account_update(ela);
}

static void eb_yahoo_add_user(eb_local_account *ela, eb_account * ea)
{
	yahoo_local_account * yla = ela->protocol_account_data;
	yahoo_add_buddy(yla->id, ea->handle, ea->contact->group->name);
	
	// ASSUMPTION - FIX ME!
	eb_add_account(ea->contact, ela, ea);
}

static void eb_yahoo_del_user(eb_account * ea)
{
	yahoo_local_account * yla = ea->buddy_of->protocol_account_data;
	
	yahoo_remove_buddy(yla->id, ea->handle, ea->contact->group->name);
	// whoa! group could change!
	
        eb_del_account(ea);
}

static void eb_yahoo_ignore_user(eb_account * ea)
{
}

static void eb_yahoo_unignore_user(eb_account * ea)
{
}

static void eb_yahoo_change_group(eb_account * ea, char *new_group)
{
}

/*
char *eb_yahoo_get_status_string(eb_account * ea)
{
	yahoo_buddy_account *yba = ea->protocol_account_data;
	int i;

	if (yba->status == YAHOO_STATUS_CUSTOM && yba->status_message) {
//		LOG(("eb_yahoo_get_status_string: %s is %s", ea->handle, yba->status_message));
		return yba->status_message;
	}
	for (i = 0; eb_yahoo_status_codes[i].label; i++) {
		if (eb_yahoo_status_codes[i].id == yba->status) {
			return eb_yahoo_status_codes[i].label;
		}
	}

	LOG(("eb_yahoo_get_status_string: %s is Unknown [%d]", ea->handle, yba->status));
	return "Unk";
}
*/

static void eb_yahoo_set_away(eb_local_account *ela, char *short_msg, char *long_msg)
{
  eb_yahoo_set_current_state(ela, short_msg);
}

void ext_yahoo_got_file(int id, char *who, char *url, long expires, char *msg, char *fname, unsigned long fesize) {}

void ext_yahoo_got_conf_invite(int id, char *who, char *room, char *msg, YList *members) {}

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

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

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

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

int ext_yahoo_connect(char *host, int port)
{
	return eb_connect_sync_socket(host, port);
}

/*************************************
 * Callback handling code starts here
 */
typedef struct {
	int id;
	void * data;
	int tag;
} eb_yahoo_callback_data;

static void eb_yahoo_callback(void * data, int source, eb_input_condition condition)
{
	eb_yahoo_callback_data *d = data;
	int ret=1;
	char buff[1024]={0};

	if(condition & EB_INPUT_READ) {
		LOG(("Read: %d", source));
		ret = yahoo_read_ready(d->id, source);

		if(ret == -1)
			snprintf(buff, sizeof(buff), 
				"Yahoo read error (%d): %s", errno, 
				strerror(errno));
		else if(ret == 0)
			snprintf(buff, sizeof(buff), 
				"Yahoo read error: Server closed socket");
	}

	if(condition & EB_INPUT_WRITE) {
		LOG(("Write: %d", source));
		ret = yahoo_write_ready(d->id, source);

		if(ret == -1)
			snprintf(buff, sizeof(buff), 
				"Yahoo write error (%d): %s", errno, 
				strerror(errno));
		else if(ret == 0)
			snprintf(buff, sizeof(buff), 
				"Yahoo write error: Server closed socket");
	}

	if(condition & EB_INPUT_EXCEPTION)
		LOG(("Exception: %d", source));
	if(!(condition & (EB_INPUT_READ | EB_INPUT_WRITE | EB_INPUT_EXCEPTION)))
		LOG(("Unknown: %d", condition));

	if(buff[0])
		fprintf(stderr, buff);
}

static YList * handlers = NULL;

void ext_yahoo_add_handler(int id, int fd, yahoo_input_condition cond)
{
	eb_yahoo_callback_data *d = y_new0(eb_yahoo_callback_data, 1);
	d->id = id;
	d->tag = eb_input_add(fd, cond, eb_yahoo_callback, d);
	LOG(("%d added %d for %d", id, fd, cond));

	handlers = y_list_append(handlers, d);
}

void ext_yahoo_remove_handler(int id, int fd)
{
	YList * l;
	for(l = handlers; l; l = l->next)
	{
		eb_yahoo_callback_data *d = l->data;
		if(d->id == id) {
			LOG(("%d removed %d", id, fd));
			eb_input_remove(d->tag);
			handlers = y_list_remove_link(handlers, l);
			break;
		}
	}
}
/*
 * Callback handling code ends here
 ***********************************/

static eb_service_callbacks * query_callbacks()
{
	static eb_service_callbacks sc;

	LOG(("yahoo_query_callbacks"));

	sc.login			= eb_yahoo_login;
	sc.logout 			= eb_yahoo_logout;

	sc.send_im 			= eb_yahoo_send_im;
	sc.send_typing			= eb_yahoo_send_typing;

	sc.setup_local_account 		= eb_yahoo_setup_local_account;
	sc.release_local_account	= eb_yahoo_release_local_account;
	sc.setup_buddy_account 		= NULL;

	sc.set_current_state 		= eb_yahoo_set_current_state;
	sc.check_login			= eb_yahoo_check_login;
	
	sc.add_user 			= eb_yahoo_add_user;
	sc.del_user 			= eb_yahoo_del_user;
	sc.block_user			= eb_yahoo_ignore_user;
	sc.unblock_user			= eb_yahoo_unignore_user;
	sc.change_group			= eb_yahoo_change_group;

//	sc.get_status_string 		= eb_yahoo_get_status_string;

	sc.set_away 			= eb_yahoo_set_away;

	sc.send_file			= NULL;

	sc.terminate_chat		= NULL;

	return &sc;
}

void ext_yahoo_got_identities(int id, YList * ids)
{
}
static void register_callbacks()
{
#ifdef USE_STRUCT_CALLBACKS
	static struct yahoo_callbacks yc;
	yc.ext_yahoo_login_response = ext_yahoo_login_response;
	yc.ext_yahoo_got_buddies = ext_yahoo_got_buddies;
	yc.ext_yahoo_got_ignore = ext_yahoo_got_ignore;
	yc.ext_yahoo_got_identities = ext_yahoo_got_identities;
	yc.ext_yahoo_status_changed = ext_yahoo_status_changed;
	yc.ext_yahoo_got_im = ext_yahoo_got_im;
	yc.ext_yahoo_got_conf_invite = ext_yahoo_got_conf_invite;
	yc.ext_yahoo_conf_userdecline = ext_yahoo_conf_userdecline;
	yc.ext_yahoo_conf_userjoin = ext_yahoo_conf_userjoin;
	yc.ext_yahoo_conf_userleave = ext_yahoo_conf_userleave;
	yc.ext_yahoo_conf_message = ext_yahoo_conf_message;
	yc.ext_yahoo_got_file = ext_yahoo_got_file;
	yc.ext_yahoo_contact_added = ext_yahoo_contact_added;
	yc.ext_yahoo_rejected = ext_yahoo_rejected;
	yc.ext_yahoo_typing_notify = ext_yahoo_typing_notify;
	yc.ext_yahoo_game_notify = ext_yahoo_game_notify;
	yc.ext_yahoo_mail_notify = ext_yahoo_mail_notify;
	yc.ext_yahoo_system_message = ext_yahoo_system_message;
	yc.ext_yahoo_error = ext_yahoo_error;
	yc.ext_yahoo_log = ext_yahoo_log;
	yc.ext_yahoo_add_handler = ext_yahoo_add_handler;
	yc.ext_yahoo_remove_handler = ext_yahoo_remove_handler;
	yc.ext_yahoo_connect = ext_yahoo_connect;

	yahoo_register_callbacks(&yc);
	
#endif
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.