s3:registry: untangle assignment from check in reg_enumvalue()
[samba.git] / source3 / printing / notify.c
index 8de79c4c604e817ceef1fa8dc70cb47b256489b1..b6b7ea045e9ba70f957cec6ec97b3724cf068576 100644 (file)
 
 #include "includes.h"
 #include "printing.h"
-#include "librpc/gen_ndr/messaging.h"
 #include "../librpc/gen_ndr/spoolss.h"
 #include "nt_printing.h"
+#include "printing/notify.h"
+#include "messages.h"
+#include "util_tdb.h"
 
 static TALLOC_CTX *send_ctx;
 
@@ -252,9 +254,9 @@ static bool copy_notify2_msg( SPOOLSS_NOTIFY_MSG *to, SPOOLSS_NOTIFY_MSG *from )
        memcpy( to, from, sizeof(SPOOLSS_NOTIFY_MSG) );
        
        if ( from->len ) {
-               to->notify.data = (char *)TALLOC_MEMDUP(send_ctx, from->notify.data, from->len );
+               to->notify.data = (char *)talloc_memdup(send_ctx, from->notify.data, from->len );
                if ( !to->notify.data ) {
-                       DEBUG(0,("copy_notify2_msg: TALLOC_MEMDUP() of size [%d] failed!\n", from->len ));
+                       DEBUG(0,("copy_notify2_msg: talloc_memdup() of size [%d] failed!\n", from->len ));
                        return False;
                }
        }
