Changeset 0b09da0
- Timestamp:
- 2010-07-06T23:10:17Z (14 years ago)
- Branches:
- master
- Children:
- f545372
- Parents:
- 6c2404e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ipc.c
r6c2404e r0b09da0 33 33 34 34 GSList *child_list = NULL; 35 static int ipc_child_recv_fd = -1; 35 36 36 37 static void ipc_master_cmd_client( irc_t *data, char **cmd ) … … 115 116 { 116 117 struct bitlbee_child *child = (void*) data, *old = NULL; 118 char *resp; 117 119 GSList *l; 118 120 … … 127 129 old = l->data; 128 130 if( nick_cmp( old->nick, child->nick ) == 0 && child != old && 129 old->password && strcmp( old->password, child->password ) )131 old->password && strcmp( old->password, child->password ) == 0 ) 130 132 break; 131 133 } 132 134 133 if( old == NULL )134 return;135 136 135 child->to_child = old; 136 137 if( l ) 138 { 139 resp = "TAKEOVER INIT\r\n"; 140 } 141 else 142 { 143 /* Won't need the fd since we can't send it anywhere. */ 144 close( child->to_fd ); 145 child->to_fd = -1; 146 resp = "TAKEOVER NO\r\n"; 147 } 148 149 if( write( child->ipc_fd, resp, strlen( resp ) ) != strlen( resp ) ) 150 { 151 ipc_master_free_one( child ); 152 child_list = g_slist_remove( child_list, child ); 153 } 154 } 155 156 static gboolean ipc_send_fd( int fd, int send_fd ); 157 158 void ipc_master_cmd_takeover( irc_t *data, char **cmd ) 159 { 160 struct bitlbee_child *child = (void*) data; 161 162 /* TODO: Check if child->to_child is still valid, etc. */ 163 if( strcmp( cmd[1], "AUTH" ) == 0 ) 164 { 165 if( child->to_child && 166 child->nick && child->to_child->nick && cmd[2] && 167 child->password && child->to_child->password && cmd[3] && 168 strcmp( child->nick, child->to_child->nick ) == 0 && 169 strcmp( child->nick, cmd[2] ) == 0 && 170 strcmp( child->password, child->to_child->password ) == 0 && 171 strcmp( child->password, cmd[3] ) == 0 ) 172 { 173 char *s; 174 175 ipc_send_fd( child->to_child->ipc_fd, child->to_fd ); 176 177 s = irc_build_line( cmd ); 178 if( write( child->to_child->ipc_fd, s, strlen( s ) ) != strlen( s ) ) 179 { 180 ipc_master_free_one( child ); 181 child_list = g_slist_remove( child_list, child ); 182 } 183 g_free( s ); 184 } 185 } 137 186 } 138 187 … … 149 198 { "restart", 0, ipc_master_cmd_restart, 0 }, 150 199 { "identify", 2, ipc_master_cmd_identify, 0 }, 200 { "takeover", 1, ipc_master_cmd_takeover, 0 }, 151 201 { NULL } 152 202 }; … … 215 265 else 216 266 ipc_to_master_str( "HELLO %s %s :%s\r\n", irc->user->host, irc->user->nick, irc->user->fullname ); 267 } 268 269 static void ipc_child_cmd_takeover( irc_t *irc, char **cmd ) 270 { 271 if( strcmp( cmd[1], "NO" ) == 0 ) 272 { 273 /* No takeover, finish the login. */ 274 } 275 else if( strcmp( cmd[1], "INIT" ) == 0 ) 276 { 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 */ 289 } 290 else if( strcmp( cmd[1], "AUTH" ) == 0 ) 291 { 292 if( irc->password && cmd[2] && cmd[3] && 293 ipc_child_recv_fd != -1 && 294 strcmp( irc->user->nick, cmd[2] ) == 0 && 295 strcmp( irc->password, cmd[3] ) == 0 ) 296 { 297 fprintf( stderr, "TO\n" ); 298 b_event_remove( irc->r_watch_source_id ); 299 closesocket( irc->fd ); 300 irc->fd = ipc_child_recv_fd; 301 irc->r_watch_source_id = b_input_add( irc->fd, B_EV_IO_READ, bitlbee_io_current_client_read, irc ); 302 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 } 217 307 } 218 308 … … 225 315 { "kill", 2, ipc_child_cmd_kill, 0 }, 226 316 { "hello", 0, ipc_child_cmd_hello, 0 }, 317 { "takeover", 1, ipc_child_cmd_takeover, 0 }, 227 318 { NULL } 228 319 }; 229 230 static gboolean ipc_send_fd( int fd, int send_fd );231 320 232 321 gboolean ipc_child_identify( irc_t *irc ) … … 321 410 322 411 *recv_fd = *(int*) CMSG_DATA( cmsg ); 412 fprintf( stderr, "pid %d received fd %d\n", (int) getpid(), *recv_fd ); 323 413 } 324 414 415 fprintf( stderr, "pid %d received: %s", (int) getpid(), buf ); 325 416 return g_strndup( buf, size - 2 ); 326 417 } … … 352 443 { 353 444 char *buf, **cmd; 354 int recv_fd = -1; 355 356 if( ( buf = ipc_readline( source, &recv_fd ) ) ) 445 446 if( ( buf = ipc_readline( source, &ipc_child_recv_fd ) ) ) 357 447 { 358 448 cmd = irc_parse_line( buf );
Note: See TracChangeset
for help on using the changeset viewer.