Index: include/asterisk/pbx.h =================================================================== --- include/asterisk/pbx.h (revision 109109) +++ include/asterisk/pbx.h (working copy) @@ -758,6 +758,8 @@ const char *ast_get_ignorepat_name(struct ast_ignorepat *ip); const char *ast_get_switch_name(struct ast_sw *sw); const char *ast_get_switch_data(struct ast_sw *sw); +int ast_get_switch_eval(struct ast_sw *sw); + /*! @} */ /*! @name Other Extension stuff */ Index: main/pbx.c =================================================================== --- main/pbx.c (revision 109109) +++ main/pbx.c (working copy) @@ -5328,7 +5328,32 @@ } /* make sure the new context exists, so we have somewhere to stick this exten/prio */ if (!new) { + struct ast_include *i; + struct ast_ignorepat *ip; + struct ast_sw *sw; new = ast_context_find_or_create(extcontexts, exttable, context->name, prio_item->registrar); /* a new context created via priority from a different context in the old dialplan, gets its registrar from the prio's registrar */ + + /* copy in the includes, switches, and ignorepats */ + /* walk through includes */ + for (i = NULL; (i = ast_walk_context_includes(context, i)) ; ) { + if (strcmp(ast_get_include_registrar(i), registrar) == 0) + continue; /* not mine */ + ast_context_add_include2(new, ast_get_include_name(i), ast_get_include_registrar(i)); + } + + /* walk through switches */ + for (sw = NULL; (sw = ast_walk_context_switches(context, sw)) ; ) { + if (strcmp(ast_get_switch_registrar(sw), registrar) == 0) + continue; /* not mine */ + ast_context_add_switch2(new, ast_get_switch_name(sw), ast_get_switch_data(sw), ast_get_switch_eval(sw), ast_get_switch_registrar(sw)); + } + + /* walk thru ignorepats ... */ + for (ip = NULL; (ip = ast_walk_context_ignorepats(context, ip)); ) { + if (strcmp(ast_get_ignorepat_registrar(ip), registrar) == 0) + continue; /* not mine */ + ast_context_add_ignorepat2(new, ast_get_ignorepat_name(ip), ast_get_ignorepat_registrar(ip)); + } } if (!new) { ast_log(LOG_ERROR,"Could not allocate a new context for %s in merge_and_delete! Danger!\n", context->name); @@ -5353,10 +5378,35 @@ if (!insert_count && !new && (strcmp(context->registrar, registrar) != 0 || (strcmp(context->registrar, registrar) == 0 && context->refcount > 1))) { + struct ast_include *i; + struct ast_ignorepat *ip; + struct ast_sw *sw; /* we could have given it the registrar of the other module who incremented the refcount, but that's not available, so we give it the registrar we know about */ new = ast_context_find_or_create(extcontexts, exttable, context->name, context->registrar); + + /* copy in the includes, switches, and ignorepats */ + /* walk through includes */ + for (i = NULL; (i = ast_walk_context_includes(context, i)) ; ) { + if (strcmp(ast_get_include_registrar(i), registrar) == 0) + continue; /* not mine */ + ast_context_add_include2(new, ast_get_include_name(i), ast_get_include_registrar(i)); + } + + /* walk through switches */ + for (sw = NULL; (sw = ast_walk_context_switches(context, sw)) ; ) { + if (strcmp(ast_get_switch_registrar(sw), registrar) == 0) + continue; /* not mine */ + ast_context_add_switch2(new, ast_get_switch_name(sw), ast_get_switch_data(sw), ast_get_switch_eval(sw), ast_get_switch_registrar(sw)); + } + + /* walk thru ignorepats ... */ + for (ip = NULL; (ip = ast_walk_context_ignorepats(context, ip)); ) { + if (strcmp(ast_get_ignorepat_registrar(ip), registrar) == 0) + continue; /* not mine */ + ast_context_add_ignorepat2(new, ast_get_ignorepat_name(ip), ast_get_ignorepat_registrar(ip)); + } } } @@ -7945,6 +7995,11 @@ return sw ? sw->data : NULL; } +int ast_get_switch_eval(struct ast_sw *sw) +{ + return sw->eval; +} + const char *ast_get_switch_registrar(struct ast_sw *sw) { return sw ? sw->registrar : NULL;