Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
87 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package ejabberd | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"path" | ||
"strings" | ||
) | ||
|
||
//============================================================================== | ||
// Helpers for command-line tool | ||
|
||
// JoinURL checks that Base URL is a valid URL and joins base URL with | ||
// the method suffix string. | ||
func JoinURL(baseURL string, suffix string) (string, error) { | ||
var u *url.URL | ||
var err error | ||
|
||
if u, err = url.Parse(baseURL); err != nil { | ||
return "", fmt.Errorf("invalid url: %s", baseURL) | ||
} | ||
|
||
if u.Scheme != "http" && u.Scheme != "https" { | ||
return "", fmt.Errorf("invalid url scheme: %s", u.Scheme) | ||
} | ||
|
||
u.Path = path.Join(u.Path, suffix) | ||
return u.String(), nil | ||
} | ||
|
||
// PrepareScope ensures we return scopes as space separated. However, | ||
// we accept comma separated scopes as input as well for convenience. | ||
func PrepareScope(s string) string { | ||
return strings.Replace(s, ",", " ", -1) | ||
} | ||
|
||
//============================================================================== | ||
// Internal helper functions | ||
|
||
// stringInSlice returns whether a string is a member of a string | ||
// slice. | ||
func stringInSlice(a string, list []string) bool { | ||
for _, b := range list { | ||
if b == a { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package ejabberd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// JID processing | ||
// TODO update gox and import it directly from gox | ||
|
||
type jid struct { | ||
username string | ||
domain string | ||
resource string | ||
} | ||
|
||
func parseJID(sjid string) (jid, error) { | ||
var j jid | ||
|
||
s1 := strings.SplitN(sjid, "/", 2) | ||
if len(s1) > 1 { | ||
j.resource = s1[1] | ||
} | ||
|
||
s2 := strings.Split(s1[0], "@") | ||
if len(s2) != 2 { | ||
return jid{}, errors.New("invalid jid") | ||
} | ||
|
||
j.username = s2[0] | ||
j.domain = s2[1] | ||
return j, nil | ||
} | ||
|
||
func (j jid) bare() string { | ||
return fmt.Sprintf("%s@%s", j.username, j.domain) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters