Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* |
michael@0 | 2 | ****************************************************************************** |
michael@0 | 3 | * |
michael@0 | 4 | * Copyright (C) 2009-2012, International Business Machines |
michael@0 | 5 | * Corporation and others. All Rights Reserved. |
michael@0 | 6 | * |
michael@0 | 7 | ****************************************************************************** |
michael@0 | 8 | * |
michael@0 | 9 | * FILE NAME : icuplug.h |
michael@0 | 10 | * |
michael@0 | 11 | * Date Name Description |
michael@0 | 12 | * 10/29/2009 sl New. |
michael@0 | 13 | ****************************************************************************** |
michael@0 | 14 | */ |
michael@0 | 15 | |
michael@0 | 16 | /** |
michael@0 | 17 | * \file |
michael@0 | 18 | * \brief C API: ICU Plugin API |
michael@0 | 19 | * |
michael@0 | 20 | * <h2>C API: ICU Plugin API</h2> |
michael@0 | 21 | * |
michael@0 | 22 | * <p>C API allowing run-time loadable modules that extend or modify ICU functionality.</p> |
michael@0 | 23 | * |
michael@0 | 24 | * <h3>Loading and Configuration</h3> |
michael@0 | 25 | * |
michael@0 | 26 | * <p>At ICU startup time, the environment variable "ICU_PLUGINS" will be |
michael@0 | 27 | * queried for a directory name. If it is not set, the preprocessor symbol |
michael@0 | 28 | * "DEFAULT_ICU_PLUGINS" will be checked for a default value.</p> |
michael@0 | 29 | * |
michael@0 | 30 | * <p>Within the above-named directory, the file "icuplugins##.txt" will be |
michael@0 | 31 | * opened, if present, where ## is the major+minor number of the currently |
michael@0 | 32 | * running ICU (such as, 44 for ICU 4.4, thus icuplugins44.txt)</p> |
michael@0 | 33 | * |
michael@0 | 34 | * <p>The configuration file has this format:</p> |
michael@0 | 35 | * |
michael@0 | 36 | * <ul> |
michael@0 | 37 | * <li>Hash (#) begins a comment line</li> |
michael@0 | 38 | * |
michael@0 | 39 | * <li>Non-comment lines have two or three components: |
michael@0 | 40 | * LIBRARYNAME ENTRYPOINT [ CONFIGURATION .. ]</li> |
michael@0 | 41 | * |
michael@0 | 42 | * <li>Tabs or spaces separate the three items.</li> |
michael@0 | 43 | * |
michael@0 | 44 | * <li>LIBRARYNAME is the name of a shared library, either a short name if |
michael@0 | 45 | * it is on the loader path, or a full pathname.</li> |
michael@0 | 46 | * |
michael@0 | 47 | * <li>ENTRYPOINT is the short (undecorated) symbol name of the plugin's |
michael@0 | 48 | * entrypoint, as above.</li> |
michael@0 | 49 | * |
michael@0 | 50 | * <li>CONFIGURATION is the entire rest of the line . It's passed as-is to |
michael@0 | 51 | * the plugin.</li> |
michael@0 | 52 | * </ul> |
michael@0 | 53 | * |
michael@0 | 54 | * <p>An example configuration file is, in its entirety:</p> |
michael@0 | 55 | * |
michael@0 | 56 | * \code |
michael@0 | 57 | * # this is icuplugins44.txt |
michael@0 | 58 | * testplug.dll myPlugin hello=world |
michael@0 | 59 | * \endcode |
michael@0 | 60 | * <p>Plugins are categorized as "high" or "low" level. Low level are those |
michael@0 | 61 | * which must be run BEFORE high level plugins, and before any operations |
michael@0 | 62 | * which cause ICU to be 'initialized'. If a plugin is low level but |
michael@0 | 63 | * causes ICU to allocate memory or become initialized, that plugin is said |
michael@0 | 64 | * to cause a 'level change'. </p> |
michael@0 | 65 | * |
michael@0 | 66 | * <p>At load time, ICU first queries all plugins to determine their level, |
michael@0 | 67 | * then loads all 'low' plugins first, and then loads all 'high' plugins. |
michael@0 | 68 | * Plugins are otherwise loaded in the order listed in the configuration file.</p> |
michael@0 | 69 | * |
michael@0 | 70 | * <h3>Implementing a Plugin</h3> |
michael@0 | 71 | * \code |
michael@0 | 72 | * U_CAPI UPlugTokenReturn U_EXPORT2 |
michael@0 | 73 | * myPlugin (UPlugData *plug, UPlugReason reason, UErrorCode *status) { |
michael@0 | 74 | * if(reason==UPLUG_REASON_QUERY) { |
michael@0 | 75 | * uplug_setPlugName(plug, "Simple Plugin"); |
michael@0 | 76 | * uplug_setPlugLevel(plug, UPLUG_LEVEL_HIGH); |
michael@0 | 77 | * } else if(reason==UPLUG_REASON_LOAD) { |
michael@0 | 78 | * ... Set up some ICU things here.... |
michael@0 | 79 | * } else if(reason==UPLUG_REASON_UNLOAD) { |
michael@0 | 80 | * ... unload, clean up ... |
michael@0 | 81 | * } |
michael@0 | 82 | * return UPLUG_TOKEN; |
michael@0 | 83 | * } |
michael@0 | 84 | * \endcode |
michael@0 | 85 | * |
michael@0 | 86 | * <p>The UPlugData* is an opaque pointer to the plugin-specific data, and is |
michael@0 | 87 | * used in all other API calls.</p> |
michael@0 | 88 | * |
michael@0 | 89 | * <p>The API contract is:</p> |
michael@0 | 90 | * <ol><li>The plugin MUST always return UPLUG_TOKEN as a return value- to |
michael@0 | 91 | * indicate that it is a valid plugin.</li> |
michael@0 | 92 | * |
michael@0 | 93 | * <li>When the 'reason' parameter is set to UPLUG_REASON_QUERY, the |
michael@0 | 94 | * plugin MUST call uplug_setPlugLevel() to indicate whether it is a high |
michael@0 | 95 | * level or low level plugin.</li> |
michael@0 | 96 | * |
michael@0 | 97 | * <li>When the 'reason' parameter is UPLUG_REASON_QUERY, the plugin |
michael@0 | 98 | * SHOULD call uplug_setPlugName to indicate a human readable plugin name.</li></ol> |
michael@0 | 99 | * |
michael@0 | 100 | * |
michael@0 | 101 | * \internal ICU 4.4 Technology Preview |
michael@0 | 102 | */ |
michael@0 | 103 | |
michael@0 | 104 | |
michael@0 | 105 | #ifndef ICUPLUG_H |
michael@0 | 106 | #define ICUPLUG_H |
michael@0 | 107 | |
michael@0 | 108 | #include "unicode/utypes.h" |
michael@0 | 109 | |
michael@0 | 110 | |
michael@0 | 111 | /* === Basic types === */ |
michael@0 | 112 | |
michael@0 | 113 | #ifndef U_HIDE_INTERNAL_API |
michael@0 | 114 | /** |
michael@0 | 115 | * @{ |
michael@0 | 116 | * Opaque structure passed to/from a plugin. |
michael@0 | 117 | * use the APIs to access it. |
michael@0 | 118 | * @internal ICU 4.4 Technology Preview |
michael@0 | 119 | */ |
michael@0 | 120 | |
michael@0 | 121 | struct UPlugData; |
michael@0 | 122 | typedef struct UPlugData UPlugData; |
michael@0 | 123 | |
michael@0 | 124 | /** @} */ |
michael@0 | 125 | |
michael@0 | 126 | /** |
michael@0 | 127 | * Random Token to identify a valid ICU plugin. Plugins must return this |
michael@0 | 128 | * from the entrypoint. |
michael@0 | 129 | * @internal ICU 4.4 Technology Preview |
michael@0 | 130 | */ |
michael@0 | 131 | #define UPLUG_TOKEN 0x54762486 |
michael@0 | 132 | |
michael@0 | 133 | /** |
michael@0 | 134 | * Max width of names, symbols, and configuration strings |
michael@0 | 135 | * @internal ICU 4.4 Technology Preview |
michael@0 | 136 | */ |
michael@0 | 137 | #define UPLUG_NAME_MAX 100 |
michael@0 | 138 | |
michael@0 | 139 | |
michael@0 | 140 | /** |
michael@0 | 141 | * Return value from a plugin entrypoint. |
michael@0 | 142 | * Must always be set to UPLUG_TOKEN |
michael@0 | 143 | * @see UPLUG_TOKEN |
michael@0 | 144 | * @internal ICU 4.4 Technology Preview |
michael@0 | 145 | */ |
michael@0 | 146 | typedef uint32_t UPlugTokenReturn; |
michael@0 | 147 | |
michael@0 | 148 | /** |
michael@0 | 149 | * Reason code for the entrypoint's call |
michael@0 | 150 | * @internal ICU 4.4 Technology Preview |
michael@0 | 151 | */ |
michael@0 | 152 | typedef enum { |
michael@0 | 153 | UPLUG_REASON_QUERY = 0, /**< The plugin is being queried for info. **/ |
michael@0 | 154 | UPLUG_REASON_LOAD = 1, /**< The plugin is being loaded. **/ |
michael@0 | 155 | UPLUG_REASON_UNLOAD = 2, /**< The plugin is being unloaded. **/ |
michael@0 | 156 | UPLUG_REASON_COUNT /**< count of known reasons **/ |
michael@0 | 157 | } UPlugReason; |
michael@0 | 158 | |
michael@0 | 159 | |
michael@0 | 160 | /** |
michael@0 | 161 | * Level of plugin loading |
michael@0 | 162 | * INITIAL: UNKNOWN |
michael@0 | 163 | * QUERY: INVALID -> { LOW | HIGH } |
michael@0 | 164 | * ERR -> INVALID |
michael@0 | 165 | * @internal ICU 4.4 Technology Preview |
michael@0 | 166 | */ |
michael@0 | 167 | typedef enum { |
michael@0 | 168 | UPLUG_LEVEL_INVALID = 0, /**< The plugin is invalid, hasn't called uplug_setLevel, or can't load. **/ |
michael@0 | 169 | UPLUG_LEVEL_UNKNOWN = 1, /**< The plugin is waiting to be installed. **/ |
michael@0 | 170 | UPLUG_LEVEL_LOW = 2, /**< The plugin must be called before u_init completes **/ |
michael@0 | 171 | UPLUG_LEVEL_HIGH = 3, /**< The plugin can run at any time. **/ |
michael@0 | 172 | UPLUG_LEVEL_COUNT /**< count of known reasons **/ |
michael@0 | 173 | } UPlugLevel; |
michael@0 | 174 | |
michael@0 | 175 | /** |
michael@0 | 176 | * Entrypoint for an ICU plugin. |
michael@0 | 177 | * @param plug the UPlugData handle. |
michael@0 | 178 | * @param status the plugin's extended status code. |
michael@0 | 179 | * @return A valid plugin must return UPLUG_TOKEN |
michael@0 | 180 | * @internal ICU 4.4 Technology Preview |
michael@0 | 181 | */ |
michael@0 | 182 | typedef UPlugTokenReturn (U_EXPORT2 UPlugEntrypoint) ( |
michael@0 | 183 | UPlugData *plug, |
michael@0 | 184 | UPlugReason reason, |
michael@0 | 185 | UErrorCode *status); |
michael@0 | 186 | |
michael@0 | 187 | /* === Needed for Implementing === */ |
michael@0 | 188 | |
michael@0 | 189 | /** |
michael@0 | 190 | * Request that this plugin not be unloaded at cleanup time. |
michael@0 | 191 | * This is appropriate for plugins which cannot be cleaned up. |
michael@0 | 192 | * @see u_cleanup() |
michael@0 | 193 | * @param plug plugin |
michael@0 | 194 | * @param dontUnload set true if this plugin can't be unloaded |
michael@0 | 195 | * @internal ICU 4.4 Technology Preview |
michael@0 | 196 | */ |
michael@0 | 197 | U_INTERNAL void U_EXPORT2 |
michael@0 | 198 | uplug_setPlugNoUnload(UPlugData *plug, UBool dontUnload); |
michael@0 | 199 | |
michael@0 | 200 | /** |
michael@0 | 201 | * Set the level of this plugin. |
michael@0 | 202 | * @param plug plugin data handle |
michael@0 | 203 | * @param level the level of this plugin |
michael@0 | 204 | * @internal ICU 4.4 Technology Preview |
michael@0 | 205 | */ |
michael@0 | 206 | U_INTERNAL void U_EXPORT2 |
michael@0 | 207 | uplug_setPlugLevel(UPlugData *plug, UPlugLevel level); |
michael@0 | 208 | |
michael@0 | 209 | /** |
michael@0 | 210 | * Get the level of this plugin. |
michael@0 | 211 | * @param plug plugin data handle |
michael@0 | 212 | * @return the level of this plugin |
michael@0 | 213 | * @internal ICU 4.4 Technology Preview |
michael@0 | 214 | */ |
michael@0 | 215 | U_INTERNAL UPlugLevel U_EXPORT2 |
michael@0 | 216 | uplug_getPlugLevel(UPlugData *plug); |
michael@0 | 217 | |
michael@0 | 218 | /** |
michael@0 | 219 | * Get the lowest level of plug which can currently load. |
michael@0 | 220 | * For example, if UPLUG_LEVEL_LOW is returned, then low level plugins may load |
michael@0 | 221 | * if UPLUG_LEVEL_HIGH is returned, then only high level plugins may load. |
michael@0 | 222 | * @return the lowest level of plug which can currently load |
michael@0 | 223 | * @internal ICU 4.4 Technology Preview |
michael@0 | 224 | */ |
michael@0 | 225 | U_INTERNAL UPlugLevel U_EXPORT2 |
michael@0 | 226 | uplug_getCurrentLevel(void); |
michael@0 | 227 | |
michael@0 | 228 | |
michael@0 | 229 | /** |
michael@0 | 230 | * Get plug load status |
michael@0 | 231 | * @return The error code of this plugin's load attempt. |
michael@0 | 232 | * @internal ICU 4.4 Technology Preview |
michael@0 | 233 | */ |
michael@0 | 234 | U_INTERNAL UErrorCode U_EXPORT2 |
michael@0 | 235 | uplug_getPlugLoadStatus(UPlugData *plug); |
michael@0 | 236 | |
michael@0 | 237 | /** |
michael@0 | 238 | * Set the human-readable name of this plugin. |
michael@0 | 239 | * @param plug plugin data handle |
michael@0 | 240 | * @param name the name of this plugin. The first UPLUG_NAME_MAX characters willi be copied into a new buffer. |
michael@0 | 241 | * @internal ICU 4.4 Technology Preview |
michael@0 | 242 | */ |
michael@0 | 243 | U_INTERNAL void U_EXPORT2 |
michael@0 | 244 | uplug_setPlugName(UPlugData *plug, const char *name); |
michael@0 | 245 | |
michael@0 | 246 | /** |
michael@0 | 247 | * Get the human-readable name of this plugin. |
michael@0 | 248 | * @param plug plugin data handle |
michael@0 | 249 | * @return the name of this plugin |
michael@0 | 250 | * @internal ICU 4.4 Technology Preview |
michael@0 | 251 | */ |
michael@0 | 252 | U_INTERNAL const char * U_EXPORT2 |
michael@0 | 253 | uplug_getPlugName(UPlugData *plug); |
michael@0 | 254 | |
michael@0 | 255 | /** |
michael@0 | 256 | * Return the symbol name for this plugin, if known. |
michael@0 | 257 | * @param plug plugin data handle |
michael@0 | 258 | * @return the symbol name, or NULL |
michael@0 | 259 | * @internal ICU 4.4 Technology Preview |
michael@0 | 260 | */ |
michael@0 | 261 | U_INTERNAL const char * U_EXPORT2 |
michael@0 | 262 | uplug_getSymbolName(UPlugData *plug); |
michael@0 | 263 | |
michael@0 | 264 | /** |
michael@0 | 265 | * Return the library name for this plugin, if known. |
michael@0 | 266 | * @param plug plugin data handle |
michael@0 | 267 | * @param status error code |
michael@0 | 268 | * @return the library name, or NULL |
michael@0 | 269 | * @internal ICU 4.4 Technology Preview |
michael@0 | 270 | */ |
michael@0 | 271 | U_INTERNAL const char * U_EXPORT2 |
michael@0 | 272 | uplug_getLibraryName(UPlugData *plug, UErrorCode *status); |
michael@0 | 273 | |
michael@0 | 274 | /** |
michael@0 | 275 | * Return the library used for this plugin, if known. |
michael@0 | 276 | * Plugins could use this to load data out of their |
michael@0 | 277 | * @param plug plugin data handle |
michael@0 | 278 | * @return the library, or NULL |
michael@0 | 279 | * @internal ICU 4.4 Technology Preview |
michael@0 | 280 | */ |
michael@0 | 281 | U_INTERNAL void * U_EXPORT2 |
michael@0 | 282 | uplug_getLibrary(UPlugData *plug); |
michael@0 | 283 | |
michael@0 | 284 | /** |
michael@0 | 285 | * Return the plugin-specific context data. |
michael@0 | 286 | * @param plug plugin data handle |
michael@0 | 287 | * @return the context, or NULL if not set |
michael@0 | 288 | * @internal ICU 4.4 Technology Preview |
michael@0 | 289 | */ |
michael@0 | 290 | U_INTERNAL void * U_EXPORT2 |
michael@0 | 291 | uplug_getContext(UPlugData *plug); |
michael@0 | 292 | |
michael@0 | 293 | /** |
michael@0 | 294 | * Set the plugin-specific context data. |
michael@0 | 295 | * @param plug plugin data handle |
michael@0 | 296 | * @param context new context to set |
michael@0 | 297 | * @internal ICU 4.4 Technology Preview |
michael@0 | 298 | */ |
michael@0 | 299 | U_INTERNAL void U_EXPORT2 |
michael@0 | 300 | uplug_setContext(UPlugData *plug, void *context); |
michael@0 | 301 | |
michael@0 | 302 | |
michael@0 | 303 | /** |
michael@0 | 304 | * Get the configuration string, if available. |
michael@0 | 305 | * The string is in the platform default codepage. |
michael@0 | 306 | * @param plug plugin data handle |
michael@0 | 307 | * @return configuration string, or else null. |
michael@0 | 308 | * @internal ICU 4.4 Technology Preview |
michael@0 | 309 | */ |
michael@0 | 310 | U_INTERNAL const char * U_EXPORT2 |
michael@0 | 311 | uplug_getConfiguration(UPlugData *plug); |
michael@0 | 312 | |
michael@0 | 313 | /** |
michael@0 | 314 | * Return all currently installed plugins, from newest to oldest |
michael@0 | 315 | * Usage Example: |
michael@0 | 316 | * \code |
michael@0 | 317 | * UPlugData *plug = NULL; |
michael@0 | 318 | * while(plug=uplug_nextPlug(plug)) { |
michael@0 | 319 | * ... do something with 'plug' ... |
michael@0 | 320 | * } |
michael@0 | 321 | * \endcode |
michael@0 | 322 | * Not thread safe- do not call while plugs are added or removed. |
michael@0 | 323 | * @param prior pass in 'NULL' to get the first (most recent) plug, |
michael@0 | 324 | * otherwise pass the value returned on a prior call to uplug_nextPlug |
michael@0 | 325 | * @return the next oldest plugin, or NULL if no more. |
michael@0 | 326 | * @internal ICU 4.4 Technology Preview |
michael@0 | 327 | */ |
michael@0 | 328 | U_INTERNAL UPlugData* U_EXPORT2 |
michael@0 | 329 | uplug_nextPlug(UPlugData *prior); |
michael@0 | 330 | |
michael@0 | 331 | /** |
michael@0 | 332 | * Inject a plugin as if it were loaded from a library. |
michael@0 | 333 | * This is useful for testing plugins. |
michael@0 | 334 | * Note that it will have a 'NULL' library pointer associated |
michael@0 | 335 | * with it, and therefore no llibrary will be closed at cleanup time. |
michael@0 | 336 | * Low level plugins may not be able to load, as ordering can't be enforced. |
michael@0 | 337 | * @param entrypoint entrypoint to install |
michael@0 | 338 | * @param config user specified configuration string, if available, or NULL. |
michael@0 | 339 | * @param status error result |
michael@0 | 340 | * @return the new UPlugData associated with this plugin, or NULL if error. |
michael@0 | 341 | * @internal ICU 4.4 Technology Preview |
michael@0 | 342 | */ |
michael@0 | 343 | U_INTERNAL UPlugData* U_EXPORT2 |
michael@0 | 344 | uplug_loadPlugFromEntrypoint(UPlugEntrypoint *entrypoint, const char *config, UErrorCode *status); |
michael@0 | 345 | |
michael@0 | 346 | |
michael@0 | 347 | /** |
michael@0 | 348 | * Inject a plugin from a library, as if the information came from a config file. |
michael@0 | 349 | * Low level plugins may not be able to load, and ordering can't be enforced. |
michael@0 | 350 | * @param libName DLL name to load |
michael@0 | 351 | * @param sym symbol of plugin (UPlugEntrypoint function) |
michael@0 | 352 | * @param config configuration string, or NULL |
michael@0 | 353 | * @param status error result |
michael@0 | 354 | * @return the new UPlugData associated with this plugin, or NULL if error. |
michael@0 | 355 | * @internal ICU 4.4 Technology Preview |
michael@0 | 356 | */ |
michael@0 | 357 | U_INTERNAL UPlugData* U_EXPORT2 |
michael@0 | 358 | uplug_loadPlugFromLibrary(const char *libName, const char *sym, const char *config, UErrorCode *status); |
michael@0 | 359 | |
michael@0 | 360 | /** |
michael@0 | 361 | * Remove a plugin. |
michael@0 | 362 | * Will request the plugin to be unloaded, and close the library if needed |
michael@0 | 363 | * @param plug plugin handle to close |
michael@0 | 364 | * @param status error result |
michael@0 | 365 | * @internal ICU 4.4 Technology Preview |
michael@0 | 366 | */ |
michael@0 | 367 | U_INTERNAL void U_EXPORT2 |
michael@0 | 368 | uplug_removePlug(UPlugData *plug, UErrorCode *status); |
michael@0 | 369 | #endif /* U_HIDE_INTERNAL_API */ |
michael@0 | 370 | |
michael@0 | 371 | #endif |