/* * libyahoo2 wrapper to BitlBee * * Mostly Copyright 2004 Wilmer van der Gaast * * 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 #include #include #include #include #include #include #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 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, "' ); 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 = ""; } 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; if( yd->current_status == YAHOO_STATUS_INVISIBLE ) yahoo_set_away( yd->y2_id, yd->current_status, NULL, gc->away != NULL ); else 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, BYA
#include <stdlib.h>
#include <glib.h>
#include <gmodule.h>
#include <check.h>
#include <string.h>
#include <stdio.h>

char *sasl_get_part( char *data, char *field );

#define challenge1 "nonce=\"1669585310\",qop=\"auth\",charset=utf-8,algorithm=md5-sess," \
                   "something=\"Not \\\"standardized\\\"\""
#define challenge2 "realm=\"quadpoint.org\", nonce=\"NPotlQpQf9RNYodOwierkQ==\", " \
                   "qop=\"auth, auth-int\", charset=utf-8, algorithm=md5-sess"
#define challenge3 ", realm=\"localhost\", nonce=\"LlBV2txnO8RbB5hgs3KgiQ==\", " \
                   "qop=\"auth, auth-int, \", ,\n, charset=utf-8, algorithm=md5-sess,"

struct
{
	char *challenge;
	char *key;
	char *value;
} get_part_tests[] = {
	{
		challenge1,
		"nonce",
		"1669585310"
	},
	{
		challenge1,
		"charset",
		"utf-8"
	},
	{
		challenge1,
		"harset",
		NULL
	},
	{
		challenge1,
		"something",
		"Not \"standardized\""
	},
	{
		challenge1,
		"something_else",
		NULL
	},
	{
		challenge2,
		"realm",
		"quadpoint.org",
	},
	{
		challenge2,
		"real",
		NULL
	},
	{
		challenge2,
		"qop",
		"auth, auth-int"
	},
	{
		challenge3,
		"realm",
		"localhost"
	},
	{
		challenge3,
		"qop",
		"auth, auth-int, "
	},
	{
		challenge3,
		"charset",
		"utf-8"
	},
	{ NULL, NULL, NULL }
};

static void check_get_part(int l)
{
	int i;
	
	for( i = 0; get_part_tests[i].key; i++ )
	{
  		tcase_fn_start( get_part_tests[i].key, __FILE__, i );
		char *res;
		int len;
		
		res = sasl_get_part( get_part_tests[i].challenge,
		                     get_part_tests[i].key );
		
		if( get_part_tests[i].value == NULL )
			fail_if( res != NULL, "Found key %s in %s while it shouldn't be there!",
			         get_part_tests[i].key, get_part_tests[i].challenge );
		else if(