MagickCore  6.9.13-7
Convert, Edit, Or Compose Bitmap Images
delegate-private.h
1 /*
2  Copyright 1999 ImageMagick Studio LLC, a non-profit organization
3  dedicated to making software imaging solutions freely available.
4 
5  You may not use this file except in compliance with the License. You may
6  obtain a copy of the License at
7 
8  https://imagemagick.org/script/license.php
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16  MagickCore delegates private methods.
17 */
18 #ifndef MAGICKCORE_DELEGATE_PRIVATE_H
19 #define MAGICKCORE_DELEGATE_PRIVATE_H
20 
21 #include "magick/locale_.h"
22 #include "magick/string_.h"
23 
24 #if defined(MAGICKCORE_GS_DELEGATE)
25 #include "ghostscript/iapi.h"
26 #include "ghostscript/ierrors.h"
27 #else
28 typedef struct gsapi_revision_s
29 {
30  const char *product;
31  const char *copyright;
32  long revision;
33  long revisiondate;
35 #endif
36 
37 #if defined(__cplusplus) || defined(c_plusplus)
38 extern "C" {
39 #endif
40 
41 #ifndef gs_main_instance_DEFINED
42 # define gs_main_instance_DEFINED
43 typedef struct gs_main_instance_s
44  gs_main_instance;
45 #endif
46 
47 #if !defined(MagickDLLCall)
48 # if defined(MAGICKCORE_WINDOWS_SUPPORT)
49 # define MagickDLLCall __stdcall
50 # else
51 # define MagickDLLCall
52 # endif
53 #endif
54 
55 typedef struct _GhostInfo
56 {
57  void
58  (MagickDLLCall *delete_instance)(gs_main_instance *);
59 
60  int
61  (MagickDLLCall *exit)(gs_main_instance *);
62 
63  int
64  (MagickDLLCall *init_with_args)(gs_main_instance *,int,char **);
65 
66  int
67  (MagickDLLCall *new_instance)(gs_main_instance **,void *);
68 
69  int
70  (MagickDLLCall *run_string)(gs_main_instance *,const char *,int,int *);
71 
72  int
73  (MagickDLLCall *set_stdio)(gs_main_instance *,int(MagickDLLCall *)(void *,
74  char *,int),int(MagickDLLCall *)(void *,const char *,int),
75  int(MagickDLLCall *)(void *,const char *,int));
76 
77  int
78  (MagickDLLCall *revision)(gsapi_revision_t *, int);
79 } GhostInfo;
80 
81 static inline char *SanitizeDelegateString(const char *source)
82 {
83  char
84  *sanitize_source;
85 
86  const char
87  *q;
88 
89  char
90  *p;
91 
92  static char
93 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
94  allowlist[] =
95  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "
96  "$-_.+!;*(),{}|^~[]`\'><#%/?:@&=";
97 #else
98  allowlist[] =
99  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "
100  "$-_.+!;*(),{}|\\^~[]`\"><#%/?:@&=";
101 #endif
102 
103  sanitize_source=AcquireString(source);
104  p=sanitize_source;
105  q=sanitize_source+strlen(sanitize_source);
106  for (p+=strspn(p,allowlist); p != q; p+=strspn(p,allowlist))
107  *p='_';
108  return(sanitize_source);
109 }
110 
111 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
112 static inline void FormatSanitizedDelegateOption(char *string,
113  const size_t length,const char *windows_format,
114  const char *magick_unused(non_windows_format),const char *option)
115 {
116  char
117  *sanitized_option;
118 
119  magick_unreferenced(non_windows_format);
120  sanitized_option=SanitizeDelegateString(option);
121  (void) FormatLocaleString(string,length,windows_format,sanitized_option);
122  sanitized_option=DestroyString(sanitized_option);
123 }
124 #else
125 static inline void FormatSanitizedDelegateOption(char *string,
126  const size_t length,const char *magick_unused(windows_format),
127  const char *non_windows_format,const char *option)
128 {
129  char
130  *sanitized_option;
131 
132  magick_unreferenced(windows_format);
133  sanitized_option=SanitizeDelegateString(option);
134  (void) FormatLocaleString(string,length,non_windows_format,sanitized_option);
135  sanitized_option=DestroyString(sanitized_option);
136 }
137 #endif
138 
139 #if defined(__cplusplus) || defined(c_plusplus)
140 }
141 #endif
142 
143 #endif