Coverage Report

Created: 2025-06-24 07:01

/src/ghostpdl/psi/ziodev2.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2001-2023 Artifex Software, Inc.
2
   All Rights Reserved.
3
4
   This software is provided AS-IS with no warranty, either express or
5
   implied.
6
7
   This software is distributed under license and may not be copied,
8
   modified or distributed except as expressly authorized under the terms
9
   of the license contained in the file LICENSE in this distribution.
10
11
   Refer to licensing information at http://www.artifex.com or contact
12
   Artifex Software, Inc.,  39 Mesa Street, Suite 108A, San Francisco,
13
   CA 94129, USA, for further information.
14
*/
15
16
17
/* (Level 2) IODevice operators */
18
#include "string_.h"
19
#include "ghost.h"
20
#include "gp.h"
21
#include "oper.h"
22
#include "stream.h"
23
#include "gxiodev.h"
24
#include "dstack.h"   /* for systemdict */
25
#include "files.h"    /* for file_open_stream */
26
#include "iparam.h"
27
#include "iutil2.h"
28
#include "store.h"
29
30
/* ------ %null% ------ */
31
32
/* This represents the null output file. */
33
static iodev_proc_open_device(null_open);
34
const gx_io_device gs_iodev_null = {
35
    "%null%", "Special",
36
    {
37
        iodev_no_init, iodev_no_finit, null_open, iodev_no_open_file,
38
        iodev_os_gp_fopen, iodev_os_fclose,
39
        iodev_no_delete_file, iodev_no_rename_file, iodev_no_file_status,
40
        iodev_no_enumerate_files, NULL, NULL,
41
        iodev_no_get_params, iodev_no_put_params
42
    },
43
    NULL,
44
    NULL
45
};
46
47
static int
48
null_open(gx_io_device * iodev, const char *access, stream ** ps,
49
          gs_memory_t * mem)
50
0
{
51
0
    if (!streq1(access, 'w'))
52
0
        return_error(gs_error_invalidfileaccess);
53
0
    return file_open_stream(gp_null_file_name,
54
0
                            strlen(gp_null_file_name),
55
0
                            access, 256 /* arbitrary */ , ps,
56
0
                            iodev, iodev->procs.gp_fopen, mem);
57
0
}
58
59
/* ------ Operators ------ */
60
61
/* <iodevice> .getdevparams <mark> <name> <value> ... */
62
static int
63
zgetdevparams(i_ctx_t *i_ctx_p)
64
0
{
65
0
    os_ptr op = osp;
66
0
    gx_io_device *iodev;
67
0
    stack_param_list list;
68
0
    gs_param_list *const plist = (gs_param_list *) & list;
69
0
    int code;
70
0
    ref *pmark;
71
72
0
    check_read_type(*op, t_string);
73
0
    iodev = gs_findiodevice(imemory, op->value.bytes, r_size(op));
74
0
    if (iodev == 0)
75
0
        return_error(gs_error_undefined);
76
0
    stack_param_list_write(&list, &o_stack, NULL, iimemory);
77
0
    if ((code = gs_getdevparams(iodev, plist)) < 0) {
78
0
        pop(list.count * 2);
79
0
        return code;
80
0
    }
81
0
    pmark = ref_stack_index(&o_stack, list.count * 2);
82
0
    if (pmark == NULL)
83
0
        return_error(gs_error_stackunderflow);
84
0
    make_mark(pmark);
85
0
    return 0;
86
0
}
87
88
/* <mark> <name> <value> ... <iodevice> .putdevparams */
89
static int
90
zputdevparams(i_ctx_t *i_ctx_p)
91
0
{
92
0
    os_ptr op = osp;
93
0
    gx_io_device *iodev;
94
0
    stack_param_list list;
95
0
    gs_param_list *const plist = (gs_param_list *) & list;
96
0
    int code;
97
0
    password system_params_password;
98
99
0
    check_read_type(*op, t_string);
100
0
    iodev = gs_findiodevice(imemory, op->value.bytes, r_size(op));
101
0
    if (iodev == 0)
102
0
        return_error(gs_error_undefined);
103
0
    code = stack_param_list_read(&list, &o_stack, 1, NULL, false, iimemory);
104
0
    if (code < 0)
105
0
        return code;
106
0
    code = dict_read_password(&system_params_password, systemdict,
107
0
                              "SystemParamsPassword");
108
0
    if (code < 0)
109
0
        return code;
110
0
    code = param_check_password(plist, &system_params_password);
111
0
    if (code != 0) {
112
0
        iparam_list_release(&list);
113
0
        return_error(code < 0 ? code : gs_error_invalidaccess);
114
0
    }
115
0
    code = gs_putdevparams(iodev, plist);
116
0
    iparam_list_release(&list);
117
0
    if (code < 0)
118
0
        return code;
119
0
    pop(list.count * 2 + 2);
120
0
    return 0;
121
0
}
122
123
/* ------ Initialization procedure ------ */
124
125
const op_def ziodev2_l2_op_defs[] =
126
{
127
    op_def_begin_level2(),
128
    {"1.getdevparams", zgetdevparams},
129
    {"2.putdevparams", zputdevparams},
130
    op_def_end(0)
131
};