cookie.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Copyright (C) 2004-2021 Artifex Software, Inc.
  2. //
  3. // This file is part of MuPDF.
  4. //
  5. // MuPDF is free software: you can redistribute it and/or modify it under the
  6. // terms of the GNU Affero General Public License as published by the Free
  7. // Software Foundation, either version 3 of the License, or (at your option)
  8. // any later version.
  9. //
  10. // MuPDF is distributed in the hope that it will be useful, but WITHOUT ANY
  11. // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. // FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  13. // details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with MuPDF. If not, see <https://www.gnu.org/licenses/agpl-3.0.en.html>
  17. //
  18. // Alternative licensing terms are available from the licensor.
  19. // For commercial licensing, see <https://www.artifex.com/> or contact
  20. // Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
  21. // CA 94129, USA, for further information.
  22. /* Cookie interface */
  23. JNIEXPORT void JNICALL
  24. FUN(Cookie_finalize)(JNIEnv *env, jobject self)
  25. {
  26. fz_context *ctx = get_context(env);
  27. fz_cookie *cookie = from_Cookie_safe(env, self);
  28. if (!ctx || !cookie) return;
  29. (*env)->SetLongField(env, self, fid_Cookie_pointer, 0);
  30. fz_free(ctx, cookie);
  31. }
  32. JNIEXPORT jlong JNICALL
  33. FUN(Cookie_newNative)(JNIEnv *env, jobject self)
  34. {
  35. fz_context *ctx = get_context(env);
  36. fz_cookie *cookie = NULL;
  37. if (!ctx) return 0;
  38. fz_try(ctx)
  39. cookie = fz_malloc_struct(ctx, fz_cookie);
  40. fz_catch(ctx)
  41. jni_rethrow(env, ctx);
  42. return jlong_cast(cookie);
  43. }
  44. JNIEXPORT void JNICALL
  45. FUN(Cookie_abort)(JNIEnv *env, jobject self)
  46. {
  47. fz_context *ctx = get_context(env);
  48. fz_cookie *cookie = from_Cookie(env, self);
  49. if (!ctx || !cookie) return;
  50. cookie->abort = 1;
  51. }
  52. JNIEXPORT jint JNICALL
  53. FUN(Cookie_getProgress)(JNIEnv *env, jobject self)
  54. {
  55. fz_context *ctx = get_context(env);
  56. fz_cookie *cookie = from_Cookie(env, self);
  57. if (!ctx || !cookie) return 0;
  58. return cookie->progress;
  59. }
  60. JNIEXPORT jint JNICALL
  61. FUN(Cookie_getProgressMax)(JNIEnv *env, jobject self)
  62. {
  63. fz_context *ctx = get_context(env);
  64. fz_cookie *cookie = from_Cookie(env, self);
  65. if (!ctx || !cookie) return 0;
  66. return cookie->progress_max;
  67. }
  68. JNIEXPORT jint JNICALL
  69. FUN(Cookie_getErrors)(JNIEnv *env, jobject self)
  70. {
  71. fz_context *ctx = get_context(env);
  72. fz_cookie *cookie = from_Cookie(env, self);
  73. if (!ctx || !cookie) return 0;
  74. return cookie->errors;
  75. }
  76. JNIEXPORT jboolean JNICALL
  77. FUN(Cookie_getIncomplete)(JNIEnv *env, jobject self)
  78. {
  79. fz_context *ctx = get_context(env);
  80. fz_cookie *cookie = from_Cookie(env, self);
  81. if (!ctx || !cookie) return JNI_FALSE;
  82. return cookie->incomplete ? JNI_TRUE : JNI_FALSE;
  83. }