Changeset f545372
- Timestamp:
- 2010-07-08T23:10:43Z (14 years ago)
- Branches:
- master
- Children:
- 9595d2b
- Parents:
- 0b09da0
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
ipc.c
r0b09da0 rf545372 133 133 } 134 134 135 child->to_child = old; 136 137 if( l ) 135 if( l && !child->to_child && !old->to_child ) 138 136 { 139 137 resp = "TAKEOVER INIT\r\n"; 138 child->to_child = old; 139 old->to_child = child; 140 140 } 141 141 else … … 159 159 { 160 160 struct bitlbee_child *child = (void*) data; 161 char *fwd = NULL; 161 162 162 163 /* TODO: Check if child->to_child is still valid, etc. */ … … 171 172 strcmp( child->password, cmd[3] ) == 0 ) 172 173 { 173 char *s;174 175 174 ipc_send_fd( child->to_child->ipc_fd, child->to_fd ); 176 175 177 s= irc_build_line( cmd );178 if( write( child->to_child->ipc_fd, s, strlen( s ) ) != strlen( s) )176 fwd = irc_build_line( cmd ); 177 if( write( child->to_child->ipc_fd, fwd, strlen( fwd ) ) != strlen( fwd ) ) 179 178 { 180 179 ipc_master_free_one( child ); 181 180 child_list = g_slist_remove( child_list, child ); 182 181 } 183 g_free( s ); 184 } 182 g_free( fwd ); 183 } 184 } 185 else if( strcmp( cmd[1], "DONE" ) == 0 || strcmp( cmd[1], "FAIL" ) == 0 ) 186 { 187 int fd; 188 189 /* The copy was successful (or not), we don't need it anymore. */ 190 close( child->to_fd ); 191 child->to_fd = -1; 192 193 /* Pass it through to the other party, and flush all state. */ 194 fwd = irc_build_line( cmd ); 195 fd = child->to_child->ipc_fd; 196 child->to_child->to_child = NULL; 197 child->to_child = NULL; 198 if( write( fd, fwd, strlen( fwd ) ) != strlen( fwd ) ) 199 { 200 ipc_master_free_one( child ); 201 child_list = g_slist_remove( child_list, child ); 202 } 203 g_free( fwd ); 185 204 } 186 205 } … … 267 286 } 268 287 288 static void ipc_child_cmd_takeover_yes( void *data ); 289 static void ipc_child_cmd_takeover_no( void *data ); 290 269 291 static void ipc_child_cmd_takeover( irc_t *irc, char **cmd ) 270 292 { 271 293 if( strcmp( cmd[1], "NO" ) == 0 ) 272 294 { 295 /* Master->New connection */ 273 296 /* No takeover, finish the login. */ 274 297 } 275 298 else if( strcmp( cmd[1], "INIT" ) == 0 ) 276 299 { 277 ipc_to_master_str( "TAKEOVER AUTH %s :%s\r\n", 278 irc->user->nick, irc->password ); 279 280 /* Drop credentials, we'll shut down soon and shouldn't overwrite 281 any settings. */ 282 /* TODO: irc_setpass() should do all of this. */ 283 irc_usermsg( irc, "Trying to take over existing session" ); 284 /** NOT YET 285 irc_setpass( irc, NULL ); 286 irc->status &= ~USTATUS_IDENTIFIED; 287 irc_umode_set( irc, "-R", 1 ); 288 */ 300 /* Master->New connection */ 301 /* Offer to take over the old session, unless for some reason 302 we're already logging into IM connections. */ 303 if( irc->login_source_id != -1 ) 304 query_add( irc, NULL, 305 "You're already connected to this server. " 306 "Would you like to take over this session?", 307 ipc_child_cmd_takeover_yes, 308 ipc_child_cmd_takeover_no, irc ); 309 310 /* This one's going to connect to accounts, avoid that. */ 311 b_event_remove( irc->login_source_id ); 312 irc->login_source_id = -1; 289 313 } 290 314 else if( strcmp( cmd[1], "AUTH" ) == 0 ) 291 315 { 316 /* Master->Old connection */ 292 317 if( irc->password && cmd[2] && cmd[3] && 293 318 ipc_child_recv_fd != -1 && … … 295 320 strcmp( irc->password, cmd[3] ) == 0 ) 296 321 { 297 fprintf( stderr, "TO\n" ); 322 GSList *l; 323 298 324 b_event_remove( irc->r_watch_source_id ); 299 325 closesocket( irc->fd ); … … 301 327 irc->r_watch_source_id = b_input_add( irc->fd, B_EV_IO_READ, bitlbee_io_current_client_read, irc ); 302 328 ipc_child_recv_fd = -1; 303 } 304 fprintf( stderr, "%s %s %s\n", irc->password, cmd[2], cmd[3] ); 305 fprintf( stderr, "%d %s %s\n", ipc_child_recv_fd, irc->user->nick, irc->password ); 306 } 329 330 for( l = irc->channels; l; l = l->next ) 331 { 332 irc_channel_t *ic = l->data; 333 if( ic->flags & IRC_CHANNEL_JOINED ) 334 irc_send_join( ic, irc->user ); 335 } 336 irc_usermsg( irc, "You've successfully taken over your old session" ); 337 338 ipc_to_master_str( "TAKEOVER DONE\r\n" ); 339 } 340 else 341 { 342 ipc_to_master_str( "TAKEOVER FAIL\r\n" ); 343 } 344 } 345 else if( strcmp( cmd[1], "DONE" ) == 0 ) 346 { 347 /* Master->New connection (now taken over by old process) */ 348 irc_free( irc ); 349 } 350 else if( strcmp( cmd[1], "FAIL" ) == 0 ) 351 { 352 /* Master->New connection */ 353 irc_usermsg( irc, "Could not take over old session" ); 354 } 355 } 356 357 static void ipc_child_cmd_takeover_yes( void *data ) 358 { 359 irc_t *irc = data; 360 GSList *l; 361 362 /* Master->New connection */ 363 ipc_to_master_str( "TAKEOVER AUTH %s :%s\r\n", 364 irc->user->nick, irc->password ); 365 366 /* Drop credentials, we'll shut down soon and shouldn't overwrite 367 any settings. */ 368 irc_usermsg( irc, "Trying to take over existing session" ); 369 370 /* TODO: irc_setpass() should do all of this. */ 371 irc_setpass( irc, NULL ); 372 irc->status &= ~USTATUS_IDENTIFIED; 373 irc_umode_set( irc, "-R", 1 ); 374 375 for( l = irc->channels; l; l = l->next ) 376 irc_channel_del_user( l->data, irc->user, IRC_CDU_KICK, 377 "Switching to old session" ); 378 } 379 380 static void ipc_child_cmd_takeover_no( void *data ) 381 { 382 ipc_to_master_str( "TAKEOVER NO\r\n" ); 383 cmd_identify_finish( data, 0, 0 ); 307 384 } 308 385 -
root_commands.c
r0b09da0 rf545372 182 182 cmd_account( irc, account_on ); 183 183 184 irc->login_source_id = -1; 184 185 return FALSE; 185 186 }
Note: See TracChangeset
for help on using the changeset viewer.