1 /* 2 * XpdfPluginAPI.h 3 * 4 * Copyright 2004 Glyph & Cog, LLC 5 */ 6 7 //======================================================================== 8 // 9 // Modified under the Poppler project - http://poppler.freedesktop.org 10 // 11 // All changes made under the Poppler project to this file are licensed 12 // under GPL version 2 or later 13 // 14 // Copyright (C) 2012 Albert Astals Cid <aacid@kde.org> 15 // Copyright (C) 2014 Bogdan Cristea <cristeab@gmail.com> 16 // Copyright (C) 2014 Peter Breitenlohner <peb@mppmu.mpg.de> 17 // 18 // To see a description of the changes please see the Changelog file that 19 // came with your tarball or type make ChangeLog if you are building from git 20 // 21 //======================================================================== 22 23 #ifndef XPDFPLUGINAPI_H 24 #define XPDFPLUGINAPI_H 25 26 #ifdef _WIN32 27 #ifndef NOMINMAX 28 #define NOMINMAX 29 #endif 30 #include <windows.h> 31 #else 32 #define Object XtObject 33 #include <X11/Intrinsic.h> 34 #undef Object 35 #endif 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 /*------------------------------------------------------------------------ 42 * Macros 43 *------------------------------------------------------------------------*/ 44 45 /* 46 * The current API version. 47 */ 48 #define xpdfPluginAPIVersion 1 49 50 #ifdef _WIN32 51 # ifdef __cplusplus 52 # define PLUGINFUNC(retType) extern "C" __declspec(dllexport) retType 53 # else 54 # define PLUGINFUNC(retType) extern __declspec(dllexport) retType 55 # endif 56 #else 57 # ifdef __cplusplus 58 # define PLUGINFUNC(retType) extern "C" retType 59 # else 60 # define PLUGINFUNC(retType) extern retType 61 # endif 62 #endif 63 64 /*------------------------------------------------------------------------ 65 * Plugin setup/cleanup 66 *------------------------------------------------------------------------*/ 67 68 /* 69 * All plugins are required to implement two functions: 70 * 71 * -- Initialize the plugin. Returns non-zero if successful. 72 * PLUGINFUNC(XpdfBool) xpdfInitPlugin(void); 73 * 74 * -- Free the plugin. 75 * PLUGINFUNC(void) xpdfFreePlugin(void); 76 */ 77 78 /*------------------------------------------------------------------------ 79 * Types 80 *------------------------------------------------------------------------*/ 81 82 /* 83 * Standard C boolean -- zero = false, non-zero = true. 84 */ 85 typedef int XpdfBool; 86 #define xpdfTrue 1 87 #define xpdfFalse 0 88 89 /* 90 * PDF document handle. 91 */ 92 typedef struct _XpdfDoc *XpdfDoc; 93 94 /* 95 * PDF object handle. 96 */ 97 typedef struct _XpdfObject *XpdfObject; 98 99 /* 100 * Document access permissions. Any of these can be bitwise 'or'ed 101 * together. If xpdfPermissionOpen is not included, the document 102 * cannot be opened at all, and the other bits are ignored. 103 */ 104 typedef unsigned int XpdfPermission; 105 #define xpdfPermissionOpen (1 << 0) 106 #define xpdfPermissionPrint (1 << 2) 107 #define xpdfPermissionChange (1 << 3) 108 #define xpdfPermissionCopy (1 << 4) 109 #define xpdfPermissionNotes (1 << 5) 110 111 /*------------------------------------------------------------------------ 112 * Security handler 113 *------------------------------------------------------------------------*/ 114 115 /* 116 * XpdfSecurityHandler - a security handler plugin should create one 117 * of these and pass it to xpdfRegisterSecurityHandler. 118 */ 119 #ifdef __cplusplus 120 struct XpdfSecurityHandler { 121 #else 122 typedef struct { 123 #endif 124 125 /* 126 * Version of the security handler spec (this document) -- use 127 * xpdfPluginAPIVersion. 128 */ 129 int version; 130 131 /* 132 * Security handler name. 133 */ 134 char *name; 135 136 /* 137 * Any global data the security handler needs. XpdfViewer will pass 138 * this pointer to all handler functions as the <handlerData> 139 * argument. 140 */ 141 void *handlerData; 142 143 /* 144 * Allocate and initialize data for a new document. XpdfViewer will 145 * pass the returned pointer to all other handler functions as the 146 * <docData> argument. Returns non-zero if successful. 147 */ 148 XpdfBool (*newDoc)(void *handlerData, XpdfDoc doc, 149 XpdfObject encryptDict, void **docData); 150 151 /* 152 * Free the data allocated by newDoc. 153 */ 154 void (*freeDoc)(void *handlerData, void *docData); 155 156 /* 157 * Construct authorization data based on the supplied owner and user 158 * passwords (either or both of which may be NULL). This function 159 * is called in "batch" mode, i.e., if the password was supplied on 160 * the command line or via an Xpdf library API. It should not 161 * generate any user interaction (e.g., a password dialog). It is 162 * not required to support this function: the makeAuthData function 163 * pointer can be set to NULL. Returns non-zero if successful. 164 */ 165 XpdfBool (*makeAuthData)(void *handlerData, void *docData, 166 char *ownerPassword, char *userPassword, 167 void **authData); 168 169 /* 170 * Request any needed information (e.g., a password) from the user, 171 * and construct an authorization data object. Returns non-zero if 172 * successful. 173 */ 174 XpdfBool (*getAuthData)(void *handlerData, void *docData, 175 void **authData); 176 177 /* 178 * Free the data allocated by getAuthData. 179 */ 180 void (*freeAuthData)(void *handlerData, void *docData, 181 void *authData); 182 183 /* 184 * Request permission to access the document. This returns all 185 * permissions granted by authData. 186 */ 187 XpdfPermission (*authorize)(void *handlerData, void *docData, 188 void *authData); 189 190 /* 191 * Get the decryption key and algorithm version associated with the 192 * document. Returns non-zero if successful. 193 */ 194 XpdfBool (*getKey)(void *handlerData, void *docData, 195 char **key, int *keyLen, int *cryptVersion, int *cryptRevision); 196 197 /* 198 * Free the data allocated by getKey. 199 */ 200 void (*freeKey)(void *handlerData, void *docData, 201 char *key, int keyLen); 202 203 #ifdef __cplusplus 204 }; 205 #else 206 } XpdfSecurityHandler; 207 #endif 208 209 /*------------------------------------------------------------------------*/ 210 211 typedef struct { 212 int version; 213 214 /*------------------------------------------------------------------------ 215 * Document access functions 216 *------------------------------------------------------------------------*/ 217 218 /* 219 * Get a document's info dictionary. (The returned object must be 220 * freed with xpdfFreeObj.) 221 */ 222 XpdfObject (*_xpdfGetInfoDict)(XpdfDoc doc); 223 224 /* 225 * Get a document's catalog ("root") dictionary. (The returned object 226 * must be freed with xpdfFreeObj.) 227 */ 228 XpdfObject (*_xpdfGetCatalog)(XpdfDoc doc); 229 230 /*------------------------------------------------------------------------ 231 * Object access functions 232 *------------------------------------------------------------------------*/ 233 234 /* 235 * Check an object's type. 236 */ 237 XpdfBool (*_xpdfObjIsBool)(XpdfObject obj); 238 XpdfBool (*_xpdfObjIsInt)(XpdfObject obj); 239 XpdfBool (*_xpdfObjIsReal)(XpdfObject obj); 240 XpdfBool (*_xpdfObjIsString)(XpdfObject obj); 241 XpdfBool (*_xpdfObjIsName)(XpdfObject obj); 242 XpdfBool (*_xpdfObjIsNull)(XpdfObject obj); 243 XpdfBool (*_xpdfObjIsArray)(XpdfObject obj); 244 XpdfBool (*_xpdfObjIsDict)(XpdfObject obj); 245 XpdfBool (*_xpdfObjIsStream)(XpdfObject obj); 246 XpdfBool (*_xpdfObjIsRef)(XpdfObject obj); 247 248 /* 249 * Value access. 250 * (Objects returned by xpdfArrayGet and xpdfDictGet must be freed 251 * with xpdfFreeObj.) 252 */ 253 XpdfBool (*_xpdfBoolValue)(XpdfObject obj); 254 int (*_xpdfIntValue)(XpdfObject obj); 255 double (*_xpdfRealValue)(XpdfObject obj); 256 int (*_xpdfStringLength)(XpdfObject obj); 257 char *(*_xpdfStringValue)(XpdfObject obj); 258 char *(*_xpdfNameValue)(XpdfObject obj); 259 int (*_xpdfArrayLength)(XpdfObject obj); 260 XpdfObject (*_xpdfArrayGet)(XpdfObject obj, int idx); 261 XpdfObject (*_xpdfDictGet)(XpdfObject obj, char *key); 262 263 /* 264 * Object destruction. NB: *all* objects must be freed after use. 265 */ 266 void (*_xpdfFreeObj)(XpdfObject obj); 267 268 /*------------------------------------------------------------------------ 269 * Memory allocation functions 270 *------------------------------------------------------------------------*/ 271 272 void *(*_xpdfMalloc)(int size); 273 void *(*_xpdfRealloc)(void *p, int size); 274 void (*_xpdfFree)(void *p); 275 276 /*------------------------------------------------------------------------ 277 * Security handler functions 278 *------------------------------------------------------------------------*/ 279 280 /* 281 * Register a new security handler. 282 */ 283 void (*_xpdfRegisterSecurityHandler)(XpdfSecurityHandler *handler); 284 285 /*------------------------------------------------------------------------*/ 286 287 } XpdfPluginVecTable; 288 289 #ifdef _WIN32 290 291 extern __declspec(dllexport) XpdfPluginVecTable xpdfPluginVecTable; 292 293 #define xpdfPluginSetup \ 294 extern __declspec(dllexport) \ 295 XpdfPluginVecTable xpdfPluginVecTable = {xpdfPluginAPIVersion}; 296 297 #else 298 299 extern XpdfPluginVecTable xpdfPluginVecTable; 300 301 #define xpdfPluginSetup \ 302 XpdfPluginVecTable xpdfPluginVecTable = {xpdfPluginAPIVersion}; 303 304 #endif 305 306 #define xpdfGetInfoDict (*xpdfPluginVecTable._xpdfGetInfoDict) 307 #define xpdfGetCatalog (*xpdfPluginVecTable._xpdfGetCatalog) 308 #ifdef _WIN32 309 #define xpdfWin32GetWindow (*xpdfPluginVecTable._xpdfWin32GetWindow) 310 #else 311 #define xpdfXGetWindow (*xpdfPluginVecTable._xpdfXGetWindow) 312 #endif 313 #define xpdfObjIsBool (*xpdfPluginVecTable._xpdfObjIsBool) 314 #define xpdfObjIsInt (*xpdfPluginVecTable._xpdfObjIsInt) 315 #define xpdfObjIsReal (*xpdfPluginVecTable._xpdfObjIsReal) 316 #define xpdfObjIsString (*xpdfPluginVecTable._xpdfObjIsString) 317 #define xpdfObjIsName (*xpdfPluginVecTable._xpdfObjIsName) 318 #define xpdfObjIsNull (*xpdfPluginVecTable._xpdfObjIsNull) 319 #define xpdfObjIsArray (*xpdfPluginVecTable._xpdfObjIsArray) 320 #define xpdfObjIsDict (*xpdfPluginVecTable._xpdfObjIsDict) 321 #define xpdfObjIsStream (*xpdfPluginVecTable._xpdfObjIsStream) 322 #define xpdfObjIsRef (*xpdfPluginVecTable._xpdfObjIsRef) 323 #define xpdfBoolValue (*xpdfPluginVecTable._xpdfBoolValue) 324 #define xpdfIntValue (*xpdfPluginVecTable._xpdfIntValue) 325 #define xpdfRealValue (*xpdfPluginVecTable._xpdfRealValue) 326 #define xpdfStringLength (*xpdfPluginVecTable._xpdfStringLength) 327 #define xpdfStringValue (*xpdfPluginVecTable._xpdfStringValue) 328 #define xpdfNameValue (*xpdfPluginVecTable._xpdfNameValue) 329 #define xpdfArrayLength (*xpdfPluginVecTable._xpdfArrayLength) 330 #define xpdfArrayGet (*xpdfPluginVecTable._xpdfArrayGet) 331 #define xpdfDictGet (*xpdfPluginVecTable._xpdfDictGet) 332 #define xpdfFreeObj (*xpdfPluginVecTable._xpdfFreeObj) 333 #define xpdfMalloc (*xpdfPluginVecTable._xpdfMalloc) 334 #define xpdfRealloc (*xpdfPluginVecTable._xpdfRealloc) 335 #define xpdfFree (*xpdfPluginVecTable._xpdfFree) 336 #define xpdfRegisterSecurityHandler (*xpdfPluginVecTable._xpdfRegisterSecurityHandler) 337 338 #ifdef __cplusplus 339 } 340 #endif 341 342 #endif 343