lib: Move "message_send_all" to serverid.c
authorVolker Lendecke <vl@samba.org>
Thu, 14 Jul 2016 10:47:16 +0000 (12:47 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 28 Jul 2016 03:00:19 +0000 (05:00 +0200)
Trying to trim down messages.c a bit: Sending to all processes that are
registered in serverid.tdb and filtering to me is not really logic of general
messaging but more of the serverid code.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/include/messages.h
source3/include/serverid.h
source3/lib/messages.c
source3/lib/serverid.c
source3/passdb/pdb_interface.c
source3/rpc_server/fss/srv_fss_agent.c
source3/rpc_server/srvsvc/srv_srvsvc_nt.c
source3/smbd/statcache.c

index 2eaf146fbb2bd84a90a29ac4d066adce5dae0f08..1b4e2f61c9e5cc360dbfb3c3b280b8e711b792e9 100644 (file)
 #define MSG_FLAG_LOWPRIORITY           0x80000000
 
 
-/* Flags to classify messages - used in message_send_all() */
-/* Sender will filter by flag. */
-
-#define FLAG_MSG_GENERAL               0x0001
-#define FLAG_MSG_SMBD                  0x0002
-#define FLAG_MSG_NMBD                  0x0004
-#define FLAG_MSG_WINBIND               0x0008
-#define FLAG_MSG_PRINT_GENERAL         0x0010
-/* dbwrap messages 4001-4999 */
-#define FLAG_MSG_DBWRAP                        0x0020
-
 /*
  * ctdb gives us 64-bit server ids for messaging_send. This is done to avoid
  * pid clashes and to be able to register for special messages like "all
@@ -84,10 +73,6 @@ int messaging_ctdbd_reinit(struct messaging_context *msg_ctx,
                           struct messaging_backend *backend);
 struct ctdbd_connection *messaging_ctdbd_connection(void);
 
-bool message_send_all(struct messaging_context *msg_ctx,
-                     int msg_type,
-                     const void *buf, size_t len,
-                     int *n_sent);
 struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, 
                                         struct tevent_context *ev);
 
index 19caec8f8132fe776d3d3cfe1c8f7723c6254331..749b950f2c83bc7a8981393e93eceafd96b94545 100644 (file)
 #include "lib/dbwrap/dbwrap.h"
 #include "librpc/gen_ndr/server_id.h"
 
+/* Flags to classify messages - used in message_send_all() */
+/* Sender will filter by flag. */
+
+#define FLAG_MSG_GENERAL               0x0001
+#define FLAG_MSG_SMBD                  0x0002
+#define FLAG_MSG_NMBD                  0x0004
+#define FLAG_MSG_WINBIND               0x0008
+#define FLAG_MSG_PRINT_GENERAL         0x0010
+/* dbwrap messages 4001-4999 */
+#define FLAG_MSG_DBWRAP                        0x0020
+
 /*
  * Register a server with its unique id
  */
@@ -60,4 +71,11 @@ bool serverid_traverse_read(int (*fn)(const struct server_id *id,
  */
 bool serverid_parent_init(TALLOC_CTX *mem_ctx);
 
+struct messaging_context;
+
+bool message_send_all(struct messaging_context *msg_ctx,
+                     int msg_type,
+                     const void *buf, size_t len,
+                     int *n_sent);
+
 #endif
index ba97fb51553539cd8f0a731183d474732806f9cb..98bcf829e1571afed386543191c7dbf75ad7ab4d 100644 (file)
@@ -105,108 +105,6 @@ static void ping_message(struct messaging_context *msg_ctx,
        messaging_send(msg_ctx, src, MSG_PONG, data);
 }
 
-/****************************************************************************
- Register/replace a dispatch function for a particular message type.
- JRA changed Dec 13 2006. Only one message handler now permitted per type.
- *NOTE*: Dispatch functions must be able to cope with incoming
- messages on an *odd* byte boundary.
-****************************************************************************/
-
-struct msg_all {
-       struct messaging_context *msg_ctx;
-       int msg_type;
-       uint32_t msg_flag;
-       const void *buf;
-       size_t len;
-       int n_sent;
-};
-
-/****************************************************************************
- Send one of the messages for the broadcast.
-****************************************************************************/
-
-static int traverse_fn(struct db_record *rec, const struct server_id *id,
-                      uint32_t msg_flags, void *state)
-{
-       struct msg_all *msg_all = (struct msg_all *)state;
-       NTSTATUS status;
-
-       /* Don't send if the receiver hasn't registered an interest. */
-
-       if((msg_flags & msg_all->msg_flag) == 0) {
-               return 0;
-       }
-
-       /* If the msg send fails because the pid was not found (i.e. smbd died), 
-        * the msg has already been deleted from the messages.tdb.*/
-
-       status = messaging_send_buf(msg_all->msg_ctx, *id, msg_all->msg_type,
-                                   (const uint8_t *)msg_all->buf, msg_all->len);
-
-       if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
-               struct server_id_buf idbuf;
-
-               /*
-                * If the pid was not found delete the entry from
-                * serverid.tdb
-                */
-
-               DEBUG(2, ("pid %s doesn't exist\n",
-                         server_id_str_buf(*id, &idbuf)));
-
-               dbwrap_record_delete(rec);
-       }
-       msg_all->n_sent++;
-       return 0;
-}
-
-/**
- * Send a message to all smbd processes.
- *
- * It isn't very efficient, but should be OK for the sorts of
- * applications that use it. When we need efficient broadcast we can add
- * it.
- *
- * @param n_sent Set to the number of messages sent.  This should be
- * equal to the number of processes, but be careful for races.
- *
- * @retval True for success.
- **/
-bool message_send_all(struct messaging_context *msg_ctx,
-                     int msg_type,
-                     const void *buf, size_t len,
-                     int *n_sent)
-{
-       struct msg_all msg_all;
-
-       msg_all.msg_type = msg_type;
-       if (msg_type < 0x100) {
-               msg_all.msg_flag = FLAG_MSG_GENERAL;
-       } else if (msg_type > 0x100 && msg_type < 0x200) {
-               msg_all.msg_flag = FLAG_MSG_NMBD;
-       } else if (msg_type > 0x200 && msg_type < 0x300) {
-               msg_all.msg_flag = FLAG_MSG_PRINT_GENERAL;
-       } else if (msg_type > 0x300 && msg_type < 0x400) {
-               msg_all.msg_flag = FLAG_MSG_SMBD;
-       } else if (msg_type > 0x400 && msg_type < 0x600) {
-               msg_all.msg_flag = FLAG_MSG_WINBIND;
-       } else if (msg_type > 4000 && msg_type < 5000) {
-               msg_all.msg_flag = FLAG_MSG_DBWRAP;
-       } else {
-               return false;
-       }
-
-       msg_all.buf = buf;
-       msg_all.len = len;
-       msg_all.n_sent = 0;
-       msg_all.msg_ctx = msg_ctx;
-
-       serverid_traverse(traverse_fn, &msg_all);
-       if (n_sent)
-               *n_sent = msg_all.n_sent;
-       return true;
-}
-
 static void messaging_recv_cb(const uint8_t *msg, size_t msg_len,
                              int *fds, size_t num_fds,
                              void *private_data)
index 5c2fa6532a6b2b690ab34c0230a1f796e515e99d..f2c64001d7407bf92c1be0d69c50b310013474a1 100644 (file)
@@ -313,3 +313,98 @@ bool serverid_traverse(int (*fn)(struct db_record *rec,
        status = dbwrap_traverse(db, serverid_traverse_fn, &state, NULL);
        return NT_STATUS_IS_OK(status);
 }
+
+struct msg_all {
+       struct messaging_context *msg_ctx;
+       int msg_type;
+       uint32_t msg_flag;
+       const void *buf;
+       size_t len;
+       int n_sent;
+};
+
+/****************************************************************************
+ Send one of the messages for the broadcast.
+****************************************************************************/
+
+static int traverse_fn(struct db_record *rec, const struct server_id *id,
+                      uint32_t msg_flags, void *state)
+{
+       struct msg_all *msg_all = (struct msg_all *)state;
+       NTSTATUS status;
+
+       /* Don't send if the receiver hasn't registered an interest. */
+
+       if((msg_flags & msg_all->msg_flag) == 0) {
+               return 0;
+       }
+
+       /* If the msg send fails because the pid was not found (i.e. smbd died),
+        * the msg has already been deleted from the messages.tdb.*/
+
+       status = messaging_send_buf(msg_all->msg_ctx, *id, msg_all->msg_type,
+                                   (const uint8_t *)msg_all->buf, msg_all->len);
+
+       if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
+               struct server_id_buf idbuf;
+
+               /*
+                * If the pid was not found delete the entry from
+                * serverid.tdb
+                */
+
+               DEBUG(2, ("pid %s doesn't exist\n",
+                         server_id_str_buf(*id, &idbuf)));
+
+               dbwrap_record_delete(rec);
+       }
+       msg_all->n_sent++;
+       return 0;
+}
+
+/**
+ * Send a message to all smbd processes.
+ *
+ * It isn't very efficient, but should be OK for the sorts of
+ * applications that use it. When we need efficient broadcast we can add
+ * it.
+ *
+ * @param n_sent Set to the number of messages sent.  This should be
+ * equal to the number of processes, but be careful for races.
+ *
+ * @retval True for success.
+ **/
+bool message_send_all(struct messaging_context *msg_ctx,
+                     int msg_type,
+                     const void *buf, size_t len,
+                     int *n_sent)
+{
+       struct msg_all msg_all;
+
+       msg_all.msg_type = msg_type;
+       if (msg_type < 0x100) {
+               msg_all.msg_flag = FLAG_MSG_GENERAL;
+       } else if (msg_type > 0x100 && msg_type < 0x200) {
+               msg_all.msg_flag = FLAG_MSG_NMBD;
+       } else if (msg_type > 0x200 && msg_type < 0x300) {
+               msg_all.msg_flag = FLAG_MSG_PRINT_GENERAL;
+       } else if (msg_type > 0x300 && msg_type < 0x400) {
+               msg_all.msg_flag = FLAG_MSG_SMBD;
+       } else if (msg_type > 0x400 && msg_type < 0x600) {
+               msg_all.msg_flag = FLAG_MSG_WINBIND;
+       } else if (msg_type > 4000 && msg_type < 5000) {
+               msg_all.msg_flag = FLAG_MSG_DBWRAP;
+       } else {
+               return false;
+       }
+
+       msg_all.buf = buf;
+       msg_all.len = len;
+       msg_all.n_sent = 0;
+       msg_all.msg_ctx = msg_ctx;
+
+       serverid_traverse(traverse_fn, &msg_all);
+       if (n_sent)
+               *n_sent = msg_all.n_sent;
+       return true;
+}
index 6b6b1061cbcc1bffcb0bdedde73d6f6fd61b7c1d..5260320939e8834e2a9ecb1c0d5443dbbcdf1345 100644 (file)
@@ -25,6 +25,7 @@
 #include "passdb.h"
 #include "secrets.h"
 #include "messages.h"
+#include "serverid.h"
 #include "../librpc/gen_ndr/samr.h"
 #include "../librpc/gen_ndr/drsblobs.h"
 #include "../librpc/gen_ndr/ndr_drsblobs.h"
index 2a1f770fd949a3b0aed410aae586422057c7a437..880244e335135b1efde8f9b989a9f75a77121ac2 100644 (file)
@@ -20,6 +20,7 @@
 #include "includes.h"
 #include "ntdomain.h"
 #include "include/messages.h"
+#include "serverid.h"
 #include "include/auth.h"
 #include "../libcli/security/security.h"
 #include "../libcli/util/hresult.h"
index 980411edf30794995ed4b32ead63efd619605673..d6e1dfa76c9392a6b1ce84e5604d1ef5f04a0bf5 100644 (file)
@@ -37,6 +37,7 @@
 #include "smbd/globals.h"
 #include "auth.h"
 #include "messages.h"
+#include "serverid.h"
 #include "lib/conn_tdb.h"
 
 extern const struct generic_mapping file_generic_mapping;
index b0b264082aea1932f2d0c2ee0ae5c63561081d10..89a4a3d22373a40280330a9b33584a6c0ac013e3 100644 (file)
@@ -24,6 +24,7 @@
 #include "../lib/util/memcache.h"
 #include "smbd/smbd.h"
 #include "messages.h"
+#include "serverid.h"
 #include "smbprofile.h"
 #include <tdb.h>