@@ -303,7 +305,7 @@ static void send_spoolss_notify2_msg(struct tevent_context *ev,
 
        /* Store the message on the pending queue. */
 
-       pnqueue = TALLOC_P(send_ctx, struct notify_queue);
+       pnqueue = talloc(send_ctx, struct notify_queue);
        if (!pnqueue) {
                DEBUG(0,("send_spoolss_notify2_msg: Out of memory.\n"));
                return;
@@ -311,7 +313,7 @@ static void send_spoolss_notify2_msg(struct tevent_context *ev,
 
        /* allocate a new msg structure and copy the fields */
        
-       if ( !(pnqueue->msg = TALLOC_P(send_ctx, SPOOLSS_NOTIFY_MSG)) ) {
+       if ( !(pnqueue->msg = talloc(send_ctx, SPOOLSS_NOTIFY_MSG)) ) {
                DEBUG(0,("send_spoolss_notify2_msg: talloc() of size [%lu] failed!\n", 
                        (unsigned long)sizeof(SPOOLSS_NOTIFY_MSG)));
                return;
@@ -355,7 +357,7 @@ static void send_notify_field_values(struct tevent_context *ev,
        if (!create_send_ctx())
                return;
 
-       msg = TALLOC_P(send_ctx, struct spoolss_notify_msg);
+       msg = talloc(send_ctx, struct spoolss_notify_msg);
        if (!msg)
                return;
 
@@ -386,7 +388,7 @@ static void send_notify_field_buffer(struct tevent_context *ev,
        if (!create_send_ctx())
                return;
 
-       msg = TALLOC_P(send_ctx, struct spoolss_notify_msg);
+       msg = talloc(send_ctx, struct spoolss_notify_msg);
        if (!msg)
                return;
 
@@ -397,7 +399,7 @@ static void send_notify_field_buffer(struct tevent_context *ev,
        msg->field = field;
        msg->id = id;
        msg->len = len;
-       msg->notify.data = CONST_DISCARD(char *,buffer);
+       msg->notify.data = discard_const_p(char, buffer);
 
        send_spoolss_notify2_msg(ev, msg_ctx, msg);
 }
@@ -517,57 +519,83 @@ void notify_printer_driver(struct tevent_context *ev,
                snum, strlen(driver_name) + 1, driver_name);
 }
 
-void notify_printer_comment(int snum, const char *comment)
+void notify_printer_comment(struct tevent_context *ev,
+                           struct messaging_context *msg_ctx,
+                           int snum, const char *comment)
 {
        const char *sharename = lp_servicename(snum);
 
        send_notify_field_buffer(
-               server_event_context(), server_messaging_context(),
+               ev, msg_ctx,
                sharename, PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_COMMENT,
                snum, strlen(comment) + 1, comment);
 }
 
-void notify_printer_sharename(int snum, const char *share_name)
+void notify_printer_sharename(struct tevent_context *ev,
+                             struct messaging_context *msg_ctx,
+                             int snum, const char *share_name)
 {
        const char *sharename = lp_servicename(snum);
 
        send_notify_field_buffer(
-               server_event_context(), server_messaging_context(),
+               ev, msg_ctx,
                sharename, PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SHARE_NAME,
                snum, strlen(share_name) + 1, share_name);
 }
 
-void notify_printer_printername(int snum, const char *printername)
+void notify_printer_printername(struct tevent_context *ev,
+                               struct messaging_context *msg_ctx,
+                               int snum, const char *printername)
 {
        const char *sharename = lp_servicename(snum);
 
        send_notify_field_buffer(
-               server_event_context(), server_messaging_context(),
+               ev, msg_ctx,
                sharename, PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PRINTER_NAME,
                snum, strlen(printername) + 1, printername);
 }
 
-void notify_printer_port(int snum, const char *port_name)
+void notify_printer_port(struct tevent_context *ev,
+                        struct messaging_context *msg_ctx,
+                        int snum, const char *port_name)
 {
        const char *sharename = lp_servicename(snum);
 
        send_notify_field_buffer(
-               server_event_context(), server_messaging_context(),
+               ev, msg_ctx,
                sharename, PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_PORT_NAME,
                snum, strlen(port_name) + 1, port_name);
 }
 
-void notify_printer_location(int snum, const char *location)
+void notify_printer_location(struct tevent_context *ev,
+                            struct messaging_context *msg_ctx,
+                            int snum, const char *location)
 {
        const char *sharename = lp_servicename(snum);
 
        send_notify_field_buffer(
-               server_event_context(), server_messaging_context(),
+               ev, msg_ctx,
                sharename, PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_LOCATION,
                snum, strlen(location) + 1, location);
 }
 
-void notify_printer_byname( const char *printername, uint32 change, const char *value )
+void notify_printer_sepfile(struct tevent_context *ev,
+                           struct messaging_context *msg_ctx,
+                           int snum, const char *sepfile)
+{
+       const char *sharename = lp_servicename(snum);
+
+       send_notify_field_buffer(
+               ev, msg_ctx,
+               sharename, PRINTER_NOTIFY_TYPE, PRINTER_NOTIFY_FIELD_SEPFILE,
+               snum, strlen(sepfile) + 1, sepfile);
+}
+
+
+void notify_printer_byname(struct tevent_context *ev,
+                          struct messaging_context *msg_ctx,
+                          const char *printername, uint32 change,
+                          const char *value)
 {
        int snum = print_queue_snum(printername);
        int type = PRINTER_NOTIFY_TYPE;
@@ -576,7 +604,7 @@ void notify_printer_byname( const char *printername, uint32 change, const char *
                return;
                
        send_notify_field_buffer(
-               server_event_context(), server_messaging_context(),
+               ev, msg_ctx,
                printername, type, change, snum, strlen(value)+1, value );
 } 
 
@@ -604,7 +632,7 @@ static bool print_notify_pid_list(const char *printername, TALLOC_CTX *mem_ctx,
                return False;
        tdb = pdb->tdb;
 
-       if (tdb_read_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) == -1) {
+       if (tdb_read_lock_bystring_with_timeout(tdb, NOTIFY_PID_LIST_KEY, 10) != 0) {
                DEBUG(0,("print_notify_pid_list: Failed to lock printer %s database\n",
                                        printername));
                if (pdb)
@@ -622,7 +650,7 @@ static bool print_notify_pid_list(const char *printername, TALLOC_CTX *mem_ctx,
        num_pids = data.dsize / 8;
 
        if (num_pids) {
-               if ((pid_list = TALLOC_ARRAY(mem_ctx, pid_t, num_pids)) == NULL) {
+               if ((pid_list = talloc_array(mem_ctx, pid_t, num_pids)) == NULL) {
                        ret = False;
                        goto done;
                }