From 6ab52e2b9e1c61e0072edeb67769b887195124f6 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 13 Aug 2019 11:10:56 +0200 Subject: [PATCH] =?UTF-8?q?Add=20a=20JNI=C2=A0method=20to=20check=20if=20a?= =?UTF-8?q?n=20url=20exists=20and=20is=20a=20redirection.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/android/kiwixreader.cpp | 15 +++++++++++++++ .../org/kiwix/kiwixlib/JNIKiwixReader.java | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/android/kiwixreader.cpp b/src/android/kiwixreader.cpp index 91dcec78b..f306d81e1 100644 --- a/src/android/kiwixreader.cpp +++ b/src/android/kiwixreader.cpp @@ -224,6 +224,21 @@ JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixlib_JNIKiwixReader_getMimeType( return mimeType; } +JNIEXPORT jstring JNICALL Java_org_kiwix_kiwixlib_JNIKiwixReader_checkUrl( + JNIEnv* env, jobject obj, jstring url) +{ + jstring finalUrl; + std::string cUrl = jni2c(url, env); + try { + auto entry = READER->getEntryFromEncodedPath(cUrl); + entry = entry.getFinalEntry(); + finalUrl = c2jni(entry.getPath(), env); + } catch (std::exception& e) { + finalUrl = c2jni("", env); + } + return finalUrl; +} + JNIEXPORT jbyteArray JNICALL Java_org_kiwix_kiwixlib_JNIKiwixReader_getContent( JNIEnv* env, jobject obj, jobject url, jobject titleObj, jobject mimeTypeObj, jobject sizeObj) { diff --git a/src/android/org/kiwix/kiwixlib/JNIKiwixReader.java b/src/android/org/kiwix/kiwixlib/JNIKiwixReader.java index ea3a3d4b3..86f5f455b 100644 --- a/src/android/org/kiwix/kiwixlib/JNIKiwixReader.java +++ b/src/android/org/kiwix/kiwixlib/JNIKiwixReader.java @@ -38,6 +38,16 @@ public class JNIKiwixReader public native String getMimeType(String url); + /** + * Check if a url exists and is a redirect or not. + * + * Return an empty string if the url doesn't exist in the reader. + * Return the url of the "final" entry. + * - equal to the input url if the entry is not a redirection. + * - different if the url is a redirection (and the webview should redirect to it). + */ + public native String checkUrl(String url); + /** * Get the content of a article. *