cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % CCCC OOO N N FFFFF IIIII GGGG U U RRRR EEEEE % |
| 7 | % C O O NN N F I G U U R R E % |
| 8 | % C O O N N N FFF I G GG U U RRRR EEE % |
| 9 | % C O O N NN F I G G U U R R E % |
| 10 | % CCCC OOO N N F IIIII GGG UUU R R EEEEE % |
| 11 | % % |
| 12 | % % |
| 13 | % MagickCore Image Configure Methods % |
| 14 | % % |
| 15 | % Software Design % |
cristy | de984cd | 2013-12-01 14:49:27 +0000 | [diff] [blame] | 16 | % Cristy % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 17 | % July 2003 % |
| 18 | % % |
| 19 | % % |
Cristy | d842011 | 2021-01-01 14:52:00 -0500 | [diff] [blame] | 20 | % Copyright 1999-2021 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
Cristy | 9ddfcca | 2018-09-09 19:46:34 -0400 | [diff] [blame] | 26 | % https://imagemagick.org/script/license.php % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 27 | % % |
| 28 | % Unless required by applicable law or agreed to in writing, software % |
| 29 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 30 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 31 | % See the License for the specific language governing permissions and % |
| 32 | % limitations under the License. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | */ |
| 38 | |
| 39 | /* |
| 40 | Include declarations. |
| 41 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 42 | #include "MagickCore/studio.h" |
| 43 | #include "MagickCore/blob.h" |
| 44 | #include "MagickCore/client.h" |
| 45 | #include "MagickCore/configure.h" |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 46 | #include "MagickCore/configure-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 47 | #include "MagickCore/exception.h" |
| 48 | #include "MagickCore/exception-private.h" |
dirk | abed7e2 | 2016-01-31 17:10:21 +0100 | [diff] [blame] | 49 | #include "MagickCore/linked-list.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 50 | #include "MagickCore/log.h" |
| 51 | #include "MagickCore/memory_.h" |
| 52 | #include "MagickCore/semaphore.h" |
| 53 | #include "MagickCore/string_.h" |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 54 | #include "MagickCore/string-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 55 | #include "MagickCore/token.h" |
| 56 | #include "MagickCore/utility.h" |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 57 | #include "MagickCore/utility-private.h" |
Dirk Lemstra | 0816fc3 | 2019-01-13 12:38:59 +0100 | [diff] [blame] | 58 | #include "MagickCore/version.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 59 | #include "MagickCore/xml-tree.h" |
cristy | 3291f51 | 2014-03-16 22:16:22 +0000 | [diff] [blame] | 60 | #include "MagickCore/xml-tree-private.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 61 | |
| 62 | /* |
| 63 | Define declarations. |
| 64 | */ |
| 65 | #define ConfigureFilename "configure.xml" |
| 66 | |
| 67 | /* |
cristy | 54a531d | 2009-10-21 17:58:01 +0000 | [diff] [blame] | 68 | Typedef declarations. |
| 69 | */ |
| 70 | typedef struct _ConfigureMapInfo |
| 71 | { |
| 72 | const char |
| 73 | *name, |
| 74 | *value; |
| 75 | } ConfigureMapInfo; |
| 76 | |
| 77 | /* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 78 | Static declarations. |
| 79 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 80 | |
| 81 | static LinkedListInfo |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 82 | *configure_cache = (LinkedListInfo *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 83 | |
| 84 | static SemaphoreInfo |
| 85 | *configure_semaphore = (SemaphoreInfo *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 86 | |
| 87 | /* |
| 88 | Forward declarations. |
| 89 | */ |
| 90 | static MagickBooleanType |
Cristy | d1e7b76 | 2019-12-07 19:00:20 -0500 | [diff] [blame] | 91 | IsConfigureCacheInstantiated(ExceptionInfo *); |
| 92 | |
| 93 | #if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT |
| 94 | static MagickBooleanType |
cristy | cd2cd18 | 2014-03-18 12:10:55 +0000 | [diff] [blame] | 95 | LoadConfigureCache(LinkedListInfo *,const char *,const char *,const size_t, |
| 96 | ExceptionInfo *); |
Cristy | d1e7b76 | 2019-12-07 19:00:20 -0500 | [diff] [blame] | 97 | #endif |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 98 | |
| 99 | /* |
| 100 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 101 | % % |
| 102 | % % |
| 103 | % % |
| 104 | % A c q u i r e C o n f i g u r e C a c h e % |
| 105 | % % |
| 106 | % % |
| 107 | % % |
| 108 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 109 | % |
cristy | cd2cd18 | 2014-03-18 12:10:55 +0000 | [diff] [blame] | 110 | % AcquireConfigureCache() caches one or more configure configurations which |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 111 | % provides a mapping between configure attributes and a configure name. |
| 112 | % |
| 113 | % The format of the AcquireConfigureCache method is: |
| 114 | % |
| 115 | % LinkedListInfo *AcquireConfigureCache(const char *filename, |
| 116 | % ExceptionInfo *exception) |
| 117 | % |
| 118 | % A description of each parameter follows: |
| 119 | % |
| 120 | % o filename: the font file name. |
| 121 | % |
| 122 | % o exception: return any errors or warnings in this structure. |
| 123 | % |
| 124 | */ |
Dirk Lemstra | 0816fc3 | 2019-01-13 12:38:59 +0100 | [diff] [blame] | 125 | static inline void AddConfigureKey(LinkedListInfo *cache,const char *path, |
Dirk Lemstra | e8342ff | 2019-01-13 13:07:18 +0100 | [diff] [blame] | 126 | const char *name,const char *value,MagickBooleanType exempt) |
Cristy | 1af75e5 | 2018-11-15 07:59:32 -0500 | [diff] [blame] | 127 | { |
| 128 | ConfigureInfo |
| 129 | *configure_info; |
| 130 | |
Cristy | 8357b5d | 2020-11-22 12:39:10 +0000 | [diff] [blame] | 131 | configure_info=(ConfigureInfo *) AcquireMagickMemory(sizeof(*configure_info)); |
Cristy | 1af75e5 | 2018-11-15 07:59:32 -0500 | [diff] [blame] | 132 | if (configure_info == (ConfigureInfo *) NULL) |
Dirk Lemstra | 0816fc3 | 2019-01-13 12:38:59 +0100 | [diff] [blame] | 133 | return; |
Cristy | 1af75e5 | 2018-11-15 07:59:32 -0500 | [diff] [blame] | 134 | (void) memset(configure_info,0,sizeof(*configure_info)); |
Dirk Lemstra | e8342ff | 2019-01-13 13:07:18 +0100 | [diff] [blame] | 135 | if (exempt == MagickTrue) |
| 136 | { |
| 137 | configure_info->path=(char *) path; |
| 138 | configure_info->name=(char *) name; |
| 139 | configure_info->value=(char *) value; |
| 140 | } |
| 141 | else |
| 142 | { |
| 143 | configure_info->path=ConstantString(path); |
| 144 | configure_info->name=ConstantString(name); |
| 145 | configure_info->value=ConstantString(value); |
| 146 | } |
| 147 | configure_info->exempt=exempt; |
Cristy | 1af75e5 | 2018-11-15 07:59:32 -0500 | [diff] [blame] | 148 | configure_info->signature=MagickCoreSignature; |
Dirk Lemstra | 0816fc3 | 2019-01-13 12:38:59 +0100 | [diff] [blame] | 149 | (void) AppendValueToLinkedList(cache,configure_info); |
Cristy | 1af75e5 | 2018-11-15 07:59:32 -0500 | [diff] [blame] | 150 | } |
| 151 | |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 152 | static LinkedListInfo *AcquireConfigureCache(const char *filename, |
| 153 | ExceptionInfo *exception) |
| 154 | { |
Cristy | 1af75e5 | 2018-11-15 07:59:32 -0500 | [diff] [blame] | 155 | char |
| 156 | head_path[MagickPathExtent], |
| 157 | path[MagickPathExtent]; |
| 158 | |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 159 | LinkedListInfo |
dirk | b18d864 | 2016-07-17 19:32:43 +0200 | [diff] [blame] | 160 | *cache; |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 161 | |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 162 | /* |
| 163 | Load external configure map. |
| 164 | */ |
dirk | b18d864 | 2016-07-17 19:32:43 +0200 | [diff] [blame] | 165 | cache=NewLinkedList(0); |
Cristy | d1e7b76 | 2019-12-07 19:00:20 -0500 | [diff] [blame] | 166 | #if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 167 | { |
dirk | b18d864 | 2016-07-17 19:32:43 +0200 | [diff] [blame] | 168 | const StringInfo |
| 169 | *option; |
| 170 | |
| 171 | LinkedListInfo |
| 172 | *options; |
| 173 | |
Dirk Lemstra | 2ae30a5 | 2019-01-13 12:42:45 +0100 | [diff] [blame] | 174 | MagickBooleanType |
| 175 | status; |
| 176 | |
dirk | b18d864 | 2016-07-17 19:32:43 +0200 | [diff] [blame] | 177 | options=GetConfigureOptions(filename,exception); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 178 | option=(const StringInfo *) GetNextValueInLinkedList(options); |
dirk | b18d864 | 2016-07-17 19:32:43 +0200 | [diff] [blame] | 179 | while (option != (const StringInfo *) NULL) |
| 180 | { |
Dirk Lemstra | 2ae30a5 | 2019-01-13 12:42:45 +0100 | [diff] [blame] | 181 | status=LoadConfigureCache(cache,(const char *) |
dirk | b18d864 | 2016-07-17 19:32:43 +0200 | [diff] [blame] | 182 | GetStringInfoDatum(option),GetStringInfoPath(option),0,exception); |
Dirk Lemstra | 2ae30a5 | 2019-01-13 12:42:45 +0100 | [diff] [blame] | 183 | if (status == MagickTrue) |
| 184 | break; |
dirk | b18d864 | 2016-07-17 19:32:43 +0200 | [diff] [blame] | 185 | option=(const StringInfo *) GetNextValueInLinkedList(options); |
| 186 | } |
| 187 | options=DestroyConfigureOptions(options); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 188 | } |
dirk | b18d864 | 2016-07-17 19:32:43 +0200 | [diff] [blame] | 189 | #endif |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 190 | /* |
Dirk Lemstra | 0816fc3 | 2019-01-13 12:38:59 +0100 | [diff] [blame] | 191 | Load built-in configure. |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 192 | */ |
Dirk Lemstra | e8342ff | 2019-01-13 13:07:18 +0100 | [diff] [blame] | 193 | AddConfigureKey(cache,"[built-in]","NAME","ImageMagick",MagickTrue); |
Cristy | 1af75e5 | 2018-11-15 07:59:32 -0500 | [diff] [blame] | 194 | /* |
| 195 | Load runtime configuration. |
| 196 | */ |
Dirk Lemstra | 0816fc3 | 2019-01-13 12:38:59 +0100 | [diff] [blame] | 197 | AddConfigureKey(cache,"[built-in]","QuantumDepth",GetMagickQuantumDepth( |
Dirk Lemstra | e8342ff | 2019-01-13 13:07:18 +0100 | [diff] [blame] | 198 | (size_t *)NULL),MagickTrue); |
| 199 | AddConfigureKey(cache,"[built-in]","FEATURES",GetMagickFeatures(), |
| 200 | MagickTrue); |
| 201 | AddConfigureKey(cache,"[built-in]","DELEGATES",GetMagickDelegates(), |
| 202 | MagickTrue); |
Cristy | 1af75e5 | 2018-11-15 07:59:32 -0500 | [diff] [blame] | 203 | (void) AcquireUniqueFilename(path); |
| 204 | GetPathComponent(path,HeadPath,head_path); |
Dirk Lemstra | e8342ff | 2019-01-13 13:07:18 +0100 | [diff] [blame] | 205 | AddConfigureKey(cache,"[built-in]","MAGICK_TEMPORARY_PATH",head_path, |
| 206 | MagickFalse); |
dirk | b18d864 | 2016-07-17 19:32:43 +0200 | [diff] [blame] | 207 | return(cache); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 208 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 209 | |
| 210 | /* |
| 211 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 212 | % % |
| 213 | % % |
| 214 | % % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 215 | + C o n f i g u r e C o m p o n e n t G e n e s i s % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 216 | % % |
| 217 | % % |
| 218 | % % |
| 219 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 220 | % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 221 | % ConfigureComponentGenesis() instantiates the configure component. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 222 | % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 223 | % The format of the ConfigureComponentGenesis method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 224 | % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 225 | % MagickBooleanType ConfigureComponentGenesis(void) |
| 226 | % |
| 227 | */ |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 228 | MagickPrivate MagickBooleanType ConfigureComponentGenesis(void) |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 229 | { |
cristy | 7c97706 | 2014-04-04 14:05:53 +0000 | [diff] [blame] | 230 | if (configure_semaphore == (SemaphoreInfo *) NULL) |
| 231 | configure_semaphore=AcquireSemaphoreInfo(); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 232 | return(MagickTrue); |
| 233 | } |
| 234 | |
| 235 | /* |
| 236 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 237 | % % |
| 238 | % % |
| 239 | % % |
| 240 | + C o n f i g u r e C o m p o n e n t T e r m i n u s % |
| 241 | % % |
| 242 | % % |
| 243 | % % |
| 244 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 245 | % |
| 246 | % ConfigureComponentTerminus() destroys the configure component. |
| 247 | % |
| 248 | % The format of the ConfigureComponentTerminus method is: |
| 249 | % |
| 250 | % ConfigureComponentTerminus(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 251 | % |
| 252 | */ |
| 253 | |
| 254 | static void *DestroyConfigureElement(void *configure_info) |
| 255 | { |
Cristy | f2dc1dd | 2020-12-28 13:59:26 -0500 | [diff] [blame] | 256 | ConfigureInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 257 | *p; |
| 258 | |
| 259 | p=(ConfigureInfo *) configure_info; |
cristy | 54a531d | 2009-10-21 17:58:01 +0000 | [diff] [blame] | 260 | if (p->exempt == MagickFalse) |
| 261 | { |
| 262 | if (p->value != (char *) NULL) |
| 263 | p->value=DestroyString(p->value); |
| 264 | if (p->name != (char *) NULL) |
| 265 | p->name=DestroyString(p->name); |
| 266 | if (p->path != (char *) NULL) |
| 267 | p->path=DestroyString(p->path); |
| 268 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 269 | p=(ConfigureInfo *) RelinquishMagickMemory(p); |
| 270 | return((void *) NULL); |
| 271 | } |
| 272 | |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 273 | MagickPrivate void ConfigureComponentTerminus(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 274 | { |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 275 | if (configure_semaphore == (SemaphoreInfo *) NULL) |
cristy | 04b11db | 2014-02-16 15:10:39 +0000 | [diff] [blame] | 276 | ActivateSemaphoreInfo(&configure_semaphore); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 277 | LockSemaphoreInfo(configure_semaphore); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 278 | if (configure_cache != (LinkedListInfo *) NULL) |
| 279 | configure_cache=DestroyLinkedList(configure_cache,DestroyConfigureElement); |
| 280 | configure_cache=(LinkedListInfo *) NULL; |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 281 | UnlockSemaphoreInfo(configure_semaphore); |
cristy | 3d162a9 | 2014-02-16 14:05:06 +0000 | [diff] [blame] | 282 | RelinquishSemaphoreInfo(&configure_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | /* |
| 286 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 287 | % % |
| 288 | % % |
| 289 | % % |
| 290 | % D e s t r o y C o n f i g u r e O p t i o n s % |
| 291 | % % |
| 292 | % % |
| 293 | % % |
| 294 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 295 | % |
| 296 | % DestroyConfigureOptions() releases memory associated with an configure |
| 297 | % options. |
| 298 | % |
| 299 | % The format of the DestroyProfiles method is: |
| 300 | % |
| 301 | % LinkedListInfo *DestroyConfigureOptions(Image *image) |
| 302 | % |
| 303 | % A description of each parameter follows: |
| 304 | % |
| 305 | % o image: the image. |
| 306 | % |
| 307 | */ |
| 308 | |
| 309 | static void *DestroyOptions(void *option) |
| 310 | { |
| 311 | return(DestroyStringInfo((StringInfo *) option)); |
| 312 | } |
| 313 | |
| 314 | MagickExport LinkedListInfo *DestroyConfigureOptions(LinkedListInfo *options) |
| 315 | { |
| 316 | assert(options != (LinkedListInfo *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 317 | return(DestroyLinkedList(options,DestroyOptions)); |
| 318 | } |
| 319 | |
| 320 | /* |
| 321 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 322 | % % |
| 323 | % % |
| 324 | % % |
| 325 | + G e t C o n f i g u r e I n f o % |
| 326 | % % |
| 327 | % % |
| 328 | % % |
| 329 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 330 | % |
| 331 | % GetConfigureInfo() searches the configure list for the specified name and if |
| 332 | % found returns attributes for that element. |
| 333 | % |
| 334 | % The format of the GetConfigureInfo method is: |
| 335 | % |
| 336 | % const ConfigureInfo *GetConfigureInfo(const char *name, |
| 337 | % ExceptionInfo *exception) |
| 338 | % |
| 339 | % A description of each parameter follows: |
| 340 | % |
| 341 | % o configure_info: GetConfigureInfo() searches the configure list for the |
| 342 | % specified name and if found returns attributes for that element. |
| 343 | % |
| 344 | % o name: the configure name. |
| 345 | % |
| 346 | % o exception: return any errors or warnings in this structure. |
| 347 | % |
| 348 | */ |
| 349 | MagickExport const ConfigureInfo *GetConfigureInfo(const char *name, |
| 350 | ExceptionInfo *exception) |
| 351 | { |
Cristy | f2dc1dd | 2020-12-28 13:59:26 -0500 | [diff] [blame] | 352 | const ConfigureInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 353 | *p; |
| 354 | |
| 355 | assert(exception != (ExceptionInfo *) NULL); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 356 | if (IsConfigureCacheInstantiated(exception) == MagickFalse) |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 357 | return((const ConfigureInfo *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 358 | /* |
| 359 | Search for configure tag. |
| 360 | */ |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 361 | LockSemaphoreInfo(configure_semaphore); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 362 | ResetLinkedListIterator(configure_cache); |
| 363 | p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_cache); |
cristy | 49d4d22 | 2014-03-16 00:37:58 +0000 | [diff] [blame] | 364 | if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) |
| 365 | { |
| 366 | UnlockSemaphoreInfo(configure_semaphore); |
| 367 | return(p); |
| 368 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 369 | while (p != (const ConfigureInfo *) NULL) |
| 370 | { |
| 371 | if (LocaleCompare(name,p->name) == 0) |
| 372 | break; |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 373 | p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_cache); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 374 | } |
| 375 | if (p != (ConfigureInfo *) NULL) |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 376 | (void) InsertValueInLinkedList(configure_cache,0, |
| 377 | RemoveElementByValueFromLinkedList(configure_cache,p)); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 378 | UnlockSemaphoreInfo(configure_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 379 | return(p); |
| 380 | } |
| 381 | |
| 382 | /* |
| 383 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 384 | % % |
| 385 | % % |
| 386 | % % |
| 387 | % G e t C o n f i g u r e I n f o L i s t % |
| 388 | % % |
| 389 | % % |
| 390 | % % |
| 391 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 392 | % |
| 393 | % GetConfigureInfoList() returns any configure options that match the |
| 394 | % specified pattern. |
| 395 | % |
| 396 | % The format of the GetConfigureInfoList function is: |
| 397 | % |
| 398 | % const ConfigureInfo **GetConfigureInfoList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 399 | % size_t *number_options,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 400 | % |
| 401 | % A description of each parameter follows: |
| 402 | % |
| 403 | % o pattern: Specifies a pointer to a text string containing a pattern. |
| 404 | % |
| 405 | % o number_options: This integer returns the number of configure options in |
| 406 | % the list. |
| 407 | % |
| 408 | % o exception: return any errors or warnings in this structure. |
| 409 | % |
| 410 | */ |
| 411 | |
| 412 | #if defined(__cplusplus) || defined(c_plusplus) |
| 413 | extern "C" { |
| 414 | #endif |
| 415 | |
| 416 | static int ConfigureInfoCompare(const void *x,const void *y) |
| 417 | { |
| 418 | const ConfigureInfo |
| 419 | **p, |
| 420 | **q; |
| 421 | |
| 422 | p=(const ConfigureInfo **) x, |
| 423 | q=(const ConfigureInfo **) y; |
| 424 | if (LocaleCompare((*p)->path,(*q)->path) == 0) |
| 425 | return(LocaleCompare((*p)->name,(*q)->name)); |
| 426 | return(LocaleCompare((*p)->path,(*q)->path)); |
| 427 | } |
| 428 | |
| 429 | #if defined(__cplusplus) || defined(c_plusplus) |
| 430 | } |
| 431 | #endif |
| 432 | |
| 433 | MagickExport const ConfigureInfo **GetConfigureInfoList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 434 | size_t *number_options,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 435 | { |
| 436 | const ConfigureInfo |
| 437 | **options; |
| 438 | |
Cristy | f2dc1dd | 2020-12-28 13:59:26 -0500 | [diff] [blame] | 439 | const ConfigureInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 440 | *p; |
| 441 | |
Cristy | f2dc1dd | 2020-12-28 13:59:26 -0500 | [diff] [blame] | 442 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 443 | i; |
| 444 | |
| 445 | /* |
| 446 | Allocate configure list. |
| 447 | */ |
| 448 | assert(pattern != (char *) NULL); |
| 449 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 450 | assert(number_options != (size_t *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 451 | *number_options=0; |
| 452 | p=GetConfigureInfo("*",exception); |
| 453 | if (p == (const ConfigureInfo *) NULL) |
| 454 | return((const ConfigureInfo **) NULL); |
| 455 | options=(const ConfigureInfo **) AcquireQuantumMemory((size_t) |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 456 | GetNumberOfElementsInLinkedList(configure_cache)+1UL,sizeof(*options)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 457 | if (options == (const ConfigureInfo **) NULL) |
| 458 | return((const ConfigureInfo **) NULL); |
| 459 | /* |
| 460 | Generate configure list. |
| 461 | */ |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 462 | LockSemaphoreInfo(configure_semaphore); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 463 | ResetLinkedListIterator(configure_cache); |
| 464 | p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_cache); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 465 | for (i=0; p != (const ConfigureInfo *) NULL; ) |
| 466 | { |
| 467 | if ((p->stealth == MagickFalse) && |
| 468 | (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) |
| 469 | options[i++]=p; |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 470 | p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_cache); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 471 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 472 | UnlockSemaphoreInfo(configure_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 473 | qsort((void *) options,(size_t) i,sizeof(*options),ConfigureInfoCompare); |
| 474 | options[i]=(ConfigureInfo *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 475 | *number_options=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 476 | return(options); |
| 477 | } |
| 478 | |
| 479 | /* |
| 480 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 481 | % % |
| 482 | % % |
| 483 | % % |
| 484 | % G e t C o n f i g u r e L i s t % |
| 485 | % % |
| 486 | % % |
| 487 | % % |
| 488 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 489 | % |
| 490 | % GetConfigureList() returns any configure options that match the specified |
| 491 | % pattern. |
| 492 | % |
| 493 | % The format of the GetConfigureList function is: |
| 494 | % |
| 495 | % char **GetConfigureList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 496 | % size_t *number_options,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 497 | % |
| 498 | % A description of each parameter follows: |
| 499 | % |
| 500 | % o pattern: Specifies a pointer to a text string containing a pattern. |
| 501 | % |
| 502 | % o number_options: This integer returns the number of options in the list. |
| 503 | % |
| 504 | % o exception: return any errors or warnings in this structure. |
| 505 | % |
| 506 | */ |
| 507 | |
| 508 | #if defined(__cplusplus) || defined(c_plusplus) |
| 509 | extern "C" { |
| 510 | #endif |
| 511 | |
| 512 | static int ConfigureCompare(const void *x,const void *y) |
| 513 | { |
Cristy | f2dc1dd | 2020-12-28 13:59:26 -0500 | [diff] [blame] | 514 | char |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 515 | **p, |
| 516 | **q; |
| 517 | |
| 518 | p=(char **) x; |
| 519 | q=(char **) y; |
| 520 | return(LocaleCompare(*p,*q)); |
| 521 | } |
| 522 | |
| 523 | #if defined(__cplusplus) || defined(c_plusplus) |
| 524 | } |
| 525 | #endif |
| 526 | |
| 527 | MagickExport char **GetConfigureList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 528 | size_t *number_options,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 529 | { |
| 530 | char |
| 531 | **options; |
| 532 | |
Cristy | f2dc1dd | 2020-12-28 13:59:26 -0500 | [diff] [blame] | 533 | const ConfigureInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 534 | *p; |
| 535 | |
Cristy | f2dc1dd | 2020-12-28 13:59:26 -0500 | [diff] [blame] | 536 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 537 | i; |
| 538 | |
| 539 | /* |
| 540 | Allocate configure list. |
| 541 | */ |
| 542 | assert(pattern != (char *) NULL); |
| 543 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 544 | assert(number_options != (size_t *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 545 | *number_options=0; |
| 546 | p=GetConfigureInfo("*",exception); |
| 547 | if (p == (const ConfigureInfo *) NULL) |
| 548 | return((char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 549 | options=(char **) AcquireQuantumMemory((size_t) |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 550 | GetNumberOfElementsInLinkedList(configure_cache)+1UL,sizeof(*options)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 551 | if (options == (char **) NULL) |
| 552 | return((char **) NULL); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 553 | LockSemaphoreInfo(configure_semaphore); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 554 | ResetLinkedListIterator(configure_cache); |
| 555 | p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_cache); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 556 | for (i=0; p != (const ConfigureInfo *) NULL; ) |
| 557 | { |
| 558 | if ((p->stealth == MagickFalse) && |
| 559 | (GlobExpression(p->name,pattern,MagickFalse) != MagickFalse)) |
| 560 | options[i++]=ConstantString(p->name); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 561 | p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_cache); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 562 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 563 | UnlockSemaphoreInfo(configure_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 564 | qsort((void *) options,(size_t) i,sizeof(*options),ConfigureCompare); |
| 565 | options[i]=(char *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 566 | *number_options=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 567 | return(options); |
| 568 | } |
| 569 | |
| 570 | /* |
| 571 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 572 | % % |
| 573 | % % |
| 574 | % % |
| 575 | % G e t C o n f i g u r e O p t i o n % |
| 576 | % % |
| 577 | % % |
| 578 | % % |
| 579 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 580 | % |
| 581 | % GetConfigureOption() returns the value associated with the configure option. |
| 582 | % |
| 583 | % The format of the GetConfigureOption method is: |
| 584 | % |
| 585 | % char *GetConfigureOption(const char *option) |
| 586 | % |
| 587 | % A description of each parameter follows: |
| 588 | % |
| 589 | % o configure_info: The configure info. |
| 590 | % |
| 591 | */ |
| 592 | MagickExport char *GetConfigureOption(const char *option) |
| 593 | { |
| 594 | const char |
| 595 | *value; |
| 596 | |
| 597 | const ConfigureInfo |
| 598 | *configure_info; |
| 599 | |
| 600 | ExceptionInfo |
| 601 | *exception; |
| 602 | |
| 603 | assert(option != (const char *) NULL); |
| 604 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",option); |
| 605 | exception=AcquireExceptionInfo(); |
| 606 | configure_info=GetConfigureInfo(option,exception); |
| 607 | exception=DestroyExceptionInfo(exception); |
| 608 | if (configure_info == (ConfigureInfo *) NULL) |
| 609 | return((char *) NULL); |
| 610 | value=GetConfigureValue(configure_info); |
| 611 | if ((value == (const char *) NULL) || (*value == '\0')) |
| 612 | return((char *) NULL); |
| 613 | return(ConstantString(value)); |
| 614 | } |
| 615 | |
| 616 | /* |
| 617 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 618 | % % |
| 619 | % % |
| 620 | % % |
| 621 | % G e t C o n f i g u r e O p t i o n s % |
| 622 | % % |
| 623 | % % |
| 624 | % % |
| 625 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 626 | % |
| 627 | % GetConfigureOptions() returns any Magick configuration options associated |
| 628 | % with the specified filename. |
| 629 | % |
| 630 | % The format of the GetConfigureOptions method is: |
| 631 | % |
| 632 | % LinkedListInfo *GetConfigureOptions(const char *filename, |
| 633 | % ExceptionInfo *exception) |
| 634 | % |
| 635 | % A description of each parameter follows: |
| 636 | % |
| 637 | % o filename: the configure file name. |
| 638 | % |
| 639 | % o exception: return any errors or warnings in this structure. |
| 640 | % |
| 641 | */ |
| 642 | MagickExport LinkedListInfo *GetConfigureOptions(const char *filename, |
| 643 | ExceptionInfo *exception) |
| 644 | { |
| 645 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 646 | path[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 647 | |
| 648 | const char |
| 649 | *element; |
| 650 | |
| 651 | LinkedListInfo |
| 652 | *options, |
| 653 | *paths; |
| 654 | |
| 655 | StringInfo |
| 656 | *xml; |
| 657 | |
| 658 | assert(filename != (const char *) NULL); |
| 659 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename); |
| 660 | assert(exception != (ExceptionInfo *) NULL); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 661 | (void) CopyMagickString(path,filename,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 662 | /* |
| 663 | Load XML from configuration files to linked-list. |
| 664 | */ |
| 665 | options=NewLinkedList(0); |
| 666 | paths=GetConfigurePaths(filename,exception); |
| 667 | if (paths != (LinkedListInfo *) NULL) |
| 668 | { |
| 669 | ResetLinkedListIterator(paths); |
| 670 | element=(const char *) GetNextValueInLinkedList(paths); |
| 671 | while (element != (const char *) NULL) |
| 672 | { |
Cristy | f4a35c3 | 2016-06-02 13:45:36 -0400 | [diff] [blame] | 673 | (void) FormatLocaleString(path,MagickPathExtent,"%s%s",element, |
| 674 | filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 675 | (void) LogMagickEvent(ConfigureEvent,GetMagickModule(), |
| 676 | "Searching for configure file: \"%s\"",path); |
| 677 | xml=ConfigureFileToStringInfo(path); |
| 678 | if (xml != (StringInfo *) NULL) |
| 679 | (void) AppendValueToLinkedList(options,xml); |
| 680 | element=(const char *) GetNextValueInLinkedList(paths); |
| 681 | } |
| 682 | paths=DestroyLinkedList(paths,RelinquishMagickMemory); |
| 683 | } |
cristy | 0157aea | 2010-04-24 21:12:18 +0000 | [diff] [blame] | 684 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) |
cristy | 7e24752 | 2011-11-29 14:59:23 +0000 | [diff] [blame] | 685 | if (GetNumberOfElementsInLinkedList(options) == 0) |
| 686 | { |
| 687 | char |
| 688 | *blob; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 689 | |
cristy | 7e24752 | 2011-11-29 14:59:23 +0000 | [diff] [blame] | 690 | blob=(char *) NTResourceToBlob(filename); |
| 691 | if (blob != (char *) NULL) |
| 692 | { |
| 693 | xml=AcquireStringInfo(0); |
| 694 | SetStringInfoLength(xml,strlen(blob)+1); |
cristy | 52070b4 | 2012-02-19 22:03:21 +0000 | [diff] [blame] | 695 | SetStringInfoDatum(xml,(unsigned char *) blob); |
cristy | 7e24752 | 2011-11-29 14:59:23 +0000 | [diff] [blame] | 696 | SetStringInfoPath(xml,filename); |
| 697 | (void) AppendValueToLinkedList(options,xml); |
| 698 | } |
| 699 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 700 | #endif |
| 701 | if (GetNumberOfElementsInLinkedList(options) == 0) |
| 702 | (void) ThrowMagickException(exception,GetMagickModule(),ConfigureWarning, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 703 | "UnableToOpenConfigureFile","`%s'",filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 704 | ResetLinkedListIterator(options); |
| 705 | return(options); |
| 706 | } |
| 707 | |
| 708 | /* |
| 709 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 710 | % % |
| 711 | % % |
| 712 | % % |
| 713 | % G e t C o n f i g u r e P a t h s % |
| 714 | % % |
| 715 | % % |
| 716 | % % |
| 717 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 718 | % |
| 719 | % GetConfigurePaths() returns any Magick configuration paths associated |
| 720 | % with the specified filename. |
| 721 | % |
| 722 | % The format of the GetConfigurePaths method is: |
| 723 | % |
| 724 | % LinkedListInfo *GetConfigurePaths(const char *filename, |
| 725 | % ExceptionInfo *exception) |
| 726 | % |
| 727 | % A description of each parameter follows: |
| 728 | % |
| 729 | % o filename: the configure file name. |
| 730 | % |
| 731 | % o exception: return any errors or warnings in this structure. |
| 732 | % |
| 733 | */ |
| 734 | MagickExport LinkedListInfo *GetConfigurePaths(const char *filename, |
| 735 | ExceptionInfo *exception) |
| 736 | { |
cristy | 7e24752 | 2011-11-29 14:59:23 +0000 | [diff] [blame] | 737 | #define RegistryKey "ConfigurePath" |
cristy | 6c28ec0 | 2011-10-28 11:37:57 +0000 | [diff] [blame] | 738 | #define MagickCoreDLL "CORE_RL_MagickCore_.dll" |
| 739 | #define MagickCoreDebugDLL "CORE_DB_MagickCore_.dll" |
| 740 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 741 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 742 | path[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 743 | |
| 744 | LinkedListInfo |
| 745 | *paths; |
| 746 | |
| 747 | assert(filename != (const char *) NULL); |
| 748 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename); |
| 749 | assert(exception != (ExceptionInfo *) NULL); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 750 | (void) CopyMagickString(path,filename,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 751 | paths=NewLinkedList(0); |
| 752 | { |
| 753 | char |
| 754 | *configure_path; |
| 755 | |
| 756 | /* |
| 757 | Search $MAGICK_CONFIGURE_PATH. |
| 758 | */ |
| 759 | configure_path=GetEnvironmentValue("MAGICK_CONFIGURE_PATH"); |
| 760 | if (configure_path != (char *) NULL) |
| 761 | { |
Cristy | f2dc1dd | 2020-12-28 13:59:26 -0500 | [diff] [blame] | 762 | char |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 763 | *p, |
| 764 | *q; |
| 765 | |
| 766 | for (p=configure_path-1; p != (char *) NULL; ) |
| 767 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 768 | (void) CopyMagickString(path,p+1,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 769 | q=strchr(path,DirectoryListSeparator); |
| 770 | if (q != (char *) NULL) |
| 771 | *q='\0'; |
| 772 | q=path+strlen(path)-1; |
| 773 | if ((q >= path) && (*q != *DirectorySeparator)) |
| 774 | (void) ConcatenateMagickString(path,DirectorySeparator, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 775 | MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 776 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
| 777 | p=strchr(p+1,DirectoryListSeparator); |
| 778 | } |
| 779 | configure_path=DestroyString(configure_path); |
| 780 | } |
| 781 | } |
| 782 | #if defined(MAGICKCORE_INSTALLED_SUPPORT) |
cristy | 4f82071 | 2011-04-01 12:35:43 +0000 | [diff] [blame] | 783 | #if defined(MAGICKCORE_SHARE_PATH) |
cristy | 6c28ec0 | 2011-10-28 11:37:57 +0000 | [diff] [blame] | 784 | (void) AppendValueToLinkedList(paths,ConstantString(MAGICKCORE_SHARE_PATH)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 785 | #endif |
cristy | 670aa3c | 2011-11-03 00:54:00 +0000 | [diff] [blame] | 786 | #if defined(MAGICKCORE_SHAREARCH_PATH) |
| 787 | (void) AppendValueToLinkedList(paths,ConstantString( |
| 788 | MAGICKCORE_SHAREARCH_PATH)); |
| 789 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 790 | #if defined(MAGICKCORE_CONFIGURE_PATH) |
| 791 | (void) AppendValueToLinkedList(paths,ConstantString( |
| 792 | MAGICKCORE_CONFIGURE_PATH)); |
| 793 | #endif |
| 794 | #if defined(MAGICKCORE_DOCUMENTATION_PATH) |
| 795 | (void) AppendValueToLinkedList(paths,ConstantString( |
| 796 | MAGICKCORE_DOCUMENTATION_PATH)); |
| 797 | #endif |
cristy | 4f82071 | 2011-04-01 12:35:43 +0000 | [diff] [blame] | 798 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) && !(defined(MAGICKCORE_CONFIGURE_PATH) || defined(MAGICKCORE_SHARE_PATH)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 799 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 800 | unsigned char |
| 801 | *key_value; |
| 802 | |
| 803 | /* |
| 804 | Locate file via registry key. |
| 805 | */ |
cristy | 7e24752 | 2011-11-29 14:59:23 +0000 | [diff] [blame] | 806 | key_value=NTRegistryKeyLookup(RegistryKey); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 807 | if (key_value != (unsigned char *) NULL) |
| 808 | { |
Cristy | 9799a84 | 2015-10-04 19:44:36 -0400 | [diff] [blame] | 809 | (void) FormatLocaleString(path,MagickPathExtent,"%s%s",(char *) |
| 810 | key_value,DirectorySeparator); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 811 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
| 812 | key_value=(unsigned char *) RelinquishMagickMemory(key_value); |
| 813 | } |
| 814 | } |
| 815 | #endif |
| 816 | #else |
| 817 | { |
| 818 | char |
| 819 | *home; |
| 820 | |
| 821 | /* |
| 822 | Search under MAGICK_HOME. |
| 823 | */ |
| 824 | home=GetEnvironmentValue("MAGICK_HOME"); |
| 825 | if (home != (char *) NULL) |
| 826 | { |
Cristy | 9125cd5 | 2015-09-17 20:16:13 -0400 | [diff] [blame] | 827 | #if !defined(MAGICKCORE_POSIX_SUPPORT) || defined( __VMS ) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 828 | (void) FormatLocaleString(path,MagickPathExtent,"%s%s",home, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 829 | DirectorySeparator); |
| 830 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
| 831 | #else |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 832 | (void) FormatLocaleString(path,MagickPathExtent,"%s/etc/%s/",home, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 833 | MAGICKCORE_CONFIGURE_RELATIVE_PATH); |
| 834 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 835 | (void) FormatLocaleString(path,MagickPathExtent,"%s/share/%s/",home, |
cristy | 4f82071 | 2011-04-01 12:35:43 +0000 | [diff] [blame] | 836 | MAGICKCORE_SHARE_RELATIVE_PATH); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 837 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 838 | (void) FormatLocaleString(path,MagickPathExtent,"%s", |
cristy | 780d58c | 2013-05-03 13:49:00 +0000 | [diff] [blame] | 839 | MAGICKCORE_SHAREARCH_PATH); |
| 840 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 841 | #endif |
| 842 | home=DestroyString(home); |
| 843 | } |
| 844 | } |
| 845 | if (*GetClientPath() != '\0') |
| 846 | { |
Cristy | 9125cd5 | 2015-09-17 20:16:13 -0400 | [diff] [blame] | 847 | #if !defined(MAGICKCORE_POSIX_SUPPORT) || defined( __VMS ) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 848 | (void) FormatLocaleString(path,MagickPathExtent,"%s%s",GetClientPath(), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 849 | DirectorySeparator); |
| 850 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
| 851 | #else |
| 852 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 853 | prefix[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 854 | |
| 855 | /* |
| 856 | Search based on executable directory if directory is known. |
| 857 | */ |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 858 | (void) CopyMagickString(prefix,GetClientPath(),MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 859 | ChopPathComponents(prefix,1); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 860 | (void) FormatLocaleString(path,MagickPathExtent,"%s/etc/%s/",prefix, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 861 | MAGICKCORE_CONFIGURE_RELATIVE_PATH); |
| 862 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 863 | (void) FormatLocaleString(path,MagickPathExtent,"%s/share/%s/",prefix, |
cristy | 4f82071 | 2011-04-01 12:35:43 +0000 | [diff] [blame] | 864 | MAGICKCORE_SHARE_RELATIVE_PATH); |
| 865 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 866 | (void) FormatLocaleString(path,MagickPathExtent,"%s", |
cristy | 780d58c | 2013-05-03 13:49:00 +0000 | [diff] [blame] | 867 | MAGICKCORE_SHAREARCH_PATH); |
| 868 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 869 | #endif |
| 870 | } |
cristy | 51b1ac5 | 2010-10-30 02:27:14 +0000 | [diff] [blame] | 871 | /* |
| 872 | Search current directory. |
| 873 | */ |
| 874 | (void) AppendValueToLinkedList(paths,ConstantString("")); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 875 | #endif |
| 876 | { |
| 877 | char |
| 878 | *home; |
| 879 | |
Cristy | 9799a84 | 2015-10-04 19:44:36 -0400 | [diff] [blame] | 880 | home=GetEnvironmentValue("XDG_CONFIG_HOME"); |
Dirk Lemstra | dfb9ecb | 2019-04-12 22:24:33 +0200 | [diff] [blame] | 881 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__MINGW32__) |
Cristy | 1dd96da | 2015-10-06 07:52:01 -0400 | [diff] [blame] | 882 | if (home == (char *) NULL) |
| 883 | home=GetEnvironmentValue("LOCALAPPDATA"); |
| 884 | if (home == (char *) NULL) |
| 885 | home=GetEnvironmentValue("APPDATA"); |
| 886 | if (home == (char *) NULL) |
| 887 | home=GetEnvironmentValue("USERPROFILE"); |
Dirk Lemstra | dfb9ecb | 2019-04-12 22:24:33 +0200 | [diff] [blame] | 888 | #endif |
Cristy | 9799a84 | 2015-10-04 19:44:36 -0400 | [diff] [blame] | 889 | if (home != (char *) NULL) |
Cristy | 1dd96da | 2015-10-06 07:52:01 -0400 | [diff] [blame] | 890 | { |
Cristy | 9799a84 | 2015-10-04 19:44:36 -0400 | [diff] [blame] | 891 | /* |
| 892 | Search $XDG_CONFIG_HOME/ImageMagick. |
| 893 | */ |
Cristy | a8b2bb2 | 2016-03-25 10:39:01 -0400 | [diff] [blame] | 894 | (void) FormatLocaleString(path,MagickPathExtent,"%s%sImageMagick%s", |
dirk | a4bed21 | 2015-11-09 13:02:16 +0100 | [diff] [blame] | 895 | home,DirectorySeparator,DirectorySeparator); |
Cristy | 9799a84 | 2015-10-04 19:44:36 -0400 | [diff] [blame] | 896 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
| 897 | home=DestroyString(home); |
| 898 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 899 | home=GetEnvironmentValue("HOME"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 900 | if (home != (char *) NULL) |
| 901 | { |
| 902 | /* |
cristy | 9f3b4fc | 2014-02-08 14:56:20 +0000 | [diff] [blame] | 903 | Search $HOME/.config/ImageMagick. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 904 | */ |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 905 | (void) FormatLocaleString(path,MagickPathExtent, |
cristy | 9f3b4fc | 2014-02-08 14:56:20 +0000 | [diff] [blame] | 906 | "%s%s.config%sImageMagick%s",home,DirectorySeparator, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 907 | DirectorySeparator,DirectorySeparator); |
| 908 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
| 909 | home=DestroyString(home); |
| 910 | } |
| 911 | } |
cristy | 0157aea | 2010-04-24 21:12:18 +0000 | [diff] [blame] | 912 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 913 | { |
| 914 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 915 | module_path[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 916 | |
cristy | 6c28ec0 | 2011-10-28 11:37:57 +0000 | [diff] [blame] | 917 | if ((NTGetModulePath(MagickCoreDLL,module_path) != MagickFalse) || |
| 918 | (NTGetModulePath(MagickCoreDebugDLL,module_path) != MagickFalse)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 919 | { |
cristy | 7e24752 | 2011-11-29 14:59:23 +0000 | [diff] [blame] | 920 | unsigned char |
| 921 | *key_value; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 922 | |
| 923 | /* |
| 924 | Search module path. |
| 925 | */ |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 926 | (void) FormatLocaleString(path,MagickPathExtent,"%s%s",module_path, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 927 | DirectorySeparator); |
cristy | 7e24752 | 2011-11-29 14:59:23 +0000 | [diff] [blame] | 928 | key_value=NTRegistryKeyLookup(RegistryKey); |
| 929 | if (key_value == (unsigned char *) NULL) |
| 930 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
| 931 | else |
| 932 | key_value=(unsigned char *) RelinquishMagickMemory(key_value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 933 | } |
| 934 | if (NTGetModulePath("Magick.dll",module_path) != MagickFalse) |
| 935 | { |
| 936 | /* |
| 937 | Search PerlMagick module path. |
| 938 | */ |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 939 | (void) FormatLocaleString(path,MagickPathExtent,"%s%s",module_path, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 940 | DirectorySeparator); |
| 941 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 942 | (void) FormatLocaleString(path,MagickPathExtent,"%s%s",module_path, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 943 | "\\inc\\lib\\auto\\Image\\Magick\\"); |
| 944 | (void) AppendValueToLinkedList(paths,ConstantString(path)); |
| 945 | } |
| 946 | } |
| 947 | #endif |
Cristy | 7603949 | 2018-01-21 14:49:02 -0500 | [diff] [blame] | 948 | if (GetNumberOfElementsInLinkedList(paths) == 0) |
| 949 | (void) ThrowMagickException(exception,GetMagickModule(),ConfigureWarning, |
| 950 | "no configuration paths found","`%s'",filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 951 | return(paths); |
| 952 | } |
| 953 | |
| 954 | /* |
| 955 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 956 | % % |
| 957 | % % |
| 958 | % % |
| 959 | % G e t C o n f i g u r e V a l u e % |
| 960 | % % |
| 961 | % % |
| 962 | % % |
| 963 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 964 | % |
| 965 | % GetConfigureValue() returns the value associated with the configure info. |
| 966 | % |
| 967 | % The format of the GetConfigureValue method is: |
| 968 | % |
| 969 | % const char *GetConfigureValue(const ConfigureInfo *configure_info) |
| 970 | % |
| 971 | % A description of each parameter follows: |
| 972 | % |
| 973 | % o configure_info: The configure info. |
| 974 | % |
| 975 | */ |
| 976 | MagickExport const char *GetConfigureValue(const ConfigureInfo *configure_info) |
| 977 | { |
| 978 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 979 | assert(configure_info != (ConfigureInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 980 | assert(configure_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 981 | return(configure_info->value); |
| 982 | } |
| 983 | |
| 984 | /* |
| 985 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 986 | % % |
| 987 | % % |
| 988 | % % |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 989 | + I s C o n f i g u r e C a c h e I n s t a n t i a t e d % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 990 | % % |
| 991 | % % |
| 992 | % % |
| 993 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 994 | % |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 995 | % IsConfigureCacheInstantiated() determines if the configure list is |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 996 | % instantiated. If not, it instantiates the list and returns it. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 997 | % |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 998 | % The format of the IsConfigureInstantiated method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 999 | % |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 1000 | % MagickBooleanType IsConfigureCacheInstantiated(ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1001 | % |
| 1002 | % A description of each parameter follows. |
| 1003 | % |
| 1004 | % o exception: return any errors or warnings in this structure. |
| 1005 | % |
| 1006 | */ |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 1007 | static MagickBooleanType IsConfigureCacheInstantiated(ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1008 | { |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 1009 | if (configure_cache == (LinkedListInfo *) NULL) |
| 1010 | { |
| 1011 | if (configure_semaphore == (SemaphoreInfo *) NULL) |
| 1012 | ActivateSemaphoreInfo(&configure_semaphore); |
| 1013 | LockSemaphoreInfo(configure_semaphore); |
| 1014 | if (configure_cache == (LinkedListInfo *) NULL) |
| 1015 | configure_cache=AcquireConfigureCache(ConfigureFilename,exception); |
| 1016 | UnlockSemaphoreInfo(configure_semaphore); |
| 1017 | } |
| 1018 | return(configure_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | /* |
| 1022 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1023 | % % |
| 1024 | % % |
| 1025 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1026 | % L i s t C o n f i g u r e I n f o % |
| 1027 | % % |
| 1028 | % % |
| 1029 | % % |
| 1030 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1031 | % |
| 1032 | % ListConfigureInfo() lists the configure info to a file. |
| 1033 | % |
| 1034 | % The format of the ListConfigureInfo method is: |
| 1035 | % |
| 1036 | % MagickBooleanType ListConfigureInfo(FILE *file,ExceptionInfo *exception) |
| 1037 | % |
| 1038 | % A description of each parameter follows. |
| 1039 | % |
| 1040 | % o file: An pointer to a FILE. |
| 1041 | % |
| 1042 | % o exception: return any errors or warnings in this structure. |
| 1043 | % |
| 1044 | */ |
| 1045 | MagickExport MagickBooleanType ListConfigureInfo(FILE *file, |
| 1046 | ExceptionInfo *exception) |
| 1047 | { |
| 1048 | const char |
| 1049 | *name, |
| 1050 | *path, |
| 1051 | *value; |
| 1052 | |
| 1053 | const ConfigureInfo |
| 1054 | **configure_info; |
| 1055 | |
Cristy | f2dc1dd | 2020-12-28 13:59:26 -0500 | [diff] [blame] | 1056 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1057 | i; |
| 1058 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1059 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1060 | number_options; |
| 1061 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 1062 | ssize_t |
| 1063 | j; |
| 1064 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1065 | if (file == (const FILE *) NULL) |
| 1066 | file=stdout; |
| 1067 | configure_info=GetConfigureInfoList("*",&number_options,exception); |
| 1068 | if (configure_info == (const ConfigureInfo **) NULL) |
| 1069 | return(MagickFalse); |
| 1070 | path=(const char *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1071 | for (i=0; i < (ssize_t) number_options; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1072 | { |
| 1073 | if (configure_info[i]->stealth != MagickFalse) |
| 1074 | continue; |
| 1075 | if ((path == (const char *) NULL) || |
| 1076 | (LocaleCompare(path,configure_info[i]->path) != 0)) |
| 1077 | { |
| 1078 | if (configure_info[i]->path != (char *) NULL) |
cristy | 1e60481 | 2011-05-19 18:07:50 +0000 | [diff] [blame] | 1079 | (void) FormatLocaleFile(file,"\nPath: %s\n\n", |
| 1080 | configure_info[i]->path); |
Cristy | 1af75e5 | 2018-11-15 07:59:32 -0500 | [diff] [blame] | 1081 | (void) FormatLocaleFile(file,"Name Value\n"); |
cristy | 1e60481 | 2011-05-19 18:07:50 +0000 | [diff] [blame] | 1082 | (void) FormatLocaleFile(file, |
| 1083 | "-------------------------------------------------" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1084 | "------------------------------\n"); |
| 1085 | } |
| 1086 | path=configure_info[i]->path; |
| 1087 | name="unknown"; |
| 1088 | if (configure_info[i]->name != (char *) NULL) |
| 1089 | name=configure_info[i]->name; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1090 | (void) FormatLocaleFile(file,"%s",name); |
Cristy | 1af75e5 | 2018-11-15 07:59:32 -0500 | [diff] [blame] | 1091 | for (j=(ssize_t) strlen(name); j <= 20; j++) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1092 | (void) FormatLocaleFile(file," "); |
| 1093 | (void) FormatLocaleFile(file," "); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1094 | value="unknown"; |
| 1095 | if (configure_info[i]->value != (char *) NULL) |
| 1096 | value=configure_info[i]->value; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1097 | (void) FormatLocaleFile(file,"%s",value); |
| 1098 | (void) FormatLocaleFile(file,"\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1099 | } |
| 1100 | (void) fflush(file); |
cristy | cd2cd18 | 2014-03-18 12:10:55 +0000 | [diff] [blame] | 1101 | configure_info=(const ConfigureInfo **) RelinquishMagickMemory((void *) |
| 1102 | configure_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1103 | return(MagickTrue); |
| 1104 | } |
| 1105 | |
Cristy | d1e7b76 | 2019-12-07 19:00:20 -0500 | [diff] [blame] | 1106 | #if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1107 | /* |
| 1108 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1109 | % % |
| 1110 | % % |
| 1111 | % % |
dirk | fc0f124 | 2016-03-26 00:36:39 +0100 | [diff] [blame] | 1112 | + L o a d C o n f i g u r e C a c h e % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1113 | % % |
| 1114 | % % |
| 1115 | % % |
| 1116 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1117 | % |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 1118 | % LoadConfigureCache() loads the configure configurations which provides a |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1119 | % mapping between configure attributes and a configure name. |
| 1120 | % |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 1121 | % The format of the LoadConfigureCache method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1122 | % |
dirk | b18d864 | 2016-07-17 19:32:43 +0200 | [diff] [blame] | 1123 | % MagickBooleanType LoadConfigureCache(LinkedListInfo *cache, |
cristy | 0d8101e | 2014-04-10 00:13:05 +0000 | [diff] [blame] | 1124 | % const char *xml,const char *filename,const size_t depth, |
| 1125 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1126 | % |
| 1127 | % A description of each parameter follows: |
| 1128 | % |
| 1129 | % o xml: The configure list in XML format. |
| 1130 | % |
| 1131 | % o filename: The configure list filename. |
| 1132 | % |
| 1133 | % o depth: depth of <include /> statements. |
| 1134 | % |
| 1135 | % o exception: return any errors or warnings in this structure. |
| 1136 | % |
| 1137 | */ |
dirk | b18d864 | 2016-07-17 19:32:43 +0200 | [diff] [blame] | 1138 | static MagickBooleanType LoadConfigureCache(LinkedListInfo *cache, |
cristy | cd2cd18 | 2014-03-18 12:10:55 +0000 | [diff] [blame] | 1139 | const char *xml,const char *filename,const size_t depth, |
| 1140 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1141 | { |
| 1142 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1143 | keyword[MagickPathExtent], |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1144 | *token; |
| 1145 | |
| 1146 | ConfigureInfo |
| 1147 | *configure_info; |
| 1148 | |
| 1149 | const char |
| 1150 | *q; |
| 1151 | |
cristy | 759ba91 | 2014-06-26 11:59:43 +0000 | [diff] [blame] | 1152 | MagickStatusType |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1153 | status; |
| 1154 | |
dirk | fc0f124 | 2016-03-26 00:36:39 +0100 | [diff] [blame] | 1155 | size_t |
| 1156 | extent; |
| 1157 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1158 | /* |
| 1159 | Load the configure map file. |
| 1160 | */ |
| 1161 | (void) LogMagickEvent(ConfigureEvent,GetMagickModule(), |
| 1162 | "Loading configure file \"%s\" ...",filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1163 | status=MagickTrue; |
| 1164 | configure_info=(ConfigureInfo *) NULL; |
dirk | fc0f124 | 2016-03-26 00:36:39 +0100 | [diff] [blame] | 1165 | token=AcquireString(xml); |
| 1166 | extent=strlen(token)+MagickPathExtent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1167 | for (q=(char *) xml; *q != '\0'; ) |
| 1168 | { |
| 1169 | /* |
| 1170 | Interpret XML. |
| 1171 | */ |
Cristy | 448fd18 | 2019-07-27 16:26:38 -0400 | [diff] [blame] | 1172 | (void) GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1173 | if (*token == '\0') |
| 1174 | break; |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1175 | (void) CopyMagickString(keyword,token,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1176 | if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0) |
| 1177 | { |
| 1178 | /* |
| 1179 | Doctype element. |
| 1180 | */ |
| 1181 | while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0')) |
Cristy | 448fd18 | 2019-07-27 16:26:38 -0400 | [diff] [blame] | 1182 | (void) GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1183 | continue; |
| 1184 | } |
| 1185 | if (LocaleNCompare(keyword,"<!--",4) == 0) |
| 1186 | { |
| 1187 | /* |
| 1188 | Comment element. |
| 1189 | */ |
| 1190 | while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0')) |
Cristy | 448fd18 | 2019-07-27 16:26:38 -0400 | [diff] [blame] | 1191 | (void) GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1192 | continue; |
| 1193 | } |
| 1194 | if (LocaleCompare(keyword,"<include") == 0) |
| 1195 | { |
| 1196 | /* |
| 1197 | Include element. |
| 1198 | */ |
| 1199 | while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0')) |
| 1200 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1201 | (void) CopyMagickString(keyword,token,MagickPathExtent); |
Cristy | 448fd18 | 2019-07-27 16:26:38 -0400 | [diff] [blame] | 1202 | (void) GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1203 | if (*token != '=') |
| 1204 | continue; |
Cristy | 448fd18 | 2019-07-27 16:26:38 -0400 | [diff] [blame] | 1205 | (void) GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1206 | if (LocaleCompare(keyword,"file") == 0) |
| 1207 | { |
Cristy | 8a4029f | 2018-02-05 07:35:07 -0500 | [diff] [blame] | 1208 | if (depth > MagickMaxRecursionDepth) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1209 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1210 | ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1211 | else |
| 1212 | { |
| 1213 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1214 | path[MagickPathExtent], |
dirk | b81f0ab | 2015-10-20 23:01:53 +0200 | [diff] [blame] | 1215 | *file_xml; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1216 | |
| 1217 | GetPathComponent(filename,HeadPath,path); |
| 1218 | if (*path != '\0') |
| 1219 | (void) ConcatenateMagickString(path,DirectorySeparator, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1220 | MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1221 | if (*token == *DirectorySeparator) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1222 | (void) CopyMagickString(path,token,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1223 | else |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1224 | (void) ConcatenateMagickString(path,token,MagickPathExtent); |
dirk | b81f0ab | 2015-10-20 23:01:53 +0200 | [diff] [blame] | 1225 | file_xml=FileToXML(path,~0UL); |
| 1226 | if (file_xml != (char *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1227 | { |
dirk | b18d864 | 2016-07-17 19:32:43 +0200 | [diff] [blame] | 1228 | status&=LoadConfigureCache(cache,file_xml,path,depth+1, |
| 1229 | exception); |
dirk | b81f0ab | 2015-10-20 23:01:53 +0200 | [diff] [blame] | 1230 | file_xml=DestroyString(file_xml); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1231 | } |
| 1232 | } |
| 1233 | } |
| 1234 | } |
| 1235 | continue; |
| 1236 | } |
| 1237 | if (LocaleCompare(keyword,"<configure") == 0) |
| 1238 | { |
| 1239 | /* |
| 1240 | Configure element. |
| 1241 | */ |
Dirk Lemstra | 06344a0 | 2017-10-15 10:10:01 +0200 | [diff] [blame] | 1242 | configure_info=(ConfigureInfo *) AcquireCriticalMemory( |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1243 | sizeof(*configure_info)); |
Cristy | 81bfff2 | 2018-03-10 07:58:31 -0500 | [diff] [blame] | 1244 | (void) memset(configure_info,0,sizeof(*configure_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1245 | configure_info->path=ConstantString(filename); |
cristy | 54a531d | 2009-10-21 17:58:01 +0000 | [diff] [blame] | 1246 | configure_info->exempt=MagickFalse; |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1247 | configure_info->signature=MagickCoreSignature; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1248 | continue; |
| 1249 | } |
| 1250 | if (configure_info == (ConfigureInfo *) NULL) |
| 1251 | continue; |
Cristy | fed111e | 2017-01-09 07:22:16 -0500 | [diff] [blame] | 1252 | if ((LocaleCompare(keyword,"/>") == 0) || |
| 1253 | (LocaleCompare(keyword,"</policy>") == 0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1254 | { |
dirk | b18d864 | 2016-07-17 19:32:43 +0200 | [diff] [blame] | 1255 | status=AppendValueToLinkedList(cache,configure_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1256 | if (status == MagickFalse) |
| 1257 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1258 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1259 | configure_info->name); |
| 1260 | configure_info=(ConfigureInfo *) NULL; |
cristy | d45122f | 2014-01-14 23:46:16 +0000 | [diff] [blame] | 1261 | continue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1262 | } |
| 1263 | /* |
| 1264 | Parse configure element. |
| 1265 | */ |
Cristy | 448fd18 | 2019-07-27 16:26:38 -0400 | [diff] [blame] | 1266 | (void) GetNextToken(q,(const char **) NULL,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1267 | if (*token != '=') |
| 1268 | continue; |
Cristy | 448fd18 | 2019-07-27 16:26:38 -0400 | [diff] [blame] | 1269 | (void) GetNextToken(q,&q,extent,token); |
| 1270 | (void) GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1271 | switch (*keyword) |
| 1272 | { |
| 1273 | case 'N': |
| 1274 | case 'n': |
| 1275 | { |
| 1276 | if (LocaleCompare((char *) keyword,"name") == 0) |
| 1277 | { |
| 1278 | configure_info->name=ConstantString(token); |
| 1279 | break; |
| 1280 | } |
| 1281 | break; |
| 1282 | } |
| 1283 | case 'S': |
| 1284 | case 's': |
| 1285 | { |
| 1286 | if (LocaleCompare((char *) keyword,"stealth") == 0) |
| 1287 | { |
anthony | 6f20131 | 2012-03-30 04:08:15 +0000 | [diff] [blame] | 1288 | configure_info->stealth=IsStringTrue(token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1289 | break; |
| 1290 | } |
| 1291 | break; |
| 1292 | } |
| 1293 | case 'V': |
| 1294 | case 'v': |
| 1295 | { |
| 1296 | if (LocaleCompare((char *) keyword,"value") == 0) |
| 1297 | { |
| 1298 | configure_info->value=ConstantString(token); |
| 1299 | break; |
| 1300 | } |
| 1301 | break; |
| 1302 | } |
| 1303 | default: |
| 1304 | break; |
| 1305 | } |
| 1306 | } |
| 1307 | token=(char *) RelinquishMagickMemory(token); |
cristy | 759ba91 | 2014-06-26 11:59:43 +0000 | [diff] [blame] | 1308 | return(status != 0 ? MagickTrue : MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1309 | } |
Cristy | d1e7b76 | 2019-12-07 19:00:20 -0500 | [diff] [blame] | 1310 | #endif |