Index: main/channel.c =================================================================== --- main/channel.c (revision 90591) +++ main/channel.c (working copy) @@ -953,7 +953,7 @@ */ } if (name) { /* want match by name */ - if ((!namelen && strcasecmp(c->name, name)) || + if ((!namelen && strcasecmp(c->name, name) && strcmp(c->uniqueid, name)) || (namelen && strncasecmp(c->name, name, namelen))) continue; /* name match failed */ } else if (exten) { @@ -3521,10 +3521,10 @@ struct ast_cdr *cdr; int rformat = original->readformat; int wformat = original->writeformat; - char newn[100]; - char orig[100]; - char masqn[100]; - char zombn[100]; + char newn[AST_CHANNEL_NAME]; + char orig[AST_CHANNEL_NAME]; + char masqn[AST_CHANNEL_NAME + 6]; /* */ + char zombn[AST_CHANNEL_NAME + 8]; /* */ ast_debug(4, "Actually Masquerading %s(%d) into the structure of %s(%d)\n", clone->name, clone->_state, original->name, original->_state); @@ -3551,25 +3551,34 @@ /* Unlink the masquerade */ original->masq = NULL; clone->masqr = NULL; - + /* Save the original name */ ast_copy_string(orig, original->name, sizeof(orig)); /* Save the new name */ ast_copy_string(newn, clone->name, sizeof(newn)); /* Create the masq name */ snprintf(masqn, sizeof(masqn), "%s", newn); - + /* Copy the name from the clone channel */ ast_string_field_set(original, name, newn); /* Mangle the name of the clone channel */ ast_string_field_set(clone, name, masqn); - + + if (original->tech == &null_tech) { + /* Swap the clone and original's uniqueids, since the + clone doesn't really exist yet. */ + char clone_uid[25]; + ast_copy_string(clone_uid, clone->uniqueid, sizeof(clone_uid)); + ast_string_field_set(clone, uniqueid, original->uniqueid); + ast_string_field_set(original, uniqueid, clone_uid); + } + /* Notify any managers of the change, first the masq then the other */ manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", newn, masqn, clone->uniqueid); manager_event(EVENT_FLAG_CALL, "Rename", "Oldname: %s\r\nNewname: %s\r\nUniqueid: %s\r\n", orig, newn, original->uniqueid); - /* Swap the technologies */ + /* Swap the technologies */ t = original->tech; original->tech = clone->tech; clone->tech = t; @@ -3649,7 +3658,7 @@ ast_channel_unlock(clone); return -1; } - + snprintf(zombn, sizeof(zombn), "%s", orig); /* Mangle the name of the clone channel */ ast_string_field_set(clone, name, zombn); @@ -3659,7 +3668,7 @@ t_pvt = original->monitor; original->monitor = clone->monitor; clone->monitor = t_pvt; - + /* Keep the same language. */ ast_string_field_set(original, language, clone->language); /* Copy the FD's other than the generator fd */ @@ -3693,16 +3702,16 @@ tmpcid = original->cid; original->cid = clone->cid; clone->cid = tmpcid; - + /* Restore original timing file descriptor */ ast_channel_set_fd(original, AST_TIMING_FD, original->timingfd); - + /* Our native formats are different now */ original->nativeformats = clone->nativeformats; - + /* Context, extension, priority, app data, jump table, remain the same */ /* pvt switches. pbx stays the same, as does next */ - + /* Set the write format */ ast_set_write_format(original, wformat); @@ -3731,7 +3740,7 @@ /* If an indication is currently playing maintain it on the channel that is taking the place of original */ if (original->visible_indication) ast_indicate(original, original->visible_indication); - + /* Now, at this point, the "clone" channel is totally F'd up. We mark it as a zombie so nothing tries to touch it. If it's already been marked as a zombie, then free it now (since it already is considered invalid). */ @@ -3755,7 +3764,7 @@ ast_queue_frame(clone, &ast_null_frame); ast_channel_unlock(clone); } - + /* Signal any blocker */ if (ast_test_flag(original, AST_FLAG_BLOCKING)) pthread_kill(original->blocker, SIGURG);