init commit

This commit is contained in:
Luxferre
2023-03-25 16:51:49 +02:00
commit 8b4c8c7e8e
12 changed files with 690 additions and 0 deletions
+24
View File
@@ -0,0 +1,24 @@
// KaiOS 2.x specific part to connect and retrieve raw data from Gopher servers
// Requires "tcp-socket" permission in the manifest
// and the "privileged" or "certified" app permission level
// resource format: [type, selector, host, port]
// type is autotrimmed, so you don't have to manually strip the description
// input is optional and only considered for resource type 7
function gopherRequest(resource, input, successCb, errorCb) {
var xsock = navigator.mozTCPSocket.open(resource[2], (resource[3]||70) | 0, {binaryType: 'string'}),
type = resource[0][0], databuf = ''
xsock.ondata = function(data) {
databuf += data.data
}
xsock.onclose = function() {
successCb(databuf, type)
}
xsock.onerror = errorCb
xsock.onopen = function() {
var selpath = resource[1]
if(type == '7' && input)
selpath += '\t' + input
xsock.send(selpath + '\r\n') // send CRLF-terminated selector path and optionally the search string
}
}