summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorGünther Deschner <gd@samba.org>2009-03-11 02:16:29 +0100
committerGünther Deschner <gd@samba.org>2009-03-13 09:25:20 +0100
commit635b8070b665473bf067ed71f7240b9707d3ca95 (patch)
tree1f20bddf3acb71717c87df1a3f369c07bbffd604 /source3
parentb2b3cfbe316d8bb082428f285cc8fb737e3dab87 (diff)
downloadsamba-635b8070b665473bf067ed71f7240b9707d3ca95.tar.gz
samba-635b8070b665473bf067ed71f7240b9707d3ca95.tar.bz2
samba-635b8070b665473bf067ed71f7240b9707d3ca95.zip
s3-spoolss: use macros for _spoolss_EnumForms and split out level 1 enum.
Guenther
Diffstat (limited to 'source3')
-rw-r--r--source3/rpc_server/srv_spoolss_nt.c152
1 files changed, 91 insertions, 61 deletions
diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c
index c4355b6f58..40e3fd06cb 100644
--- a/source3/rpc_server/srv_spoolss_nt.c
+++ b/source3/rpc_server/srv_spoolss_nt.c
@@ -7256,7 +7256,7 @@ WERROR _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS
static WERROR fill_form_info_1(TALLOC_CTX *mem_ctx,
struct spoolss_FormInfo1 *form,
- nt_forms_struct *list)
+ const nt_forms_struct *list)
{
form->form_name = talloc_strdup(mem_ctx, list->name);
W_ERROR_HAVE_NO_MEMORY(form->form_name);
@@ -7273,21 +7273,73 @@ static WERROR fill_form_info_1(TALLOC_CTX *mem_ctx,
}
/****************************************************************
+ spoolss_enumforms_level1
+****************************************************************/
+
+static WERROR spoolss_enumforms_level1(TALLOC_CTX *mem_ctx,
+ const nt_forms_struct *builtin_forms,
+ uint32_t num_builtin_forms,
+ const nt_forms_struct *user_forms,
+ uint32_t num_user_forms,
+ union spoolss_FormInfo **info_p,
+ uint32_t *count)
+{
+ union spoolss_FormInfo *info;
+ WERROR result = WERR_OK;
+ int i;
+
+ *count = num_builtin_forms + num_user_forms;
+
+ info = TALLOC_ARRAY(mem_ctx, union spoolss_FormInfo, *count);
+ W_ERROR_HAVE_NO_MEMORY(info);
+
+ /* construct the list of form structures */
+ for (i=0; i<num_builtin_forms; i++) {
+ DEBUGADD(6,("Filling form number [%d]\n",i));
+ result = fill_form_info_1(info, &info[i].info1,
+ &builtin_forms[i]);
+ if (!W_ERROR_IS_OK(result)) {
+ goto out;
+ }
+ }
+
+ for (; i<num_user_forms; i++) {
+ DEBUGADD(6,("Filling form number [%d]\n",i));
+ result = fill_form_info_1(info, &info[i].info1,
+ &user_forms[i-num_builtin_forms]);
+ if (!W_ERROR_IS_OK(result)) {
+ goto out;
+ }
+ }
+
+ out:
+ if (!W_ERROR_IS_OK(result)) {
+ TALLOC_FREE(info);
+ *count = 0;
+ return result;
+ }
+
+ *info_p = info;
+
+ return WERR_OK;
+}
+
+/****************************************************************
_spoolss_EnumForms
****************************************************************/
WERROR _spoolss_EnumForms(pipes_struct *p,
struct spoolss_EnumForms *r)
{
- nt_forms_struct *list=NULL;
- nt_forms_struct *builtinlist=NULL;
- union spoolss_FormInfo *info;
- uint32_t count;
- uint32_t numbuiltinforms;
- size_t buffer_size = 0;
- int i;
+ WERROR result;
+ nt_forms_struct *user_forms = NULL;
+ nt_forms_struct *builtin_forms = NULL;
+ uint32_t num_user_forms;
+ uint32_t num_builtin_forms;
*r->out.count = 0;
+ *r->out.needed = 0;
+ *r->out.info = NULL;
/* that's an [in out] buffer */
@@ -7299,69 +7351,47 @@ WERROR _spoolss_EnumForms(pipes_struct *p,
DEBUGADD(5,("Offered buffer size [%d]\n", r->in.offered));
DEBUGADD(5,("Info level [%d]\n", r->in.level));
- numbuiltinforms = get_builtin_ntforms(&builtinlist);
- DEBUGADD(5,("Number of builtin forms [%d]\n", numbuiltinforms));
- count = get_ntforms(&list);
- DEBUGADD(5,("Number of user forms [%d]\n", count));
- count += numbuiltinforms;
+ num_builtin_forms = get_builtin_ntforms(&builtin_forms);
+ DEBUGADD(5,("Number of builtin forms [%d]\n", num_builtin_forms));
+ num_user_forms = get_ntforms(&user_forms);
+ DEBUGADD(5,("Number of user forms [%d]\n", num_user_forms));
- if (count == 0) {
- SAFE_FREE(builtinlist);
- SAFE_FREE(list);
+ if (num_user_forms + num_builtin_forms == 0) {
+ SAFE_FREE(builtin_forms);
+ SAFE_FREE(user_forms);
return WERR_NO_MORE_ITEMS;
}
- info = TALLOC_ARRAY(p->mem_ctx, union spoolss_FormInfo, count);
- if (!info) {
- SAFE_FREE(builtinlist);
- SAFE_FREE(list);
- return WERR_NOMEM;
- }
-
switch (r->in.level) {
case 1:
- /* construct the list of form structures */
- for (i=0; i<numbuiltinforms; i++) {
- DEBUGADD(6,("Filling form number [%d]\n",i));
- fill_form_info_1(info, &info[i].info1, &builtinlist[i]);
- }
-
- SAFE_FREE(builtinlist);
-
- for (; i<count; i++) {
- DEBUGADD(6,("Filling form number [%d]\n",i));
- fill_form_info_1(info, &info[i].info1, &list[i-numbuiltinforms]);
- }
-
- SAFE_FREE(list);
-
- /* check the required size. */
- for (i=0; i<numbuiltinforms; i++) {
- DEBUGADD(6,("adding form [%d]'s size\n",i));
- buffer_size += ndr_size_spoolss_FormInfo1(&info[i].info1, NULL, 0);
- }
- for (; i<count; i++) {
- DEBUGADD(6,("adding form [%d]'s size\n",i));
- buffer_size += ndr_size_spoolss_FormInfo1(&info[i].info1, NULL, 0);
- }
-
- *r->out.needed = buffer_size;
+ result = spoolss_enumforms_level1(p->mem_ctx,
+ builtin_forms,
+ num_builtin_forms,
+ user_forms,
+ num_user_forms,
+ r->out.info,
+ r->out.count);
+ break;
+ default:
+ result = WERR_UNKNOWN_LEVEL;
+ break;
+ }
- if (*r->out.needed > r->in.offered) {
- TALLOC_FREE(info);
- return WERR_INSUFFICIENT_BUFFER;
- }
+ SAFE_FREE(user_forms);
+ SAFE_FREE(builtin_forms);
- *r->out.count = count;
- *r->out.info = info;
+ if (!W_ERROR_IS_OK(result)) {
+ return result;
+ }
- return WERR_OK;
+ *r->out.needed = SPOOLSS_BUFFER_UNION_ARRAY(p->mem_ctx,
+ spoolss_EnumForms, NULL,
+ *r->out.info, r->in.level,
+ *r->out.count);
+ *r->out.info = SPOOLSS_BUFFER_OK(*r->out.info, NULL);
+ *r->out.count = SPOOLSS_BUFFER_OK(*r->out.count, 0);
- default:
- SAFE_FREE(list);
- SAFE_FREE(builtinlist);
- return WERR_UNKNOWN_LEVEL;
- }
+ return SPOOLSS_BUFFER_OK(WERR_OK, WERR_INSUFFICIENT_BUFFER);
}
/****************************************************************