*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.)

54
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,10 +126,8 @@ 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.
if bytes.Contains(body, []byte("NotifyETicketsSynced")) {
fmt.Println("NETS") fmt.Println("NETS")
NETS := NETS{} NETS := NETS{}
err = xml.Unmarshal([]byte(body), &NETS) err = xml.Unmarshal([]byte(body), &NETS)
@ -158,10 +156,8 @@ func handler(w http.ResponseWriter, r *http.Request) {
</soapenv:Envelope>`) </soapenv:Envelope>`)
fmt.Println("Delivered response!") fmt.Println("Delivered response!")
} else { case []byte("ListETickets"):
// ListETickets
if bytes.Contains(body, []byte("ListETickets")) {
fmt.Println("LET") fmt.Println("LET")
LET := LET{} LET := LET{}
err = xml.Unmarshal([]byte(body), &LET) err = xml.Unmarshal([]byte(body), &LET)
@ -193,8 +189,8 @@ func handler(w http.ResponseWriter, r *http.Request) {
</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)
@ -235,12 +231,10 @@ 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
if bytes.Contains(body, []byte("CheckRegistration")) {
fmt.Println("CR.") fmt.Println("CR.")
CR := CR{} CR := CR{}
err = xml.Unmarshal([]byte(body), &CR) err = xml.Unmarshal([]byte(body), &CR)
@ -269,10 +263,10 @@ 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)
@ -307,10 +301,10 @@ 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)
@ -342,10 +336,10 @@ 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)
@ -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")
} }