/* <mark> <name> <value> ... <iodevice> .putdevparams */ static int zputdevparams(i_ctx_t *i_ctx_p) { os_ptr op = osp; gx_io_device *iodev; stack_param_list list; gs_param_list *const plist = (gs_param_list *) & list; int code; password system_params_password; check_read_type(*op, t_string); iodev = gs_findiodevice(imemory, op->value.bytes, r_size(op)); if (iodev == 0) return_error(e_undefined); code = stack_param_list_read(&list, &o_stack, 1, NULL, false, iimemory); if (code < 0) return code; code = dict_read_password(&system_params_password, systemdict, "SystemParamsPassword"); if (code < 0) return code; code = param_check_password(plist, &system_params_password); if (code != 0) { iparam_list_release(&list); return_error(code < 0 ? code : e_invalidaccess); } code = gs_putdevparams(iodev, plist); iparam_list_release(&list); if (code < 0) return code; ref_stack_pop(&o_stack, list.count * 2 + 2); return 0; }
/* <string|int> .checkpassword <0|1|2> */ static int zcheckpassword(i_ctx_t *i_ctx_p) { os_ptr op = osp; ref params[2]; array_param_list list; gs_param_list *const plist = (gs_param_list *)&list; int result = 0; int code = name_ref(imemory, (const byte *)"Password", 8, ¶ms[0], 0); password pass; if (code < 0) return code; params[1] = *op; array_param_list_read(&list, params, 2, NULL, false, iimemory); if (dict_read_password(&pass, systemdict, "StartJobPassword") >= 0 && param_check_password(plist, &pass) == 0 ) result = 1; if (dict_read_password(&pass, systemdict, "SystemParamsPassword") >= 0 && param_check_password(plist, &pass) == 0 ) result = 2; iparam_list_release(&list); make_int(op, result); return 0; }
/* <dict> .builddevicecolorrendering1 <crd> */ static int zbuilddevicecolorrendering1(i_ctx_t *i_ctx_p) { os_ptr op = osp; gs_memory_t *mem = gs_state_memory(igs); dict_param_list list; gs_cie_render *pcrd = 0; int code; check_type(*op, t_dictionary); code = dict_param_list_read(&list, op, NULL, false, iimemory); if (code < 0) return code; code = gs_cie_render1_build(&pcrd, mem, ".builddevicecolorrendering1"); if (code >= 0) { code = param_get_cie_render1(pcrd, (gs_param_list *) & list, gs_currentdevice(igs)); if (code >= 0) { /****** FIX refct ******/ /*rc_decrement(pcrd, ".builddevicecolorrendering1"); *//* build sets rc = 1 */ } } iparam_list_release(&list); if (code < 0) { rc_free_struct(pcrd, ".builddevicecolorrendering1"); return code; } istate->colorrendering.dict = *op; make_istruct_new(op, a_readonly, pcrd); return 0; }
static int ref_param_end_read_collection(gs_param_list * plist, gs_param_name pkey, gs_param_dict * pvalue) { iparam_list_release((dict_param_list *) pvalue->list); gs_free_object(plist->memory, pvalue->list, "ref_param_end_read_collection"); return 0; }
/* <dict> .setsystemparams - */ static int zsetsystemparams(i_ctx_t *i_ctx_p) { os_ptr op = osp; int code; dict_param_list list; gs_param_list *const plist = (gs_param_list *)&list; password pass; check_type(*op, t_dictionary); code = dict_param_list_read(&list, op, NULL, false, iimemory); if (code < 0) return code; code = dict_read_password(&pass, systemdict, "SystemParamsPassword"); if (code < 0) return code; code = param_check_password(plist, &pass); if (code != 0) { if (code > 0) code = gs_note_error(gs_error_invalidaccess); goto out; } code = param_read_password(plist, "StartJobPassword", &pass); switch (code) { default: /* invalid */ goto out; case 1: /* missing */ break; case 0: code = dict_write_password(&pass, systemdict, "StartJobPassword", ! i_ctx_p->LockFilePermissions); if (code < 0) goto out; } code = param_read_password(plist, "SystemParamsPassword", &pass); switch (code) { default: /* invalid */ goto out; case 1: /* missing */ break; case 0: code = dict_write_password(&pass, systemdict, "SystemParamsPassword", ! i_ctx_p->LockFilePermissions); if (code < 0) goto out; } code = setparams(i_ctx_p, plist, &system_param_set); out: iparam_list_release(&list); if (code < 0) return code; pop(1); return 0; }
/* <source> DCTDecode/filter <file> */ static int zDCTD(i_ctx_t *i_ctx_p) { os_ptr op = osp; gs_memory_t *mem; stream_DCT_state state; dict_param_list list; jpeg_decompress_data *jddp; int code; const ref *dop; uint dspace; if (r_has_type(op, t_dictionary)) dop = op, dspace = r_space(op); else dop = 0, dspace = 0; mem = (gs_memory_t *)find_stream_memory(i_ctx_p, 0, &dspace); state.memory = mem; /* First allocate space for IJG parameters. */ jddp = gs_alloc_struct_immovable(mem,jpeg_decompress_data, &st_jpeg_decompress_data, "zDCTD"); if (jddp == 0) return_error(e_VMerror); if (s_DCTD_template.set_defaults) (*s_DCTD_template.set_defaults) ((stream_state *) & state); state.data.decompress = jddp; jddp->memory = state.jpeg_memory = mem; /* set now for allocation */ jddp->scanline_buffer = NULL; /* set this early for safe error exit */ state.report_error = filter_report_error; /* in case create fails */ if ((code = gs_jpeg_create_decompress(&state)) < 0) goto fail; /* correct to do jpeg_destroy here */ /* Read parameters from dictionary */ if ((code = dict_param_list_read(&list, dop, NULL, false, iimemory)) < 0) goto fail; if ((code = s_DCTD_put_params((gs_param_list *) & list, &state)) < 0) goto rel; /* Create the filter. */ jddp->templat = s_DCTD_template; code = filter_read(i_ctx_p, 0, &jddp->templat, (stream_state *) & state, dspace); if (code >= 0) /* Success! */ return code; /* * We assume that if filter_read fails, the stream has not been * registered for closing, so s_DCTD_release will never be called. * Therefore we free the allocated memory before failing. */ rel: iparam_list_release(&list); fail: gs_jpeg_destroy(&state); gs_free_object(mem, jddp, "zDCTD fail"); return code; }
/* We break this out for use when switching contexts. */ int set_user_params(i_ctx_t *i_ctx_p, const ref *paramdict) { dict_param_list list; int code; check_type(*paramdict, t_dictionary); code = dict_param_list_read(&list, paramdict, NULL, false, iimemory); if (code < 0) return code; code = setparams(i_ctx_p, (gs_param_list *)&list, &user_param_set); iparam_list_release(&list); return code; }
/* <dict> .settrapparams - */ static int zsettrapparams(i_ctx_t *i_ctx_p) { os_ptr op = osp; dict_param_list list; int code; check_type(*op, t_dictionary); code = dict_param_list_read(&list, op, NULL, false, iimemory); if (code < 0) return code; code = gs_settrapparams(&i_trap_params, (gs_param_list *) & list); iparam_list_release(&list); if (code < 0) return code; pop(1); return 0; }
/* Note that .putdeviceparams clears the current pagedevice. */ static int zputdeviceparams(i_ctx_t *i_ctx_p) { uint count = ref_stack_counttomark(&o_stack); ref *prequire_all; ref *ppolicy; ref *pdev; gx_device *dev; stack_param_list list; int code; int old_width, old_height; int i, dest; if (count == 0) return_error(e_unmatchedmark); prequire_all = ref_stack_index(&o_stack, count); ppolicy = ref_stack_index(&o_stack, count + 1); pdev = ref_stack_index(&o_stack, count + 2); if (pdev == 0) return_error(e_stackunderflow); check_type_only(*prequire_all, t_boolean); check_write_type_only(*pdev, t_device); dev = pdev->value.pdevice; code = stack_param_list_read(&list, &o_stack, 0, ppolicy, prequire_all->value.boolval, iimemory); if (code < 0) return code; old_width = dev->width; old_height = dev->height; code = gs_putdeviceparams(dev, (gs_param_list *) & list); /* Check for names that were undefined or caused errors. */ for (dest = count - 2, i = 0; i < count >> 1; i++) if (list.results[i] < 0) { *ref_stack_index(&o_stack, dest) = *ref_stack_index(&o_stack, count - (i << 1) - 2); gs_errorname(i_ctx_p, list.results[i], ref_stack_index(&o_stack, dest - 1)); dest -= 2; } iparam_list_release(&list); if (code < 0) { /* There were errors reported. */ ref_stack_pop(&o_stack, dest + 1); return 0; } if (code > 0 || (code == 0 && (dev->width != old_width || dev->height != old_height))) { /* * The device was open and is now closed, or its dimensions have * changed. If it was the current device, call setdevice to * reinstall it and erase the page. */ /****** DOESN'T FIND ALL THE GSTATES THAT REFERENCE THE DEVICE. ******/ if (gs_currentdevice(igs) == dev) { bool was_open = dev->is_open; code = gs_setdevice_no_erase(igs, dev); /* If the device wasn't closed, setdevice won't erase the page. */ if (was_open && code >= 0) code = 1; } } if (code < 0) return code; ref_stack_pop(&o_stack, count + 1); make_bool(osp, code); clear_pagedevice(istate); return 0; }
/* <dict> <string> .parse_dsc_comments <dict> <dsc code> */ static int zparse_dsc_comments(i_ctx_t *i_ctx_p) { #define MAX_DSC_MSG_SIZE (DSC_LINE_LENGTH + 4) /* Allow for %% and CR/LF */ os_ptr const opString = osp; os_ptr const opDict = opString - 1; uint ssize; int comment_code, code; char dsc_buffer[MAX_DSC_MSG_SIZE + 2]; const cmdlist_t *pCmdList = DSCcmdlist; const char * const *pBadList = BadCmdlist; ref * pvalue; CDSC * dsc_data = NULL; dict_param_list list; /* * Verify operand types and length of DSC comment string. If a comment * is too long then we simply truncate it. Russell's parser gets to * handle any errors that may result. (Crude handling but the comment * is bad, so ...). */ check_type(*opString, t_string); check_dict_write(*opDict); ssize = r_size(opString); if (ssize > MAX_DSC_MSG_SIZE) /* need room for EOL + \0 */ ssize = MAX_DSC_MSG_SIZE; /* * Pick up the comment string to be parsed. */ memcpy(dsc_buffer, opString->value.bytes, ssize); dsc_buffer[ssize] = 0x0d; /* Russell wants a 'line end' */ dsc_buffer[ssize + 1] = 0; /* Terminate string */ /* * Skip data block comments (see comments in front of BadCmdList). */ while (*pBadList && strncmp(*pBadList, dsc_buffer, strlen(*pBadList))) pBadList++; if (*pBadList) { /* If found in list, then skip comment */ comment_code = 0; /* Force NOP */ } else { /* * Parse comments - use Russell Lang's DSC parser. We need to get * data area for Russell Lang's parser. Note: We have saved the * location of the data area for the parser in our DSC dict. */ code = dict_find_string(opDict, dsc_dict_name, &pvalue); dsc_data = r_ptr(pvalue, dsc_data_t)->dsc_data_ptr; if (code < 0) return code; comment_code = dsc_scan_data(dsc_data, dsc_buffer, ssize + 1); if_debug1('%', "[%%].parse_dsc_comments: code = %d\n", comment_code); /* * We ignore any errors from Russell's parser. The only value that * it will return for an error is -1 so there is very little information. * We also do not want bad DSC comments to abort processing of an * otherwise valid PS file. */ if (comment_code < 0) comment_code = 0; } /* * Transfer data from DSC structure to postscript variables. * Look up proper handler in the local cmd decode list. */ while (pCmdList->code && pCmdList->code != comment_code ) pCmdList++; if (pCmdList->dsc_proc) { code = dict_param_list_write(&list, opDict, NULL, iimemory); if (code < 0) return code; code = (pCmdList->dsc_proc)((gs_param_list *)&list, dsc_data); iparam_list_release(&list); if (code < 0) return code; } /* Put DSC comment name onto operand stack (replace string). */ return name_enter_string(imemory, pCmdList->comment_name, opString); }