-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (48 loc) · 1.05 KB
/
main.go
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
/*
Copyright 2013 Mathieu Lonjaret.
*/
package main
import (
"bytes"
"flag"
"fmt"
"log"
"os"
"github.com/mpl/scgiclient"
)
func ghettoXMLRpc(command, arg string) string {
// TODO(mpl): allow more args, types other than string maybe.
xml := `<?xml version="1.0"?>
<methodCall>
<methodName>` + command + `</methodName>`
if arg != "" {
xml += `<params><param><value><string>` + arg + `</string></value></param></params>`
}
xml += "</methodCall>"
return xml
}
func usage() {
fmt.Print(" usage: rtorrentrpc host:port rpccommand [arg]\n")
fmt.Print(" See http://libtorrent.rakshasa.no/wiki/RTorrentCommands for the list of commands.\n")
os.Exit(1)
}
func main() {
flag.Parse()
args := flag.Args()
if len(args) < 2 {
usage()
}
addr := args[0]
command := args[1]
cmdArg := ""
if len(args) > 2 {
cmdArg = args[2]
}
xmlrpc := ghettoXMLRpc(command, cmdArg)
resp, err := scgiclient.Send(addr, bytes.NewReader([]byte(xmlrpc)))
if err != nil {
log.Fatal(err)
}
// TODO(mpl): Unmarshall response. meh.
fmt.Printf("%v", string(resp.Body))
}