[PATCH 1/6] printing: add jobid_to_sysjob helper function

David Disseldorp ddiss at samba.org
Wed Oct 29 18:37:46 MDT 2014


Samba needs to deal with two types of print job identifiers, those
allocated by the printing backend (sysjob ids), and those allocated
by Samba's spoolss server (jobids).

This change adds a helper function to map spoolss jobids to sysjob ids,
to go alongside the corresponding sysjob to jobid mapping function.

Signed-off-by: David Disseldorp <ddiss at samba.org>
---
 source3/include/printing.h  |  1 +
 source3/printing/printing.c | 70 +++++++++++++++++++++++++++++++++------------
 2 files changed, 53 insertions(+), 18 deletions(-)

diff --git a/source3/include/printing.h b/source3/include/printing.h
index ec5a53b..563659a 100644
--- a/source3/include/printing.h
+++ b/source3/include/printing.h
@@ -195,6 +195,7 @@ uint16_t print_spool_rap_jobid(struct print_file_data *print_file);
 
 uint32 sysjob_to_jobid_pdb(struct tdb_print_db *pdb, int sysjob);
 uint32 sysjob_to_jobid(int unix_jobid);
+int jobid_to_sysjob_pdb(struct tdb_print_db *pdb, uint32_t jobid);
 bool print_notify_register_pid(int snum);
 bool print_notify_deregister_pid(int snum);
 bool print_job_exists(const char* sharename, uint32 jobid);
diff --git a/source3/printing/printing.c b/source3/printing/printing.c
index d8b6191..5d053cc 100644
--- a/source3/printing/printing.c
+++ b/source3/printing/printing.c
@@ -501,19 +501,18 @@ err_out:
 	return pjob;
 }
 
-/* Convert a unix jobid to a smb jobid */
-
-struct unixjob_traverse_state {
+struct job_traverse_state {
 	int sysjob;
-	uint32 sysjob_to_jobid_value;
+	uint32_t jobid;
 };
 
-static int unixjob_traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key,
-			       TDB_DATA data, void *private_data)
+/* find spoolss jobid based on sysjob */
+static int sysjob_to_jobid_traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key,
+				       TDB_DATA data, void *private_data)
 {
 	struct printjob *pjob;
-	struct unixjob_traverse_state *state =
-		(struct unixjob_traverse_state *)private_data;
+	struct job_traverse_state *state =
+		(struct job_traverse_state *)private_data;
 
 	if (!data.dptr || data.dsize == 0)
 		return 0;
@@ -523,7 +522,7 @@ static int unixjob_traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key,
 		return 0;
 
 	if (state->sysjob == pjob->sysjob) {
-		state->sysjob_to_jobid_value = pjob->jobid;
+		state->jobid = pjob->jobid;
 		return 1;
 	}
 
@@ -532,14 +531,14 @@ static int unixjob_traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key,
 
 uint32 sysjob_to_jobid_pdb(struct tdb_print_db *pdb, int sysjob)
 {
-	struct unixjob_traverse_state state;
+	struct job_traverse_state state;
 
 	state.sysjob = sysjob;
-	state.sysjob_to_jobid_value = (uint32)-1;
+	state.jobid = (uint32_t)-1;
 
-	tdb_traverse(pdb->tdb, unixjob_traverse_fn, &state);
+	tdb_traverse(pdb->tdb, sysjob_to_jobid_traverse_fn, &state);
 
-	return state.sysjob_to_jobid_value;
+	return state.jobid;
 }
 
 /****************************************************************************
@@ -551,10 +550,10 @@ uint32 sysjob_to_jobid(int unix_jobid)
 {
 	int services = lp_numservices();
 	int snum;
-	struct unixjob_traverse_state state;
+	struct job_traverse_state state;
 
 	state.sysjob = unix_jobid;
-	state.sysjob_to_jobid_value = (uint32)-1;
+	state.jobid = (uint32_t)-1;
 
 	for (snum = 0; snum < services; snum++) {
 		struct tdb_print_db *pdb;
@@ -564,14 +563,49 @@ uint32 sysjob_to_jobid(int unix_jobid)
 		if (!pdb) {
 			continue;
 		}
-		tdb_traverse(pdb->tdb, unixjob_traverse_fn, &state);
+		tdb_traverse(pdb->tdb, sysjob_to_jobid_traverse_fn, &state);
 		release_print_db(pdb);
-		if (state.sysjob_to_jobid_value != (uint32)-1)
-			return state.sysjob_to_jobid_value;
+		if (state.jobid != (uint32_t)-1)
+			return state.jobid;
 	}
 	return (uint32)-1;
 }
 
+/* find sysjob based on spoolss jobid */
+static int jobid_to_sysjob_traverse_fn(TDB_CONTEXT *the_tdb, TDB_DATA key,
+				       TDB_DATA data, void *private_data)
+{
+	struct printjob *pjob;
+	struct job_traverse_state *state =
+		(struct job_traverse_state *)private_data;
+
+	if (!data.dptr || data.dsize == 0)
+		return 0;
+
+	pjob = (struct printjob *)data.dptr;
+	if (key.dsize != sizeof(uint32_t))
+		return 0;
+
+	if (state->jobid == pjob->jobid) {
+		state->sysjob = pjob->sysjob;
+		return 1;
+	}
+
+	return 0;
+}
+
+int jobid_to_sysjob_pdb(struct tdb_print_db *pdb, uint32_t jobid)
+{
+	struct job_traverse_state state;
+
+	state.sysjob = -1;
+	state.jobid = jobid;
+
+	tdb_traverse(pdb->tdb, jobid_to_sysjob_traverse_fn, &state);
+
+	return state.sysjob;
+}
+
 /****************************************************************************
  Send notifications based on what has changed after a pjob_store.
 ****************************************************************************/
-- 
1.8.4.5



More information about the samba-technical mailing list