Index: pbx/pbx_config.c
===================================================================
--- pbx/pbx_config.c	(revision 131907)
+++ pbx/pbx_config.c	(working copy)
@@ -47,6 +47,7 @@
 static int autofallthrough_config = 1;
 static int clearglobalvars_config = 0;
 static int extenpatternmatchnew_config = 0;
+static char *alwayscheckrt_config = NULL;
 
 AST_MUTEX_DEFINE_STATIC(save_dialplan_lock);
 
@@ -732,7 +733,7 @@
  */
 static char *handle_cli_dialplan_save(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
-	char filename[256];
+	char filename[256], alwayscheckrt[256] = "";
 	struct ast_context *c;
 	struct ast_config *cfg;
 	struct ast_variable *v;
@@ -812,12 +813,13 @@
 	}
 
 	/* fireout general info */
-	fprintf(output, "[general]\nstatic=%s\nwriteprotect=%s\nautofallthrough=%s\nclearglobalvars=%s\nextenpatternmatchnew=%s\n\n",
+	fprintf(output, "[general]\nstatic=%s\nwriteprotect=%s\nautofallthrough=%s\nclearglobalvars=%s\nextenpatternmatchnew=%s\nalwayscheckrt=%s\n\n",
 		static_config ? "yes" : "no",
 		write_protect_config ? "yes" : "no",
                 autofallthrough_config ? "yes" : "no",
 				clearglobalvars_config ? "yes" : "no",
-				extenpatternmatchnew_config ? "yes" : "no");
+				extenpatternmatchnew_config ? "yes" : "no",
+				alwayscheckrt_config ? alwayscheckrt : "");
 
 	if ((v = ast_variable_browse(cfg, "globals"))) {
 		fprintf(output, "[globals]\n");
@@ -1386,6 +1388,9 @@
 		ast_cli_unregister(&cli_dialplan_save);
 	ast_cli_unregister_multiple(cli_pbx_config, sizeof(cli_pbx_config) / sizeof(struct ast_cli_entry));
 	ast_context_destroy(NULL, registrar);
+	if (alwayscheckrt_config) {
+		ast_free(alwayscheckrt_config);
+	}
 	return 0;
 }
 
@@ -1401,6 +1406,7 @@
 	const char *cxt;
 	const char *aft;
 	const char *newpm;
+	const char *achrt;
 	struct ast_flags config_flags = { 0 };
 	cfg = ast_config_load(config_file, config_flags);
 	if (!cfg)
@@ -1414,6 +1420,17 @@
 	if ((newpm = ast_variable_retrieve(cfg, "general", "extenpatternmatchnew")))
 		extenpatternmatchnew_config = ast_true(newpm);
 	clearglobalvars_config = ast_true(ast_variable_retrieve(cfg, "general", "clearglobalvars"));
+
+	if ((achrt = ast_variable_retrieve(cfg, "general", "alwayscheckrt"))) {
+		if (alwayscheckrt_config) {
+			ast_free(alwayscheckrt_config);
+		}
+		if (!ast_strlen_zero(achrt)) {
+			alwayscheckrt_config = ast_strdup(achrt);
+		} else {
+			alwayscheckrt_config = NULL;
+		}
+	}
 	
 
 	if ((cxt = ast_variable_retrieve(cfg, "general", "userscontext"))) 
@@ -1681,6 +1698,7 @@
 	for (con = NULL; (con = ast_walk_contexts(con));)
 		ast_context_verify_includes(con);
 
+	pbx_set_alwayscheckrt(alwayscheckrt_config);
 	pbx_set_autofallthrough(autofallthrough_config);
 	pbx_set_extenpatternmatchnew(extenpatternmatchnew_config);
 
Index: include/asterisk/pbx.h
===================================================================
--- include/asterisk/pbx.h	(revision 131907)
+++ include/asterisk/pbx.h	(working copy)
@@ -865,6 +865,10 @@
   the old linear-search algorithm.  Returns previous value. */
 int pbx_set_extenpatternmatchnew(int newval);
 
+/*! Set "alwayscheckrt" field.  If set and of nonzero length, each context
+ * will be tried through the RealTime switch if it doesn't exists in memory. */
+void pbx_set_alwayscheckrt(const char *newval);
+
 /*!
  * \note This function will handle locking the channel as needed.
  */
Index: main/pbx.c
===================================================================
--- main/pbx.c	(revision 131907)
+++ main/pbx.c	(working copy)
@@ -430,6 +430,7 @@
 
 static int autofallthrough = 1;
 static int extenpatternmatchnew = 0;
+static char *alwayscheckrt = NULL;
 
 /*! \brief Subscription for device state change events */
 static struct ast_event_sub *device_state_sub;
@@ -2067,8 +2068,49 @@
 				break;
 		}
 #endif
-		if (!tmp)
-			return NULL;
+		if (!tmp) {
+			if (!ast_strlen_zero(alwayscheckrt)) {
+				struct ast_switch *asw = pbx_findswitch("Realtime");
+				ast_switch_f *aswf = NULL;
+				char *datap;
+
+				if (!asw) {
+					ast_log(LOG_WARNING, "No such switch 'Realtime'\n");
+					return NULL;
+				}
+				/* equivalent of extension_match_core() at the switch level */
+				if (action == E_CANMATCH) {
+					aswf = asw->canmatch;
+				} else if (action == E_MATCHMORE) {
+					aswf = asw->matchmore;
+				} else { /* action == E_MATCH */
+					aswf = asw->exists;
+				}
+				datap = alwayscheckrt;
+				if (!aswf) {
+					res = 0;
+				} else {
+					if (chan) {
+						ast_autoservice_start(chan);
+					}
+					res = aswf(chan, context, exten, priority, callerid, datap);
+					if (chan) {
+						ast_autoservice_stop(chan);
+					}
+				}
+				if (res) {	/* Got a match */
+					q->swo = asw;
+					q->data = datap;
+					q->foundcontext = context;
+					/* XXX keep status = STATUS_NO_CONTEXT ? */
+					return NULL;
+				}
+				q->incstack[q->stacklen++] = tmp->name;	/* Setup the stack */
+				return NULL;
+			} else {
+				return NULL;
+			}
+		}
 		
 	}
 
@@ -4009,6 +4051,17 @@
 	return oldval;
 }
 
+void pbx_set_alwayscheckrt(const char *newval) {
+	if (alwayscheckrt) {
+		ast_free(alwayscheckrt);
+	}
+	if (!ast_strlen_zero(newval)) {
+		alwayscheckrt = ast_strdup(newval);
+	} else {
+		alwayscheckrt = NULL;
+	}
+}
+
 /*!
  * \brief lookup for a context with a given name,
  * \retval with conlock held if found.
Index: configs/extensions.conf.sample
===================================================================
--- configs/extensions.conf.sample	(revision 131907)
+++ configs/extensions.conf.sample	(working copy)
@@ -101,6 +101,15 @@
 ;
 ;userscontext=default
 ;
+; If user's context wasn't specified in this file, asterisk, by default, will
+; reject all calls from that user. alwayscheckrt allows asterisk to automaticaly
+; look in Realtime engine for contexts which wasn't included in extensions.conf
+;
+;alwayscheckrt=[context]@[rtfamily]
+;
+; context and rtfamily are optional. If context is present, it will replace 
+; user's one. If rtfamily is not present, 'extensions' will be used.
+;
 ; You can include other config files, use the #include command
 ; (without the ';'). Note that this is different from the "include" command
 ; that includes contexts within other contexts. The #include command works
