-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshiori_proxy.nim
60 lines (51 loc) · 1.68 KB
/
shiori_proxy.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import shioridll
import shiori_charset_convert
import yaml.serialization
import osproc
import streams
import strutils
type ShioriProxyConfig = object
command: seq[string]
var config: ShioriProxyConfig
var shioriProcess: Process
var shioriStdin: Stream
var shioriStdout: Stream
proc loadConfig(): void =
let configFile = newFileStream("shiori_proxy.yml")
load(configFile, config)
configFile.close()
proc openShioriProcess(): void =
shioriProcess = startProcess(config.command[0], ".", config.command[1..^1], options = {poDemon})
shioriStdin = shioriProcess.inputStream
shioriStdout = shioriProcess.outputStream
shioriLoadCallback = proc (dirpath: string): bool =
loadConfig()
openShioriProcess()
shioriStdin.writeLine("LOAD SHIORIPROXY/1.0")
shioriStdin.writeLine(dirpath)
shioriStdin.flush()
let value = shioriStdout.readLine()
value == "1"
shioriRequestCallback = autoConvertShioriMessageCharset(proc (requestStr: string): string =
shioriStdin.writeLine("REQUEST SHIORIPROXY/1.0")
shioriStdin.write(requestStr)
shioriStdin.flush()
var line: string = ""
var lines: seq[string] = @[]
while shioriStdout.readLine(line):
lines.add(line)
if line.len() == 0:
break
lines.join("\n")
)
shioriUnloadCallback = proc (): bool =
shioriStdin.writeLine("UNLOAD SHIORIPROXY/1.0")
shioriStdin.flush()
let value = shioriStdout.readLine()
shioriProcess.terminate()
value == "1"
when appType != "lib":
main("C:\\ssp\\ghost\\nim\\", @[
"GET SHIORI/3.0\nCharset: UTF-8\nSender: embryo\nID: version\n\n",
"GET SHIORI/3.0\nCharset: UTF-8\nSender: embryo\nID: OnBoot\n\n",
])