Compare commits

...

4 Commits

Author SHA1 Message Date
Corewala 53c1980fa6 Updated todo 2022-07-29 16:23:24 -04:00
Corewala 0ae42a214d Removed redundant ouri and fixed local redirects (again) 2022-07-29 16:21:00 -04:00
Corewala 319b0b4d14 Fixed sharing of relative links 2022-07-29 15:47:33 -04:00
Corewala 13f21bc09b Fixed relative link handling with proxy 2022-07-29 15:09:26 -04:00
5 changed files with 33 additions and 37 deletions

View File

@ -29,7 +29,7 @@ Buran is a simple Gemini protocol browser for Android.
- [X] Attention guide mode
- [ ] Simple A/B page switching system
- [ ] Pass [Egsam test](https://github.com/pitr/egsam)
- [ ] Option to define an HTTPS gateway
- [X] Option to define an HTTPS gateway
## Credits

View File

@ -69,6 +69,14 @@ class OmniTerm(private val listener: Listener) {
println("OmniTerm resolved address: $address")
}
fun getGlobalUri(reference: String): String {
return when {
reference.contains(":") -> reference
reference.startsWith("//") -> "gemini:$reference"
else -> uri.resolve(reference)
}
}
fun reset(){
uri = penultimate.copy()
}

View File

@ -1,6 +1,8 @@
package corewala.buran
const val SCHEME = "gemini://"
import corewala.toURI
const val GEMSCHEME = "gemini://"
const val TRAVERSE = "../"
const val SOLIDUS = "/"
const val DIREND = "/"
@ -15,21 +17,28 @@ class OppenURI constructor(private var ouri: String) {
constructor(): this("")
var host: String = ""
var scheme: String = ""
init {
extractHost()
if(ouri.isNotEmpty()){
host = ouri.toURI().host
scheme = ouri.toURI().scheme
}
}
fun set(ouri: String){
this.ouri = ouri
extractHost()
if(ouri.isNotEmpty()){
host = ouri.toURI().host
scheme = ouri.toURI().scheme
}
}
fun resolve(reference: String): String{
if(ouri == "$SCHEME$host") ouri = "$ouri/"
if(ouri == "$GEMSCHEME$host") ouri = "$ouri/"
when {
reference.startsWith(SCHEME) -> set(reference)
reference.startsWith(SOLIDUS) -> ouri = "$SCHEME$host$reference"
reference.startsWith(GEMSCHEME) -> set(reference)
reference.startsWith(SOLIDUS) -> ouri = "$scheme://$host$reference"
reference.startsWith(TRAVERSE) -> {
if(!ouri.endsWith(DIREND)) ouri = ouri.removeFile()
val traversalCount = reference.split(TRAVERSE).size - 1
@ -46,16 +55,16 @@ class OppenURI constructor(private var ouri: String) {
}
fun traverse(): OppenURI{
val path = ouri.removePrefix("$SCHEME$host")
val path = ouri.removePrefix("$GEMSCHEME$host")
val segments = path.split(SOLIDUS).filter { it.isNotEmpty() }
var nouri = "$SCHEME$host"
var nouri = "$GEMSCHEME$host"
when (ouri) {
"" -> {
}
SCHEME -> ouri = ""
"$nouri/" -> ouri = SCHEME
GEMSCHEME -> ouri = ""
"$nouri/" -> ouri = GEMSCHEME
else -> {
when {
segments.isNotEmpty() -> {
@ -74,10 +83,10 @@ class OppenURI constructor(private var ouri: String) {
}
private fun traverse(count: Int): String{
val path = ouri.removePrefix("$SCHEME$host")
val path = ouri.removePrefix("$GEMSCHEME$host")
val segments = path.split(SOLIDUS).filter { it.isNotEmpty() }
val segmentCount = segments.size
var nouri = "$SCHEME$host"
var nouri = "$GEMSCHEME$host"
segments.forEachIndexed{ index, segment ->
if(index < segmentCount - count){
@ -89,15 +98,6 @@ class OppenURI constructor(private var ouri: String) {
}
private fun extractHost(){
if(ouri.isEmpty()) return
val urn = ouri.removePrefix(SCHEME)
host = when {
urn.contains(SOLIDUS) -> urn.substring(0, urn.indexOf(SOLIDUS))
else -> urn
}
}
fun copy(): OppenURI = OppenURI(ouri)
override fun toString(): String = ouri

View File

@ -147,7 +147,7 @@ class GeminiDatasource(private val context: Context, val history: BuranHistory):
when {
currentRequestAddress != uri.toString() -> {}
header.code == GeminiResponse.INPUT -> onUpdate(GemState.ResponseInput(uri, header))
header.code == GeminiResponse.REDIRECT -> onUpdate(GemState.Redirect(resolve(uri, header.meta)))
header.code == GeminiResponse.REDIRECT -> onUpdate(GemState.Redirect(header.meta))
header.code == GeminiResponse.CLIENT_CERTIFICATE_REQUIRED -> onUpdate(GemState.ClientCertRequired(uri, header))
header.code != GeminiResponse.SUCCESS -> onUpdate(GemState.ResponseError(header))
header.meta.startsWith("text/gemini") -> getGemtext(bufferedReader, requestEntity.trim().toURI(), header, onUpdate)
@ -173,8 +173,6 @@ class GeminiDatasource(private val context: Context, val history: BuranHistory):
outWriter.close()
socket.close()
currentRequestAddress = null
}
private fun getGemtext(reader: BufferedReader, uri: URI, header: GeminiResponse.Header, onUpdate: (state: GemState) -> Unit){
@ -241,12 +239,6 @@ class GeminiDatasource(private val context: Context, val history: BuranHistory):
}
}
private fun resolve(uri: URI, address: String): String{
val ouri = OppenURI()
ouri.set(uri.scheme + uri.host)
return ouri.resolve(address)
}
override fun canGoBack(): Boolean = runtimeHistory.isEmpty() || runtimeHistory.size > 1
//This just forces the factory to rebuild before the next request

View File

@ -97,11 +97,7 @@ class GemActivity : AppCompatActivity() {
private val onLink: (link: URI, longTap: Boolean, adapterPosition: Int) -> Unit = { uri, longTap, _: Int ->
if(longTap){
val globalURI = if(!uri.toString().contains("//") and !uri.toString().contains(":")){
(omniTerm.getCurrent() + uri.toString()).replace("//", "/").replace(":/", "://")
} else {
uri.toString()
}
val globalURI = omniTerm.getGlobalUri(uri.toString())
Intent().apply {
action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, globalURI)
@ -462,7 +458,7 @@ class GemActivity : AppCompatActivity() {
.show()
}
is GemState.Redirect -> gemRequest(state.uri)
is GemState.Redirect -> gemRequest(omniTerm.getGlobalUri(state.uri))
is GemState.ClientCertRequired -> runOnUiThread {
loadingView(false)