diff options
author | Günther Deschner <gd@samba.org> | 2009-03-11 15:26:12 +0100 |
---|---|---|
committer | Günther Deschner <gd@samba.org> | 2009-03-13 09:25:20 +0100 |
commit | 427987d2bfae5bd0a259f87ff00e0d1f0a6e8802 (patch) | |
tree | 01ff089302142ea3d986745df8a827b1e1ba2dba | |
parent | 635b8070b665473bf067ed71f7240b9707d3ca95 (diff) | |
download | samba-427987d2bfae5bd0a259f87ff00e0d1f0a6e8802.tar.gz samba-427987d2bfae5bd0a259f87ff00e0d1f0a6e8802.tar.bz2 samba-427987d2bfae5bd0a259f87ff00e0d1f0a6e8802.zip |
s3-spoolss: use macros for _spoolss_GetForm and split out level 1 get.
Guenther
-rw-r--r-- | source3/rpc_server/srv_spoolss_nt.c | 145 |
1 files changed, 72 insertions, 73 deletions
diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 40e3fd06cb..35d206047c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -7255,19 +7255,19 @@ WERROR _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS ****************************************************************************/ static WERROR fill_form_info_1(TALLOC_CTX *mem_ctx, - struct spoolss_FormInfo1 *form, - const nt_forms_struct *list) + struct spoolss_FormInfo1 *r, + const nt_forms_struct *form) { - form->form_name = talloc_strdup(mem_ctx, list->name); - W_ERROR_HAVE_NO_MEMORY(form->form_name); + r->form_name = talloc_strdup(mem_ctx, form->name); + W_ERROR_HAVE_NO_MEMORY(r->form_name); - form->flags = list->flag; - form->size.width = list->width; - form->size.height = list->length; - form->area.left = list->left; - form->area.top = list->top; - form->area.right = list->right; - form->area.bottom = list->bottom; + r->flags = form->flag; + r->size.width = form->width; + r->size.height = form->length; + r->area.left = form->left; + r->area.top = form->top; + r->area.right = form->right; + r->area.bottom = form->bottom; return WERR_OK; } @@ -7395,92 +7395,91 @@ WERROR _spoolss_EnumForms(pipes_struct *p, } /**************************************************************** - _spoolss_GetForm ****************************************************************/ -WERROR _spoolss_GetForm(pipes_struct *p, - struct spoolss_GetForm *r) +static WERROR find_form_byname(const char *name, + nt_forms_struct *form) { - uint32 level = r->in.level; - uint32 offered = r->in.offered; - uint32 *needed = r->out.needed; + nt_forms_struct *list = NULL; + int num_forms = 0, i = 0; - nt_forms_struct *list=NULL; - nt_forms_struct builtin_form; - bool foundBuiltin; - union spoolss_FormInfo info; - struct spoolss_FormInfo1 form_1; - int numofforms=0, i=0; + if (get_a_builtin_ntform_by_string(name, form)) { + return WERR_OK; + } - /* that's an [in out] buffer */ + num_forms = get_ntforms(&list); + DEBUGADD(5,("Number of forms [%d]\n", num_forms)); - if (!r->in.buffer && (offered!=0)) { - return WERR_INVALID_PARAM; + if (num_forms == 0) { + return WERR_BADFID; } - DEBUG(4,("_spoolss_GetForm\n")); - DEBUGADD(5,("Offered buffer size [%d]\n", offered)); - DEBUGADD(5,("Info level [%d]\n", level)); + /* Check if the requested name is in the list of form structures */ + for (i = 0; i < num_forms; i++) { - foundBuiltin = get_a_builtin_ntform_by_string(r->in.form_name, &builtin_form); - if (!foundBuiltin) { - numofforms = get_ntforms(&list); - DEBUGADD(5,("Number of forms [%d]\n", numofforms)); + DEBUG(4,("checking form %s (want %s)\n", list[i].name, name)); - if (numofforms == 0) - return WERR_BADFID; + if (strequal(name, list[i].name)) { + DEBUGADD(6,("Found form %s number [%d]\n", name, i)); + *form = list[i]; + SAFE_FREE(list); + return WERR_OK; + } } - ZERO_STRUCT(form_1); + SAFE_FREE(list); - switch (level) { - case 1: - if (foundBuiltin) { - fill_form_info_1(p->mem_ctx, &form_1, &builtin_form); - } else { + return WERR_BADFID; +} - /* Check if the requested name is in the list of form structures */ - for (i=0; i<numofforms; i++) { +/**************************************************************** + _spoolss_GetForm +****************************************************************/ - DEBUG(4,("_spoolss_GetForm: checking form %s (want %s)\n", - list[i].name, r->in.form_name)); +WERROR _spoolss_GetForm(pipes_struct *p, + struct spoolss_GetForm *r) +{ + WERROR result; + nt_forms_struct form; - if (strequal(r->in.form_name, list[i].name)) { - DEBUGADD(6,("Found form %s number [%d]\n", - r->in.form_name, i)); - fill_form_info_1(p->mem_ctx, &form_1, &list[i]); - break; - } - } + /* that's an [in out] buffer */ - SAFE_FREE(list); - if (i == numofforms) { - return WERR_BADFID; - } - } - /* check the required size. */ + if (!r->in.buffer && (r->in.offered != 0)) { + return WERR_INVALID_PARAM; + } - info.info1 = form_1; + DEBUG(4,("_spoolss_GetForm\n")); + DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered)); + DEBUGADD(5,("Info level [%d]\n", r->in.level)); - *needed = ndr_size_spoolss_FormInfo(&info, 1, NULL, 0); + result = find_form_byname(r->in.form_name, &form); + if (!W_ERROR_IS_OK(result)) { + TALLOC_FREE(r->out.info); + return result; + } - if (*needed > offered) { - r->out.info = NULL; - return WERR_INSUFFICIENT_BUFFER; - } + switch (r->in.level) { + case 1: + result = fill_form_info_1(p->mem_ctx, + &r->out.info->info1, + &form); + break; - r->out.info->info1 = form_1; + default: + result = WERR_UNKNOWN_LEVEL; + break; + } - /* fill the buffer with the form structures */ - DEBUGADD(6,("adding form %s [%d] to buffer\n", - r->in.form_name, i)); + if (!W_ERROR_IS_OK(result)) { + TALLOC_FREE(r->out.info); + return result; + } - return WERR_OK; + *r->out.needed = SPOOLSS_BUFFER_UNION(spoolss_FormInfo, NULL, + r->out.info, r->in.level); + r->out.info = SPOOLSS_BUFFER_OK(r->out.info, NULL); - default: - SAFE_FREE(list); - return WERR_UNKNOWN_LEVEL; - } + return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER); } /**************************************************************************** |