aboutsummaryrefslogtreecommitdiffstats
path: root/lib/misc.c
blob: c56b31f39be906d70d0a1cd69123ec26aae636bd (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
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
  /********************************************************************\
  * BitlBee -- An IRC to other IM-networks gateway                     *
  *                                                                    *
  * Copyright 2002-2006 Wilmer van der Gaast and others                *
  \********************************************************************/

/*
 * Various utility functions. Some are copied from Gaim to support the
 * IM-modules, most are from BitlBee.
 *
 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
 *                          (and possibly other members of the Gaim team)
 * Copyright 2002-2006 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 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
*/

#define BITLBEE_CORE
#include "nogaim.h"
#include "base64.h"
#include "md5.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <glib.h>
#include <time.h>

#ifdef HAVE_RESOLV_A
#include <arpa/nameser.h>
#include <resolv.h>
#endif

#include "md5.h"
#include "ssl_client.h"

void strip_linefeed(gchar *text)
{
	int i, j;
	gchar *text2 = g_malloc(strlen(text) + 1);

	for (i = 0, j = 0; text[i]; i++)
		if (text[i] != '\r')
			text2[j++] = text[i];
	text2[j] = '\0';

	strcpy(text, text2);
	g_free(text2);
}

time_t get_time(int year, int month, int day, int hour, int min, int sec)
{
	struct tm tm;

	memset(&tm, 0, sizeof(struct tm));
	tm.tm_year = year - 1900;
	tm.tm_mon = month - 1;
	tm.tm_mday = day;
	tm.tm_hour = hour;
	tm.tm_min = min;
	tm.tm_sec = sec >= 0 ? sec : time(NULL) % 60;
	
	return mktime(&tm);
}

time_t mktime_utc( struct tm *tp )
{
	struct tm utc;
	time_t res, tres;
	
	tp->tm_isdst = -1;
	res = mktime( tp );
	/* Problem is, mktime() just gave us the GMT timestamp for the
	   given local time... While the given time WAS NOT local. So
	   we should fix this now.
	   
	   Now I could choose between messing with environment variables
	   (kludgy) or using timegm() (not portable)... Or doing the
	   following, which I actually prefer...
	   
	   tzset() may also work but in other places I actually want to
	   use local time.
	   
	   FFFFFFFFFFFFFFFFFFFFFUUUUUUUUUUUUUUUUUUUU!! */
	gmtime_r( &res, &utc );
	utc.tm_isdst = -1;
	if( utc.tm_hour == tp->tm_hour && utc.tm_min == tp->tm_min )
		/* Sweet! We're in UTC right now... */
		return res;
	
	tres = mktime( &utc );
	res += res - tres;
	
	/* Yes, this is a hack. And it will go wrong around DST changes.
	   BUT this is more likely to be threadsafe than messing with
	   environment variables, and possibly more portable... */
	
	return res;
}

typedef struct htmlentity
{
	char code[7];
	char is[3];
} htmlentity_t;

static const htmlentity_t ent[] =
{
	{ "lt",     "<" },
	{ "gt",     ">" },
	{ "amp",    "&" },
	{ "apos",   "'" },
	{ "quot",   "\"" },
	{ "aacute", "á" },
	{ "eacute", "é" },
	{ "iacute", "é" },
	{ "oacute", "ó" },
	{ "uacute", "ú" },
	{ "agrave", "à" },
	{ "egrave", "è" },
	{ "igrave", "ì" },
	{ "ograve", "ò" },
	{ "ugrave", "ù" },
	{ "acirc",  "â" },
	{ "ecirc",  "ê" },
	{ "icirc",  "î" },
	{ "ocirc",  "ô" },
	{ "ucirc",  "û" },
	{ "auml",   "ä" },
	{ "euml",   "ë" },
	{ "iuml",   "ï" },
	{ "ouml",   "ö" },
	{ "uuml",   "ü" },
	{ "nbsp",   " " },
	{ "",        ""  }
};

void strip_html( char *in )
{
	char *start = in;
	char *out = g_malloc( strlen( in ) + 1 );
	char *s = out, *cs;
	int i, matched;
	
	memset( out, 0, strlen( in ) + 1 );
	
	while( *in )
	{
		if( *in == '<' && ( isalpha( *(in+1) ) || *(in+1) == '/' ) )
		{
			/* If in points at a < and in+1 points at a letter or a slash, this is probably
			   a HTML-tag. Try to find a closing > and continue there. If the > can't be
			   found, assume that it wasn't a HTML-tag after all. */
			
			cs = in;
			
			while( *in && *in != '>' )
				in ++;
			
			if( *in )
			{
				if( g_strncasecmp( cs+1, "br", 2) == 0 )
					*(s++) = '\n';
				in ++;
			}
			else
			{
				in = cs;
				*(s++) = *(in++);
			}
		}
		else if( *in == '&' )
		{
			cs = ++in;
			while( *in && isalpha( *in ) )
				in ++;
			
			if( *in == ';' ) in ++;
			matched = 0;
			
			for( i = 0; *ent[i].code; i ++ )
				if( g_strncasecmp( ent[i].code, cs, strlen( ent[i].code ) ) == 0 )
				{
					int j;
					
					for( j = 0; ent[i].is[j]; j ++ )
						*(s++) = ent[i].is[j];
					
					matched = 1;
					break;
				}

			/* None of the entities were matched, so return the string */
			if( !matched )
			{
				in = cs - 1;
				*(s++) = *(in++);
			}
		}
		else
		{
			*(s++) = *(in++);
		}
	}
	
	strcpy( start, out );
	g_free( out );
}

char *escape_html( const char *html )
{
	const char *c = html;
	GString *ret;
	char *str;
	
	if( html == NULL )
		return( NULL );
	
	ret = g_string_new( "" );
	
	while( *c )
	{
		switch( *c )
		{
			case '&':
				ret = g_string_append( ret, "&amp;" );
				break;
			case '<':
				ret = g_string_append( ret, "&lt;" );
				break;
			case '>':
				ret = g_string_append( ret, "&gt;" );
				break;
			case '"':
				ret = g_string_append( ret, "&quot;" );
				break;
			default:
				ret = g_string_append_c( ret, *c );
		}
		c ++;
	}
	
	str = ret->str;
	g_string_free( ret, FALSE );
	return( str );
}

/* Decode%20a%20file%20name						*/
void http_decode( char *s )
{
	char *t;
	int i, j, k;
	
	t = g_new( char, strlen( s ) + 1 );
	
	for( i = j = 0; s[i]; i ++, j ++ )
	{
		if( s[i] == '%' )
		{
			if( sscanf( s + i + 1, "%2x", &k ) )
			{
				t[j] = k;
				i += 2;
			}
			else
			{
				*t = 0;
				break;
			}
		}
		else
		{
			t[j] = s[i];
		}
	}
	t[j] = 0;
	
	strcpy( s, t );
	g_free( t );
}

/* Warning: This one explodes the string. Worst-cases can make the string 3x its original size! */
/* This fuction is safe, but make sure you call it safely as well! */
void http_encode( char *s )
{
	char *t;
	int i, j;
	
	t = g_strdup( s );
	
	for( i = j = 0; t[i]; i ++, j ++ )
	{
		if( !isalnum( t[i] ) && !strchr( "._-~", t[i] ) )
		{
			sprintf( s + j, "%%%02X", ((unsigned char*)t)[i] );
			j += 2;
		}
		else
		{
			s[j] = t[i];
		}
	}
	s[j] = 0;
	
	g_free( t );
}

/* Strip newlines from a string. Modifies the string passed to it. */ 
char *strip_newlines( char *source )
{
	int i;	

	for( i = 0; source[i] != '\0'; i ++ )
		if( source[i] == '\n' || source[i] == '\r' )
			source[i] = ' ';
	
	return source;
}

/* Wrap an IPv4 address into IPv6 space. Not thread-safe... */
char *ipv6_wrap( char *src )
{
	static char dst[64];
	int i;
	
	for( i = 0; src[i]; i ++ )
		if( ( src[i] < '0' || src[i] > '9' ) && src[i] != '.' )
			break;
	
	/* Hmm, it's not even an IP... */
	if( src[i] )
		return src;
	
	g_snprintf( dst, sizeof( dst ), "::ffff:%s", src );
	
	return dst;
}

/* Unwrap an IPv4 address into IPv6 space. Thread-safe, because it's very simple. :-) */
char *ipv6_unwrap( char *src )
{
	int i;
	
	if( g_strncasecmp( src, "::ffff:", 7 ) != 0 )
		return src;
	
	for( i = 7; src[i]; i ++ )
		if( ( src[i] < '0' || src[i] > '9' ) && src[i] != '.' )
			break;
	
	/* Hmm, it's not even an IP... */
	if( src[i] )
		return src;
	
	return ( src + 7 );
}

/* Convert from one charset to another.
   
   from_cs, to_cs: Source and destination charsets
   src, dst: Source and destination strings
   size: Size if src. 0 == use strlen(). strlen() is not reliable for UNICODE/UTF16 strings though.
   maxbuf: Maximum number of bytes to write to dst
   
   Returns the number of bytes written to maxbuf or -1 on an error.
*/
signed int do_iconv( char *from_cs, char *to_cs, char *src, char *dst, size_t size, size_t maxbuf )
{
	GIConv cd;
	size_t res;
	size_t inbytesleft, outbytesleft;
	char *inbuf = src;
	char *outbuf = dst;
	
	cd = g_iconv_open( to_cs, from_cs );
	if( cd == (GIConv) -1 )
		return( -1 );
	
	inbytesleft = size ? size : strlen( src );
	outbytesleft = maxbuf - 1;
	res = g_iconv( cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft );
	*outbuf = '\0';
	g_iconv_close( cd );
	
	if( res == (size_t) -1 )
		return( -1 );
	else
		return( outbuf - dst );
}

/* A pretty reliable random number generator. Tries to use the /dev/random
   devices first, and falls back to the random number generator from libc
   when it fails. Opens randomizer devices with O_NONBLOCK to make sure a
   lack of entropy won't halt BitlBee. */
void random_bytes( unsigned char *buf, int count )
{
#ifndef _WIN32
	static int use_dev = -1;
	
	/* Actually this probing code isn't really necessary, is it? */
	if( use_dev == -1 )
	{
		if( access( "/dev/random", R_OK ) == 0 || access( "/dev/urandom", R_OK ) == 0 )
			use_dev = 1;
		else
		{
			use_dev = 0;
			srand( ( getpid() << 16 ) ^ time( NULL ) );
		}
	}
	
	if( use_dev )
	{
		int fd;
		
		/* At least on Linux, /dev/random can block if there's not
		   enough entropy. We really don't want that, so if it can't
		   give anything, use /dev/urandom instead. */
		if( ( fd = open( "/dev/random", O_RDONLY | O_NONBLOCK ) ) >= 0 )
			if( read( fd, buf, count ) == count )
			{
				close( fd );
				return;
			}
		close( fd );
		
		/* urandom isn't supposed to block at all, but just to be
		   sure. If it blocks, we'll disable use_dev and use the libc
		   randomizer instead. */
		if( ( fd = open( "/dev/urandom", O_RDONLY | O_NONBLOCK ) ) >= 0 )
			if( read( fd, buf, count ) == count )
			{
				close( fd );
				return;
			}
		close( fd );
		
		/* If /dev/random blocks once, we'll still try to use it
		   again next time. If /dev/urandom also fails for some
		   reason, stick with libc during this session. */
		
		use_dev = 0;
		srand( ( getpid() << 16 ) ^ time( NULL ) );
	}
	
	if( !use_dev )
#endif
	{
		int i;
		
		/* Possibly the LSB of rand() isn't very random on some
		   platforms. Seems okay on at least Linux and OSX though. */
		for( i = 0; i < count; i ++ )
			buf[i] = rand() & 0xff;
	}
}

int is_bool( char *value )
{
	if( *value == 0 )
		return 0;
	
	if( ( g_strcasecmp( value, "true" ) == 0 ) || ( g_strcasecmp( value, "yes" ) == 0 ) || ( g_strcasecmp( value, "on" ) == 0 ) )
		return 1;
	if( ( g_strcasecmp( value, "false" ) == 0 ) || ( g_strcasecmp( value, "no" ) == 0 ) || ( g_strcasecmp( value, "off" ) == 0 ) )
		return 1;
	
	while( *value )
		if( !isdigit( *value ) )
			return 0;
		else
			value ++;
	
	return 1;
}

int bool2int( char *value )
{
	int i;
	
	if( ( g_strcasecmp( value, "true" ) == 0 ) || ( g_strcasecmp( value, "yes" ) == 0 ) || ( g_strcasecmp( value, "on" ) == 0 ) )
		return 1;
	if( ( g_strcasecmp( value, "false" ) == 0 ) || ( g_strcasecmp( value, "no" ) == 0 ) || ( g_strcasecmp( value, "off" ) == 0 ) )
		return 0;
	
	if( sscanf( value, "%d", &i ) == 1 )
		return i;
	
	return 0;
}

struct ns_srv_reply *srv_lookup( char *service, char *protocol, char *domain )
{	
	struct ns_srv_reply *reply = NULL;
#ifdef HAVE_RESOLV_A
	char name[1024];
	unsigned char querybuf[1024];
	const unsigned char *buf;
	ns_msg nsh;
	ns_rr rr;
	int i, len, size;
	
	g_snprintf( name, sizeof( name ), "_%s._%s.%s", service, protocol, domain );
	
	if( ( size = res_query( name, ns_c_in, ns_t_srv, querybuf, sizeof( querybuf ) ) ) <= 0 )
		return NULL;
	
	if( ns_initparse( querybuf, size, &nsh ) != 0 )
		return NULL;
	
	if( ns_parserr( &nsh, ns_s_an, 0, &rr ) != 0 )
		return NULL;
	
	size = ns_rr_rdlen( rr );
	buf = ns_rr_rdata( rr );
	
	len = 0;
	for( i = 6; i < size && buf[i]; i += buf[i] + 1 )
		len += buf[i] + 1;
	
	if( i > size )
		return NULL;
	
	reply = g_malloc( sizeof( struct ns_srv_reply ) + len );
	memcpy( reply->name, buf + 7, len );
	
	for( i = buf[6]; i < len && buf[7+i]; i += buf[7+i] + 1 )
		reply->name[i] = '.';
	
	if( i > len )
	{
		g_free( reply );
		return NULL;
	}
	
	reply->prio = ( buf[0] << 8 ) | buf[1];
	reply->weight = ( buf[2] << 8 ) | buf[3];
	reply->port = ( buf[4] << 8 ) | buf[5];
#endif
	
	return reply;
}

/* Word wrapping. Yes, I know this isn't UTF-8 clean. I'm willing to take the risk. */
char *word_wrap( const char *msg, int line_len )
{
	GString *ret = g_string_sized_new( strlen( msg ) + 16 );
	
	while( strlen( msg ) > line_len )
	{
		int i;
		
		/* First try to find out if there's a newline already. Don't
		   want to add more splits than necessary. */
		for( i = line_len; i > 0 && msg[i] != '\n'; i -- );
		if( msg[i] == '\n' )
		{
			g_string_append_len( ret, msg, i + 1 );
			msg += i + 1;
			continue;
		}
		
		for( i = line_len; i > 0; i -- )
		{
			if( msg[i] == '-' )
			{
				g_string_append_len( ret, msg, i + 1 );
				g_string_append_c( ret, '\n' );
				msg += i + 1;
				break;
			}
			else if( msg[i] == ' ' )
			{
				g_string_append_len( ret, msg, i );
				g_string_append_c( ret, '\n' );
				msg += i + 1;
				break;
			}
		}
		if( i == 0 )
		{
			g_string_append_len( ret, msg, line_len );
			g_string_append_c( ret, '\n' );
			msg += line_len;
		}
	}
	g_string_append( ret, msg );
	
	return g_string_free( ret, FALSE );
}

gboolean ssl_sockerr_again( void *ssl )
{
	if( ssl )
		return ssl_errno == SSL_AGAIN;
	else
		return sockerr_again();
}

/* Returns values: -1 == Failure (base64-decoded to something unexpected)
                    0 == Okay
                    1 == Password doesn't match the hash. */
int md5_verify_password( char *password, char *hash )
{
	md5_byte_t *pass_dec = NULL;
	md5_byte_t pass_md5[16];
	md5_state_t md5_state;
	int ret = -1, i;
	
	if( base64_decode( hash, &pass_dec ) == 21 )
	{
		md5_init( &md5_state );
		md5_append( &md5_state, (md5_byte_t*) password, strlen( password ) );
		md5_append( &md5_state, (md5_byte_t*) pass_dec + 16, 5 ); /* Hmmm, salt! */
		md5_finish( &md5_state, pass_md5 );
		
		for( i = 0; i < 16; i ++ )
		{
			if( pass_dec[i] != pass_md5[i] )
			{
				ret = 1;
				break;
			}
		}
		
		/* If we reached the end of the loop, it was a match! */
		if( i == 16 )
			ret = 0;
	}
	
	g_free( pass_dec );

	return ret;
}
s="p">, "%B %d, %Y", &tm); g_string_append_printf(st, "Birthday: %s\n", ib); strftime(ib, 256, "%Y", &tm); int year = atoi(ib); time_t t = time(NULL); struct tm *lt = localtime(&t); g_string_append_printf(st, "Age: %d\n", lt->tm_year+1900-year); } g_free(sd->info_birthday); } if (sd->info_sex) { if (strlen(sd->info_sex)) { char *iptr = sd->info_sex; while (*iptr++) *iptr = tolower(*iptr); g_string_append_printf(st, "Gender: %s\n", sd->info_sex); } g_free(sd->info_sex); } if (sd->info_language) { if (strlen(sd->info_language)) { char *iptr = strchr(sd->info_language, ' '); if (iptr) iptr++; else iptr = sd->info_language; g_string_append_printf(st, "Language: %s\n", iptr); } g_free(sd->info_language); } if (sd->info_country) { if (strlen(sd->info_country)) { char *iptr = strchr(sd->info_country, ' '); if (iptr) iptr++; else iptr = sd->info_country; g_string_append_printf(st, "Country: %s\n", iptr); } g_free(sd->info_country); } if (sd->info_province) { if (strlen(sd->info_province)) g_string_append_printf(st, "Region: %s\n", sd->info_province); g_free(sd->info_province); } if (sd->info_city) { if (strlen(sd->info_city)) g_string_append_printf(st, "City: %s\n", sd->info_city); g_free(sd->info_city); } if (sd->info_homepage) { if (strlen(sd->info_homepage)) g_string_append_printf(st, "Homepage: %s\n", sd->info_homepage); g_free(sd->info_homepage); } if (sd->info_about) { if (strlen(sd->info_about)) g_string_append_printf(st, "%s\n", sd->info_about); g_free(sd->info_about); } imcb_log(ic, "%s", st->str); g_string_free(st, TRUE); } } static void skype_parse_chatmessage(struct im_connection *ic, char *line) { struct skype_data *sd = ic->proto_data; char buf[IRC_LINE_SIZE]; char *id = strchr(line, ' '); if (!++id) return; char *info = strchr(id, ' '); if (!info) return; *info = '\0'; info++; if (!strcmp(info, "STATUS RECEIVED") || !strncmp(info, "EDITED_TIMESTAMP", 16)) { /* New message ID: * (1) Request its from field * (2) Request its body * (3) Request its type * (4) Query chatname */ skype_printf(ic, "GET CHATMESSAGE %s FROM_HANDLE\n", id); if (!strcmp(info, "STATUS RECEIVED")) skype_printf(ic, "GET CHATMESSAGE %s BODY\n", id); else sd->is_edit = 1; skype_printf(ic, "GET CHATMESSAGE %s TYPE\n", id); skype_printf(ic, "GET CHATMESSAGE %s CHATNAME\n", id); } else if (!strncmp(info, "FROM_HANDLE ", 12)) { info += 12; /* New from field value. Store * it, then we can later use it * when we got the message's * body. */ g_free(sd->handle); sd->handle = g_strdup_printf("%s@skype.com", info); } else if (!strncmp(info, "EDITED_BY ", 10)) { info += 10; /* This is the same as * FROM_HANDLE, except that we * never request these lines * from Skype, we just get * them. */ g_free(sd->handle); sd->handle = g_strdup_printf("%s@skype.com", info); } else if (!strncmp(info, "BODY ", 5)) { info += 5; sd->body = g_list_append(sd->body, g_strdup(info)); } else if (!strncmp(info, "TYPE ", 5)) { info += 5; g_free(sd->type); sd->type = g_strdup(info); } else if (!strncmp(info, "CHATNAME ", 9)) { info += 9; if (sd->handle && sd->body && sd->type) { struct groupchat *gc = bee_chat_by_title(ic->bee, ic, info); int i; for (i = 0; i < g_list_length(sd->body); i++) { char *body = g_list_nth_data(sd->body, i); if (!strcmp(sd->type, "SAID") || !strcmp(sd->type, "EMOTED")) { if (!strcmp(sd->type, "SAID")) { if (!sd->is_edit) g_snprintf(buf, IRC_LINE_SIZE, "%s", body); else { g_snprintf(buf, IRC_LINE_SIZE, "%s %s", set_getstr(&ic->acc->set, "edit_prefix"), body); sd->is_edit = 0; } } else g_snprintf(buf, IRC_LINE_SIZE, "/me %s", body); if (!gc) /* Private message */ imcb_buddy_msg(ic, sd->handle, buf, 0, 0); else /* Groupchat message */ imcb_chat_msg(gc, sd->handle, buf, 0, 0); } else if (!strcmp(sd->type, "SETTOPIC") && gc) imcb_chat_topic(gc, sd->handle, body, 0); else if (!strcmp(sd->type, "LEFT") && gc) imcb_chat_remove_buddy(gc, sd->handle, NULL); } g_list_free(sd->body); sd->body = NULL; } } } static void skype_parse_call(struct im_connection *ic, char *line) { struct skype_data *sd = ic->proto_data; char *id = strchr(line, ' '); char buf[IRC_LINE_SIZE]; if (!++id) return; char *info = strchr(id, ' '); if (!info) return; *info = '\0'; info++; if (!strncmp(info, "FAILUREREASON ", 14)) sd->failurereason = atoi(strchr(info, ' ')); else if (!strcmp(info, "STATUS RINGING")) { if (sd->call_id) g_free(sd->call_id); sd->call_id = g_strdup(id); skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id); sd->call_status = SKYPE_CALL_RINGING; } else if (!strcmp(info, "STATUS MISSED")) { skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id); sd->call_status = SKYPE_CALL_MISSED; } else if (!strcmp(info, "STATUS CANCELLED")) { skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id); sd->call_status = SKYPE_CALL_CANCELLED; } else if (!strcmp(info, "STATUS FINISHED")) { skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id); sd->call_status = SKYPE_CALL_FINISHED; } else if (!strcmp(info, "STATUS REFUSED")) { skype_printf(ic, "GET CALL %s PARTNER_HANDLE\n", id); sd->call_status = SKYPE_CALL_REFUSED; } else if (!strcmp(info, "STATUS UNPLACED")) { if (sd->call_id) g_free(sd->call_id); /* Save the ID for later usage (Cancel/Finish). */ sd->call_id = g_strdup(id); sd->call_out = TRUE; } else if (!strcmp(info, "STATUS FAILED")) { imcb_error(ic, "Call failed: %s", skype_call_strerror(sd->failurereason)); sd->call_id = NULL; } else if (!strncmp(info, "DURATION ", 9)) { if (sd->call_duration) g_free(sd->call_duration); sd->call_duration = g_strdup(info+9); } else if (!strncmp(info, "PARTNER_HANDLE ", 15)) { info += 15; if (!sd->call_status) return; switch (sd->call_status) { case SKYPE_CALL_RINGING: if (sd->call_out) imcb_log(ic, "You are currently ringing " "the user %s.", info); else { g_snprintf(buf, IRC_LINE_SIZE, "The user %s is currently ringing you.", info); skype_call_ask(ic, sd->call_id, buf); } break; case SKYPE_CALL_MISSED: imcb_log(ic, "You have missed a call from user %s.", info); break; case SKYPE_CALL_CANCELLED: imcb_log(ic, "You cancelled the call to the user %s.", info); sd->call_status = 0; sd->call_out = FALSE; break; case SKYPE_CALL_REFUSED: if (sd->call_out) imcb_log(ic, "The user %s refused the call.", info); else imcb_log(ic, "You refused the call from user %s.", info); sd->call_out = FALSE; break; case SKYPE_CALL_FINISHED: if (sd->call_duration) imcb_log(ic, "You finished the call to the user %s " "(duration: %s seconds).", info, sd->call_duration); else imcb_log(ic, "You finished the call to the user %s.", info); sd->call_out = FALSE; break; default: /* Don't be noisy, ignore other statuses for now. */ break; } sd->call_status = 0; } } static void skype_parse_filetransfer(struct im_connection *ic, char *line) { struct skype_data *sd = ic->proto_data; char *id = strchr(line, ' '); if (!++id) return; char *info = strchr(id, ' '); if (!info) return; *info = '\0'; info++; if (!strcmp(info, "STATUS NEW")) { skype_printf(ic, "GET FILETRANSFER %s PARTNER_HANDLE\n", id); sd->filetransfer_status = SKYPE_FILETRANSFER_NEW; } else if (!strcmp(info, "STATUS FAILED")) { skype_printf(ic, "GET FILETRANSFER %s PARTNER_HANDLE\n", id); sd->filetransfer_status = SKYPE_FILETRANSFER_FAILED; } else if (!strncmp(info, "PARTNER_HANDLE ", 15)) { info += 15; if (!sd->filetransfer_status) return; switch (sd->filetransfer_status) { case SKYPE_FILETRANSFER_NEW: imcb_log(ic, "The user %s offered a new file for you.", info); break; case SKYPE_FILETRANSFER_FAILED: imcb_log(ic, "Failed to transfer file from user %s.", info); break; } sd->filetransfer_status = 0; } } static struct skype_group *skype_group_by_id(struct im_connection *ic, int id) { struct skype_data *sd = ic->proto_data; int i; for (i = 0; i < g_list_length(sd->groups); i++) { struct skype_group *sg = (struct skype_group *)g_list_nth_data(sd->groups, i); if (sg->id == id) return sg; } return NULL; } static void skype_group_free(struct skype_group *sg, gboolean usersonly) { int i; for (i = 0; i < g_list_length(sg->users); i++) { char *user = g_list_nth_data(sg->users, i); g_free(user); } sg->users = NULL; if (usersonly) return; g_free(sg->name); g_free(sg); } /* Update the group of each user in this group */ static void skype_group_users(struct im_connection *ic, struct skype_group *sg) { int i; for (i = 0; i < g_list_length(sg->users); i++) { char *user = g_list_nth_data(sg->users, i); char *buf = g_strdup_printf("%s@skype.com", user); imcb_add_buddy(ic, buf, sg->name); g_free(buf); } } static void skype_parse_group(struct im_connection *ic, char *line) { struct skype_data *sd = ic->proto_data; char *id = strchr(line, ' '); if (!++id) return; char *info = strchr(id, ' '); if (!info) return; *info = '\0'; info++; if (!strncmp(info, "DISPLAYNAME ", 12)) { info += 12; /* Name given for a group ID: try to update it or insert a new * one if not found */ struct skype_group *sg = skype_group_by_id(ic, atoi(id)); if (sg) { g_free(sg->name); sg->name = g_strdup(info); } else { sg = g_new0(struct skype_group, 1); sg->id = atoi(id); sg->name = g_strdup(info); sd->groups = g_list_append(sd->groups, sg); } } else if (!strncmp(info, "USERS ", 6)) { struct skype_group *sg = skype_group_by_id(ic, atoi(id)); if (sg) { char **i; char **users = g_strsplit(info + 6, ", ", 0); skype_group_free(sg, TRUE); i = users; while (*i) { sg->users = g_list_append(sg->users, g_strdup(*i)); i++; } g_strfreev(users); skype_group_users(ic, sg); } else log_message(LOGLVL_ERROR, "No skype group with id %s. That's probably a bug.", id); } else if (!strncmp(info, "NROFUSERS ", 10)) { if (!sd->pending_user) { /* Number of users changed in this group, query its type to see * if it's a custom one we should care about. */ skype_printf(ic, "GET GROUP %s TYPE", id); return; } /* This is a newly created group, we have a single user * to add. */ struct skype_group *sg = skype_group_by_id(ic, atoi(id)); if (sg) { skype_printf(ic, "ALTER GROUP %d ADDUSER %s", sg->id, sd->pending_user); g_free(sd->pending_user); sd->pending_user = NULL; } else log_message(LOGLVL_ERROR, "No skype group with id %s. That's probably a bug.", id); } else if (!strcmp(info, "TYPE CUSTOM_GROUP")) /* This one is interesting, query its users. */ skype_printf(ic, "GET GROUP %s USERS", id); } static void skype_parse_chat(struct im_connection *ic, char *line) { struct skype_data *sd = ic->proto_data; char buf[IRC_LINE_SIZE]; char *id = strchr(line, ' '); if (!++id) return; struct groupchat *gc; char *info = strchr(id, ' '); if (!info) return; *info = '\0'; info++; /* Remove fake chat if we created one in skype_chat_with() */ gc = bee_chat_by_title(ic->bee, ic, ""); if (gc) imcb_chat_free(gc); if (!strcmp(info, "STATUS MULTI_SUBSCRIBED")) { gc = bee_chat_by_title(ic->bee, ic, id); if (!gc) { gc = imcb_chat_new(ic, id); imcb_chat_name_hint(gc, id); } skype_printf(ic, "GET CHAT %s ADDER\n", id); skype_printf(ic, "GET CHAT %s TOPIC\n", id); } else if (!strcmp(info, "STATUS DIALOG") && sd->groupchat_with) { gc = imcb_chat_new(ic, id); imcb_chat_name_hint(gc, id); /* According to the docs this * is necessary. However it * does not seem the situation * and it would open an extra * window on our client, so * just leave it out. */ /*skype_printf(ic, "OPEN CHAT %s\n", id);*/ g_snprintf(buf, IRC_LINE_SIZE, "%s@skype.com", sd->groupchat_with); imcb_chat_add_buddy(gc, buf); imcb_chat_add_buddy(gc, sd->username); g_free(sd->groupchat_with); sd->groupchat_with = NULL; skype_printf(ic, "GET CHAT %s ADDER\n", id); skype_printf(ic, "GET CHAT %s TOPIC\n", id); } else if (!strcmp(info, "STATUS UNSUBSCRIBED")) { gc = bee_chat_by_title(ic->bee, ic, id); if (gc) gc->data = (void *)FALSE; } else if (!strncmp(info, "ADDER ", 6)) { info += 6; g_free(sd->adder); sd->adder = g_strdup_printf("%s@skype.com", info); } else if (!strncmp(info, "TOPIC ", 6)) { info += 6; gc = bee_chat_by_title(ic->bee, ic, id); if (gc && (sd->adder || sd->topic_wait)) { if (sd->topic_wait) { sd->adder = g_strdup(sd->username); sd->topic_wait = 0; } imcb_chat_topic(gc, sd->adder, info, 0); g_free(sd->adder); sd->adder = NULL; } } else if (!strncmp(info, "ACTIVEMEMBERS ", 14)) { info += 14; gc = bee_chat_by_title(ic->bee, ic, id); /* Hack! We set ->data to TRUE * while we're on the channel * so that we won't rejoin * after a /part. */ if (!gc || gc->data) return; char **members = g_strsplit(info, " ", 0); int i; for (i = 0; members[i]; i++) { if (!strcmp(members[i], sd->username)) continue; g_snprintf(buf, IRC_LINE_SIZE, "%s@skype.com", members[i]); if (!g_list_find_custom(gc->in_room, buf, (GCompareFunc)strcmp)) imcb_chat_add_buddy(gc, buf); } imcb_chat_add_buddy(gc, sd->username); g_strfreev(members); } } static void skype_parse_password(struct im_connection *ic, char *line) { if (!strncmp(line+9, "OK", 2)) imcb_connected(ic); else { imcb_error(ic, "Authentication Failed"); imc_logout(ic, TRUE); } } static void skype_parse_profile(struct im_connection *ic, char *line) { imcb_log(ic, "SkypeOut balance value is '%s'.", line+21); } static void skype_parse_ping(struct im_connection *ic, char *line) { /* Unused parameter */ line = line; skype_printf(ic, "PONG\n"); } static void skype_parse_chats(struct im_connection *ic, char *line) { char **i; char **chats = g_strsplit(line + 6, ", ", 0); i = chats; while (*i) { skype_printf(ic, "GET CHAT %s STATUS\n", *i); skype_printf(ic, "GET CHAT %s ACTIVEMEMBERS\n", *i); i++; } g_strfreev(chats); } static void skype_parse_groups(struct im_connection *ic, char *line) { char **i; char **groups = g_strsplit(line + 7, ", ", 0); i = groups; while (*i) { skype_printf(ic, "GET GROUP %s DISPLAYNAME\n", *i); skype_printf(ic, "GET GROUP %s USERS\n", *i); i++; } g_strfreev(groups); } static void skype_parse_alter_group(struct im_connection *ic, char *line) { char *id = line + strlen("ALTER GROUP"); if (!++id) return; char *info = strchr(id, ' '); if (!info) return; *info = '\0'; info++; if (!strncmp(info, "ADDUSER ", 8)) { struct skype_group *sg = skype_group_by_id(ic, atoi(id)); info += 8; if (sg) { char *buf = g_strdup_printf("%s@skype.com", info); sg->users = g_list_append(sg->users, g_strdup(info)); imcb_add_buddy(ic, buf, sg->name); g_free(buf); } else log_message(LOGLVL_ERROR, "No skype group with id %s. That's probably a bug.", id); } } typedef void (*skype_parser)(struct im_connection *ic, char *line); static gboolean skype_read_callback(gpointer data, gint fd, b_input_condition cond) { struct im_connection *ic = data; struct skype_data *sd = ic->proto_data; char buf[IRC_LINE_SIZE]; int st, i; char **lines, **lineptr, *line; static struct parse_map { char *k; skype_parser v; } parsers[] = { { "USERS ", skype_parse_users }, { "USER ", skype_parse_user }, { "CHATMESSAGE ", skype_parse_chatmessage }, { "CALL ", skype_parse_call }, { "FILETRANSFER ", skype_parse_filetransfer }, { "CHAT ", skype_parse_chat }, { "GROUP ", skype_parse_group }, { "PASSWORD ", skype_parse_password }, { "PROFILE PSTN_BALANCE ", skype_parse_profile }, { "PING", skype_parse_ping }, { "CHATS ", skype_parse_chats }, { "GROUPS ", skype_parse_groups }, { "ALTER GROUP ", skype_parse_alter_group }, }; /* Unused parameters */ fd = fd; cond = cond; if (!sd || sd->fd == -1) return FALSE; /* Read the whole data. */ st = ssl_read(sd->ssl, buf, sizeof(buf)); if (st > 0) { buf[st] = '\0'; /* Then split it up to lines. */ lines = g_strsplit(buf, "\n", 0); lineptr = lines; while ((line = *lineptr)) { if (!strlen(line)) break; if (set_getbool(&ic->acc->set, "skypeconsole_receive")) imcb_buddy_msg(ic, "skypeconsole", line, 0, 0); for (i = 0; i < ARRAY_SIZE(parsers); i++) if (!strncmp(line, parsers[i].k, strlen(parsers[i].k))) { parsers[i].v(ic, line); break; } lineptr++; } g_strfreev(lines); } else if (st == 0 || (st < 0 && !sockerr_again())) { closesocket(sd->fd); sd->fd = -1; imcb_error(ic, "Error while reading from server"); imc_logout(ic, TRUE); return FALSE; } return TRUE; } gboolean skype_start_stream(struct im_connection *ic) { struct skype_data *sd = ic->proto_data; int st; if (!sd) return FALSE; if (sd->bfd <= 0) sd->bfd = b_input_add(sd->fd, B_EV_IO_READ, skype_read_callback, ic); /* Log in */ skype_printf(ic, "USERNAME %s\n", ic->acc->user); skype_printf(ic, "PASSWORD %s\n", ic->acc->pass); /* This will download all buddies and groups. */ st = skype_printf(ic, "SEARCH GROUPS CUSTOM\n"); skype_printf(ic, "SEARCH FRIENDS\n"); skype_printf(ic, "SET USERSTATUS ONLINE\n"); /* Auto join to bookmarked chats if requested.*/ if (set_getbool(&ic->acc->set, "auto_join")) skype_printf(ic, "SEARCH BOOKMARKEDCHATS\n"); return st; } gboolean skype_connected(gpointer data, int returncode, void *source, b_input_condition cond) { struct im_connection *ic = data; struct skype_data *sd = ic->proto_data; /* Unused parameter */ cond = cond; if (!source) { sd->ssl = NULL; imcb_error(ic, "Could not connect to server"); imc_logout(ic, TRUE); return FALSE; } imcb_log(ic, "Connected to server, logging in"); return skype_start_stream(ic); } static void skype_login(account_t *acc) { struct im_connection *ic = imcb_new(acc); struct skype_data *sd = g_new0(struct skype_data, 1); ic->proto_data = sd; imcb_log(ic, "Connecting"); sd->ssl = ssl_connect(set_getstr(&acc->set, "server"), set_getint(&acc->set, "port"), skype_connected, ic); sd->fd = sd->ssl ? ssl_getfd(sd->ssl) : -1; sd->username = g_strdup(acc->user); sd->ic = ic; if (set_getbool(&acc->set, "skypeconsole")) imcb_add_buddy(ic, "skypeconsole", NULL); } static void skype_logout(struct im_connection *ic) { struct skype_data *sd = ic->proto_data; int i; skype_printf(ic, "SET USERSTATUS OFFLINE\n"); while( ic->groupchats ) imcb_chat_free(ic->groupchats->data); for (i = 0; i < g_list_length(sd->groups); i++) { struct skype_group *sg = (struct skype_group *)g_list_nth_data(sd->groups, i); skype_group_free(sg, FALSE); } g_free(sd->username); g_free(sd->handle); g_free(sd); ic->proto_data = NULL; } static int skype_buddy_msg(struct im_connection *ic, char *who, char *message, int flags) { char *ptr, *nick; int st; /* Unused parameter */ flags = flags; nick = g_strdup(who); ptr = strchr(nick, '@'); if (ptr) *ptr = '\0'; if (!strncmp(who, "skypeconsole", 12)) st = skype_printf(ic, "%s\n", message); else st = skype_printf(ic, "MESSAGE %s %s\n", nick, message); g_free(nick); return st; } const struct skype_away_state *skype_away_state_by_name(char *name) { int i; for (i = 0; skype_away_state_list[i].full_name; i++) if (g_strcasecmp(skype_away_state_list[i].full_name, name) == 0) return skype_away_state_list + i; return NULL; } static void skype_set_away(struct im_connection *ic, char *state_txt, char *message) { const struct skype_away_state *state; /* Unused parameter */ message = message; if (state_txt == NULL) state = skype_away_state_by_name("Online"); else state = skype_away_state_by_name(state_txt); skype_printf(ic, "SET USERSTATUS %s\n", state->code); } static GList *skype_away_states(struct im_connection *ic) { static GList *l; int i; /* Unused parameter */ ic = ic; if (l == NULL) for (i = 0; skype_away_state_list[i].full_name; i++) l = g_list_append(l, (void *)skype_away_state_list[i].full_name); return l; } static char *skype_set_display_name(set_t *set, char *value) { account_t *acc = set->data; struct im_connection *ic = acc->ic; skype_printf(ic, "SET PROFILE FULLNAME %s", value); return value; } static char *skype_set_balance(set_t *set, char *value) { account_t *acc = set->data; struct im_connection *ic = acc->ic; skype_printf(ic, "GET PROFILE PSTN_BALANCE"); return value; } static void skype_call(struct im_connection *ic, char *value) { char *nick = g_strdup(value); char *ptr = strchr(nick, '@'); if (ptr) *ptr = '\0'; skype_printf(ic, "CALL %s", nick); g_free(nick); } static void skype_hangup(struct im_connection *ic) { struct skype_data *sd = ic->proto_data; if (sd->call_id) { skype_printf(ic, "SET CALL %s STATUS FINISHED", sd->call_id); g_free(sd->call_id); sd->call_id = 0; } else imcb_error(ic, "There are no active calls currently."); } static char *skype_set_call(set_t *set, char *value) { account_t *acc = set->data; struct im_connection *ic = acc->ic; if (value) skype_call(ic, value); else skype_hangup(ic); return value; } static void skype_add_buddy(struct im_connection *ic, char *who, char *group) { struct skype_data *sd = ic->proto_data; char *nick, *ptr; nick = g_strdup(who); ptr = strchr(nick, '@'); if (ptr) *ptr = '\0'; if (!group) { skype_printf(ic, "SET USER %s BUDDYSTATUS 2 Please authorize me\n", nick); g_free(nick); } else { struct skype_group *sg = skype_group_by_name(ic, group); if (!sg) { /* No such group, we need to create it, then have to * add the user once it's created. */ skype_printf(ic, "CREATE GROUP %s", group); sd->pending_user = g_strdup(nick); } else { skype_printf(ic, "ALTER GROUP %d ADDUSER %s", sg->id, nick); } } } static void skype_remove_buddy(struct im_connection *ic, char *who, char *group) { char *nick, *ptr; /* Unused parameter */ group = group; nick = g_strdup(who); ptr = strchr(nick, '@'); if (ptr) *ptr = '\0'; skype_printf(ic, "SET USER %s BUDDYSTATUS 1\n", nick); g_free(nick); } void skype_chat_msg(struct groupchat *gc, char *message, int flags) { struct im_connection *ic = gc->ic; /* Unused parameter */ flags = flags; skype_printf(ic, "CHATMESSAGE %s %s\n", gc->title, message); } void skype_chat_leave(struct groupchat *gc) { struct im_connection *ic = gc->ic; skype_printf(ic, "ALTER CHAT %s LEAVE\n", gc->title); gc->data = (void *)TRUE; } void skype_chat_invite(struct groupchat *gc, char *who, char *message) { struct im_connection *ic = gc->ic; char *ptr, *nick; nick = g_strdup(who); ptr = strchr(nick, '@'); if (ptr) *ptr = '\0'; skype_printf(ic, "ALTER CHAT %s ADDMEMBERS %s\n", gc->title, nick); g_free(nick); } void skype_chat_topic(struct groupchat *gc, char *message) { struct im_connection *ic = gc->ic; struct skype_data *sd = ic->proto_data; skype_printf(ic, "ALTER CHAT %s SETTOPIC %s\n", gc->title, message); sd->topic_wait = 1; } struct groupchat *skype_chat_with(struct im_connection *ic, char *who) { struct skype_data *sd = ic->proto_data; char *ptr, *nick; nick = g_strdup(who); ptr = strchr(nick, '@'); if (ptr) *ptr = '\0'; skype_printf(ic, "CHAT CREATE %s\n", nick); sd->groupchat_with = g_strdup(nick); g_free(nick); /* We create a fake chat for now. We will replace it with a real one in * the real callback. */ return imcb_chat_new(ic, ""); } static void skype_get_info(struct im_connection *ic, char *who) { char *ptr, *nick; nick = g_strdup(who); ptr = strchr(nick, '@'); if (ptr) *ptr = '\0'; skype_printf(ic, "GET USER %s FULLNAME\n", nick); skype_printf(ic, "GET USER %s PHONE_HOME\n", nick); skype_printf(ic, "GET USER %s PHONE_OFFICE\n", nick); skype_printf(ic, "GET USER %s PHONE_MOBILE\n", nick); skype_printf(ic, "GET USER %s NROF_AUTHED_BUDDIES\n", nick); skype_printf(ic, "GET USER %s TIMEZONE\n", nick); skype_printf(ic, "GET USER %s LASTONLINETIMESTAMP\n", nick); skype_printf(ic, "GET USER %s BIRTHDAY\n", nick); skype_printf(ic, "GET USER %s SEX\n", nick); skype_printf(ic, "GET USER %s LANGUAGE\n", nick); skype_printf(ic, "GET USER %s COUNTRY\n", nick); skype_printf(ic, "GET USER %s PROVINCE\n", nick); skype_printf(ic, "GET USER %s CITY\n", nick); skype_printf(ic, "GET USER %s HOMEPAGE\n", nick); skype_printf(ic, "GET USER %s ABOUT\n", nick); } static void skype_set_my_name(struct im_connection *ic, char *info) { skype_set_display_name(set_find(&ic->acc->set, "display_name"), info); } static void skype_init(account_t *acc) { set_t *s; s = set_add(&acc->set, "server", SKYPE_DEFAULT_SERVER, set_eval_account, acc); s->flags |= ACC_SET_OFFLINE_ONLY; s = set_add(&acc->set, "port", SKYPE_DEFAULT_PORT, set_eval_int, acc); s->flags |= ACC_SET_OFFLINE_ONLY; s = set_add(&acc->set, "display_name", NULL, skype_set_display_name, acc); s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY; s = set_add(&acc->set, "call", NULL, skype_set_call, acc); s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY; s = set_add(&acc->set, "balance", NULL, skype_set_balance, acc); s->flags |= ACC_SET_NOSAVE | ACC_SET_ONLINE_ONLY; s = set_add(&acc->set, "skypeout_offline", "true", set_eval_bool, acc); s = set_add(&acc->set, "skypeconsole", "false", set_eval_bool, acc); s->flags |= ACC_SET_OFFLINE_ONLY; s = set_add(&acc->set, "skypeconsole_receive", "false", set_eval_bool, acc); s->flags |= ACC_SET_OFFLINE_ONLY; s = set_add(&acc->set, "auto_join", "false", set_eval_bool, acc); s->flags |= ACC_SET_OFFLINE_ONLY; s = set_add(&acc->set, "test_join", "false", set_eval_bool, acc); s->flags |= ACC_SET_OFFLINE_ONLY; s = set_add(&acc->set, "show_moods", "false", set_eval_bool, acc); s = set_add(&acc->set, "edit_prefix", "EDIT:", NULL, acc); } #if BITLBEE_VERSION_CODE > BITLBEE_VER(3, 0, 1) GList *skype_buddy_action_list(bee_user_t *bu) { static GList *ret; /* Unused parameter */ bu = bu; if (ret == NULL) { static const struct buddy_action ba[3] = { {"CALL", "Initiate a call" }, {"HANGUP", "Hang up a call" }, }; ret = g_list_prepend(ret, (void *) ba + 0); } return ret; } void *skype_buddy_action(struct bee_user *bu, const char *action, char * const args[], void *data) { /* Unused parameters */ args = args; data = data; if (!g_strcasecmp(action, "CALL")) skype_call(bu->ic, bu->handle); else if (!g_strcasecmp(action, "HANGUP")) skype_hangup(bu->ic); return NULL; } #endif void init_plugin(void) { struct prpl *ret = g_new0(struct prpl, 1); ret->name = "skype"; ret->login = skype_login; ret->init = skype_init; ret->logout = skype_logout; ret->buddy_msg = skype_buddy_msg; ret->get_info = skype_get_info; ret->set_my_name = skype_set_my_name; ret->away_states = skype_away_states; ret->set_away = skype_set_away; ret->add_buddy = skype_add_buddy; ret->remove_buddy = skype_remove_buddy; ret->chat_msg = skype_chat_msg; ret->chat_leave = skype_chat_leave; ret->chat_invite = skype_chat_invite; ret->chat_with = skype_chat_with; ret->handle_cmp = g_strcasecmp; ret->chat_topic = skype_chat_topic; #if BITLBEE_VERSION_CODE > BITLBEE_VER(3, 0, 1) ret->buddy_action_list = skype_buddy_action_list; ret->buddy_action = skype_buddy_action; #endif register_protocol(ret); }