-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
165 lines (136 loc) · 3.49 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// stegstream-client project main.go
package main
import (
"fmt"
"os"
)
// Main: program entry point
func main() {
var hiddenFileExtracted bool = false
var hiddenFileName string
exitCode := 0
// Hardcode command line arguments for testing
// testArgs := []string{"", ""}
// testArgs[0] = "./stegstream-client"
// testArgs[1] = "http://localhost:8080/Audio"
// os.Args = testArgs
if os.Args != nil {
if DEBUG == true {
fmt.Println(len(os.Args), UI_Arguments, os.Args)
}
if len(os.Args) == 1 {
// No user arguments given - display help
fmt.Println(UI_Help)
}
if len(os.Args) == 2 {
if IsStringHelpArgument(os.Args[1]) {
// User has given help argument - display help
fmt.Println(UI_Help)
} else {
// User has given server URL as argument
// Get container file from server URL
if GetServerFile(os.Args[1]) == true {
// Extract hidden file from container file
hiddenFileExtracted, hiddenFileName = Unsteg(TEMP_FILE)
// Wipe container file
if FileExists(TEMP_FILE) {
if WipeFile(TEMP_FILE) == false {
exitCode = 1
fmt.Println(fmt.Sprintf(UI_WipeFileError, TEMP_FILE))
}
}
if hiddenFileExtracted == true {
fmt.Println(UI_ExtractedHiddenFile, hiddenFileName)
} else {
exitCode = 1
fmt.Println(UI_FailedToExtractHiddenFile)
}
} else {
// Delete container file
if FileExists(TEMP_FILE) {
if DeleteFile(TEMP_FILE) == false {
// File deleted
} else {
exitCode = 1
fmt.Println(UI_DeleteError, TEMP_FILE)
}
}
exitCode = 1
fmt.Println(UI_FailedToDownloadContainerFile)
}
}
}
if len(os.Args) == 3 {
if IsStringHelpArgument(os.Args[1]) || IsStringHelpArgument(os.Args[2]) {
// User has given help argument - display help
fmt.Println(UI_Help)
} else {
// User has given local command and local file as arguments
if os.Args[1] == UI_LocalFile {
if FileExists(os.Args[2]) {
// Extract hidden file from container file
hiddenFileExtracted, hiddenFileName = Unsteg(os.Args[2])
if hiddenFileExtracted == true {
fmt.Println(UI_ExtractedHiddenFile, hiddenFileName)
} else {
exitCode = 1
fmt.Println(UI_FailedToExtractHiddenFile)
}
} else {
exitCode = 1
fmt.Println(UI_FileNotFound, os.Args[2])
}
} else {
exitCode = 1
fmt.Println(UI_InvalidArgs)
}
}
}
if len(os.Args) > 3 {
// Too many arguments - display error
exitCode = 1
fmt.Println(UI_InvalidArgs)
}
} else {
// No arguments
exitCode = 1
fmt.Println(UI_NoParametersGiven)
}
os.Exit(exitCode)
}
// IsStringHelpArgument: Returns true if given string is a help argument, false if it is not
func IsStringHelpArgument(_theString string) bool {
isHelpArgument := false
if len(_theString) > 0 {
switch _theString {
case "?":
isHelpArgument = true
case "/?":
isHelpArgument = true
case "-?":
isHelpArgument = true
case "--?":
isHelpArgument = true
case "h":
isHelpArgument = true
case "/h":
isHelpArgument = true
case "-h":
isHelpArgument = true
case "--h":
isHelpArgument = true
case "help":
isHelpArgument = true
case "/help":
isHelpArgument = true
case "-help":
isHelpArgument = true
case "--help":
isHelpArgument = true
}
} else {
fmt.Print(fmt.Sprintf(UI_ParameterInvalid, GetFunctionName()))
fmt.Println(fmt.Sprintf(UI_Parameter, "_theString:"+_theString))
}
return isHelpArgument
}