mirror of
https://github.com/go-i2p/goSam.git
synced 2025-07-13 14:18:25 -04:00
Improve the parser, automatically set empty destinations to TRANSIENT when using a dialer, better error handling, when a socket gets closed, increment the ID and re-create it
This commit is contained in:
@ -44,6 +44,25 @@ func parseReply(line string) (*Reply, error) {
|
||||
if len(parts) < 3 {
|
||||
return nil, fmt.Errorf("Malformed Reply.\n%s\n", line)
|
||||
}
|
||||
preParseReply := func() []string {
|
||||
val := ""
|
||||
quote := false
|
||||
for _, v := range parts {
|
||||
if strings.Contains(v, "=\"") {
|
||||
quote = true
|
||||
}
|
||||
if strings.Contains(v, "\"\n") || strings.Contains(v, "\" ") {
|
||||
quote = false
|
||||
}
|
||||
if quote {
|
||||
val += v + "_"
|
||||
} else {
|
||||
val += v + " "
|
||||
}
|
||||
}
|
||||
return strings.Split(strings.TrimSuffix(strings.TrimSpace(val), "_"), " ")
|
||||
}
|
||||
parts = preParseReply()
|
||||
|
||||
r := &Reply{
|
||||
Topic: parts[0],
|
||||
@ -64,8 +83,9 @@ func parseReply(line string) (*Reply, error) {
|
||||
kvPair := strings.SplitN(v, "=", 2)
|
||||
if kvPair != nil {
|
||||
if len(kvPair) == 1 {
|
||||
return nil, fmt.Errorf("Malformed key-value-pair len 1.\n%s\n", kvPair)
|
||||
} else if len(kvPair) != 2 {
|
||||
return nil, fmt.Errorf("Malformed key-value-pair.\n%s\n", kvPair)
|
||||
return nil, fmt.Errorf("Malformed key-value-pair len != 2.\n%s\n", kvPair)
|
||||
}
|
||||
}
|
||||
r.Pairs[kvPair[0]] = kvPair[len(kvPair)-1]
|
||||
|
Reference in New Issue
Block a user