*pulls switch card*

This commit is contained in:
CornierKhan1 2018-11-18 12:35:33 +11:00
parent 34ff5eb299
commit 3d130ccafa
2 changed files with 109 additions and 120 deletions

View File

@ -7,6 +7,9 @@ This is the SOAP Server Software. The other repository only has the communicatio
# Changelog # Changelog
Versions on this software are based on goals. (e.g 0.2 works towards SQL support. 0.3 works towards NUS support, etc.) Versions on this software are based on goals. (e.g 0.2 works towards SQL support. 0.3 works towards NUS support, etc.)
## 0.2.x Kawauso ## 0.2.x Kawauso
### 0.2.2
- Switched from if else to switch case. This makes the script cleaner, and makes the program faster.
- No changes to SQL have been made in this update.
### 0.2.1 ### 0.2.1
- Added working Config. - Added working Config.
- SQL now works. (In terms of opening a connection.) - SQL now works. (In terms of opening a connection.)

226
main.go
View File

@ -18,7 +18,6 @@
package main package main
import ( import (
"bytes"
"database/sql" "database/sql"
"encoding/xml" "encoding/xml"
"fmt" "fmt"
@ -47,7 +46,7 @@ func CheckError(e error) {
func main() { func main() {
fmt.Println("WiiSOAP 0.2.1 Kawauso") fmt.Println("WiiSOAP 0.2.2 Kawauso")
fmt.Println("Reading the Config...") fmt.Println("Reading the Config...")
configfile, err := os.Open("./config.xml") configfile, err := os.Open("./config.xml")
CheckError(err) CheckError(err)
@ -86,10 +85,11 @@ func handler(w http.ResponseWriter, r *http.Request) {
http.StatusInternalServerError) http.StatusInternalServerError)
} }
// The following block of code here is a cluster of disgust. // The requests are in byte format, so please use []byte("") when adding a new case.
switch body {
// TODO: Make the case functions cleaner. (e.g. The should the response be a variable?)
case []byte("CheckDeviceStatus"):
// CheckDeviceStatus
if bytes.Contains(body, []byte("CheckDeviceStatus")) {
fmt.Println("CDS.") fmt.Println("CDS.")
CDS := CDS{} CDS := CDS{}
err = xml.Unmarshal([]byte(body), &CDS) err = xml.Unmarshal([]byte(body), &CDS)
@ -126,22 +126,20 @@ func handler(w http.ResponseWriter, r *http.Request) {
</soapenv:Envelope>`) </soapenv:Envelope>`)
fmt.Println("Delivered response!") fmt.Println("Delivered response!")
} else { case []byte("NotifiedETicketsSynced"):
// NotifyETicketsSynced. fmt.Println("NETS")
if bytes.Contains(body, []byte("NotifyETicketsSynced")) { NETS := NETS{}
fmt.Println("NETS") err = xml.Unmarshal([]byte(body), &NETS)
NETS := NETS{} if err != nil {
err = xml.Unmarshal([]byte(body), &NETS) fmt.Println("...or not. Bad or incomplete request. (End processing.)")
if err != nil { fmt.Fprint(w, "This is a disgusting request, but 20 dollars is 20 dollars. ;)")
fmt.Println("...or not. Bad or incomplete request. (End processing.)") fmt.Printf("error: %v", err)
fmt.Fprint(w, "This is a disgusting request, but 20 dollars is 20 dollars. ;)") return
fmt.Printf("error: %v", err) }
return fmt.Println(NETS)
} fmt.Println("The request is valid! Responding...")
fmt.Println(NETS) fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?>
fmt.Println("The request is valid! Responding...")
fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
@ -156,24 +154,22 @@ func handler(w http.ResponseWriter, r *http.Request) {
</NotifyETicketsSyncedResponse> </NotifyETicketsSyncedResponse>
</soapenv:Body> </soapenv:Body>
</soapenv:Envelope>`) </soapenv:Envelope>`)
fmt.Println("Delivered response!") fmt.Println("Delivered response!")
} else { case []byte("ListETickets"):
// ListETickets fmt.Println("LET")
if bytes.Contains(body, []byte("ListETickets")) { LET := LET{}
fmt.Println("LET") err = xml.Unmarshal([]byte(body), &LET)
LET := LET{} if err != nil {
err = xml.Unmarshal([]byte(body), &LET) fmt.Println("...or not. Bad or incomplete request. (End processing.)")
if err != nil { fmt.Fprint(w, "This is a disgusting request, but 20 dollars is 20 dollars. ;)")
fmt.Println("...or not. Bad or incomplete request. (End processing.)") fmt.Printf("error: %v", err)
fmt.Fprint(w, "This is a disgusting request, but 20 dollars is 20 dollars. ;)") return
fmt.Printf("error: %v", err) }
return fmt.Println(LET)
} fmt.Println("The request is valid! Responding...")
fmt.Println(LET) fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?>
fmt.Println("The request is valid! Responding...")
fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
@ -191,22 +187,22 @@ func handler(w http.ResponseWriter, r *http.Request) {
</ListETicketsResponse> </ListETicketsResponse>
</soapenv:Body> </soapenv:Body>
</soapenv:Envelope>`) </soapenv:Envelope>`)
fmt.Println("Delivered response!") fmt.Println("Delivered response!")
} else { case []byte("PurchaseTitle"):
if bytes.Contains(body, []byte("PurchaseTitle")) {
fmt.Println("PT") fmt.Println("PT")
PT := PT{} PT := PT{}
err = xml.Unmarshal([]byte(body), &PT) err = xml.Unmarshal([]byte(body), &PT)
if err != nil { if err != nil {
fmt.Println("...or not. Bad or incomplete request. (End processing.)") fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Fprint(w, "if you wanna fun time, its gonna cost ya extra sweetie. ;)") fmt.Fprint(w, "if you wanna fun time, its gonna cost ya extra sweetie. ;)")
fmt.Printf("error: %v", err) fmt.Printf("error: %v", err)
return return
} }
fmt.Println(PT) fmt.Println(PT)
fmt.Println("The request is valid! Responding...") fmt.Println("The request is valid! Responding...")
fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?> fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
@ -235,24 +231,22 @@ func handler(w http.ResponseWriter, r *http.Request) {
</PurchaseTitleResponse> </PurchaseTitleResponse>
</soapenv:Body> </soapenv:Body>
</soapenv:Envelope>`) </soapenv:Envelope>`)
fmt.Println("Delivered response!")
} else { case []byte("CheckRegistration"):
// IDENTITY AUTHENTICATION SOAP fmt.Println("CR.")
CR := CR{}
if bytes.Contains(body, []byte("CheckRegistration")) { err = xml.Unmarshal([]byte(body), &CR)
fmt.Println("CR.") if err != nil {
CR := CR{} fmt.Println("...or not. Bad or incomplete request. (End processing.)")
err = xml.Unmarshal([]byte(body), &CR) fmt.Fprint(w, "not good enough for me. ;)")
if err != nil { fmt.Printf("error: %v", err)
fmt.Println("...or not. Bad or incomplete request. (End processing.)") return
fmt.Fprint(w, "not good enough for me. ;)") }
fmt.Printf("error: %v", err) fmt.Println(CR)
return fmt.Println("The request is valid! Responding...")
} fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?>
fmt.Println(CR)
fmt.Println("The request is valid! Responding...")
fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
@ -269,22 +263,22 @@ func handler(w http.ResponseWriter, r *http.Request) {
</CheckRegistrationResponse> </CheckRegistrationResponse>
</soapenv:Body> </soapenv:Body>
</soapenv:Envelope>`) </soapenv:Envelope>`)
fmt.Println("Delivered response!")
} else { case []byte("GetRegistrationInfo"):
if bytes.Contains(body, []byte("GetRegistrationInfo")) { fmt.Println("GRI.")
fmt.Println("GRI.") GRI := GRI{}
GRI := GRI{} err = xml.Unmarshal([]byte(body), &GRI)
err = xml.Unmarshal([]byte(body), &GRI) if err != nil {
if err != nil { fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Println("...or not. Bad or incomplete request. (End processing.)") fmt.Fprint(w, "how dirty. ;)")
fmt.Fprint(w, "how dirty. ;)") fmt.Printf("error: %v", err)
fmt.Printf("error: %v", err) return
return }
} fmt.Println(GRI)
fmt.Println(GRI) fmt.Println("The request is valid! Responding...")
fmt.Println("The request is valid! Responding...") fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?>
fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
@ -307,22 +301,22 @@ func handler(w http.ResponseWriter, r *http.Request) {
</GetRegistrationInfoResponse> </GetRegistrationInfoResponse>
</soapenv:Body> </soapenv:Body>
</soapenv:Envelope>`) </soapenv:Envelope>`)
fmt.Println("Delivered response!")
} else { case []byte("Register"):
if bytes.Contains(body, []byte("Register")) { fmt.Println("REG.")
fmt.Println("REG.") REG := REG{}
REG := REG{} err = xml.Unmarshal([]byte(body), &REG)
err = xml.Unmarshal([]byte(body), &REG) if err != nil {
if err != nil { fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Println("...or not. Bad or incomplete request. (End processing.)") fmt.Fprint(w, "disgustingly invalid. ;)")
fmt.Fprint(w, "disgustingly invalid. ;)") fmt.Printf("error: %v", err)
fmt.Printf("error: %v", err) return
return }
} fmt.Println(REG)
fmt.Println(REG) fmt.Println("The request is valid! Responding...")
fmt.Println("The request is valid! Responding...") fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?>
fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
@ -342,22 +336,22 @@ func handler(w http.ResponseWriter, r *http.Request) {
</RegisterResponse> </RegisterResponse>
</soapenv:Body> </soapenv:Body>
</soapenv:Envelope>`) </soapenv:Envelope>`)
fmt.Println("Delivered response!")
} else { case []byte("Unregister"):
if bytes.Contains(body, []byte("Unregister")) { fmt.Println("UNR.")
fmt.Println("UNR.") UNR := UNR{}
UNR := UNR{} err = xml.Unmarshal([]byte(body), &UNR)
err = xml.Unmarshal([]byte(body), &UNR) if err != nil {
if err != nil { fmt.Println("...or not. Bad or incomplete request. (End processing.)")
fmt.Println("...or not. Bad or incomplete request. (End processing.)") fmt.Fprint(w, "how abnormal... ;)")
fmt.Fprint(w, "how abnormal... ;)") fmt.Printf("error: %v", err)
fmt.Printf("error: %v", err) return
return }
} fmt.Println(UNR)
fmt.Println(UNR) fmt.Println("The request is valid! Responding...")
fmt.Println("The request is valid! Responding...") fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?>
fmt.Fprintf(w, `<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body> <soapenv:Body>
<UnregisterResponse xmlns="urn:ias.wsapi.broadon.com"> <UnregisterResponse xmlns="urn:ias.wsapi.broadon.com">
@ -370,18 +364,10 @@ func handler(w http.ResponseWriter, r *http.Request) {
</UnregisterResponse> </UnregisterResponse>
</soapenv:Body> </soapenv:Body>
</soapenv:Envelope>`) </soapenv:Envelope>`)
fmt.Println("Delivered response!")
} else {
fmt.Println("Nothing sent?")
fmt.Fprintf(w, "the bathtub is empty, it needs SOAP. ;)")
}
}
}
}
}
}
}
} }
// TODO: Add NUS and CAS SOAP to the case list.
fmt.Println("-=End of Request.=-" + "\n") fmt.Println("-=End of Request.=-" + "\n")
} }