virtual registry framework with initial printing hooks.
[Samba.git] / source / registry / reg_printing.c
blob8144110d1f852ae1e8eeb07622dbce254c447180
1 /*
2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Gerald Carter 2002.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 /* Implementation of registry virtual views for printing information */
23 #include "includes.h"
25 #undef DBGC_CLASS
26 #define DBGC_CLASS DBGC_RPC_SRV
28 #define MAX_TOP_LEVEL_KEYS 3
30 /* some symbolic indexes into the top_level_keys */
32 #define KEY_INDEX_ENVIR 0
33 #define KEY_INDEX_FORMS 1
34 #define KEY_INDEX_PRINTER 2
36 static char *top_level_keys[MAX_TOP_LEVEL_KEYS] = {
37 "Environments",
38 "Forms",
39 "Printers"
42 /**********************************************************************
43 It is safe to assume that every registry path passed into on of
44 the exported functions here begins with KEY_PRINTING else
45 these functions would have never been called. This is a small utility
46 function to strip the beginning of the path and make a copy that the
47 caller can modify. Note that the caller is responsible for releasing
48 the memory allocated here.
49 **********************************************************************/
51 static char* trim_reg_path( char *path )
53 char *p;
55 p = path + strlen(KEY_PRINTING);
57 if ( *p )
58 return strdup(p);
59 else
60 return NULL;
63 /**********************************************************************
64 handle enumeration of subkeys below KEY_PRINTING.
65 *********************************************************************/
67 static int handle_printing_subpath( char *key, char **subkeys, uint32 index )
69 int result = 0;
70 char *p, *base;
71 int i;
74 /*
75 * break off the first part of the path
76 * topmost base **must** be one of the strings
77 * in top_level_keys[]
80 base = key;
81 p = strchr( key, '\\' );
82 if ( p )
83 *p = '\0';
85 for ( i=0; i<MAX_TOP_LEVEL_KEYS; i++ ) {
86 if ( StrCaseCmp( top_level_keys[i], base ) == 0 )
87 break;
90 if ( !(i < MAX_TOP_LEVEL_KEYS) )
91 return -1;
93 /* Call routine to handle each top level key */
94 switch ( i )
96 case KEY_INDEX_ENVIR:
97 break;
99 case KEY_INDEX_FORMS:
100 break;
102 case KEY_INDEX_PRINTER:
103 break;
105 /* default case for top level key that has no handler */
107 default:
108 break;
113 return result;
116 /**********************************************************************
117 Enumerate registry subkey names given a registry path.
118 Caller is responsible for freeing memory to **subkeys
119 *********************************************************************/
121 int printing_subkey_info( char *key, char **subkeys )
123 char *path;
124 BOOL top_level = False;
125 int num_subkeys = 0;
127 DEBUG(10,("printing_subkey_info: key=>[%s]\n", key));
129 path = trim_reg_path( key );
131 /* check to see if we are dealing with the top level key */
133 if ( !path )
134 top_level = True;
136 if ( top_level ) {
137 if ( ! (*subkeys = malloc( sizeof(top_level_keys) )) )
138 goto done;
140 num_subkeys = MAX_TOP_LEVEL_KEYS;
141 memcpy( *subkeys, top_level_keys, sizeof(top_level_keys) );
143 else
144 num_subkeys = handle_printing_subpath( path, subkeys, -1 );
146 done:
147 SAFE_FREE( path );
148 return num_subkeys;
151 /**********************************************************************
152 Count the registry subkey names given a registry path.
153 Caller is responsible for freeing memory to **subkey
154 *********************************************************************/
156 BOOL printing_subkey_specific( char *key, char** subkey, uint32 index )
158 char *path;
159 BOOL top_level = False;
160 BOOL result = False;
162 DEBUG(10,("printing_subkey_specific: key=>[%s], index=>[%d]\n", key, index));
164 path = trim_reg_path( key );
166 /* check to see if we are dealing with the top level key */
168 if ( !path )
169 top_level = True;
173 if ( top_level ) {
175 /* make sure the index is in range */
177 if ( !(index < MAX_TOP_LEVEL_KEYS) )
178 goto done;
180 if ( !(*subkey = malloc( strlen(top_level_keys[index])+1 )) )
181 goto done;
183 strncpy( *subkey, top_level_keys[index], strlen(top_level_keys[index])+1 );
185 result = True;
187 else {
188 if ( handle_printing_subpath( path, subkey, index ) != -1 )
189 result = True;
192 done:
193 SAFE_FREE( path );
195 return result;
198 /**********************************************************************
199 Enumerate registry values given a registry path.
200 Caller is responsible for freeing memory
201 *********************************************************************/
203 int printing_value_info( char *key, REGISTRY_VALUE **val )
205 DEBUG(10,("printing_value_info: key=>[%s]\n", key));
207 return 0;
210 /**********************************************************************
211 Stub function which always returns failure since we don't want
212 people storing printing information directly via regostry calls
213 (for now at least)
214 *********************************************************************/
216 BOOL printing_store_subkey( char *key, char **subkeys, uint32 num_subkeys )
218 return False;
221 /**********************************************************************
222 Stub function which always returns failure since we don't want
223 people storing printing information directly via regostry calls
224 (for now at least)
225 *********************************************************************/
227 BOOL printing_store_value( char *key, REGISTRY_VALUE **val, uint32 num_values )
229 return False;
233 * Table of function pointers for accessing printing data
236 REGISTRY_OPS printing_ops = {
237 printing_subkey_info,
238 printing_subkey_specific,
239 printing_value_info,
240 printing_store_subkey,
241 printing_store_value