2005-12-11 20:11:22 +00:00
//Released under the terms of the gpl as this file uses a bit of quake derived code. All sections of the like are marked as such
2013-07-13 12:14:32 +00:00
/*
Network limitations :
googletalk :
username : same as gmail ( foobar @ gmail . com ) .
FIXME : need to test foobar @ googlemail . com
auth mechanism : oauth2 ( tls + nontls ) or plain ( tls - only ) . no digests supported , so mitm can easily grab your password if they use certificate authority hackery , so DO NOT log in from work .
oauth2 : I ' ve registered a clientid for use with googletalk ' s network , but the whole web - browser - is - required crap makes it near unusable . We ' ll try it if they omit a password .
otherwise a complete implementation .
2013-11-21 23:02:28 +00:00
other users appear unresponsive and permanently away . this is a wtf on google ' s part and not something I can trivially work around . these people are really offline but have previously used ' google hangouts ' , and google insist on the UI nightmare infecting other clients too .
appears to hack avatar vcards into all presence messages , which is just an interesting thing to note as it seems to keep fucking up resulting in extra queries for avatar images .
2013-07-13 12:14:32 +00:00
facebook :
username : foobar @ chat . facebook . com
auth mechanism : digest - md5 , x - facebook - platform .
gateway implementation : no arbitary iq support ( no invite / join / voice ) .
no roster control
completely untested . I ' ve no interest in signing up to be tracked constantly ( but somehow google is okay . . . go figure . . . I guess I ' m just trying to avoid a double - whammy )
oauth2 : no idea where to register a clientid , or what the correct addresses are . a google search implies they don ' t do refresh tokens properly . sticking with digest - md5 should work .
2013-11-21 23:02:28 +00:00
* should * work for chat .
2013-07-13 12:14:32 +00:00
msn :
username : foobar @ messenger . live . com ( NOT foobar @ live . com - this will timeout )
auth mechansim : x - messenger - oath ONLY
non - standard unusable crap .
uses incorrect certificates . any client that doesn ' t warn about that is buggy as fuck .
probably doesn ' t have iq support , no idea , can ' t log in to test that
requires annoying see - other - host redirection .
no roster control
stun servers are listed in srv records for live . com and messanger . live . com but not messenger . live . com . retards .
oauth2 : too lazy to register a clientid . stupid crap . I hate having to register everywhere .
ejabberd :
auth mechanism : digest - md5 , scram - sha1 , plain .
complete implementation . no issues .
may be lacking srv entries , depends on installation .
2013-07-14 16:39:21 +00:00
may have self - signed certificate issues , depends on installation .
2013-07-13 12:14:32 +00:00
client compat :
2013-11-21 23:02:28 +00:00
hangouts :
UI nightmare infects the entire network and thus other clients also .
voip not supported . does not advertise any extensions and thus no voip .
no file transfer support .
2013-07-13 12:14:32 +00:00
googletalk :
2013-11-21 23:02:28 +00:00
impossible to download from google any more . completely unsupported .
implements old version of jingle . voice calls appear to not work .
does not support SI file transfer .
2013-07-13 12:14:32 +00:00
not tested by me .
pidgin :
2013-11-21 23:02:28 +00:00
( linux ) has issues with jingle + ice , and can easily be made to crash . voip uses speex . pidgin ' s ice seems vulnerable to dropped packets .
2013-07-13 12:14:32 +00:00
( windows ) doesn ' t support voice calls
2013-11-21 23:02:28 +00:00
file transfer works .
2013-07-13 12:14:32 +00:00
otherwise works .
*/
2013-08-21 07:42:42 +00:00
# include "xmpp.h"
2019-09-04 07:59:40 +00:00
# include <time.h>
static plugsubconsolefuncs_t * confuncs ;
static plug2dfuncs_t * drawfuncs ; //needed for avatars.
plugnetfuncs_t * netfuncs ;
plugfsfuncs_t * filefuncs ;
static plugclientfuncs_t * clientfuncs ; //for more accurate presence info.
static struct
{
int width ;
int height ;
} pvid ;
2013-06-23 02:33:52 +00:00
2017-09-20 11:27:13 +00:00
//#define USE_GOOGLE_MAIL_NOTIFY
2015-06-04 06:15:14 +00:00
# ifdef DEFAULTDOMAIN
# define EXAMPLEDOMAIN DEFAULTDOMAIN //used in examples / default text field (but not otherwise assumed when omitted)
# else
2017-09-20 11:27:13 +00:00
# define EXAMPLEDOMAIN "example.com" //used in examples
2015-06-04 06:15:14 +00:00
# endif
2013-06-23 02:33:52 +00:00
2013-07-13 12:14:32 +00:00
# ifdef JINGLE
2013-06-29 16:01:07 +00:00
icefuncs_t * piceapi ;
2013-07-13 12:14:32 +00:00
# endif
2019-09-04 07:59:40 +00:00
static qboolean jclient_needreadconfig ;
2021-06-21 13:36:30 +00:00
static qboolean jclient_configdirty ;
2019-09-04 07:59:40 +00:00
static qboolean jclient_updatebuddylist ;
static jclient_t * jclient_action_cl ;
static buddy_t * jclient_action_buddy ;
static enum
2015-04-27 06:19:33 +00:00
{
ACT_NONE ,
ACT_OAUTH ,
ACT_NEWACCOUNT ,
2017-09-20 11:27:13 +00:00
ACT_SETAUSERNAME ,
ACT_SETADOMAIN ,
ACT_SETASERVER ,
ACT_SETARESOURCE ,
ACT_SETAPASSWORD ,
2015-04-27 06:19:33 +00:00
ACT_ADDFRIEND ,
2017-09-20 11:27:13 +00:00
ACT_SETBALIAS ,
2015-04-27 06:19:33 +00:00
} jclient_action ;
# define BUDDYLISTTITLE "Buddy List"
2017-09-20 11:27:13 +00:00
# define COL_NAME_THEM "^1" //red
# define COL_NAME_US "^5" //cyan
# define COL_TEXT_THEM "^7" //white
# define COL_TEXT_US "^3" //yellow
# define IMG_FB_THEM "gfx / menudot1.lmp"
# define IMG_FB_US "gfx / menuplyr.lmp"
2005-12-11 20:11:22 +00:00
# define Q_strncpyz(o, i, l) do {strncpy(o, i, l-1);o[l-1]='\0';}while(0)
2019-09-04 07:59:40 +00:00
static qboolean ( * Con_TrySubPrint ) ( const char * conname , const char * message ) ;
qboolean Fallback_ConPrint ( const char * conname , const char * message )
2013-03-31 04:21:08 +00:00
{
2019-09-04 07:59:40 +00:00
plugfuncs - > Print ( message ) ;
return true ;
2013-03-31 04:21:08 +00:00
}
2005-12-11 20:11:22 +00:00
2017-10-12 12:02:25 +00:00
void Con_SubPrintf ( const char * subname , const char * format , . . . )
2005-12-11 20:11:22 +00:00
{
va_list argptr ;
static char string [ 1024 ] ;
va_start ( argptr , format ) ;
2013-05-11 14:02:55 +00:00
Q_vsnprintf ( string , sizeof ( string ) , format , argptr ) ;
2005-12-11 20:11:22 +00:00
va_end ( argptr ) ;
2013-03-31 04:21:08 +00:00
Con_TrySubPrint ( subname , string ) ;
2005-12-11 20:11:22 +00:00
}
//porting zone:
# define COLOURWHITE "^7" // word
2013-06-23 02:33:52 +00:00
# define COMMANDPREFIX "xmpp"
# define COMMANDPREFIX2 "jab"
# define COMMANDPREFIX3 "jabbercl"
2005-12-11 20:11:22 +00:00
2013-08-21 07:42:42 +00:00
static char * JCL_ParseOut ( char * data , char * buf , int bufsize ) //GPL: this is taken out of quake
2005-12-11 20:11:22 +00:00
{
int c ;
int len ;
len = 0 ;
2013-06-23 02:33:52 +00:00
buf [ 0 ] = 0 ;
2005-12-11 20:11:22 +00:00
if ( ! data )
return NULL ;
// skip whitespace
while ( ( c = * data ) < = ' ' )
{
if ( c = = 0 )
return NULL ; // end of file;
data + + ;
}
// handle quoted strings specially
if ( c = = ' \" ' )
{
data + + ;
while ( 1 )
{
2013-06-23 02:33:52 +00:00
if ( len > = bufsize - 1 )
2005-12-11 20:11:22 +00:00
return data ;
c = * data + + ;
if ( c = = ' \" ' | | ! c )
{
2013-06-23 02:33:52 +00:00
buf [ len ] = 0 ;
2005-12-11 20:11:22 +00:00
return data ;
}
2013-06-23 02:33:52 +00:00
buf [ len ] = c ;
2005-12-11 20:11:22 +00:00
len + + ;
}
}
// parse a regular word
do
{
2013-06-23 02:33:52 +00:00
if ( len > = bufsize - 1 )
2005-12-11 20:11:22 +00:00
return data ;
2013-06-23 02:33:52 +00:00
buf [ len ] = c ;
2005-12-11 20:11:22 +00:00
data + + ;
len + + ;
c = * data ;
} while ( c > 32 ) ;
2013-06-23 02:33:52 +00:00
buf [ len ] = 0 ;
2005-12-11 20:11:22 +00:00
return data ;
}
2017-10-12 12:02:25 +00:00
char * JCL_Info_ValueForKey ( char * s , const char * key , char * valuebuf , int valuelen ) //GPL: ripped from quake
2013-06-29 16:01:07 +00:00
{
char pkey [ 1024 ] ;
char * o ;
if ( * s = = ' \\ ' )
s + + ;
while ( 1 )
{
o = pkey ;
while ( * s ! = ' \\ ' )
{
if ( ! * s )
{
* valuebuf = ' \0 ' ;
return valuebuf ;
}
* o + + = * s + + ;
if ( o + 2 > = pkey + sizeof ( pkey ) ) //hrm. hackers at work..
{
* valuebuf = ' \0 ' ;
return valuebuf ;
}
}
* o = 0 ;
s + + ;
o = valuebuf ;
while ( * s ! = ' \\ ' & & * s )
{
if ( ! * s )
{
* valuebuf = ' \0 ' ;
return valuebuf ;
}
* o + + = * s + + ;
if ( o + 2 > = valuebuf + valuelen ) //hrm. hackers at work..
{
* valuebuf = ' \0 ' ;
return valuebuf ;
}
}
* o = 0 ;
if ( ! strcmp ( key , pkey ) )
return valuebuf ;
2005-12-11 20:11:22 +00:00
2013-06-29 16:01:07 +00:00
if ( ! * s )
{
* valuebuf = ' \0 ' ;
return valuebuf ;
}
s + + ;
}
}
2005-12-11 20:11:22 +00:00
2017-10-12 12:02:25 +00:00
/*
this is a fairly basic implementation .
don ' t expect it to do much .
You can probably get a better version from somewhere .
This has been tweaked to do xml markup in % s . Use % + s if you want to include xml - formatted text as - is .
*/
int Q_vsnprintxf ( char * buffer , size_t maxlen , const char * format , va_list vargs )
{
int tokens = 0 ;
char * string ;
char tempbuffer [ 64 ] ;
char sign ;
unsigned int _uint ;
int _int ;
float _float ;
int i ;
int use0s ;
int width , useprepad , plus ;
int precision ;
if ( ! maxlen )
return 0 ;
maxlen - - ;
while ( * format )
{
switch ( * format )
{
case ' % ' :
plus = 0 ;
width = 0 ;
precision = - 1 ;
useprepad = 0 ;
use0s = 0 ;
retry :
switch ( * ( + + format ) )
{
case ' - ' :
useprepad = true ;
goto retry ;
case ' + ' :
plus = true ;
goto retry ;
case ' . ' :
precision = 0 ;
while ( format [ 1 ] > = ' 0 ' & & format [ 1 ] < = ' 9 ' )
precision = precision * 10 + * + + format - ' 0 ' ;
goto retry ;
case ' 0 ' :
if ( ! width )
{
use0s = true ;
goto retry ;
}
case ' 1 ' :
case ' 2 ' :
case ' 3 ' :
case ' 4 ' :
case ' 5 ' :
case ' 6 ' :
case ' 7 ' :
case ' 8 ' :
case ' 9 ' :
width = width * 10 + * format - ' 0 ' ;
goto retry ;
case ' % ' : /*emit a %*/
if ( maxlen - - = = 0 )
{ * buffer + + = ' \0 ' ; return tokens ; }
* buffer + + = * format ;
break ;
case ' s ' :
string = va_arg ( vargs , char * ) ;
if ( ! string )
string = " (null) " ;
if ( ! plus )
{
while ( * string )
{
char * rep ;
size_t replen ;
char c = * string + + ;
switch ( c )
{
default :
if ( maxlen - - = = 0 )
{ * buffer + + = ' \0 ' ; return tokens ; }
* buffer + + = c ;
continue ;
case ' < ' : rep = " < " ; break ;
case ' > ' : rep = " > " ; break ;
case ' & ' : rep = " & " ; break ;
case ' \' ' : rep = " ' " ; break ;
case ' \" ' : rep = " " " ; break ;
}
replen = strlen ( rep ) ;
if ( maxlen < replen )
{ * buffer + + = ' \0 ' ; return tokens ; }
maxlen - = replen ;
memcpy ( buffer , rep , replen ) ;
buffer + = replen ;
}
}
else if ( width )
{
while ( * string & & width - - )
{
if ( maxlen - - = = 0 )
{ * buffer + + = ' \0 ' ; return tokens ; }
* buffer + + = * string + + ;
}
}
else
{
while ( * string )
{
if ( maxlen - - = = 0 )
{ * buffer + + = ' \0 ' ; return tokens ; }
* buffer + + = * string + + ;
}
}
tokens + + ;
break ;
/*case 'c':
_int = va_arg ( vargs , int ) ;
if ( maxlen - - = = 0 )
{ * buffer + + = ' \0 ' ; return tokens ; }
* buffer + + = _int ;
tokens + + ;
break ; */
case ' p ' :
if ( 1 )
_uint = ( size_t ) va_arg ( vargs , void * ) ;
else
case ' x ' :
_uint = va_arg ( vargs , unsigned int ) ;
i = sizeof ( tempbuffer ) - 2 ;
tempbuffer [ i + 1 ] = ' \0 ' ;
while ( _uint )
{
tempbuffer [ i ] = ( _uint & 0xf ) + ' 0 ' ;
if ( tempbuffer [ i ] > ' 9 ' )
tempbuffer [ i ] = tempbuffer [ i ] - ' : ' + ' a ' ;
_uint / = 16 ;
i - - ;
}
string = tempbuffer + i + 1 ;
if ( ! * string )
{
i = 61 ;
string = tempbuffer + i + 1 ;
string [ 0 ] = ' 0 ' ;
string [ 1 ] = ' \0 ' ;
}
width - = 62 - i ;
while ( width > 0 )
{
string - - ;
if ( use0s )
* string = ' 0 ' ;
else
* string = ' ' ;
width - - ;
}
while ( * string )
{
if ( maxlen - - = = 0 )
{ * buffer + + = ' \0 ' ; return tokens ; }
* buffer + + = * string + + ;
}
tokens + + ;
break ;
case ' d ' :
case ' u ' :
case ' i ' :
_int = va_arg ( vargs , int ) ;
if ( useprepad )
{
}
if ( _int < 0 )
{
sign = ' - ' ;
_int * = - 1 ;
}
else if ( plus )
sign = ' + ' ;
else
sign = 0 ;
i = sizeof ( tempbuffer ) - 2 ;
tempbuffer [ sizeof ( tempbuffer ) - 1 ] = ' \0 ' ;
while ( _int )
{
tempbuffer [ i - - ] = _int % 10 + ' 0 ' ;
_int / = 10 ;
}
if ( sign )
tempbuffer [ i - - ] = sign ;
string = tempbuffer + i + 1 ;
if ( ! * string )
{
i = 61 ;
string = tempbuffer + i + 1 ;
string [ 0 ] = ' 0 ' ;
string [ 1 ] = ' \0 ' ;
}
width - = 62 - i ;
/* while (width>0)
{
string - - ;
* string = ' ' ;
width - - ;
}
*/
while ( width > 0 )
{
if ( maxlen - - = = 0 )
{ * buffer + + = ' \0 ' ; return tokens ; }
if ( use0s )
* buffer + + = ' 0 ' ;
else
* buffer + + = ' ' ;
width - - ;
}
while ( * string )
{
if ( maxlen - - = = 0 )
{ * buffer + + = ' \0 ' ; return tokens ; }
* buffer + + = * string + + ;
}
tokens + + ;
break ;
case ' f ' :
_float = ( float ) va_arg ( vargs , double ) ;
//integer part.
_int = ( int ) _float ;
if ( _int < 0 )
{
if ( maxlen - - = = 0 )
{ * buffer + + = ' \0 ' ; return tokens ; }
* buffer + + = ' - ' ;
_int * = - 1 ;
}
i = sizeof ( tempbuffer ) - 2 ;
tempbuffer [ sizeof ( tempbuffer ) - 1 ] = ' \0 ' ;
if ( ! _int )
{
tempbuffer [ i - - ] = ' 0 ' ;
}
else
{
while ( _int )
{
tempbuffer [ i - - ] = _int % 10 + ' 0 ' ;
_int / = 10 ;
}
}
string = tempbuffer + i + 1 ;
while ( * string )
{
if ( maxlen - - = = 0 )
{ * buffer + + = ' \0 ' ; return tokens ; }
* buffer + + = * string + + ;
}
_int = sizeof ( tempbuffer ) - 2 - i ;
//floating point part.
_float - = ( int ) _float ;
i = 0 ;
tempbuffer [ i + + ] = ' . ' ;
if ( precision < 0 )
precision = 7 ;
while ( _float - ( int ) _float )
{
if ( i > precision ) //remove the excess presision.
break ;
_float * = 10 ;
tempbuffer [ i + + ] = ( int ) _float % 10 + ' 0 ' ;
}
if ( i = = 1 ) //no actual fractional part
{
tokens + + ;
break ;
}
//concatinate to our string
tempbuffer [ i ] = ' \0 ' ;
string = tempbuffer ;
while ( * string )
{
if ( maxlen - - = = 0 )
{ * buffer + + = ' \0 ' ; return tokens ; }
* buffer + + = * string + + ;
}
tokens + + ;
break ;
default :
string = " ERROR IN FORMAT " ;
while ( * string )
{
if ( maxlen - - = = 0 )
{ * buffer + + = ' \0 ' ; return tokens ; }
* buffer + + = * string + + ;
}
break ;
}
break ;
default :
if ( maxlen - - = = 0 )
{ * buffer + + = ' \0 ' ; return tokens ; }
* buffer + + = * format ;
break ;
}
format + + ;
}
{ * buffer + + = ' \0 ' ; return tokens ; }
}
2017-03-26 23:03:02 +00:00
# if defined(_WIN32) && defined(HAVE_PACKET)
# include <windns.h>
2013-07-13 12:14:32 +00:00
static DNS_STATUS ( WINAPI * pDnsQuery_UTF8 ) ( PCSTR pszName , WORD wType , DWORD Options , PIP4_ARRAY aipServers , PDNS_RECORD * ppQueryResults , PVOID * pReserved ) ;
static VOID ( WINAPI * pDnsRecordListFree ) ( PDNS_RECORD pRecordList , DNS_FREE_TYPE FreeType ) ;
static HMODULE dnsapi_lib ;
2017-10-12 12:02:25 +00:00
qboolean NET_DNSLookup_SRV ( const char * host , char * out , int outlen )
2013-07-13 12:14:32 +00:00
{
DNS_RECORD * result = NULL ;
if ( ! dnsapi_lib )
{
dnsapi_lib = LoadLibrary ( " dnsapi.dll " ) ;
pDnsQuery_UTF8 = ( void * ) GetProcAddress ( dnsapi_lib , " DnsQuery_UTF8 " ) ;
pDnsRecordListFree = ( void * ) GetProcAddress ( dnsapi_lib , " DnsRecordListFree " ) ;
}
//win98?
if ( ! pDnsQuery_UTF8 | | ! pDnsRecordListFree )
return false ;
//do lookup
2016-07-12 00:40:13 +00:00
pDnsQuery_UTF8 ( host , DNS_TYPE_SRV , DNS_QUERY_STANDARD , NULL , & result , NULL ) ;
2013-07-13 12:14:32 +00:00
if ( result )
{
Q_snprintf ( out , outlen , " [%s]:%i " , result - > Data . SRV . pNameTarget , result - > Data . SRV . wPort ) ;
pDnsRecordListFree ( result , DnsFreeRecordList ) ;
return true ;
}
return false ;
}
2019-05-10 02:06:07 +00:00
# elif (defined(__unix__) || defined(__MACH__) || defined(__linux__)) && !defined(ANDROID)
2013-11-21 23:02:28 +00:00
# include <resolv.h>
# include <arpa/nameser.h>
2017-10-21 18:08:45 +00:00
qboolean NET_DNSLookup_SRV ( const char * host , char * out , int outlen )
2013-07-13 12:14:32 +00:00
{
2013-11-21 23:02:28 +00:00
int questions ;
int answers ;
qbyte answer [ 512 ] ;
qbyte dname [ 512 ] ;
int len , i ;
2016-07-12 00:40:13 +00:00
qbyte * msg , * eom ;
2013-11-21 23:02:28 +00:00
2016-07-12 00:40:13 +00:00
len = res_query ( host , C_IN , T_SRV , answer , sizeof ( answer ) ) ;
2013-11-21 23:02:28 +00:00
if ( len < 12 )
{
Con_Printf ( " srv lookup failed for %s \n " , host ) ;
return false ;
}
eom = answer + len ;
questions = ( answer [ 4 ] < < 8 ) | answer [ 5 ] ;
answers = ( answer [ 6 ] < < 8 ) | answer [ 7 ] ;
// id @ 0
// bits @ 2
// questioncount@4
/// answer count@6
// nameserver record count @8
// additional record count @10
// questions@12
// answers@12+sizeof(questions)
if ( answers < 1 )
return false ;
msg = answer + 12 ;
while ( questions - - > 0 )
{
dn_expand ( answer , eom , msg , dname , sizeof ( dname ) ) ;
// Con_Printf("Skip question %s\n", dname);
i = dn_skipname ( msg , eom ) ;
if ( i < = 0 )
return false ;
msg + = i ;
msg + = 2 ; //query type
msg + = 2 ; //query class
}
while ( answers - - > 0 )
{
i = dn_expand ( answer , eom , msg , dname , sizeof ( dname ) ) ;
// i = dn_skipname(msg, eom);
msg + = i ;
msg + = 2 ; //query type
msg + = 2 ; //query class
msg + = 4 ; //ttl
i = ( msg [ 0 ] < < 8 ) | msg [ 1 ] ;
msg + = 2 ;
//noone tried to send the wrong type then, woo.
if ( ! strcmp ( dname , host ) )
{
int port ;
//we're not serving to other dns servers, and it seems they're already getting randomized, so just grab the first without rerandomizing.
msg + = 2 ; //priority
msg + = 2 ; //weight
port = ( msg [ 0 ] < < 8 ) | msg [ 1 ] ;
msg + = 2 ; //port
dn_expand ( answer , eom , msg , dname , sizeof ( dname ) ) ;
Q_snprintf ( out , outlen , " [%s]:%i " , dname , port ) ;
// Con_Printf("Resolved to %s\n", out);
return true ;
}
dn_expand ( answer , eom , msg , out , outlen ) ;
// Con_Printf("Ignoring resolution to %s\n", out);
msg + = i ;
}
//type (2 octets)
//class (2 octets)
//TTL (4 octets)
//resource data length (2 octets)
//resource data (variable length)
if ( i < 0 )
return false ;
return true ;
2013-07-13 12:14:32 +00:00
}
2017-03-26 23:03:02 +00:00
# else
2017-10-21 18:08:45 +00:00
qboolean NET_DNSLookup_SRV ( const char * host , char * out , int outlen )
2017-03-26 23:03:02 +00:00
{
return false ;
}
2013-07-13 12:14:32 +00:00
# endif
2019-09-04 07:59:40 +00:00
static char base64 [ ( ( 4096 + 3 ) * 4 / 3 ) + 1 ] ;
static unsigned int base64_len ; //current output length
static unsigned int base64_cur ; //current pending value
static unsigned int base64_bits ; //current pending bits
2013-07-13 12:14:32 +00:00
char Base64_From64 ( int byt )
{
if ( byt > = 0 & & byt < 26 )
return ' A ' + byt - 0 ;
if ( byt > = 26 & & byt < 52 )
return ' a ' + byt - 26 ;
if ( byt > = 52 & & byt < 62 )
return ' 0 ' + byt - 52 ;
if ( byt = = 62 )
return ' + ' ;
if ( byt = = 63 )
return ' / ' ;
return ' ! ' ;
}
void Base64_Byte ( unsigned int byt )
{
if ( base64_len + 4 > = sizeof ( base64 ) - 1 )
return ;
base64_cur | = byt < < ( 16 - base64_bits ) ; //first byte fills highest bits
base64_bits + = 8 ;
if ( base64_bits = = 24 )
{
base64 [ base64_len + + ] = Base64_From64 ( ( base64_cur > > 18 ) & 63 ) ;
base64 [ base64_len + + ] = Base64_From64 ( ( base64_cur > > 12 ) & 63 ) ;
base64 [ base64_len + + ] = Base64_From64 ( ( base64_cur > > 6 ) & 63 ) ;
base64 [ base64_len + + ] = Base64_From64 ( ( base64_cur > > 0 ) & 63 ) ;
base64 [ base64_len ] = ' \0 ' ;
// Con_Printf("base64: %s\n", base64+base64_len-4);
base64_bits = 0 ;
base64_cur = 0 ;
}
}
2017-10-12 12:02:25 +00:00
void Base64_Add ( const char * s , int len )
2013-07-13 12:14:32 +00:00
{
2019-09-04 07:59:40 +00:00
const unsigned char * us = ( const unsigned char * ) s ;
2013-07-13 12:14:32 +00:00
while ( len - - > 0 )
Base64_Byte ( * us + + ) ;
}
2013-11-21 23:02:28 +00:00
char * Base64_Finish ( void )
2013-07-13 12:14:32 +00:00
{
//output is always a multiple of four
//0(0)->0(0)
//1(8)->2(12)
//2(16)->3(18)
//3(24)->4(24)
if ( base64_bits ! = 0 )
{
base64 [ base64_len + + ] = Base64_From64 ( ( base64_cur > > 18 ) & 63 ) ;
base64 [ base64_len + + ] = Base64_From64 ( ( base64_cur > > 12 ) & 63 ) ;
if ( base64_bits = = 8 )
{
base64 [ base64_len + + ] = ' = ' ;
base64 [ base64_len + + ] = ' = ' ;
}
else
{
base64 [ base64_len + + ] = Base64_From64 ( ( base64_cur > > 6 ) & 63 ) ;
if ( base64_bits = = 16 )
base64 [ base64_len + + ] = ' = ' ;
else
base64 [ base64_len + + ] = Base64_From64 ( ( base64_cur > > 0 ) & 63 ) ;
}
}
base64 [ base64_len + + ] = ' \0 ' ;
base64_len = 0 ; //for next time (use strlen)
base64_bits = 0 ;
base64_cur = 0 ;
2013-11-21 23:02:28 +00:00
return base64 ;
2013-07-13 12:14:32 +00:00
}
//decode a base64 byte to a 0-63 value. Cannot cope with =.
static int Base64_DecodeByte ( char byt )
{
if ( byt > = ' A ' & & byt < = ' Z ' )
return ( byt - ' A ' ) + 0 ;
if ( byt > = ' a ' & & byt < = ' z ' )
return ( byt - ' a ' ) + 26 ;
if ( byt > = ' 0 ' & & byt < = ' 9 ' )
return ( byt - ' 0 ' ) + 52 ;
if ( byt = = ' + ' )
return 62 ;
if ( byt = = ' / ' )
return 63 ;
return - 1 ;
}
2013-11-21 23:02:28 +00:00
//FIXME: we should be able to skip whitespace.
2017-10-12 12:02:25 +00:00
int Base64_Decode ( char * out , int outlen , const char * src , int srclen )
2013-07-13 12:14:32 +00:00
{
int len = 0 ;
int result ;
//4 input chars give 3 output chars
while ( srclen > = 4 )
{
if ( len + 3 > outlen )
break ;
result = Base64_DecodeByte ( src [ 0 ] ) < < 18 ;
result | = Base64_DecodeByte ( src [ 1 ] ) < < 12 ;
out [ len + + ] = ( result > > 16 ) & 0xff ;
if ( src [ 2 ] ! = ' = ' )
{
result | = Base64_DecodeByte ( src [ 2 ] ) < < 6 ;
out [ len + + ] = ( result > > 8 ) & 0xff ;
if ( src [ 3 ] ! = ' = ' )
{
result | = Base64_DecodeByte ( src [ 3 ] ) < < 0 ;
out [ len + + ] = ( result > > 0 ) & 0xff ;
}
}
if ( result & 0xff000000 )
return 0 ; //some kind of invalid char
src + = 4 ;
srclen - = 4 ;
}
//some kind of error
if ( srclen )
return 0 ;
return len ;
}
2013-10-29 17:38:22 +00:00
void XMPP_Menu_Password ( jclient_t * acc ) ;
2013-06-23 02:33:52 +00:00
void RenameConsole ( char * totrim ) ;
2013-07-13 12:14:32 +00:00
void JCL_Command ( int accid , char * consolename ) ;
2013-06-23 02:33:52 +00:00
void JCL_LoadConfig ( void ) ;
void JCL_WriteConfig ( void ) ;
2005-12-11 20:11:22 +00:00
2019-09-04 07:59:40 +00:00
static struct {
2013-11-21 23:02:28 +00:00
char * names ;
unsigned int cap ;
} capnames [ ] =
{
{ " avatars " , CAP_AVATARS } ,
{ " jingle_voice " , CAP_VOICE } ,
{ " jingle_video " , CAP_VIDEO } ,
{ " google_voice " , CAP_GOOGLE_VOICE } ,
{ " quake_invite " , CAP_GAMEINVITE } ,
{ " poke " , CAP_POKE } ,
# ifdef FILETRANSFERS
{ " si_filetransfer " , CAP_SIFT } ,
# endif
{ NULL }
} ;
2019-09-04 07:59:40 +00:00
qboolean JCL_ExecuteCommand ( qboolean isinsecure )
2005-12-11 20:11:22 +00:00
{
2007-09-17 20:55:15 +00:00
char cmd [ 256 ] ;
2019-09-04 07:59:40 +00:00
cmdfuncs - > Argv ( 0 , cmd , sizeof ( cmd ) ) ;
2013-06-23 02:33:52 +00:00
if ( ! strcmp ( cmd , COMMANDPREFIX ) | | ! strcmp ( cmd , COMMANDPREFIX2 ) | | ! strcmp ( cmd , COMMANDPREFIX3 ) )
2005-12-11 20:11:22 +00:00
{
2019-09-04 07:59:40 +00:00
if ( ! isinsecure | | cmdfuncs - > Argc ( ) = = 1 )
2013-07-13 12:14:32 +00:00
JCL_Command ( 0 , " " ) ;
return true ;
}
if ( ! strncmp ( cmd , COMMANDPREFIX , strlen ( COMMANDPREFIX ) ) )
{
2019-09-04 07:59:40 +00:00
if ( ! isinsecure | | cmdfuncs - > Argc ( ) = = 1 )
2013-07-13 12:14:32 +00:00
JCL_Command ( atoi ( cmd + strlen ( COMMANDPREFIX ) ) , " " ) ;
2005-12-11 20:11:22 +00:00
return true ;
}
return false ;
}
2019-09-04 07:59:40 +00:00
qboolean JCL_ConsoleLink ( void ) ;
qboolean JCL_ConsoleLinkMouseOver ( float x , float y ) ;
int JCL_ConExecuteCommand ( qboolean isinsecure ) ;
2005-12-11 20:11:22 +00:00
2019-09-04 07:59:40 +00:00
void JCL_Frame ( double realtime , double gametime ) ;
void JCL_Shutdown ( void ) ;
2005-12-11 20:11:22 +00:00
2019-09-04 07:59:40 +00:00
static void QDECL JCL_UpdateVideo ( int width , int height )
2015-04-27 06:19:33 +00:00
{
2019-09-04 07:59:40 +00:00
pvid . width = width ;
pvid . height = height ;
2015-04-27 06:19:33 +00:00
//FIXME: clear/reload images.
}
2019-09-04 07:59:40 +00:00
qboolean Plug_Init ( void )
2005-12-11 20:11:22 +00:00
{
2015-04-27 06:19:33 +00:00
jclient_needreadconfig = true ;
2020-04-19 03:50:14 +00:00
confuncs = ( plugsubconsolefuncs_t * ) plugfuncs - > GetEngineInterface ( plugsubconsolefuncs_name , sizeof ( * confuncs ) ) ;
drawfuncs = ( plug2dfuncs_t * ) plugfuncs - > GetEngineInterface ( plug2dfuncs_name , sizeof ( * drawfuncs ) ) ;
netfuncs = ( plugnetfuncs_t * ) plugfuncs - > GetEngineInterface ( plugnetfuncs_name , sizeof ( * netfuncs ) ) ;
filefuncs = ( plugfsfuncs_t * ) plugfuncs - > GetEngineInterface ( plugfsfuncs_name , sizeof ( * filefuncs ) ) ;
clientfuncs = ( plugclientfuncs_t * ) plugfuncs - > GetEngineInterface ( plugclientfuncs_name , sizeof ( * clientfuncs ) ) ;
if ( netfuncs & & filefuncs & &
plugfuncs - > ExportFunction ( " Tick " , JCL_Frame ) & &
2019-09-04 07:59:40 +00:00
plugfuncs - > ExportFunction ( " Shutdown " , JCL_Shutdown ) & &
plugfuncs - > ExportFunction ( " ExecuteCommand " , JCL_ExecuteCommand ) )
2005-12-11 20:11:22 +00:00
{
2019-09-04 07:59:40 +00:00
Con_Printf ( " XMPP Plugin Loaded. For help, use: ^[/ " COMMANDPREFIX " /help^] \n " ) ;
2013-06-23 02:33:52 +00:00
2019-09-04 07:59:40 +00:00
plugfuncs - > ExportFunction ( " UpdateVideo " , JCL_UpdateVideo ) ;
plugfuncs - > ExportFunction ( " ConsoleLink " , JCL_ConsoleLink ) ;
2020-04-19 03:50:14 +00:00
if ( drawfuncs )
plugfuncs - > ExportFunction ( " ConsoleLinkMouseOver " , JCL_ConsoleLinkMouseOver ) ;
2005-12-15 02:01:57 +00:00
2020-04-19 03:50:14 +00:00
if ( ! confuncs | | ! plugfuncs - > ExportFunction ( " ConExecuteCommand " , JCL_ConExecuteCommand ) )
2005-12-15 02:01:57 +00:00
{
2013-06-23 02:33:52 +00:00
Con_Printf ( " XMPP plugin in single-console mode \n " ) ;
2013-03-31 04:21:08 +00:00
Con_TrySubPrint = Fallback_ConPrint ;
2005-12-15 02:01:57 +00:00
}
2005-12-11 20:11:22 +00:00
else
2019-09-04 07:59:40 +00:00
Con_TrySubPrint = confuncs - > SubPrint ;
2005-12-15 02:01:57 +00:00
2019-09-04 07:59:40 +00:00
cmdfuncs - > AddCommand ( COMMANDPREFIX ) ;
cmdfuncs - > AddCommand ( COMMANDPREFIX2 ) ;
cmdfuncs - > AddCommand ( COMMANDPREFIX3 ) ;
2013-06-23 02:33:52 +00:00
2019-09-04 07:59:40 +00:00
cmdfuncs - > AddCommand ( COMMANDPREFIX " 0 " ) ;
cmdfuncs - > AddCommand ( COMMANDPREFIX " 1 " ) ;
cmdfuncs - > AddCommand ( COMMANDPREFIX " 2 " ) ;
cmdfuncs - > AddCommand ( COMMANDPREFIX " 3 " ) ;
cmdfuncs - > AddCommand ( COMMANDPREFIX " 4 " ) ;
cmdfuncs - > AddCommand ( COMMANDPREFIX " 5 " ) ;
cmdfuncs - > AddCommand ( COMMANDPREFIX " 6 " ) ;
cmdfuncs - > AddCommand ( COMMANDPREFIX " 7 " ) ;
2013-07-13 12:14:32 +00:00
2013-06-29 16:01:07 +00:00
//flags&1 == archive
2019-09-04 07:59:40 +00:00
cvarfuncs - > Register ( " xmpp_nostatus " , " 0 " , 0 , " xmpp " ) ;
cvarfuncs - > Register ( " xmpp_showstatusupdates " , " 0 " , 0 , " xmpp " ) ;
cvarfuncs - > Register ( " xmpp_autoacceptjoins " , " 0 " , 0 , " xmpp " ) ;
cvarfuncs - > Register ( " xmpp_autoacceptinvites " , " 0 " , 0 , " xmpp " ) ;
cvarfuncs - > Register ( " xmpp_autoacceptvoice " , " 0 " , 0 , " xmpp " ) ;
cvarfuncs - > Register ( " xmpp_debug " , " 0 " , 0 , " xmpp " ) ;
2013-06-23 02:33:52 +00:00
2013-07-13 12:14:32 +00:00
# ifdef JINGLE
2019-09-04 07:59:40 +00:00
piceapi = plugfuncs - > GetEngineInterface ( ICE_API_CURRENT , sizeof ( * piceapi ) ) ;
2013-07-13 12:14:32 +00:00
# endif
2013-06-23 02:33:52 +00:00
2005-12-11 20:11:22 +00:00
return 1 ;
}
else
2013-06-23 18:43:59 +00:00
Con_Printf ( " JCL Client Plugin failed \n " ) ;
2005-12-11 20:11:22 +00:00
return 0 ;
}
//\r\n is used to end a line.
//meaning \0s are valid.
//but never used cos it breaks strings
2019-09-04 07:59:40 +00:00
static jclient_t * jclients [ 8 ] ;
static int jclient_curtime ;
static int jclient_poketime ;
2013-07-13 12:14:32 +00:00
2017-09-20 11:27:13 +00:00
typedef struct saslmethod_s
2013-07-13 12:14:32 +00:00
{
char * method ;
2017-09-20 11:27:13 +00:00
int ( * sasl_initial ) ( struct sasl_ctx_s * ctx , char * buf , int bufsize ) ;
int ( * sasl_challenge ) ( struct sasl_ctx_s * ctx , char * inbuf , int insize , char * outbuf , int outsize ) ;
int ( * sasl_success ) ( struct sasl_ctx_s * ctx , char * inbuf , int insize ) ;
2013-07-13 12:14:32 +00:00
} saslmethod_t ;
//#define OAUTH_CLIENT_ID_MSN "0"
# ifdef OAUTH_CLIENT_ID_MSN
2017-09-20 11:27:13 +00:00
static int sasl_plain_initial ( struct sasl_ctx_s * ctx , char * buf , int bufsize )
2013-07-13 12:14:32 +00:00
{
//"https://oauth.live.com/authorize?client_id=" OAUTH_CLIENT_ID_MSN "&scope=wl.messenger,wl.basic,wl.offline_access,wl.contacts_create,wl.share&response_type=token&redirect_uri=http://localhost/";
}
# endif
//\0username\0password
2017-09-20 11:27:13 +00:00
static int sasl_plain_initial ( struct sasl_ctx_s * ctx , char * buf , int bufsize )
2013-07-13 12:14:32 +00:00
{
int len = 0 ;
2017-09-20 11:27:13 +00:00
if ( ctx - > issecure ? ctx - > allowauth_plaintls : ctx - > allowauth_plainnontls )
2013-07-13 12:14:32 +00:00
{
2017-09-20 11:27:13 +00:00
if ( ! * ctx - > password_plain )
2013-10-29 17:38:22 +00:00
return - 2 ;
2013-07-13 12:14:32 +00:00
//realm isn't specified
buf [ len + + ] = 0 ;
2017-09-20 11:27:13 +00:00
memcpy ( buf + len , ctx - > username , strlen ( ctx - > username ) ) ;
len + = strlen ( ctx - > username ) ;
2013-07-13 12:14:32 +00:00
buf [ len + + ] = 0 ;
2017-09-20 11:27:13 +00:00
memcpy ( buf + len , ctx - > password_plain , strlen ( ctx - > password_plain ) ) ;
len + = strlen ( ctx - > password_plain ) ;
2013-07-13 12:14:32 +00:00
return len ;
}
return - 1 ;
}
static int saslattr ( char * out , int outlen , char * srcbuf , int srclen , char * arg )
{
char * vn ;
char * s = srcbuf ;
char * e = s + srclen ;
char * vs ;
while ( s < e )
{
while ( s < e & & * s = = ' , ' )
s + + ;
vn = s ;
s + + ;
while ( s < e & & * s > = ' a ' & & * s < = ' z ' )
s + + ;
if ( * s = = ' = ' )
{
vs = + + s ;
if ( * s = = ' \" ' )
{
vs = + + s ;
while ( s < e & & * s ! = ' \" ' )
s + + ;
outlen = s - vs ;
s + + ;
}
else
{
while ( s < e & & * s ! = ' , ' )
s + + ;
outlen = s - vs ;
}
if ( ! strncmp ( vn , arg , strlen ( arg ) ) & & vn [ strlen ( arg ) ] = = ' = ' )
{
memcpy ( out , vs , outlen ) ;
out [ outlen ] = 0 ;
return outlen ;
}
}
}
out [ 0 ] = 0 ;
return 0 ;
}
2017-09-20 11:27:13 +00:00
static int sasl_digestmd5_initial ( struct sasl_ctx_s * ctx , char * buf , int bufsize )
2013-07-13 12:14:32 +00:00
{
2017-09-20 11:27:13 +00:00
if ( ctx - > allowauth_digestmd5 )
2013-07-13 12:14:32 +00:00
{
2017-09-20 11:27:13 +00:00
if ( ! * ctx - > password_plain & & ctx - > password_hash_size ! = 16 )
2013-10-29 17:38:22 +00:00
return - 2 ;
2013-07-13 12:14:32 +00:00
//FIXME: randomize the cnonce and check the auth key
//although really I'm not entirely sure what the point is.
//if we just authenticated with a mitm attacker relay, we're screwed either way.
2017-09-20 11:27:13 +00:00
strcpy ( ctx - > digest . authnonce , " abcdefghijklmnopqrstuvwxyz " ) ;
2013-07-13 12:14:32 +00:00
//nothing. server does the initial data.
return 0 ;
}
return - 1 ;
}
char * MD5_ToHex ( char * input , int inputlen , char * ret , int retlen ) ;
char * MD5_ToBinary ( char * input , int inputlen , char * ret , int retlen ) ;
2017-09-20 11:27:13 +00:00
static int sasl_digestmd5_challenge ( struct sasl_ctx_s * ctx , char * in , int inlen , char * out , int outlen )
2013-07-13 12:14:32 +00:00
{
2017-09-20 11:27:13 +00:00
char * username = ctx - > username ;
char * cnonce = ctx - > digest . authnonce ;
2013-07-13 12:14:32 +00:00
char rspauth [ 512 ] ;
char realm [ 512 ] ;
char nonce [ 512 ] ;
char qop [ 512 ] ;
char charset [ 512 ] ;
char algorithm [ 512 ] ;
char X [ 512 ] ;
char Y [ 33 ] ;
char A1 [ 512 ] ;
char A2 [ 512 ] ;
char HA1 [ 33 ] ;
char HA2 [ 33 ] ;
char KD [ 512 ] ;
char Z [ 33 ] ;
char * nc = " 00000001 " ;
char digesturi [ 512 ] ;
char * authzid = " " ;
saslattr ( rspauth , sizeof ( rspauth ) , in , inlen , " rspauth " ) ;
if ( * rspauth )
{
return 0 ; //we don't actually send any data back, just an xml 'response' tag to tell the server that we accept it.
}
saslattr ( realm , sizeof ( realm ) , in , inlen , " realm " ) ;
saslattr ( nonce , sizeof ( nonce ) , in , inlen , " nonce " ) ;
saslattr ( qop , sizeof ( qop ) , in , inlen , " qop " ) ;
saslattr ( charset , sizeof ( charset ) , in , inlen , " charset " ) ;
saslattr ( algorithm , sizeof ( algorithm ) , in , inlen , " algorithm " ) ;
if ( ! * realm )
2017-09-20 11:27:13 +00:00
Q_strlcpy ( realm , ctx - > domain , sizeof ( realm ) ) ;
2021-08-05 16:49:25 +00:00
if ( Q_snprintfz ( digesturi , sizeof ( digesturi ) , " xmpp/%s " , realm ) )
2019-09-04 07:59:40 +00:00
return - 1 ;
2013-07-13 12:14:32 +00:00
2017-09-20 11:27:13 +00:00
2021-08-05 16:49:25 +00:00
if ( Q_snprintfz ( X , sizeof ( X ) , " %s:%s: " , username , realm ) )
2019-09-04 07:59:40 +00:00
return - 1 ;
2017-09-20 11:27:13 +00:00
if ( ctx - > password_hash_size = = 16 & & ! strcmp ( X , ctx - > password_validity ) )
memcpy ( Y , ctx - > password_hash , 16 ) ; //use the hashed password, instead of the (missing) plain one
2019-08-01 02:13:44 +00:00
else if ( * ctx - > password_plain )
2017-09-20 11:27:13 +00:00
{
Q_strlcpy ( ctx - > password_validity , X , sizeof ( ctx - > password_validity ) ) ;
2021-08-05 16:49:25 +00:00
if ( Q_snprintfz ( X , sizeof ( X ) , " %s:%s:%s " , username , realm , ctx - > password_plain ) )
2019-09-04 07:59:40 +00:00
return - 1 ;
2017-09-20 11:27:13 +00:00
MD5_ToBinary ( X , strlen ( X ) , Y , sizeof ( Y ) ) ;
ctx - > password_hash_size = 16 ;
memcpy ( ctx - > password_hash , Y , 16 ) ; //save that hash for later.
}
else
return - 1 ; //err, we didn't have a password...
2013-07-13 12:14:32 +00:00
memcpy ( A1 , Y , 16 ) ;
if ( * authzid )
2019-09-04 07:59:40 +00:00
{
2021-08-05 16:49:25 +00:00
if ( Q_snprintfz ( A1 + 16 , sizeof ( A1 ) - 16 , " :%s:%s:%s " , nonce , cnonce , authzid ) )
2019-09-04 07:59:40 +00:00
return - 1 ;
}
2013-07-13 12:14:32 +00:00
else
2019-09-04 07:59:40 +00:00
{
2021-08-05 16:49:25 +00:00
if ( Q_snprintfz ( A1 + 16 , sizeof ( A1 ) - 16 , " :%s:%s " , nonce , cnonce ) )
2019-09-04 07:59:40 +00:00
return - 1 ;
}
2021-08-05 16:49:25 +00:00
if ( Q_snprintfz ( A2 , sizeof ( A2 ) , " %s:%s " , " AUTHENTICATE " , digesturi ) )
2019-09-04 07:59:40 +00:00
return - 1 ;
2013-07-13 12:14:32 +00:00
MD5_ToHex ( A1 , strlen ( A1 + 16 ) + 16 , HA1 , sizeof ( HA1 ) ) ;
MD5_ToHex ( A2 , strlen ( A2 ) , HA2 , sizeof ( HA2 ) ) ;
2021-08-05 16:49:25 +00:00
if ( Q_snprintfz ( KD , sizeof ( KD ) , " %s:%s:%s:%s:%s:%s " , HA1 , nonce , nc , cnonce , qop , HA2 ) )
2019-09-04 07:59:40 +00:00
return - 1 ;
2013-07-13 12:14:32 +00:00
MD5_ToHex ( KD , strlen ( KD ) , Z , sizeof ( Z ) ) ;
if ( * authzid )
Q_snprintf ( out , outlen , " username= \" %s \" ,realm= \" %s \" ,nonce= \" %s \" ,cnonce= \" %s \" ,nc= \" %s \" ,qop= \" %s \" ,digest-uri= \" %s \" ,response= \" %s \" ,charset= \" %s \" ,authzid= \" %s \" " ,
username , realm , nonce , cnonce , nc , qop , digesturi , Z , charset , authzid ) ;
else
Q_snprintf ( out , outlen , " username= \" %s \" ,realm= \" %s \" ,nonce= \" %s \" ,cnonce= \" %s \" ,nc= \" %s \" ,qop= \" %s \" ,digest-uri= \" %s \" ,response= \" %s \" ,charset= \" %s \" " ,
username , realm , nonce , cnonce , nc , qop , digesturi , Z , charset ) ;
return strlen ( out ) ;
}
2017-09-20 11:27:13 +00:00
typedef struct
{
int len ;
char buf [ 512 ] ;
} buf_t ;
2021-04-14 05:21:04 +00:00
static int sasl_scram_initial ( struct sasl_ctx_s * ctx , char * buf , int bufsize , hashfunc_t * hashfunc , qboolean plus )
2013-07-13 12:14:32 +00:00
{
2017-09-20 11:27:13 +00:00
if ( ctx - > allowauth_scramsha1 )
2013-07-13 12:14:32 +00:00
{
2017-09-20 11:27:13 +00:00
unsigned int t ;
buf_t bindingdata ;
int bs ;
2021-04-14 05:21:04 +00:00
if ( ! * ctx - > password_plain & & ctx - > password_hash_size ! = hashfunc - > digestsize )
2013-10-29 17:38:22 +00:00
return - 2 ;
2013-07-13 12:14:32 +00:00
2017-09-20 11:27:13 +00:00
# if 1 //FIXME: test that we're compliant when we're verifying channel bindings.
//the channel binding thing helps to avoid MITM attacks by tying the auth to the tls keys.
//a MITM attacker will have different binding ids each side, resulting in screwed hashes (they would need to use the public keys (which would require knowing private keys too), or something).
if ( ctx - > issecure )
{
bindingdata . len = sizeof ( bindingdata . buf ) ;
2019-09-04 07:59:40 +00:00
if ( netfuncs )
bs = netfuncs - > GetTLSBinding ( ctx - > socket , bindingdata . buf , & bindingdata . len ) ;
2017-09-20 11:27:13 +00:00
else
bs = - 1 ;
}
else
# endif
{
bindingdata . len = 0 ;
bs = - 1 ;
}
//couldn't use plus for some reason
if ( bs < 0 )
{ //not implemented by our tls implementation.
if ( plus )
return - 1 ; //can't auth with this mechanism
Q_strlcpy ( ctx - > scram . authcbindtype , " n " , sizeof ( ctx - > scram . authcbindtype ) ) ;
}
else if ( plus & & bs > 0 )
{ //both sides should support it.
Q_strlcpy ( ctx - > scram . authcbindtype , " p=tls-unique " , sizeof ( ctx - > scram . authcbindtype ) ) ;
Base64_Add ( bindingdata . buf , bindingdata . len ) ;
Q_snprintf ( ctx - > scram . authcbinding , sizeof ( ctx - > scram . authcbinding ) , " %s " , Base64_Finish ( ) ) ;
}
else
{ //we support it, but the server does not appear to (we failed the plus method, or it just wasn't listed).
//server will fail the auth if it can do channel bindings (assuming someone stripped the plus method).
Q_strlcpy ( ctx - > scram . authcbindtype , " y " , sizeof ( ctx - > scram . authcbindtype ) ) ;
}
//FIXME: this should be more random, to validate that the server actually knows our password too
//we can't really do anything until we've already signed in, so why bother?
2019-09-04 07:59:40 +00:00
t = plugfuncs - > GetMilliseconds ( ) ;
2017-09-20 11:27:13 +00:00
Base64_Add ( ( void * ) & t , sizeof ( t ) ) ;
Base64_Add ( " 0123456789abcdef " , 16 ) ;
Base64_Add ( ( void * ) & jclient_curtime , sizeof ( jclient_curtime ) ) ;
strcpy ( ctx - > scram . authnonce , Base64_Finish ( ) ) ;
ctx - > scram . hashfunc = hashfunc ;
Q_snprintf ( buf , bufsize , " %s,,n=%s,r=%s " , ctx - > scram . authcbindtype , ctx - > username , ctx - > scram . authnonce ) ;
2013-07-13 12:14:32 +00:00
return strlen ( buf ) ;
}
return - 1 ;
}
2017-09-20 11:27:13 +00:00
static int sasl_scramsha1minus_initial ( struct sasl_ctx_s * ctx , char * buf , int bufsize )
2013-07-13 12:14:32 +00:00
{
2021-04-14 05:21:04 +00:00
return sasl_scram_initial ( ctx , buf , bufsize , & hash_sha1 , false ) ;
}
static int sasl_scramsha256minus_initial ( struct sasl_ctx_s * ctx , char * buf , int bufsize )
{
return sasl_scram_initial ( ctx , buf , bufsize , & hash_sha256 , false ) ;
}
static int sasl_scramsha512minus_initial ( struct sasl_ctx_s * ctx , char * buf , int bufsize )
{
return sasl_scram_initial ( ctx , buf , bufsize , & hash_sha512 , false ) ;
2017-09-20 11:27:13 +00:00
}
static int sasl_scramsha1plus_initial ( struct sasl_ctx_s * ctx , char * buf , int bufsize )
{
2021-04-14 05:21:04 +00:00
return sasl_scram_initial ( ctx , buf , bufsize , & hash_sha1 , true ) ;
}
static int sasl_scramsha256plus_initial ( struct sasl_ctx_s * ctx , char * buf , int bufsize )
{
return sasl_scram_initial ( ctx , buf , bufsize , & hash_sha256 , true ) ;
}
static int sasl_scramsha512plus_initial ( struct sasl_ctx_s * ctx , char * buf , int bufsize )
{
return sasl_scram_initial ( ctx , buf , bufsize , & hash_sha512 , true ) ;
2017-09-20 11:27:13 +00:00
}
2013-07-13 12:14:32 +00:00
static void buf_cat ( buf_t * buf , char * data , int len )
{
memcpy ( buf - > buf + buf - > len , data , len ) ;
buf - > len + = len ;
buf - > buf [ buf - > len ] = 0 ;
}
static void buf_cats ( buf_t * buf , char * data )
{
buf_cat ( buf , data , strlen ( data ) ) ;
}
2017-09-20 11:27:13 +00:00
static size_t HMAC_Hi ( hashfunc_t * hashfunc , char * out , char * password , int passwordlen , buf_t * salt , int times )
2013-07-13 12:14:32 +00:00
{
2017-09-20 11:27:13 +00:00
size_t digestsize ;
char prev [ 64 ] ;
2013-07-13 12:14:32 +00:00
int i , j ;
//first iteration is special
buf_cat ( salt , " \0 \0 \0 \1 " , 4 ) ;
2021-04-14 05:21:04 +00:00
digestsize = CalcHMAC ( hashfunc , prev , sizeof ( prev ) , salt - > buf , salt - > len , password , passwordlen ) ;
2017-09-20 11:27:13 +00:00
memcpy ( out , prev , digestsize ) ;
2013-07-13 12:14:32 +00:00
//later iterations just use the previous iteration
for ( i = 1 ; i < times ; i + + )
{
2021-04-14 05:21:04 +00:00
CalcHMAC ( hashfunc , prev , digestsize , prev , digestsize , password , passwordlen ) ;
2013-07-13 12:14:32 +00:00
2017-09-20 11:27:13 +00:00
for ( j = 0 ; j < digestsize ; j + + )
2013-07-13 12:14:32 +00:00
out [ j ] ^ = prev [ j ] ;
}
2017-09-20 11:27:13 +00:00
return digestsize ;
2013-07-13 12:14:32 +00:00
}
2017-09-20 11:27:13 +00:00
static int sasl_scram_challenge ( struct sasl_ctx_s * ctx , char * in , int inlen , char * out , int outlen )
2013-07-13 12:14:32 +00:00
{
2017-09-20 11:27:13 +00:00
hashfunc_t * func = ctx - > scram . hashfunc ;
2021-04-14 05:21:04 +00:00
size_t digestsize = func - > digestsize ;
2013-07-13 12:14:32 +00:00
//sasl SCRAM-SHA-1 challenge
//send back the same 'r' attribute
buf_t saslchal ;
2013-11-21 23:02:28 +00:00
int i ;
2013-07-13 12:14:32 +00:00
buf_t salt ;
buf_t csn ;
buf_t itr ;
buf_t final ;
buf_t sigkey ;
2021-04-14 05:21:04 +00:00
unsigned char salted_password [ DIGEST_MAXSIZE ] ;
unsigned char proof [ DIGEST_MAXSIZE ] ;
unsigned char clientkey [ DIGEST_MAXSIZE ] ;
unsigned char serverkey [ DIGEST_MAXSIZE ] ;
unsigned char storedkey [ DIGEST_MAXSIZE ] ;
unsigned char clientsignature [ DIGEST_MAXSIZE ] ;
2017-09-20 11:27:13 +00:00
char * username = ctx - > username ;
char validationstr [ 256 ] ;
const unsigned char * tmp ;
2013-07-13 12:14:32 +00:00
2021-04-14 05:21:04 +00:00
if ( digestsize > DIGEST_MAXSIZE )
return - 1 ;
2013-07-13 12:14:32 +00:00
saslchal . len = 0 ;
buf_cat ( & saslchal , in , inlen ) ;
//be warned, these CAN contain nulls.
csn . len = saslattr ( csn . buf , sizeof ( csn . buf ) , saslchal . buf , saslchal . len , " r " ) ;
salt . len = saslattr ( salt . buf , sizeof ( salt . buf ) , saslchal . buf , saslchal . len , " s " ) ;
itr . len = saslattr ( itr . buf , sizeof ( itr . buf ) , saslchal . buf , saslchal . len , " i " ) ;
salt . len = Base64_Decode ( salt . buf , sizeof ( salt . buf ) , salt . buf , salt . len ) ;
2017-09-20 11:27:13 +00:00
//csn MUST be prefixed with out authnone, to avoid mess.
if ( strncmp ( csn . buf , ctx - > scram . authnonce , strlen ( ctx - > scram . authnonce ) ) )
return - 1 ;
2013-07-13 12:14:32 +00:00
//this is the first part of the message we're about to send, with no proof.
//c(channel) is mandatory but nulled and forms part of the hash
final . len = 0 ;
buf_cats ( & final , " c= " ) ;
2017-09-20 11:27:13 +00:00
Base64_Add ( ctx - > scram . authcbindtype , strlen ( ctx - > scram . authcbindtype ) ) ;
Base64_Add ( " ,, " , 2 ) ;
Base64_Add ( ctx - > scram . authcbinding , strlen ( ctx - > scram . authcbinding ) ) ;
buf_cats ( & final , Base64_Finish ( ) ) ;
2013-07-13 12:14:32 +00:00
buf_cats ( & final , " ,r= " ) ;
buf_cat ( & final , csn . buf , csn . len ) ;
//our original message + ',' + challenge + ',' + the message we're about to send.
sigkey . len = 0 ;
buf_cats ( & sigkey , " n= " ) ;
buf_cats ( & sigkey , username ) ;
buf_cats ( & sigkey , " ,r= " ) ;
2017-09-20 11:27:13 +00:00
buf_cats ( & sigkey , ctx - > scram . authnonce ) ;
2013-07-13 12:14:32 +00:00
buf_cats ( & sigkey , " , " ) ;
buf_cat ( & sigkey , saslchal . buf , saslchal . len ) ;
buf_cats ( & sigkey , " , " ) ;
buf_cat ( & sigkey , final . buf , final . len ) ;
2017-09-20 11:27:13 +00:00
Base64_Add ( salt . buf , salt . len ) ;
Q_snprintf ( validationstr , sizeof ( validationstr ) , " %i:%s " , atoi ( itr . buf ) , Base64_Finish ( ) ) ;
if ( ctx - > password_hash_size = = digestsize & & ! strcmp ( validationstr , ctx - > password_validity ) )
{
//restore the hash
memcpy ( salted_password , ctx - > password_hash , digestsize ) ;
}
else if ( * ctx - > password_plain )
{
ctx - > password_hash_size = HMAC_Hi ( func , salted_password , ctx - > password_plain , strlen ( ctx - > password_plain ) , & salt , atoi ( itr . buf ) ) ;
//save that hash for later.
Q_strlcpy ( ctx - > password_validity , validationstr , sizeof ( ctx - > password_validity ) ) ;
memcpy ( ctx - > password_hash , salted_password , ctx - > password_hash_size ) ;
}
else
return - 2 ; //panic. password not known any more. the server should not be changing salt/itr.
2021-04-14 05:21:04 +00:00
CalcHMAC ( func , clientkey , digestsize , " Client Key " , strlen ( " Client Key " ) , salted_password , digestsize ) ;
2017-09-20 11:27:13 +00:00
//Note: if we wanted to be fancy, we could store both clientkey and serverkey instead of salted_password, but I'm not sure there's all that much point.
tmp = clientkey ;
2021-04-14 05:21:04 +00:00
CalcHash ( func , storedkey , digestsize , tmp , digestsize ) ;
CalcHMAC ( func , clientsignature , digestsize , sigkey . buf , sigkey . len , storedkey , digestsize ) ;
2013-07-13 12:14:32 +00:00
2017-09-20 11:27:13 +00:00
for ( i = 0 ; i < digestsize ; i + + )
2013-07-13 12:14:32 +00:00
proof [ i ] = clientkey [ i ] ^ clientsignature [ i ] ;
2017-09-20 11:27:13 +00:00
Base64_Add ( proof , digestsize ) ;
2013-07-13 12:14:32 +00:00
Base64_Finish ( ) ;
2017-09-20 11:27:13 +00:00
//to validate the server...
2021-04-14 05:21:04 +00:00
CalcHMAC ( func , serverkey , digestsize , " Server Key " , strlen ( " Server Key " ) , salted_password , digestsize ) ;
CalcHMAC ( func , ctx - > scram . authvhash , digestsize , sigkey . buf , sigkey . len , serverkey , digestsize ) ; //aka:serversignature
2013-07-13 12:14:32 +00:00
//"c=biws,r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j,p=v0X8v3Bz2T0CJGbJQyF0X+HI4Ts="
Q_snprintf ( out , outlen , " %s,p=%s " , final . buf , base64 ) ;
return strlen ( out ) ;
}
2017-09-20 11:27:13 +00:00
static int sasl_scram_final ( struct sasl_ctx_s * ctx , char * in , int inlen )
{
buf_t valid ;
valid . len = saslattr ( valid . buf , sizeof ( valid . buf ) , in , inlen , " v " ) ;
valid . len = Base64_Decode ( valid . buf , sizeof ( valid . buf ) , valid . buf , valid . len ) ;
2021-04-14 05:21:04 +00:00
if ( valid . len ! = ctx - > scram . hashfunc - > digestsize | | memcmp ( ctx - > scram . authvhash , valid . buf , valid . len ) )
2017-09-20 11:27:13 +00:00
return - 1 ; //server didn't give us the right answer. this is NOT the server we're looking for. give up now.
return true ;
}
2013-07-13 12:14:32 +00:00
void URL_Split ( char * url , char * proto , int protosize , char * host , int hostsize , char * res , int ressize )
{
char * s ;
* proto = 0 ;
* host = 0 ;
* res = 0 ;
s = strchr ( url , ' : ' ) ;
if ( ! s )
return ;
protosize = min ( protosize - 1 , s - url ) ;
memcpy ( proto , url , protosize ) ;
proto [ protosize ] = 0 ;
s + + ;
if ( s [ 0 ] = = ' / ' & & s [ 1 ] = = ' / ' )
s + = 2 ;
url = s ;
s = strchr ( url , ' / ' ) ;
if ( ! s )
s = url + strlen ( url ) ;
hostsize = min ( hostsize - 1 , s - url ) ;
memcpy ( host , url , hostsize ) ;
host [ hostsize ] = 0 ;
url = s ;
s = url + strlen ( url ) ;
ressize = min ( ressize - 1 , s - url ) ;
memcpy ( res , url , ressize ) ;
res [ ressize ] = 0 ;
}
void Q_strlcat_urlencode ( char * d , const char * s , int n )
{
char hex [ 16 ] = " 0123456789ABCDEF " ;
int clen = strlen ( d ) ;
d + = clen ;
n - = clen ;
n - - ;
if ( s )
while ( * s )
{
if ( ( * s > = ' 0 ' & & * s < = ' 9 ' ) | |
( * s > = ' a ' & & * s < = ' z ' ) | |
( * s > = ' A ' & & * s < = ' Z ' ) | |
* s = = ' - ' | | * s = = ' _ ' | | * s = = ' . ' )
{
if ( ! n )
break ;
n - - ;
* d + + = * s + + ;
}
else
{
if ( n < 3 )
break ;
n - = 3 ;
* d + + = ' % ' ;
* d + + = hex [ * s > > 4 ] ;
* d + + = hex [ * s & 15 ] ;
s + + ;
}
}
* d = 0 ;
}
2017-09-20 11:27:13 +00:00
static int sasl_oauth2_initial ( struct sasl_ctx_s * ctx , char * buf , int bufsize )
2013-07-13 12:14:32 +00:00
{
char proto [ 256 ] ;
char host [ 256 ] ;
char resource [ 256 ] ;
int sock , l , rl = 0 ;
char result [ 8192 ] ;
xmltree_t * x ;
2017-09-20 11:27:13 +00:00
if ( * ctx - > password_plain )
2013-07-13 12:14:32 +00:00
return - 1 ;
2017-09-20 11:27:13 +00:00
if ( 0 ) //*jcl->password_plain)
2013-07-13 12:14:32 +00:00
{
char body [ 4096 ] ;
char header [ 4096 ] ;
2017-09-20 11:27:13 +00:00
URL_Split ( ctx - > oauth2 . refreshurl , proto , sizeof ( proto ) , host , sizeof ( host ) , resource , sizeof ( resource ) ) ;
2013-07-13 12:14:32 +00:00
* body = 0 ;
Q_strlcat ( body , " client_id= " , sizeof ( body ) ) ;
2017-09-20 11:27:13 +00:00
Q_strlcat_urlencode ( body , ctx - > oauth2 . clientid , sizeof ( body ) ) ;
2013-07-13 12:14:32 +00:00
Q_strlcat ( body , " &client_secret= " , sizeof ( body ) ) ;
2017-09-20 11:27:13 +00:00
Q_strlcat_urlencode ( body , ctx - > oauth2 . clientsecret , sizeof ( body ) ) ;
2013-07-13 12:14:32 +00:00
Q_strlcat ( body , " & " , sizeof ( body ) ) ;
Q_strlcat ( body , " grant_type=password&username= " , sizeof ( body ) ) ;
2017-09-20 11:27:13 +00:00
Q_strlcat_urlencode ( body , ctx - > oauth2 . useraccount , sizeof ( body ) ) ;
2013-07-13 12:14:32 +00:00
Q_strlcat ( body , " &password= " , sizeof ( body ) ) ;
2017-09-20 11:27:13 +00:00
Q_strlcat_urlencode ( body , ctx - > password_plain , sizeof ( body ) ) ;
2013-07-13 12:14:32 +00:00
Q_strlcat ( body , " &response_type=code " , sizeof ( body ) ) ;
Q_strlcat ( body , " &redirect_uri= " , sizeof ( body ) ) ;
Q_strlcat_urlencode ( body , " urn:ietf:wg:oauth:2.0:oob " , sizeof ( body ) ) ;
Q_strlcat ( body , " &scope= " , sizeof ( body ) ) ;
2017-09-20 11:27:13 +00:00
Q_strlcat_urlencode ( body , ctx - > oauth2 . scope , sizeof ( body ) ) ;
2013-07-13 12:14:32 +00:00
Q_snprintf ( header , sizeof ( header ) ,
" POST %s HTTP/1.1 \r \n "
" Host: %s \r \n "
//"Authorization: Basic %s\r\n"
2019-02-16 19:09:07 +00:00
" Content-length: %u \r \n "
2013-07-13 12:14:32 +00:00
" Content-Type: application/x-www-form-urlencoded \r \n "
" Connection: close \r \n "
" \r \n " ,
resource ,
host ,
2019-02-16 19:09:07 +00:00
( unsigned ) strlen ( body ) ) ;
2013-07-13 12:14:32 +00:00
2019-09-04 07:59:40 +00:00
sock = netfuncs - > TCPConnect ( host , 443 ) ;
if ( netfuncs - > SetTLSClient ( sock , host ) > = 0 )
2013-07-13 12:14:32 +00:00
{
2019-09-04 07:59:40 +00:00
netfuncs - > Send ( sock , header , strlen ( header ) ) ;
netfuncs - > Send ( sock , body , strlen ( body ) ) ;
while ( 1 )
{
//FIXME: infinite loop!
l = netfuncs - > Recv ( sock , result + rl , sizeof ( result ) - rl ) ;
if ( l < 0 )
break ;
else
rl + = l ;
}
2013-07-13 12:14:32 +00:00
}
2019-09-04 07:59:40 +00:00
netfuncs - > Close ( sock ) ;
2013-07-13 12:14:32 +00:00
result [ rl ] = 0 ;
Con_Printf ( " Got %s \n " , result ) ;
}
//if we have nothing, load up a browser to ask for the first token
2017-09-20 11:27:13 +00:00
if ( ! * ctx - > oauth2 . refreshtoken & & ! * ctx - > oauth2 . authtoken )
2013-07-13 12:14:32 +00:00
{
char url [ 4096 ] ;
* url = 0 ;
2017-09-20 11:27:13 +00:00
Q_strlcat ( url , ctx - > oauth2 . obtainurl , sizeof ( url ) ) ;
2013-07-13 12:14:32 +00:00
Q_strlcat ( url , " ?redirect_uri= " , sizeof ( url ) ) ;
Q_strlcat_urlencode ( url , " urn:ietf:wg:oauth:2.0:oob " , sizeof ( url ) ) ;
Q_strlcat ( url , " &%72esponse_type=code&client_id= " , sizeof ( url ) ) ; //%72 = r. fucking ezquake colour codes. works with firefox anyway. no idea if that's the server changing it to an r or not. :s
2017-09-20 11:27:13 +00:00
Q_strlcat_urlencode ( url , ctx - > oauth2 . clientid , sizeof ( url ) ) ;
2013-07-13 12:14:32 +00:00
Q_strlcat ( url , " &scope= " , sizeof ( url ) ) ;
2017-09-20 11:27:13 +00:00
Q_strlcat_urlencode ( url , ctx - > oauth2 . scope , sizeof ( url ) ) ;
2013-07-13 12:14:32 +00:00
Q_strlcat ( url , " &access_type=offline " , sizeof ( url ) ) ;
Q_strlcat ( url , " &login_hint= " , sizeof ( url ) ) ;
2017-09-20 11:27:13 +00:00
Q_strlcat_urlencode ( url , ctx - > oauth2 . useraccount , sizeof ( url ) ) ;
2013-07-13 12:14:32 +00:00
2017-09-20 11:27:13 +00:00
// Con_Printf("Please visit ^[^4%s\\url\\%s^] and then enter:\n^[/"COMMANDPREFIX"%i /oa2token <TOKEN>^]\nNote: you can right-click the link to copy it to your browser, and you can use ctrl+v to paste the resulting auth token as part of the given command.\n", url, url, jcl->accountnum);
2013-07-13 12:14:32 +00:00
//wait for user to act.
return - 2 ;
}
//refresh token is not known, try and get one
2017-09-20 11:27:13 +00:00
if ( ! * ctx - > oauth2 . refreshtoken & & * ctx - > oauth2 . authtoken )
2013-07-13 12:14:32 +00:00
{
xmltree_t * x ;
char body [ 4096 ] ;
char header [ 4096 ] ;
//send a refresh request
* body = 0 ;
Q_strlcat ( body , " code= " , sizeof ( body ) ) ;
2017-09-20 11:27:13 +00:00
Q_strlcat_urlencode ( body , ctx - > oauth2 . authtoken , sizeof ( body ) ) ;
2013-07-13 12:14:32 +00:00
Q_strlcat ( body , " &client_id= " , sizeof ( body ) ) ;
2017-09-20 11:27:13 +00:00
Q_strlcat_urlencode ( body , ctx - > oauth2 . clientid , sizeof ( body ) ) ;
2013-07-13 12:14:32 +00:00
Q_strlcat ( body , " &client_secret= " , sizeof ( body ) ) ;
2017-09-20 11:27:13 +00:00
Q_strlcat_urlencode ( body , ctx - > oauth2 . clientsecret , sizeof ( body ) ) ;
2013-07-13 12:14:32 +00:00
Q_strlcat ( body , " &redirect_uri= " , sizeof ( body ) ) ;
Q_strlcat_urlencode ( body , " urn:ietf:wg:oauth:2.0:oob " , sizeof ( body ) ) ;
Q_strlcat ( body , " &grant_type= " , sizeof ( body ) ) ;
Q_strlcat_urlencode ( body , " authorization_code " , sizeof ( body ) ) ;
2017-09-20 11:27:13 +00:00
URL_Split ( ctx - > oauth2 . refreshurl , proto , sizeof ( proto ) , host , sizeof ( host ) , resource , sizeof ( resource ) ) ;
2013-07-13 12:14:32 +00:00
Q_snprintf ( header , sizeof ( header ) ,
" POST %s HTTP/1.1 \r \n "
" Host: %s \r \n "
//"Authorization: Basic %s\r\n"
2019-02-16 19:09:07 +00:00
" Content-length: %u \r \n "
2013-07-13 12:14:32 +00:00
" Content-Type: application/x-www-form-urlencoded \r \n "
" user-agent: fteqw-plugin-xmpp \r \n "
" Connection: close \r \n "
" \r \n " ,
2019-02-16 19:09:07 +00:00
resource , host , ( unsigned ) strlen ( body ) ) ;
2013-07-13 12:14:32 +00:00
Con_Printf ( " XMPP: Requesting access token \n " ) ;
2019-09-04 07:59:40 +00:00
sock = netfuncs - > TCPConnect ( host , 443 ) ;
if ( netfuncs - > SetTLSClient ( sock , host ) > = 0 )
{
netfuncs - > Send ( sock , header , strlen ( header ) ) ;
netfuncs - > Send ( sock , body , strlen ( body ) ) ;
while ( 1 )
{
//FIXME: infinite loop!
l = netfuncs - > Recv ( sock , result + rl , sizeof ( result ) - rl ) ;
if ( l < 0 )
break ;
else
rl + = l ;
}
2013-07-13 12:14:32 +00:00
}
result [ rl ] = 0 ;
2019-09-04 07:59:40 +00:00
netfuncs - > Close ( sock ) ;
2013-07-13 12:14:32 +00:00
//should contain something like:
//{
//"access_token" : "ya29.AHES6ZR-_Sx0UpexZdgqQwR8LFqTx-GFi-Zrq4nKrcLLA98N7g",
//"token_type" : "Bearer",
//"expires_in" : 3600
//}
l = strstr ( result , " \r \n \r \n " ) - result ;
l + = 4 ;
if ( l < 0 | | l > rl )
l = rl ;
x = XML_FromJSON ( NULL , " oauth2 " , result , & l , rl ) ;
2013-11-21 23:02:28 +00:00
XML_ConPrintTree ( x , " " , 1 ) ;
2017-09-20 11:27:13 +00:00
free ( ctx - > oauth2 . accesstoken ) ;
free ( ctx - > oauth2 . refreshtoken ) ;
ctx - > oauth2 . accesstoken = strdup ( XML_GetChildBody ( x , " access_token " , " " ) ) ;
// ctx->oauth2.token_type = strdup(XML_GetChildBody(x, "token_type", ""));
// ctx->oauth2.expires_in = strdup(XML_GetChildBody(x, "expires_in", ""));
ctx - > oauth2 . refreshtoken = strdup ( XML_GetChildBody ( x , " refresh_token " , " " ) ) ;
2013-07-13 12:14:32 +00:00
//in theory, the auth token is no longer valid/needed
2017-09-20 11:27:13 +00:00
free ( ctx - > oauth2 . authtoken ) ;
ctx - > oauth2 . authtoken = strdup ( " " ) ;
2013-07-13 12:14:32 +00:00
}
//refresh our refresh token, obtaining a usable sign-in token at the same time.
2017-09-20 11:27:13 +00:00
else if ( ! * ctx - > oauth2 . accesstoken )
2013-07-13 12:14:32 +00:00
{
char body [ 4096 ] ;
char header [ 4096 ] ;
2017-10-12 12:02:25 +00:00
const char * newrefresh ;
2013-07-13 12:14:32 +00:00
//send a refresh request
* body = 0 ;
Q_strlcat ( body , " client_id= " , sizeof ( body ) ) ;
2017-09-20 11:27:13 +00:00
Q_strlcat_urlencode ( body , ctx - > oauth2 . clientid , sizeof ( body ) ) ;
2013-07-13 12:14:32 +00:00
Q_strlcat ( body , " &client_secret= " , sizeof ( body ) ) ;
2017-09-20 11:27:13 +00:00
Q_strlcat_urlencode ( body , ctx - > oauth2 . clientsecret , sizeof ( body ) ) ;
2013-07-13 12:14:32 +00:00
Q_strlcat ( body , " &grant_type= " , sizeof ( body ) ) ;
Q_strlcat_urlencode ( body , " refresh_token " , sizeof ( body ) ) ;
Q_strlcat ( body , " &refresh_token= " , sizeof ( body ) ) ;
2017-09-20 11:27:13 +00:00
Q_strlcat_urlencode ( body , ctx - > oauth2 . refreshtoken , sizeof ( body ) ) ;
URL_Split ( ctx - > oauth2 . refreshurl , proto , sizeof ( proto ) , host , sizeof ( host ) , resource , sizeof ( resource ) ) ;
2013-07-13 12:14:32 +00:00
Q_snprintf ( header , sizeof ( header ) ,
" POST %s HTTP/1.1 \r \n "
" Host: %s \r \n "
//"Authorization: Basic %s\r\n"
2019-02-16 19:09:07 +00:00
" Content-length: %u \r \n "
2013-07-13 12:14:32 +00:00
" Content-Type: application/x-www-form-urlencoded \r \n "
" user-agent: fteqw-plugin-xmpp \r \n "
" Connection: close \r \n "
" \r \n " ,
2019-02-16 19:09:07 +00:00
resource , host , ( unsigned ) strlen ( body ) ) ;
2013-07-13 12:14:32 +00:00
Con_Printf ( " XMPP: Refreshing access token \n " ) ;
2019-09-04 07:59:40 +00:00
sock = netfuncs - > TCPConnect ( host , 443 ) ;
if ( netfuncs - > SetTLSClient ( sock , host ) > = 0 )
{
netfuncs - > Send ( sock , header , strlen ( header ) ) ;
netfuncs - > Send ( sock , body , strlen ( body ) ) ;
while ( 1 )
{
//FIXME: infinite loop!
l = netfuncs - > Recv ( sock , result + rl , sizeof ( result ) - rl ) ;
if ( l < 0 )
break ;
else
rl + = l ;
}
2013-07-13 12:14:32 +00:00
}
2019-09-04 07:59:40 +00:00
netfuncs - > Close ( sock ) ;
2013-07-13 12:14:32 +00:00
result [ rl ] = 0 ;
l = strstr ( result , " \r \n \r \n " ) - result ;
l + = 4 ;
if ( l < 0 | | l > rl )
l = rl ;
x = XML_FromJSON ( NULL , " oauth2 " , result , & l , rl ) ;
2015-08-02 19:08:36 +00:00
// XML_ConPrintTree(x, "", 1);
2013-07-13 12:14:32 +00:00
newrefresh = XML_GetChildBody ( x , " refresh_token " , NULL ) ;
2017-09-20 11:27:13 +00:00
free ( ctx - > oauth2 . accesstoken ) ;
ctx - > oauth2 . accesstoken = strdup ( XML_GetChildBody ( x , " access_token " , " " ) ) ;
if ( newrefresh | | ! * ctx - > oauth2 . accesstoken )
2013-07-13 12:14:32 +00:00
{
2017-09-20 11:27:13 +00:00
free ( ctx - > oauth2 . refreshtoken ) ;
ctx - > oauth2 . refreshtoken = strdup ( XML_GetChildBody ( x , " refresh_token " , " " ) ) ;
2013-07-13 12:14:32 +00:00
}
2017-09-20 11:27:13 +00:00
// ctx->oauth2.token_type = strdup(XML_GetChildBody(x, "token_type", ""));
// ctx->oauth2.expires_in = strdup(XML_GetChildBody(x, "expires_in", ""));
2013-07-13 12:14:32 +00:00
//refresh token may mutate. follow the mutation.
}
2017-09-20 11:27:13 +00:00
else if ( * ctx - > oauth2 . accesstoken )
2013-07-13 12:14:32 +00:00
Con_Printf ( " XMPP: Using explicit access token \n " ) ;
2017-09-20 11:27:13 +00:00
if ( * ctx - > oauth2 . accesstoken )
2013-07-13 12:14:32 +00:00
{
int len = 0 ;
2017-09-20 11:27:13 +00:00
if ( * ctx - > oauth2 . useraccount )
2013-07-13 12:14:32 +00:00
{
//realm isn't specified
buf [ len + + ] = 0 ;
2017-09-20 11:27:13 +00:00
memcpy ( buf + len , ctx - > oauth2 . useraccount , strlen ( ctx - > oauth2 . useraccount ) ) ;
len + = strlen ( ctx - > oauth2 . useraccount ) ;
2013-07-13 12:14:32 +00:00
buf [ len + + ] = 0 ;
}
2017-09-20 11:27:13 +00:00
memcpy ( buf + len , ctx - > oauth2 . accesstoken , strlen ( ctx - > oauth2 . accesstoken ) ) ;
len + = strlen ( ctx - > oauth2 . accesstoken ) ;
2013-07-13 12:14:32 +00:00
Con_Printf ( " XMPP: Signing in \n " ) ;
2017-09-20 11:27:13 +00:00
free ( ctx - > oauth2 . accesstoken ) ;
ctx - > oauth2 . accesstoken = strdup ( " " ) ;
2013-07-13 12:14:32 +00:00
return len ;
}
//if the reply has a refresh token in it, clear out any password info
2013-08-21 08:59:26 +00:00
return - 2 ;
2013-07-13 12:14:32 +00:00
}
//in descending priority order
2019-09-04 07:59:40 +00:00
static saslmethod_t saslmethods [ ] =
2013-07-13 12:14:32 +00:00
{
2021-04-14 05:21:04 +00:00
{ " SCRAM-SHA-512-PLUS " , sasl_scramsha512plus_initial , sasl_scram_challenge , sasl_scram_final } , //lots of unreadable hashing, with added channel bindings
{ " SCRAM-SHA-256-PLUS " , sasl_scramsha256plus_initial , sasl_scram_challenge , sasl_scram_final } , //lots of unreadable hashing, with added channel bindings
2017-09-20 11:27:13 +00:00
{ " SCRAM-SHA-1-PLUS " , sasl_scramsha1plus_initial , sasl_scram_challenge , sasl_scram_final } , //lots of unreadable hashing, with added channel bindings
2021-04-14 05:21:04 +00:00
{ " SCRAM-SHA-512 " , sasl_scramsha512minus_initial , sasl_scram_challenge , sasl_scram_final } , //lots of unreadable hashing
{ " SCRAM-SHA-256 " , sasl_scramsha256minus_initial , sasl_scram_challenge , sasl_scram_final } , //lots of unreadable hashing
2017-09-20 11:27:13 +00:00
{ " SCRAM-SHA-1 " , sasl_scramsha1minus_initial , sasl_scram_challenge , sasl_scram_final } , //lots of unreadable hashing
2021-04-14 05:21:04 +00:00
{ " DIGEST-MD5 " , sasl_digestmd5_initial , sasl_digestmd5_challenge , NULL } , //kinda silly but still better than plaintext.
2017-09-20 11:27:13 +00:00
{ " PLAIN " , sasl_plain_initial , NULL , NULL } , //realm\0username\0password
2021-04-14 05:21:04 +00:00
{ NULL , sasl_oauth2_initial , NULL , NULL } //potentially avoids having to ask+store their password. a browser is required to obtain auth token for us, so basically like pulling teeth.
2013-07-13 12:14:32 +00:00
} ;
/*
pidgin ' s msn request
https : //oauth.live.com/authorize?client_id=000000004C07035A&scope=wl.messenger,wl.basic,wl.offline_access,wl.contacts_create,wl.share&response_type=token&redirect_uri=http://pidgin.im/
*/
2005-12-11 20:11:22 +00:00
2013-06-23 02:33:52 +00:00
struct subtree_s ;
2017-10-12 12:02:25 +00:00
//void JCL_AddClientMessagef(jclient_t *jcl, char *fmt, ...);
//qboolean JCL_FindBuddy(jclient_t *jcl, const char *jid, buddy_t **buddy, bresource_t **bres, qboolean create);
2013-06-29 16:01:07 +00:00
void JCL_GeneratePresence ( jclient_t * jcl , qboolean force ) ;
2017-10-12 12:02:25 +00:00
struct iq_s * JCL_SendIQf ( jclient_t * jcl , qboolean ( * callback ) ( jclient_t * jcl , struct subtree_s * tree , struct iq_s * iq ) , const char * iqtype , const char * target , const char * fmt , . . . ) ;
//struct iq_s *JCL_SendIQNode(jclient_t *jcl, qboolean (*callback) (jclient_t *jcl, xmltree_t *tree, struct iq_s *iq), const char *iqtype, const char *target, xmltree_t *node, qboolean destroynode);
2015-04-27 06:19:33 +00:00
void JCL_CloseConnection ( jclient_t * jcl , const char * reason , qboolean reconnect ) ;
2017-10-12 12:02:25 +00:00
void JCL_JoinMUCChat ( jclient_t * jcl , const char * room , const char * server , const char * myhandle , const char * password ) ;
2013-11-21 23:02:28 +00:00
static qboolean JCL_BuddyVCardReply ( jclient_t * jcl , xmltree_t * tree , struct iq_s * iq ) ;
2013-07-13 12:14:32 +00:00
2017-10-12 12:02:25 +00:00
void JCL_GenLink ( jclient_t * jcl , char * out , int outlen , const char * action , const char * context , const char * contextres , const char * sid , const char * txtfmt , . . . )
2013-07-13 12:14:32 +00:00
{
va_list argptr ;
qboolean textonly = false ;
* out = 0 ;
if ( ! strchr ( txtfmt , ' % ' ) )
2013-11-21 23:02:28 +00:00
{ //protect against potential bugs and exploits.
2013-07-13 12:14:32 +00:00
Q_strlcpy ( out , " bad link text " , outlen ) ;
return ;
}
2013-11-21 23:02:28 +00:00
//FIXME: validate that there is no \\ markup within any section that would break the link.
//FIXME: validate that ^[ and ^] are not used, as that would also mess things up. add markup for every ^?
2013-07-13 12:14:32 +00:00
if ( textonly )
{
va_start ( argptr , txtfmt ) ;
Q_strlcat ( out , " [ " , outlen ) ;
Q_vsnprintf ( out , outlen , txtfmt , argptr ) ;
Q_strlcat ( out , " ] " , outlen ) ;
va_end ( argptr ) ;
return ;
}
Q_strlcat ( out , " ^[[ " , outlen ) ;
va_start ( argptr , txtfmt ) ;
Q_vsnprintf ( out + 3 , outlen - 3 , txtfmt , argptr ) ;
va_end ( argptr ) ;
Q_strlcat ( out , " ] " , outlen ) ;
if ( jcl & & jcl - > accountnum )
{
char acc [ 32 ] ;
Q_snprintf ( acc , sizeof ( acc ) , " %i " , jcl - > accountnum ) ;
Q_strlcat ( out , " \\ xmppacc \\ " , outlen ) ;
Q_strlcat ( out , acc , outlen ) ;
}
if ( action )
{
Q_strlcat ( out , " \\ xmppact \\ " , outlen ) ;
Q_strlcat ( out , action , outlen ) ;
}
if ( context )
{
Q_strlcat ( out , " \\ xmpp \\ " , outlen ) ;
Q_strlcat ( out , context , outlen ) ;
if ( contextres )
{
Q_strlcat ( out , " / " , outlen ) ;
Q_strlcat ( out , contextres , outlen ) ;
}
}
if ( sid )
{
Q_strlcat ( out , " \\ xmppsid \\ " , outlen ) ;
Q_strlcat ( out , sid , outlen ) ;
}
Q_strlcat ( out , " ^] " , outlen ) ;
}
2013-06-23 02:33:52 +00:00
2013-06-29 16:01:07 +00:00
char * TrimResourceFromJid ( char * jid )
2013-06-23 02:33:52 +00:00
{
2013-06-29 16:01:07 +00:00
char * slash ;
slash = strchr ( jid , ' / ' ) ;
if ( slash )
{
* slash = ' \0 ' ;
return slash + 1 ;
}
return NULL ;
}
2013-06-23 02:33:52 +00:00
2019-09-04 07:59:40 +00:00
qboolean JCL_ConsoleLinkMouseOver ( float x , float y )
2013-11-21 23:02:28 +00:00
{
jclient_t * jcl ;
// char text[256];
char link [ 256 ] ;
char who [ 256 ] ;
char what [ 256 ] ;
char which [ 256 ] ;
char * actiontext ;
int i ;
2016-07-12 00:40:13 +00:00
buddy_t * b , * me = NULL ;
2013-11-21 23:02:28 +00:00
bresource_t * br ;
2019-09-04 07:59:40 +00:00
// cmdfuncs->Argv(0, text, sizeof(text));
cmdfuncs - > Argv ( 1 , link , sizeof ( link ) ) ;
2013-11-21 23:02:28 +00:00
JCL_Info_ValueForKey ( link , " xmpp " , who , sizeof ( who ) ) ;
JCL_Info_ValueForKey ( link , " xmppact " , what , sizeof ( what ) ) ;
JCL_Info_ValueForKey ( link , " xmppacc " , which , sizeof ( which ) ) ;
if ( ! * who )
return false ;
i = atoi ( which ) ;
i = bound ( 0 , i , sizeof ( jclients ) / sizeof ( jclients [ 0 ] ) ) ;
jcl = jclients [ i ] ;
x + = 16 ;
if ( ! jcl )
return false ;
if ( jcl - > status ! = JCL_ACTIVE )
{
2019-09-04 07:59:40 +00:00
drawfuncs - > String ( x , y , " ^&C0You are currently offline " ) ;
2013-11-21 23:02:28 +00:00
return true ;
}
if ( ! strcmp ( what , " pauth " ) )
actiontext = " Befriend " ;
else if ( ! strcmp ( what , " pdeny " ) )
actiontext = " Decline " ;
# ifdef FILETRANSFERS
else if ( ! strcmp ( what , " fauth " ) & & ( jcl - > enabledcapabilities & CAP_SIFT ) )
actiontext = " Receive " ;
else if ( ! strcmp ( what , " fdeny " ) & & ( jcl - > enabledcapabilities & CAP_SIFT ) )
actiontext = " Decline " ;
# endif
# ifdef JINGLE
else if ( ! strcmp ( what , " jauth " ) & & ( jcl - > enabledcapabilities & ( CAP_GAMEINVITE | CAP_VOICE | CAP_VIDEO | CAP_GOOGLE_VOICE ) ) )
actiontext = " Answer " ;
else if ( ! strcmp ( what , " jdeny " ) & & ( jcl - > enabledcapabilities & ( CAP_GAMEINVITE | CAP_VOICE | CAP_VIDEO | CAP_GOOGLE_VOICE ) ) )
actiontext = " Hang Up " ;
else if ( ! strcmp ( what , " join " ) & & ( jcl - > enabledcapabilities & CAP_GAMEINVITE ) )
actiontext = " Join Game " ;
else if ( ! strcmp ( what , " invite " ) & & ( jcl - > enabledcapabilities & CAP_GAMEINVITE ) )
actiontext = " Invite To Game " ;
else if ( ! strcmp ( what , " call " ) & & ( jcl - > enabledcapabilities & ( CAP_VOICE | CAP_GOOGLE_VOICE ) ) )
actiontext = " Call " ;
else if ( ! strcmp ( what , " vidcall " ) & & ( jcl - > enabledcapabilities & CAP_VIDEO ) )
actiontext = " Video Call " ;
# endif
else if ( ! strcmp ( what , " mucjoin " ) )
actiontext = " Join Chat: " ;
else if ( ( * who & & ! * what ) | | ! strcmp ( what , " msg " ) )
actiontext = " Chat With " ;
else
return false ;
JCL_FindBuddy ( jcl , who , & b , & br , false ) ;
if ( ! b )
return false ;
2017-09-20 11:27:13 +00:00
JCL_FindBuddy ( jcl , jcl - > fulljid , & me , NULL , true ) ;
2013-11-21 23:02:28 +00:00
2019-09-04 07:59:40 +00:00
if ( ( jcl - > enabledcapabilities & CAP_AVATARS ) & & drawfuncs )
2013-11-21 23:02:28 +00:00
{
2015-04-27 06:19:33 +00:00
if ( b - > vcardphotochanged & & b - > friended & & ! jcl - > avatarupdate )
2013-11-21 23:02:28 +00:00
{
b - > vcardphotochanged = false ;
2015-04-27 06:19:33 +00:00
Con_Printf ( " Querying %s's photo \n " , b - > accountdomain ) ;
jcl - > avatarupdate = JCL_SendIQf ( jcl , JCL_BuddyVCardReply , " get " , b - > accountdomain , " <vCard xmlns='vcard-temp'/> " ) ;
2013-11-21 23:02:28 +00:00
}
if ( b - > image )
{
//xep-0153: The image height and width SHOULD be between thirty-two (32) and ninety-six (96) pixels; the recommended size is sixty-four (64) pixels high and sixty-four (64) pixels wide.
//96 just feels far too large for a game that was origionally running at a resolution of 320*200.
//FIXME: we should proably respect the image's aspect ratio...
# define IMGSIZE 96 / 2
2019-09-04 07:59:40 +00:00
drawfuncs - > Image ( x , y , IMGSIZE , IMGSIZE , 0 , 0 , 1 , 1 , b - > image ) ;
2013-11-21 23:02:28 +00:00
x + = IMGSIZE + 8 ;
}
}
2019-09-04 07:59:40 +00:00
drawfuncs - > String ( x , y , va ( " ^&F0%s ^2%s " , actiontext , b - > name ) ) ;
2013-11-21 23:02:28 +00:00
y + = 8 ;
2019-09-04 07:59:40 +00:00
drawfuncs - > String ( x , y , va ( " ^&F0%s " , b - > accountdomain ) ) ;
2013-11-21 23:02:28 +00:00
y + = 8 ;
if ( br )
{
2019-09-04 07:59:40 +00:00
drawfuncs - > String ( x , y , va ( " ^&F0 %s " , br - > resource ) ) ;
2013-11-21 23:02:28 +00:00
y + = 8 ;
}
if ( b = = me )
2019-09-04 07:59:40 +00:00
drawfuncs - > String ( x , y , " ^&90 " " You " ) ;
2013-11-21 23:02:28 +00:00
else if ( ! b - > friended )
2019-09-04 07:59:40 +00:00
drawfuncs - > String ( x , y , " ^&C0 " " Unknown " ) ;
2013-11-21 23:02:28 +00:00
y + = 8 ;
return true ;
}
2019-09-04 07:59:40 +00:00
qboolean JCL_ConsoleLink ( void )
2013-06-23 02:33:52 +00:00
{
2013-07-13 12:14:32 +00:00
jclient_t * jcl ;
2013-06-23 02:33:52 +00:00
char link [ 256 ] ;
2013-06-29 16:01:07 +00:00
char who [ 256 ] ;
char what [ 256 ] ;
2013-07-13 12:14:32 +00:00
char which [ 256 ] ;
int i ;
2017-10-12 12:02:25 +00:00
buddy_t * b = NULL ;
2019-09-04 07:59:40 +00:00
// cmdfuncs->Argv(0, text, sizeof(text));
cmdfuncs - > Argv ( 1 , link , sizeof ( link ) ) ;
2013-06-23 02:33:52 +00:00
2013-06-29 16:01:07 +00:00
JCL_Info_ValueForKey ( link , " xmpp " , who , sizeof ( who ) ) ;
JCL_Info_ValueForKey ( link , " xmppact " , what , sizeof ( what ) ) ;
2013-07-13 12:14:32 +00:00
JCL_Info_ValueForKey ( link , " xmppacc " , which , sizeof ( which ) ) ;
2013-06-29 16:01:07 +00:00
if ( ! * who & & ! * what )
return false ;
2013-07-13 12:14:32 +00:00
i = atoi ( which ) ;
i = bound ( 0 , i , sizeof ( jclients ) / sizeof ( jclients [ 0 ] ) ) ;
jcl = jclients [ i ] ;
2015-04-27 06:19:33 +00:00
jclient_updatebuddylist = true ;
2013-06-29 16:01:07 +00:00
if ( ! strcmp ( what , " pauth " ) )
2013-06-23 02:33:52 +00:00
{
//we should friend them too.
2013-07-13 12:14:32 +00:00
if ( jcl & & jcl - > status = = JCL_ACTIVE )
JCL_AddClientMessagef ( jcl , " <presence to='%s' type='subscribed'/> " , who ) ;
2013-06-23 02:33:52 +00:00
return true ;
}
2013-06-29 16:01:07 +00:00
else if ( ! strcmp ( what , " pdeny " ) )
2013-06-23 02:33:52 +00:00
{
2013-07-13 12:14:32 +00:00
if ( jcl & & jcl - > status = = JCL_ACTIVE )
JCL_AddClientMessagef ( jcl , " <presence to='%s' type='unsubscribed'/> " , who ) ;
2013-06-23 02:33:52 +00:00
return true ;
}
2013-10-29 17:38:22 +00:00
# ifdef FILETRANSFERS
2013-11-21 23:02:28 +00:00
else if ( ! strcmp ( what , " fauth " ) & & ( jcl - > enabledcapabilities & CAP_SIFT ) )
2013-10-29 17:38:22 +00:00
{
JCL_Info_ValueForKey ( link , " xmppsid " , what , sizeof ( what ) ) ;
if ( jcl & & jcl - > status = = JCL_ACTIVE )
2013-11-21 23:02:28 +00:00
XMPP_FT_AcceptFile ( jcl , atoi ( what ) , true ) ;
2013-10-29 17:38:22 +00:00
return true ;
}
2013-11-21 23:02:28 +00:00
else if ( ! strcmp ( what , " fdeny " ) & & ( jcl - > enabledcapabilities & CAP_SIFT ) )
2013-10-29 17:38:22 +00:00
{
JCL_Info_ValueForKey ( link , " xmppsid " , what , sizeof ( what ) ) ;
if ( jcl & & jcl - > status = = JCL_ACTIVE )
2013-11-21 23:02:28 +00:00
XMPP_FT_AcceptFile ( jcl , atoi ( what ) , false ) ;
2013-10-29 17:38:22 +00:00
return true ;
}
# endif
2013-07-13 12:14:32 +00:00
# ifdef JINGLE
2013-11-21 23:02:28 +00:00
//jauth/jdeny are used to accept/cancel all jingle/gingle content types.
else if ( ! strcmp ( what , " jauth " ) & & ( jcl - > enabledcapabilities & ( CAP_VOICE | CAP_VIDEO | CAP_GAMEINVITE | CAP_GOOGLE_VOICE ) ) )
2013-06-23 02:33:52 +00:00
{
2013-06-29 16:01:07 +00:00
JCL_Info_ValueForKey ( link , " xmppsid " , what , sizeof ( what ) ) ;
2013-07-13 12:14:32 +00:00
if ( jcl & & jcl - > status = = JCL_ACTIVE )
JCL_Join ( jcl , who , what , true , ICEP_INVALID ) ;
2017-06-21 01:24:25 +00:00
jclient_updatebuddylist = true ;
2013-06-29 16:01:07 +00:00
return true ;
}
2013-11-21 23:02:28 +00:00
else if ( ! strcmp ( what , " jdeny " ) & & ( jcl - > enabledcapabilities & ( CAP_VOICE | CAP_VIDEO | CAP_GAMEINVITE | CAP_GOOGLE_VOICE ) ) )
2013-06-29 16:01:07 +00:00
{
JCL_Info_ValueForKey ( link , " xmppsid " , what , sizeof ( what ) ) ;
2013-07-13 12:14:32 +00:00
if ( jcl & & jcl - > status = = JCL_ACTIVE )
JCL_Join ( jcl , who , what , false , ICEP_INVALID ) ;
2017-06-21 01:24:25 +00:00
jclient_updatebuddylist = true ;
2013-06-29 16:01:07 +00:00
return true ;
}
2013-11-21 23:02:28 +00:00
else if ( ! strcmp ( what , " join " ) & & ( jcl - > enabledcapabilities & CAP_GAMEINVITE ) )
2013-06-29 16:01:07 +00:00
{
2013-07-13 12:14:32 +00:00
if ( jcl & & jcl - > status = = JCL_ACTIVE )
JCL_Join ( jcl , who , NULL , true , ICEP_QWCLIENT ) ;
2017-06-21 01:24:25 +00:00
jclient_updatebuddylist = true ;
2013-06-29 16:01:07 +00:00
return true ;
}
2013-11-21 23:02:28 +00:00
else if ( ! strcmp ( what , " invite " ) & & ( jcl - > enabledcapabilities & CAP_GAMEINVITE ) )
2013-06-29 16:01:07 +00:00
{
2013-07-13 12:14:32 +00:00
if ( jcl & & jcl - > status = = JCL_ACTIVE )
JCL_Join ( jcl , who , NULL , true , ICEP_QWSERVER ) ;
2017-06-21 01:24:25 +00:00
jclient_updatebuddylist = true ;
2013-06-29 16:01:07 +00:00
return true ;
}
2013-11-21 23:02:28 +00:00
else if ( ! strcmp ( what , " call " ) & & ( jcl - > enabledcapabilities & ( CAP_VOICE | CAP_GOOGLE_VOICE ) ) )
2013-06-29 16:01:07 +00:00
{
2013-07-13 12:14:32 +00:00
if ( jcl & & jcl - > status = = JCL_ACTIVE )
JCL_Join ( jcl , who , NULL , true , ICEP_VOICE ) ;
2017-06-21 01:24:25 +00:00
jclient_updatebuddylist = true ;
2013-06-29 16:01:07 +00:00
return true ;
2013-06-23 02:33:52 +00:00
}
2013-11-21 23:02:28 +00:00
else if ( ! strcmp ( what , " vidcall " ) & & ( jcl - > enabledcapabilities & ( CAP_VIDEO ) ) )
{
if ( jcl & & jcl - > status = = JCL_ACTIVE )
JCL_Join ( jcl , who , NULL , true , ICEP_VIDEO ) ;
2017-06-21 01:24:25 +00:00
jclient_updatebuddylist = true ;
2013-11-21 23:02:28 +00:00
return true ;
}
2013-07-13 12:14:32 +00:00
# endif
else if ( ! strcmp ( what , " mucjoin " ) )
{ //conference/chat join
2015-04-27 06:19:33 +00:00
if ( jcl )
{
JCL_Info_ValueForKey ( link , " xmppsid " , what , sizeof ( what ) ) ;
JCL_JoinMUCChat ( jcl , who , NULL , NULL , what ) ;
}
}
else if ( ! strcmp ( what , " addfriend " ) )
{
if ( jcl )
{
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleFloat ( BUDDYLISTTITLE , " linebuffered " , true ) ;
confuncs - > SetConsoleString ( BUDDYLISTTITLE , " footer " , " Please enter your friend's account name " ) ;
2015-04-27 06:19:33 +00:00
jclient_action_cl = jcl ;
jclient_action_buddy = NULL ;
jclient_action = ACT_ADDFRIEND ;
}
}
else if ( ! strcmp ( what , " connect " ) )
{
if ( jcl & & ( jcl - > status = = JCL_INACTIVE | | jcl - > status = = JCL_DEAD ) )
{
jcl - > status = JCL_DEAD ; //flag it as still trying to connect.
jcl - > timeout = jclient_curtime ; //do it now
}
}
else if ( ! strcmp ( what , " disconnect " ) )
{
if ( jcl )
{
if ( jcl - > status = = JCL_INACTIVE )
JCL_CloseConnection ( jcl , " " , false ) ;
else
{
JCL_CloseConnection ( jcl , " " , true ) ;
jcl - > status = JCL_INACTIVE ;
}
}
}
2017-06-21 01:24:25 +00:00
else if ( ! strcmp ( what , " forgetacc " ) )
{
if ( jcl )
{
JCL_CloseConnection ( jcl , " " , false ) ;
}
}
2015-04-27 06:19:33 +00:00
else if ( ! strcmp ( what , " newaccount " ) )
{
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleFloat ( BUDDYLISTTITLE , " linebuffered " , true ) ;
confuncs - > SetConsoleString ( BUDDYLISTTITLE , " footer " , " Please enter your XMPP account name \n eg: example@ " EXAMPLEDOMAIN ) ;
2015-04-27 06:19:33 +00:00
jclient_action_cl = jcl ;
jclient_action_buddy = NULL ;
jclient_action = ACT_NEWACCOUNT ;
}
2017-09-20 11:27:13 +00:00
else if ( ! strcmp ( what , " setausername " ) )
{
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleFloat ( BUDDYLISTTITLE , " linebuffered " , true ) ;
confuncs - > SetConsoleString ( BUDDYLISTTITLE , " footer " , " Please enter your user name " ) ;
2017-09-20 11:27:13 +00:00
jclient_action_cl = jcl ;
jclient_action_buddy = NULL ;
jclient_action = ACT_SETAUSERNAME ;
}
else if ( ! strcmp ( what , " setadomain " ) )
{
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleFloat ( BUDDYLISTTITLE , " linebuffered " , true ) ;
confuncs - > SetConsoleString ( BUDDYLISTTITLE , " footer " , " Please enter the domain for which your account is valid " ) ;
2017-09-20 11:27:13 +00:00
jclient_action_cl = jcl ;
jclient_action_buddy = NULL ;
jclient_action = ACT_SETADOMAIN ;
}
else if ( ! strcmp ( what , " setaserver " ) )
{
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleFloat ( BUDDYLISTTITLE , " linebuffered " , true ) ;
confuncs - > SetConsoleString ( BUDDYLISTTITLE , " footer " , " Please enter the server to connect to. " ) ;
2017-09-20 11:27:13 +00:00
jclient_action_cl = jcl ;
jclient_action_buddy = NULL ;
jclient_action = ACT_SETASERVER ;
}
else if ( ! strcmp ( what , " setaresource " ) )
{
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleFloat ( BUDDYLISTTITLE , " linebuffered " , true ) ;
confuncs - > SetConsoleString ( BUDDYLISTTITLE , " footer " , " Please enter some resource name. " ) ;
2017-09-20 11:27:13 +00:00
jclient_action_cl = jcl ;
jclient_action_buddy = NULL ;
jclient_action = ACT_SETARESOURCE ;
}
else if ( ! strcmp ( what , " setapassword " ) )
{
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleFloat ( BUDDYLISTTITLE , " linebuffered " , true ) ;
confuncs - > SetConsoleString ( BUDDYLISTTITLE , " footer " , " Please enter your XMPP account name \n eg: example@ " EXAMPLEDOMAIN ) ;
2017-09-20 11:27:13 +00:00
jclient_action_cl = jcl ;
jclient_action_buddy = NULL ;
jclient_action = ACT_SETAPASSWORD ;
}
else if ( ! strcmp ( what , " setasavepassword " ) )
jcl - > savepassword = ! jcl - > savepassword ;
else if ( ! strcmp ( what , " accopts " ) )
{
if ( jcl )
{
char footer [ 2048 ] ;
char link [ 512 ] ;
if ( jcl - > status = = JCL_INACTIVE )
JCL_GenLink ( jcl , link , sizeof ( link ) , " forgetacc " , NULL , NULL , NULL , " %s " , " Forget Account " ) ;
else if ( jcl - > status = = JCL_DEAD )
JCL_GenLink ( jcl , link , sizeof ( link ) , " disconnect " , NULL , NULL , NULL , " %s " , " Disable " ) ;
else
JCL_GenLink ( jcl , link , sizeof ( link ) , " disconnect " , NULL , NULL , NULL , " %s " , " Disconnect " ) ;
Q_strlcpy ( footer , " \n " , sizeof ( footer ) ) ;
Q_strlcat ( footer , link , sizeof ( footer ) ) ;
if ( jcl - > status = = JCL_INACTIVE )
JCL_GenLink ( jcl , link , sizeof ( link ) , " connect " , NULL , NULL , NULL , " %s " , " Connect " ) ;
else if ( jcl - > status = = JCL_DEAD )
JCL_GenLink ( jcl , link , sizeof ( link ) , " connect " , NULL , NULL , NULL , " %s " , " Reconnect " ) ;
else if ( jcl - > status = = JCL_ACTIVE )
JCL_GenLink ( jcl , link , sizeof ( link ) , " addfriend " , NULL , NULL , NULL , " %s " , " Add Friend " ) ;
else
* link = 0 ;
if ( * link )
{
Q_strlcat ( footer , " \n " , sizeof ( footer ) ) ;
Q_strlcat ( footer , link , sizeof ( footer ) ) ;
}
if ( jcl - > status = = JCL_INACTIVE )
{
JCL_GenLink ( jcl , link , sizeof ( link ) , " setausername " , NULL , NULL , NULL , " Username: %s " , jcl - > username ) ;
Q_strlcat ( footer , " \n " , sizeof ( footer ) ) ;
Q_strlcat ( footer , link , sizeof ( footer ) ) ;
JCL_GenLink ( jcl , link , sizeof ( link ) , " setadomain " , NULL , NULL , NULL , " Domain: %s " , jcl - > domain ) ;
Q_strlcat ( footer , " \n " , sizeof ( footer ) ) ;
Q_strlcat ( footer , link , sizeof ( footer ) ) ;
JCL_GenLink ( jcl , link , sizeof ( link ) , " setaserver " , NULL , NULL , NULL , " Server: %s " , * jcl - > serveraddr ? jcl - > serveraddr : " <AUTO> " ) ;
Q_strlcat ( footer , " \n " , sizeof ( footer ) ) ;
Q_strlcat ( footer , link , sizeof ( footer ) ) ;
JCL_GenLink ( jcl , link , sizeof ( link ) , " setaresource " , NULL , NULL , NULL , " Resource: %s " , jcl - > resource ) ;
Q_strlcat ( footer , " \n " , sizeof ( footer ) ) ;
Q_strlcat ( footer , link , sizeof ( footer ) ) ;
}
// if (jcl->status == JCL_INACTIVE)
{
JCL_GenLink ( jcl , link , sizeof ( link ) , " setapassword " , NULL , NULL , NULL , " Password: %s " , jcl - > sasl . password_plain ) ;
Q_strlcat ( footer , " \n " , sizeof ( footer ) ) ;
Q_strlcat ( footer , link , sizeof ( footer ) ) ;
JCL_GenLink ( jcl , link , sizeof ( link ) , " setasavepassword " , NULL , NULL , NULL , " Save Password: %s " , jcl - > savepassword ? " true " : " false " ) ;
Q_strlcat ( footer , " \n " , sizeof ( footer ) ) ;
Q_strlcat ( footer , link , sizeof ( footer ) ) ;
}
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleString ( BUDDYLISTTITLE , " footer " , footer ) ;
2017-09-20 11:27:13 +00:00
}
}
2015-04-27 06:19:33 +00:00
else if ( ! strcmp ( what , " buddyopts " ) )
{
char footer [ 2048 ] ;
char chatlink [ 512 ] ;
char unfriend [ 512 ] ;
char realias [ 512 ] ;
JCL_FindBuddy ( jcl , * who ? who : jcl - > defaultdest , & b , NULL , false ) ;
if ( b )
{
2017-10-12 12:02:25 +00:00
if ( b - > btype = = BT_CHATROOM )
{
JCL_GenLink ( jcl , chatlink , sizeof ( chatlink ) , NULL , b - > accountdomain , NULL , NULL , " Chat in %s " , b - > name ) ;
JCL_GenLink ( jcl , unfriend , sizeof ( unfriend ) , " unfriend " , b - > accountdomain , NULL , NULL , " Forget %s " , b - > name ) ;
JCL_GenLink ( jcl , realias , sizeof ( realias ) , " setbalias " , b - > accountdomain , NULL , NULL , " Set alias for %s " , b - > name ) ;
}
else
{
JCL_GenLink ( jcl , chatlink , sizeof ( chatlink ) , NULL , b - > accountdomain , NULL , NULL , " Chat with %s " , b - > name ) ;
JCL_GenLink ( jcl , unfriend , sizeof ( unfriend ) , " unfriend " , b - > accountdomain , NULL , NULL , " Unfriend %s " , b - > name ) ;
JCL_GenLink ( jcl , realias , sizeof ( realias ) , " setbalias " , b - > accountdomain , NULL , NULL , " Set alias for %s " , b - > name ) ;
}
2015-04-27 06:19:33 +00:00
Q_snprintf ( footer , sizeof ( footer ) , " \n %s \n %s \n %s " , chatlink , unfriend , realias ) ;
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleString ( BUDDYLISTTITLE , " footer " , footer ) ;
2015-04-27 06:19:33 +00:00
}
2013-07-13 12:14:32 +00:00
}
2017-10-12 12:02:25 +00:00
else if ( ! strcmp ( what , " unfriend " ) )
{
JCL_FindBuddy ( jcl , * who ? who : jcl - > defaultdest , & b , NULL , false ) ;
if ( b )
{
if ( b - > btype = = BT_CHATROOM )
{
JCL_AddClientMessagef ( jcl , " <presence to='%s/%s' type='unavailable'/> " , b - > accountdomain , b - > ourselves ? b - > ourselves - > resource : " " ) ;
JCL_ForgetBuddy ( jcl , b , NULL ) ;
}
else if ( b - > btype = = BT_ROSTER )
{
//hide from em
JCL_AddClientMessagef ( jcl , " <presence to='%s' type='unsubscribed'/> " , b - > accountdomain ) ;
//stop looking for em
JCL_AddClientMessagef ( jcl , " <presence to='%s' type='unsubscribe'/> " , b - > accountdomain ) ;
//stop listing em
JCL_SendIQf ( jcl , NULL , " set " , NULL , " <query xmlns='jabber:iq:roster'><item jid='%s' subscription='remove' /></query> " , b - > accountdomain ) ;
// b->btype = BT_UNKNOWN;
JCL_ForgetBuddy ( jcl , b , NULL ) ;
}
else
{
JCL_AddClientMessagef ( jcl , " <presence to='%s' type='unavailable'/> " , b - > accountdomain ) ;
JCL_ForgetBuddy ( jcl , b , NULL ) ;
}
}
}
else if ( ! strcmp ( what , " setbalias " ) )
{
JCL_FindBuddy ( jcl , * who ? who : jcl - > defaultdest , & b , NULL , false ) ;
if ( b )
{
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleFloat ( BUDDYLISTTITLE , " linebuffered " , true ) ;
confuncs - > SetConsoleString ( BUDDYLISTTITLE , " footer " , " Please enter what you want to see them as " ) ;
2017-10-12 12:02:25 +00:00
jclient_action_cl = jcl ;
jclient_action_buddy = b ;
jclient_action = ACT_SETBALIAS ;
}
}
2013-06-29 16:01:07 +00:00
else if ( ( * who & & ! * what ) | | ! strcmp ( what , " msg " ) )
2013-06-23 02:33:52 +00:00
{
2013-07-13 12:14:32 +00:00
if ( jcl )
2013-06-23 02:33:52 +00:00
{
char * f ;
2015-04-27 06:19:33 +00:00
buddy_t * b = NULL ;
bresource_t * br = NULL ;
JCL_FindBuddy ( jcl , * who ? who : jcl - > defaultdest , & b , & br , true ) ;
if ( b )
2013-11-21 23:02:28 +00:00
{
2015-04-27 06:19:33 +00:00
f = b - > accountdomain ;
2017-10-12 12:02:25 +00:00
if ( b - > btype ! = BT_CHATROOM )
b - > defaultresource = br ;
2013-06-23 02:33:52 +00:00
2019-09-04 07:59:40 +00:00
if ( confuncs )
2015-04-27 06:19:33 +00:00
{
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleString ( f , " title " , b - > name ) ;
confuncs - > SetConsoleFloat ( f , " iswindow " , true ) ;
confuncs - > SetConsoleFloat ( f , " forceutf8 " , true ) ;
confuncs - > SetConsoleFloat ( f , " wnd_w " , 256 ) ;
confuncs - > SetConsoleFloat ( f , " wnd_h " , 320 ) ;
2015-04-27 06:19:33 +00:00
}
2019-09-04 07:59:40 +00:00
if ( confuncs )
confuncs - > SetActive ( f ) ;
2013-11-21 23:02:28 +00:00
}
2013-06-23 02:33:52 +00:00
}
return true ;
}
2013-06-29 16:01:07 +00:00
else
{
Con_Printf ( " Unsupported xmpp action (%s) in link \n " , what ) ;
}
2013-06-23 02:33:52 +00:00
return false ;
}
2015-04-27 06:19:33 +00:00
void JCL_ToJID ( jclient_t * jcl , const char * in , char * out , int outsize , qboolean assumeresource )
{
//decompose links first
if ( in [ 0 ] = = ' ^ ' & & in [ 1 ] = = ' [ ' )
{
const char * sl ;
const char * le ;
sl = in + 2 ;
sl = strchr ( in , ' \\ ' ) ;
if ( sl )
{
le = strstr ( sl , " ^] " ) ;
if ( le )
{
char info [ 512 ] ;
if ( le - sl < 512 )
{
memcpy ( info , sl , le - sl ) ;
info [ le - sl ] = 0 ;
JCL_Info_ValueForKey ( info , " xmpp " , out , outsize ) ;
}
return ;
}
}
}
if ( ! strchr ( in , ' @ ' ) & & jcl )
{
//no @? probably its an alias, but could also be a server/domain perhaps. not sure we care. you'll just have to rename your friend.
//check to see if we can find a friend going by that name
//fixme: allow resources to make it through here
buddy_t * b ;
for ( b = jcl - > buddies ; b ; b = b - > next )
{
if ( ! strcasecmp ( b - > name , in ) )
{
if ( b - > defaultresource & & assumeresource )
Q_snprintf ( out , outsize , " %s/%s " , b - > accountdomain , b - > defaultresource - > resource ) ;
else
Q_strlcpy ( out , b - > accountdomain , outsize ) ;
return ;
}
}
}
if ( assumeresource )
{
buddy_t * b ;
for ( b = jcl - > buddies ; b ; b = b - > next )
{
if ( ! strcasecmp ( b - > accountdomain , in ) )
{
if ( b - > defaultresource & & assumeresource )
Q_snprintf ( out , outsize , " %s/%s " , b - > accountdomain , b - > defaultresource - > resource ) ;
else
Q_strlcpy ( out , b - > accountdomain , outsize ) ;
return ;
}
}
}
//a regular jabber account name
Q_strlcpy ( out , in , outsize ) ;
}
void XMPP_AddFriend ( jclient_t * jcl , const char * account , const char * nick )
{
char jid [ 256 ] ;
//FIXME: validate the name. deal with xml markup.
//try and make sense of the name given
JCL_ToJID ( jcl , account , jid , sizeof ( jid ) , false ) ;
if ( ! strchr ( jid , ' @ ' ) )
Con_Printf ( " Missing @ character. Trying anyway, but this will be assumed to be a server rather than a user. \n " ) ;
//can also rename. We should probably read back the groups for the update.
JCL_SendIQf ( jcl , NULL , " set " , NULL , " <query xmlns='jabber:iq:roster'><item jid='%s' name='%s'></item></query> " , jid , nick ) ;
//start looking for em
JCL_AddClientMessagef ( jcl , " <presence to='%s' type='subscribe'/> " , jid ) ;
//let em see us
if ( jcl - > preapproval )
JCL_AddClientMessagef ( jcl , " <presence to='%s' type='subscribed'/> " , jid ) ;
}
jclient_t * JCL_Connect ( int accnum , char * server , int forcetls , char * account , char * password ) ;
2019-09-04 07:59:40 +00:00
int JCL_ConExecuteCommand ( qboolean isinsecure )
2005-12-11 20:11:22 +00:00
{
2013-06-23 02:33:52 +00:00
buddy_t * b ;
char consolename [ 256 ] ;
2013-10-29 17:38:22 +00:00
jclient_t * jcl ;
int i ;
2013-07-13 12:14:32 +00:00
2019-09-04 07:59:40 +00:00
cmdfuncs - > Argv ( 0 , consolename , sizeof ( consolename ) ) ;
2015-04-27 06:19:33 +00:00
if ( ! strcmp ( consolename , BUDDYLISTTITLE ) )
{
char args [ 512 ] ;
2019-09-04 07:59:40 +00:00
cmdfuncs - > Args ( args , sizeof ( args ) ) ;
confuncs - > SetConsoleFloat ( BUDDYLISTTITLE , " linebuffered " , false ) ;
confuncs - > SetConsoleString ( BUDDYLISTTITLE , " footer " , " " ) ;
2015-04-27 06:19:33 +00:00
jclient_updatebuddylist = true ;
//FIXME: validate that the client is still active.
switch ( jclient_action )
{
case ACT_NONE :
break ;
2016-07-12 00:40:13 +00:00
case ACT_OAUTH :
jcl = jclient_action_cl ;
if ( jcl )
{
2017-09-20 11:27:13 +00:00
free ( jcl - > sasl . oauth2 . authtoken ) ;
jcl - > sasl . oauth2 . authtoken = strdup ( args ) ;
2016-07-12 00:40:13 +00:00
if ( jcl - > status = = JCL_INACTIVE )
jcl - > status = JCL_DEAD ;
}
break ;
2015-04-27 06:19:33 +00:00
case ACT_NEWACCOUNT :
2015-06-04 06:15:14 +00:00
if ( ! * args )
2015-04-27 06:19:33 +00:00
break ; //they didn't enter anything! oh well.
for ( i = 0 ; i < sizeof ( jclients ) / sizeof ( jclients [ 0 ] ) ; i + + )
{
if ( jclients [ i ] )
continue ;
2019-09-04 07:59:40 +00:00
jclients [ i ] = JCL_Connect ( i , " " , 1 , args , " " ) ;
2015-04-27 06:19:33 +00:00
break ;
}
if ( i = = sizeof ( jclients ) / sizeof ( jclients [ 0 ] ) )
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleString ( BUDDYLISTTITLE , " footer " , " Too many accounts open " ) ;
2015-04-27 06:19:33 +00:00
else if ( ! jclients [ i ] )
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleString ( BUDDYLISTTITLE , " footer " , " Unable to create account " ) ;
2015-04-27 06:19:33 +00:00
else
{ //now ask for a password instantly. because oauth2 is basically unusable.
jclients [ i ] - > status = JCL_INACTIVE ;
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleFloat ( BUDDYLISTTITLE , " linebuffered " , true ) ;
confuncs - > SetConsoleString ( BUDDYLISTTITLE , " footer " , " Please enter password " ) ;
2015-04-27 06:19:33 +00:00
jclient_action_cl = jclients [ i ] ;
jclient_action_buddy = NULL ;
2017-09-20 11:27:13 +00:00
jclient_action = ACT_SETAPASSWORD ;
2015-04-27 06:19:33 +00:00
return true ;
}
break ;
2017-09-20 11:27:13 +00:00
case ACT_SETAUSERNAME :
Q_strncpyz ( jclient_action_cl - > username , args , sizeof ( jclient_action_cl - > username ) ) ;
break ;
case ACT_SETADOMAIN :
Q_strncpyz ( jclient_action_cl - > domain , args , sizeof ( jclient_action_cl - > domain ) ) ;
break ;
case ACT_SETASERVER :
Q_strncpyz ( jclient_action_cl - > serveraddr , args , sizeof ( jclient_action_cl - > serveraddr ) ) ;
break ;
case ACT_SETARESOURCE :
Q_strncpyz ( jclient_action_cl - > resource , args , sizeof ( jclient_action_cl - > resource ) ) ;
break ;
case ACT_SETAPASSWORD :
2015-04-27 06:19:33 +00:00
if ( * args )
2017-09-20 11:27:13 +00:00
{
Q_strncpyz ( jclient_action_cl - > sasl . password_plain , args , sizeof ( jclient_action_cl - > sasl . password_plain ) ) ;
jclient_action_cl - > sasl . password_hash_size = 0 ; //invalidate it
}
2015-04-27 06:19:33 +00:00
if ( jclient_action_cl - > status = = JCL_INACTIVE )
jclient_action_cl - > status = JCL_DEAD ;
jclient_action = ACT_NONE ;
2021-06-21 13:36:30 +00:00
jclient_configdirty = true ;
2015-04-27 06:19:33 +00:00
return 2 ; //ask to not store in history.
case ACT_ADDFRIEND :
if ( * args )
XMPP_AddFriend ( jclient_action_cl , args , " " ) ;
break ;
2017-09-20 11:27:13 +00:00
case ACT_SETBALIAS :
2021-06-21 13:36:30 +00:00
jclient_configdirty = true ;
2015-04-27 06:19:33 +00:00
Q_strncpyz ( jclient_action_buddy - > name , args , sizeof ( jclient_action_buddy - > name ) ) ;
2017-10-12 12:02:25 +00:00
if ( jclient_action_buddy - > btype = = BT_ROSTER )
JCL_SendIQf ( jclient_action_cl , NULL , " set " , NULL , " <query xmlns='jabber:iq:roster'><item jid='%s' name='%s'></item></query> " , jclient_action_buddy - > accountdomain , jclient_action_buddy - > name ) ;
2019-09-04 07:59:40 +00:00
if ( confuncs )
confuncs - > SetConsoleString ( jclient_action_buddy - > accountdomain , " title " , jclient_action_buddy - > name ) ;
2015-04-27 06:19:33 +00:00
break ;
}
jclient_action = ACT_NONE ;
return true ;
}
2013-10-29 17:38:22 +00:00
for ( i = 0 ; i < sizeof ( jclients ) / sizeof ( jclients [ 0 ] ) ; i + + )
2013-06-23 02:33:52 +00:00
{
2013-10-29 17:38:22 +00:00
jcl = jclients [ i ] ;
if ( ! jcl )
continue ;
for ( b = jcl - > buddies ; b ; b = b - > next )
2013-06-23 02:33:52 +00:00
{
2015-04-27 06:19:33 +00:00
if ( ! strcmp ( b - > accountdomain , consolename ) )
2013-10-29 17:38:22 +00:00
{
if ( b - > defaultresource )
Q_snprintf ( jcl - > defaultdest , sizeof ( jcl - > defaultdest ) , " %s/%s " , b - > accountdomain , b - > defaultresource - > resource ) ;
else
Q_snprintf ( jcl - > defaultdest , sizeof ( jcl - > defaultdest ) , " %s " , b - > accountdomain ) ;
JCL_Command ( i , consolename ) ;
return true ;
}
2013-06-23 02:33:52 +00:00
}
}
2013-10-29 17:38:22 +00:00
for ( i = 0 ; i < sizeof ( jclients ) / sizeof ( jclients [ 0 ] ) ; i + + )
{
jcl = jclients [ i ] ;
if ( ! jcl )
continue ;
JCL_Command ( i , consolename ) ;
return true ;
}
Con_SubPrintf ( consolename , " You were disconnected \n " ) ;
2005-12-11 20:11:22 +00:00
return true ;
}
2013-06-23 02:33:52 +00:00
void JCL_FlushOutgoing ( jclient_t * jcl )
{
int sent ;
2013-07-13 12:14:32 +00:00
if ( ! jcl | | ! jcl - > outbuflen | | jcl - > socket = = - 1 )
2013-06-23 02:33:52 +00:00
return ;
2019-09-04 07:59:40 +00:00
sent = netfuncs - > Send ( jcl - > socket , jcl - > outbuf + jcl - > outbufpos , jcl - > outbuflen ) ; //FIXME: This needs rewriting to cope with errors.
2013-06-23 02:33:52 +00:00
if ( sent > 0 )
{
//and print it on some subconsole if we're debugging
if ( jcl - > streamdebug )
{
char t = jcl - > outbuf [ jcl - > outbufpos + sent ] ;
jcl - > outbuf [ jcl - > outbufpos + sent ] = 0 ;
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( " xmppout " , " xmppout " , false , " ^3%s \n " , jcl - > outbuf + jcl - > outbufpos ) ;
2013-06-23 02:33:52 +00:00
jcl - > outbuf [ jcl - > outbufpos + sent ] = t ;
}
jcl - > outbufpos + = sent ;
jcl - > outbuflen - = sent ;
}
2013-07-13 12:14:32 +00:00
else if ( sent < 0 )
2013-11-21 23:02:28 +00:00
Con_Printf ( " XMPP: Error sending \n " ) ;
2013-06-24 09:04:00 +00:00
// else
// Con_Printf("Unable to send anything\n");
2013-06-23 02:33:52 +00:00
}
2017-10-12 12:02:25 +00:00
void JCL_AddClientMessage ( jclient_t * jcl , const char * msg , int datalen )
2005-12-11 20:11:22 +00:00
{
2013-06-23 02:33:52 +00:00
//handle overflows
if ( jcl - > outbufpos + jcl - > outbuflen + datalen > jcl - > outbufmax )
{
if ( jcl - > outbuflen + datalen < = jcl - > outbufmax )
{
//can get away with just moving the data
memmove ( jcl - > outbuf , jcl - > outbuf + jcl - > outbufpos , jcl - > outbuflen ) ;
jcl - > outbufpos = 0 ;
}
else
{
//need to expand the buffer.
int newmax = ( jcl - > outbuflen + datalen ) * 2 ;
char * newbuf ;
if ( newmax < jcl - > outbuflen )
newbuf = NULL ; //eep... some special kind of evil overflow.
else
newbuf = malloc ( newmax + 1 ) ;
if ( newbuf )
{
memcpy ( newbuf , jcl - > outbuf + jcl - > outbufpos , jcl - > outbuflen ) ;
jcl - > outbufmax = newmax ;
jcl - > outbufpos = 0 ;
jcl - > outbuf = newbuf ;
}
else
datalen = 0 ; //eep!
}
}
//and write our data to it
memcpy ( jcl - > outbuf + jcl - > outbufpos + jcl - > outbuflen , msg , datalen ) ;
jcl - > outbuflen + = datalen ;
//try and flush it now
JCL_FlushOutgoing ( jcl ) ;
2005-12-11 20:11:22 +00:00
}
2017-10-12 12:02:25 +00:00
void JCL_AddClientMessageString ( jclient_t * jcl , const char * msg )
2005-12-11 20:11:22 +00:00
{
JCL_AddClientMessage ( jcl , msg , strlen ( msg ) ) ;
}
2017-10-12 12:02:25 +00:00
void JCL_AddClientMessagef ( jclient_t * jcl , const char * fmt , . . . )
2013-06-23 02:33:52 +00:00
{
va_list argptr ;
2013-07-13 12:14:32 +00:00
char body [ 4096 ] ;
2013-06-23 18:43:59 +00:00
2013-06-23 02:33:52 +00:00
va_start ( argptr , fmt ) ;
2017-10-12 12:02:25 +00:00
Q_vsnprintxf ( body , sizeof ( body ) , fmt , argptr ) ;
2013-06-23 02:33:52 +00:00
va_end ( argptr ) ;
2005-12-11 20:11:22 +00:00
2013-06-23 02:33:52 +00:00
JCL_AddClientMessageString ( jcl , body ) ;
}
2013-06-29 16:01:07 +00:00
qboolean JCL_Reconnect ( jclient_t * jcl )
2005-12-11 20:11:22 +00:00
{
2013-07-13 12:14:32 +00:00
char * serveraddr ;
2013-06-29 16:01:07 +00:00
//destroy any data that never got sent
free ( jcl - > outbuf ) ;
jcl - > outbuf = NULL ;
jcl - > outbuflen = 0 ;
jcl - > outbufpos = 0 ;
jcl - > outbufmax = 0 ;
jcl - > instreampos = 0 ;
jcl - > bufferedinammount = 0 ;
Q_strlcpy ( jcl - > localalias , " >> " , sizeof ( jcl - > localalias ) ) ;
2017-09-20 11:27:13 +00:00
jcl - > sasl . authmethod = NULL ;
2005-12-11 20:11:22 +00:00
2013-07-13 12:14:32 +00:00
if ( * jcl - > redirserveraddr )
serveraddr = jcl - > redirserveraddr ;
else
serveraddr = jcl - > serveraddr ;
2005-12-11 20:11:22 +00:00
2013-07-13 12:14:32 +00:00
if ( ! * serveraddr )
{
//jcl->tlsconnect requires an explicit hostname, so should not be able to take this path.
char srv [ 256 ] ;
char srvserver [ 256 ] ;
2021-08-05 16:49:25 +00:00
if ( ! Q_snprintfz ( srv , sizeof ( srv ) , " _xmpp-client._tcp.%s " , jcl - > domain ) & & NET_DNSLookup_SRV ( srv , srvserver , sizeof ( srvserver ) ) )
2013-07-13 12:14:32 +00:00
{
2013-08-21 07:42:42 +00:00
Con_DPrintf ( " XMPP: Trying to connect to %s (%s) \n " , jcl - > domain , srvserver ) ;
2019-09-04 07:59:40 +00:00
jcl - > socket = netfuncs - > TCPConnect ( srvserver , jcl - > serverport ) ; //port is should already be part of the srvserver name
2013-07-13 12:14:32 +00:00
}
else
{
2017-06-21 01:24:25 +00:00
//SRV lookup failed. attempt to just use the domain directly.
Con_DPrintf ( " XMPP: Trying to connect to %s \n " , jcl - > domain ) ;
2019-09-04 07:59:40 +00:00
jcl - > socket = netfuncs - > TCPConnect ( jcl - > domain , jcl - > serverport ) ; //port is only used if the url doesn't contain one. It's a default.
2013-07-13 12:14:32 +00:00
}
}
else
{
2013-08-21 07:42:42 +00:00
Con_DPrintf ( " XMPP: Trying to connect to %s \n " , jcl - > domain ) ;
2019-09-04 07:59:40 +00:00
jcl - > socket = netfuncs - > TCPConnect ( serveraddr , jcl - > serverport ) ; //port is only used if the url doesn't contain one. It's a default.
2013-07-13 12:14:32 +00:00
}
2005-12-11 20:11:22 +00:00
2013-06-29 16:01:07 +00:00
//not yet blocking. So no frequent attempts please...
//non blocking prevents connect from returning worthwhile sensible value.
if ( ( int ) jcl - > socket < 0 )
{
2015-04-27 06:19:33 +00:00
Q_strncpyz ( jcl - > errormsg , " Unable to connect " , sizeof ( jcl - > errormsg ) ) ;
2013-06-29 16:01:07 +00:00
return false ;
}
2005-12-11 20:11:22 +00:00
2013-06-29 16:01:07 +00:00
jcl - > issecure = false ;
2013-07-13 12:14:32 +00:00
if ( jcl - > forcetls = = 2 )
2019-09-04 07:59:40 +00:00
if ( netfuncs - > SetTLSClient ( jcl - > socket , jcl - > certificatedomain ) > = 0 )
2013-06-29 16:01:07 +00:00
jcl - > issecure = true ;
2005-12-11 20:11:22 +00:00
2013-06-29 16:01:07 +00:00
jcl - > status = JCL_AUTHING ;
2017-06-21 01:24:25 +00:00
jcl - > connecting = true ;
2005-12-11 20:11:22 +00:00
2013-06-29 16:01:07 +00:00
JCL_AddClientMessageString ( jcl ,
" <?xml version='1.0' ?> "
" <stream:stream to=' " ) ;
JCL_AddClientMessageString ( jcl , jcl - > domain ) ;
JCL_AddClientMessageString ( jcl , " ' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'> " ) ;
2005-12-11 20:11:22 +00:00
2015-04-27 06:19:33 +00:00
jclient_updatebuddylist = true ;
2013-06-29 16:01:07 +00:00
return true ;
}
2013-07-13 12:14:32 +00:00
jclient_t * JCL_ConnectXML ( xmltree_t * acc )
{
//this is a list of xmpp networks that use oauth2 for which we have a clientid registered. this allows us to get the right oauth defaults.
struct
{
char * domain ;
char * saslmethod ;
char * obtainurl ;
char * refreshurl ;
char * revokeurl ;
char * scope ;
char * clientid ;
char * clientsecret ;
//char *signouturl;
//char *clientregistrationurl;
} * oa , dfltoauth [ ] = {
{
" gmail.com " ,
" X-OAUTH2 " ,
" https://accounts.google.com/o/oauth2/auth " , //authorize
" https://accounts.google.com/o/oauth2/token " , //refresh
" https://accounts.google.com/o/oauth2/revoke " , //revoke
" https://www.googleapis.com/auth/googletalk " , //scope
" 1060926168015.apps.googleusercontent.com " , //clientid
" mptCRRTE5I626npsnoZ_RqoG " //client secrit. there really is no securing this. I'll just have to avoid any pay-for google apis. *shrug*
//"https://accounts.google.com/IssuedAuthSubTokens"
//"https://code.google.com/apis/console"
} ,
/*
{
" messenger.live.com " ,
" X-MESSENGER-OAUTH2 " ,
" https://oauth.live.com/authorize " ,
" https://oauth.live.com/token " ,
" " , //FIXME fill in revoke url
" wl.messenger,wl.basic,wl.offline_access,wl.contacts_create,wl.share " , //no idea what's actually needed.
" " , //client-id - none registered. go register it yourself.
" " //client-secret - client not registered, go do it yourself.
//""
//"https://manage.dev.live.com/"
} ,
*/
/*
{
" messenger.live.com " ,
" X-FACEBOOK-PLATFORM " ,
" " , //FIXME fill in obtain url
" " , //FIXME fill in refresh url
" " , //FIXME fill in revoke url
" " , //FIXME: fill in scope
" " , //client-id - none registered. go register it yourself.
" " //client-secret - client not registered, go do it yourself.
//""
//""
} ,
*/
{
NULL ,
" " ,
" " ,
" " ,
" " ,
" " ,
" " ,
" "
}
} ;
jclient_t * jcl ;
xmltree_t * oauth2 ;
2013-11-21 23:02:28 +00:00
xmltree_t * features ;
2019-09-04 07:59:40 +00:00
char oauthname [ 512 ] ;
2015-04-27 06:19:33 +00:00
struct buddyinfo_s * bi ;
int bn ;
2013-07-13 12:14:32 +00:00
jcl = malloc ( sizeof ( jclient_t ) ) ;
if ( ! jcl )
return NULL ;
memset ( jcl , 0 , sizeof ( jclient_t ) ) ;
jcl - > socket = - 1 ;
2017-10-12 12:02:25 +00:00
jcl - > rcon_pipe = - 1 ;
2013-07-13 12:14:32 +00:00
2013-11-21 23:02:28 +00:00
jcl - > enabledcapabilities = CAP_DEFAULTENABLEDCAPS ;
2013-07-13 12:14:32 +00:00
jcl - > accountnum = atoi ( XML_GetParameter ( acc , " id " , " 1 " ) ) ;
//make sure dependant properties are listed beneath their dependancies...
jcl - > forcetls = atoi ( XML_GetChildBody ( acc , " forcetls " , " 1 " ) ) ;
2013-11-21 23:02:28 +00:00
jcl - > streamdebug = atoi ( XML_GetChildBody ( acc , " streamdebug " , " 0 " ) ) ;
jcl - > streamdebug = bound ( 0 , jcl - > streamdebug , 2 ) ;
2013-07-13 12:14:32 +00:00
Q_strlcpy ( jcl - > serveraddr , XML_GetChildBody ( acc , " serveraddr " , " " ) , sizeof ( jcl - > serveraddr ) ) ;
jcl - > serverport = atoi ( XML_GetChildBody ( acc , " serverport " , ( jcl - > forcetls = = 2 ) ? " 5223 " : " 5222 " ) ) ;
Q_strlcpy ( jcl - > username , XML_GetChildBody ( acc , " username " , " user " ) , sizeof ( jcl - > username ) ) ;
Q_strlcpy ( jcl - > domain , XML_GetChildBody ( acc , " domain " , " localhost " ) , sizeof ( jcl - > domain ) ) ;
Q_strlcpy ( jcl - > resource , XML_GetChildBody ( acc , " resource " , " " ) , sizeof ( jcl - > resource ) ) ;
2017-09-20 11:27:13 +00:00
//half of these networks seem to have weird domains. especially microsoft.
2013-07-13 12:14:32 +00:00
if ( strchr ( jcl - > username , ' @ ' ) )
Q_strlcpy ( oauthname , jcl - > username , sizeof ( oauthname ) ) ;
else
Q_snprintf ( oauthname , sizeof ( oauthname ) , " %s@%s " , jcl - > username , jcl - > domain ) ;
for ( oa = dfltoauth ; oa - > domain ; oa + + )
{
if ( ! strcmp ( oa - > domain , jcl - > domain ) )
break ;
}
oauth2 = XML_ChildOfTree ( acc , " oauth2 " , 0 ) ;
2017-09-20 11:27:13 +00:00
Q_strlcpy ( jcl - > sasl . oauth2 . saslmethod , XML_GetParameter ( oauth2 , " method " , oa - > saslmethod ) , sizeof ( jcl - > sasl . oauth2 . saslmethod ) ) ;
Q_strlcpy ( jcl - > sasl . oauth2 . obtainurl , XML_GetChildBody ( oauth2 , " obtain-url " , oa - > obtainurl ) , sizeof ( jcl - > sasl . oauth2 . obtainurl ) ) ;
Q_strlcpy ( jcl - > sasl . oauth2 . refreshurl , XML_GetChildBody ( oauth2 , " refresh-url " , oa - > refreshurl ) , sizeof ( jcl - > sasl . oauth2 . refreshurl ) ) ;
Q_strlcpy ( jcl - > sasl . oauth2 . clientid , XML_GetChildBody ( oauth2 , " client-id " , oa - > clientid ) , sizeof ( jcl - > sasl . oauth2 . clientid ) ) ;
Q_strlcpy ( jcl - > sasl . oauth2 . clientsecret , XML_GetChildBody ( oauth2 , " client-secret " , oa - > clientsecret ) , sizeof ( jcl - > sasl . oauth2 . clientsecret ) ) ;
jcl - > sasl . oauth2 . scope = strdup ( XML_GetChildBody ( oauth2 , " scope " , oa - > scope ) ) ;
jcl - > sasl . oauth2 . useraccount = strdup ( XML_GetChildBody ( oauth2 , " authname " , oauthname ) ) ;
jcl - > sasl . oauth2 . authtoken = strdup ( XML_GetChildBody ( oauth2 , " auth-token " , " " ) ) ;
jcl - > sasl . oauth2 . refreshtoken = strdup ( XML_GetChildBody ( oauth2 , " refresh-token " , " " ) ) ;
jcl - > sasl . oauth2 . accesstoken = strdup ( XML_GetChildBody ( oauth2 , " access-token " , " " ) ) ;
Q_strlcpy ( jcl - > sasl . password_plain , XML_GetChildBody ( acc , " password " , " " ) , sizeof ( jcl - > sasl . password_plain ) ) ;
2013-07-13 12:14:32 +00:00
if ( ! * jcl - > resource )
{ //the default resource matches the game that they're trying to play.
char gamename [ 64 ] , * res , * o ;
2019-09-04 07:59:40 +00:00
if ( cvarfuncs - > GetString ( " fs_gamename " , gamename , sizeof ( gamename ) ) )
2013-07-13 12:14:32 +00:00
{
//strip out any weird chars (namely whitespace)
for ( o = gamename , res = gamename ; * res ; )
{
if ( * res = = ' ' | | * res = = ' \t ' )
res + + ;
else
* o + + = * res + + ;
}
if ( ! * gamename )
Q_strlcpy ( jcl - > resource , " FTE " , sizeof ( jcl - > resource ) ) ;
else
Q_strlcpy ( jcl - > resource , gamename , sizeof ( jcl - > resource ) ) ;
}
}
Q_strlcpy ( jcl - > certificatedomain , XML_GetChildBody ( acc , " certificatedomain " , jcl - > domain ) , sizeof ( jcl - > certificatedomain ) ) ;
jcl - > status = atoi ( XML_GetChildBody ( acc , " inactive " , " 0 " ) ) ? JCL_INACTIVE : JCL_DEAD ;
2017-09-20 11:27:13 +00:00
jcl - > sasl . allowauth_plainnontls = atoi ( XML_GetChildBody ( acc , " allowauth_plain_nontls " , " 0 " ) ) ;
jcl - > sasl . allowauth_plaintls = atoi ( XML_GetChildBody ( acc , " allowauth_plain_tls " , " 1 " ) ) ; //required 1 for googletalk, otherwise I'd set it to 0.
jcl - > sasl . allowauth_digestmd5 = atoi ( XML_GetChildBody ( acc , " allowauth_digest_md5 " , " 1 " ) ) ;
jcl - > sasl . allowauth_scramsha1 = atoi ( XML_GetChildBody ( acc , " allowauth_scram_sha_1 " , " 1 " ) ) ;
2019-08-01 02:13:44 +00:00
jcl - > sasl . allowauth_oauth2 = atoi ( XML_GetChildBody ( acc , " allowauth_oauth2 " , * jcl - > sasl . oauth2 . saslmethod ? " 1 " : " 0 " ) ) ;
2013-07-13 12:14:32 +00:00
2013-11-21 23:02:28 +00:00
jcl - > savepassword = atoi ( XML_GetChildBody ( acc , " savepassword " , " 0 " ) ) ;
features = XML_ChildOfTree ( acc , " features " , 0 ) ;
if ( features & & XML_GetParameter ( features , " ver " , JCL_BUILD ) )
{
2017-10-12 12:02:25 +00:00
const char * val ;
2013-11-21 23:02:28 +00:00
int j ;
for ( j = 0 ; capnames [ j ] . names ; j + + )
{
val = XML_GetChildBody ( features , capnames [ j ] . names , NULL ) ;
if ( val )
{
if ( atoi ( val ) )
jcl - > enabledcapabilities | = capnames [ j ] . cap ;
else
jcl - > enabledcapabilities & = ~ capnames [ j ] . cap ;
}
}
}
2015-04-27 06:19:33 +00:00
2017-10-12 12:02:25 +00:00
//parse chatrooms
features = XML_ChildOfTree ( acc , " chats " , 0 ) ;
if ( features )
{
for ( bn = 0 ; ; bn + + )
{
xmltree_t * b = XML_ChildOfTree ( features , " room " , bn ) ;
if ( b )
{
buddy_t * room ;
const char * jid = XML_GetParameter ( b , " name " , " " ) ;
const char * alias = XML_GetParameter ( b , " alias " , jid ) ;
const char * topic = XML_GetParameter ( b , " topic " , NULL ) ;
const char * nick = XML_GetParameter ( b , " nick " , NULL ) ;
const char * password = XML_GetParameter ( b , " password " , NULL ) ;
qboolean autojoin = atoi ( XML_GetParameter ( b , " autojoin " , " 1 " ) ) ;
if ( JCL_FindBuddy ( jcl , jid , & room , NULL , true ) & & room )
{
room - > btype = BT_CHATROOM ;
Q_strlcpy ( room - > name , alias , sizeof ( room - > name ) ) ;
room - > room_topic = topic ? strdup ( topic ) : NULL ;
room - > room_nick = nick ? strdup ( nick ) : NULL ;
room - > room_password = password ? strdup ( password ) : NULL ;
room - > room_autojoin = autojoin ;
}
}
else
break ;
}
}
else
{
/*buddy_t *room;
const char * jid = " quake@somedomain " ;
const char * alias = " FTE Users " ;
const char * topic = NULL ;
const char * nick = NULL ;
const char * password = NULL ;
if ( JCL_FindBuddy ( jcl , jid , & room , NULL , true ) & & room )
{
room - > btype = BT_CHATROOM ;
Q_strlcpy ( room - > name , alias , sizeof ( room - > name ) ) ;
room - > room_topic = topic ? strdup ( topic ) : NULL ;
room - > room_nick = nick ? strdup ( nick ) : NULL ;
room - > room_password = password ? strdup ( password ) : NULL ;
} */
}
2015-04-27 06:19:33 +00:00
features = XML_ChildOfTree ( acc , " buddyinfo " , 0 ) ;
for ( bn = 0 ; ; bn + + )
{
xmltree_t * b = XML_ChildOfTree ( features , " buddy " , bn ) ;
if ( b )
{
2017-10-12 12:02:25 +00:00
const char * buddyid = XML_GetParameter ( b , " name " , JCL_BUILD ) ;
const char * buddyimage = XML_GetChildBody ( b , " image " , NULL ) ;
const char * buddyimagemime = XML_GetChildBody ( b , " imagemime " , NULL ) ;
const char * buddyimagehash = XML_GetChildBody ( b , " imagehash " , NULL ) ;
2015-04-27 06:19:33 +00:00
bi = malloc ( sizeof ( * bi ) + strlen ( buddyid ) ) ;
strcpy ( bi - > accountdomain , buddyid ) ;
bi - > image = buddyimage ? strdup ( buddyimage ) : NULL ;
bi - > imagemime = buddyimagemime ? strdup ( buddyimagemime ) : NULL ;
bi - > imagehash = buddyimagehash ? strdup ( buddyimagehash ) : NULL ;
bi - > next = jcl - > buddyinfo ;
jcl - > buddyinfo = bi ;
}
else
break ;
}
2013-07-13 12:14:32 +00:00
return jcl ;
}
jclient_t * JCL_Connect ( int accnum , char * server , int forcetls , char * account , char * password )
2013-06-29 16:01:07 +00:00
{
char gamename [ 64 ] ;
jclient_t * jcl ;
char * domain ;
char * res ;
2013-07-13 12:14:32 +00:00
xmltree_t * x ;
2005-12-11 20:11:22 +00:00
2013-06-29 16:01:07 +00:00
res = TrimResourceFromJid ( account ) ;
2013-10-29 17:38:22 +00:00
if ( ! res | | ! * res )
2005-12-11 20:11:22 +00:00
{
2013-06-29 16:01:07 +00:00
//the default resource matches the game that they're trying to play.
2019-09-04 07:59:40 +00:00
if ( cvarfuncs - > GetString ( " fs_gamename " , gamename , sizeof ( gamename ) ) )
2013-06-29 16:01:07 +00:00
{
//strip out any weird chars (namely whitespace)
char * o ;
for ( o = gamename , res = gamename ; * res ; )
{
if ( * res = = ' ' | | * res = = ' \t ' )
res + + ;
else
* o + + = * res + + ;
}
res = gamename ;
}
2005-12-11 20:11:22 +00:00
}
2019-09-04 07:59:40 +00:00
/*
2013-07-13 12:14:32 +00:00
if ( forcetls > 0 )
2005-12-11 20:11:22 +00:00
{
2013-06-29 16:01:07 +00:00
if ( ! BUILTINISVALID ( Net_SetTLSClient ) )
2005-12-11 20:11:22 +00:00
{
2013-06-29 16:01:07 +00:00
Con_Printf ( " XMPP: TLS is not supported \n " ) ;
2005-12-11 20:11:22 +00:00
return NULL ;
}
2013-06-29 16:01:07 +00:00
}
2019-09-04 07:59:40 +00:00
*/
2013-06-29 16:01:07 +00:00
domain = strchr ( account , ' @ ' ) ;
if ( domain )
{
* domain = ' \0 ' ;
domain + + ;
2005-12-11 20:11:22 +00:00
}
else
2013-06-29 16:01:07 +00:00
{
2015-06-04 06:15:14 +00:00
# ifdef DEFAULTDOMAIN
2013-06-29 16:01:07 +00:00
domain = DEFAULTDOMAIN ;
2015-06-04 06:15:14 +00:00
Con_Printf ( " XMPP: domain not specified, assuming %s \n " , domain ) ;
# else
Con_Printf ( " XMPP: domain not specified \n " ) ;
return NULL ;
# endif
2013-06-29 16:01:07 +00:00
}
2005-12-11 20:11:22 +00:00
2013-07-13 12:14:32 +00:00
x = XML_CreateNode ( NULL , " account " , " " , " " ) ;
XML_AddParameteri ( x , " id " , accnum ) ;
2013-07-14 12:22:51 +00:00
XML_CreateNode ( x , " serveraddr " , " " , server ) ;
2013-07-13 12:14:32 +00:00
XML_CreateNode ( x , " username " , " " , account ) ;
XML_CreateNode ( x , " domain " , " " , domain ) ;
XML_CreateNode ( x , " resource " , " " , res ) ;
XML_CreateNode ( x , " password " , " " , password ) ;
jcl = JCL_ConnectXML ( x ) ;
XML_Destroy ( x ) ;
2005-12-11 20:11:22 +00:00
return jcl ;
}
2013-06-29 16:01:07 +00:00
void JCL_ForgetBuddyResource ( jclient_t * jcl , buddy_t * buddy , bresource_t * bres )
2013-06-23 02:33:52 +00:00
{
2013-06-29 16:01:07 +00:00
bresource_t * * link ;
bresource_t * r ;
for ( link = & buddy - > resources ; * link ; )
2013-06-23 02:33:52 +00:00
{
2013-06-29 16:01:07 +00:00
r = * link ;
if ( ! bres | | bres = = r )
{
* link = r - > next ;
free ( r ) ;
if ( bres )
break ;
}
else
link = & r - > next ;
}
}
void JCL_ForgetBuddy ( jclient_t * jcl , buddy_t * buddy , bresource_t * bres )
{
buddy_t * * link ;
buddy_t * b ;
for ( link = & jcl - > buddies ; * link ; )
{
b = * link ;
if ( ! buddy | | buddy = = b )
{
* link = b - > next ;
JCL_ForgetBuddyResource ( jcl , b , bres ) ;
2017-10-12 12:02:25 +00:00
if ( jclient_action_buddy = = b )
{
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleFloat ( BUDDYLISTTITLE , " linebuffered " , false ) ;
2017-10-12 12:02:25 +00:00
jclient_action = ACT_NONE ;
jclient_action_buddy = NULL ;
jclient_action_cl = NULL ;
}
2013-06-29 16:01:07 +00:00
free ( b ) ;
if ( buddy )
break ;
}
else
link = & b - > next ;
2013-06-23 02:33:52 +00:00
}
2017-10-12 12:02:25 +00:00
jclient_updatebuddylist = true ;
2013-06-23 02:33:52 +00:00
}
2015-04-27 06:19:33 +00:00
struct stringprep_range
{
unsigned int cp_min ;
unsigned int cp_max ;
unsigned int remap [ 2 ] ;
} ;
2019-09-04 07:59:40 +00:00
static struct stringprep_range stringprep_A1 [ ] =
2015-04-27 06:19:33 +00:00
{
{ 0x0234 , 0x024F } ,
{ 0x02AE , 0x02AF } ,
{ 0x02EF , 0x02FF } ,
{ 0x0350 , 0x035F } ,
{ 0x0370 , 0x0373 } ,
{ 0x0376 , 0x0379 } ,
{ 0x037B , 0x037D } ,
{ 0x037F , 0x0383 } ,
{ 0x038B } ,
{ 0x038D } ,
{ 0x03A2 } ,
{ 0x03CF } ,
{ 0x03F7 , 0x03FF } ,
{ 0x0487 } ,
{ 0x04CF } ,
{ 0x04F6 , 0x04F7 } ,
{ 0x04FA , 0x04FF } ,
{ 0x0510 , 0x0530 } ,
{ 0x0557 , 0x0558 } ,
{ 0x0560 } ,
{ 0x0588 } ,
{ 0x058B , 0x0590 } ,
{ 0x05A2 } ,
{ 0x05BA } ,
{ 0x05C5 , 0x05CF } ,
{ 0x05EB , 0x05EF } ,
{ 0x05F5 , 0x060B } ,
Reworked client support for DPP5+. less code now, its much more graceful.
added waterfog command. waterfog overrides regular fog only when the view is in water.
fixed 64bit printf format specifiers. should work better on winxp64.
fixed some spec angle weirdness.
fixed viewsize 99.99 weirdness with ezhud.
fixed extra offset on the console (exhibited in 64bit builds, but not limited to).
fixed .avi playback, can now actually display frames again.
reimplemented line sparks.
fixed r_editlights_save flipping the light's pitch.
fixed issue with oggs failing to load.
fixed condump to cope with unicode properly.
made sv_bigcoords default except in quake. hexen2 kinda needs it for bsp angle precision.
fixed nq server to not stall weirdly on map changes.
fixed qwprogs svc_cdtrack not bugging out with nq clients on the server.
fixed restart command to load the last map run by the server, instead of start.bsp (when idle)
optimised d3d9 renderer a little. now uses less draw calls, especially with complex scenes. seems to get higher framerates than opengl now.
fixed d3d9 renderer to not bug out quite so much when run fullscreen (shader subsystem is now correctly initialised).
fixed a couple of bugs from font change. also now supports utf-8 in a few more places.
r_editlights_reload no longer generates rtlights inside the void. this resolves a few glitches (but should also help framerates a little).
fixed so corona-only lights won't generate shadowmaps and waste lots of time.
removed lots of #defines from qclib. I should never have made them in the first place, but I was lazy. obviously there's more left that I cba to remove yet.
fixed nested calls with variant-vectors. this fixes csaddon's light editor.
fixed qcc hc calling conventions using redundant stores.
disabled keywords can still be used by using __keyword instead.
fixed ftegccgui grep feature.
fixed motionless-dog qcc bug.
tweaked qcc warnings a little. -Wall is now a viable setting. you should be able to fix all those warnings.
fixed qw svc_intermission + dpp5+ clients bug.
fixed annoying spam about disconnecting in hexen2.
rewrote status command a little to cope with ipv6 addresses more gracefully
fixed significant stall when hibernating/debugging a server with a player sitting on it.
fixed truelightning.
fixed rocketlight overriding pflags.
fixed torches vanishing on vid_restart.
fixed issue with decal scaling.
fixed findentityfield builtin.
fixed fteqcc issue with ptr+1
fixed use of arrays inside class functions.
fixed/implemented fteqcc emulation of pointer opcodes.
added __inout keyword to fteqcc, so that it doesn't feel so horrendous.
fixed sizeof(*foo)
fixed *struct = struct;
fixed recursive structs.
fixed fteqcc warning report.
fixed sdl2 controller support, hopefully.
attempted to implement xinput, including per-player audio playback.
slightly fixed relaxed attitude to mouse focus when running fullscreen.
fixed weird warnings/errors with 'ent.arrayhead' terms. now generates sane errors.
implemented bindmaps (for csqc).
fixed crashing bug with eprint builtin.
implemented subset of music_playlist_* functionality. significant changes to music playback.
fixed some more dpcsqc compat.
fixed binds menu. now displays and accepts modifiers.
fixed issues with huge lightmaps.
fixed protocol determinism with dp clients connecting to fte servers. the initial getchallenge request now inhibits vanilla nq connection requests.
implemented support for 'dupe' userinfo key, allowing clients to request client->server packet duplication. should probably queue them tbh.
implemented sv_saveentfile command.
fixed resume after breaking inside a stepped-over function.
fixed erroneous footer after debugging.
(I wonder just how many things I broke with these fixes)
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4946 fc73d0e0-1445-4013-8a0c-d673dee63da5
2015-07-26 10:56:18 +00:00
{ 0x0600 , ~ 0 } , //FIXME rest of A.1 (utf)
2015-04-27 06:19:33 +00:00
} ;
2019-09-04 07:59:40 +00:00
static struct stringprep_range stringprep_B1 [ ] =
2015-04-27 06:19:33 +00:00
{
{ 0x00AD } ,
{ 0x034F } ,
{ 0x1806 } ,
{ 0x180B } ,
{ 0x180C } ,
{ 0x180D } ,
{ 0x200B } ,
{ 0x200C } ,
{ 0x200D } ,
{ 0x2060 } ,
{ 0xFE00 } ,
{ 0xFE01 } ,
{ 0xFE02 } ,
{ 0xFE03 } ,
{ 0xFE04 } ,
{ 0xFE05 } ,
{ 0xFE06 } ,
{ 0xFE07 } ,
{ 0xFE08 } ,
{ 0xFE09 } ,
{ 0xFE0A } ,
{ 0xFE0B } ,
{ 0xFE0C } ,
{ 0xFE0D } ,
{ 0xFE0E } ,
{ 0xFE0F } ,
{ 0xFEFF } ,
} ;
2019-09-04 07:59:40 +00:00
static struct stringprep_range stringprep_B2 [ ] =
2015-04-27 06:19:33 +00:00
{
{ 0x0041 , 0x005A , { 0x0061 } } ,
{ 0x00B5 , 0x00B5 , { 0x03BC } } ,
{ 0x00C0 , 0x00DE , { 0x00E0 } } ,
{ 0x00DF , 0 , { 0x0073 , 0x0073 } } ,
} ;
2019-09-04 07:59:40 +00:00
static struct stringprep_range stringprep_C1 [ ] =
2015-04-27 06:19:33 +00:00
{
//C1.1
{ 0x0020 } ,
//C2.2
{ 0x0020 } ,
{ 0x00A0 } ,
{ 0x1680 } ,
Reworked client support for DPP5+. less code now, its much more graceful.
added waterfog command. waterfog overrides regular fog only when the view is in water.
fixed 64bit printf format specifiers. should work better on winxp64.
fixed some spec angle weirdness.
fixed viewsize 99.99 weirdness with ezhud.
fixed extra offset on the console (exhibited in 64bit builds, but not limited to).
fixed .avi playback, can now actually display frames again.
reimplemented line sparks.
fixed r_editlights_save flipping the light's pitch.
fixed issue with oggs failing to load.
fixed condump to cope with unicode properly.
made sv_bigcoords default except in quake. hexen2 kinda needs it for bsp angle precision.
fixed nq server to not stall weirdly on map changes.
fixed qwprogs svc_cdtrack not bugging out with nq clients on the server.
fixed restart command to load the last map run by the server, instead of start.bsp (when idle)
optimised d3d9 renderer a little. now uses less draw calls, especially with complex scenes. seems to get higher framerates than opengl now.
fixed d3d9 renderer to not bug out quite so much when run fullscreen (shader subsystem is now correctly initialised).
fixed a couple of bugs from font change. also now supports utf-8 in a few more places.
r_editlights_reload no longer generates rtlights inside the void. this resolves a few glitches (but should also help framerates a little).
fixed so corona-only lights won't generate shadowmaps and waste lots of time.
removed lots of #defines from qclib. I should never have made them in the first place, but I was lazy. obviously there's more left that I cba to remove yet.
fixed nested calls with variant-vectors. this fixes csaddon's light editor.
fixed qcc hc calling conventions using redundant stores.
disabled keywords can still be used by using __keyword instead.
fixed ftegccgui grep feature.
fixed motionless-dog qcc bug.
tweaked qcc warnings a little. -Wall is now a viable setting. you should be able to fix all those warnings.
fixed qw svc_intermission + dpp5+ clients bug.
fixed annoying spam about disconnecting in hexen2.
rewrote status command a little to cope with ipv6 addresses more gracefully
fixed significant stall when hibernating/debugging a server with a player sitting on it.
fixed truelightning.
fixed rocketlight overriding pflags.
fixed torches vanishing on vid_restart.
fixed issue with decal scaling.
fixed findentityfield builtin.
fixed fteqcc issue with ptr+1
fixed use of arrays inside class functions.
fixed/implemented fteqcc emulation of pointer opcodes.
added __inout keyword to fteqcc, so that it doesn't feel so horrendous.
fixed sizeof(*foo)
fixed *struct = struct;
fixed recursive structs.
fixed fteqcc warning report.
fixed sdl2 controller support, hopefully.
attempted to implement xinput, including per-player audio playback.
slightly fixed relaxed attitude to mouse focus when running fullscreen.
fixed weird warnings/errors with 'ent.arrayhead' terms. now generates sane errors.
implemented bindmaps (for csqc).
fixed crashing bug with eprint builtin.
implemented subset of music_playlist_* functionality. significant changes to music playback.
fixed some more dpcsqc compat.
fixed binds menu. now displays and accepts modifiers.
fixed issues with huge lightmaps.
fixed protocol determinism with dp clients connecting to fte servers. the initial getchallenge request now inhibits vanilla nq connection requests.
implemented support for 'dupe' userinfo key, allowing clients to request client->server packet duplication. should probably queue them tbh.
implemented sv_saveentfile command.
fixed resume after breaking inside a stepped-over function.
fixed erroneous footer after debugging.
(I wonder just how many things I broke with these fixes)
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4946 fc73d0e0-1445-4013-8a0c-d673dee63da5
2015-07-26 10:56:18 +00:00
//FIXME... utf
2015-04-27 06:19:33 +00:00
} ;
2019-09-04 07:59:40 +00:00
static struct stringprep_range stringprep_C2 [ ] =
2015-04-27 06:19:33 +00:00
{
//C.2.1
{ 0x0000 , 0x001F } ,
{ 0x007F , 0x007F } ,
//C.2.1
{ 0x0080 , 0x009F } , //C.2.2
Reworked client support for DPP5+. less code now, its much more graceful.
added waterfog command. waterfog overrides regular fog only when the view is in water.
fixed 64bit printf format specifiers. should work better on winxp64.
fixed some spec angle weirdness.
fixed viewsize 99.99 weirdness with ezhud.
fixed extra offset on the console (exhibited in 64bit builds, but not limited to).
fixed .avi playback, can now actually display frames again.
reimplemented line sparks.
fixed r_editlights_save flipping the light's pitch.
fixed issue with oggs failing to load.
fixed condump to cope with unicode properly.
made sv_bigcoords default except in quake. hexen2 kinda needs it for bsp angle precision.
fixed nq server to not stall weirdly on map changes.
fixed qwprogs svc_cdtrack not bugging out with nq clients on the server.
fixed restart command to load the last map run by the server, instead of start.bsp (when idle)
optimised d3d9 renderer a little. now uses less draw calls, especially with complex scenes. seems to get higher framerates than opengl now.
fixed d3d9 renderer to not bug out quite so much when run fullscreen (shader subsystem is now correctly initialised).
fixed a couple of bugs from font change. also now supports utf-8 in a few more places.
r_editlights_reload no longer generates rtlights inside the void. this resolves a few glitches (but should also help framerates a little).
fixed so corona-only lights won't generate shadowmaps and waste lots of time.
removed lots of #defines from qclib. I should never have made them in the first place, but I was lazy. obviously there's more left that I cba to remove yet.
fixed nested calls with variant-vectors. this fixes csaddon's light editor.
fixed qcc hc calling conventions using redundant stores.
disabled keywords can still be used by using __keyword instead.
fixed ftegccgui grep feature.
fixed motionless-dog qcc bug.
tweaked qcc warnings a little. -Wall is now a viable setting. you should be able to fix all those warnings.
fixed qw svc_intermission + dpp5+ clients bug.
fixed annoying spam about disconnecting in hexen2.
rewrote status command a little to cope with ipv6 addresses more gracefully
fixed significant stall when hibernating/debugging a server with a player sitting on it.
fixed truelightning.
fixed rocketlight overriding pflags.
fixed torches vanishing on vid_restart.
fixed issue with decal scaling.
fixed findentityfield builtin.
fixed fteqcc issue with ptr+1
fixed use of arrays inside class functions.
fixed/implemented fteqcc emulation of pointer opcodes.
added __inout keyword to fteqcc, so that it doesn't feel so horrendous.
fixed sizeof(*foo)
fixed *struct = struct;
fixed recursive structs.
fixed fteqcc warning report.
fixed sdl2 controller support, hopefully.
attempted to implement xinput, including per-player audio playback.
slightly fixed relaxed attitude to mouse focus when running fullscreen.
fixed weird warnings/errors with 'ent.arrayhead' terms. now generates sane errors.
implemented bindmaps (for csqc).
fixed crashing bug with eprint builtin.
implemented subset of music_playlist_* functionality. significant changes to music playback.
fixed some more dpcsqc compat.
fixed binds menu. now displays and accepts modifiers.
fixed issues with huge lightmaps.
fixed protocol determinism with dp clients connecting to fte servers. the initial getchallenge request now inhibits vanilla nq connection requests.
implemented support for 'dupe' userinfo key, allowing clients to request client->server packet duplication. should probably queue them tbh.
implemented sv_saveentfile command.
fixed resume after breaking inside a stepped-over function.
fixed erroneous footer after debugging.
(I wonder just how many things I broke with these fixes)
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@4946 fc73d0e0-1445-4013-8a0c-d673dee63da5
2015-07-26 10:56:18 +00:00
//FIXME... utf
2015-04-27 06:19:33 +00:00
{ 0x06DD , ~ 0 } ,
} ;
2019-09-04 07:59:40 +00:00
static struct stringprep_range stringprep_C3 [ ] =
2015-04-27 06:19:33 +00:00
{
{ 0xE000 , 0xF8FF } ,
{ 0xF0000 , 0xFFFFD } ,
{ 0x100000 , 0x10FFFD } ,
} ;
2019-09-04 07:59:40 +00:00
static struct stringprep_range stringprep_C4 [ ] =
2015-04-27 06:19:33 +00:00
{
{ 0xFDD0 , 0xFDEF } ,
{ 0xFFFE , 0xFFFF } ,
{ 0x1FFFE , 0x1FFFF } ,
{ 0x2FFFE , 0x2FFFF } ,
{ 0x3FFFE , 0x3FFFF } ,
{ 0x4FFFE , 0x4FFFF } ,
{ 0x5FFFE , 0x5FFFF } ,
{ 0x6FFFE , 0x6FFFF } ,
{ 0x7FFFE , 0x7FFFF } ,
{ 0x8FFFE , 0x8FFFF } ,
{ 0x9FFFE , 0x9FFFF } ,
{ 0xAFFFE , 0xAFFFF } ,
{ 0xBFFFE , 0xBFFFF } ,
{ 0xCFFFE , 0xCFFFF } ,
{ 0xDFFFE , 0xDFFFF } ,
{ 0xEFFFE , 0xEFFFF } ,
{ 0xFFFFE , 0xFFFFF } ,
{ 0x10FFFE , 0x10FFFF } ,
} ;
2019-09-04 07:59:40 +00:00
static struct stringprep_range stringprep_C5 [ ] =
2015-04-27 06:19:33 +00:00
{
{ 0xD800 , 0xDFFF } ,
} ;
2019-09-04 07:59:40 +00:00
static struct stringprep_range stringprep_C6 [ ] =
2015-04-27 06:19:33 +00:00
{
{ 0xFFF9 } ,
{ 0xFFFA } ,
{ 0xFFFB } ,
{ 0xFFFC } ,
{ 0xFFFD } ,
} ;
2019-09-04 07:59:40 +00:00
static struct stringprep_range stringprep_C7 [ ] =
2015-04-27 06:19:33 +00:00
{
{ 0x2FF0 , 0x2FFB } ,
} ;
2019-09-04 07:59:40 +00:00
static struct stringprep_range stringprep_C8 [ ] =
2015-04-27 06:19:33 +00:00
{
{ 0x0340 } ,
{ 0x0341 } ,
{ 0x200E } ,
{ 0x200F } ,
{ 0x202A } ,
{ 0x202B } ,
{ 0x202C } ,
{ 0x202D } ,
{ 0x202E } ,
{ 0x206A } ,
{ 0x206B } ,
{ 0x206C } ,
{ 0x206D } ,
{ 0x206E } ,
{ 0x206F } ,
} ;
2019-09-04 07:59:40 +00:00
static struct stringprep_range stringprep_C9 [ ] =
2015-04-27 06:19:33 +00:00
{
{ 0xE0001 } ,
{ 0xE0001 } ,
{ 0xE0020 , 0xE007F } ,
} ;
2019-09-04 07:59:40 +00:00
static struct stringprep_range * StringPrep_InRange_ ( unsigned int codepoint , struct stringprep_range * range , size_t slots )
2015-04-27 06:19:33 +00:00
{
int i ;
for ( i = 0 ; i < slots ; i + + )
{
if ( codepoint < range [ i ] . cp_min )
return NULL ; //early out
if ( range [ i ] . cp_max )
{
if ( codepoint < range [ i ] . cp_max )
return & range [ i ] ;
}
else
{
if ( codepoint = = range [ i ] . cp_min )
return & range [ i ] ;
}
}
return NULL ;
}
2019-09-04 07:59:40 +00:00
# define StringPrep_InRange(cp,r) StringPrep_InRange_(cp,r,sizeof(r) / sizeof(r[0]))
2015-04-27 06:19:33 +00:00
static qboolean JCL_NamePrep ( const char * in , size_t insize , char * out , size_t outsize )
{
int j ;
unsigned int offset ;
unsigned int codepoint ;
struct stringprep_range * mapping ;
struct stringprep_range nomap ;
outsize - - ;
while ( insize - - > 0 )
{
codepoint = * in + + ;
if ( codepoint > = 0x80 )
return false ; //FIXME: utf-8 decode.
if ( StringPrep_InRange ( codepoint , stringprep_A1 ) ) return false ; //no unassigned codepoints
mapping = StringPrep_InRange ( codepoint , stringprep_B1 ) ;
if ( ! mapping )
mapping = StringPrep_InRange ( codepoint , stringprep_B2 ) ;
if ( ! mapping )
{ //no mapping, its probably fine.
nomap . cp_min = codepoint ;
nomap . cp_max = codepoint ;
nomap . remap [ 0 ] = codepoint ;
nomap . remap [ 1 ] = 0 ;
mapping = & nomap ;
}
offset = codepoint - mapping - > cp_min ;
for ( j = 0 ; j < sizeof ( mapping - > remap ) / sizeof ( mapping - > remap [ 0 ] ) & & mapping - > remap [ j ] ; j + + )
{
codepoint = mapping - > remap [ j ] + offset ;
if ( StringPrep_InRange ( codepoint , stringprep_C1 ) ) return false ;
if ( StringPrep_InRange ( codepoint , stringprep_C2 ) ) return false ;
if ( StringPrep_InRange ( codepoint , stringprep_C3 ) ) return false ;
if ( StringPrep_InRange ( codepoint , stringprep_C4 ) ) return false ;
if ( StringPrep_InRange ( codepoint , stringprep_C5 ) ) return false ;
if ( StringPrep_InRange ( codepoint , stringprep_C6 ) ) return false ;
if ( StringPrep_InRange ( codepoint , stringprep_C7 ) ) return false ;
if ( StringPrep_InRange ( codepoint , stringprep_C8 ) ) return false ;
if ( StringPrep_InRange ( codepoint , stringprep_C9 ) ) return false ;
//FIXME: utf-8 encode
if ( outsize < 1 )
return false ;
outsize - - ;
* out + + = codepoint ;
}
}
* out = 0 ;
return true ;
}
static qboolean JCL_NameResourcePrep ( const char * in , char * nout , size_t noutsize , char * * res )
{
char * resstart = strchr ( in , ' / ' ) ;
if ( resstart )
{
* res = resstart + 1 ;
//FIXME: resprep the resource.
if ( ! JCL_NamePrep ( in , resstart - in , nout , noutsize ) )
return false ;
}
else
{
* res = NULL ;
if ( ! JCL_NamePrep ( in , strlen ( in ) , nout , noutsize ) )
return false ;
}
return true ;
}
2013-07-13 12:14:32 +00:00
//FIXME: add flags to avoid creation
2017-10-12 12:02:25 +00:00
qboolean JCL_FindBuddy ( jclient_t * jcl , const char * jid , buddy_t * * buddy , bresource_t * * bres , qboolean create )
2013-06-23 02:33:52 +00:00
{
char name [ 256 ] ;
char * res ;
buddy_t * b ;
bresource_t * r = NULL ;
2017-10-12 12:02:25 +00:00
if ( ! jid | | ! * jid | | ! JCL_NameResourcePrep ( jid , name , sizeof ( name ) , & res ) )
{ //no name / nameprep failed.
2013-07-13 12:14:32 +00:00
if ( buddy )
* buddy = NULL ;
if ( bres )
* bres = NULL ;
return false ;
}
2013-06-23 02:33:52 +00:00
for ( b = jcl - > buddies ; b ; b = b - > next )
{
if ( ! strcmp ( b - > accountdomain , name ) )
break ;
}
2013-11-21 23:02:28 +00:00
if ( ! b & & create )
2013-06-23 02:33:52 +00:00
{
b = malloc ( sizeof ( * b ) + strlen ( name ) ) ;
memset ( b , 0 , sizeof ( * b ) ) ;
b - > next = jcl - > buddies ;
jcl - > buddies = b ;
2013-11-21 23:02:28 +00:00
// b->vcardphotochanged = true; //don't know what it is, query their photo as needed. google sucks, and things stop working.
2013-06-23 02:33:52 +00:00
strcpy ( b - > accountdomain , name ) ;
Q_strlcpy ( b - > name , name , sizeof ( b - > name ) ) ; //default
}
* buddy = b ;
2017-10-12 12:02:25 +00:00
if ( res & & bres & & b )
2013-06-23 02:33:52 +00:00
{
for ( r = b - > resources ; r ; r = r - > next )
{
if ( ! strcmp ( r - > resource , res ) )
break ;
}
2013-11-21 23:02:28 +00:00
if ( ! r & & create )
2013-06-23 02:33:52 +00:00
{
r = malloc ( sizeof ( * r ) + strlen ( res ) ) ;
memset ( r , 0 , sizeof ( * r ) ) ;
r - > next = b - > resources ;
b - > resources = r ;
strcpy ( r - > resource , res ) ;
}
* bres = r ;
}
else if ( bres )
* bres = NULL ;
2013-11-21 23:02:28 +00:00
if ( bres )
return * bres ! = NULL ;
return * buddy ! = NULL ;
2013-06-23 02:33:52 +00:00
}
2013-08-21 07:42:42 +00:00
void JCL_IQTimeouts ( jclient_t * jcl )
{
struct iq_s * iq , * * link ;
for ( link = & jcl - > pendingiqs ; * link ; )
{
iq = * link ;
if ( iq - > timeout < jclient_curtime )
{
iq = * link ;
* link = iq - > next ;
if ( iq - > callback )
{
Con_DPrintf ( " IQ timeout with %s \n " , iq - > to ) ;
iq - > callback ( jcl , NULL , iq ) ;
}
free ( iq ) ;
}
else
link = & ( * link ) - > next ;
}
}
2017-10-12 12:02:25 +00:00
struct iq_s * JCL_SendIQ ( jclient_t * jcl , qboolean ( * callback ) ( jclient_t * jcl , xmltree_t * tree , struct iq_s * iq ) , const char * iqtype , const char * target , const char * body )
2013-06-23 02:33:52 +00:00
{
struct iq_s * iq ;
2013-08-21 07:42:42 +00:00
if ( ! target )
target = " " ;
iq = malloc ( sizeof ( * iq ) + strlen ( target ) ) ;
2013-06-23 02:33:52 +00:00
iq - > next = jcl - > pendingiqs ;
jcl - > pendingiqs = iq ;
2013-06-23 18:43:59 +00:00
Q_snprintf ( iq - > id , sizeof ( iq - > id ) , " %i " , rand ( ) ) ;
2013-06-23 02:33:52 +00:00
iq - > callback = callback ;
2013-08-21 07:42:42 +00:00
iq - > timeout = jclient_curtime + 30 * 1000 ;
strcpy ( iq - > to , target ) ;
2013-06-23 02:33:52 +00:00
2013-08-21 07:42:42 +00:00
if ( * target )
2013-06-23 02:33:52 +00:00
{
2017-09-20 11:27:13 +00:00
if ( * jcl - > fulljid )
JCL_AddClientMessagef ( jcl , " <iq type='%s' id='%s' from='%s' to='%s'> " , iqtype , iq - > id , jcl - > fulljid , target ) ;
2013-06-23 02:33:52 +00:00
else
JCL_AddClientMessagef ( jcl , " <iq type='%s' id='%s' to='%s'> " , iqtype , iq - > id , target ) ;
}
else
{
2017-09-20 11:27:13 +00:00
if ( * jcl - > fulljid )
JCL_AddClientMessagef ( jcl , " <iq type='%s' id='%s' from='%s'> " , iqtype , iq - > id , jcl - > fulljid ) ;
2013-06-23 02:33:52 +00:00
else
JCL_AddClientMessagef ( jcl , " <iq type='%s' id='%s'> " , iqtype , iq - > id ) ;
}
JCL_AddClientMessageString ( jcl , body ) ;
JCL_AddClientMessageString ( jcl , " </iq> " ) ;
2013-06-29 16:01:07 +00:00
return iq ;
2013-06-23 02:33:52 +00:00
}
2017-10-12 12:02:25 +00:00
struct iq_s * JCL_SendIQf ( jclient_t * jcl , qboolean ( * callback ) ( jclient_t * jcl , xmltree_t * tree , struct iq_s * iq ) , const char * iqtype , const char * target , const char * fmt , . . . )
2013-06-23 02:33:52 +00:00
{
va_list argptr ;
char body [ 2048 ] ;
va_start ( argptr , fmt ) ;
2017-10-12 12:02:25 +00:00
Q_vsnprintxf ( body , sizeof ( body ) , fmt , argptr ) ;
2013-06-23 02:33:52 +00:00
va_end ( argptr ) ;
2013-06-29 16:01:07 +00:00
return JCL_SendIQ ( jcl , callback , iqtype , target , body ) ;
2013-06-23 02:33:52 +00:00
}
2017-10-12 12:02:25 +00:00
struct iq_s * JCL_SendIQNode ( jclient_t * jcl , qboolean ( * callback ) ( jclient_t * jcl , xmltree_t * tree , struct iq_s * iq ) , const char * iqtype , const char * target , xmltree_t * node , qboolean destroynode )
2013-06-23 02:33:52 +00:00
{
2013-06-29 16:01:07 +00:00
struct iq_s * n ;
2013-07-13 12:14:32 +00:00
char * s = XML_GenerateString ( node , false ) ;
2013-06-29 16:01:07 +00:00
n = JCL_SendIQ ( jcl , callback , iqtype , target , s ) ;
2013-06-23 02:33:52 +00:00
free ( s ) ;
if ( destroynode )
XML_Destroy ( node ) ;
2013-06-29 16:01:07 +00:00
return n ;
2013-06-23 02:33:52 +00:00
}
2013-11-21 23:02:28 +00:00
2017-09-20 11:27:13 +00:00
# ifdef USE_GOOGLE_MAIL_NOTIFY
2013-11-21 23:02:28 +00:00
qboolean XMPP_NewGoogleMailsReply ( jclient_t * jcl , xmltree_t * tree , struct iq_s * iq )
{
int i , j ;
xmltree_t * mailbox = XML_ChildOfTreeNS ( tree , " google:mail:notify " , " mailbox " , 0 ) ;
// char *url = XML_GetParameter(mailbox, "url", "");
// int totalmatched = atoi(XML_GetParameter(mailbox, "total-matched", "0"));
// char *resulttime = XML_GetParameter(mailbox, "result-time", "");
xmltree_t * mailthread ;
xmltree_t * senders , * sender ;
char * subject ;
char * sendername ;
char * cleanup ;
char * mailurl ;
for ( i = 0 ; ; i + + )
{
mailthread = XML_ChildOfTree ( mailbox , " mail-thread-info " , i ) ;
if ( ! mailthread )
break ;
// tid = XML_GetParameter(mailthread, "tid", "");
mailurl = XML_GetParameter ( mailthread , " url " , " " ) ;
// participation = XML_GetParameter(mailthread, "participation", "");
// messages = XML_GetParameter(mailthread, "messages", "");
// date = XML_GetParameter(mailthread, "date", "");
// labels = XML_GetChildBody(mailthread, "labels", "");
subject = XML_GetChildBody ( mailthread , " subject " , " " ) ;
if ( ! * subject )
subject = XML_GetChildBody ( mailthread , " snippet " , " <NO SUBJECT> " ) ;
senders = XML_ChildOfTree ( mailthread , " senders " , 0 ) ;
for ( j = 0 ; ; j + + )
{
sender = XML_ChildOfTree ( senders , " sender " , j ) ;
if ( ! sender )
break ;
// address = XML_GetParameter(sender, "address", "");
sendername = XML_GetParameter ( sender , " name " , " " ) ;
if ( ! * sendername )
sendername = XML_GetParameter ( sender , " address " , " " ) ;
// originator = XML_GetParameter(sender, "originator", "");
if ( atoi ( XML_GetParameter ( sender , " unread " , " 1 " ) ) )
{
//we trust the server to not feed us gibberish like \r or \n chars.
//however, other chars may be problematic and could break/hack the link markup.
for ( cleanup = sendername ; ( cleanup = strchr ( cleanup , ' ^ ' ) ) ! = NULL ; )
* cleanup = ' ' ;
for ( cleanup = sendername ; ( cleanup = strchr ( cleanup , ' \\ ' ) ) ! = NULL ; )
* cleanup = ' / ' ;
for ( cleanup = subject ; ( cleanup = strchr ( cleanup , ' ^ ' ) ) ! = NULL ; )
* cleanup = ' ' ;
for ( cleanup = subject ; ( cleanup = strchr ( cleanup , ' \\ ' ) ) ! = NULL ; )
* cleanup = ' / ' ;
for ( cleanup = mailurl ; ( cleanup = strstr ( cleanup , " ^] " ) ) ! = NULL ; )
* cleanup = ' _ ' ; //FIXME: %5E
for ( cleanup = mailurl ; ( cleanup = strchr ( cleanup , ' \\ ' ) ) ! = NULL ; )
* cleanup = ' / ' ; //FIXME: %5C
Con_Printf ( " ^[^4New spam from %s: %s \\ url \\ %s^] \n " , sendername , subject , mailurl ) ;
}
}
}
return true ;
}
2017-09-20 11:27:13 +00:00
# endif
qboolean XMPP_CarbonsEnabledReply ( jclient_t * jcl , xmltree_t * tree , struct iq_s * iq )
{
//don't care. if we don't get carbons then no real loss.
//xmltree_t *etype, *error = XML_ChildOfTreeNS(tree, NULL, "error", 0);
//etype = XML_ChildOfTreeNS(error, NULL, "forbidden", 0);
//etype = XML_ChildOfTreeNS(error, NULL, "not-allowed", 0);
return true ;
}
2013-11-21 23:02:28 +00:00
2017-10-12 12:02:25 +00:00
static void JCL_RosterUpdate ( jclient_t * jcl , xmltree_t * listp , const char * from )
2013-06-23 02:33:52 +00:00
{
xmltree_t * i ;
buddy_t * buddy ;
int cnum = 0 ;
2017-10-12 12:02:25 +00:00
const char * at = strrchr ( from , ' @ ' ) ;
2017-06-21 01:24:25 +00:00
if ( at )
{
if ( strlen ( jcl - > username ) ! = at - from | | strncasecmp ( from , jcl - > username , at - from ) )
return ;
from = at + 1 ;
}
if ( strcmp ( from , jcl - > domain ) )
return ; //ignore if from somewhere invalid
2013-06-23 02:33:52 +00:00
while ( ( i = XML_ChildOfTree ( listp , " item " , cnum + + ) ) )
{
2017-10-12 12:02:25 +00:00
const char * name = XML_GetParameter ( i , " name " , " " ) ;
const char * jid = XML_GetParameter ( i , " jid " , " " ) ;
const char * sub = XML_GetParameter ( i , " subscription " , " both " ) ;
const char * ask = XML_GetParameter ( i , " ask " , " " ) ;
2013-11-21 23:02:28 +00:00
JCL_FindBuddy ( jcl , jid , & buddy , NULL , true ) ;
2017-10-12 12:02:25 +00:00
buddy - > btype = BT_ROSTER ;
2013-06-23 02:33:52 +00:00
if ( * name )
Q_strlcpy ( buddy - > name , name , sizeof ( buddy - > name ) ) ;
2015-04-27 06:19:33 +00:00
else
buddy - > vcardphotochanged = true ; //try to query their actual name
2017-06-21 01:24:25 +00:00
if ( strcasecmp ( sub , " none " ) )
buddy - > friended = true ;
if ( * ask )
buddy - > askfriend = true ;
2013-06-23 02:33:52 +00:00
}
2017-06-21 01:24:25 +00:00
jclient_updatebuddylist = true ;
2013-06-23 02:33:52 +00:00
}
2013-06-29 16:01:07 +00:00
static qboolean JCL_RosterReply ( jclient_t * jcl , xmltree_t * tree , struct iq_s * iq )
2013-06-23 02:33:52 +00:00
{
2013-06-23 18:43:59 +00:00
xmltree_t * c ;
2013-06-29 16:01:07 +00:00
//we're probably connected once we've had this reply.
jcl - > status = JCL_ACTIVE ;
JCL_GeneratePresence ( jcl , true ) ;
2013-06-23 02:33:52 +00:00
c = XML_ChildOfTree ( tree , " query " , 0 ) ;
if ( c )
{
2017-06-21 01:24:25 +00:00
JCL_RosterUpdate ( jcl , c , jcl - > domain ) ;
2013-06-23 02:33:52 +00:00
return true ;
}
return false ;
}
2013-06-29 16:01:07 +00:00
static qboolean JCL_BindReply ( jclient_t * jcl , xmltree_t * tree , struct iq_s * iq )
2013-06-23 02:33:52 +00:00
{
xmltree_t * c ;
c = XML_ChildOfTree ( tree , " bind " , 0 ) ;
if ( c )
{
c = XML_ChildOfTree ( c , " jid " , 0 ) ;
if ( c )
2005-12-11 20:11:22 +00:00
{
2013-07-13 12:14:32 +00:00
char myjid [ 512 ] ;
2017-09-20 11:27:13 +00:00
Q_strlcpy ( jcl - > fulljid , c - > body , sizeof ( jcl - > fulljid ) ) ;
JCL_GenLink ( jcl , myjid , sizeof ( myjid ) , NULL , jcl - > fulljid , NULL , NULL , " %s " , jcl - > fulljid ) ;
Con_DPrintf ( " Bound to jid %s \n " , jcl - > fulljid ) ;
2013-06-23 02:33:52 +00:00
return true ;
2005-12-11 20:11:22 +00:00
}
}
2013-06-23 02:33:52 +00:00
return false ;
}
2013-11-21 23:02:28 +00:00
static qboolean JCL_BuddyVCardReply ( jclient_t * jcl , xmltree_t * tree , struct iq_s * iq )
2013-06-29 16:01:07 +00:00
{
2019-09-04 07:59:40 +00:00
char myself [ 512 ] ;
2013-11-21 23:02:28 +00:00
char photodata [ 65536 ] ;
xmltree_t * vc , * photo , * photobinval ;
2015-04-27 06:19:33 +00:00
const char * nickname ;
const char * photomime ;
2013-11-21 23:02:28 +00:00
2016-07-12 00:40:13 +00:00
buddy_t * b = NULL ;
2015-08-02 19:08:36 +00:00
char * from = iq - > to ;
2013-11-21 23:02:28 +00:00
2015-08-10 18:28:23 +00:00
if ( ! * from )
{
Q_snprintf ( myself , sizeof ( myself ) , " %s@%s " , jcl - > username , jcl - > domain ) ;
from = myself ;
}
2015-04-27 06:19:33 +00:00
if ( jcl - > avatarupdate = = iq )
{
if ( ! tree )
Con_DPrintf ( " timeout for %s's photo \n " , iq - > to ) ;
else
Con_DPrintf ( " Response for %s's photo \n " , iq - > to ) ;
jcl - > avatarupdate = NULL ;
}
JCL_FindBuddy ( jcl , from , & b , NULL , true ) ;
2013-11-21 23:02:28 +00:00
if ( ! b )
{
Con_DPrintf ( " unknown vcard from %s \n " , from ) ;
return false ;
}
2015-04-27 06:19:33 +00:00
jclient_updatebuddylist = true ; //make sure any new info is displayed properly.
2013-11-21 23:02:28 +00:00
vc = XML_ChildOfTree ( tree , " vCard " , 0 ) ;
if ( ! vc )
Con_DPrintf ( " invalid vcard from %s \n " , from ) ;
2015-04-27 06:19:33 +00:00
else
2013-11-21 23:02:28 +00:00
{
2015-04-27 06:19:33 +00:00
if ( ! strcmp ( b - > name , b - > accountdomain ) )
2013-11-21 23:02:28 +00:00
{
2015-04-27 06:19:33 +00:00
nickname = XML_GetChildBody ( vc , " NICKNAME " , NULL ) ;
if ( ! nickname )
nickname = XML_GetChildBody ( vc , " FN " , NULL ) ;
if ( nickname )
Q_strlcpy ( b - > name , nickname , sizeof ( b - > name ) ) ;
2013-11-21 23:02:28 +00:00
}
2015-04-27 06:19:33 +00:00
photo = XML_ChildOfTree ( vc , " PHOTO " , 0 ) ;
photobinval = XML_ChildOfTree ( photo , " BINVAL " , 0 ) ;
2019-09-04 07:59:40 +00:00
if ( ( jcl - > enabledcapabilities & CAP_AVATARS ) & & drawfuncs )
2013-11-21 23:02:28 +00:00
{
2015-04-27 06:19:33 +00:00
if ( photobinval )
{
struct buddyinfo_s * bi ;
unsigned int photosize = Base64_Decode ( photodata , sizeof ( photodata ) , photobinval - > body , strlen ( photobinval - > body ) ) ;
photomime = XML_GetChildBody ( photo , " TYPE " , " " ) ;
//xep-0153: If the <TYPE/> is something other than image/gif, image/jpeg, or image/png, it SHOULD be ignored.
if ( strcmp ( photomime , " image/png " ) & & strcmp ( photomime , " image/jpeg " ) & & strcmp ( photomime , " image/gif " ) )
photomime = " " ;
2019-09-04 07:59:40 +00:00
b - > image = drawfuncs - > LoadImageData ( va ( " xmpp/%s.png " , b - > accountdomain ) , photomime , photodata , photosize ) ;
2015-04-27 06:19:33 +00:00
Con_DPrintf ( " vcard photo updated from %s \n " , from ) ;
for ( bi = jcl - > buddyinfo ; bi ; bi = bi - > next )
{
if ( ! strcmp ( bi - > accountdomain , b - > accountdomain ) )
break ;
}
if ( ! bi )
{
bi = malloc ( sizeof ( * bi ) + strlen ( b - > accountdomain ) ) ;
memset ( bi , 0 , sizeof ( * bi ) ) ;
strcpy ( bi - > accountdomain , b - > accountdomain ) ;
bi - > next = jcl - > buddyinfo ;
jcl - > buddyinfo = bi ;
}
if ( bi )
{
char * hex = " 0123456789abcdef " ;
char hash [ 20 ] ;
char hasha [ 41 ] ;
int i , o ;
free ( bi - > image ) ;
free ( bi - > imagehash ) ;
free ( bi - > imagemime ) ;
2020-03-25 21:29:30 +00:00
CalcHash ( & hash_sha1 , hash , sizeof ( hash ) , photodata , photosize ) ;
2015-04-27 06:19:33 +00:00
for ( i = 0 , o = 0 ; i < sizeof ( hash ) ; i + + )
{
hasha [ o + + ] = hex [ ( hash [ i ] > > 4 ) & 0xf ] ;
hasha [ o + + ] = hex [ ( hash [ i ] > > 0 ) & 0xf ] ;
}
hasha [ o ] = 0 ;
bi - > imagehash = strdup ( hasha ) ;
bi - > image = strdup ( photobinval - > body ) ;
bi - > imagemime = strdup ( photomime ) ;
2021-06-21 13:36:30 +00:00
jclient_configdirty = true ;
2015-04-27 06:19:33 +00:00
}
}
else
{
2019-09-04 07:59:40 +00:00
b - > image = drawfuncs - > LoadImageData ( va ( " xmpp/%s.png " , b - > accountdomain ) , " " , NULL , 0 ) ;
2015-04-27 06:19:33 +00:00
Con_DPrintf ( " vcard photo invalidated from %s \n " , from ) ;
}
2013-11-21 23:02:28 +00:00
}
2015-04-27 06:19:33 +00:00
else
Con_DPrintf ( " vcard photo ignored from %s \n " , from ) ;
2013-11-21 23:02:28 +00:00
}
return true ;
}
static qboolean JCL_MyVCardReply ( jclient_t * jcl , xmltree_t * tree , struct iq_s * iq )
{
char photodata [ 65536 ] ;
char digest [ 20 ] ;
xmltree_t * vc , * fn , * nickname , * photo , * photobinval ;
2015-04-27 06:19:33 +00:00
//hack the from parametmer so it looks legit
Q_snprintf ( photodata , sizeof ( photodata ) , " %s@%s " , jcl - > username , jcl - > domain ) ;
2013-11-21 23:02:28 +00:00
//make sure our image is loaded etc
JCL_BuddyVCardReply ( jcl , tree , iq ) ;
2013-06-29 16:01:07 +00:00
vc = XML_ChildOfTree ( tree , " vCard " , 0 ) ;
fn = XML_ChildOfTree ( vc , " FN " , 0 ) ;
nickname = XML_ChildOfTree ( vc , " NICKNAME " , 0 ) ;
2013-11-21 23:02:28 +00:00
photo = XML_ChildOfTree ( vc , " PHOTO " , 0 ) ;
photobinval = XML_ChildOfTree ( photo , " BINVAL " , 0 ) ;
if ( ! tree | | ! photobinval )
{
//server doesn't support vcards?
if ( jcl - > vcardphotohashstatus ! = VCP_NONE )
{
jcl - > vcardphotohashstatus = VCP_NONE ;
jcl - > vcardphotohashchanged = true ;
* jcl - > vcardphotohash = 0 ;
}
}
else
{
2016-07-12 00:40:13 +00:00
int photosize = Base64_Decode ( photodata , sizeof ( photodata ) , photobinval - > body , strlen ( photobinval - > body ) ) ;
2020-03-25 21:29:30 +00:00
CalcHash ( & hash_sha1 , digest , sizeof ( digest ) , photodata , photosize ) ;
2013-11-21 23:02:28 +00:00
if ( jcl - > vcardphotohashstatus ! = VCP_KNOWN | | memcmp ( jcl - > vcardphotohash , digest , sizeof ( jcl - > vcardphotohash ) ) )
{
memcpy ( jcl - > vcardphotohash , digest , sizeof ( jcl - > vcardphotohash ) ) ;
jcl - > vcardphotohashchanged = true ;
jcl - > vcardphotohashstatus = VCP_KNOWN ;
}
}
2013-06-29 16:01:07 +00:00
if ( nickname & & * nickname - > body )
Q_strlcpy ( jcl - > localalias , nickname - > body , sizeof ( jcl - > localalias ) ) ;
else if ( fn & & * fn - > body )
Q_strlcpy ( jcl - > localalias , fn - > body , sizeof ( jcl - > localalias ) ) ;
2017-09-20 11:27:13 +00:00
else
Q_strlcpy ( jcl - > localalias , jcl - > barejid , sizeof ( jcl - > localalias ) ) ; //barejid or just username?
2013-06-29 16:01:07 +00:00
return true ;
}
2013-11-21 23:02:28 +00:00
static qboolean JCL_ServerFeatureReply ( jclient_t * jcl , xmltree_t * tree , struct iq_s * iq )
{
xmltree_t * query = XML_ChildOfTreeNS ( tree , " http://jabber.org/protocol/disco#info " , " query " , 0 ) ;
xmltree_t * feature ;
2017-10-12 12:02:25 +00:00
const char * featurename ;
2013-11-21 23:02:28 +00:00
int f ;
2017-09-20 11:27:13 +00:00
# ifdef USE_GOOGLE_MAIL_NOTIFY
2013-11-21 23:02:28 +00:00
qboolean gmail = false ;
2017-09-20 11:27:13 +00:00
# endif
qboolean carbons = false ;
2013-11-21 23:02:28 +00:00
if ( ! query )
return false ;
for ( f = 0 ; ; f + + )
{
feature = XML_ChildOfTree ( query , " feature " , f ) ;
if ( ! feature )
break ;
featurename = XML_GetParameter ( feature , " var " , " " ) ;
2017-09-20 11:27:13 +00:00
# ifdef USE_GOOGLE_MAIL_NOTIFY
2013-11-21 23:02:28 +00:00
if ( ! strcmp ( featurename , " google:mail:notify " ) )
gmail = true ;
else
2017-09-20 11:27:13 +00:00
# endif
if ( ! strcmp ( featurename , " urn:xmpp:carbons:2 " ) )
carbons = true ;
else
2013-11-21 23:02:28 +00:00
{
Con_DPrintf ( " Server supports feature %s \n " , featurename ) ;
}
}
2017-09-20 11:27:13 +00:00
# ifdef USE_GOOGLE_MAIL_NOTIFY
2013-11-21 23:02:28 +00:00
if ( gmail )
JCL_SendIQf ( jcl , XMPP_NewGoogleMailsReply , " get " , NULL , " <query xmlns='google:mail:notify'/> " ) ;
2017-09-20 11:27:13 +00:00
# endif
if ( carbons )
JCL_SendIQf ( jcl , XMPP_CarbonsEnabledReply , " set " , NULL , " <enable xmlns='urn:xmpp:carbons:2'/> " ) ;
2013-11-21 23:02:28 +00:00
return true ;
}
2017-10-31 22:52:58 +00:00
/*static qboolean JCL_ServerPeerReply(jclient_t *jcl, xmltree_t *tree, struct iq_s *iq)
2017-10-12 12:02:25 +00:00
{
xmltree_t * query = XML_ChildOfTreeNS ( tree , " http://jabber.org/protocol/disco#info " , " query " , 0 ) ;
xmltree_t * feature ;
xmltree_t * identity ;
const char * from = iq - > to ;
const char * name ;
const char * type ;
const char * category ;
int f ;
if ( ! query )
return false ;
for ( f = 0 ; ; f + + )
{
identity = XML_ChildOfTree ( query , " identity " , f ) ;
if ( ! identity )
break ;
name = XML_GetParameter ( identity , " name " , " " ) ;
type = XML_GetParameter ( identity , " type " , " " ) ;
category = XML_GetParameter ( identity , " category " , " " ) ;
Con_Printf ( " Server %s supports identity type=%s category=%s name=%s \n " , from , type , category , name ) ;
}
for ( f = 0 ; ; f + + )
{
feature = XML_ChildOfTree ( query , " feature " , f ) ;
if ( ! feature )
break ;
name = XML_GetParameter ( feature , " var " , " " ) ;
Con_Printf ( " Server %s supports feature %s \n " , from , name ) ;
}
return true ;
}
2017-10-31 22:52:58 +00:00
static qboolean JCL_ServerItemsReply ( jclient_t * jcl , xmltree_t * tree , struct iq_s * iq )
2017-10-12 12:02:25 +00:00
{
xmltree_t * query = XML_ChildOfTreeNS ( tree , " http://jabber.org/protocol/disco#items " , " query " , 0 ) ;
xmltree_t * item ;
const char * itemname ;
int f ;
if ( ! query )
return false ;
for ( f = 0 ; ; f + + )
{
item = XML_ChildOfTree ( query , " item " , f ) ;
if ( ! item )
break ;
itemname = XML_GetParameter ( item , " jid " , " " ) ;
if ( * itemname )
{
Con_DPrintf ( " Server reports peer %s \n " , itemname ) ;
JCL_SendIQf ( jcl , JCL_ServerPeerReply , " get " , itemname , " <query xmlns='http://jabber.org/protocol/disco#info'/> " ) ;
}
}
return true ;
2017-10-21 18:08:45 +00:00
} */
2013-06-29 16:01:07 +00:00
static qboolean JCL_SessionReply ( jclient_t * jcl , xmltree_t * tree , struct iq_s * iq )
2013-06-23 02:33:52 +00:00
{
2017-10-12 12:02:25 +00:00
buddy_t * b ;
2013-06-23 02:33:52 +00:00
JCL_SendIQf ( jcl , JCL_RosterReply , " get " , NULL , " <query xmlns='jabber:iq:roster'/> " ) ;
2017-09-20 11:27:13 +00:00
JCL_SendIQf ( jcl , JCL_MyVCardReply , " get " , jcl - > barejid , " <vCard xmlns='vcard-temp'/> " ) ;
2013-11-21 23:02:28 +00:00
JCL_SendIQf ( jcl , JCL_ServerFeatureReply , " get " , jcl - > domain , " <query xmlns='http://jabber.org/protocol/disco#info'/> " ) ;
2017-10-12 12:02:25 +00:00
// JCL_SendIQf(jcl, JCL_ServerItemsReply, "get", jcl->domain, "<query xmlns='http://jabber.org/protocol/disco#items'/>");
for ( b = jcl - > buddies ; b ; b = b - > next )
{
if ( b - > btype = = BT_CHATROOM )
if ( b - > room_autojoin )
JCL_JoinMUCChat ( jcl , b - > accountdomain , NULL , b - > room_nick , b - > room_password ) ;
}
2013-06-23 02:33:52 +00:00
return true ;
2005-12-11 20:11:22 +00:00
}
2013-11-21 23:02:28 +00:00
static struct
{
char * name ;
unsigned int withcap ;
} caps [ ] =
2013-06-23 02:33:52 +00:00
{
# if 1
2013-11-21 23:02:28 +00:00
{ " http://jabber.org/protocol/caps " } ,
{ " http://jabber.org/protocol/disco#info " } ,
2017-10-12 12:02:25 +00:00
{ " http://jabber.org/protocol/disco#items " } ,
2013-06-23 02:33:52 +00:00
2013-11-21 23:02:28 +00:00
{ " jabber:iq:version " } ,
2013-07-13 12:14:32 +00:00
# ifdef JINGLE
2013-11-21 23:02:28 +00:00
{ " urn:xmpp:jingle:1 " , CAP_GAMEINVITE | CAP_VOICE | CAP_VIDEO } ,
{ QUAKEMEDIAXMLNS , CAP_GAMEINVITE } ,
2013-07-13 12:14:32 +00:00
# ifdef VOIP
2013-08-21 07:42:42 +00:00
# ifdef VOIP_LEGACY
2013-11-21 23:02:28 +00:00
{ " http://www.google.com/xmpp/protocol/session " , CAP_GOOGLE_VOICE } , //so google's non-standard clients can chat with us
{ " http://www.google.com/xmpp/protocol/voice/v1 " , CAP_GOOGLE_VOICE } , //so google's non-standard clients can chat with us
2017-09-20 11:27:13 +00:00
// {"http://www.google.com/xmpp/protocol/camera/v1", CAP_GOOGLE_VOICE}, //can send video
2013-11-21 23:02:28 +00:00
// {"http://www.google.com/xmpp/protocol/video/v1", CAP_GOOGLE_VOICE}, //can receive video
2013-08-21 07:42:42 +00:00
# endif
# ifndef VOIP_LEGACY_ONLY
2013-11-21 23:02:28 +00:00
{ " urn:xmpp:jingle:apps:rtp:1 " , CAP_VOICE | CAP_VIDEO } ,
{ " urn:xmpp:jingle:apps:rtp:audio " , CAP_VOICE } ,
{ " urn:xmpp:jingle:apps:rtp:video " , CAP_VIDEO } ,
2013-08-21 07:42:42 +00:00
# endif
2017-09-20 11:27:13 +00:00
// {"urn:xmpp:jingle:apps:rtp:video", CAP_VIDEO}, //we don't support rtp video chat
2013-07-13 12:14:32 +00:00
# endif
2013-11-21 23:02:28 +00:00
{ " urn:xmpp:jingle:transports:raw-udp:1 " , CAP_GAMEINVITE | CAP_VOICE | CAP_VIDEO } ,
2013-07-13 12:14:32 +00:00
# ifndef NOICE
2013-11-21 23:02:28 +00:00
{ " urn:xmpp:jingle:transports:ice-udp:1 " , CAP_GAMEINVITE | CAP_VOICE | CAP_VIDEO } ,
2013-07-13 12:14:32 +00:00
# endif
# endif
# ifndef Q3_VM
2013-11-21 23:02:28 +00:00
{ " urn:xmpp:time " } ,
2013-07-13 12:14:32 +00:00
# endif
2013-11-21 23:02:28 +00:00
{ " urn:xmpp:ping " } , //FIXME: I'm not keen on this. I only added support to stop errors from pidgin when trying to debug.
{ " urn:xmpp:attention:0 " } , //poke.
2013-06-23 02:33:52 +00:00
2013-07-13 12:14:32 +00:00
//file transfer
2013-10-29 17:38:22 +00:00
# ifdef FILETRANSFERS
2013-11-21 23:02:28 +00:00
{ " http://jabber.org/protocol/si " , CAP_SIFT } ,
{ " http://jabber.org/protocol/si/profile/file-transfer " , CAP_SIFT } ,
{ " http://jabber.org/protocol/ibb " , CAP_SIFT } ,
{ " http://jabber.org/protocol/bytestreams " , CAP_SIFT } ,
2013-07-13 12:14:32 +00:00
# endif
2017-09-20 11:27:13 +00:00
{ " urn:xmpp:avatar:data " } ,
{ " urn:xmpp:avatar:metadata " } ,
{ " urn:xmpp:avatar:metadata+notify " } ,
// {"http://jabber.org/protocol/mood"},
// {"http://jabber.org/protocol/mood+notify"},
/// {"http://jabber.org/protocol/tune"},
// {"http://jabber.org/protocol/tune+notify"},
{ " http://jabber.org/protocol/nick " } ,
{ " http://jabber.org/protocol/nick+notify " } ,
2017-10-12 12:02:25 +00:00
{ " http://jabber.org/protocol/commands " } ,
2013-06-23 02:33:52 +00:00
# else
//for testing, this is the list of features pidgin supports (which is the other client I'm testing against).
" jabber:iq:last " ,
" jabber:iq:oob " ,
" urn:xmpp:time " ,
" jabber:iq:version " ,
" jabber:x:conference " ,
" http://jabber.org/protocol/bytestreams " ,
" http://jabber.org/protocol/caps " ,
" http://jabber.org/protocol/chatstates " ,
" http://jabber.org/protocol/disco#info " ,
" http://jabber.org/protocol/disco#items " ,
" http://jabber.org/protocol/muc " ,
" http://jabber.org/protocol/muc#user " ,
" http://jabber.org/protocol/si " ,
2013-07-13 12:14:32 +00:00
" http://jabber.org/protocol/si/profile/file-transfer " ,
2013-06-23 02:33:52 +00:00
" http://jabber.org/protocol/xhtml-im " ,
" urn:xmpp:ping " ,
" urn:xmpp:attention:0 " ,
" urn:xmpp:bob " ,
" urn:xmpp:jingle:1 " ,
" http://www.google.com/xmpp/protocol/session " ,
" http://www.google.com/xmpp/protocol/voice/v1 " ,
" http://www.google.com/xmpp/protocol/video/v1 " ,
" http://www.google.com/xmpp/protocol/camera/v1 " ,
" urn:xmpp:jingle:apps:rtp:1 " ,
" urn:xmpp:jingle:apps:rtp:audio " ,
" urn:xmpp:jingle:apps:rtp:video " ,
" urn:xmpp:jingle:transports:raw-udp:1 " ,
" urn:xmpp:jingle:transports:ice-udp:1 " ,
" urn:xmpp:avatar:metadata " ,
" urn:xmpp:avatar:data " ,
" urn:xmpp:avatar:metadata+notify " ,
" http://jabber.org/protocol/mood " ,
" http://jabber.org/protocol/mood+notify " ,
" http://jabber.org/protocol/tune " ,
" http://jabber.org/protocol/tune+notify " ,
" http://jabber.org/protocol/nick " ,
" http://jabber.org/protocol/nick+notify " ,
" http://jabber.org/protocol/ibb " ,
# endif
2013-11-21 23:02:28 +00:00
{ NULL }
2013-06-23 02:33:52 +00:00
} ;
2013-11-21 23:02:28 +00:00
static void buildcaps ( jclient_t * jcl , char * out , int outlen )
2005-12-11 20:11:22 +00:00
{
2013-06-23 02:33:52 +00:00
int i ;
Q_strncpyz ( out , " <identity category='client' type='pc' name='FTEQW'/> " , outlen ) ;
2005-12-11 20:11:22 +00:00
2013-11-21 23:02:28 +00:00
for ( i = 0 ; caps [ i ] . name ; i + + )
2005-12-11 20:11:22 +00:00
{
2017-09-20 11:27:13 +00:00
if ( caps [ i ] . withcap & & ! ( caps [ i ] . withcap & jcl - > enabledcapabilities ) )
2013-11-21 23:02:28 +00:00
continue ;
2013-06-23 02:33:52 +00:00
Q_strlcat ( out , " <feature var=' " , outlen ) ;
2013-11-21 23:02:28 +00:00
Q_strlcat ( out , caps [ i ] . name , outlen ) ;
2013-06-23 02:33:52 +00:00
Q_strlcat ( out , " '/> " , outlen ) ;
2005-12-11 20:11:22 +00:00
}
}
2013-06-23 02:33:52 +00:00
static int qsortcaps ( const void * va , const void * vb )
{
2019-09-04 07:59:40 +00:00
char * const a = * ( char * const * ) va ;
char * const b = * ( char * const * ) vb ;
2013-06-23 02:33:52 +00:00
return strcmp ( a , b ) ;
}
2013-11-21 23:02:28 +00:00
char * buildcapshash ( jclient_t * jcl )
2013-06-23 02:33:52 +00:00
{
int i , l ;
char out [ 8192 ] ;
int outlen = sizeof ( out ) ;
unsigned char digest [ 64 ] ;
Q_strlcpy ( out , " client/pc//FTEQW< " , outlen ) ;
2013-11-21 23:02:28 +00:00
qsort ( caps , sizeof ( caps ) / sizeof ( caps [ 0 ] ) - 1 , sizeof ( caps [ 0 ] ) , qsortcaps ) ;
for ( i = 0 ; caps [ i ] . name ; i + + )
2013-06-23 02:33:52 +00:00
{
2017-09-20 11:27:13 +00:00
if ( caps [ i ] . withcap & & ! ( caps [ i ] . withcap & jcl - > enabledcapabilities ) )
2013-11-21 23:02:28 +00:00
continue ;
Q_strlcat ( out , caps [ i ] . name , outlen ) ;
2013-06-23 02:33:52 +00:00
Q_strlcat ( out , " < " , outlen ) ;
}
2020-03-25 21:29:30 +00:00
l = CalcHash ( & hash_sha1 , digest , sizeof ( digest ) , out , strlen ( out ) ) ;
2013-06-23 02:33:52 +00:00
for ( i = 0 ; i < l ; i + + )
Base64_Byte ( digest [ i ] ) ;
Base64_Finish ( ) ;
return base64 ;
}
2005-12-11 20:11:22 +00:00
2013-11-21 23:02:28 +00:00
//xep-0115 1.4+
//xep-0153
char * buildcapsvcardpresence ( jclient_t * jcl , char * caps , size_t sizeofcaps )
{
char * vcard ;
char * voiceext = " " ; //xep-0115 1.0
# ifdef VOIP_LEGACY
if ( jcl - > enabledcapabilities & CAP_GOOGLE_VOICE )
2015-04-27 06:19:33 +00:00
{
if ( jcl - > enabledcapabilities & CAP_VIDEO )
voiceext = " ext='voice-v1 camera-v1 video-v1' " ;
else
voiceext = " ext='voice-v1' " ;
}
2013-11-21 23:02:28 +00:00
# endif
Q_snprintf ( caps , sizeofcaps ,
" <c xmlns='http://jabber.org/protocol/caps' "
" hash='sha-1' "
" node=' " DISCONODE " ' "
" ver='%s' "
" %s/> "
, buildcapshash ( jcl ) , voiceext ) ;
//xep-0153
vcard = caps + strlen ( caps ) ;
sizeofcaps - = strlen ( caps ) ;
if ( jcl - > vcardphotohashstatus = = VCP_NONE )
{
//let other people know that we don't have one. yay. pointless. whatever.
Q_snprintf ( vcard , sizeofcaps ,
" <x xmlns='vcard-temp:x:update'><photo/></x> " ) ;
}
else if ( jcl - > vcardphotohashstatus = = VCP_KNOWN )
{
2016-07-12 00:40:13 +00:00
unsigned char * hex = " 0123456789abcdef " ;
2013-11-21 23:02:28 +00:00
char inhex [ 41 ] ;
int i , o ;
for ( i = 0 , o = 0 ; i < sizeof ( jcl - > vcardphotohash ) ; i + + )
{
2016-07-12 00:40:13 +00:00
inhex [ o + + ] = hex [ ( jcl - > vcardphotohash [ i ] > > 4 ) & 0xf ] ;
inhex [ o + + ] = hex [ ( jcl - > vcardphotohash [ i ] > > 0 ) & 0xf ] ;
2013-11-21 23:02:28 +00:00
}
inhex [ o ] = 0 ;
//if we know the vcard hash, we must tell other people what it is or if its changed, etc.
Q_snprintf ( vcard , sizeofcaps ,
" <x xmlns='vcard-temp:x:update'><photo>%s</photo></x> " , inhex ) ;
}
else
{
//always include a vcard update tag.
//this says that we won't corrupt other resource's vcard.
//note that googletalk seems to hack the current vcard hash anyway. don't test this feature on that network.
Q_snprintf ( vcard , sizeofcaps ,
" <x xmlns='vcard-temp:x:update'/> " ) ;
}
return caps ;
}
2013-06-29 16:01:07 +00:00
void JCL_ParseIQ ( jclient_t * jcl , xmltree_t * tree )
2005-12-11 20:11:22 +00:00
{
2013-06-29 16:01:07 +00:00
qboolean unparsable = true ;
2017-10-12 12:02:25 +00:00
const char * from ;
// const char *to;
const char * id ;
const char * f ;
2013-06-29 16:01:07 +00:00
xmltree_t * ot ;
2005-12-11 20:11:22 +00:00
2013-06-29 16:01:07 +00:00
//FIXME: block from people who we don't know.
2005-12-11 20:11:22 +00:00
2013-06-29 16:01:07 +00:00
id = XML_GetParameter ( tree , " id " , " " ) ;
2013-11-21 23:02:28 +00:00
from = XML_GetParameter ( tree , " from " , jcl - > domain ) ;
2013-06-29 16:01:07 +00:00
// to = XML_GetParameter(tree, "to", "");
2005-12-11 20:11:22 +00:00
2013-06-29 16:01:07 +00:00
f = XML_GetParameter ( tree , " type " , " " ) ;
if ( ! strcmp ( f , " get " ) )
2013-03-31 04:21:08 +00:00
{
2013-06-29 16:01:07 +00:00
ot = XML_ChildOfTree ( tree , " query " , 0 ) ;
if ( ot )
{
if ( from & & ! strcmp ( ot - > xmlns , " http://jabber.org/protocol/disco#info " ) )
{ //http://xmpp.org/extensions/xep-0030.html
char msg [ 2048 ] ;
2013-08-21 07:42:42 +00:00
char hashednode [ 1024 ] ;
2017-10-12 12:02:25 +00:00
const char * node = XML_GetParameter ( ot , " node " , NULL ) ;
2013-03-31 04:21:08 +00:00
2013-11-21 23:02:28 +00:00
buildcaps ( jcl , msg , sizeof ( msg ) ) ;
Q_snprintf ( hashednode , sizeof ( hashednode ) , DISCONODE " #%s " , buildcapshash ( jcl ) ) ;
2005-12-11 20:11:22 +00:00
2015-04-27 06:19:33 +00:00
if ( ! node | | ! strcmp ( node , hashednode ) | | ! strcmp ( node , DISCONODE " # " ) )
2013-08-21 07:42:42 +00:00
{
2017-10-12 12:02:25 +00:00
unparsable = false ;
2013-08-21 07:42:42 +00:00
JCL_AddClientMessagef ( jcl ,
" <iq type='result' to='%s' id='%s'> "
" <query xmlns='http://jabber.org/protocol/disco#info' node='%s'> "
2017-10-12 12:02:25 +00:00
" %+s "
2013-08-21 07:42:42 +00:00
" </query> "
" </iq> " , from , id , node ? node : hashednode , msg ) ;
}
# ifdef VOIP_LEGACY
2013-11-21 23:02:28 +00:00
else if ( ! strcmp ( node , DISCONODE " #voice-v1 " ) & & ( jcl - > enabledcapabilities & CAP_GOOGLE_VOICE ) )
2013-08-21 07:42:42 +00:00
{
2017-10-12 12:02:25 +00:00
unparsable = false ;
2013-08-21 07:42:42 +00:00
JCL_AddClientMessagef ( jcl ,
" <iq type='result' to='%s' id='%s'> "
" <query xmlns='http://jabber.org/protocol/disco#info' node='%s'> "
" <feature var='http://www.google.com/xmpp/protocol/voice/v1'/> "
" </query> "
" </iq> " , from , id , node , msg ) ;
}
2013-11-21 23:02:28 +00:00
else if ( ! strcmp ( node , DISCONODE " #camera-v1 " ) & & ( jcl - > enabledcapabilities & CAP_GOOGLE_VOICE ) )
{
2017-10-12 12:02:25 +00:00
unparsable = false ;
2013-11-21 23:02:28 +00:00
JCL_AddClientMessagef ( jcl ,
" <iq type='result' to='%s' id='%s'> "
" <query xmlns='http://jabber.org/protocol/disco#info' node='%s'> "
" <feature var='http://www.google.com/xmpp/protocol/camera/v1'/> "
" </query> "
" </iq> " , from , id , node , msg ) ;
}
else if ( ! strcmp ( node , DISCONODE " #video-v1 " ) & & ( jcl - > enabledcapabilities & CAP_GOOGLE_VOICE ) )
{
2017-10-12 12:02:25 +00:00
unparsable = false ;
2013-11-21 23:02:28 +00:00
JCL_AddClientMessagef ( jcl ,
" <iq type='result' to='%s' id='%s'> "
" <query xmlns='http://jabber.org/protocol/disco#info' node='%s'> "
" <feature var='http://www.google.com/xmpp/protocol/video/v1'/> "
" </query> "
" </iq> " , from , id , node , msg ) ;
}
2013-08-21 07:42:42 +00:00
# endif
else
{
JCL_AddClientMessagef ( jcl ,
" <iq type='error' to='%s' id='%s'> "
2015-04-27 06:19:33 +00:00
" <error code='404' type='cancel'> "
2013-08-21 07:42:42 +00:00
" <item-not-found/> "
" </error> "
" </iq> " , from , id ) ;
}
2013-06-29 16:01:07 +00:00
}
2017-10-12 12:02:25 +00:00
else if ( from & & ! strcmp ( ot - > xmlns , " http://jabber.org/protocol/disco#items " ) )
{ //http://xmpp.org/extensions/xep-0030.html
const char * node = XML_GetParameter ( ot , " node " , NULL ) ;
if ( ! strcmp ( node , " http://jabber.org/protocol/commands " ) )
{
const char * to = XML_GetParameter ( tree , " to " , " " ) ;
unparsable = false ;
JCL_AddClientMessagef ( jcl ,
" <iq type='result' to='%s' id='%s'> "
" <query xmlns='http://jabber.org/protocol/disco#items' node='%s'> "
" <item jid='%s' node='rcon' name='Toggle Remote Control'/> "
" </query> "
" </iq> " , from , id , node , to ) ;
}
else
{ //send back an empty list if its something we don't recognise
JCL_AddClientMessagef ( jcl ,
" <iq type='result' to='%s' id='%s'> "
" <query xmlns='http://jabber.org/protocol/disco#items' node='%s' /> "
" </iq> " , from , id , node ) ;
}
}
2013-06-29 16:01:07 +00:00
else if ( from & & ! strcmp ( ot - > xmlns , " jabber:iq:version " ) )
{ //client->client version request
char msg [ 2048 ] ;
unparsable = false ;
2005-12-11 20:11:22 +00:00
2013-06-29 16:01:07 +00:00
Q_snprintf ( msg , sizeof ( msg ) ,
" <iq type='result' to='%s' id='%s'> "
" <query xmlns='jabber:iq:version'> "
" <name>FTEQW XMPP</name> "
" <version>V " JCL_BUILD " </version> "
# ifdef Q3_VM
" <os>QVM plugin</os> "
# else
//don't specify the os otherwise, as it gives away required base addresses etc for exploits
# endif
" </query> "
" </iq> " , from , id ) ;
JCL_AddClientMessageString ( jcl , msg ) ;
}
else if ( from & & ! strcmp ( ot - > xmlns , " jabber:iq:last " ) )
2005-12-11 20:11:22 +00:00
{
2013-06-29 16:01:07 +00:00
unparsable = false ;
JCL_AddClientMessagef ( jcl ,
" <iq type='error' to='%s' id='%s'> "
" <error type='cancel'> "
" <service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/> "
" </error> "
" </iq> " , from , id ) ;
2005-12-11 20:11:22 +00:00
}
2013-06-29 16:01:07 +00:00
/* else if (from && !strcmp(ot->xmlns, "jabber:iq:last"))
{ //http://xmpp.org/extensions/xep-0012.html
char msg [ 2048 ] ;
int idletime = 0 ;
unparsable = false ;
2005-12-11 20:11:22 +00:00
2013-06-29 16:01:07 +00:00
//last activity
Q_snprintf ( msg , sizeof ( msg ) ,
" <iq type='result' to='%s' id='%s'> "
" <query xmlns='jabber:iq:last' seconds='%i'/> "
" </iq> " , from , id , idletime ) ;
JCL_AddClientMessageString ( jcl , msg ) ;
}
*/
2005-12-11 20:11:22 +00:00
}
2013-06-29 16:01:07 +00:00
# ifndef Q3_VM
ot = XML_ChildOfTree ( tree , " time " , 0 ) ;
if ( ot & & ! strcmp ( ot - > xmlns , " urn:xmpp:time " ) )
{ //http://xmpp.org/extensions/xep-0202.html
char msg [ 2048 ] ;
char tz [ 256 ] ;
char timestamp [ 256 ] ;
struct tm * timeinfo ;
int tzh , tzm ;
time_t rawtime ;
time ( & rawtime ) ;
timeinfo = localtime ( & rawtime ) ;
tzh = timeinfo - > tm_hour ;
tzm = timeinfo - > tm_min ;
timeinfo = gmtime ( & rawtime ) ;
tzh - = timeinfo - > tm_hour ;
tzm - = timeinfo - > tm_min ;
Q_snprintf ( tz , sizeof ( tz ) , " %+i:%i " , tzh , tzm ) ;
strftime ( timestamp , sizeof ( timestamp ) , " %Y-%m-%dT%H:%M:%SZ " , timeinfo ) ;
unparsable = false ;
//strftime
Q_snprintf ( msg , sizeof ( msg ) ,
" <iq type='result' to='%s' id='%s'> "
" <time xmlns='urn:xmpp:time'> "
" <tzo>%s</tzo> "
" <utc>%s</utc> "
" </time> "
" </iq> " , from , id , tz , timestamp ) ;
JCL_AddClientMessageString ( jcl , msg ) ;
2005-12-11 20:11:22 +00:00
}
2013-06-29 16:01:07 +00:00
# endif
2005-12-11 20:11:22 +00:00
2013-06-29 16:01:07 +00:00
ot = XML_ChildOfTree ( tree , " ping " , 0 ) ;
if ( ot & & ! strcmp ( ot - > xmlns , " urn:xmpp:ping " ) )
2013-06-23 02:33:52 +00:00
{
2013-06-29 16:01:07 +00:00
JCL_AddClientMessagef ( jcl , " <iq type='result' to='%s' id='%s' /> " , from , id ) ;
2013-06-23 02:33:52 +00:00
}
2013-06-29 16:01:07 +00:00
if ( unparsable )
{ //unsupported stuff
char msg [ 2048 ] ;
unparsable = false ;
2013-06-23 02:33:52 +00:00
2013-06-29 16:01:07 +00:00
Con_Printf ( " Unsupported iq get \n " ) ;
2013-11-21 23:02:28 +00:00
XML_ConPrintTree ( tree , " " , 0 ) ;
2013-06-29 16:01:07 +00:00
//tell them OH NOES, instead of requiring some timeout.
Q_snprintf ( msg , sizeof ( msg ) ,
" <iq type='error' to='%s' id='%s'> "
" <error type='cancel'> "
" <service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/> "
" </error> "
" </iq> " , from , id ) ;
JCL_AddClientMessageString ( jcl , msg ) ;
2005-12-11 20:11:22 +00:00
}
2013-07-13 12:14:32 +00:00
}
else if ( ! strcmp ( f , " set " ) )
{
xmltree_t * c ;
2013-11-21 23:02:28 +00:00
# ifdef FILETRANSFERS
if ( XMPP_FT_ParseIQSet ( jcl , from , id , tree ) )
return ;
2013-07-13 12:14:32 +00:00
# endif
2013-11-21 23:02:28 +00:00
2013-06-29 16:01:07 +00:00
c = XML_ChildOfTree ( tree , " query " , 0 ) ;
2017-06-21 01:24:25 +00:00
if ( c & & ! strcmp ( c - > xmlns , " jabber:iq:roster " ) )
2005-12-11 20:11:22 +00:00
{
2013-06-29 16:01:07 +00:00
unparsable = false ;
2017-10-12 12:02:25 +00:00
if ( strcmp ( from , jcl - > domain ) )
Con_Printf ( " Roster push from unknown entity: \" %s \" \n " , from ) ;
else
JCL_RosterUpdate ( jcl , c , from ) ;
}
c = XML_ChildOfTreeNS ( tree , " http://jabber.org/protocol/commands " , " command " , 0 ) ;
if ( c )
{
char * s ;
const char * key , * val ;
xmltree_t * rep , * cmd , * x , * fld ;
const char * node = XML_GetParameter ( c , " node " , " " ) ;
char * completed = NULL ;
char * canceled = NULL ;
char infostring [ 65536 ] ;
int i ;
unparsable = false ;
* infostring = 0 ;
x = XML_ChildOfTreeNS ( c , " jabber:x:data " , " x " , 0 ) ;
for ( i = 0 ; ; i + + )
{
fld = XML_ChildOfTree ( x , " field " , i ) ;
if ( ! fld )
break ;
key = XML_GetParameter ( fld , " var " , " " ) ;
val = XML_GetChildBody ( fld , " value " , " " ) ;
if ( * key & & * val )
{
Q_strlcat ( infostring , " \\ " , sizeof ( infostring ) ) ;
Q_strlcat ( infostring , key , sizeof ( infostring ) ) ;
Q_strlcat ( infostring , " \\ " , sizeof ( infostring ) ) ;
Q_strlcat ( infostring , val , sizeof ( infostring ) ) ;
}
}
if ( ! strcmp ( XML_GetParameter ( c , " action " , " submit " ) , " cancel " ) )
canceled = " " ;
else if ( ! strcmp ( node , " rcon " ) )
{
char pwd [ 64 ] ;
JCL_Info_ValueForKey ( infostring , " password " , pwd , sizeof ( pwd ) ) ;
if ( * pwd )
{
char rcon_password [ 64 ] ;
2019-09-04 07:59:40 +00:00
cvarfuncs - > GetString ( " rcon_password " , rcon_password , sizeof ( rcon_password ) ) ;
2017-10-12 12:02:25 +00:00
if ( * rcon_password & & ! strcmp ( JCL_Info_ValueForKey ( infostring , " password " , pwd , sizeof ( pwd ) ) , rcon_password ) )
{
Q_strlcpy ( jcl - > rcon_peer , from , sizeof ( jcl - > rcon_peer ) ) ;
if ( jcl - > rcon_pipe > = 0 )
2019-09-04 07:59:40 +00:00
filefuncs - > Close ( jcl - > rcon_pipe ) ;
if ( confuncs )
jcl - > rcon_pipe = confuncs - > POpen ( NULL ) ;
2017-10-12 12:02:25 +00:00
if ( jcl - > rcon_pipe < 0 )
canceled = " Unable to read console " ;
else
completed = " Rcon Enabled " ;
}
else
completed = " Invalid Password " ;
}
}
else
canceled = " Unrecognised request " ;
rep = XML_CreateNode ( NULL , " iq " , NULL , " " ) ;
XML_AddParameter ( rep , " type " , " result " ) ;
XML_AddParameter ( rep , " id " , id ) ;
XML_AddParameter ( rep , " to " , from ) ;
cmd = XML_CreateNode ( rep , " command " , " http://jabber.org/protocol/commands " , " " ) ;
XML_AddParameter ( cmd , " sessionid " , XML_GetParameter ( c , " sessionid " , id ) ) ;
XML_AddParameter ( cmd , " node " , node ) ;
if ( canceled )
{
if ( * canceled )
{
XML_AddParameter ( cmd , " status " , " completed " ) ;
XML_AddParameter ( XML_CreateNode ( cmd , " note " , NULL , canceled ) , " type " , " error " ) ;
}
else
XML_AddParameter ( cmd , " status " , " canceled " ) ;
}
else if ( completed )
{
XML_AddParameter ( cmd , " status " , " completed " ) ;
if ( * completed )
XML_AddParameter ( XML_CreateNode ( cmd , " note " , NULL , completed ) , " type " , " info " ) ;
}
else
{
XML_AddParameter ( cmd , " status " , " executing " ) ;
// x = XML_CreateNode(cmd, "actions", NULL, "");
// XML_AddParameter(x, "execute", "complete");
// XML_CreateNode(x, "complete", NULL, NULL);
// x = XML_CreateNode(cmd, "actions", NULL, "");
// XML_AddParameter(x, "execute", "next");
// XML_CreateNode(x, "next", NULL, NULL);
x = XML_CreateNode ( cmd , " x " , " jabber:x:data " , " " ) ;
XML_AddParameter ( x , " type " , " result " ) ;
XML_CreateNode ( x , " title " , NULL , " Enable RCon " ) ;
XML_CreateNode ( x , " instructions " , NULL , " RCon password required... \n WARNING: This is NOT end-to-end encrypted. " ) ;
fld = XML_CreateNode ( x , " field " , NULL , NULL ) ;
XML_AddParameter ( fld , " var " , " password " ) ;
XML_AddParameter ( fld , " type " , " text-private " ) ;
XML_AddParameter ( fld , " label " , " Rcon Password " ) ;
XML_CreateNode ( fld , " value " , NULL , " " ) ;
}
s = XML_GenerateString ( rep , false ) ;
XML_Destroy ( rep ) ;
JCL_AddClientMessagef ( jcl , s , from , id ) ;
free ( s ) ;
2005-12-11 20:11:22 +00:00
}
2017-09-21 00:52:52 +00:00
# ifdef USE_GOOGLE_MAIL_NOTIFY
2013-11-21 23:02:28 +00:00
//google-specific - new mail notifications.
c = XML_ChildOfTree ( tree , " new-mail " , 0 ) ;
if ( c & & ! strcmp ( c - > xmlns , " google:mail:notify " ) & & ! strcmp ( from , jcl - > domain ) )
{
JCL_AddClientMessagef ( jcl , " <iq type='result' to='%s' id='%s' /> " , from , id ) ;
JCL_SendIQf ( jcl , XMPP_NewGoogleMailsReply , " get " , " " , " <query xmlns='google:mail:notify'/> " ) ;
return ;
}
2017-09-21 00:52:52 +00:00
# endif
2013-11-21 23:02:28 +00:00
2013-07-13 12:14:32 +00:00
# ifdef JINGLE
2013-08-21 07:42:42 +00:00
c = XML_ChildOfTreeNS ( tree , " urn:xmpp:jingle:1 " , " jingle " , 0 ) ;
2013-11-21 23:02:28 +00:00
if ( c & & ( jcl - > enabledcapabilities & ( CAP_GAMEINVITE | CAP_VOICE | CAP_VIDEO ) ) )
2017-06-21 01:24:25 +00:00
{
2013-06-29 16:01:07 +00:00
unparsable = ! JCL_ParseJingle ( jcl , c , from , id ) ;
2017-06-21 01:24:25 +00:00
jclient_updatebuddylist = true ;
}
2013-08-21 07:42:42 +00:00
# ifdef VOIP_LEGACY
c = XML_ChildOfTreeNS ( tree , " http://www.google.com/session " , " session " , 0 ) ;
2013-11-21 23:02:28 +00:00
if ( c & & ( jcl - > enabledcapabilities & ( CAP_GOOGLE_VOICE ) ) )
2017-06-21 01:24:25 +00:00
{
2013-08-21 07:42:42 +00:00
unparsable = ! JCL_HandleGoogleSession ( jcl , c , from , id ) ;
2017-06-21 01:24:25 +00:00
jclient_updatebuddylist = true ;
}
2013-08-21 07:42:42 +00:00
# endif
2013-07-13 12:14:32 +00:00
# endif
2005-12-11 20:11:22 +00:00
2013-11-21 23:02:28 +00:00
2013-06-29 16:01:07 +00:00
if ( unparsable )
{
char msg [ 2048 ] ;
//tell them OH NOES, instead of requiring some timeout.
Q_snprintf ( msg , sizeof ( msg ) ,
" <iq type='error' to='%s' id='%s'> "
" <error type='cancel'> "
" <service-unavailable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/> "
" </error> "
" </iq> " , from , id ) ;
JCL_AddClientMessageString ( jcl , msg ) ;
unparsable = false ;
2005-12-11 20:11:22 +00:00
}
}
2013-06-29 16:01:07 +00:00
else if ( ! strcmp ( f , " result " ) | | ! strcmp ( f , " error " ) )
2005-12-11 20:11:22 +00:00
{
2017-10-12 12:02:25 +00:00
const char * id = XML_GetParameter ( tree , " id " , " " ) ;
2013-06-29 16:01:07 +00:00
struct iq_s * * link , * iq ;
2017-10-12 12:02:25 +00:00
const char * from = XML_GetParameter ( tree , " from " , jcl - > domain ) ;
2013-06-29 16:01:07 +00:00
unparsable = false ;
for ( link = & jcl - > pendingiqs ; * link ; link = & ( * link ) - > next )
2005-12-11 20:11:22 +00:00
{
2013-06-29 16:01:07 +00:00
iq = * link ;
2013-10-29 17:38:22 +00:00
if ( ! strcmp ( iq - > id , id ) & & ( ! strcmp ( iq - > to , from ) | | ! * iq - > to ) )
2013-06-29 16:01:07 +00:00
break ;
}
if ( * link )
{
iq = * link ;
* link = iq - > next ;
if ( iq - > callback )
{
if ( ! iq - > callback ( jcl , ! strcmp ( f , " error " ) ? NULL : tree , iq ) )
{
Con_Printf ( " Invalid iq result \n " ) ;
2013-11-21 23:02:28 +00:00
XML_ConPrintTree ( tree , " " , 0 ) ;
2013-06-29 16:01:07 +00:00
}
}
free ( iq ) ;
}
else
{
2015-08-02 19:08:36 +00:00
Con_Printf ( " Unrecognised iq result from %s \n " , from ) ;
// XML_ConPrintTree(tree, "", 0);
2013-06-29 16:01:07 +00:00
}
}
if ( unparsable )
{
unparsable = false ;
Con_Printf ( " Unrecognised iq type \n " ) ;
2013-11-21 23:02:28 +00:00
XML_ConPrintTree ( tree , " " , 0 ) ;
2013-06-29 16:01:07 +00:00
}
}
2019-09-04 07:59:40 +00:00
void XMPP_ConversationPrintf ( const char * context , const char * title , qboolean takefocus , char * format , . . . )
2015-04-27 06:19:33 +00:00
{
va_list argptr ;
static char string [ 1024 ] ;
va_start ( argptr , format ) ;
Q_vsnprintf ( string , sizeof ( string ) , format , argptr ) ;
va_end ( argptr ) ;
2019-09-04 07:59:40 +00:00
if ( * context & & confuncs & & confuncs - > GetConsoleFloat ( context , " iswindow " ) < true )
2015-04-27 06:19:33 +00:00
{
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleFloat ( context , " iswindow " , true ) ;
confuncs - > SetConsoleFloat ( context , " forceutf8 " , true ) ;
confuncs - > SetConsoleFloat ( context , " wnd_w " , 256 ) ;
confuncs - > SetConsoleFloat ( context , " wnd_h " , 320 ) ;
confuncs - > SetConsoleString ( context , " title " , title ) ;
2015-04-27 06:19:33 +00:00
}
Con_TrySubPrint ( context , string ) ;
}
2013-06-29 16:01:07 +00:00
void JCL_ParseMessage ( jclient_t * jcl , xmltree_t * tree )
{
xmltree_t * ot ;
qboolean unparsable = true ;
2017-10-12 12:02:25 +00:00
const char * f = XML_GetParameter ( tree , " from " , jcl - > domain ) ;
const char * type = XML_GetParameter ( tree , " type " , " normal " ) ;
const char * ctx = f ;
2013-06-29 16:01:07 +00:00
2017-09-20 11:27:13 +00:00
xmltree_t * received = XML_ChildOfTree ( tree , " received " , 0 ) ;
xmltree_t * sent = XML_ChildOfTree ( tree , " sent " , 0 ) ;
2017-10-12 12:02:25 +00:00
const char * showicon = NULL ; //their icon
2017-09-20 11:27:13 +00:00
if ( received & & sent )
return ; //no, just no.
if ( received )
{
xmltree_t * forwarded = XML_ChildOfTree ( received , " forwarded " , 0 ) ;
if ( ! forwarded | | strcmp ( f , jcl - > barejid ) )
return ; //no bugs, no spoofing
tree = XML_ChildOfTree ( forwarded , " message " , 0 ) ;
f = XML_GetParameter ( tree , " from " , jcl - > domain ) ;
}
if ( sent )
{
xmltree_t * forwarded = XML_ChildOfTree ( sent , " forwarded " , 0 ) ;
if ( ! forwarded | | strcmp ( f , jcl - > barejid ) )
return ; //no bugs, no spoofing
tree = XML_ChildOfTree ( forwarded , " message " , 0 ) ;
f = XML_GetParameter ( tree , " to " , jcl - > domain ) ;
}
if ( ! strcmp ( f , jcl - > fulljid ) )
2013-06-29 16:01:07 +00:00
unparsable = false ;
else
{
if ( f )
{
2015-04-27 06:19:33 +00:00
buddy_t * b = NULL ;
bresource_t * br = NULL ;
2013-06-29 16:01:07 +00:00
Q_strlcpy ( jcl - > defaultdest , f , sizeof ( jcl - > defaultdest ) ) ;
2015-04-27 06:19:33 +00:00
JCL_FindBuddy ( jcl , f , & b , & br , true ) ;
2017-10-12 12:02:25 +00:00
if ( b & & b - > btype = = BT_CHATROOM & & strchr ( jcl - > defaultdest , ' / ' ) )
* strchr ( jcl - > defaultdest , ' / ' ) = 0 ;
2015-04-27 06:19:33 +00:00
if ( b )
2013-07-13 12:14:32 +00:00
{
2015-04-27 06:19:33 +00:00
ctx = b - > accountdomain ;
2013-11-21 23:02:28 +00:00
if ( ! strcmp ( type , " groupchat " ) )
2017-10-12 12:02:25 +00:00
{ //clients can act as a MUC too, which is awkward.
if ( br )
f = br - > resource ;
}
else if ( b - > btype = = BT_CHATROOM )
2013-11-21 23:02:28 +00:00
{
2015-04-27 06:19:33 +00:00
ctx = f ; //one server with multiple rooms requires that we retain resource info.
2017-10-12 12:02:25 +00:00
if ( br )
f = br - > resource ;
2013-11-21 23:02:28 +00:00
}
else
{
2019-09-04 07:59:40 +00:00
if ( confuncs )
2017-10-12 12:02:25 +00:00
showicon = b - > accountdomain ;
2013-11-21 23:02:28 +00:00
f = b - > name ;
2015-04-27 06:19:33 +00:00
if ( br )
b - > defaultresource = br ;
2013-11-21 23:02:28 +00:00
}
2013-07-13 12:14:32 +00:00
}
2013-06-29 16:01:07 +00:00
}
2014-04-24 01:53:01 +00:00
if ( ! strcmp ( type , " error " ) )
{
2017-10-12 12:02:25 +00:00
const char * reason = NULL ;
unparsable = false ;
2017-09-20 11:27:13 +00:00
if ( sent )
return ;
2014-08-03 14:47:47 +00:00
ot = XML_ChildOfTree ( tree , " error " , 0 ) ;
if ( ot - > child )
reason = ot - > child - > name ;
if ( XML_ChildOfTree ( ot , " remote-server-not-found " , 0 ) ) reason = " Remote Server Not Found " ;
if ( XML_ChildOfTree ( ot , " bad-request " , 0 ) ) reason = " Bad Request " ;
if ( XML_ChildOfTree ( ot , " conflict " , 0 ) ) reason = " Conflict Error " ;
if ( XML_ChildOfTree ( ot , " feature-not-implemented " , 0 ) ) reason = " feature-not-implemented " ;
if ( XML_ChildOfTree ( ot , " forbidden " , 0 ) ) reason = " forbidden " ;
if ( XML_ChildOfTree ( ot , " gone " , 0 ) ) reason = " 'gone' Error " ;
if ( XML_ChildOfTree ( ot , " internal-server-error " , 0 ) ) reason = " internal-server-error " ;
if ( XML_ChildOfTree ( ot , " item-not-found " , 0 ) ) reason = " item-not-found " ;
if ( XML_ChildOfTree ( ot , " jid-malformed " , 0 ) ) reason = " jid-malformed " ;
if ( XML_ChildOfTree ( ot , " not-acceptable " , 0 ) ) reason = " not-acceptable " ;
if ( XML_ChildOfTree ( ot , " not-allowed " , 0 ) ) reason = " not-allowed " ;
if ( XML_ChildOfTree ( ot , " not-authorized " , 0 ) ) reason = " not-authorized " ;
if ( XML_ChildOfTree ( ot , " policy-violation " , 0 ) ) reason = " policy-violation " ;
if ( XML_ChildOfTree ( ot , " recipient-unavailable " , 0 ) ) reason = " recipient-unavailable " ;
if ( XML_ChildOfTree ( ot , " redirect " , 0 ) ) reason = " 'redirect' Error " ;
if ( XML_ChildOfTree ( ot , " registration-required " , 0 ) ) reason = " registration-required " ;
if ( XML_ChildOfTree ( ot , " remote-server-not-found " , 0 ) ) reason = " remote-server-not-found " ;
if ( XML_ChildOfTree ( ot , " remote-server-timeout " , 0 ) ) reason = " remote-server-timeout " ;
if ( XML_ChildOfTree ( ot , " resource-constraint " , 0 ) ) reason = " resource-constraint " ;
if ( XML_ChildOfTree ( ot , " service-unavailable " , 0 ) ) reason = " service-unavailable " ;
if ( XML_ChildOfTree ( ot , " subscription-required " , 0 ) ) reason = " subscription-required " ;
if ( XML_ChildOfTree ( ot , " undefined-condition " , 0 ) ) reason = " undefined-condition " ;
if ( XML_ChildOfTree ( ot , " unexpected-request " , 0 ) ) reason = " unexpected-request " ;
2017-10-12 12:02:25 +00:00
reason = XML_GetChildBody ( ot , " text " , reason ) ;
2014-08-03 14:47:47 +00:00
2014-04-24 01:53:01 +00:00
ot = XML_ChildOfTree ( tree , " body " , 0 ) ;
if ( ot )
{
2014-08-03 14:47:47 +00:00
if ( reason )
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , false , " ^1Error: %s (%s): " , reason , f ) ;
2014-08-03 14:47:47 +00:00
else
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , false , " ^1error sending message to %s: " , f ) ;
2014-04-24 01:53:01 +00:00
if ( f )
{
if ( ! strncmp ( ot - > body , " /me " , 4 ) )
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , false , " * ^2%s^7%s \r " , ( ( ! strcmp ( jcl - > localalias , " >> " ) ) ? " me " : jcl - > localalias ) , ot - > body + 3 ) ;
2014-04-24 01:53:01 +00:00
else
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , false , " %s \r " , ot - > body ) ;
2014-04-24 01:53:01 +00:00
}
}
else
2017-10-12 12:02:25 +00:00
{
if ( reason )
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , false , " ^1Error: %s (%s) \r " , reason , f ) ;
2017-10-12 12:02:25 +00:00
else
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , false , " error sending message to %s \r " , f ) ;
2017-10-12 12:02:25 +00:00
}
2014-08-03 14:47:47 +00:00
return ;
2014-04-24 01:53:01 +00:00
}
2017-09-20 11:27:13 +00:00
if ( f & & ! sent )
2013-06-29 16:01:07 +00:00
{
ot = XML_ChildOfTree ( tree , " composing " , 0 ) ;
if ( ot & & ! strcmp ( ot - > xmlns , " http://jabber.org/protocol/chatstates " ) )
{
unparsable = false ;
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , false , " %s is typing \r " , f ) ;
2013-06-29 16:01:07 +00:00
}
ot = XML_ChildOfTree ( tree , " paused " , 0 ) ;
if ( ot & & ! strcmp ( ot - > xmlns , " http://jabber.org/protocol/chatstates " ) )
{
unparsable = false ;
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , false , " %s has stopped typing \r " , f ) ;
2013-06-29 16:01:07 +00:00
}
ot = XML_ChildOfTree ( tree , " inactive " , 0 ) ;
if ( ot & & ! strcmp ( ot - > xmlns , " http://jabber.org/protocol/chatstates " ) )
{
unparsable = false ;
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , false , " \r " , f ) ;
2013-06-29 16:01:07 +00:00
}
ot = XML_ChildOfTree ( tree , " active " , 0 ) ;
if ( ot & & ! strcmp ( ot - > xmlns , " http://jabber.org/protocol/chatstates " ) )
{
unparsable = false ;
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , false , " \r " , f ) ;
2013-06-29 16:01:07 +00:00
}
ot = XML_ChildOfTree ( tree , " gone " , 0 ) ;
if ( ot & & ! strcmp ( ot - > xmlns , " http://jabber.org/protocol/chatstates " ) )
{
unparsable = false ;
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , false , " %s has gone away \r " , f ) ;
2013-06-29 16:01:07 +00:00
}
}
2017-09-20 11:27:13 +00:00
ot = XML_ChildOfTreeNS ( tree , " urn:xmpp:attention:0 " , " attention " , 0 ) ;
if ( ot & & ! sent )
2013-06-29 21:08:09 +00:00
{
2017-09-20 11:27:13 +00:00
unparsable = false ;
2013-07-13 12:14:32 +00:00
if ( jclient_poketime < jclient_curtime ) //throttle these.
{
jclient_poketime = jclient_curtime + 10 * 1000 ;
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , true , " %s is an attention whore. \n " , f ) ;
if ( drawfuncs )
drawfuncs - > LocalSound ( " misc/talk.wav " , 256 , 1 ) ;
2013-07-13 12:14:32 +00:00
}
}
ot = XML_ChildOfTree ( tree , " subject " , 0 ) ;
if ( ot & & ! strcmp ( type , " groupchat " ) )
{
2017-10-12 12:02:25 +00:00
buddy_t * b ;
JCL_FindBuddy ( jcl , ctx , & b , NULL , true ) ;
if ( b & & b - > btype = = BT_CHATROOM )
{
free ( b - > room_topic ) ;
b - > room_topic = strdup ( ot - > body ) ;
jclient_updatebuddylist = true ;
}
2013-07-13 12:14:32 +00:00
unparsable = false ;
2017-09-20 11:27:13 +00:00
if ( sent )
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , false , COL_NAME_US " You " COL_TEXT_US " have set the topic to: %s \n " , ot - > body ) ;
2017-09-20 11:27:13 +00:00
else
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , false , COL_NAME_THEM " %s " COL_TEXT_THEM " has set the topic to: %s \n " , f , ot - > body ) ;
2013-07-13 12:14:32 +00:00
}
2017-09-20 11:27:13 +00:00
ot = XML_ChildOfTreeNS ( tree , " http://jabber.org/protocol/pubsub#event " , " event " , 0 ) ;
if ( ot )
{
buddy_t * b ;
unparsable = false ;
JCL_FindBuddy ( jcl , f , & b , NULL , false ) ;
if ( ! sent )
{
xmltree_t * items = XML_ChildOfTree ( ot , " items " , 0 ) ;
const char * node = XML_GetParameter ( items , " node " , " " ) ;
if ( ! strcmp ( node , " http://jabber.org/protocol/nick " ) )
{
xmltree_t * item = XML_ChildOfTree ( items , " item " , 0 ) ;
const char * nick = XML_GetChildBody ( item , " nick " , NULL ) ;
if ( nick & & b )
Q_strlcpy ( b - > name , nick , sizeof ( b - > name ) ) ;
}
else if ( ! strcmp ( node , " http://jabber.org/protocol/tune " ) )
{
// xmltree_t *item = XML_ChildOfTree(items, "item", 0);
// xmltree_t *tune = XML_ChildOfTreeNS(item, "http://jabber.org/protocol/tune", "tune", 0);
}
else if ( ! strcmp ( node , " http://jabber.org/protocol/mood " ) )
{
// xmltree_t *item = XML_ChildOfTree(items, "item", 0);
// xmltree_t *mood = XML_ChildOfTreeNS(item, "http://jabber.org/protocol/mood", "mood", 0);
// const char *text = XML_GetChildBody(mood, "text", NULL);
//there's a whole army of options here. crazy stuff that makes it unusable.
}
else if ( ! strcmp ( node , " urn:xmpp:avatar:metadata " ) )
{
// xmltree_t *item = XML_ChildOfTree(items, "item", 0);
// xmltree_t *tune = XML_ChildOfTreeNS(item, "urn:xmpp:avatar:metadata", "metadata", 0);
//this can get messy.
}
else
{
Con_DPrintf ( " Unknown pubsub/pep node \" %s \" \n " , node ) ;
}
}
}
2013-07-13 12:14:32 +00:00
ot = XML_ChildOfTreeNS ( tree , " http://jabber.org/protocol/muc#user " , " x " , 0 ) ;
if ( ot & & f & & ! strchr ( f , ' / ' ) )
{
//this is an appaling extension protocol. we really have no way to know if someone's just making this shit up just to see our presence.
//this message came from the groupchat server.
xmltree_t * inv = XML_ChildOfTree ( ot , " invite " , 0 ) ;
if ( inv )
{
2017-10-12 12:02:25 +00:00
const char * who = XML_GetParameter ( inv , " from " , jcl - > domain ) ;
const char * reason = XML_GetChildBody ( inv , " reason " , NULL ) ;
const char * password = XML_GetChildBody ( ot , " password " , 0 ) ;
2013-07-13 12:14:32 +00:00
char link [ 512 ] ;
buddy_t * b ;
2017-09-20 11:27:13 +00:00
if ( ! sent & & JCL_FindBuddy ( jcl , f , & b , NULL , true ) )
2013-11-21 23:02:28 +00:00
{
2017-10-12 12:02:25 +00:00
if ( b - > btype = = BT_CHATROOM )
2013-11-21 23:02:28 +00:00
return ; //we already know about it. don't spam.
JCL_GenLink ( jcl , link , sizeof ( link ) , " mucjoin " , f , NULL , password , " %s " , f ) ;
2015-04-27 06:19:33 +00:00
// ctx = who;
2013-11-21 23:02:28 +00:00
if ( reason )
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , true , " * ^2%s^7 has invited you to join %s: %s. \n " , who , link , reason ) ;
2013-11-21 23:02:28 +00:00
else
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , true , " * ^2%s^7 has invited you to join %s. \n " , who , link ) ;
2013-11-21 23:02:28 +00:00
}
2013-07-13 12:14:32 +00:00
return ; //ignore any body/jabber:x:conference
}
}
ot = XML_ChildOfTreeNS ( tree , " jabber:x:conference " , " x " , 0 ) ;
if ( ot )
{
char link [ 512 ] ;
2017-10-12 12:02:25 +00:00
const char * chatjit = XML_GetParameter ( ot , " jid " , " " ) ;
const char * reason = XML_GetParameter ( ot , " reason " , NULL ) ;
const char * password = XML_GetParameter ( ot , " password " , NULL ) ;
2013-07-13 12:14:32 +00:00
unparsable = false ;
JCL_GenLink ( jcl , link , sizeof ( link ) , " mucjoin " , chatjit , NULL , password , " %s " , chatjit ) ;
2017-09-20 11:27:13 +00:00
if ( sent )
{
if ( reason )
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , true , " * You have invited ^2%s^7 to join %s: %s. \n " , f , link , reason ) ;
2017-09-20 11:27:13 +00:00
else
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , true , " * You have invited ^2%s^7 to join %s. \n " , f , link ) ;
2017-09-20 11:27:13 +00:00
}
2013-07-13 12:14:32 +00:00
else
2017-09-20 11:27:13 +00:00
{
if ( reason )
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , true , " * ^2%s^7 has invited you to join %s: %s. \n " , f , link , reason ) ;
2017-09-20 11:27:13 +00:00
else
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , true , " * ^2%s^7 has invited you to join %s. \n " , f , link ) ;
2017-09-20 11:27:13 +00:00
}
2013-07-13 12:14:32 +00:00
return ; //ignore any body
2013-06-29 21:08:09 +00:00
}
2013-06-29 16:01:07 +00:00
ot = XML_ChildOfTree ( tree , " body " , 0 ) ;
if ( ot )
{
unparsable = false ;
if ( f )
{
2017-09-20 11:27:13 +00:00
if ( sent )
{
if ( ! strncmp ( ot - > body , " /me " , 4 ) )
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , false , " * " COL_NAME_US " %s " COL_TEXT_US " %s \n " , jcl - > localalias , ot - > body + 3 ) ;
2017-09-20 11:27:13 +00:00
else if ( showicon )
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , false , " ^[ \\ img \\ xmpp/%s.png \\ fbimg \\ " IMG_FB_US " \\ w \\ 32 \\ h \\ 32^] " COL_NAME_US " %s " COL_TEXT_US " : \v %s \n " , jcl - > barejid , jcl - > localalias , ot - > body ) ;
2017-09-20 11:27:13 +00:00
else
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , false , COL_NAME_US " %s " COL_TEXT_US " : %s \n " , jcl - > localalias , ot - > body ) ;
2017-09-20 11:27:13 +00:00
}
2013-06-29 16:01:07 +00:00
else
2017-09-20 11:27:13 +00:00
{
if ( ! strncmp ( ot - > body , " /me " , 4 ) )
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , false , " * " COL_NAME_THEM " %s " COL_TEXT_THEM " %s \n " , f , ot - > body + 3 ) ;
2017-09-20 11:27:13 +00:00
else if ( showicon )
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , false , " ^[ \\ img \\ xmpp/%s.png \\ fbimg \\ " IMG_FB_THEM " \\ w \\ 32 \\ h \\ 32^] " COL_NAME_THEM " %s " COL_TEXT_THEM " : \v %s \n " , showicon , f , ot - > body ) ;
2017-09-20 11:27:13 +00:00
else
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , false , COL_NAME_THEM " %s " COL_TEXT_THEM " : %s \n " , f , ot - > body ) ;
2017-09-20 11:27:13 +00:00
}
2013-06-29 16:01:07 +00:00
}
else
2017-09-20 11:27:13 +00:00
{
if ( ! sent )
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , false , " NOTICE: %s \n " , ot - > body ) ;
2017-09-20 11:27:13 +00:00
}
2013-06-29 16:01:07 +00:00
2019-09-04 07:59:40 +00:00
if ( drawfuncs )
drawfuncs - > LocalSound ( " misc/talk.wav " , 256 , 1 ) ;
2013-06-29 16:01:07 +00:00
}
if ( unparsable )
{
unparsable = false ;
if ( jcl - > streamdebug )
{
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( ctx , f , false , " Received a message without a body \n " ) ;
2013-11-21 23:02:28 +00:00
XML_ConPrintTree ( tree , " " , 0 ) ;
2013-06-29 16:01:07 +00:00
}
}
}
}
2017-09-20 11:27:13 +00:00
#if 0
static qboolean JCL_ValidateCaps ( xmltree_t * query , const char * node , const char * ver , const char * hash )
{
const char * respnode = XML_GetParameter ( query , " node " , " " ) ;
int l ;
char out [ 8192 ] ;
int outlen = sizeof ( out ) ;
unsigned char digest [ 64 ] ;
const char * features [ 1024 ] ;
size_t i , numfeatures = 0 ;
size_t nlen = strlen ( node ) ;
if ( strcmp ( hash , " sha-1 " ) )
return false ; //unable to validate.
if ( strncmp ( respnode , node , nlen ) )
return false ; //the client's name changed...
respnode + = nlen ;
if ( * respnode + + ! = ' # ' )
return false ; //o.O
if ( strcmp ( respnode , ver ) )
return false ; //the client's name changed...
for ( i = 0 ; i < 64 ; i + + )
{
xmltree_t * ident = XML_ChildOfTree ( query , " identity " , i ) ;
if ( ident )
{
const char * category = XML_GetParameter ( ident , " category " , " " ) ;
const char * name = XML_GetParameter ( ident , " name " , " " ) ;
const char * type = XML_GetParameter ( ident , " type " , " " ) ;
const char * lang = XML_GetParameter ( ident , " xml:lang " , " " ) ;
Q_snprintf ( out , outlen , " %s/%s/%s/%s< " , category , type , lang , name ) ;
}
else
break ;
}
for ( i = 0 ; i < countof ( features ) ; i + + )
{
xmltree_t * feature = XML_ChildOfTree ( query , " feature " , i ) ;
if ( feature )
{
const char * var = XML_GetParameter ( feature , " var " , " " ) ;
features [ numfeatures + + ] = var ;
}
else
break ;
}
// qsort(caps, sizeof(caps)/sizeof(caps[0]) - 1, sizeof(caps[0]), qsortcaps);
for ( i = 0 ; i < numfeatures ; i + + )
{
Q_strlcat ( out , features [ i ] , outlen ) ;
Q_strlcat ( out , " < " , outlen ) ;
}
//fixme: add any form crap
l = SHA1 ( digest , sizeof ( digest ) , out , strlen ( out ) ) ;
for ( i = 0 ; i < l ; i + + )
Base64_Byte ( digest [ i ] ) ;
return ! strcmp ( respnode , Base64_Finish ( ) ) ; //make sure its mostly valid.
}
# endif
2013-11-21 23:02:28 +00:00
unsigned int JCL_ParseCaps ( jclient_t * jcl , char * account , char * resource , xmltree_t * query )
2013-06-29 16:01:07 +00:00
{
xmltree_t * feature ;
unsigned int caps = 0 ;
qboolean rtp = false ;
qboolean rtpaudio = false ;
2013-11-21 23:02:28 +00:00
qboolean rtpvideo = false ;
2013-06-29 16:01:07 +00:00
qboolean quake = false ;
qboolean ice = false ;
qboolean raw = false ;
qboolean jingle = false ;
2013-08-21 07:42:42 +00:00
qboolean si = false ;
qboolean sift = false ;
qboolean ibb = false ;
int i = 0 ;
2017-10-12 12:02:25 +00:00
const char * var ;
2013-08-21 07:42:42 +00:00
// XML_ConPrintTree(query, 0);
2013-06-29 16:01:07 +00:00
while ( ( feature = XML_ChildOfTree ( query , " feature " , i + + ) ) )
{
var = XML_GetParameter ( feature , " var " , " " ) ;
//check ones we recognise.
2013-08-21 07:42:42 +00:00
// Con_Printf("%s/%s: %s\n", account, resource, var);
2013-06-29 16:01:07 +00:00
if ( ! strcmp ( var , QUAKEMEDIAXMLNS ) )
quake = true ;
2013-08-21 07:42:42 +00:00
# ifndef VOIP_LEGACY_ONLY
2013-06-29 16:01:07 +00:00
if ( ! strcmp ( var , " urn:xmpp:jingle:apps:rtp:audio " ) )
rtpaudio = true ;
2013-11-21 23:02:28 +00:00
if ( ! strcmp ( var , " urn:xmpp:jingle:apps:rtp:video " ) )
rtpvideo = true ;
2013-08-21 07:42:42 +00:00
# endif
2013-06-29 16:01:07 +00:00
if ( ! strcmp ( var , " urn:xmpp:jingle:apps:rtp:1 " ) )
rtp = true ; //kinda implied, but ensures version is okay
if ( ! strcmp ( var , " urn:xmpp:jingle:transports:ice-udp:1 " ) )
ice = true ;
if ( ! strcmp ( var , " urn:xmpp:jingle:transports:raw-udp:1 " ) )
raw = true ;
if ( ! strcmp ( var , " urn:xmpp:jingle:1 " ) )
jingle = true ; //kinda implied, but ensures version is okay
2013-08-21 07:42:42 +00:00
# ifdef VOIP_LEGACY
if ( ! strcmp ( var , " http://www.google.com/xmpp/protocol/voice/v1 " ) )
2013-11-21 23:02:28 +00:00
caps | = CAP_GOOGLE_VOICE ; //legacy crap, so we can call google's official clients, which do not follow current xmpp standards.
2013-08-21 07:42:42 +00:00
# endif
if ( ! strcmp ( var , " http://jabber.org/protocol/si " ) )
si = true ;
if ( ! strcmp ( var , " http://jabber.org/protocol/si/profile/file-transfer " ) )
sift = true ;
if ( ! strcmp ( var , " http://jabber.org/protocol/ibb " ) )
ibb = true ;
2013-06-29 16:01:07 +00:00
}
2013-08-21 07:42:42 +00:00
2013-06-29 16:01:07 +00:00
if ( ( ice | | raw ) & & jingle )
{
if ( rtpaudio & & rtp )
caps | = CAP_VOICE ;
2013-11-21 23:02:28 +00:00
if ( rtpvideo & & rtp )
caps | = CAP_VIDEO ;
2013-06-29 16:01:07 +00:00
if ( quake )
2013-11-21 23:02:28 +00:00
caps | = CAP_GAMEINVITE ;
2013-06-29 16:01:07 +00:00
}
2013-08-21 07:42:42 +00:00
if ( si & & sift & & ibb )
caps | = CAP_SIFT ;
2013-11-21 23:02:28 +00:00
caps & = jcl - > enabledcapabilities ;
2013-08-21 07:42:42 +00:00
return caps ;
}
void JCL_CheckClientCaps ( jclient_t * jcl , buddy_t * buddy , bresource_t * bres ) ;
qboolean JCL_ClientDiscoInfo ( jclient_t * jcl , xmltree_t * tree , struct iq_s * iq )
{
xmltree_t * query = XML_ChildOfTree ( tree , " query " , 0 ) ;
unsigned int caps = 0 ;
buddy_t * b , * ob ;
bresource_t * r , * or ;
2013-11-21 23:02:28 +00:00
if ( ! JCL_FindBuddy ( jcl , iq - > to , & b , & r , true ) )
return false ;
2013-08-21 07:42:42 +00:00
if ( ! query )
2013-11-21 23:02:28 +00:00
{
caps & = ~ ( CAP_QUERYING | CAP_QUERIED ) ;
caps | = CAP_QUERYFAILED ;
}
2013-08-21 07:42:42 +00:00
else
{
// XML_ConPrintTree(tree, 0);
2017-09-20 11:27:13 +00:00
// if (!JCL_ValidateCaps(query, r->client_node, r->client_ver, r->client_hash))
// caps = 0;
// else
caps = JCL_ParseCaps ( jcl , b - > accountdomain , r - > resource , query ) ;
2013-08-21 07:42:42 +00:00
}
2013-06-29 16:01:07 +00:00
if ( b & & r )
2013-08-21 07:42:42 +00:00
{
if ( ! ( caps & CAP_QUERYFAILED ) )
{
// Con_Printf("%s/%s caps = %x\n", b->accountdomain, r->resource, caps);
if ( ! ( r - > caps & CAP_QUERIED ) )
r - > caps = CAP_QUERIED ; //reset it
2013-11-21 23:02:28 +00:00
r - > caps | = caps ;
2013-08-21 07:42:42 +00:00
//as we got a valid response, make sure other resources running the same software get the same caps
for ( ob = jcl - > buddies ; ob ; ob = ob - > next )
{
for ( or = ob - > resources ; or ; or = or - > next )
{
//ignore evil clients.
if ( r = = or | | ( or - > caps & ( CAP_QUERYFAILED | CAP_QUERIED | CAP_QUERYING ) ) | | ! or - > client_node )
continue ;
//all resources with the same details then get the same caps flags.
if ( ! strcmp ( r - > client_node , or - > client_node ) & & ! strcmp ( r - > client_ver , or - > client_ver ) & & ! strcmp ( r - > client_hash , or - > client_hash ) & & ! strcmp ( r - > client_ext , or - > client_ext ) )
{
// Con_Printf("%s/%s matches (updated) %s/%s (%s#%s)\n", ob->accountdomain, or->resource, b->accountdomain, r->resource, r->client_node, r->client_ver);
or - > caps = r - > caps ;
}
}
}
}
else
{
if ( ! ( r - > caps & ( CAP_QUERIED | CAP_QUERYFAILED ) ) )
{
r - > caps = CAP_QUERYFAILED ;
//as the response is invalid, we need to ensure that other resources that claim to use the same software are still queried anyway.
//(this is needed in case the one that we asked was spoofing)
for ( ob = jcl - > buddies ; ob ; ob = ob - > next )
{
for ( or = ob - > resources ; or ; or = or - > next )
{
//ignore evil clients.
if ( r = = or | | ( or - > caps & ( CAP_QUERYFAILED | CAP_QUERIED | CAP_QUERYING ) ) | | ! or - > client_node )
continue ;
//all resources with the same details then get the same caps flags.
if ( r - > client_node & & ! strcmp ( r - > client_node , or - > client_node ) & & ! strcmp ( r - > client_ver , or - > client_ver ) & & ! strcmp ( r - > client_hash , or - > client_hash ) & & ! strcmp ( r - > client_ext , or - > client_ext ) )
{
JCL_CheckClientCaps ( jcl , ob , or ) ;
return true ;
}
}
}
}
}
}
2013-06-29 16:01:07 +00:00
return true ;
}
2013-08-21 07:42:42 +00:00
void JCL_CheckClientCaps ( jclient_t * jcl , buddy_t * buddy , bresource_t * bres )
{
buddy_t * b ;
bresource_t * r ;
char extname [ 64 ] , * ext ;
//ignore it if we're already asking them...
if ( bres - > caps & ( CAP_QUERYING | CAP_QUERIED | CAP_QUERYFAILED ) )
return ;
2015-04-27 06:19:33 +00:00
bres - > buggycaps = 0 ;
# ifdef VOIP_LEGACY
if ( ! bres - > client_node | | ! bres - > client_hash | | ! * bres - > client_hash )
{
//one of google's nodes. ONLY google get this fucked up evil hack because they're the only ones that are arrogant enough to not bother to query what that 'ext' actually means - and then to not even bother to tell other clients.
//every other client is expected to have its act together and not fuck up like this.
if ( bres - > client_node & & ( ! ! strstr ( bres - > client_node , " google.com " ) | | ! ! strstr ( bres - > client_node , " android.com " ) ) )
{
for ( ext = bres - > client_ext ; ext ; )
{
ext = JCL_ParseOut ( ext , extname , sizeof ( extname ) ) ;
if ( googlefuckedup )
{
//work around repeated bugs in google's various clients.
if ( ! strcmp ( extname , " voice-v1 " ) )
bres - > buggycaps | = CAP_GOOGLE_VOICE ;
}
}
}
}
# endif
2013-08-21 07:42:42 +00:00
//look for another resource that we might already know about that is the same client+ver and thus has the same caps.
if ( bres - > client_node )
for ( b = jcl - > buddies ; b ; b = b - > next )
{
for ( r = b - > resources ; r ; r = r - > next )
{
if ( r = = bres )
continue ;
//ignore evil clients.
if ( ( r - > caps & CAP_QUERYFAILED ) | | ! r - > client_node )
continue ;
if ( ! strcmp ( r - > client_node , bres - > client_node ) & & ! strcmp ( r - > client_ver , bres - > client_ver ) & & ! strcmp ( r - > client_hash , bres - > client_hash ) & & ! strcmp ( r - > client_ext , bres - > client_ext ) )
{
if ( r - > caps & CAP_QUERIED )
{
bres - > caps = r - > caps ;
// Con_Printf("%s/%s matches (known) %s/%s (%s#%s)\n", buddy->accountdomain, bres->resource, b->accountdomain, r->resource, r->client_node, r->client_ver);
return ;
}
if ( r - > caps & CAP_QUERYING )
{
//we're already asking one client with the same software. don't ask for dupes.
bres - > caps = 0 ;
// Con_Printf("%s/%s matches (pending) %s/%s (%s#%s)\n", buddy->accountdomain, bres->resource, b->accountdomain, r->resource, r->client_node, r->client_ver);
return ;
}
}
}
}
// Con_Printf("%s/%s querying (%s#%s)\n", buddy->accountdomain, bres->resource, bres->client_node, bres->client_ver);
//okay, this is the first time we've seen that software version. ask it what it supports, and hope we get a valid response...
2015-04-27 06:19:33 +00:00
if ( ! bres - > client_node | | ! bres - > client_hash | | ! * bres - > client_hash )
{
//if we cannot cache the result, don't bother asking.
//this saves googletalk bugging out on us.
bres - > caps = CAP_QUERIED ;
}
else
2013-08-21 07:42:42 +00:00
{
2015-04-27 06:19:33 +00:00
bres - > caps = CAP_QUERYING ;
//ask for info about each extension too. which should only be used if the specified version isn't a hash.
if ( bres - > client_hash & & ! * bres - > client_hash )
2013-08-21 07:42:42 +00:00
{
2015-04-27 06:19:33 +00:00
for ( ext = bres - > client_ext ; ext ; )
2013-11-21 23:02:28 +00:00
{
2015-04-27 06:19:33 +00:00
ext = JCL_ParseOut ( ext , extname , sizeof ( extname ) ) ;
if ( * extname )
JCL_SendIQf ( jcl , JCL_ClientDiscoInfo , " get " , va ( " %s/%s " , buddy - > accountdomain , bres - > resource ) , " <query xmlns='http://jabber.org/protocol/disco#info' node='%s#%s'/> " , bres - > client_node , extname ) ;
2013-11-21 23:02:28 +00:00
}
2013-08-21 07:42:42 +00:00
}
2015-04-27 06:19:33 +00:00
JCL_SendIQf ( jcl , JCL_ClientDiscoInfo , " get " , va ( " %s/%s " , buddy - > accountdomain , bres - > resource ) , " <query xmlns='http://jabber.org/protocol/disco#info' node='%s#%s'/> " , bres - > client_node , bres - > client_ver ) ;
2013-08-21 07:42:42 +00:00
}
}
2013-06-29 16:01:07 +00:00
void JCL_ParsePresence ( jclient_t * jcl , xmltree_t * tree )
{
buddy_t * buddy ;
bresource_t * bres ;
2017-10-12 12:02:25 +00:00
const char * from = XML_GetParameter ( tree , " from " , jcl - > domain ) ;
2013-06-29 16:01:07 +00:00
xmltree_t * show = XML_ChildOfTree ( tree , " show " , 0 ) ;
xmltree_t * status = XML_ChildOfTree ( tree , " status " , 0 ) ;
xmltree_t * quake = XML_ChildOfTree ( tree , " quake " , 0 ) ;
2017-10-21 18:08:45 +00:00
//xmltree_t *mucmain = XML_ChildOfTreeNS(tree, "http://jabber.org/protocol/muc", "x", 0);
2017-10-12 12:02:25 +00:00
xmltree_t * mucuser = XML_ChildOfTreeNS ( tree , " http://jabber.org/protocol/muc#user " , " x " , 0 ) ;
2013-08-21 07:42:42 +00:00
xmltree_t * caps = XML_ChildOfTreeNS ( tree , " http://jabber.org/protocol/caps " , " c " , 0 ) ;
2017-10-12 12:02:25 +00:00
const char * type = XML_GetParameter ( tree , " type " , " " ) ;
const char * serverip = NULL ;
const char * servermap = NULL ;
2013-07-13 12:14:32 +00:00
char startconvo [ 512 ] ;
char oldbstatus [ 128 ] ;
char oldfstatus [ 128 ] ;
2013-06-29 16:01:07 +00:00
2017-10-12 12:02:25 +00:00
//should really be using pep for this.
2013-11-21 23:02:28 +00:00
if ( quake & & ! strcmp ( quake - > xmlns , " fteqw.com:game " ) & & ( jcl - > enabledcapabilities & CAP_GAMEINVITE ) )
2013-06-29 16:01:07 +00:00
{
serverip = XML_GetParameter ( quake , " serverip " , NULL ) ;
servermap = XML_GetParameter ( quake , " servermap " , NULL ) ;
}
2015-04-27 06:19:33 +00:00
jclient_updatebuddylist = true ;
2017-10-12 12:02:25 +00:00
if ( type & & ! strcmp ( type , " error " ) )
{
JCL_FindBuddy ( jcl , from , & buddy , & bres , false ) ;
if ( buddy & & bres )
{
xmltree_t * error = XML_ChildOfTree ( tree , " error " , 0 ) ;
if ( error - > child )
{
Q_strlcpy ( bres - > fstatus , error - > child - > name , sizeof ( bres - > fstatus ) ) ;
}
}
}
else if ( type & & ! strcmp ( type , " subscribe " ) )
2013-06-29 16:01:07 +00:00
{
2013-11-21 23:02:28 +00:00
//they want us to let them see us.
2013-07-13 12:14:32 +00:00
char pauth [ 512 ] , pdeny [ 512 ] ;
JCL_GenLink ( jcl , startconvo , sizeof ( startconvo ) , NULL , from , NULL , NULL , " %s " , from ) ;
JCL_GenLink ( jcl , pauth , sizeof ( pauth ) , " pauth " , from , NULL , NULL , " %s " , " Authorize " ) ;
JCL_GenLink ( jcl , pdeny , sizeof ( pdeny ) , " pdeny " , from , NULL , NULL , " %s " , " Deny " ) ;
Con_Printf ( " %s wants to be your friend! %s %s \n " , startconvo , pauth , pdeny ) ;
2013-06-29 16:01:07 +00:00
}
else if ( type & & ! strcmp ( type , " subscribed " ) )
{
2013-11-21 23:02:28 +00:00
//they allowed us to add them.
2013-07-13 12:14:32 +00:00
JCL_GenLink ( jcl , startconvo , sizeof ( startconvo ) , NULL , from , NULL , NULL , " %s " , from ) ;
Con_Printf ( " %s is now your friend! \n " , startconvo ) ;
2013-06-29 16:01:07 +00:00
}
else if ( type & & ! strcmp ( type , " unsubscribe " ) )
{
2013-11-21 23:02:28 +00:00
//they removed us.
2013-07-13 12:14:32 +00:00
JCL_GenLink ( jcl , startconvo , sizeof ( startconvo ) , NULL , from , NULL , NULL , " %s " , from ) ;
Con_Printf ( " %s has unfriended you \n " , startconvo ) ;
2013-06-29 16:01:07 +00:00
}
else if ( type & & ! strcmp ( type , " unsubscribed " ) )
{
2013-11-21 23:02:28 +00:00
//we removed them.
2013-07-13 12:14:32 +00:00
JCL_GenLink ( jcl , startconvo , sizeof ( startconvo ) , NULL , from , NULL , NULL , " %s " , from ) ;
2013-11-21 23:02:28 +00:00
Con_Printf ( " %s is no longer your friend \n " , startconvo ) ;
2013-06-29 16:01:07 +00:00
}
else
{
2013-11-21 23:02:28 +00:00
JCL_FindBuddy ( jcl , from , & buddy , & bres , true ) ;
2013-10-08 14:28:11 +00:00
if ( ! bres )
{
2013-11-21 23:02:28 +00:00
JCL_FindBuddy ( jcl , va ( " %s/ " , from ) , & buddy , & bres , true ) ;
2013-10-08 14:28:11 +00:00
}
2013-07-13 12:14:32 +00:00
JCL_GenLink ( jcl , startconvo , sizeof ( startconvo ) , NULL , from , NULL , NULL , " %s " , buddy - > name ) ;
2013-06-29 16:01:07 +00:00
if ( bres )
{
if ( servermap )
{
bres - > servertype = 2 ;
Q_strlcpy ( bres - > server , servermap , sizeof ( bres - > server ) ) ;
}
else if ( serverip )
{
bres - > servertype = 1 ;
Q_strlcpy ( bres - > server , serverip , sizeof ( bres - > server ) ) ;
}
else
{
bres - > servertype = 0 ;
Q_strlcpy ( bres - > server , " " , sizeof ( bres - > server ) ) ;
}
2013-07-13 12:14:32 +00:00
Q_strlcpy ( oldbstatus , bres - > bstatus , sizeof ( oldbstatus ) ) ;
Q_strlcpy ( oldfstatus , bres - > fstatus , sizeof ( oldfstatus ) ) ;
2013-06-29 16:01:07 +00:00
Q_strlcpy ( bres - > fstatus , ( status & & * status - > body ) ? status - > body : " " , sizeof ( bres - > fstatus ) ) ;
if ( ! tree - > child )
{
Q_strlcpy ( bres - > bstatus , " offline " , sizeof ( bres - > bstatus ) ) ;
bres - > caps = 0 ;
}
else
{
2013-11-21 23:02:28 +00:00
xmltree_t * vcu ;
2017-10-12 12:02:25 +00:00
const char * photohash ;
2013-11-21 23:02:28 +00:00
buddy_t * me ;
vcu = XML_ChildOfTreeNS ( tree , " vcard-temp:x:update " , " x " , 0 ) ;
photohash = XML_GetChildBody ( vcu , " photo " , buddy - > vcardphotohash ) ;
if ( strcmp ( buddy - > vcardphotohash , photohash ) )
{
Con_DPrintf ( " %s changed their photo from \" %s \" to \" %s \" \n " , from , buddy - > vcardphotohash , photohash ) ;
Q_strlcpy ( buddy - > vcardphotohash , photohash , sizeof ( buddy - > vcardphotohash ) ) ;
buddy - > vcardphotochanged = true ;
}
2017-09-20 11:27:13 +00:00
JCL_FindBuddy ( jcl , jcl - > fulljid , & me , NULL , true ) ;
2013-11-21 23:02:28 +00:00
if ( buddy = = me )
{
if ( strcmp ( buddy - > vcardphotohash , jcl - > vcardphotohash ) )
2015-04-27 06:19:33 +00:00
{ //if one of your other resources changed its image, we need to retrieve it so we can tell other clients about it if the other resource goes away
2013-11-21 23:02:28 +00:00
jcl - > vcardphotohashstatus = VCP_UNKNOWN ;
JCL_SendIQf ( jcl , JCL_MyVCardReply , " get " , NULL , " <vCard xmlns='vcard-temp'/> " ) ;
}
}
2013-06-29 16:01:07 +00:00
Q_strlcpy ( bres - > bstatus , ( show & & * show - > body ) ? show - > body : " present " , sizeof ( bres - > bstatus ) ) ;
2013-08-21 07:42:42 +00:00
if ( caps )
2013-06-29 16:01:07 +00:00
{
2017-10-12 12:02:25 +00:00
const char * ext = XML_GetParameter ( caps , " ext " , " " ) ; //deprecated
const char * ver = XML_GetParameter ( caps , " ver " , " " ) ;
const char * node = XML_GetParameter ( caps , " node " , " " ) ;
const char * hash = XML_GetParameter ( caps , " hash " , " " ) ;
2013-08-21 07:42:42 +00:00
if ( ! bres - > client_hash | | strcmp ( ext , bres - > client_ext ) | | strcmp ( hash , bres - > client_hash ) | | strcmp ( node , bres - > client_node ) | | strcmp ( ver , bres - > client_ver ) )
{
bres - > caps & = ~ ( CAP_QUERIED | CAP_QUERYING | CAP_QUERYFAILED ) ; //no idea what the new caps are.
free ( bres - > client_ext ) ;
free ( bres - > client_hash ) ;
free ( bres - > client_node ) ;
free ( bres - > client_ver ) ;
bres - > client_ext = strdup ( ext ) ;
bres - > client_hash = strdup ( hash ) ;
bres - > client_node = strdup ( node ) ;
bres - > client_ver = strdup ( ver ) ;
}
2013-06-29 16:01:07 +00:00
}
2013-08-21 07:42:42 +00:00
JCL_CheckClientCaps ( jcl , buddy , bres ) ;
2013-06-29 16:01:07 +00:00
}
2017-10-12 12:02:25 +00:00
if ( mucuser )
2013-07-13 12:14:32 +00:00
{
2017-10-12 12:02:25 +00:00
//<item affiliation='' jid='' role=''/>
//<status code='xxx'/>
//100=public jids
//101=affiliation changed
//102=shows unavailable members
//103=no longer shows unavailable
//104=room config changed
//110=this is you
//170=room logging enabled
//171=room logging disabled
//172=now annon
//173=now semi-anon
//201=new room created
//210=roomnick changed
//301=you're banned
//303=
//307=you're kicked
//321=removed by affiliation change
//322=not a member
//332=shutdown
2013-07-13 12:14:32 +00:00
JCL_GenLink ( jcl , startconvo , sizeof ( startconvo ) , NULL , from , NULL , NULL , " %s " , bres - > resource ) ;
if ( type & & ! strcmp ( type , " unavailable " ) )
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( buddy - > name , buddy - > name , false , " %s has left the conversation \n " , bres - > resource ) ;
2013-07-13 12:14:32 +00:00
else if ( strcmp ( oldbstatus , bres - > bstatus ) )
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( buddy - > name , buddy - > name , false , " %s is now %s \n " , startconvo , bres - > bstatus ) ;
2013-07-13 12:14:32 +00:00
}
2013-06-29 16:01:07 +00:00
else
2013-07-13 12:14:32 +00:00
{
2015-04-27 06:19:33 +00:00
char * conv = buddy - > accountdomain ;
char * title = buddy - > name ;
//if we're not currently talking with them, put the status update into the main console instead (which will probably then get dropped).
2019-09-04 07:59:40 +00:00
if ( ! confuncs | | confuncs - > GetConsoleFloat ( conv , " iswindow " ) ! = true )
2015-04-27 06:19:33 +00:00
conv = " " ;
2013-07-13 12:14:32 +00:00
if ( bres - > servertype = = 2 )
{
char joinlink [ 512 ] ;
JCL_GenLink ( jcl , joinlink , sizeof ( joinlink ) , " join " , from , NULL , NULL , " Playing Quake - %s " , bres - > server ) ;
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( conv , title , false , " %s is now %s \n " , startconvo , joinlink ) ;
2013-07-13 12:14:32 +00:00
}
else if ( bres - > servertype = = 1 )
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( conv , title , false , " %s is now ^[[Playing Quake - %s] \\ observe \\ %s^] \n " , startconvo , bres - > server , bres - > server ) ;
else if ( ( cvarfuncs - > GetFloat ( " xmpp_showstatusupdates " ) | | * conv ) & & ( strcmp ( oldbstatus , bres - > bstatus ) | | strcmp ( oldfstatus , bres - > fstatus ) ) )
2013-07-13 12:14:32 +00:00
{
if ( * bres - > fstatus )
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( conv , title , false , " %s is now %s: %s \n " , startconvo , bres - > bstatus , bres - > fstatus ) ;
2013-07-13 12:14:32 +00:00
else
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( conv , title , false , " %s is now %s \n " , startconvo , bres - > bstatus ) ;
2013-07-13 12:14:32 +00:00
}
}
2013-06-29 16:01:07 +00:00
2013-07-13 12:14:32 +00:00
if ( type & & ! strcmp ( type , " unavailable " ) )
2013-06-29 16:01:07 +00:00
{
//remove this buddy resource
}
}
else
{
Con_Printf ( " Weird presence: \n " ) ;
2013-11-21 23:02:28 +00:00
XML_ConPrintTree ( tree , " " , 0 ) ;
2013-06-29 16:01:07 +00:00
}
}
}
# define JCL_DONE 0 //no more data available for now.
# define JCL_CONTINUE 1 //more data needs parsing.
# define JCL_KILL 2 //some error, needs reconnecting.
# define JCL_NUKEFROMORBIT 3 //permanent error (or logged on from elsewhere)
2015-04-27 06:19:33 +00:00
int JCL_ClientFrame ( jclient_t * jcl , char * * error )
2013-06-29 16:01:07 +00:00
{
int pos ;
xmltree_t * tree , * ot ;
int ret ;
qboolean unparsable ;
2019-09-04 07:59:40 +00:00
ret = netfuncs - > Recv ( jcl - > socket , jcl - > bufferedinmessage + jcl - > bufferedinammount , sizeof ( jcl - > bufferedinmessage ) - 1 - jcl - > bufferedinammount ) ;
2013-06-29 16:01:07 +00:00
if ( ret = = 0 )
{
if ( ! jcl - > bufferedinammount ) //if we are half way through a message, read any possible conjunctions.
return JCL_DONE ; //nothing more this frame
}
if ( ret < 0 )
{
2015-04-27 06:19:33 +00:00
* error = " Socket Error " ;
2013-11-21 23:02:28 +00:00
if ( jcl - > socket ! = - 1 )
2019-09-04 07:59:40 +00:00
netfuncs - > Close ( jcl - > socket ) ;
2013-11-21 23:02:28 +00:00
jcl - > socket = - 1 ;
2013-06-29 16:01:07 +00:00
return JCL_KILL ;
}
if ( ret > 0 )
{
jcl - > bufferedinammount + = ret ;
jcl - > bufferedinmessage [ jcl - > bufferedinammount ] = 0 ;
}
//we never end parsing in the middle of a < >
//this means we can filter out the <? ?>, <!-- --> and < /> stuff properly
for ( pos = jcl - > instreampos ; pos < jcl - > bufferedinammount ; pos + + )
{
if ( jcl - > bufferedinmessage [ pos ] = = ' < ' )
{
jcl - > instreampos = pos ;
}
else if ( jcl - > bufferedinmessage [ pos ] = = ' > ' )
{
if ( pos < 1 )
break ; //erm...
2017-06-21 01:24:25 +00:00
/* if (jcl->bufferedinmessage[pos-1] != '/') //<blah/> is a tag without a body
2013-06-29 16:01:07 +00:00
{
if ( jcl - > bufferedinmessage [ jcl - > instreampos + 1 ] ! = ' ? ' ) //<? blah ?> is a tag without a body
{
if ( jcl - > bufferedinmessage [ pos - 1 ] ! = ' ? ' )
{
if ( jcl - > bufferedinmessage [ jcl - > instreampos + 1 ] = = ' / ' ) //</blah> is the end of a tag with a body
jcl - > tagdepth - - ;
else
jcl - > tagdepth + + ; //<blah> is the start of a tag with a body
}
}
}
2017-06-21 01:24:25 +00:00
*/
2013-06-29 16:01:07 +00:00
jcl - > instreampos = pos + 1 ;
}
}
2017-06-21 01:24:25 +00:00
pos = 0 ;
while ( jcl - > connecting )
2013-06-29 16:01:07 +00:00
{ //first bit of info
tree = XML_Parse ( jcl - > bufferedinmessage , & pos , jcl - > instreampos , true , " " ) ;
2017-06-21 01:24:25 +00:00
if ( tree & & ! strcmp ( tree - > name , " ?xml " ) )
2013-06-29 16:01:07 +00:00
{
XML_Destroy ( tree ) ;
2017-06-21 01:24:25 +00:00
continue ;
2013-06-29 16:01:07 +00:00
}
2013-11-21 23:02:28 +00:00
if ( jcl - > streamdebug = = 2 )
2013-06-29 16:01:07 +00:00
{
char t = jcl - > bufferedinmessage [ pos ] ;
jcl - > bufferedinmessage [ pos ] = 0 ;
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( " xmppin " , " xmppin " , false , " %s " , jcl - > bufferedinmessage ) ;
2013-06-29 16:01:07 +00:00
if ( tree )
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( " xmppin " , " xmppin " , false , " \n " ) ;
2013-06-29 16:01:07 +00:00
jcl - > bufferedinmessage [ pos ] = t ;
}
if ( ! tree )
{
2015-04-27 06:19:33 +00:00
* error = " Not an xml stream " ;
2013-06-29 16:01:07 +00:00
return JCL_KILL ;
}
if ( strcmp ( tree - > name , " stream " ) | | strcmp ( tree - > xmlns , " http://etherx.jabber.org/streams " ) )
{
2015-04-27 06:19:33 +00:00
* error = " Not an xmpp stream " ;
2013-06-29 16:01:07 +00:00
return JCL_KILL ;
}
Q_strlcpy ( jcl - > defaultnamespace , tree - > xmlns_dflt , sizeof ( jcl - > defaultnamespace ) ) ;
ot = tree ;
tree = tree - > child ;
ot - > child = NULL ;
// Con_Printf("Discard\n");
// XML_ConPrintTree(ot, 0);
XML_Destroy ( ot ) ;
2017-06-21 01:24:25 +00:00
jcl - > connecting = false ;
2013-06-29 16:01:07 +00:00
}
2017-06-21 01:24:25 +00:00
/* if (jcl->tagdepth != 1)
2013-06-29 16:01:07 +00:00
{
2017-06-21 01:24:25 +00:00
if ( jcl - > tagdepth < 1 & & jcl - > bufferedinammount = = jcl - > instreampos )
2013-06-29 16:01:07 +00:00
{
2017-06-21 01:24:25 +00:00
* error = " End of XML stream " ;
return JCL_KILL ;
2005-12-11 20:11:22 +00:00
}
2017-06-21 01:24:25 +00:00
return JCL_DONE ;
}
*/
tree = XML_Parse ( jcl - > bufferedinmessage , & pos , jcl - > instreampos , false , jcl - > defaultnamespace ) ;
2005-12-11 20:11:22 +00:00
2017-06-21 01:24:25 +00:00
if ( jcl - > streamdebug = = 2 & & tree )
{
char t = jcl - > bufferedinmessage [ pos ] ;
jcl - > bufferedinmessage [ pos ] = 0 ;
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( " xmppin " , " xmppin " , false , " %s " , jcl - > bufferedinmessage ) ;
XMPP_ConversationPrintf ( " xmppin " , " xmppin " , false , " \n " ) ;
2017-06-21 01:24:25 +00:00
jcl - > bufferedinmessage [ pos ] = t ;
}
2005-12-11 20:11:22 +00:00
2017-06-21 01:24:25 +00:00
if ( ! tree )
{
//make sure any prior crap is flushed.
memmove ( jcl - > bufferedinmessage , jcl - > bufferedinmessage + pos , jcl - > bufferedinammount - pos ) ;
jcl - > bufferedinammount - = pos ;
jcl - > instreampos - = pos ;
pos = 0 ;
2013-06-23 02:33:52 +00:00
2005-12-11 20:11:22 +00:00
// Con_Printf("No input tree: %s", jcl->bufferedinmessage);
2017-06-21 01:24:25 +00:00
return JCL_DONE ;
2005-12-11 20:11:22 +00:00
}
2013-03-31 04:21:08 +00:00
// Con_Printf("read\n");
// XML_ConPrintTree(tree, 0);
2005-12-11 20:11:22 +00:00
2013-11-21 23:02:28 +00:00
if ( jcl - > streamdebug = = 1 )
2015-04-27 06:19:33 +00:00
{
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( " xmppin " , " xmppin " , false , " " ) ;
2013-11-21 23:02:28 +00:00
XML_ConPrintTree ( tree , " xmppin " , 0 ) ;
2015-04-27 06:19:33 +00:00
}
2013-11-21 23:02:28 +00:00
2013-06-29 16:01:07 +00:00
jcl - > timeout = jclient_curtime + 60 * 1000 ;
2005-12-11 20:11:22 +00:00
unparsable = true ;
2013-03-31 04:21:08 +00:00
if ( ! strcmp ( tree - > name , " features " ) )
2005-12-11 20:11:22 +00:00
{
2021-08-05 16:49:25 +00:00
if ( Q_snprintfz ( jcl - > barejid , sizeof ( jcl - > barejid ) , " %s@%s " , jcl - > username , jcl - > domain ) | |
Q_snprintfz ( jcl - > fulljid , sizeof ( jcl - > fulljid ) , " %s@%s/%s " , jcl - > username , jcl - > domain , jcl - > resource ) )
2019-09-04 07:59:40 +00:00
{
XML_Destroy ( tree ) ;
return JCL_KILL ;
}
2005-12-11 20:11:22 +00:00
if ( ( ot = XML_ChildOfTree ( tree , " bind " , 0 ) ) )
{
unparsable = false ;
2013-06-23 02:33:52 +00:00
JCL_SendIQf ( jcl , JCL_BindReply , " set " , NULL , " <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>%s</resource></bind> " , jcl - > resource ) ;
2005-12-11 20:11:22 +00:00
}
if ( ( ot = XML_ChildOfTree ( tree , " session " , 0 ) ) )
{
unparsable = false ;
2013-06-23 02:33:52 +00:00
JCL_SendIQf ( jcl , JCL_SessionReply , " set " , NULL , " <session xmlns='urn:ietf:params:xml:ns:xmpp-session'/> " ) ;
2013-03-31 04:21:08 +00:00
jcl - > connected = true ;
2013-06-23 02:33:52 +00:00
JCL_WriteConfig ( ) ;
2005-12-11 20:11:22 +00:00
}
if ( unparsable )
{
2019-09-04 07:59:40 +00:00
if ( ( ! jcl - > issecure ) & & XML_ChildOfTree ( tree , " starttls " , 0 ) ! = NULL & & jcl - > forcetls > = 0 )
2005-12-11 20:11:22 +00:00
{
2013-08-21 07:42:42 +00:00
Con_DPrintf ( " XMPP: Attempting to switch to TLS \n " ) ;
2005-12-11 20:11:22 +00:00
JCL_AddClientMessageString ( jcl , " <starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls' /> " ) ;
unparsable = false ;
}
else if ( ( ot = XML_ChildOfTree ( tree , " mechanisms " , 0 ) ) )
{
2013-07-13 12:14:32 +00:00
xmltree_t * m ;
int sm ;
char out [ 512 ] ;
char * method = NULL ;
int outlen = - 1 ;
2013-10-29 17:38:22 +00:00
qboolean needpass = false ;
2013-07-13 12:14:32 +00:00
if ( jcl - > forcetls > 0 & & ! jcl - > issecure )
2005-12-11 20:11:22 +00:00
{
2019-09-04 07:59:40 +00:00
* error = " Unable to switch to TLS. You are probably being man-in-the-middle attacked. " ;
XML_ConPrintTree ( tree , " " , 0 ) ;
2013-07-13 12:14:32 +00:00
XML_Destroy ( tree ) ;
2013-10-08 14:28:11 +00:00
return JCL_KILL ;
2013-06-24 09:04:00 +00:00
}
2017-09-20 11:27:13 +00:00
//init some sasl fields from the jcl state.
jcl - > sasl . username = jcl - > username ; //auth user name
jcl - > sasl . domain = jcl - > domain ; //auth domain
jcl - > sasl . issecure = jcl - > issecure ; //says that its connected over tls, and that sock is the tls connection.
jcl - > sasl . socket = jcl - > socket ; //just for channel bindings
jcl - > sasl . authmethod = NULL ; //unknown at this point
//attempt to use a method based on the ones that we prefer.
2013-07-13 12:14:32 +00:00
for ( sm = 0 ; sm < sizeof ( saslmethods ) / sizeof ( saslmethods [ 0 ] ) ; sm + + )
2013-06-24 09:04:00 +00:00
{
2017-09-20 11:27:13 +00:00
method = saslmethods [ sm ] . method ? saslmethods [ sm ] . method : jcl - > sasl . oauth2 . saslmethod ;
2013-07-13 12:14:32 +00:00
if ( ! * method )
continue ;
for ( m = ot - > child ; m ; m = m - > sibling )
{
if ( ! strcmp ( m - > body , method ) )
{
2017-09-20 11:27:13 +00:00
outlen = saslmethods [ sm ] . sasl_initial ( & jcl - > sasl , out , sizeof ( out ) ) ;
2013-10-29 17:38:22 +00:00
if ( outlen > = 0 )
2017-09-20 11:27:13 +00:00
{
jcl - > sasl . authmethod = & saslmethods [ sm ] ;
2013-07-13 12:14:32 +00:00
break ;
2017-09-20 11:27:13 +00:00
}
2013-10-29 17:38:22 +00:00
if ( outlen = = - 2 )
needpass = true ;
2013-07-13 12:14:32 +00:00
}
}
2013-10-29 17:38:22 +00:00
if ( outlen > = 0 )
2013-07-13 12:14:32 +00:00
break ;
2013-06-24 09:04:00 +00:00
}
2013-07-13 12:14:32 +00:00
2017-09-20 11:27:13 +00:00
if ( outlen < 0 | | ! jcl - > sasl . authmethod )
2013-07-13 12:14:32 +00:00
{
XML_Destroy ( tree ) ;
2013-10-29 17:38:22 +00:00
//can't authenticate for some reason
if ( needpass )
XMPP_Menu_Password ( jcl ) ;
2015-04-27 06:19:33 +00:00
* error = " Password needed " ;
2013-10-29 17:38:22 +00:00
return JCL_NUKEFROMORBIT ;
2013-07-13 12:14:32 +00:00
}
if ( outlen > = 0 )
2013-06-24 09:04:00 +00:00
{
2013-07-13 12:14:32 +00:00
Base64_Add ( out , outlen ) ;
2013-06-24 09:04:00 +00:00
Base64_Finish ( ) ;
2013-07-13 12:14:32 +00:00
2013-08-21 07:42:42 +00:00
Con_DPrintf ( " XMPP: Authing with %s%s. \n " , method , jcl - > issecure ? " over tls " : " without encription " ) ;
2013-07-13 12:14:32 +00:00
JCL_AddClientMessagef ( jcl , " <auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='%s' "
2017-09-20 11:27:13 +00:00
" auth:service='oauth2' "
2013-07-13 12:14:32 +00:00
" xmlns:auth='http://www.google.com/talk/protocol/auth' "
" >%s</auth> " , method , base64 ) ;
2013-06-24 09:04:00 +00:00
unparsable = false ;
2005-12-11 20:11:22 +00:00
}
2013-06-24 09:04:00 +00:00
else
2005-12-11 20:11:22 +00:00
{
2015-04-27 06:19:33 +00:00
* error = " No suitable auth methods " ;
2013-11-21 23:02:28 +00:00
XML_ConPrintTree ( tree , " " , 0 ) ;
2013-06-24 09:04:00 +00:00
XML_Destroy ( tree ) ;
2013-10-08 14:28:11 +00:00
return JCL_KILL ;
2005-12-11 20:11:22 +00:00
}
}
else //we cannot auth, no suitable method.
{
2015-04-27 06:19:33 +00:00
* error = " Neither SASL or TLS are usable " ;
2013-06-24 09:04:00 +00:00
XML_Destroy ( tree ) ;
2013-10-08 14:28:11 +00:00
return JCL_KILL ;
2005-12-11 20:11:22 +00:00
}
}
}
2017-09-20 11:27:13 +00:00
else if ( ! strcmp ( tree - > name , " challenge " ) & & ! strcmp ( tree - > xmlns , " urn:ietf:params:xml:ns:xmpp-sasl " ) & & jcl - > sasl . authmethod )
2013-07-13 12:14:32 +00:00
{
char in [ 512 ] ;
int inlen ;
char out [ 512 ] ;
int outlen ;
inlen = Base64_Decode ( in , sizeof ( in ) , tree - > body , strlen ( tree - > body ) ) ;
2017-09-20 11:27:13 +00:00
outlen = jcl - > sasl . authmethod - > sasl_challenge ( & jcl - > sasl , in , inlen , out , sizeof ( out ) ) ;
2013-07-13 12:14:32 +00:00
if ( outlen < 0 )
{
2015-04-27 06:19:33 +00:00
* error = " Unable to auth with server " ;
2013-07-13 12:14:32 +00:00
XML_Destroy ( tree ) ;
return JCL_KILL ;
}
Base64_Add ( out , outlen ) ;
2013-06-24 09:04:00 +00:00
Base64_Finish ( ) ;
JCL_AddClientMessagef ( jcl , " <response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>%s</response> " , base64 ) ;
2013-07-13 12:14:32 +00:00
unparsable = false ;
2013-06-24 09:04:00 +00:00
}
2005-12-11 20:11:22 +00:00
else if ( ! strcmp ( tree - > name , " proceed " ) )
{
//switch to TLS, if we can
//Restart everything, basically.
jcl - > bufferedinammount = 0 ;
jcl - > instreampos = 0 ;
2013-07-13 12:14:32 +00:00
//when using srv records, the certificate must match the user's domain, rather than merely the hostname of the server.
//if you want to match the hostname of the server, use (oldstyle) tlsconnect directly instead.
2019-09-04 07:59:40 +00:00
if ( netfuncs - > SetTLSClient ( jcl - > socket , jcl - > certificatedomain ) < 0 )
2005-12-11 20:11:22 +00:00
{
2015-04-27 06:19:33 +00:00
* error = " failed to switch to TLS " ;
2013-03-31 04:21:08 +00:00
XML_Destroy ( tree ) ;
2005-12-11 20:11:22 +00:00
return JCL_KILL ;
}
2013-07-13 12:14:32 +00:00
if ( ! * jcl - > certificatedomain )
Con_Printf ( " XMPP: WARNING: Connecting via TLS without validating certificate \n " ) ;
jcl - > issecure = true ;
2005-12-11 20:11:22 +00:00
2017-06-21 01:24:25 +00:00
jcl - > connecting = true ;
2005-12-11 20:11:22 +00:00
JCL_AddClientMessageString ( jcl ,
" <?xml version='1.0' ?> "
" <stream:stream to=' " ) ;
JCL_AddClientMessageString ( jcl , jcl - > domain ) ;
JCL_AddClientMessageString ( jcl , " ' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'> " ) ;
2013-03-31 04:21:08 +00:00
XML_Destroy ( tree ) ;
2005-12-11 20:11:22 +00:00
return JCL_DONE ;
}
else if ( ! strcmp ( tree - > name , " failure " ) )
{
if ( tree - > child )
2015-04-27 06:19:33 +00:00
* error = va ( " Failure: %s \n " , tree - > child - > name ) ;
2005-12-11 20:11:22 +00:00
else
2015-04-27 06:19:33 +00:00
* error = " Unknown failure " ;
2013-03-31 04:21:08 +00:00
XML_Destroy ( tree ) ;
2005-12-11 20:11:22 +00:00
return JCL_KILL ;
}
2013-06-29 16:01:07 +00:00
else if ( ! strcmp ( tree - > name , " error " ) )
{
2013-11-21 23:02:28 +00:00
xmltree_t * condition ;
condition = XML_ChildOfTree ( tree , " success " , 0 ) ;
if ( ! condition )
condition = XML_ChildOfTree ( tree , " see-other-host " , 0 ) ;
if ( ! condition )
condition = XML_ChildOfTree ( tree , " invalid-xml " , 0 ) ;
if ( condition & & ! strcmp ( condition - > name , " see-other-host " ) )
2013-07-13 12:14:32 +00:00
{
//msn needs this, apparently
2013-11-21 23:02:28 +00:00
Q_strlcpy ( jcl - > redirserveraddr , condition - > body , sizeof ( jcl - > redirserveraddr ) ) ;
2015-04-27 06:19:33 +00:00
JCL_CloseConnection ( jcl , " Redirecting " , true ) ;
2013-07-13 12:14:32 +00:00
if ( ! JCL_Reconnect ( jcl ) )
2015-04-27 06:19:33 +00:00
{
* error = " Unable to redirect " ;
2013-07-13 12:14:32 +00:00
return JCL_KILL ;
2015-04-27 06:19:33 +00:00
}
2013-07-13 12:14:32 +00:00
return JCL_CONTINUE ;
}
2013-11-21 23:02:28 +00:00
else if ( condition & & ! strcmp ( condition - > name , " success " ) )
{
2015-04-27 06:19:33 +00:00
* error = " error: success " ;
2013-11-21 23:02:28 +00:00
unparsable = false ;
}
2013-06-29 16:01:07 +00:00
else
2013-07-13 12:14:32 +00:00
{
ot = XML_ChildOfTree ( tree , " text " , 0 ) ;
if ( ot )
2015-04-27 06:19:33 +00:00
* error = va ( " error: %s " , ot - > body ) ;
2013-11-21 23:02:28 +00:00
else if ( condition )
2015-04-27 06:19:33 +00:00
* error = va ( " error: %s " , condition - > name ) ;
2013-07-13 12:14:32 +00:00
else
2015-04-27 06:19:33 +00:00
* error = " Unknown error " ;
2013-06-29 16:01:07 +00:00
2013-07-13 12:14:32 +00:00
ot = XML_ChildOfTree ( tree , " conflict " , 0 ) ;
XML_Destroy ( tree ) ;
2013-06-29 16:01:07 +00:00
2013-07-13 12:14:32 +00:00
if ( ot )
return JCL_NUKEFROMORBIT ;
else
return JCL_KILL ;
}
2013-06-29 16:01:07 +00:00
}
2017-09-20 11:27:13 +00:00
else if ( ! strcmp ( tree - > name , " success " ) & & ! strcmp ( tree - > xmlns , " urn:ietf:params:xml:ns:xmpp-sasl " ) )
2005-12-11 20:11:22 +00:00
{
2017-09-20 11:27:13 +00:00
if ( ! jcl - > sasl . authmethod | | jcl - > sasl . authmethod - > sasl_success )
{
char in [ 512 ] ;
int inlen ;
inlen = Base64_Decode ( in , sizeof ( in ) , tree - > body , strlen ( tree - > body ) ) ;
if ( ! jcl - > sasl . authmethod | | jcl - > sasl . authmethod - > sasl_success ( & jcl - > sasl , in , inlen ) < 0 )
{
* error = " Server validation failed " ;
XML_Destroy ( tree ) ;
return JCL_KILL ;
}
}
2005-12-11 20:11:22 +00:00
//Restart everything, basically, AGAIN! (third time lucky?)
jcl - > bufferedinammount = 0 ;
jcl - > instreampos = 0 ;
2017-06-21 01:24:25 +00:00
jcl - > connecting = true ;
2005-12-11 20:11:22 +00:00
JCL_AddClientMessageString ( jcl ,
" <?xml version='1.0' ?> "
" <stream:stream to=' " ) ;
JCL_AddClientMessageString ( jcl , jcl - > domain ) ;
JCL_AddClientMessageString ( jcl , " ' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'> " ) ;
return JCL_DONE ;
}
else if ( ! strcmp ( tree - > name , " iq " ) )
{
2013-06-29 16:01:07 +00:00
JCL_ParseIQ ( jcl , tree ) ;
unparsable = false ;
2005-12-11 20:11:22 +00:00
}
else if ( ! strcmp ( tree - > name , " message " ) )
{
2013-06-29 16:01:07 +00:00
JCL_ParseMessage ( jcl , tree ) ;
unparsable = false ;
2005-12-11 20:11:22 +00:00
}
else if ( ! strcmp ( tree - > name , " presence " ) )
{
2013-06-29 16:01:07 +00:00
JCL_ParsePresence ( jcl , tree ) ;
2005-12-11 20:11:22 +00:00
//we should keep a list of the people that we know of.
unparsable = false ;
}
else
2013-06-23 02:33:52 +00:00
{
2005-12-11 20:11:22 +00:00
Con_Printf ( " JCL unrecognised stanza: %s \n " , tree - > name ) ;
2013-11-21 23:02:28 +00:00
XML_ConPrintTree ( tree , " " , 0 ) ;
2013-06-23 02:33:52 +00:00
}
2005-12-11 20:11:22 +00:00
memmove ( jcl - > bufferedinmessage , jcl - > bufferedinmessage + pos , jcl - > bufferedinammount - pos ) ;
jcl - > bufferedinammount - = pos ;
jcl - > instreampos - = pos ;
if ( unparsable )
{
2015-04-27 06:19:33 +00:00
* error = " Input corrupt, urecognised, or unusable. " ;
2013-11-21 23:02:28 +00:00
XML_ConPrintTree ( tree , " " , 0 ) ;
2013-07-13 12:14:32 +00:00
XML_Destroy ( tree ) ;
2005-12-11 20:11:22 +00:00
return JCL_KILL ;
}
2013-07-13 12:14:32 +00:00
XML_Destroy ( tree ) ;
2005-12-11 20:11:22 +00:00
return JCL_CONTINUE ;
}
2015-04-27 06:19:33 +00:00
void JCL_CloseConnection ( jclient_t * jcl , const char * reason , qboolean reconnect )
2005-12-11 20:11:22 +00:00
{
2013-06-29 16:01:07 +00:00
//send our signoff to the server, if we're still alive.
2013-07-13 12:14:32 +00:00
if ( jcl - > status ! = JCL_DEAD & & jcl - > status ! = JCL_INACTIVE )
Con_Printf ( " XMPP: Disconnected from %s@%s \n " , jcl - > username , jcl - > domain ) ;
2013-06-29 16:01:07 +00:00
if ( jcl - > status = = JCL_ACTIVE )
JCL_AddClientMessageString ( jcl , " <presence type='unavailable'/> " ) ;
2013-07-13 12:14:32 +00:00
if ( jcl - > status ! = JCL_DEAD & & jcl - > status ! = JCL_INACTIVE )
JCL_AddClientMessageString ( jcl , " </stream:stream> " ) ;
2013-06-29 16:01:07 +00:00
JCL_FlushOutgoing ( jcl ) ;
//forget all our friends.
JCL_ForgetBuddy ( jcl , NULL , NULL ) ;
//destroy any data that never got sent
free ( jcl - > outbuf ) ;
jcl - > outbuf = NULL ;
jcl - > outbuflen = 0 ;
jcl - > outbufpos = 0 ;
jcl - > outbufmax = 0 ;
2013-07-13 12:14:32 +00:00
if ( jcl - > socket ! = - 1 )
2019-09-04 07:59:40 +00:00
netfuncs - > Close ( jcl - > socket ) ;
2013-06-29 16:01:07 +00:00
jcl - > socket = - 1 ;
jcl - > status = JCL_DEAD ;
2015-04-27 06:19:33 +00:00
Q_strncpyz ( jcl - > errormsg , reason , sizeof ( jcl - > errormsg ) ) ;
2013-06-29 16:01:07 +00:00
jcl - > timeout = jclient_curtime + 30 * 1000 ; //wait 30 secs before reconnecting, to avoid flood-prot-protection issues.
if ( ! reconnect )
{
2013-07-13 12:14:32 +00:00
int i ;
2013-06-29 16:01:07 +00:00
free ( jcl ) ;
2013-07-13 12:14:32 +00:00
for ( i = 0 ; i < sizeof ( jclients ) / sizeof ( jclients [ 0 ] ) ; i + + )
{
if ( jclients [ i ] = = jcl )
2021-06-21 13:36:30 +00:00
{
2013-07-13 12:14:32 +00:00
jclients [ i ] = NULL ;
2021-06-21 13:36:30 +00:00
jclient_configdirty = true ;
}
2013-07-13 12:14:32 +00:00
}
2013-06-29 16:01:07 +00:00
}
2015-04-27 06:19:33 +00:00
jclient_updatebuddylist = true ;
2005-12-11 20:11:22 +00:00
}
2013-06-23 02:33:52 +00:00
//can be polled for server address updates
2013-06-29 16:01:07 +00:00
void JCL_GeneratePresence ( jclient_t * jcl , qboolean force )
2013-06-23 02:33:52 +00:00
{
int dummystat ;
char serveraddr [ 1024 * 16 ] ;
char servermap [ 1024 * 16 ] ;
//get the last server address
serveraddr [ 0 ] = 0 ;
servermap [ 0 ] = 0 ;
2019-09-04 07:59:40 +00:00
if ( ! cvarfuncs - > GetFloat ( " xmpp_nostatus " ) )
2013-06-23 02:33:52 +00:00
{
2019-09-04 07:59:40 +00:00
if ( cvarfuncs - > GetFloat ( " sv.state " ) )
2013-06-23 02:33:52 +00:00
{
2019-09-04 07:59:40 +00:00
cvarfuncs - > GetString ( " sv.mapname " , servermap , sizeof ( servermap ) ) ;
2013-06-23 02:33:52 +00:00
}
else
{
2019-09-04 07:59:40 +00:00
if ( ! cvarfuncs - > GetString ( " cl_serveraddress " , serveraddr , sizeof ( serveraddr ) ) )
2013-06-23 02:33:52 +00:00
serveraddr [ 0 ] = 0 ;
2019-09-04 07:59:40 +00:00
if ( clientfuncs )
2013-06-23 02:33:52 +00:00
{
//if we can't get any stats, its because we're not actually on the server.
2019-09-04 07:59:40 +00:00
if ( ! clientfuncs - > GetStats ( 0 , & dummystat , 1 ) )
2013-06-23 02:33:52 +00:00
serveraddr [ 0 ] = 0 ;
}
}
}
2013-11-21 23:02:28 +00:00
if ( force | | jcl - > vcardphotohashchanged | | strcmp ( jcl - > curquakeserver , * servermap ? servermap : serveraddr ) )
2013-06-23 02:33:52 +00:00
{
2015-04-27 06:19:33 +00:00
char * prior = " <priority>24</priority> " ;
2013-11-21 23:02:28 +00:00
char caps [ 512 ] ;
jcl - > vcardphotohashchanged = false ;
2013-06-29 16:01:07 +00:00
Q_strlcpy ( jcl - > curquakeserver , * servermap ? servermap : serveraddr , sizeof ( jcl - > curquakeserver ) ) ;
Con_DPrintf ( " Sending presence %s \n " , jcl - > curquakeserver ) ;
2013-08-21 07:42:42 +00:00
2013-11-21 23:02:28 +00:00
buildcapsvcardpresence ( jcl , caps , sizeof ( caps ) ) ;
2013-06-23 02:33:52 +00:00
2013-06-29 16:01:07 +00:00
if ( ! * jcl - > curquakeserver )
JCL_AddClientMessagef ( jcl ,
2017-09-20 11:27:13 +00:00
" <presence from='%s'> "
2017-10-12 12:02:25 +00:00
" %+s "
" %+s "
2017-09-20 11:27:13 +00:00
" </presence> " , jcl - > fulljid , prior , caps ) ;
2013-06-23 02:33:52 +00:00
else if ( * servermap ) //if we're running a server, say so
2013-06-29 16:01:07 +00:00
JCL_AddClientMessagef ( jcl ,
2017-09-20 11:27:13 +00:00
" <presence from='%s'> "
2017-10-12 12:02:25 +00:00
" %+s "
2013-06-23 02:33:52 +00:00
" <quake xmlns='fteqw.com:game' servermap='%s'/> "
2017-10-12 12:02:25 +00:00
" %+s "
2013-06-23 02:33:52 +00:00
" </presence> "
2017-09-20 11:27:13 +00:00
, jcl - > fulljid , prior , servermap , caps ) ;
2013-06-23 02:33:52 +00:00
else //if we're connected to a server, say so
2013-06-29 16:01:07 +00:00
JCL_AddClientMessagef ( jcl ,
2017-09-20 11:27:13 +00:00
" <presence from='%s'> "
2017-10-12 12:02:25 +00:00
" %+s "
2013-06-23 02:33:52 +00:00
" <quake xmlns='fteqw.com:game' serverip='%s' /> "
2017-10-12 12:02:25 +00:00
" %+s "
2013-06-23 02:33:52 +00:00
" </presence> "
2017-09-20 11:27:13 +00:00
, jcl - > fulljid , prior , jcl - > curquakeserver , caps ) ;
2013-06-23 02:33:52 +00:00
}
}
2015-04-27 06:19:33 +00:00
static void JCL_PrintBuddyStatus ( char * console , jclient_t * jcl , buddy_t * b , bresource_t * r )
{
if ( r - > servertype = = 2 )
{
char joinlink [ 512 ] ;
JCL_GenLink ( jcl , joinlink , sizeof ( joinlink ) , " join " , b - > accountdomain , r - > resource , NULL , " Playing Quake - %s " , r - > server ) ;
Con_SubPrintf ( console , " %s " , joinlink ) ;
}
else if ( r - > servertype )
Con_SubPrintf ( console , " ^[[Playing Quake - %s] \\ observe \\ %s^] " , r - > server , r - > server ) ;
else if ( * r - > fstatus )
Con_SubPrintf ( console , " %s - %s " , r - > bstatus , r - > fstatus ) ;
else
Con_SubPrintf ( console , " %s " , r - > bstatus ) ;
if ( ( r - > caps & CAP_GAMEINVITE ) & & ! r - > servertype )
{
char invitelink [ 512 ] ;
JCL_GenLink ( jcl , invitelink , sizeof ( invitelink ) , " invite " , b - > accountdomain , r - > resource , NULL , " %s " , " Invite " ) ;
Con_SubPrintf ( console , " %s " , invitelink ) ;
}
if ( r - > caps & CAP_VOICE )
{
char calllink [ 512 ] ;
JCL_GenLink ( jcl , calllink , sizeof ( calllink ) , " call " , b - > accountdomain , r - > resource , NULL , " %s " , " Call " ) ;
Con_SubPrintf ( console , " %s " , calllink ) ;
}
else if ( ( r - > caps | r - > buggycaps ) & CAP_GOOGLE_VOICE )
{
char calllink [ 512 ] ;
JCL_GenLink ( jcl , calllink , sizeof ( calllink ) , " call " , b - > accountdomain , r - > resource , NULL , " %s " , " Call " ) ;
Con_SubPrintf ( console , " %s " , calllink ) ;
}
}
static void JCL_RegenerateBuddyList ( qboolean force )
{
const char * console = BUDDYLISTTITLE ;
jclient_t * jcl ;
buddy_t * b , * me ;
bresource_t * r ;
int i , j ;
char convolink [ 512 ] ;
2017-10-12 12:02:25 +00:00
struct c2c_s * c2c ;
2015-04-27 06:19:33 +00:00
buddy_t * sortlist [ 256 ] ;
int buds ;
jclient_updatebuddylist = false ;
2019-09-04 07:59:40 +00:00
if ( ! confuncs )
2015-04-27 06:19:33 +00:00
return ;
//only redraw the window if it actually exists. if they closed it, then don't mess things up.
2019-09-04 07:59:40 +00:00
if ( ! force & & confuncs - > GetConsoleFloat ( console , " iswindow " ) < = 0 )
2015-04-27 06:19:33 +00:00
return ;
2019-09-04 07:59:40 +00:00
if ( confuncs - > GetConsoleFloat ( console , " iswindow " ) ! = true )
2015-04-27 06:19:33 +00:00
{
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleFloat ( console , " iswindow " , true ) ;
confuncs - > SetConsoleFloat ( console , " forceutf8 " , true ) ;
confuncs - > SetConsoleFloat ( console , " linebuffered " , false ) ;
confuncs - > SetConsoleFloat ( console , " wnd_x " , pvid . width - 256 ) ;
confuncs - > SetConsoleFloat ( console , " wnd_y " , true ) ;
confuncs - > SetConsoleFloat ( console , " wnd_w " , 256 ) ;
confuncs - > SetConsoleFloat ( console , " wnd_h " , pvid . height ) ;
2015-04-27 06:19:33 +00:00
}
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleFloat ( console , " linecount " , 0 ) ; //clear it
2015-04-27 06:19:33 +00:00
if ( force )
2019-09-04 07:59:40 +00:00
confuncs - > SetActive ( console ) ;
2015-04-27 06:19:33 +00:00
for ( i = 0 ; i < sizeof ( jclients ) / sizeof ( jclients [ 0 ] ) ; i + + )
{
jcl = jclients [ i ] ;
if ( ! jcl )
continue ;
if ( * jcl - > localalias & & * jcl - > localalias ! = ' > ' )
2017-10-12 12:02:25 +00:00
Con_SubPrintf ( console , " \n " COL_NAME_US " %s \n " , jcl - > localalias ) ;
2015-04-27 06:19:33 +00:00
else
2017-10-12 12:02:25 +00:00
Con_SubPrintf ( console , " \n " COL_NAME_US " %s@%s \n " , jcl - > username , jcl - > domain ) ;
2015-04-27 06:19:33 +00:00
if ( jcl - > status = = JCL_INACTIVE )
Con_SubPrintf ( console , " Not connected. \n " , jcl - > accountnum ) ;
else if ( jcl - > status = = JCL_DEAD )
Con_SubPrintf ( console , " %s. \n " , * jcl - > errormsg ? jcl - > errormsg : " Connect failed " , jcl - > accountnum ) ;
else if ( jcl - > status = = JCL_AUTHING )
Con_SubPrintf ( console , " Connecting... Please wait. \n " ) ;
2017-09-20 11:27:13 +00:00
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , " accopts " , NULL , NULL , NULL , " %s " , " Options " ) ;
Con_SubPrintf ( console , " %s \n " , convolink ) ;
/*
2015-04-27 06:19:33 +00:00
if ( jcl - > status = = JCL_INACTIVE )
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , " forgetacc " , NULL , NULL , NULL , " %s " , " Forget Account " ) ;
else if ( jcl - > status = = JCL_DEAD )
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , " disconnect " , NULL , NULL , NULL , " %s " , " Disable " ) ;
else
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , " disconnect " , NULL , NULL , NULL , " %s " , " Disconnect " ) ;
Con_SubPrintf ( console , " %s " , convolink ) ;
if ( jcl - > status = = JCL_INACTIVE )
{
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , " connect " , NULL , NULL , NULL , " %s " , " Connect " ) ;
Con_SubPrintf ( console , " %s " , convolink ) ;
}
else if ( jcl - > status = = JCL_DEAD )
{
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , " connect " , NULL , NULL , NULL , " %s " , " Reconnect " ) ;
Con_SubPrintf ( console , " %s " , convolink ) ;
}
2017-09-20 11:27:13 +00:00
*/
2017-10-12 12:02:25 +00:00
for ( c2c = jcl - > c2c ; c2c ; c2c = c2c - > next )
c2c - > displayed = false ;
2015-04-27 06:19:33 +00:00
if ( jcl - > status ! = JCL_ACTIVE )
Con_SubPrintf ( console , " \n " ) ;
else
{
qboolean youarealoner = true ;
2017-09-20 11:27:13 +00:00
// JCL_GenLink(jcl, convolink, sizeof(convolink), "addfriend", NULL, NULL, NULL, "%s", "Add Friend");
// Con_SubPrintf(console, " %s\n", convolink);
2015-04-27 06:19:33 +00:00
2017-09-20 11:27:13 +00:00
JCL_FindBuddy ( jcl , jcl - > fulljid , & me , NULL , true ) ;
2015-04-27 06:19:33 +00:00
for ( b = jcl - > buddies , buds = 0 ; b & & buds < sizeof ( sortlist ) / sizeof ( sortlist [ 0 ] ) ; b = b - > next )
{
if ( b = = me )
continue ;
if ( ! b - > resources ) //can't be online.
continue ;
2017-10-12 12:02:25 +00:00
if ( b - > btype = = BT_UNKNOWN )
continue ; //don't list people we don't actually know
2015-04-27 06:19:33 +00:00
for ( j = buds ; j > 0 ; j - - )
{
if ( strcasecmp ( sortlist [ j - 1 ] - > name , b - > name ) > = 0 )
break ;
sortlist [ j ] = sortlist [ j - 1 ] ;
}
buds + + ;
sortlist [ j ] = b ;
}
Con_SubPrintf ( console , " \n " ) ;
while ( buds - - > 0 )
{
bresource_t * gameres = NULL ;
bresource_t * voiceres = NULL ;
bresource_t * chatres = NULL ;
b = sortlist [ buds ] ;
2017-10-12 12:02:25 +00:00
if ( b - > btype = = BT_ROSTER )
{ //gather capabilities from all of their resources
for ( r = b - > resources ; r ; r = r - > next )
{
if ( ! strcmp ( r - > bstatus , " offline " ) )
continue ;
2015-04-27 06:19:33 +00:00
2017-10-12 12:02:25 +00:00
if ( ( r - > caps & CAP_VOICE ) & & ( ! voiceres | | r - > priority > voiceres - > priority ) )
voiceres = r ;
if ( ( r - > caps & CAP_GAMEINVITE ) & & ( ! gameres | | r - > priority > gameres - > priority ) )
gameres = r ;
if ( ! chatres | | r - > priority > chatres - > priority )
chatres = r ;
}
2015-04-27 06:19:33 +00:00
}
if ( b - > defaultresource )
{
r = b - > defaultresource ;
if ( r - > caps & CAP_VOICE )
voiceres = r ;
if ( r - > caps & CAP_GAMEINVITE )
gameres = r ;
chatres = r ;
}
2017-10-12 12:02:25 +00:00
if ( chatres | | b - > btype = = BT_CHATROOM )
2015-04-27 06:19:33 +00:00
{
youarealoner = false ;
if ( b - > vcardphotochanged & & b - > friended )
{
struct buddyinfo_s * bi ;
for ( bi = jcl - > buddyinfo ; bi ; bi = bi - > next )
{
if ( ! strcmp ( bi - > accountdomain , b - > accountdomain ) )
break ;
}
if ( bi & & ! strcmp ( b - > vcardphotohash , bi - > imagehash ) )
{
char photodata [ 65536 ] ;
unsigned int photosize = bi - > image ? Base64_Decode ( photodata , sizeof ( photodata ) , bi - > image , strlen ( bi - > image ) ) : 0 ;
2019-09-04 07:59:40 +00:00
b - > image = drawfuncs - > LoadImageData ( va ( " xmpp/%s.png " , b - > accountdomain ) , bi - > imagemime , photodata , photosize ) ;
2015-04-27 06:19:33 +00:00
b - > vcardphotochanged = false ;
}
else if ( ! * b - > vcardphotohash )
{ //this buddy has no photo, so don't bother querying it
b - > vcardphotochanged = false ;
b - > image = 0 ;
}
else if ( jcl - > avatarupdate = = NULL )
{
b - > vcardphotochanged = false ;
Con_DPrintf ( " Querying %s's photo \n " , b - > accountdomain ) ;
jcl - > avatarupdate = JCL_SendIQf ( jcl , JCL_BuddyVCardReply , " get " , b - > accountdomain , " <vCard xmlns='vcard-temp'/> " ) ;
}
}
Q_snprintf ( convolink , sizeof ( convolink ) , " ^[%s \\ xmppacc \\ %i \\ xmpp \\ %s^] " , b - > name , jcl - > accountnum , b - > accountdomain ) ;
2017-09-20 11:27:13 +00:00
Con_SubPrintf ( console , " ^[ \\ img \\ xmpp/%s.png \\ fbimg \\ " IMG_FB_THEM " \\ w \\ 32 \\ h \\ 32^] " , b - > accountdomain ) ;
2015-04-27 06:19:33 +00:00
Con_SubPrintf ( console , " %s " , convolink ) ;
2017-10-12 12:02:25 +00:00
if ( chatres & & * chatres - > fstatus )
2015-04-27 06:19:33 +00:00
Con_SubPrintf ( console , " \v %s " , chatres - > fstatus ) ;
2017-10-12 12:02:25 +00:00
else if ( b - > btype = = BT_CHATROOM & & b - > room_topic )
Con_SubPrintf ( console , " \v %s " , b - > room_topic ) ;
2015-04-27 06:19:33 +00:00
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , " buddyopts " , b - > accountdomain , NULL , NULL , " ^h%s^h " , " Options " ) ;
2017-10-12 12:02:25 +00:00
if ( chatres )
Con_SubPrintf ( console , " \v %s %s " , chatres - > bstatus , convolink ) ;
else if ( b - > btype = = BT_CHATROOM )
Con_SubPrintf ( console , " \v %s %s " , " chatroom " , convolink ) ;
else
Con_SubPrintf ( console , " \v %s %s " , " unknown " , convolink ) ;
2015-04-27 06:19:33 +00:00
for ( c2c = jcl - > c2c ; c2c ; c2c = c2c - > next )
{
2016-07-12 00:40:13 +00:00
buddy_t * peer = NULL ;
qboolean voice = false , video = false , server = false ;
2015-04-27 06:19:33 +00:00
int c ;
2017-10-12 12:02:25 +00:00
if ( JCL_FindBuddy ( jcl , c2c - > with , & peer , NULL , false ) & & peer = = b )
2015-04-27 06:19:33 +00:00
{
for ( c = 0 ; c < c2c - > contents ; c + + )
{
switch ( c2c - > content [ c ] . mediatype )
{
2016-07-12 00:40:13 +00:00
case ICEP_INVALID : break ;
2015-04-27 06:19:33 +00:00
case ICEP_VOICE : voice = true ; break ;
case ICEP_VIDEO : video = true ; break ;
case ICEP_QWSERVER : server = true ; break ;
2016-07-12 00:40:13 +00:00
case ICEP_QWCLIENT : /*client = true;*/ break ;
2015-04-27 06:19:33 +00:00
}
}
2017-10-12 12:02:25 +00:00
c2c - > displayed = true ;
2015-04-27 06:19:33 +00:00
if ( server )
{
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , " jdeny " , c2c - > with , NULL , c2c - > sid , " %s " , " Kick " ) ;
gameres = NULL ;
}
else if ( video | | voice )
{
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , " jdeny " , c2c - > with , NULL , c2c - > sid , " %s " , " Hang Up " ) ;
voiceres = NULL ;
}
2016-07-12 00:40:13 +00:00
else /*if (client)*/
2015-04-27 06:19:33 +00:00
{
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , " jdeny " , c2c - > with , NULL , c2c - > sid , " %s " , " Disconnect " ) ;
gameres = NULL ;
}
Con_SubPrintf ( console , " %s " , convolink ) ;
}
}
if ( gameres )
{
if ( * gameres - > server )
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , " join " , b - > accountdomain , gameres - > resource , NULL , " Playing Quake - %s " , gameres - > server ) ;
else
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , " invite " , b - > accountdomain , gameres - > resource , NULL , " %s " , " Invite " ) ;
Con_SubPrintf ( console , " %s " , convolink ) ;
}
if ( voiceres )
{
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , " call " , b - > accountdomain , voiceres - > resource , NULL , " %s " , " Call " ) ;
Con_SubPrintf ( console , " %s " , convolink ) ;
}
Con_SubPrintf ( console , " \n " ) ;
}
}
if ( youarealoner )
Con_SubPrintf ( console , " You have no friends \n " ) ;
}
2017-10-12 12:02:25 +00:00
//and show any lingering c2cs with anyone not on our list.
for ( c2c = jcl - > c2c ; c2c ; c2c = c2c - > next )
{
if ( ! c2c - > displayed )
{
qboolean voice = false , video = false , server = false ;
int c ;
for ( c = 0 ; c < c2c - > contents ; c + + )
{
switch ( c2c - > content [ c ] . mediatype )
{
case ICEP_INVALID : break ;
case ICEP_VOICE : voice = true ; break ;
case ICEP_VIDEO : video = true ; break ;
case ICEP_QWSERVER : server = true ; break ;
case ICEP_QWCLIENT : /*client = true;*/ break ;
}
}
c2c - > displayed = true ;
if ( server )
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , " jdeny " , c2c - > with , NULL , c2c - > sid , " %s " , " Kick " ) ;
else if ( video | | voice )
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , " jdeny " , c2c - > with , NULL , c2c - > sid , " %s " , " Hang Up " ) ;
else /*if (client)*/
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , " jdeny " , c2c - > with , NULL , c2c - > sid , " %s " , " Disconnect " ) ;
Con_SubPrintf ( console , " %s: %s \n " , c2c - > with , convolink ) ;
}
}
2015-04-27 06:19:33 +00:00
}
for ( i = 0 ; i < sizeof ( jclients ) / sizeof ( jclients [ 0 ] ) ; i + + )
if ( ! jclients [ i ] )
{
JCL_GenLink ( NULL , convolink , sizeof ( convolink ) , " newaccount " , NULL , NULL , NULL , " %s " , " Open New Account " ) ;
Con_SubPrintf ( console , " \n %s \n " , convolink ) ;
break ;
}
}
static void JCL_PrintBuddyList ( char * console , jclient_t * jcl , qboolean all )
{
buddy_t * b ;
bresource_t * r ;
struct c2c_s * c2c ;
struct ft_s * ft ;
char convolink [ 512 ] , actlink [ 512 ] ;
int c ;
if ( ! jcl - > buddies )
Con_SubPrintf ( console , " You have no friends \n " ) ;
for ( b = jcl - > buddies ; b ; b = b - > next )
{
//if we don't actually know them, don't list them.
2017-10-12 12:02:25 +00:00
if ( b - > btype = = BT_UNKNOWN )
2015-04-27 06:19:33 +00:00
continue ;
2017-10-12 12:02:25 +00:00
if ( b - > btype = = BT_CHATROOM )
{
r = b - > resources ;
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , NULL , b - > accountdomain , r - > resource , NULL , " %s " , b - > name ) ;
Con_SubPrintf ( console , " %s: " , convolink ) ;
JCL_PrintBuddyStatus ( console , jcl , b , r ) ;
Con_SubPrintf ( console , " \n " ) ;
}
else if ( ! b - > resources ) //offline
2015-04-27 06:19:33 +00:00
{
if ( all )
{
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , NULL , b - > accountdomain , NULL , NULL , " %s " , b - > name ) ;
Con_SubPrintf ( console , " %s: offline \n " , convolink ) ;
}
}
else if ( b - > resources - > next )
{ //multiple potential resources
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , NULL , b - > accountdomain , NULL , NULL , " %s " , b - > name ) ;
Con_SubPrintf ( console , " %s: \n " , convolink ) ;
for ( r = b - > resources ; r ; r = r - > next )
{
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , NULL , b - > accountdomain , r - > resource , NULL , " %s " , r - > resource ) ;
Con_SubPrintf ( console , " %s: " , convolink ) ;
JCL_PrintBuddyStatus ( console , jcl , b , r ) ;
Con_SubPrintf ( console , " \n " ) ;
}
}
else //only one resource
{
r = b - > resources ;
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , NULL , b - > accountdomain , r - > resource , NULL , " %s " , b - > name ) ;
Con_SubPrintf ( console , " %s: " , convolink ) ;
JCL_PrintBuddyStatus ( console , jcl , b , r ) ;
Con_SubPrintf ( console , " \n " ) ;
}
}
# ifdef JINGLE
if ( jcl - > c2c )
Con_SubPrintf ( console , " Active sessions: \n " ) ;
for ( c2c = jcl - > c2c ; c2c ; c2c = c2c - > next )
{
qboolean voice = false , video = false , server = false , client = false ;
JCL_FindBuddy ( jcl , c2c - > with , & b , & r , true ) ;
for ( c = 0 ; c < c2c - > contents ; c + + )
{
switch ( c2c - > content [ c ] . mediatype )
{
2016-07-12 00:40:13 +00:00
case ICEP_INVALID : break ;
2015-04-27 06:19:33 +00:00
case ICEP_VOICE : voice = true ; break ;
case ICEP_VIDEO : video = true ; break ;
case ICEP_QWSERVER : server = true ; break ;
case ICEP_QWCLIENT : client = true ; break ;
}
}
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , NULL , b - > accountdomain , r - > resource , NULL , " %s " , b - > name ) ;
Con_SubPrintf ( console , " %s: " , convolink ) ;
if ( video )
Con_SubPrintf ( console , " video " ) ;
if ( voice )
Con_SubPrintf ( console , " voice " ) ;
if ( server )
Con_SubPrintf ( console , " server " ) ;
if ( client )
Con_SubPrintf ( console , " client " ) ;
if ( server )
JCL_GenLink ( jcl , actlink , sizeof ( actlink ) , " jdeny " , c2c - > with , NULL , c2c - > sid , " %s " , " Kick " ) ;
else if ( video | | voice )
JCL_GenLink ( jcl , actlink , sizeof ( actlink ) , " jdeny " , c2c - > with , NULL , c2c - > sid , " %s " , " Hang Up " ) ;
else
JCL_GenLink ( jcl , actlink , sizeof ( actlink ) , " jdeny " , c2c - > with , NULL , c2c - > sid , " %s " , " Disconnect " ) ;
Con_SubPrintf ( console , " %s \n " , actlink ) ;
}
# endif
# ifdef FILETRANSFERS
if ( jcl - > ft )
Con_SubPrintf ( console , " Active file transfers: \n " ) ;
for ( ft = jcl - > ft ; ft ; ft = ft - > next )
{
JCL_FindBuddy ( jcl , ft - > with , & b , & r , true ) ;
JCL_GenLink ( jcl , convolink , sizeof ( convolink ) , NULL , b - > accountdomain , r - > resource , NULL , " %s " , b - > name ) ;
JCL_GenLink ( jcl , actlink , sizeof ( actlink ) , " fdeny " , ft - > with , NULL , ft - > sid , " %s " , " Cancel " ) ;
Con_SubPrintf ( console , " %s: %s \n " , convolink , ft - > fname ) ;
}
# endif
}
2005-12-11 20:11:22 +00:00
//functions above this line allow connections to multiple servers.
//it is just the control functions that only allow one server.
2019-09-04 07:59:40 +00:00
void JCL_Frame ( double realtime , double gametime )
2005-12-11 20:11:22 +00:00
{
2013-07-13 12:14:32 +00:00
int i ;
2019-09-04 07:59:40 +00:00
jclient_curtime = realtime ;
2015-04-27 06:19:33 +00:00
if ( jclient_needreadconfig )
{
JCL_LoadConfig ( ) ;
JCL_RegenerateBuddyList ( false ) ;
}
if ( jclient_updatebuddylist )
JCL_RegenerateBuddyList ( false ) ;
2013-07-13 12:14:32 +00:00
for ( i = 0 ; i < sizeof ( jclients ) / sizeof ( jclients [ 0 ] ) ; i + + )
2005-12-11 20:11:22 +00:00
{
2013-07-13 12:14:32 +00:00
jclient_t * jcl = jclients [ i ] ;
if ( jcl & & jcl - > status ! = JCL_INACTIVE )
2013-03-31 04:21:08 +00:00
{
2013-07-13 12:14:32 +00:00
int stat = JCL_CONTINUE ;
if ( jcl - > status = = JCL_DEAD )
2013-06-29 16:01:07 +00:00
{
2013-07-13 12:14:32 +00:00
if ( jclient_curtime > jcl - > timeout )
{
JCL_Reconnect ( jcl ) ;
jcl - > timeout = jclient_curtime + 60 * 1000 ;
2015-04-27 06:19:33 +00:00
jclient_updatebuddylist = true ;
2013-07-13 12:14:32 +00:00
}
2013-06-29 16:01:07 +00:00
}
else
2013-07-13 12:14:32 +00:00
{
2015-04-27 06:19:33 +00:00
char * error = " " ;
2013-07-13 12:14:32 +00:00
if ( jcl - > connected )
JCL_GeneratePresence ( jcl , false ) ;
while ( stat = = JCL_CONTINUE )
2015-04-27 06:19:33 +00:00
stat = JCL_ClientFrame ( jcl , & error ) ;
2013-07-13 12:14:32 +00:00
if ( stat = = JCL_NUKEFROMORBIT )
{
2015-04-27 06:19:33 +00:00
JCL_CloseConnection ( jcl , error , true ) ;
2013-07-13 12:14:32 +00:00
jcl - > status = JCL_INACTIVE ;
}
else if ( stat = = JCL_KILL )
2015-04-27 06:19:33 +00:00
JCL_CloseConnection ( jcl , error , true ) ;
2013-07-13 12:14:32 +00:00
else
JCL_FlushOutgoing ( jcl ) ;
2013-11-21 23:02:28 +00:00
if ( stat = = JCL_DONE )
{
XMPP_FT_Frame ( jcl ) ;
if ( jclient_curtime > jcl - > timeout )
{
//client needs to send something valid as a keep-alive so routers don't silently forget mappings.
JCL_SendIQf ( jcl , NULL , " get " , NULL , " <ping xmlns='urn:xmpp:ping'/> " ) ;
jcl - > timeout = jclient_curtime + 60 * 1000 ;
}
2017-10-12 12:02:25 +00:00
if ( jcl - > status = = JCL_ACTIVE )
{
if ( jcl - > rcon_pipe > = 0 )
{
char rcondata [ 64000 ] ;
2019-09-04 07:59:40 +00:00
int rconsize = netfuncs - > Recv ( jcl - > rcon_pipe , rcondata , sizeof ( rcondata ) - 1 ) ;
2017-10-12 12:02:25 +00:00
if ( rconsize > 0 )
{
char * ls , * le ;
rcondata [ rconsize ] = 0 ;
ls = rcondata ;
while ( ls )
{
le = strchr ( ls , ' \n ' ) ;
if ( le )
* le + + = 0 ;
JCL_AddClientMessagef ( jcl , " <message to='%s'><body>%s</body></message> " , jcl - > rcon_peer , ls ) ;
ls = le ;
}
}
else if ( rconsize < 0 )
{
JCL_AddClientMessagef ( jcl , " <message to='%s'><body>%s</body></message> " , jcl - > rcon_peer , " RCON ERROR " ) ;
2019-09-04 07:59:40 +00:00
filefuncs - > Close ( jcl - > rcon_pipe ) ;
2017-10-12 12:02:25 +00:00
jcl - > rcon_pipe = - 1 ;
}
}
}
2013-11-21 23:02:28 +00:00
}
2013-07-13 12:14:32 +00:00
}
2013-08-21 07:42:42 +00:00
# ifdef JINGLE
JCL_JingleTimeouts ( jcl , false ) ;
# endif
JCL_IQTimeouts ( jcl ) ;
2005-12-11 20:11:22 +00:00
}
}
}
2013-06-23 02:33:52 +00:00
void JCL_WriteConfig ( void )
{
2013-11-21 23:02:28 +00:00
xmltree_t * m , * n , * oauth2 , * features ;
int i , j ;
2013-07-13 12:14:32 +00:00
qhandle_t config ;
2015-04-27 06:19:33 +00:00
struct buddyinfo_s * bi ;
2017-10-12 12:02:25 +00:00
buddy_t * bud ;
2015-04-27 06:19:33 +00:00
2021-06-21 13:36:30 +00:00
if ( ! jclient_configdirty )
return ; //no point yet.
jclient_configdirty = false ;
2015-04-27 06:19:33 +00:00
//don't write the config if we're meant to be reading it. avoid wiping it if we're killed fast.
if ( jclient_needreadconfig )
return ;
2013-07-13 12:14:32 +00:00
m = XML_CreateNode ( NULL , " xmppaccounts " , " " , " " ) ;
for ( i = 0 ; i < sizeof ( jclients ) / sizeof ( jclients [ 0 ] ) ; i + + )
2013-06-23 02:33:52 +00:00
{
2013-07-13 12:14:32 +00:00
jclient_t * jcl = jclients [ i ] ;
if ( jcl )
2013-06-23 02:33:52 +00:00
{
2013-07-13 12:14:32 +00:00
char foo [ 64 ] ;
n = XML_CreateNode ( m , " account " , " " , " " ) ;
XML_AddParameteri ( n , " id " , i ) ;
2013-11-21 23:02:28 +00:00
Q_snprintf ( foo , sizeof ( foo ) , " %i " , jcl - > streamdebug ) ;
XML_CreateNode ( n , " streamdebug " , " " , foo ) ;
2013-07-13 12:14:32 +00:00
Q_snprintf ( foo , sizeof ( foo ) , " %i " , jcl - > forcetls ) ;
XML_CreateNode ( n , " forcetls " , " " , foo ) ;
2013-11-21 23:02:28 +00:00
XML_CreateNode ( n , " savepassword " , " " , jcl - > savepassword ? " 1 " : " 0 " ) ;
2017-09-20 11:27:13 +00:00
XML_CreateNode ( n , " allowauth_plain_nontls " , " " , jcl - > sasl . allowauth_plainnontls ? " 1 " : " 0 " ) ;
XML_CreateNode ( n , " allowauth_plain_tls " , " " , jcl - > sasl . allowauth_plaintls ? " 1 " : " 0 " ) ;
XML_CreateNode ( n , " allowauth_digest_md5 " , " " , jcl - > sasl . allowauth_digestmd5 ? " 1 " : " 0 " ) ;
XML_CreateNode ( n , " allowauth_scram_sha_1 " , " " , jcl - > sasl . allowauth_scramsha1 ? " 1 " : " 0 " ) ;
2013-07-13 12:14:32 +00:00
2017-09-20 11:27:13 +00:00
if ( * jcl - > sasl . oauth2 . saslmethod )
2013-07-13 12:14:32 +00:00
{
2017-09-20 11:27:13 +00:00
XML_CreateNode ( n , " allowauth_oauth2 " , " " , jcl - > sasl . allowauth_oauth2 ? " 1 " : " 0 " ) ;
2013-07-13 12:14:32 +00:00
oauth2 = XML_CreateNode ( n , " oauth2 " , " " , " " ) ;
2017-09-20 11:27:13 +00:00
XML_AddParameter ( oauth2 , " method " , jcl - > sasl . oauth2 . saslmethod ) ;
XML_CreateNode ( oauth2 , " obtain-url " , " " , jcl - > sasl . oauth2 . obtainurl ) ;
XML_CreateNode ( oauth2 , " refresh-url " , " " , jcl - > sasl . oauth2 . refreshurl ) ;
XML_CreateNode ( oauth2 , " client-id " , " " , jcl - > sasl . oauth2 . clientid ) ;
XML_CreateNode ( oauth2 , " client-secret " , " " , jcl - > sasl . oauth2 . clientsecret ) ;
XML_CreateNode ( oauth2 , " scope " , " " , jcl - > sasl . oauth2 . scope ) ;
XML_CreateNode ( oauth2 , " auth-token " , " " , jcl - > sasl . oauth2 . authtoken ) ;
XML_CreateNode ( oauth2 , " refresh-token " , " " , jcl - > sasl . oauth2 . refreshtoken ) ;
XML_CreateNode ( oauth2 , " access-token " , " " , jcl - > sasl . oauth2 . accesstoken ) ;
2013-07-13 12:14:32 +00:00
}
XML_CreateNode ( n , " username " , " " , jcl - > username ) ;
XML_CreateNode ( n , " domain " , " " , jcl - > domain ) ;
XML_CreateNode ( n , " resource " , " " , jcl - > resource ) ;
2017-09-20 11:27:13 +00:00
if ( jcl - > savepassword )
XML_CreateNode ( n , " password " , " " , jcl - > sasl . password_plain ) ; //FIXME: should we base64 this just to obscure it? probably not. trivial obscurity does few favours.
2013-07-13 12:14:32 +00:00
XML_CreateNode ( n , " serveraddr " , " " , jcl - > serveraddr ) ;
Q_snprintf ( foo , sizeof ( foo ) , " %i " , jcl - > serverport ) ;
XML_CreateNode ( n , " serverport " , " " , foo ) ;
XML_CreateNode ( n , " certificatedomain " , " " , jcl - > certificatedomain ) ;
XML_CreateNode ( n , " inactive " , " " , jcl - > status = = JCL_INACTIVE ? " 1 " : " 0 " ) ;
2013-11-21 23:02:28 +00:00
2017-10-12 12:02:25 +00:00
//write out what optional/risky features should be enabled (like file transfers, jingle, etc)
2013-11-21 23:02:28 +00:00
features = XML_CreateNode ( n , " features " , " " , " " ) ;
XML_AddParameter ( features , " ver " , JCL_BUILD ) ;
for ( j = 0 ; capnames [ j ] . names ; j + + )
{
XML_CreateNode ( features , capnames [ j ] . names , " " , ( jcl - > enabledcapabilities & capnames [ j ] . cap ) ? " 1 " : " 0 " ) ;
}
2015-04-27 06:19:33 +00:00
2017-10-12 12:02:25 +00:00
//write a list of chatrooms that can't be saved in rosters
features = XML_CreateNode ( n , " chats " , " " , " " ) ;
for ( bud = jcl - > buddies ; bud ; bud = bud - > next )
{
if ( bud - > btype = = BT_CHATROOM )
{
xmltree_t * b = XML_CreateNode ( features , " room " , " " , " " ) ;
XML_AddParameter ( b , " name " , bud - > accountdomain ) ;
XML_AddParameter ( b , " alias " , bud - > name ) ;
XML_AddParameter ( b , " nick " , bud - > room_nick ) ;
XML_AddParameter ( b , " password " , bud - > room_password ) ;
XML_AddParameteri ( b , " autojoin " , bud - > room_autojoin ) ;
}
}
//write an avatar cache
//FIXME: some sort of timeout? only people on our roster?
2015-04-27 06:19:33 +00:00
features = XML_CreateNode ( n , " buddyinfo " , " " , " " ) ;
for ( bi = jcl - > buddyinfo ; bi ; bi = bi - > next )
{
xmltree_t * b = XML_CreateNode ( features , " buddy " , " " , " " ) ;
XML_AddParameter ( b , " name " , bi - > accountdomain ) ;
if ( bi - > image )
XML_CreateNode ( b , " image " , " " , bi - > image ) ;
if ( bi - > imagemime )
XML_CreateNode ( b , " imagemime " , " " , bi - > imagemime ) ;
if ( bi - > imagehash )
XML_CreateNode ( b , " imagehash " , " " , bi - > imagehash ) ;
}
//FIXME: client disco info
2013-06-23 02:33:52 +00:00
}
}
2013-07-13 12:14:32 +00:00
2019-09-04 07:59:40 +00:00
filefuncs - > Open ( " **plugconfig " , & config , 2 ) ;
2013-07-13 12:14:32 +00:00
if ( config > = 0 )
{
char * s = XML_GenerateString ( m , true ) ;
2019-09-04 07:59:40 +00:00
filefuncs - > Write ( config , s , strlen ( s ) ) ;
2013-07-13 12:14:32 +00:00
free ( s ) ;
2019-09-04 07:59:40 +00:00
filefuncs - > Close ( config ) ;
2013-07-13 12:14:32 +00:00
}
XML_Destroy ( m ) ;
2013-06-23 02:33:52 +00:00
}
void JCL_LoadConfig ( void )
{
2015-04-27 06:19:33 +00:00
jclient_needreadconfig = false ;
2013-07-13 12:14:32 +00:00
if ( ! jclients [ 0 ] )
2013-06-23 02:33:52 +00:00
{
int len ;
qhandle_t config ;
2015-04-27 06:19:33 +00:00
char * buf ;
2013-06-23 02:33:52 +00:00
qboolean oldtls ;
2021-06-21 13:36:30 +00:00
jclient_configdirty = false ;
2019-09-04 07:59:40 +00:00
len = filefuncs - > Open ( " **plugconfig " , & config , 1 ) ;
2013-07-14 12:22:51 +00:00
if ( len > = 0 )
2013-06-23 02:33:52 +00:00
{
2015-04-27 06:19:33 +00:00
buf = malloc ( len + 1 ) ;
2013-06-23 02:33:52 +00:00
buf [ len ] = 0 ;
2019-09-04 07:59:40 +00:00
filefuncs - > Read ( config , buf , len ) ;
filefuncs - > Close ( config ) ;
2013-06-23 02:33:52 +00:00
2013-07-14 12:22:51 +00:00
if ( len & & * buf ! = ' < ' )
2013-07-13 12:14:32 +00:00
{ //legacy code, to be removed
char * line = buf ;
char tls [ 256 ] ;
char server [ 256 ] ;
char account [ 256 ] ;
char password [ 256 ] ;
line = JCL_ParseOut ( line , tls , sizeof ( tls ) ) ;
line = JCL_ParseOut ( line , server , sizeof ( server ) ) ;
line = JCL_ParseOut ( line , account , sizeof ( account ) ) ;
line = JCL_ParseOut ( line , password , sizeof ( password ) ) ;
oldtls = atoi ( tls ) ;
2013-07-14 12:22:51 +00:00
Con_Printf ( " Legacy config: %s (%i) \n " , buf , len ) ;
2013-07-13 12:14:32 +00:00
jclients [ 0 ] = JCL_Connect ( 0 , server , oldtls , account , password ) ;
}
else
{
xmltree_t * accs ;
int start = 0 ;
accs = XML_Parse ( buf , & start , len , false , " " ) ;
if ( accs )
{
int i ;
xmltree_t * acc ;
for ( i = 0 ; ( acc = XML_ChildOfTree ( accs , " account " , i ) ) ; i + + )
{
int id = atoi ( XML_GetParameter ( acc , " id " , " 0 " ) ) ;
if ( id < 0 | | id > = sizeof ( jclients ) / sizeof ( jclients [ 0 ] ) | | jclients [ id ] )
continue ;
2013-06-23 02:33:52 +00:00
2013-07-13 12:14:32 +00:00
jclients [ id ] = JCL_ConnectXML ( acc ) ;
}
XML_Destroy ( accs ) ;
}
}
2015-04-27 06:19:33 +00:00
free ( buf ) ;
2013-06-23 02:33:52 +00:00
}
}
}
2013-07-13 12:14:32 +00:00
//on shutdown, write config and close connections.
2019-09-04 07:59:40 +00:00
void JCL_Shutdown ( void )
2013-07-13 12:14:32 +00:00
{
jclient_t * jcl ;
int i ;
JCL_WriteConfig ( ) ;
for ( i = 0 ; i < sizeof ( jclients ) / sizeof ( jclients [ 0 ] ) ; i + + )
{
jcl = jclients [ i ] ;
if ( jcl )
2015-04-27 06:19:33 +00:00
JCL_CloseConnection ( jcl , " " , false ) ;
2013-07-13 12:14:32 +00:00
}
2013-07-29 17:36:44 +00:00
// if (_CrtDumpMemoryLeaks())
// OutputDebugStringA("Leaks detected\n");
2013-07-13 12:14:32 +00:00
}
2013-06-23 02:33:52 +00:00
void JCL_SendMessage ( jclient_t * jcl , char * to , char * msg )
{
2013-06-29 16:01:07 +00:00
char markup [ 1024 ] ;
2015-04-27 06:19:33 +00:00
char * con , * title ;
2013-06-23 02:33:52 +00:00
buddy_t * b ;
bresource_t * br ;
2014-04-20 02:18:51 +00:00
JCL_FindBuddy ( jcl , to , & b , & br , true ) ;
if ( ! b )
{
Con_Printf ( " Can't find buddy \" %s \" \n " , to ) ;
2013-11-21 23:02:28 +00:00
return ;
2014-04-20 02:18:51 +00:00
}
2017-10-12 12:02:25 +00:00
if ( b - > btype = = BT_CHATROOM )
2013-07-13 12:14:32 +00:00
{
if ( br )
2017-10-12 12:02:25 +00:00
{ //unicast...
2013-07-13 12:14:32 +00:00
JCL_AddClientMessagef ( jcl , " <message to='%s/%s' type='chat'><body> " , b - > accountdomain , br - > resource ) ;
con = to ;
}
else
2017-10-12 12:02:25 +00:00
{ //send to all recipients
2013-07-13 12:14:32 +00:00
JCL_AddClientMessagef ( jcl , " <message to='%s' type='groupchat'><body> " , b - > accountdomain ) ;
con = b - > name ;
}
2015-04-27 06:19:33 +00:00
title = con ;
2013-07-13 12:14:32 +00:00
}
2013-06-23 02:33:52 +00:00
else
2013-07-13 12:14:32 +00:00
{
2015-04-27 06:19:33 +00:00
title = b - > name ;
con = b - > accountdomain ;
2013-07-13 12:14:32 +00:00
if ( ! br )
br = b - > defaultresource ;
if ( br )
JCL_AddClientMessagef ( jcl , " <message to='%s/%s'><body> " , b - > accountdomain , br - > resource ) ;
else
JCL_AddClientMessagef ( jcl , " <message to='%s'><body> " , b - > accountdomain ) ;
}
2013-06-23 02:33:52 +00:00
JCL_AddClientMessage ( jcl , markup , XML_Markup ( msg , markup , sizeof ( markup ) ) - markup ) ;
JCL_AddClientMessageString ( jcl , " </body></message> " ) ;
2017-10-12 12:02:25 +00:00
if ( b - > btype = = BT_CHATROOM & & ! br )
2013-07-13 12:14:32 +00:00
return ;
2013-06-29 16:01:07 +00:00
if ( ! strncmp ( msg , " /me " , 4 ) )
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( con , title , false , " * " COL_NAME_US " %s^7 " COL_TEXT_US " %s \n " , ( ( ! strcmp ( jcl - > localalias , " >> " ) ) ? " me " : jcl - > localalias ) , msg + 3 ) ;
else if ( b - > btype = = BT_ROSTER & & confuncs )
XMPP_ConversationPrintf ( con , title , false , " ^[ \\ img \\ xmpp/%s.png \\ fbimg \\ " IMG_FB_US " \\ w \\ 32 \\ h \\ 32^] " COL_NAME_US " %s^7: \v " COL_TEXT_US " %s \n " , jcl - > barejid , jcl - > localalias , msg ) ;
2013-06-29 16:01:07 +00:00
else
2019-09-04 07:59:40 +00:00
XMPP_ConversationPrintf ( con , title , false , COL_NAME_US " %s^7: " COL_TEXT_US " %s \n " , jcl - > localalias , msg ) ;
2013-06-23 02:33:52 +00:00
}
2013-06-29 21:08:09 +00:00
void JCL_AttentionMessage ( jclient_t * jcl , char * to , char * msg )
{
char fullto [ 256 ] ;
2015-04-27 06:19:33 +00:00
buddy_t * b = NULL ;
bresource_t * br = NULL ;
2013-06-29 21:08:09 +00:00
xmltree_t * m ;
char * s ;
2013-06-23 02:33:52 +00:00
2015-04-27 06:19:33 +00:00
JCL_FindBuddy ( jcl , to , & b , & br , true ) ;
if ( ! b )
2013-11-21 23:02:28 +00:00
return ;
2013-06-29 21:08:09 +00:00
if ( ! br )
br = b - > defaultresource ;
if ( ! br )
br = b - > resources ;
if ( ! br )
{
2015-04-27 06:19:33 +00:00
Con_SubPrintf ( b - > accountdomain , " User is not online \n " ) ;
2013-06-29 21:08:09 +00:00
return ;
}
Q_snprintf ( fullto , sizeof ( fullto ) , " %s/%s " , b - > accountdomain , br - > resource ) ;
m = XML_CreateNode ( NULL , " message " , " " , " " ) ;
XML_AddParameter ( m , " to " , fullto ) ;
// XML_AddParameter(m, "type", "headline");
XML_CreateNode ( m , " attention " , " urn:xmpp:attention:0 " , " " ) ;
if ( msg )
XML_CreateNode ( m , " body " , " " , msg ) ;
2013-07-13 12:14:32 +00:00
s = XML_GenerateString ( m , false ) ;
2013-06-29 21:08:09 +00:00
JCL_AddClientMessageString ( jcl , s ) ;
free ( s ) ;
XML_Destroy ( m ) ;
if ( msg )
{
if ( ! strncmp ( msg , " /me " , 4 ) )
2017-10-12 12:02:25 +00:00
Con_SubPrintf ( b - > accountdomain , " * " COL_NAME_US " %s^7 " COL_TEXT_US " %s \n " , ( ( ! strcmp ( jcl - > localalias , " >> " ) ) ? " me " : jcl - > localalias ) , msg + 3 ) ;
2013-06-29 21:08:09 +00:00
else
2017-10-12 12:02:25 +00:00
Con_SubPrintf ( b - > accountdomain , COL_NAME_US " %s^7: " COL_TEXT_US " %s \n " , jcl - > localalias , msg ) ;
2013-06-29 21:08:09 +00:00
}
}
2013-06-23 02:33:52 +00:00
2017-10-12 12:02:25 +00:00
static qboolean JCL_IsChatroom ( jclient_t * jcl , char * room )
{
buddy_t * b ;
if ( ! jcl )
return false ;
if ( ! JCL_FindBuddy ( jcl , room , & b , NULL , true ) )
return false ;
return b - > btype = = BT_CHATROOM ;
}
2013-07-13 12:14:32 +00:00
//server may be null, in which case its expected to be folded into room.
2017-10-12 12:02:25 +00:00
void JCL_JoinMUCChat ( jclient_t * jcl , const char * room , const char * server , const char * myhandle , const char * password )
2013-07-13 12:14:32 +00:00
{
char caps [ 512 ] ;
char roomserverhandle [ 512 ] ;
buddy_t * b ;
2017-10-12 12:02:25 +00:00
// bresource_t *r;
2013-07-13 12:14:32 +00:00
if ( server )
2017-10-12 12:02:25 +00:00
Q_snprintf ( roomserverhandle , sizeof ( roomserverhandle ) , " %s@%s " , room , server ) ;
2013-07-13 12:14:32 +00:00
else
2017-10-12 12:02:25 +00:00
Q_snprintf ( roomserverhandle , sizeof ( roomserverhandle ) , " %s " , room ) ;
if ( ! JCL_FindBuddy ( jcl , roomserverhandle , & b , NULL , true ) )
2013-11-21 23:02:28 +00:00
return ;
2017-10-12 12:02:25 +00:00
if ( ! myhandle )
{
if ( b - > room_nick )
myhandle = b - > room_nick ;
else
myhandle = jcl - > username ;
}
b - > btype = BT_CHATROOM ;
2013-11-21 23:02:28 +00:00
buildcapsvcardpresence ( jcl , caps , sizeof ( caps ) ) ;
2017-10-12 12:02:25 +00:00
//FIXME: check for errors
JCL_AddClientMessagef ( jcl ,
" <presence to='%s/%s'> "
" <x xmlns='http://jabber.org/protocol/muc'> "
" <password>%s</password> "
//"<history maxstanzas= maxchars= seconds= since=/>"
" </x> "
" %+s "
" </presence> "
, roomserverhandle , myhandle , password ? password : " " , caps ) ;
if ( b - > room_nick ! = myhandle )
{
free ( b - > room_nick ) ;
b - > room_nick = myhandle ? strdup ( myhandle ) : NULL ;
}
if ( b - > room_password ! = password )
{
free ( b - > room_password ) ;
b - > room_password = myhandle ? strdup ( password ) : NULL ;
}
2013-07-13 12:14:32 +00:00
}
2013-10-29 17:38:22 +00:00
void XMPP_Menu_Password ( jclient_t * acc )
{
2015-04-27 06:19:33 +00:00
// int y;
if ( ! jclient_action )
{
JCL_RegenerateBuddyList ( true ) ;
2019-09-04 07:59:40 +00:00
confuncs - > SetConsoleFloat ( BUDDYLISTTITLE , " linebuffered " , true ) ;
2015-04-27 06:19:33 +00:00
jclient_action_cl = acc ;
jclient_action_buddy = NULL ;
2017-09-20 11:27:13 +00:00
jclient_action = ACT_SETAPASSWORD ;
2015-04-27 06:19:33 +00:00
}
/*
2019-09-04 07:59:40 +00:00
cmdfuncs - > AddText ( " conmenu \n "
2013-10-29 17:38:22 +00:00
" { \n "
" menuclear \n "
" if (option == \" SignIn \" ) \n "
2013-11-21 23:02:28 +00:00
" { \n "
COMMANDPREFIX " /set savepassword $_t1 \n "
COMMANDPREFIX " /password ${0} \n "
" } \n "
2013-10-29 17:38:22 +00:00
" } \n " , false ) ;
y = 36 ;
2019-09-04 07:59:40 +00:00
cmdfuncs - > AddText ( va ( " menutext 48 %i \" ^sXMPP Sign In \" \n " , y ) , false ) ; y + = 16 ;
cmdfuncs - > AddText ( va ( " menutext 48 %i \" ^sPlease provide your password for \" \n " , y ) , false ) ; y + = 16 ;
cmdfuncs - > AddText ( va ( " menueditpriv 48 %i \" %s@%s \" \" example \" \n " , y , acc - > username , acc - > domain ) , false ) ; y + = 16 ;
cmdfuncs - > AddText ( va ( " set _t1 0 \n menucheck 48 %i \" Save Password \" _t1 1 \n " , y ) , false ) ; y + = 16 ;
cmdfuncs - > AddText ( va ( " menutext 48 %i \" Sign In \" SignIn \n " , y ) , false ) ;
cmdfuncs - > AddText ( va ( " menutext 256 %i \" Cancel \" cancel \n " , y ) , false ) ;
2015-04-27 06:19:33 +00:00
*/
2013-10-29 17:38:22 +00:00
}
void XMPP_Menu_Connect ( void )
{
int y ;
2019-09-04 07:59:40 +00:00
cmdfuncs - > AddText ( " conmenu \n "
2013-10-29 17:38:22 +00:00
" { \n "
" menuclear \n "
" if (option == \" SignIn \" ) \n "
" { \n " COMMANDPREFIX " /connect ${0}@${1}/${2} \n } \n "
" } \n " , false ) ;
y = 36 ;
2019-09-04 07:59:40 +00:00
cmdfuncs - > AddText ( va ( " menutext 48 %i \" ^sXMPP Sign In \" \n " , y ) , false ) ; y + = 16 ;
cmdfuncs - > AddText ( va ( " menueditpriv 48 %i \" Username \" \" example \" \n " , y ) , false ) ; y + = 16 ;
cmdfuncs - > AddText ( va ( " menueditpriv 48 %i \" Domain \" \" " EXAMPLEDOMAIN " \" \n " , y ) , false ) ; y + = 16 ;
cmdfuncs - > AddText ( va ( " menueditpriv 48 %i \" Resource \" \" \" \n " , y ) , false ) ; y + = 32 ;
cmdfuncs - > AddText ( va ( " menutext 48 %i \" Sign In \" SignIn \n " , y ) , false ) ;
cmdfuncs - > AddText ( va ( " menutext 256 %i \" Cancel \" cancel \n " , y ) , false ) ;
2013-10-29 17:38:22 +00:00
}
2013-07-13 12:14:32 +00:00
void JCL_Command ( int accid , char * console )
2005-12-11 20:11:22 +00:00
{
char imsg [ 8192 ] ;
2017-10-12 12:02:25 +00:00
char arg [ 6 ] [ 1024 ] , * argstart [ 6 ] ;
2005-12-11 20:11:22 +00:00
char * msg ;
int i ;
2013-06-29 21:08:09 +00:00
char nname [ 256 ] ;
2013-07-13 12:14:32 +00:00
jclient_t * jcl ;
if ( accid < 0 | | accid > = sizeof ( jclients ) / sizeof ( jclients [ 0 ] ) )
return ;
jcl = jclients [ accid ] ;
2005-12-11 20:11:22 +00:00
2019-09-04 07:59:40 +00:00
cmdfuncs - > Args ( imsg , sizeof ( imsg ) ) ;
2005-12-11 20:11:22 +00:00
msg = imsg ;
for ( i = 0 ; i < 6 ; i + + )
{
if ( ! msg )
2017-10-12 12:02:25 +00:00
{
argstart [ i ] = " " ;
2013-10-29 17:38:22 +00:00
* arg [ i ] = 0 ;
2017-10-12 12:02:25 +00:00
}
2013-10-29 17:38:22 +00:00
else
2017-10-12 12:02:25 +00:00
{
while ( * msg = = ' ' )
msg + + ;
argstart [ i ] = msg ;
2013-10-29 17:38:22 +00:00
msg = JCL_ParseOut ( msg , arg [ i ] , sizeof ( arg [ i ] ) ) ;
2017-10-12 12:02:25 +00:00
}
2005-12-11 20:11:22 +00:00
}
2013-06-29 16:01:07 +00:00
if ( arg [ 0 ] [ 0 ] = = ' / ' & & arg [ 0 ] [ 1 ] ! = ' / ' & & strcmp ( arg [ 0 ] + 1 , " me " ) )
2005-12-11 20:11:22 +00:00
{
2017-10-12 12:02:25 +00:00
if ( * console & & ! strcmp ( arg [ 0 ] + 1 , " ban " ) & & JCL_IsChatroom ( jcl , console ) )
{
char * roomnick = arg [ 1 ] ;
char * comment = arg [ 2 ] ;
char * jid ;
if ( strchr ( roomnick , ' @ ' ) )
jid = roomnick ;
else
{
Con_TrySubPrint ( console , " Unable to translate roomnicks. Please use their bare jid. \n " ) ;
return ; //FIXME: translate from roomnick to real barejid
}
JCL_SendIQf ( jcl , NULL , " set " , console ,
" <query xmlns='http://jabber.org/protocol/muc#admin'> "
" <item affiliation='outcast' jid='%s'> "
" <reason>%s</reason> "
" </item> "
" </query> "
, jid , comment
) ;
}
else if ( * console & & ! strcmp ( arg [ 0 ] + 1 , " invite " ) & & JCL_IsChatroom ( jcl , console ) )
{
char * jid = arg [ 1 ] ;
char * reason = arg [ 2 ] ;
JCL_AddClientMessagef ( jcl ,
" <message to='%s'> "
" <x xmlns='http://jabber.org/protocol/muc#user'> "
" <invite to='%s'> "
" <reason>%s</reason> "
" </invite> "
" </x> "
" </message> "
, console , jid , reason
) ;
}
else if ( * console & & ! strcmp ( arg [ 0 ] + 1 , " join " ) & & JCL_IsChatroom ( jcl , console ) )
{
char * room = arg [ 1 ] ;
char * nick = " " ;
char * pass = arg [ 2 ] ;
JCL_AddClientMessagef ( jcl ,
" <presence to='%s/%s'> "
" <x xmlns='http://jabber.org/protocol/muc#user'> "
" <password>%s</password> "
" </x> "
" </presence> "
, room , nick , pass
) ;
}
else if ( * console & & ! strcmp ( arg [ 0 ] + 1 , " kick " ) & & JCL_IsChatroom ( jcl , console ) )
{
char * roomnick = arg [ 1 ] ;
char * comment = arg [ 2 ] ;
JCL_SendIQf ( jcl , NULL , " set " , console ,
" <query xmlns='http://jabber.org/protocol/muc#admin'> "
" <item nick='%s' role='none'> "
" <reason>%s</reason> "
" </item> "
" </query> "
, roomnick , comment
) ;
}
else if ( * console & & ! strcmp ( arg [ 0 ] + 1 , " msg " ) & & JCL_IsChatroom ( jcl , console ) )
{
char * whom = arg [ 1 ] ;
char * msgtext = argstart [ 2 ] ;
JCL_AddClientMessagef ( jcl ,
" <message to='%s/%s' type='chat'> "
" <body>%s</body> "
" </message> "
, console , whom , msgtext
) ;
}
else if ( * console & & ! strcmp ( arg [ 0 ] + 1 , " nick " ) & & JCL_IsChatroom ( jcl , console ) )
{ //FIXME: needs escape
char * mynewnick = arg [ 1 ] ;
JCL_AddClientMessagef ( jcl ,
" <presence to='%s/%s'/> "
, console , mynewnick
) ;
}
else if ( * console & & ! strcmp ( arg [ 0 ] + 1 , " part " ) & & JCL_IsChatroom ( jcl , console ) )
{ //FIXME: escapes
buddy_t * b ;
char * myroomnick = " " ;
char * comment = argstart [ 1 ] ;
if ( JCL_FindBuddy ( jcl , console , & b , NULL , false ) )
if ( b & & b - > ourselves )
myroomnick = b - > ourselves - > resource ;
JCL_AddClientMessagef ( jcl ,
" <presence to='%s/%s' type='unavailable'> "
" <status>%s</status> "
" </presence> "
, console , myroomnick , comment
) ;
if ( b & & b - > btype = = BT_CHATROOM )
JCL_ForgetBuddy ( jcl , b , NULL ) ;
}
else if ( * console & & ! strcmp ( arg [ 0 ] + 1 , " topic " ) & & JCL_IsChatroom ( jcl , console ) )
{ //FIXME: escapes
char * newtopic = argstart [ 1 ] ;
JCL_AddClientMessagef ( jcl ,
" <message to='%s' type='groupchat'> "
" <subject>%s</subject> "
" </message> "
, console , newtopic
) ;
}
else if ( * console & & ! strcmp ( arg [ 0 ] + 1 , " userlist " ) & & JCL_IsChatroom ( jcl , console ) )
{
buddy_t * b ;
bresource_t * r ;
if ( JCL_FindBuddy ( jcl , console , & b , NULL , false ) )
{
Con_SubPrintf ( console , " Users on channel %s \n " , console ) ;
for ( r = b - > resources ; r ; r = r - > next )
{
Con_SubPrintf ( console , " %s: " , r - > resource ) ;
JCL_PrintBuddyStatus ( console , jcl , b , r ) ;
Con_SubPrintf ( console , " \n " ) ;
}
Con_SubPrintf ( console , " <END> \n " ) ;
}
}
else if ( ! strcmp ( arg [ 0 ] + 1 , " open " ) | | ! strcmp ( arg [ 0 ] + 1 , " connect " ) | | ! strcmp ( arg [ 0 ] + 1 , " autoopen " ) | | ! strcmp ( arg [ 0 ] + 1 , " autoconnect " ) | | ! strcmp ( arg [ 0 ] + 1 , " plainopen " ) | | ! strcmp ( arg [ 0 ] + 1 , " plainconnect " ) | | ! strcmp ( arg [ 0 ] + 1 , " tlsopen " ) | | ! strcmp ( arg [ 0 ] + 1 , " tlsconnect " ) )
2013-06-23 02:33:52 +00:00
{ //tlsconnect is 'old'.
2013-10-08 14:28:11 +00:00
int tls ;
2009-04-19 01:48:10 +00:00
if ( ! * arg [ 1 ] )
{
2013-10-29 17:38:22 +00:00
XMPP_Menu_Connect ( ) ;
2013-06-29 16:01:07 +00:00
Con_SubPrintf ( console , " %s <account@domain/resource> <password> <server> \n " , arg [ 0 ] + 1 ) ;
2009-04-19 01:48:10 +00:00
return ;
}
2013-07-13 12:14:32 +00:00
if ( jcl )
2005-12-11 20:11:22 +00:00
{
2013-06-23 02:33:52 +00:00
Con_TrySubPrint ( console , " You are already connected \n Please /quit first \n " ) ;
2005-12-11 20:11:22 +00:00
return ;
}
2013-10-08 14:28:11 +00:00
if ( ! strncmp ( arg [ 0 ] + 1 , " tls " , 3 ) )
tls = 2 ; //old initial-tls connect
else if ( ! strncmp ( arg [ 0 ] + 1 , " plain " , 5 ) )
tls = - 1 ; //don't bother with tls. at all.
else if ( ! strncmp ( arg [ 0 ] + 1 , " auto " , 4 ) )
tls = 0 ; //use tls if its available, but don't really care otherwise.
else
tls = 1 ; //require tls
jcl = jclients [ accid ] = JCL_Connect ( accid , arg [ 3 ] , tls , arg [ 1 ] , arg [ 2 ] ) ;
2013-07-13 12:14:32 +00:00
if ( ! jclients [ accid ] )
2009-04-19 01:48:10 +00:00
{
2013-06-23 02:33:52 +00:00
Con_TrySubPrint ( console , " Connect failed \n " ) ;
2009-04-19 01:48:10 +00:00
return ;
}
2021-06-21 13:36:30 +00:00
jclient_configdirty = true ;
2005-12-11 20:11:22 +00:00
}
2013-06-23 02:33:52 +00:00
else if ( ! strcmp ( arg [ 0 ] + 1 , " help " ) )
{
2013-07-13 12:14:32 +00:00
Con_TrySubPrint ( console , " ^[/ " COMMANDPREFIX " /connect USERNAME@DOMAIN/RESOURCE [PASSWORD] [XMPPSERVER]^] \n " ) ;
2019-09-04 07:59:40 +00:00
Con_TrySubPrint ( console , " eg for gmail: ^[/ " COMMANDPREFIX " /connect myusername@gmail.com^] (using oauth2) \n " ) ;
Con_TrySubPrint ( console , " eg for gmail: ^[/ " COMMANDPREFIX " /connect myusername@gmail.com mypassword^] (warning: password will be saved locally in plain text) \n " ) ;
// Con_TrySubPrint(console, "eg for facebook: ^[/" COMMANDPREFIX " /connect myusername@chat.facebook.com mypassword chat.facebook.com^]\n");
// Con_TrySubPrint(console, "eg for msn: ^[/" COMMANDPREFIX " /connect myusername@messanger.live.com mypassword^]\n");
2013-10-08 14:28:11 +00:00
Con_TrySubPrint ( console , " Note that this info will be used the next time you start quake. \n " ) ;
2013-06-23 02:33:52 +00:00
//small note:
//for the account 'me@example.com' the server to connect to can be displayed with:
//nslookup -querytype=SRV _xmpp-client._tcp.example.com
//srv resolving seems to be non-standard on each system, I don't like having to special case things.
Con_TrySubPrint ( console , " ^[/ " COMMANDPREFIX " /help^] \n "
" This text... \n " ) ;
Con_TrySubPrint ( console , " ^[/ " COMMANDPREFIX " /raw <XML STANZAS/>^] \n "
" For debug hackery. \n " ) ;
2014-04-20 02:18:51 +00:00
Con_TrySubPrint ( console , " ^[/ " COMMANDPREFIX " /friend accountname@domain friendlyname^] \n "
2013-06-23 02:33:52 +00:00
" Befriends accountname, and shows them in your various lists using the friendly name. Can also be used to rename friends. \n " ) ;
2014-04-20 02:18:51 +00:00
Con_TrySubPrint ( console , " ^[/ " COMMANDPREFIX " /unfriend accountname@domain^] \n "
2013-06-23 02:33:52 +00:00
" Ostracise your new best enemy. You will no longer see them and they won't be able to contact you. \n " ) ;
Con_TrySubPrint ( console , " ^[/ " COMMANDPREFIX " /blist^] \n "
" Show all your friends! Names are clickable and will begin conversations. \n " ) ;
Con_TrySubPrint ( console , " ^[/ " COMMANDPREFIX " /quit^] \n "
" Disconnect from the XMPP server, noone will be able to hear you scream. \n " ) ;
2014-04-20 02:18:51 +00:00
Con_TrySubPrint ( console , " ^[/ " COMMANDPREFIX " /join accountname@domain^] \n "
2013-06-29 16:01:07 +00:00
" Joins your friends game (they will be prompted). \n " ) ;
2014-04-20 02:18:51 +00:00
Con_TrySubPrint ( console , " ^[/ " COMMANDPREFIX " /invite accountname@domain^] \n "
2013-06-29 16:01:07 +00:00
" Invite someone to join your game (they will be prompted). \n " ) ;
2014-04-20 02:18:51 +00:00
Con_TrySubPrint ( console , " ^[/ " COMMANDPREFIX " /voice accountname@domain^] \n "
2013-06-29 16:01:07 +00:00
" Begin a bi-directional peer-to-peer voice conversation with someone (they will be prompted). \n " ) ;
2014-04-20 02:18:51 +00:00
Con_TrySubPrint ( console , " ^[/ " COMMANDPREFIX " /msg ACCOUNTNAME@domain \" your message goes here \" ^] \n "
2013-06-23 02:33:52 +00:00
" Sends a message to the named person. If given a resource postfix, your message will be sent only to that resource. \n " ) ;
Con_TrySubPrint ( console , " If no arguments, will print out your friends list. If no /command is used, the arguments will be sent as a message to the person you last sent a message to. \n " ) ;
}
else if ( ! strcmp ( arg [ 0 ] + 1 , " clear " ) )
{
//just clears the current console.
if ( * console )
{
2019-09-04 07:59:40 +00:00
confuncs - > Destroy ( console ) ;
2013-06-23 18:43:59 +00:00
Con_SubPrintf ( console , " " ) ;
2019-09-04 07:59:40 +00:00
if ( confuncs )
confuncs - > SetActive ( console ) ;
2013-06-23 02:33:52 +00:00
}
else
2019-09-04 07:59:40 +00:00
cmdfuncs - > AddText ( " \n clear \n " , true ) ;
2013-06-23 02:33:52 +00:00
}
2013-07-13 12:14:32 +00:00
else if ( ! jcl )
2013-06-29 16:01:07 +00:00
{
Con_SubPrintf ( console , " No account specified. Cannot %s \n " , arg [ 0 ] ) ;
}
2013-07-13 12:14:32 +00:00
else if ( ! strcmp ( arg [ 0 ] + 1 , " oa2token " ) )
{
2021-06-21 13:36:30 +00:00
jclient_configdirty = true ;
2017-09-20 11:27:13 +00:00
free ( jcl - > sasl . oauth2 . authtoken ) ;
jcl - > sasl . oauth2 . authtoken = strdup ( arg [ 1 ] ) ;
2013-07-13 12:14:32 +00:00
if ( jcl - > status = = JCL_INACTIVE )
jcl - > status = JCL_DEAD ;
}
2013-11-21 23:02:28 +00:00
else if ( ! strcmp ( arg [ 0 ] + 1 , " set " ) )
{
2021-06-21 13:36:30 +00:00
jclient_configdirty = true ;
2013-11-21 23:02:28 +00:00
if ( ! strcmp ( arg [ 1 ] , " savepassword " ) )
jcl - > savepassword = atoi ( arg [ 2 ] ) ;
else if ( ! strcmp ( arg [ 1 ] , " avatars " ) )
2017-09-20 11:27:13 +00:00
{
2013-11-21 23:02:28 +00:00
jcl - > enabledcapabilities = ( jcl - > enabledcapabilities & ~ CAP_AVATARS ) | ( atoi ( arg [ 2 ] ) ? CAP_AVATARS : 0 ) ;
2017-09-20 11:27:13 +00:00
JCL_GeneratePresence ( jcl , true ) ;
}
else if ( ! strcmp ( arg [ 1 ] , " ft " ) )
{
jcl - > enabledcapabilities = ( jcl - > enabledcapabilities & ~ CAP_SIFT ) | ( atoi ( arg [ 2 ] ) ? CAP_SIFT : 0 ) ;
JCL_GeneratePresence ( jcl , false ) ;
}
2013-11-21 23:02:28 +00:00
else if ( ! strcmp ( arg [ 1 ] , " debug " ) )
jcl - > streamdebug = atoi ( arg [ 2 ] ) ;
else if ( ! strcmp ( arg [ 1 ] , " resource " ) )
Q_strlcpy ( jcl - > resource , arg [ 2 ] , sizeof ( jcl - > resource ) ) ;
else
Con_SubPrintf ( console , " Sorry, setting not recognised. \n " , arg [ 0 ] ) ;
}
2013-10-29 17:38:22 +00:00
else if ( ! strcmp ( arg [ 0 ] + 1 , " password " ) )
{
2021-06-21 13:36:30 +00:00
jclient_configdirty = true ;
2017-09-20 11:27:13 +00:00
Q_strncpyz ( jcl - > sasl . password_plain , arg [ 1 ] , sizeof ( jcl - > sasl . password_plain ) ) ;
jcl - > sasl . password_hash_size = 0 ;
2013-10-29 17:38:22 +00:00
if ( jcl - > status = = JCL_INACTIVE )
jcl - > status = JCL_DEAD ;
}
2013-06-29 16:01:07 +00:00
else if ( ! strcmp ( arg [ 0 ] + 1 , " quit " ) )
{
//disconnect from the xmpp server.
2015-04-27 06:19:33 +00:00
JCL_CloseConnection ( jcl , " /quit " , false ) ;
2013-06-29 16:01:07 +00:00
}
2013-07-13 12:14:32 +00:00
else if ( jcl - > status ! = JCL_ACTIVE )
2013-06-29 16:01:07 +00:00
{
Con_SubPrintf ( console , " You are not authed. Please wait. \n " , arg [ 0 ] ) ;
}
else if ( ! strcmp ( arg [ 0 ] + 1 , " blist " ) )
{
//print out a full list of everyone, even those offline.
2013-07-13 12:14:32 +00:00
JCL_PrintBuddyList ( console , jcl , true ) ;
2013-06-29 16:01:07 +00:00
}
2005-12-11 20:11:22 +00:00
else if ( ! strcmp ( arg [ 0 ] + 1 , " msg " ) )
{
2013-06-23 02:33:52 +00:00
//FIXME: validate the dest. deal with xml markup in dest.
2013-07-13 12:14:32 +00:00
Q_strlcpy ( jcl - > defaultdest , arg [ 1 ] , sizeof ( jcl - > defaultdest ) ) ;
2005-12-11 20:11:22 +00:00
msg = arg [ 2 ] ;
2014-04-20 02:18:51 +00:00
//reparse the commands, so we get all trailing text
msg = imsg ;
msg = JCL_ParseOut ( msg , arg [ 0 ] , sizeof ( arg [ 0 ] ) ) ;
msg = JCL_ParseOut ( msg , arg [ 1 ] , sizeof ( arg [ 1 ] ) ) ;
while ( * msg = = ' ' )
2016-07-12 00:40:13 +00:00
msg + + ;
2014-04-20 02:18:51 +00:00
2013-07-13 12:14:32 +00:00
JCL_SendMessage ( jcl , jcl - > defaultdest , msg ) ;
2013-06-23 02:33:52 +00:00
}
else if ( ! strcmp ( arg [ 0 ] + 1 , " friend " ) )
{
2015-04-27 06:19:33 +00:00
XMPP_AddFriend ( jcl , arg [ 1 ] , arg [ 2 ] ) ;
2013-06-23 02:33:52 +00:00
}
else if ( ! strcmp ( arg [ 0 ] + 1 , " unfriend " ) )
{
2017-10-12 12:02:25 +00:00
buddy_t * b ;
if ( JCL_FindBuddy ( jcl , arg [ 1 ] , & b , NULL , false ) )
{
if ( b - > btype = = BT_CHATROOM )
JCL_ForgetBuddy ( jcl , b , NULL ) ;
else if ( b - > btype = = BT_ROSTER )
{
//hide from em
JCL_AddClientMessagef ( jcl , " <presence to='%s' type='unsubscribed'/> " , arg [ 1 ] ) ;
2013-06-23 02:33:52 +00:00
2017-10-12 12:02:25 +00:00
//stop looking for em
JCL_AddClientMessagef ( jcl , " <presence to='%s' type='unsubscribe'/> " , arg [ 1 ] ) ;
2013-06-23 02:33:52 +00:00
2017-10-12 12:02:25 +00:00
//stop listing em
JCL_SendIQf ( jcl , NULL , " set " , NULL , " <query xmlns='jabber:iq:roster'><item jid='%s' subscription='remove' /></query> " , arg [ 1 ] ) ;
}
else
JCL_AddClientMessagef ( jcl , " <presence to='%s' type='unavailable'/> " , arg [ 1 ] ) ;
}
2013-06-23 02:33:52 +00:00
}
2013-07-13 12:14:32 +00:00
# ifdef JINGLE
2013-06-23 02:33:52 +00:00
else if ( ! strcmp ( arg [ 0 ] + 1 , " join " ) )
{
2013-10-29 17:38:22 +00:00
JCL_ToJID ( jcl , * arg [ 1 ] ? arg [ 1 ] : console , nname , sizeof ( nname ) , true ) ;
2013-07-13 12:14:32 +00:00
JCL_Join ( jcl , nname , NULL , true , ICEP_QWCLIENT ) ;
2013-06-29 16:01:07 +00:00
}
else if ( ! strcmp ( arg [ 0 ] + 1 , " invite " ) )
{
2013-10-29 17:38:22 +00:00
JCL_ToJID ( jcl , * arg [ 1 ] ? arg [ 1 ] : console , nname , sizeof ( nname ) , true ) ;
2013-07-13 12:14:32 +00:00
JCL_Join ( jcl , nname , NULL , true , ICEP_QWSERVER ) ;
2013-06-29 16:01:07 +00:00
}
else if ( ! strcmp ( arg [ 0 ] + 1 , " voice " ) | | ! strcmp ( arg [ 0 ] + 1 , " call " ) )
{
2013-10-29 17:38:22 +00:00
JCL_ToJID ( jcl , * arg [ 1 ] ? arg [ 1 ] : console , nname , sizeof ( nname ) , true ) ;
2013-07-13 12:14:32 +00:00
JCL_Join ( jcl , nname , NULL , true , ICEP_VOICE ) ;
}
else if ( ! strcmp ( arg [ 0 ] + 1 , " kick " ) )
{
2013-10-29 17:38:22 +00:00
JCL_ToJID ( jcl , * arg [ 1 ] ? arg [ 1 ] : console , nname , sizeof ( nname ) , true ) ;
2013-07-13 12:14:32 +00:00
JCL_Join ( jcl , nname , NULL , false , ICEP_INVALID ) ;
}
# endif
# ifdef FILETRANSFERS
else if ( ! strcmp ( arg [ 0 ] + 1 , " sendfile " ) )
{
char * fname = arg [ 1 ] ;
2013-11-21 23:02:28 +00:00
if ( ! ( jcl - > enabledcapabilities & CAP_SIFT ) )
{
Con_SubPrintf ( console , " XMPP: file transfers are not enabled for this account. Edit your config. \n " ) ;
return ;
}
2013-07-13 12:14:32 +00:00
if ( ! * fname | | strchr ( fname , ' * ' ) )
{
Con_SubPrintf ( console , " XMPP: /sendfile FILENAME [to] \n " ) ;
return ;
}
else
{
2013-10-29 17:38:22 +00:00
JCL_ToJID ( jcl , * arg [ 2 ] ? arg [ 2 ] : console , nname , sizeof ( nname ) , true ) ;
2013-07-13 12:14:32 +00:00
2013-11-21 23:02:28 +00:00
XMPP_FT_SendFile ( jcl , console , nname , fname ) ;
2013-07-13 12:14:32 +00:00
}
}
# endif
else if ( ! strcmp ( arg [ 0 ] + 1 , " joinchatroom " ) | | ! strcmp ( arg [ 0 ] + 1 , " muc " ) | | ! strcmp ( arg [ 0 ] + 1 , " joinmuc " ) )
{
2017-10-12 12:02:25 +00:00
if ( ! * arg [ 1 ] )
Con_SubPrintf ( console , " xmpp %s room@server roomnick password \n " ) ;
else
JCL_JoinMUCChat ( jcl , arg [ 1 ] , NULL , * arg [ 2 ] ? arg [ 2 ] : NULL , arg [ 3 ] ) ;
2013-07-13 12:14:32 +00:00
}
else if ( ! strcmp ( arg [ 0 ] + 1 , " leavechatroom " ) | | ! strcmp ( arg [ 0 ] + 1 , " leavemuc " ) )
{
char roomserverhandle [ 512 ] ;
buddy_t * b ;
bresource_t * r ;
2021-08-05 16:49:25 +00:00
if ( ! Q_snprintfz ( roomserverhandle , sizeof ( roomserverhandle ) , " %s@%s/%s " , arg [ 1 ] , arg [ 2 ] , arg [ 3 ] ) & & JCL_FindBuddy ( jcl , roomserverhandle , & b , & r , false ) )
2013-11-21 23:02:28 +00:00
{
JCL_AddClientMessagef ( jcl , " <presence to='%s' type='unavailable'/> " , roomserverhandle ) ;
JCL_ForgetBuddy ( jcl , b , NULL ) ;
}
2013-06-29 21:08:09 +00:00
}
else if ( ! strcmp ( arg [ 0 ] + 1 , " slap " ) )
{
char * msgtab [ ] =
{
" /me slaps you around a bit with a large trout " ,
" /me slaps you around a bit with a large tunafish " ,
" /me slaps you around a bit with a slimy hagfish " ,
" /me slaps a large trout around a bit with your face " ,
" /me gets eaten by a rabid shark while trying to slap you with it " ,
" /me gets crushed under the weight of a large whale " ,
" /me searches for a fresh fish, but gets crabs instead " ,
" /me searches for a fish, but there are no more fish in the sea " ,
" /me tickles you around a bit with a large fish finger " ,
" /me goes to order cod and chips. brb " ,
" /me goes to watch some monty python "
} ;
2013-10-29 17:38:22 +00:00
JCL_ToJID ( jcl , * arg [ 1 ] ? arg [ 1 ] : console , nname , sizeof ( nname ) , true ) ;
2013-07-13 12:14:32 +00:00
JCL_AttentionMessage ( jcl , nname , msgtab [ rand ( ) % ( sizeof ( msgtab ) / sizeof ( msgtab [ 0 ] ) ) ] ) ;
2013-06-29 21:08:09 +00:00
}
else if ( ! strcmp ( arg [ 0 ] + 1 , " poke " ) )
{
2013-10-29 17:38:22 +00:00
JCL_ToJID ( jcl , * arg [ 1 ] ? arg [ 1 ] : console , nname , sizeof ( nname ) , true ) ;
2013-07-13 12:14:32 +00:00
JCL_AttentionMessage ( jcl , nname , NULL ) ;
2005-12-11 20:11:22 +00:00
}
2013-06-23 02:33:52 +00:00
else if ( ! strcmp ( arg [ 0 ] + 1 , " raw " ) )
2013-03-31 04:21:08 +00:00
{
2013-07-13 12:14:32 +00:00
//parse it first, so noone ever generates invalid xml and gets kicked... too obviously.
int pos = 0 ;
int maxpos = strlen ( arg [ 1 ] ) ;
xmltree_t * t ;
while ( pos ! = maxpos )
{
t = XML_Parse ( arg [ 1 ] , & pos , maxpos , false , " " ) ;
if ( t )
XML_Destroy ( t ) ;
else
break ;
}
if ( pos = = maxpos )
{
jcl - > streamdebug = true ;
JCL_AddClientMessageString ( jcl , arg [ 1 ] ) ;
}
else
Con_Printf ( " XML not well formed \n " ) ;
2013-03-31 04:21:08 +00:00
}
2005-12-11 20:11:22 +00:00
else
2013-06-23 02:33:52 +00:00
Con_SubPrintf ( console , " Unrecognised command: %s \n " , arg [ 0 ] ) ;
2005-12-11 20:11:22 +00:00
}
else
{
2015-04-27 06:19:33 +00:00
msg = imsg ;
2013-11-21 23:02:28 +00:00
if ( jcl & & jcl - > status = = JCL_ACTIVE )
2005-12-11 20:11:22 +00:00
{
2013-06-23 02:33:52 +00:00
if ( ! * msg )
{
if ( ! * console )
{
2019-09-04 07:59:40 +00:00
if ( confuncs )
2015-04-27 06:19:33 +00:00
JCL_RegenerateBuddyList ( true ) ;
else
JCL_PrintBuddyList ( console , jcl , false ) ;
2013-06-29 16:01:07 +00:00
//Con_TrySubPrint(console, "For help, type \"^[/" COMMANDPREFIX " /help^]\"\n");
2013-06-23 02:33:52 +00:00
}
}
else
{
2013-10-29 17:38:22 +00:00
JCL_ToJID ( jcl , * console ? console : jcl - > defaultdest , nname , sizeof ( nname ) , true ) ;
2013-07-13 12:14:32 +00:00
JCL_SendMessage ( jcl , nname , msg ) ;
2013-06-23 02:33:52 +00:00
}
2005-12-11 20:11:22 +00:00
}
else
2007-09-17 20:55:15 +00:00
{
2019-09-04 07:59:40 +00:00
if ( ! * msg & & confuncs )
2015-04-27 06:19:33 +00:00
JCL_RegenerateBuddyList ( true ) ;
else
Con_TrySubPrint ( console , " Not connected. For help, type \" ^[/ " COMMANDPREFIX " /help^] \" \n " ) ;
2007-09-17 20:55:15 +00:00
}
2005-12-11 20:11:22 +00:00
}
}