winbindd: Introduce "bool_dispatch_table"
authorVolker Lendecke <vl@samba.org>
Wed, 2 May 2018 13:26:05 +0000 (15:26 +0200)
committerVolker Lendecke <vl@samba.org>
Thu, 17 May 2018 06:44:18 +0000 (08:44 +0200)
This is meant to replace the synchronous "dispatch_table".

The current dispatch_table assumes that every synchronous function does
the request_ok or request_error itself. This mixes two concerns: Doing
the work and shipping the reply to the winbind client. This new dispatch
table will make it possible to centralize shipping the reply to the
client. At a later stage this will enable easier statistics on how long
request processing took precisely.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/winbindd/winbindd.c

index 76d644b1ba60302ab6acf1820f729b71e73d105b..f9bea96bf973612334b60ecb7b21cb37643f0f88 100644 (file)
@@ -554,6 +554,13 @@ static struct winbindd_dispatch_table {
        { WINBINDD_NUM_CMDS, NULL, "NONE" }
 };
 
+static struct winbindd_bool_dispatch_table {
+       enum winbindd_cmd cmd;
+       bool (*fn)(struct winbindd_cli_state *state);
+       const char *cmd_name;
+} bool_dispatch_table[] = {
+};
+
 struct winbindd_async_dispatch_table {
        enum winbindd_cmd cmd;
        const char *cmd_name;
@@ -658,6 +665,8 @@ static void process_request(struct winbindd_cli_state *state)
 {
        struct winbindd_dispatch_table *table = dispatch_table;
        struct winbindd_async_dispatch_table *atable;
+       size_t i;
+       bool ok;
 
        state->mem_ctx = talloc_named(state, 0, "winbind request");
        if (state->mem_ctx == NULL)
@@ -725,14 +734,32 @@ static void process_request(struct winbindd_cli_state *state)
                                  table->winbindd_cmd_name ));
                        state->cmd_name = table->winbindd_cmd_name;
                        table->fn(state);
+                       return;
+               }
+       }
+
+       for (i=0; i<ARRAY_SIZE(bool_dispatch_table); i++) {
+               if (bool_dispatch_table[i].cmd == state->request->cmd) {
                        break;
                }
        }
 
-       if (!table->fn) {
+       if (i == ARRAY_SIZE(bool_dispatch_table)) {
                DEBUG(10,("process_request: unknown request fn number %d\n",
                          (int)state->request->cmd ));
                request_error(state);
+               return;
+       }
+
+       DBG_DEBUG("process_request: request fn %s\n",
+                 bool_dispatch_table[i].cmd_name);
+
+       ok = bool_dispatch_table[i].fn(state);
+
+       if (ok) {
+               request_ok(state);
+       } else {
+               request_error(state);
        }
 }