Adding couch_index_plugin:before_open/2 EPI hook

This would allow to extend existent indexers with additional
functionality such as for example:

- index file validation
- index file moves
- injection of options into #mrview.options
- any other tasks which could be done on `open`
diff --git a/src/couch_index.erl b/src/couch_index.erl
index fa08dd1..2b19cca 100644
--- a/src/couch_index.erl
+++ b/src/couch_index.erl
@@ -48,7 +48,8 @@
 }).
 
 
-start_link({Module, IdxState}) ->
+start_link({Module0, IdxState0}) ->
+    [Module, IdxState] = couch_index_plugin:before_open(Module0, IdxState0),
     proc_lib:start_link(?MODULE, init, [{Module, IdxState}]).
 
 
diff --git a/src/couch_index_plugin.erl b/src/couch_index_plugin.erl
index 48822ed..4c2f7e6 100644
--- a/src/couch_index_plugin.erl
+++ b/src/couch_index_plugin.erl
@@ -14,6 +14,8 @@
 
 -export([index_update/4]).
 
+-export([before_open/2]).
+
 -include_lib("couch/include/couch_db.hrl").
 
 -define(SERVICE_ID, couch_index).
@@ -31,6 +33,10 @@
             ok
     end.
 
+before_open(Mod, State) ->
+    Handle = couch_epi:get_handle(?SERVICE_ID),
+    couch_epi:apply(Handle, ?SERVICE_ID, before_open, [Mod, State], [pipe]).
+
 %% ------------------------------------------------------------------
 %% Internal Function Definitions
 %% ------------------------------------------------------------------