Changes in / [568aaf7:703f0f7]
- Files:
-
- 3 added
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
.bzrignore
r568aaf7 r703f0f7 8 8 build-arch-stamp 9 9 tags 10 decode 11 encode -
Makefile
r568aaf7 r703f0f7 10 10 11 11 # Program variables 12 objects = account.o bitlbee.o commands.o conf.o crypting.o help.o ini.o irc.o log.o nick.o query.o set.o unix.o url.o user.o 12 objects = account.o bitlbee.o commands.o conf.o crypting.o help.o ini.o irc.o log.o nick.o query.o set.o unix.o url.o user.o storage_text.o storage.o 13 13 subdirs = protocols 14 14 -
bitlbee.c
r568aaf7 r703f0f7 27 27 #include "bitlbee.h" 28 28 #include "commands.h" 29 #include "crypting.h"30 29 #include "protocols/nogaim.h" 31 30 #include "help.h" … … 244 243 } 245 244 246 /* DO NOT USE THIS FUNCTION IN NEW CODE. This247 * function is here merely because the save/load code still uses248 * ids rather then names */249 static struct prpl *find_protocol_by_id(int id)250 {251 switch (id) {252 case 1: return find_protocol("oscar");253 case 4: return find_protocol("msn");254 case 2: return find_protocol("yahoo");255 case 8: return find_protocol("jabber");256 default: break;257 }258 return NULL;259 }260 261 static int find_protocol_id(const char *name)262 {263 if (!strcmp(name, "oscar")) return 1;264 if (!strcmp(name, "msn")) return 4;265 if (!strcmp(name, "yahoo")) return 2;266 if (!strcmp(name, "jabber")) return 8;267 268 return -1;269 }270 271 int bitlbee_load( irc_t *irc, char* password )272 {273 char s[512];274 char *line;275 int proto;276 char nick[MAX_NICK_LENGTH+1];277 FILE *fp;278 user_t *ru = user_find( irc, ROOT_NICK );279 280 if( irc->status == USTATUS_IDENTIFIED )281 return( 1 );282 283 g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" );284 fp = fopen( s, "r" );285 if( !fp ) return( 0 );286 287 fscanf( fp, "%32[^\n]s", s );288 if( setpass( irc, password, s ) < 0 )289 {290 fclose( fp );291 return( -1 );292 }293 294 /* Do this now. If the user runs with AuthMode = Registered, the295 account command will not work otherwise. */296 irc->status = USTATUS_IDENTIFIED;297 298 while( fscanf( fp, "%511[^\n]s", s ) > 0 )299 {300 fgetc( fp );301 line = deobfucrypt( irc, s );302 root_command_string( irc, ru, line, 0 );303 g_free( line );304 }305 fclose( fp );306 307 g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks" );308 fp = fopen( s, "r" );309 if( !fp ) return( 0 );310 while( fscanf( fp, "%s %d %s", s, &proto, nick ) > 0 )311 {312 struct prpl *prpl;313 314 prpl = find_protocol_by_id(proto);315 316 if (!prpl)317 continue;318 319 http_decode( s );320 nick_set( irc, s, prpl, nick );321 }322 fclose( fp );323 324 if( set_getint( irc, "auto_connect" ) )325 {326 strcpy( s, "account on" ); /* Can't do this directly because r_c_s alters the string */327 root_command_string( irc, ru, s, 0 );328 }329 330 return( 1 );331 }332 333 int bitlbee_save( irc_t *irc )334 {335 char s[512];336 char path[512], new_path[512];337 char *line;338 nick_t *n;339 set_t *set;340 mode_t ou = umask( 0077 );341 account_t *a;342 FILE *fp;343 char *hash;344 345 /*\346 * [SH] Nothing should be saved if no password is set, because the347 * password is not set if it was wrong, or if one is not identified348 * yet. This means that a malicious user could easily overwrite349 * files owned by someone else:350 * a Bad Thing, methinks351 \*/352 353 /* [WVG] No? Really? */354 355 /*\356 * [SH] Okay, okay, it wasn't really Wilmer who said that, it was357 * me. I just thought it was funny.358 \*/359 360 hash = hashpass( irc );361 if( hash == NULL )362 {363 irc_usermsg( irc, "Please register yourself if you want to save your settings." );364 return( 0 );365 }366 367 g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks~" );368 fp = fopen( path, "w" );369 if( !fp ) return( 0 );370 for( n = irc->nicks; n; n = n->next )371 {372 strcpy( s, n->handle );373 s[169] = 0; /* Prevent any overflow (169 ~ 512 / 3) */374 http_encode( s );375 g_snprintf( s + strlen( s ), 510 - strlen( s ), " %d %s", find_protocol_id(n->proto->name), n->nick );376 if( fprintf( fp, "%s\n", s ) != strlen( s ) + 1 )377 {378 irc_usermsg( irc, "fprintf() wrote too little. Disk full?" );379 fclose( fp );380 return( 0 );381 }382 }383 if( fclose( fp ) != 0 )384 {385 irc_usermsg( irc, "fclose() reported an error. Disk full?" );386 return( 0 );387 }388 389 g_snprintf( new_path, 512, "%s%s%s", global.conf->configdir, irc->nick, ".nicks" );390 if( unlink( new_path ) != 0 )391 {392 if( errno != ENOENT )393 {394 irc_usermsg( irc, "Error while removing old .nicks file" );395 return( 0 );396 }397 }398 if( rename( path, new_path ) != 0 )399 {400 irc_usermsg( irc, "Error while renaming new .nicks file" );401 return( 0 );402 }403 404 g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts~" );405 fp = fopen( path, "w" );406 if( !fp ) return( 0 );407 if( fprintf( fp, "%s", hash ) != strlen( hash ) )408 {409 irc_usermsg( irc, "fprintf() wrote too little. Disk full?" );410 fclose( fp );411 return( 0 );412 }413 g_free( hash );414 415 for( a = irc->accounts; a; a = a->next )416 {417 if( !strcmp( a->prpl->name, "oscar" ) )418 g_snprintf( s, sizeof( s ), "account add oscar \"%s\" \"%s\" %s", a->user, a->pass, a->server );419 else420 g_snprintf( s, sizeof( s ), "account add %s \"%s\" \"%s\" \"%s\"",421 a->prpl->name, a->user, a->pass, a->server ? a->server : "" );422 423 line = obfucrypt( irc, s );424 if( *line )425 {426 if( fprintf( fp, "%s\n", line ) != strlen( line ) + 1 )427 {428 irc_usermsg( irc, "fprintf() wrote too little. Disk full?" );429 fclose( fp );430 return( 0 );431 }432 }433 g_free( line );434 }435 436 for( set = irc->set; set; set = set->next )437 {438 if( set->value && set->def )439 {440 g_snprintf( s, sizeof( s ), "set %s \"%s\"", set->key, set->value );441 line = obfucrypt( irc, s );442 if( *line )443 {444 if( fprintf( fp, "%s\n", line ) != strlen( line ) + 1 )445 {446 irc_usermsg( irc, "fprintf() wrote too little. Disk full?" );447 fclose( fp );448 return( 0 );449 }450 }451 g_free( line );452 }453 }454 455 if( strcmp( irc->mynick, ROOT_NICK ) != 0 )456 {457 g_snprintf( s, sizeof( s ), "rename %s %s", ROOT_NICK, irc->mynick );458 line = obfucrypt( irc, s );459 if( *line )460 {461 if( fprintf( fp, "%s\n", line ) != strlen( line ) + 1 )462 {463 irc_usermsg( irc, "fprintf() wrote too little. Disk full?" );464 fclose( fp );465 return( 0 );466 }467 }468 g_free( line );469 }470 if( fclose( fp ) != 0 )471 {472 irc_usermsg( irc, "fclose() reported an error. Disk full?" );473 return( 0 );474 }475 476 g_snprintf( new_path, 512, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" );477 if( unlink( new_path ) != 0 )478 {479 if( errno != ENOENT )480 {481 irc_usermsg( irc, "Error while removing old .accounts file" );482 return( 0 );483 }484 }485 if( rename( path, new_path ) != 0 )486 {487 irc_usermsg( irc, "Error while renaming new .accounts file" );488 return( 0 );489 }490 491 umask( ou );492 493 return( 1 );494 }495 496 245 void bitlbee_shutdown( gpointer data ) 497 246 { -
bitlbee.h
r568aaf7 r703f0f7 30 30 31 31 #define PACKAGE "BitlBee" 32 #define BITLBEE_VERSION " 1.0"32 #define BITLBEE_VERSION "BZR" 33 33 #define VERSION BITLBEE_VERSION 34 34 … … 100 100 101 101 #include "irc.h" 102 #include "storage.h" 102 103 #include "set.h" 103 104 #include "protocols/nogaim.h" … … 115 116 help_t *help; 116 117 conf_t *conf; 118 GList *storage; /* The first backend in the list will be used for saving */ 117 119 char *helpfile; 118 120 GMainLoop *loop; … … 127 129 int root_command_string( irc_t *irc, user_t *u, char *command, int flags ); 128 130 int root_command( irc_t *irc, char *command[] ); 129 int bitlbee_load( irc_t *irc, char *password );130 int bitlbee_save( irc_t *irc );131 131 void bitlbee_shutdown( gpointer data ); 132 132 double gettime( void ); -
commands.c
r568aaf7 r703f0f7 86 86 int cmd_identify( irc_t *irc, char **cmd ) 87 87 { 88 int checkie = bitlbee_load( irc, cmd[1]);89 90 if( checkie == -1 )91 {88 storage_status_t status = storage_load( irc->nick, cmd[1], irc ); 89 90 switch (status) { 91 case STORAGE_INVALID_PASSWORD: 92 92 irc_usermsg( irc, "Incorrect password" ); 93 } 94 else if( checkie == 0 ) 95 { 93 break; 94 case STORAGE_NO_SUCH_USER: 96 95 irc_usermsg( irc, "The nick is (probably) not registered" ); 97 } 98 else if( checkie == 1 ) 99 { 96 break; 97 case STORAGE_OK: 100 98 irc_usermsg( irc, "Password accepted" ); 101 } 102 else 103 { 99 break; 100 default: 104 101 irc_usermsg( irc, "Something very weird happened" ); 105 } 106 102 break; 103 } 104 107 105 return( 0 ); 108 106 } … … 110 108 int cmd_register( irc_t *irc, char **cmd ) 111 109 { 112 int checkie;113 char path[512];114 115 110 if( global.conf->authmode == AUTHMODE_REGISTERED ) 116 111 { … … 118 113 return( 0 ); 119 114 } 120 121 g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" ); 122 checkie = access( path, F_OK ); 123 124 g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks" ); 125 checkie += access( path, F_OK ); 126 127 if( checkie == -2 ) 128 { 129 setpassnc( irc, cmd[1] ); 130 root_command_string( irc, user_find( irc, irc->mynick ), "save", 0 ); 131 irc->status = USTATUS_IDENTIFIED; 132 } 133 else 134 { 135 irc_usermsg( irc, "Nick is already registered" ); 115 116 irc_setpass( irc, cmd[1] ); 117 switch( storage_save( irc, FALSE )) { 118 case STORAGE_ALREADY_EXISTS: 119 irc_usermsg( irc, "Nick is already registered" ); 120 break; 121 122 case STORAGE_OK: 123 irc->status = USTATUS_IDENTIFIED; 124 break; 125 126 default: 127 irc_usermsg( irc, "Error registering" ); 128 break; 136 129 } 137 130 … … 141 134 int cmd_drop( irc_t *irc, char **cmd ) 142 135 { 143 char s[512]; 144 FILE *fp; 145 146 g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" ); 147 fp = fopen( s, "r" ); 148 if( !fp ) 149 { 136 storage_status_t status; 137 138 status = storage_remove (irc->nick, cmd[1]); 139 switch (status) { 140 case STORAGE_NO_SUCH_USER: 150 141 irc_usermsg( irc, "That account does not exist" ); 151 142 return( 0 ); 152 } 153 154 fscanf( fp, "%32[^\n]s", s ); 155 fclose( fp ); 156 if( setpass( irc, cmd[1], s ) < 0 ) 157 { 158 irc_usermsg( irc, "Incorrect password" ); 159 return( 0 ); 160 } 161 162 g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" ); 163 unlink( s ); 164 165 g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks" ); 166 unlink( s ); 167 168 setpassnc( irc, NULL ); 169 irc_usermsg( irc, "Files belonging to account `%s' removed", irc->nick ); 170 171 return( 0 ); 143 case STORAGE_INVALID_PASSWORD: 144 irc_usermsg( irc, "Password invalid" ); 145 return( 0 ); 146 case STORAGE_OK: 147 irc_setpass( irc, NULL ); 148 irc_usermsg( irc, "Account `%s' removed", irc->nick ); 149 return( 0 ); 150 default: 151 irc_usermsg( irc, "Error: '%d'", status ); 152 return( 0 ); 153 } 172 154 } 173 155 … … 623 605 int cmd_save( irc_t *irc, char **cmd ) 624 606 { 625 if( bitlbee_save( irc ))607 if( storage_save( irc, TRUE ) == STORAGE_OK ) 626 608 irc_usermsg( irc, "Configuration saved" ); 627 609 else -
conf.c
r568aaf7 r703f0f7 50 50 conf->nofork = 0; 51 51 conf->verbose = 0; 52 conf->primary_storage = "text"; 52 53 conf->runmode = RUNMODE_INETD; 53 54 conf->authmode = AUTHMODE_OPEN; … … 198 199 conf->motdfile = g_strdup( ini->value ); 199 200 } 201 else if( g_strcasecmp( ini->key, "account_storage" ) == 0 ) 202 { 203 g_free( conf->primary_storage ); 204 conf->primary_storage = g_strdup( ini->value ); 205 } 206 else if( g_strcasecmp( ini->key, "account_storage_migrate" ) == 0 ) 207 { 208 g_strfreev( conf->migrate_storage ); 209 conf->migrate_storage = g_strsplit( ini->value, " \t,;", -1 ); 210 } 200 211 else if( g_strcasecmp( ini->key, "pinginterval" ) == 0 ) 201 212 { -
conf.h
r568aaf7 r703f0f7 42 42 char *configdir; 43 43 char *motdfile; 44 char *primary_storage; 45 char **migrate_storage; 44 46 int ping_interval; 45 47 int ping_timeout; -
crypting.c
r568aaf7 r703f0f7 29 29 the programs will be built. */ 30 30 31 #ifndef CRYPTING_MAIN32 #define BITLBEE_CORE33 #include "bitlbee.h"34 #include "irc.h"35 31 #include "md5.h" 36 32 #include "crypting.h" … … 38 34 #include <stdio.h> 39 35 #include <stdlib.h> 40 41 #else42 43 typedef struct irc44 {45 char *password;46 } irc_t;47 48 #define set_add( a, b, c, d )49 #define set_find( a, b ) NULL50 51 #include "md5.h"52 #include "crypting.h"53 #include <string.h>54 #include <stdio.h>55 #include <stdlib.h>56 57 #define irc_usermsg58 59 #endif60 36 61 37 /*\ … … 65 41 \*/ 66 42 67 /* USE WITH CAUTION! 68 Sets pass without checking */ 69 void setpassnc (irc_t *irc, char *pass) { 70 if (!set_find (irc, "password")) 71 set_add (irc, "password", NULL, passchange); 72 73 if (irc->password) g_free (irc->password); 74 75 if (pass) { 76 irc->password = g_strdup (pass); 77 irc_usermsg (irc, "Password successfully changed"); 78 } else { 79 irc->password = NULL; 80 } 81 } 82 83 char *passchange (irc_t *irc, void *set, char *value) { 84 setpassnc (irc, value); 85 return (NULL); 86 } 87 88 int setpass (irc_t *irc, char *pass, char* md5sum) { 43 int checkpass (const char *pass, const char *md5sum) 44 { 89 45 md5_state_t md5state; 90 46 md5_byte_t digest[16]; … … 103 59 if (digits[1] != md5sum[j + 1]) return (-1); 104 60 } 105 106 /* If pass is correct, we end up here and we set the pass */ 107 setpassnc (irc, pass); 108 109 return (0); 61 62 return( 0 ); 110 63 } 111 64 112 char *hashpass (irc_t *irc) { 65 66 char *hashpass (const char *password) 67 { 113 68 md5_state_t md5state; 114 69 md5_byte_t digest[16]; … … 117 72 char *rv; 118 73 119 if ( irc->password == NULL) return (NULL);74 if (password == NULL) return (NULL); 120 75 121 rv = (char *)g_malloc (33); 122 memset (rv, 0, 33); 76 rv = g_new0 (char, 33); 123 77 124 78 md5_init (&md5state); 125 md5_append (&md5state, ( unsigned char *)irc->password, strlen (irc->password));79 md5_append (&md5state, (const unsigned char *)password, strlen (password)); 126 80 md5_finish (&md5state, digest); 127 81 … … 135 89 } 136 90 137 char *obfucrypt (irc_t *irc, char *line) { 91 char *obfucrypt (char *line, const char *password) 92 { 138 93 int i, j; 139 94 char *rv; 140 95 141 if ( irc->password == NULL) return (NULL);96 if (password == NULL) return (NULL); 142 97 143 rv = (char *)g_malloc (strlen (line) + 1); 144 memset (rv, '\0', strlen (line) + 1); 98 rv = g_new0 (char, strlen (line) + 1); 145 99 146 100 i = j = 0; … … 148 102 /* Encrypt/obfuscate the line, using the password */ 149 103 if (*(signed char*)line < 0) *line = - (*line); 150 if (((signed char*)irc->password)[i] < 0) irc->password[i] = - irc->password[i];151 104 152 rv[j] = *line + irc->password[i]; /* Overflow intended */105 rv[j] = *line + password[i]; /* Overflow intended */ 153 106 154 107 line++; 155 if (! irc->password[++i]) i = 0;108 if (!password[++i]) i = 0; 156 109 j++; 157 110 } … … 160 113 } 161 114 162 char *deobfucrypt (irc_t *irc, char *line) { 115 char *deobfucrypt (char *line, const char *password) 116 { 163 117 int i, j; 164 118 char *rv; 165 119 166 if ( irc->password == NULL) return (NULL);120 if (password == NULL) return (NULL); 167 121 168 rv = (char *)g_malloc (strlen (line) + 1); 169 memset (rv, '\0', strlen (line) + 1); 122 rv = g_new0 (char, strlen (line) + 1); 170 123 171 124 i = j = 0; 172 125 while (*line) { 173 126 /* Decrypt/deobfuscate the line, using the pass */ 174 rv[j] = *line - irc->password[i]; /* Overflow intended */127 rv[j] = *line - password[i]; /* Overflow intended */ 175 128 176 129 line++; 177 if (! irc->password[++i]) i = 0;130 if (!password[++i]) i = 0; 178 131 j++; 179 132 } … … 189 142 int main( int argc, char *argv[] ) 190 143 { 191 irc_t *irc = g_malloc( sizeof( irc_t ) );192 144 char *hash, *action, line[256]; 193 char* (*func)( irc_t *,char * );145 char* (*func)( char *, const char * ); 194 146 195 147 if( argc < 2 ) … … 201 153 } 202 154 203 memset( irc, 0, sizeof( irc_t ) ); 204 irc->password = g_strdup( argv[1] ); 205 206 hash = hashpass( irc ); 155 hash = hashpass( argv[1] ); 207 156 action = argv[0] + strlen( argv[0] ) - strlen( "encode" ); 208 157 … … 236 185 fgetc( stdin ); 237 186 238 out = func( irc, line);187 out = func( line, argv[1] ); 239 188 printf( "%s\n", out ); 240 189 g_free( out ); -
crypting.h
r568aaf7 r703f0f7 24 24 */ 25 25 26 void setpassnc (irc_t *irc, char *pass); /* USE WITH CAUTION! */ 27 char *passchange (irc_t *irc, void *set, char *value); 28 int setpass (irc_t *irc, char *pass, char* md5sum); 29 char *hashpass (irc_t *irc); 30 char *obfucrypt (irc_t *irc, char *line); 31 char *deobfucrypt (irc_t *irc, char *line); 26 int checkpass (const char *password, const char *md5sum); 27 char *hashpass (const char *password); 28 char *obfucrypt (char *line, const char *password); 29 char *deobfucrypt (char *line, const char *password); -
irc.c
r568aaf7 r703f0f7 31 31 32 32 GSList *irc_connection_list = NULL; 33 34 static char *passchange (irc_t *irc, void *set, char *value) 35 { 36 irc_setpass (irc, value); 37 return (NULL); 38 } 33 39 34 40 irc_t *irc_new( int fd ) … … 129 135 set_add( irc, "to_char", ": ", set_eval_to_char ); 130 136 set_add( irc, "typing_notice", "false", set_eval_bool ); 137 set_add( irc, "password", NULL, passchange); 131 138 132 139 conf_loaddefaults( irc ); … … 154 161 155 162 if( irc->status >= USTATUS_IDENTIFIED && set_getint( irc, "save_on_quit" ) ) 156 if( !bitlbee_save( irc ))163 if( storage_save( irc, TRUE ) != STORAGE_OK ) 157 164 irc_usermsg( irc, "Error while saving settings!" ); 158 165 … … 259 266 if( global.conf->runmode == RUNMODE_INETD ) 260 267 g_main_quit( global.loop ); 268 } 269 270 /* USE WITH CAUTION! 271 Sets pass without checking */ 272 void irc_setpass (irc_t *irc, const char *pass) 273 { 274 if (irc->password) g_free (irc->password); 275 276 if (pass) { 277 irc->password = g_strdup (pass); 278 irc_usermsg (irc, "Password successfully changed"); 279 } else { 280 irc->password = NULL; 281 } 261 282 } 262 283 -
irc.h
r568aaf7 r703f0f7 137 137 void irc_whois( irc_t *irc, char *nick ); 138 138 int irc_away( irc_t *irc, char *away ); 139 void irc_setpass( irc_t *irc, const char *pass ); /* USE WITH CAUTION! */ 139 140 140 141 int irc_send( irc_t *irc, char *nick, char *s, int flags ); -
nick.c
r568aaf7 r703f0f7 27 27 #include "bitlbee.h" 28 28 29 void nick_set( irc_t *irc, c har *handle, struct prpl *proto,char *nick )29 void nick_set( irc_t *irc, const char *handle, struct prpl *proto, const char *nick ) 30 30 { 31 31 nick_t *m = NULL, *n = irc->nicks; … … 56 56 } 57 57 58 char *nick_get( irc_t *irc, c har *handle, struct prpl *proto, const char *realname )58 char *nick_get( irc_t *irc, const char *handle, struct prpl *proto, const char *realname ) 59 59 { 60 60 static char nick[MAX_NICK_LENGTH+1]; … … 129 129 } 130 130 131 void nick_del( irc_t *irc, c har *nick )131 void nick_del( irc_t *irc, const char *nick ) 132 132 { 133 133 nick_t *l = NULL, *n = irc->nicks; … … 176 176 } 177 177 178 int nick_ok( c har *nick )179 { 180 c har *s;178 int nick_ok( const char *nick ) 179 { 180 const char *s; 181 181 182 182 /* Empty/long nicks are not allowed */ … … 237 237 } 238 238 239 int nick_cmp( c har *a,char *b )239 int nick_cmp( const char *a, const char *b ) 240 240 { 241 241 char aa[1024] = "", bb[1024] = ""; … … 253 253 } 254 254 255 char *nick_dup( char *nick ) 256 { 257 char *cp; 258 259 cp = g_new0 ( char, MAX_NICK_LENGTH + 1 ); 260 strncpy( cp, nick, MAX_NICK_LENGTH ); 261 262 return( cp ); 263 } 255 char *nick_dup( const char *nick ) 256 { 257 return g_strndup( nick, MAX_NICK_LENGTH ); 258 } -
nick.h
r568aaf7 r703f0f7 32 32 } nick_t; 33 33 34 void nick_set( irc_t *irc, c har *handle, struct prpl *proto,char *nick );35 char *nick_get( irc_t *irc, c har *handle, struct prpl *proto, const char *realname );36 void nick_del( irc_t *irc, c har *nick );34 void nick_set( irc_t *irc, const char *handle, struct prpl *proto, const char *nick ); 35 char *nick_get( irc_t *irc, const char *handle, struct prpl *proto, const char *realname ); 36 void nick_del( irc_t *irc, const char *nick ); 37 37 void nick_strip( char *nick ); 38 38 39 int nick_ok( c har *nick );39 int nick_ok( const char *nick ); 40 40 int nick_lc( char *nick ); 41 41 int nick_uc( char *nick ); 42 int nick_cmp( c har *a,char *b );43 char *nick_dup( c har *nick );42 int nick_cmp( const char *a, const char *b ); 43 char *nick_dup( const char *nick ); -
protocols/msn/sb.c
r568aaf7 r703f0f7 644 644 if( who ) 645 645 { 646 serv_got_typing( gc, who, 5 );646 serv_got_typing( gc, who, 5, 1 ); 647 647 g_free( who ); 648 648 } -
protocols/nogaim.c
r568aaf7 r703f0f7 768 768 } 769 769 770 void serv_got_typing( struct gaim_connection *gc, char *handle, int timeout )770 void serv_got_typing( struct gaim_connection *gc, char *handle, int timeout, int type ) 771 771 { 772 772 user_t *u; … … 775 775 return; 776 776 777 if( ( u = user_findhandle( gc, handle ) ) ) 778 irc_privmsg( gc->irc, u, "PRIVMSG", gc->irc->nick, NULL, "\1TYPING 1\1" ); 777 if( ( u = user_findhandle( gc, handle ) ) ) { 778 /* If type is: 779 * 0: user has stopped typing 780 * 1: user is actively typing 781 * 2: user has entered text, but is not actively typing 782 */ 783 if (type == 0 || type == 1 || type == 2) { 784 char buf[256]; 785 g_snprintf(buf, 256, "\1TYPING %d\1", type); 786 irc_privmsg( gc->irc, u, "PRIVMSG", gc->irc->nick, NULL, buf ); 787 } 788 } 779 789 } 780 790 -
protocols/nogaim.h
r568aaf7 r703f0f7 283 283 G_MODULE_EXPORT void serv_got_update( struct gaim_connection *gc, char *handle, int loggedin, int evil, time_t signon, time_t idle, int type, guint caps ); 284 284 G_MODULE_EXPORT void serv_got_im( struct gaim_connection *gc, char *handle, char *msg, guint32 flags, time_t mtime, gint len ); 285 G_MODULE_EXPORT void serv_got_typing( struct gaim_connection *gc, char *handle, int timeout );285 G_MODULE_EXPORT void serv_got_typing( struct gaim_connection *gc, char *handle, int timeout, int type ); 286 286 G_MODULE_EXPORT void serv_got_chat_invite( struct gaim_connection *gc, char *handle, char *who, char *msg, GList *data ); 287 287 G_MODULE_EXPORT struct conversation *serv_got_joined_chat( struct gaim_connection *gc, int id, char *handle ); -
protocols/oscar/aim.h
r568aaf7 r703f0f7 466 466 int aim_addtlvtochain_caps(aim_tlvlist_t **list, const guint16 t, const guint32 caps); 467 467 int aim_addtlvtochain_noval(aim_tlvlist_t **list, const guint16 type); 468 int aim_addtlvtochain_chatroom(aim_tlvlist_t **list, guint16 type, guint16 exchange, const char *roomname, guint16 instance); 468 469 int aim_addtlvtochain_userinfo(aim_tlvlist_t **list, guint16 type, aim_userinfo_t *ui); 469 470 int aim_addtlvtochain_frozentlvlist(aim_tlvlist_t **list, guint16 type, aim_tlvlist_t **tl); … … 572 573 }; 573 574 575 struct aim_chat_invitation { 576 struct gaim_connection * gc; 577 char * name; 578 guint8 exchange; 579 }; 574 580 575 581 #define AIM_VISIBILITYCHANGE_PERMITADD 0x05 -
protocols/oscar/chat.c
r568aaf7 r703f0f7 180 180 181 181 aim_tx_enqueue(sess, fr); 182 183 return 0;184 }185 186 static int aim_addtlvtochain_chatroom(aim_tlvlist_t **list, guint16 type, guint16 exchange, const char *roomname, guint16 instance)187 {188 guint8 *buf;189 int buflen;190 aim_bstream_t bs;191 192 buflen = 2 + 1 + strlen(roomname) + 2;193 194 if (!(buf = g_malloc(buflen)))195 return 0;196 197 aim_bstream_init(&bs, buf, buflen);198 199 aimbs_put16(&bs, exchange);200 aimbs_put8(&bs, strlen(roomname));201 aimbs_putraw(&bs, (guint8 *)roomname, strlen(roomname));202 aimbs_put16(&bs, instance);203 204 aim_addtlvtochain_raw(list, type, aim_bstream_curpos(&bs), buf);205 206 g_free(buf);207 182 208 183 return 0; -
protocols/oscar/im.c
r568aaf7 r703f0f7 1369 1369 } 1370 1370 1371 1372 static void incomingim_ch2_chat_free(aim_session_t *sess, struct aim_incomingim_ch2_args *args) 1373 { 1374 1375 /* XXX aim_chat_roominfo_free() */ 1376 g_free(args->info.chat.roominfo.name); 1377 1378 return; 1379 } 1380 1381 static void incomingim_ch2_chat(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_userinfo_t *userinfo, struct aim_incomingim_ch2_args *args, aim_bstream_t *servdata) 1382 { 1383 1384 /* 1385 * Chat room info. 1386 */ 1387 if (servdata) 1388 aim_chat_readroominfo(servdata, &args->info.chat.roominfo); 1389 1390 args->destructor = (void *)incomingim_ch2_chat_free; 1391 1392 return; 1393 } 1394 1371 1395 static void incomingim_ch2_icqserverrelay_free(aim_session_t *sess, struct aim_incomingim_ch2_args *args) 1372 1396 { … … 1617 1641 if (args.reqclass & AIM_CAPS_ICQSERVERRELAY) 1618 1642 incomingim_ch2_icqserverrelay(sess, mod, rx, snac, userinfo, &args, sdbsptr); 1643 else if (args.reqclass & AIM_CAPS_CHAT) 1644 incomingim_ch2_chat(sess, mod, rx, snac, userinfo, &args, sdbsptr); 1619 1645 1620 1646 -
protocols/oscar/oscar.c
r568aaf7 r703f0f7 62 62 static int gaim_caps = AIM_CAPS_UTF8; */ 63 63 64 static int gaim_caps = AIM_CAPS_INTEROP | AIM_CAPS_ICHAT | AIM_CAPS_ICQSERVERRELAY ;64 static int gaim_caps = AIM_CAPS_INTEROP | AIM_CAPS_ICHAT | AIM_CAPS_ICQSERVERRELAY | AIM_CAPS_CHAT; 65 65 static guint8 gaim_features[] = {0x01, 0x01, 0x01, 0x02}; 66 66 … … 156 156 } 157 157 158 #if 0159 158 static struct chat_connection *find_oscar_chat(struct gaim_connection *gc, int id) { 160 159 GSList *g = ((struct oscar_data *)gc->proto_data)->oscar_chats; … … 171 170 return c; 172 171 } 173 #endif 172 174 173 175 174 static struct chat_connection *find_oscar_chat_by_conn(struct gaim_connection *gc, … … 1074 1073 } 1075 1074 1075 void oscar_accept_chat(gpointer w, struct aim_chat_invitation * inv); 1076 void oscar_reject_chat(gpointer w, struct aim_chat_invitation * inv); 1077 1076 1078 static int incomingim_chan2(aim_session_t *sess, aim_conn_t *conn, aim_userinfo_t *userinfo, struct aim_incomingim_ch2_args *args) { 1077 #if 01078 1079 struct gaim_connection *gc = sess->aux_data; 1079 #endif1080 1080 1081 1081 if (args->status != AIM_RENDEZVOUS_PROPOSE) 1082 1082 return 1; 1083 #if 0 1083 1084 1084 if (args->reqclass & AIM_CAPS_CHAT) { 1085 1085 char *name = extract_name(args->info.chat.roominfo.name); … … 1089 1089 *exch = args->info.chat.roominfo.exchange; 1090 1090 m = g_list_append(m, exch); 1091 serv_got_chat_invite(gc, 1092 name ? name : args->info.chat.roominfo.name, 1093 userinfo->sn, 1094 (char *)args->msg, 1095 m); 1091 1092 char txt[1024]; 1093 1094 g_snprintf( txt, 1024, "Got an invitation to chatroom %s from %s: %s", name, userinfo->sn, args->msg ); 1095 1096 struct aim_chat_invitation * inv = g_new0(struct aim_chat_invitation, 1); 1097 1098 inv->gc = gc; 1099 inv->exchange = *exch; 1100 inv->name = g_strdup(name); 1101 1102 do_ask_dialog( gc, txt, inv, oscar_accept_chat, oscar_reject_chat); 1103 1096 1104 if (name) 1097 1105 g_free(name); 1098 1106 } 1099 #endif 1107 1100 1108 return 1; 1101 1109 } … … 2441 2449 type2 = va_arg(ap, int); 2442 2450 va_end(ap); 2443 2444 if(type2 == 0x0001 || type2 == 0x0002) 2445 serv_got_typing(gc, sn, 0); 2446 2451 2452 if(type2 == 0x0002) { 2453 /* User is typing */ 2454 serv_got_typing(gc, sn, 0, 1); 2455 } 2456 else if (type2 == 0x0001) { 2457 /* User has typed something, but is not actively typing (stale) */ 2458 serv_got_typing(gc, sn, 0, 2); 2459 } 2460 else { 2461 /* User has stopped typing */ 2462 serv_got_typing(gc, sn, 0, 0); 2463 } 2464 2447 2465 return 1; 2448 2466 } … … 2482 2500 } 2483 2501 2502 int oscar_chat_send(struct gaim_connection * gc, int id, char *message) 2503 { 2504 struct oscar_data * od = (struct oscar_data*)gc->proto_data; 2505 struct chat_connection * ccon; 2506 2507 if(!(ccon = find_oscar_chat(gc, id))) 2508 return -1; 2509 2510 int ret; 2511 guint8 len = strlen(message); 2512 char *s; 2513 2514 for (s = message; *s; s++) 2515 if (*s & 128) 2516 break; 2517 2518 /* Message contains high ASCII chars, time for some translation! */ 2519 if (*s) { 2520 s = g_malloc(BUF_LONG); 2521 /* Try if we can put it in an ISO8859-1 string first. 2522 If we can't, fall back to UTF16. */ 2523 if ((ret = do_iconv("UTF-8", "ISO8859-1", message, s, len, BUF_LONG)) >= 0) { 2524 len = ret; 2525 } else if ((ret = do_iconv("UTF-8", "UNICODEBIG", message, s, len, BUF_LONG)) >= 0) { 2526 len = ret; 2527 } else { 2528 /* OOF, translation failed... Oh well.. */ 2529 g_free( s ); 2530 s = message; 2531 } 2532 } else { 2533 s = message; 2534 } 2535 2536 ret = aim_chat_send_im(od->sess, ccon->conn, AIM_CHATFLAGS_NOREFLECT, s, len); 2537 2538 if (s != message) { 2539 g_free(s); 2540 } 2541 2542 return (ret >= 0); 2543 } 2544 2545 void oscar_chat_invite(struct gaim_connection * gc, int id, char *message, char *who) 2546 { 2547 struct oscar_data * od = (struct oscar_data *)gc->proto_data; 2548 struct chat_connection *ccon = find_oscar_chat(gc, id); 2549 2550 if (ccon == NULL) 2551 return; 2552 2553 aim_chat_invite(od->sess, od->conn, who, message ? message : "", 2554 ccon->exchange, ccon->name, 0x0); 2555 } 2556 2557 void oscar_chat_kill(struct gaim_connection *gc, struct chat_connection *cc) 2558 { 2559 struct oscar_data *od = (struct oscar_data *)gc->proto_data; 2560 2561 /* Notify the conversation window that we've left the chat */ 2562 serv_got_chat_left(gc, cc->id); 2563 2564 /* Destroy the chat_connection */ 2565 od->oscar_chats = g_slist_remove(od->oscar_chats, cc); 2566 if (cc->inpa > 0) 2567 gaim_input_remove(cc->inpa); 2568 aim_conn_kill(od->sess, &cc->conn); 2569 g_free(cc->name); 2570 g_free(cc->show); 2571 g_free(cc); 2572 } 2573 2574 void oscar_chat_leave(struct gaim_connection * gc, int id) 2575 { 2576 struct chat_connection * ccon = find_oscar_chat(gc, id); 2577 2578 if(ccon == NULL) 2579 return; 2580 2581 oscar_chat_kill(gc, ccon); 2582 } 2583 2584 int oscar_chat_join(struct gaim_connection * gc, char * name) 2585 { 2586 struct oscar_data * od = (struct oscar_data *)gc->proto_data; 2587 2588 aim_conn_t * cur; 2589 2590 if((cur = aim_getconn_type(od->sess, AIM_CONN_TYPE_CHATNAV))) { 2591 2592 return (aim_chatnav_createroom(od->sess, cur, name, 4) == 0); 2593 2594 } else { 2595 struct create_room * cr = g_new0(struct create_room, 1); 2596 cr->exchange = 4; 2597 cr->name = g_strdup(name); 2598 od->create_rooms = g_slist_append(od->create_rooms, cr); 2599 aim_reqservice(od->sess, od->conn, AIM_CONN_TYPE_CHATNAV); 2600 return 1; 2601 } 2602 } 2603 2604 int oscar_chat_open(struct gaim_connection * gc, char *who) 2605 { 2606 struct oscar_data * od = (struct oscar_data *)gc->proto_data; 2607 2608 static int chat_id = 0; 2609 char * chatname = g_new0(char, strlen(gc->username)+4); 2610 g_snprintf(chatname, strlen(gc->username) + 4, "%s%d", gc->username, chat_id++); 2611 2612 int ret = oscar_chat_join(gc, chatname); 2613 2614 aim_chat_invite(od->sess, od->conn, who, "", 4, chatname, 0x0); 2615 2616 g_free(chatname); 2617 2618 return ret; 2619 } 2620 2621 void oscar_accept_chat(gpointer w, struct aim_chat_invitation * inv) 2622 { 2623 oscar_chat_join(inv->gc, inv->name); 2624 g_free(inv->name); 2625 g_free(inv); 2626 } 2627 2628 void oscar_reject_chat(gpointer w, struct aim_chat_invitation * inv) 2629 { 2630 g_free(inv->name); 2631 g_free(inv); 2632 } 2633 2484 2634 void oscar_init() 2485 2635 { … … 2495 2645 ret->add_buddy = oscar_add_buddy; 2496 2646 ret->remove_buddy = oscar_remove_buddy; 2647 ret->chat_send = oscar_chat_send; 2648 ret->chat_invite = oscar_chat_invite; 2649 ret->chat_leave = oscar_chat_leave; 2650 ret->chat_open = oscar_chat_open; 2497 2651 ret->add_permit = oscar_add_permit; 2498 2652 ret->add_deny = oscar_add_deny; -
protocols/oscar/tlv.c
r568aaf7 r703f0f7 340 340 } 341 341 342 int aim_addtlvtochain_chatroom(aim_tlvlist_t **list, guint16 type, guint16 exchange, const char *roomname, guint16 instance) 343 { 344 guint8 *buf; 345 int buflen; 346 aim_bstream_t bs; 347 348 buflen = 2 + 1 + strlen(roomname) + 2; 349 350 if (!(buf = g_malloc(buflen))) 351 return 0; 352 353 aim_bstream_init(&bs, buf, buflen); 354 355 aimbs_put16(&bs, exchange); 356 aimbs_put8(&bs, strlen(roomname)); 357 aimbs_putraw(&bs, (guint8 *)roomname, strlen(roomname)); 358 aimbs_put16(&bs, instance); 359 360 aim_addtlvtochain_raw(list, type, aim_bstream_curpos(&bs), buf); 361 362 g_free(buf); 363 364 return 0; 365 } 366 342 367 /** 343 368 * aim_writetlvchain - Write a TLV chain into a data buffer. -
protocols/proxy.c
r568aaf7 r703f0f7 73 73 74 74 75 static struct sockaddr_in *gaim_gethostbyname(c har *host, int port)75 static struct sockaddr_in *gaim_gethostbyname(const char *host, int port) 76 76 { 77 77 static struct sockaddr_in sin; … … 144 144 } 145 145 146 static int proxy_connect_none(c har *host, unsigned short port, struct PHB *phb)146 static int proxy_connect_none(const char *host, unsigned short port, struct PHB *phb) 147 147 { 148 148 struct sockaddr_in *sin; … … 271 271 } 272 272 273 static int proxy_connect_http(c har *host, unsigned short port, struct PHB *phb)273 static int proxy_connect_http(const char *host, unsigned short port, struct PHB *phb) 274 274 { 275 275 phb->host = g_strdup(host); … … 355 355 } 356 356 357 static int proxy_connect_socks4(c har *host, unsigned short port, struct PHB *phb)357 static int proxy_connect_socks4(const char *host, unsigned short port, struct PHB *phb) 358 358 { 359 359 phb->host = g_strdup(host); … … 537 537 } 538 538 539 static int proxy_connect_socks5(c har *host, unsigned short port, struct PHB *phb)539 static int proxy_connect_socks5(const char *host, unsigned short port, struct PHB *phb) 540 540 { 541 541 phb->host = g_strdup(host); … … 578 578 } 579 579 580 int proxy_connect(c har *host, int port, GaimInputFunction func, gpointer data)580 int proxy_connect(const char *host, int port, GaimInputFunction func, gpointer data) 581 581 { 582 582 struct PHB *phb; -
protocols/proxy.h
r568aaf7 r703f0f7 56 56 G_MODULE_EXPORT void gaim_input_remove(gint); 57 57 58 G_MODULE_EXPORT int proxy_connect(c har *host, int port, GaimInputFunction func, gpointer data);58 G_MODULE_EXPORT int proxy_connect(const char *host, int port, GaimInputFunction func, gpointer data); 59 59 60 60 #endif /* _PROXY_H_ */ -
protocols/yahoo/yahoo.c
r568aaf7 r703f0f7 635 635 { 636 636 struct gaim_connection *gc = byahoo_get_gc_by_id( id ); 637 638 serv_got_typing( gc, who, 1 ); 637 if (stat == 1) { 638 /* User is typing */ 639 serv_got_typing( gc, who, 1, 1 ); 640 } 641 else { 642 /* User stopped typing */ 643 serv_got_typing( gc, who, 1, 0 ); 644 } 639 645 } 640 646 -
unix.c
r568aaf7 r703f0f7 53 53 54 54 global.helpfile = g_strdup( HELP_FILE ); 55 55 56 56 global.conf = conf_load( argc, argv ); 57 57 if( global.conf == NULL ) 58 58 return( 1 ); 59 59 60 60 61 if( global.conf->runmode == RUNMODE_INETD ) 61 62 { … … 71 72 if( i != 0 ) 72 73 return( i ); 74 75 global.storage = storage_init( global.conf->primary_storage, 76 global.conf->migrate_storage ); 77 if ( global.storage == NULL) { 78 log_message( LOGLVL_ERROR, "Unable to load storage backend '%s'", global.conf->primary_storage ); 79 return( 1 ); 80 } 81 73 82 74 83 /* Catch some signals to tell the user what's happening before quitting */ … … 88 97 if( !getuid() || !geteuid() ) 89 98 log_message( LOGLVL_WARNING, "BitlBee is running with root privileges. Why?" ); 90 if( access( global.conf->configdir, F_OK ) != 0 )91 log_message( LOGLVL_WARNING, "The configuration directory %s does not exist. Configuration won't be saved.", CONFIG );92 else if( access( global.conf->configdir, R_OK ) != 0 || access( global.conf->configdir, W_OK ) != 0 )93 log_message( LOGLVL_WARNING, "Permission problem: Can't read/write from/to %s.", global.conf->configdir );94 99 if( help_init( &(global.help) ) == NULL ) 95 100 log_message( LOGLVL_WARNING, "Error opening helpfile %s.", HELP_FILE );
Note: See TracChangeset
for help on using the changeset viewer.