summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2020-09-25 01:47:29 +0200
committerAlbert Astals Cid <aacid@kde.org>2021-12-26 23:06:47 +0100
commit66299f05ed419b5b6ee5495f8ee5e8d670bfd1c4 (patch)
treea532a0ad00801707c640e974a0f9011114a5803c
parent4d34d6cfe9bd8fc7b8355a39502374d9d6426ed0 (diff)
Use the new api to pass the callbacks
Needs ghostscript >= 9.53
-rw-r--r--.gitlab-ci.yml6
-rw-r--r--configure.ac4
-rw-r--r--libspectre/spectre-device.c47
-rw-r--r--libspectre/spectre-gs.c20
-rw-r--r--libspectre/spectre-gs.h6
5 files changed, 41 insertions, 42 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 540640c..f3711a9 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -25,12 +25,12 @@ build_clang:
- CC=clang ./autogen.sh
- make
-build_gcc_trusty:
+build_gcc_ubuntu_21_04:
stage: build
- image: ubuntu:trusty
+ image: ubuntu:21.04
before_script:
- apt-get update
- - apt-get install --yes --no-install-recommends build-essential libgs-dev locales automake libtool
+ - apt-get install --yes --no-install-recommends build-essential libgs-dev locales automake libtool pkg-config
- echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen
- locale-gen
script:
diff --git a/configure.ac b/configure.ac
index b74e6df..d513acc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -63,7 +63,7 @@ AC_CHECK_FUNC(vasprintf, [ AC_DEFINE(HAVE_VASPRINTF, 1, [Define if the 'vasprint
AC_CHECK_FUNC(_vscprintf, [ AC_DEFINE(HAVE__VSCPRINTF, 1, [Define if the '_vscprintf' function is available.]) ])
-LIBGS_REQUIRED="9.24"
+LIBGS_REQUIRED="9.53.0"
AC_CHECK_LIB(gs, gsapi_new_instance, have_libgs=yes, have_libgs=no)
if test "x$have_libgs" = "xyes"; then
@@ -81,7 +81,7 @@ if test "x$have_libgs" = "xyes"; then
if (gsapi_revision (&gsrev, sizeof (gsrev)) != 0)
return 1;
- if (gsrev.revision < `echo "$LIBGS_REQUIRED" | sed -e 's/\.//'`)
+ if (gsrev.revision < `echo "$LIBGS_REQUIRED" | sed -e 's/\.//g'`)
return 1;
]])],
[have_libgs=yes],
diff --git a/libspectre/spectre-device.c b/libspectre/spectre-device.c
index 6959db0..15b7383 100644
--- a/libspectre/spectre-device.c
+++ b/libspectre/spectre-device.c
@@ -106,7 +106,7 @@ spectre_page (void *handle, void *device, int copies, int flush)
if (!handle)
return 0;
-
+
sd = (SpectreDevice *)handle;
sd->page_called = TRUE;
memcpy (sd->user_image, sd->gs_image, sd->row_length * sd->height);
@@ -135,7 +135,7 @@ spectre_update (void *handle, void *device, int x, int y, int w, int h)
return 0;
}
-static const display_callback spectre_device = {
+static display_callback spectre_device = {
sizeof (display_callback),
DISPLAY_VERSION_MAJOR,
DISPLAY_VERSION_MINOR,
@@ -262,6 +262,27 @@ rotate_image_to_orientation (unsigned char **page_data,
}
}
+static int spectre_callout_handler(void *instance, void *callout_handle, const char *device_name, int id, int size, void *data)
+{
+ /* On entry, callout_handle == the value of state passed in
+ * to gsapi_register_callout. */
+ /* We are only interested in callouts from the display device. */
+ if (device_name == NULL || strcmp(device_name, "display"))
+ return -1;
+
+ if (id == DISPLAY_CALLOUT_GET_CALLBACK)
+ {
+ /* Fill in the supplied block with the details of our callback
+ * handler, and the handle to use. In this instance, the handle
+ * is the pointer to our test structure. */
+ gs_display_get_callback_t *cb = (gs_display_get_callback_t *)data;
+ cb->callback = &spectre_device;
+ cb->caller_handle = callout_handle;
+ return 0;
+ }
+ return -1;
+}
+
SpectreStatus
spectre_device_render (SpectreDevice *device,
unsigned int page,
@@ -275,14 +296,13 @@ spectre_device_render (SpectreDevice *device,
{
SpectreGS *gs;
char **args;
- int n_args = 13;
+ int n_args = 12;
int arg = 0;
int success;
- char *fmt;
char *text_alpha, *graph_alpha;
char *size = NULL;
char *resolution, *set;
- char *dsp_format, *dsp_handle;
+ char *dsp_format;
char *width_points = NULL;
char *height_points = NULL;
@@ -297,10 +317,10 @@ spectre_device_render (SpectreDevice *device,
return SPECTRE_STATUS_RENDER_ERROR;
}
- if (!spectre_gs_set_display_callback (gs, (display_callback *)&spectre_device)) {
+ if (!spectre_gs_register_callout(gs, spectre_callout_handler, device)) {
spectre_gs_cleanup (gs, CLEANUP_DELETE_INSTANCE);
spectre_gs_free (gs);
-
+
return SPECTRE_STATUS_RENDER_ERROR;
}
@@ -340,16 +360,6 @@ spectre_device_render (SpectreDevice *device,
DISPLAY_LITTLEENDIAN |
#endif
DISPLAY_TOPFIRST);
-#ifdef WIN32
-#define FMT64 "I64"
-#else
-#define FMT64 "ll"
-#endif
- fmt = _spectre_strdup_printf ("-sDisplayHandle=16#%s",
- sizeof (device) == 4 ? "%lx" : "%"FMT64"x");
- args[arg++] = dsp_handle = _spectre_strdup_printf (fmt, device);
- free (fmt);
-#undef FMT64
if (rc->use_platform_fonts == FALSE)
args[arg++] = "-dNOPLATFONTS";
@@ -369,7 +379,6 @@ spectre_device_render (SpectreDevice *device,
free (height_points);
free (resolution);
free (dsp_format);
- free (dsp_handle);
free (args);
if (!success) {
free (device->user_image);
@@ -396,7 +405,7 @@ spectre_device_render (SpectreDevice *device,
*page_data = device->user_image;
*row_length = device->row_length;
- rotate_image_to_orientation (page_data, row_length, width, height, rc->orientation);
+ rotate_image_to_orientation (page_data, row_length, width, height, rc->orientation);
spectre_gs_free (gs);
diff --git a/libspectre/spectre-gs.c b/libspectre/spectre-gs.c
index ad372f3..a817281 100644
--- a/libspectre/spectre-gs.c
+++ b/libspectre/spectre-gs.c
@@ -26,14 +26,8 @@
#include "spectre-utils.h"
/* ghostscript stuff */
-#include <ghostscript/iapi.h>
#include <ghostscript/ierrors.h>
-/* Ghostscript before version 9.24 has a critial vulnerability
- * where -dSAFER could be escaped from.
- */
-#define GS_MIN_VERSION (924)
-
#define BUFFER_SIZE 32768
struct SpectreGS {
@@ -160,13 +154,8 @@ int
spectre_gs_create_instance (SpectreGS *gs,
void *caller_handle)
{
- int version;
int error;
- version = spectre_gs_get_version ();
- if (version < GS_MIN_VERSION)
- return FALSE;
-
error = gsapi_new_instance (&gs->ghostscript_instance, caller_handle);
if (!critic_error_code (error)) {
gsapi_set_stdio (gs->ghostscript_instance,
@@ -180,13 +169,12 @@ spectre_gs_create_instance (SpectreGS *gs,
}
int
-spectre_gs_set_display_callback (SpectreGS *gs,
- void *callback)
+spectre_gs_register_callout (SpectreGS *gs,
+ gs_callout callout,void *caller_handle)
{
int error;
-
- error = gsapi_set_display_callback (gs->ghostscript_instance,
- callback);
+
+ error = gsapi_register_callout(gs->ghostscript_instance, callout, caller_handle);
return !critic_error_code (error);
}
diff --git a/libspectre/spectre-gs.h b/libspectre/spectre-gs.h
index eb88736..6bbcf20 100644
--- a/libspectre/spectre-gs.h
+++ b/libspectre/spectre-gs.h
@@ -25,6 +25,8 @@
#include "ps.h"
+#include <ghostscript/iapi.h>
+
SPECTRE_BEGIN_DECLS
typedef enum {
@@ -37,8 +39,8 @@ typedef struct SpectreGS SpectreGS;
SpectreGS *spectre_gs_new (void);
int spectre_gs_create_instance (SpectreGS *gs,
void *caller_handle);
-int spectre_gs_set_display_callback (SpectreGS *gs,
- void *callback);
+int spectre_gs_register_callout (SpectreGS *gs,
+ gs_callout callout, void *caller_handle);
int spectre_gs_run (SpectreGS *gs,
int n_args,
char **args);