Enhance 'cp' command implements, add another package 'uri'
- <S3Path> <LocalPath> - <LocalPath> <S3Path> TODO - <S3Path> <S3Path> - <S3Path> <S3Bucket> - <LocalDir> <S3Bucket> Added a new package called 'URI' for parsing URI schemes in standard way.
This commit is contained in:
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014 Minio, Inc.
|
||||
* Mini Object Storage, (C) 2014,2015 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -111,5 +111,5 @@ var Configure = cli.Command{
|
||||
}
|
||||
|
||||
const (
|
||||
S3_AUTH = ".s3auth"
|
||||
AUTH = ".auth"
|
||||
)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014 Minio, Inc.
|
||||
* Mini Object Storage, (C) 2014,2015 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -40,7 +40,7 @@ var Options = []cli.Command{
|
||||
|
||||
func getAuthFilePath() string {
|
||||
home := os.Getenv("HOME")
|
||||
return path.Join(home, S3_AUTH)
|
||||
return path.Join(home, AUTH)
|
||||
}
|
||||
|
||||
func getAWSEnvironment() (auth *s3.Auth, err error) {
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ func doConfigure(c *cli.Context) {
|
||||
|
||||
var s3File *os.File
|
||||
home := os.Getenv("HOME")
|
||||
s3File, err = os.OpenFile(path.Join(home, S3_AUTH), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
|
||||
s3File, err = os.OpenFile(path.Join(home, AUTH), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
|
||||
defer s3File.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014 Minio, Inc.
|
||||
* Mini Object Storage, (C) 2014,2015 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -10,68 +10,64 @@ import (
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/minio-io/mc/pkg/s3"
|
||||
"github.com/minio-io/mc/pkg/uri"
|
||||
)
|
||||
|
||||
type fsMeta struct {
|
||||
bucket string
|
||||
body string
|
||||
key string
|
||||
get bool
|
||||
put bool
|
||||
}
|
||||
|
||||
func parseCpOptions(c *cli.Context) (fsmeta fsMeta, err error) {
|
||||
var localPath, s3Path string
|
||||
var get, put bool
|
||||
func parseCpOptions(c *cli.Context) (fsoptions fsOptions, err error) {
|
||||
switch len(c.Args()) {
|
||||
case 1:
|
||||
return fsMeta{}, errors.New("Missing <S3Path> or <LocalPath>")
|
||||
return fsOptions{}, errors.New("Missing <S3Path> or <LocalPath>")
|
||||
case 2:
|
||||
if strings.HasPrefix(c.Args().Get(0), "s3://") {
|
||||
s3Path = c.Args().Get(0)
|
||||
localPath = c.Args().Get(1)
|
||||
get = true
|
||||
put = false
|
||||
uri := uri.ParseURI(c.Args().Get(0))
|
||||
if uri.Scheme == "" {
|
||||
return fsOptions{}, errors.New("Invalid URI scheme")
|
||||
}
|
||||
fsoptions.bucket = uri.Server
|
||||
fsoptions.key = uri.Path
|
||||
fsoptions.body = c.Args().Get(1)
|
||||
fsoptions.isget = true
|
||||
fsoptions.isput = false
|
||||
} else if strings.HasPrefix(c.Args().Get(1), "s3://") {
|
||||
s3Path = c.Args().Get(1)
|
||||
localPath = c.Args().Get(0)
|
||||
get = false
|
||||
put = true
|
||||
uri := uri.ParseURI(c.Args().Get(1))
|
||||
if uri.Scheme == "" {
|
||||
return fsOptions{}, errors.New("Invalid URI scheme")
|
||||
}
|
||||
fsoptions.bucket = uri.Server
|
||||
fsoptions.key = c.Args().Get(0)
|
||||
fsoptions.body = c.Args().Get(0)
|
||||
fsoptions.isget = false
|
||||
fsoptions.isput = true
|
||||
}
|
||||
default:
|
||||
return fsMeta{}, errors.New("Arguments missing <S3Path> or <LocalPath>")
|
||||
return fsOptions{}, errors.New("Arguments missing <S3Path> or <LocalPath>")
|
||||
}
|
||||
fsmeta.bucket = strings.Split(s3Path, "s3://")[1]
|
||||
fsmeta.body = localPath
|
||||
fsmeta.key = localPath
|
||||
fsmeta.get = get
|
||||
fsmeta.put = put
|
||||
|
||||
return fsmeta, nil
|
||||
return
|
||||
}
|
||||
|
||||
func doFsCopy(c *cli.Context) {
|
||||
var auth *s3.Auth
|
||||
var err error
|
||||
var bodyFile *os.File
|
||||
auth, err = getAWSEnvironment()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
s3c := s3.NewS3Client(auth)
|
||||
|
||||
var fsmeta fsMeta
|
||||
fsmeta, err = parseCpOptions(c)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
var bodyFile *os.File
|
||||
bodyFile, err = os.Open(fsmeta.body)
|
||||
defer bodyFile.Close()
|
||||
var fsoptions fsOptions
|
||||
fsoptions, err = parseCpOptions(c)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if fsmeta.put {
|
||||
if fsoptions.isput {
|
||||
bodyFile, err = os.Open(fsoptions.body)
|
||||
defer bodyFile.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var bodyBuffer io.Reader
|
||||
var size int64
|
||||
var md5hash hash.Hash
|
||||
@@ -80,14 +76,17 @@ func doFsCopy(c *cli.Context) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
err = s3c.Put(fsmeta.bucket, fsmeta.key, md5hash, size, bodyBuffer)
|
||||
err = s3c.Put(fsoptions.bucket, fsoptions.key, md5hash, size, bodyBuffer)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
} else if fsmeta.get {
|
||||
} else if fsoptions.isget {
|
||||
var objectReader io.ReadCloser
|
||||
var objectSize int64
|
||||
objectReader, objectSize, err = s3c.Get(fsmeta.bucket, fsmeta.key)
|
||||
bodyFile, err = os.OpenFile(fsoptions.body, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
|
||||
defer bodyFile.Close()
|
||||
|
||||
objectReader, objectSize, err = s3c.Get(fsoptions.bucket, fsoptions.key)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
+13
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014 Minio, Inc.
|
||||
* Mini Object Storage, (C) 2014,2015 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,11 +21,10 @@ import (
|
||||
)
|
||||
|
||||
var Cp = cli.Command{
|
||||
Name: "cp",
|
||||
Usage: "",
|
||||
Description: `Copies a local file or Object to another location locally
|
||||
or in S3.`,
|
||||
Action: doFsCopy,
|
||||
Name: "cp",
|
||||
Usage: "",
|
||||
Description: `Copies a local file or Object to another location locally or in S3.`,
|
||||
Action: doFsCopy,
|
||||
}
|
||||
|
||||
var Ls = cli.Command{
|
||||
@@ -49,6 +48,14 @@ var Sync = cli.Command{
|
||||
Action: doFsSync,
|
||||
}
|
||||
|
||||
type fsOptions struct {
|
||||
bucket string
|
||||
body string
|
||||
key string
|
||||
isget bool
|
||||
isput bool
|
||||
}
|
||||
|
||||
func doFsList(c *cli.Context) {
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014 Minio, Inc.
|
||||
* Mini Object Storage, (C) 2014,2015 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014 Minio, Inc.
|
||||
* Mini Object Storage, (C) 2014,2015 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014 Minio, Inc.
|
||||
* Mini Object Storage, (C) 2014,2015 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
+1366
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014,2015 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package uri
|
||||
|
||||
// #include <stdlib.h>
|
||||
// #include "uri.h"
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
type URI struct {
|
||||
Scheme string
|
||||
Server string
|
||||
Path string
|
||||
}
|
||||
|
||||
func ParseURI(url string) (uri *URI) {
|
||||
var buri *C.bURI
|
||||
ret := C.minio_uri_parse(C.CString(url), &buri)
|
||||
defer C.free(unsafe.Pointer(buri))
|
||||
|
||||
uri = &URI{Scheme: "", Server: "", Path: ""}
|
||||
if int(ret) == -1 {
|
||||
// URI cannot be parsed
|
||||
return
|
||||
}
|
||||
|
||||
uri.Scheme = C.GoString(buri.scheme)
|
||||
uri.Server = C.GoString(buri.server)
|
||||
uri.Path = C.GoString(buri.path)
|
||||
|
||||
return
|
||||
}
|
||||
+282
@@ -0,0 +1,282 @@
|
||||
/**
|
||||
* Summary: library of generic URI related routines
|
||||
* Description: library of generic URI related routines
|
||||
* Implements RFC 2396
|
||||
*
|
||||
* Copyright (C) 1998-2012 Daniel Veillard. All Rights Reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* DANIEL VEILLARD BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Except as contained in this notice, the name of Daniel Veillard shall not
|
||||
* be used in advertising or otherwise to promote the sale, use or other
|
||||
* dealings in this Software without prior written authorization from him.
|
||||
*
|
||||
* daniel@veillard.com
|
||||
*
|
||||
*
|
||||
* Mini Object Storage, (C) 2014,2015 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __URI_H__
|
||||
#define __URI_H__
|
||||
|
||||
|
||||
/**
|
||||
* MAX_URI_LENGTH:
|
||||
*
|
||||
* The definition of the URI regexp in the above RFC has no size limit
|
||||
* In practice they are usually relativey short except for the
|
||||
* data URI scheme as defined in RFC 2397. Even for data URI the usual
|
||||
* maximum size before hitting random practical limits is around 64 KB
|
||||
* and 4KB is usually a maximum admitted limit for proper operations.
|
||||
* The value below is more a security limit than anything else and
|
||||
* really should never be hit by 'normal' operations
|
||||
* Set to 1 MByte in 2012, this is only enforced on output
|
||||
*/
|
||||
#define MAX_URI_LENGTH (1024 * 1024)
|
||||
|
||||
/*
|
||||
* Old rule from 2396 used in legacy handling code
|
||||
* alpha = lowalpha | upalpha
|
||||
*/
|
||||
#define IS_ALPHA(x) (IS_LOWALPHA(x) || IS_UPALPHA(x))
|
||||
|
||||
/*
|
||||
* lowalpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" |
|
||||
* "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" |
|
||||
* "u" | "v" | "w" | "x" | "y" | "z"
|
||||
*/
|
||||
|
||||
#define IS_LOWALPHA(x) (((x) >= 'a') && ((x) <= 'z'))
|
||||
|
||||
/*
|
||||
* upalpha = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" |
|
||||
* "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" |
|
||||
* "U" | "V" | "W" | "X" | "Y" | "Z"
|
||||
*/
|
||||
#define IS_UPALPHA(x) (((x) >= 'A') && ((x) <= 'Z'))
|
||||
|
||||
#ifdef IS_DIGIT
|
||||
#undef IS_DIGIT
|
||||
#endif
|
||||
/*
|
||||
* digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
|
||||
*/
|
||||
#define IS_DIGIT(x) (((x) >= '0') && ((x) <= '9'))
|
||||
|
||||
/*
|
||||
* alphanum = alpha | digit
|
||||
*/
|
||||
|
||||
#define IS_ALPHANUM(x) (IS_ALPHA(x) || IS_DIGIT(x))
|
||||
|
||||
/*
|
||||
* mark = "-" | "_" | "." | "!" | "~" | "*" | "'" | "(" | ")"
|
||||
*/
|
||||
|
||||
#define IS_MARK(x) (((x) == '-') || ((x) == '_') || ((x) == '.') || \
|
||||
((x) == '!') || ((x) == '~') || ((x) == '*') || \
|
||||
((x) == '\'') || ((x) == '(') || ((x) == ')'))
|
||||
|
||||
/*
|
||||
* unwise = "{" | "}" | "|" | "\" | "^" | "`"
|
||||
*/
|
||||
|
||||
#define IS_UNWISE(p) \
|
||||
(((*(p) == '{')) || ((*(p) == '}')) || ((*(p) == '|')) || \
|
||||
((*(p) == '\\')) || ((*(p) == '^')) || ((*(p) == '[')) || \
|
||||
((*(p) == ']')) || ((*(p) == '`')))
|
||||
/*
|
||||
* reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" | "$" | "," |
|
||||
* "[" | "]"
|
||||
*/
|
||||
|
||||
#define IS_RESERVED(x) (((x) == ';') || ((x) == '/') || ((x) == '?') || \
|
||||
((x) == ':') || ((x) == '@') || ((x) == '&') || \
|
||||
((x) == '=') || ((x) == '+') || ((x) == '$') || \
|
||||
((x) == ',') || ((x) == '[') || ((x) == ']'))
|
||||
/*
|
||||
* unreserved = alphanum | mark
|
||||
*/
|
||||
|
||||
#define IS_UNRESERVED(x) (IS_ALPHANUM(x) || IS_MARK(x))
|
||||
|
||||
/*
|
||||
* Skip to next pointer char, handle escaped sequences
|
||||
*/
|
||||
|
||||
#define NEXT(p) ((*p == '%')? p += 3 : p++)
|
||||
|
||||
/*
|
||||
* Productions from the spec.
|
||||
*
|
||||
* authority = server | reg_name
|
||||
* reg_name = 1*( unreserved | escaped | "$" | "," |
|
||||
* ";" | ":" | "@" | "&" | "=" | "+" )
|
||||
*
|
||||
* path = [ abs_path | opaque_part ]
|
||||
*/
|
||||
|
||||
|
||||
/************************************************************************
|
||||
* *
|
||||
* RFC 3986 parser *
|
||||
* *
|
||||
************************************************************************/
|
||||
|
||||
#define ISA_DIGIT(p) ((*(p) >= '0') && (*(p) <= '9'))
|
||||
#define ISA_ALPHA(p) (((*(p) >= 'a') && (*(p) <= 'z')) || \
|
||||
((*(p) >= 'A') && (*(p) <= 'Z')))
|
||||
#define ISA_HEXDIG(p) \
|
||||
(ISA_DIGIT(p) || ((*(p) >= 'a') && (*(p) <= 'f')) || \
|
||||
((*(p) >= 'A') && (*(p) <= 'F')))
|
||||
|
||||
/*
|
||||
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
||||
* / "*" / "+" / "," / ";" / "="
|
||||
*/
|
||||
#define ISA_SUB_DELIM(p) \
|
||||
(((*(p) == '!')) || ((*(p) == '$')) || ((*(p) == '&')) || \
|
||||
((*(p) == '(')) || ((*(p) == ')')) || ((*(p) == '*')) || \
|
||||
((*(p) == '+')) || ((*(p) == ',')) || ((*(p) == ';')) || \
|
||||
((*(p) == '=')) || ((*(p) == '\'')))
|
||||
|
||||
/*
|
||||
* gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
|
||||
*/
|
||||
#define ISA_GEN_DELIM(p) \
|
||||
(((*(p) == ':')) || ((*(p) == '/')) || ((*(p) == '?')) || \
|
||||
((*(p) == '#')) || ((*(p) == '[')) || ((*(p) == ']')) || \
|
||||
((*(p) == '@')))
|
||||
|
||||
/*
|
||||
* reserved = gen-delims / sub-delims
|
||||
*/
|
||||
#define ISA_RESERVED(p) (ISA_GEN_DELIM(p) || (ISA_SUB_DELIM(p)))
|
||||
|
||||
/*
|
||||
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
||||
*/
|
||||
#define ISA_UNRESERVED(p) \
|
||||
((ISA_ALPHA(p)) || (ISA_DIGIT(p)) || ((*(p) == '-')) || \
|
||||
((*(p) == '.')) || ((*(p) == '_')) || ((*(p) == '~')))
|
||||
|
||||
/*
|
||||
* pct-encoded = "%" HEXDIG HEXDIG
|
||||
*/
|
||||
#define ISA_PCT_ENCODED(p) \
|
||||
((*(p) == '%') && (ISA_HEXDIG(p + 1)) && (ISA_HEXDIG(p + 2)))
|
||||
|
||||
/*
|
||||
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
||||
*/
|
||||
#define ISA_PCHAR(p) \
|
||||
(ISA_UNRESERVED(p) || \
|
||||
ISA_PCT_ENCODED(p) || \
|
||||
ISA_SUB_DELIM(p) || \
|
||||
((*(p) == ':')) || ((*(p) == '@')))
|
||||
|
||||
#define URI_TRIM(uri) \
|
||||
if (uri != NULL) { \
|
||||
if (uri->scheme != NULL) \
|
||||
FREE(uri->scheme); \
|
||||
if (uri->server != NULL) \
|
||||
FREE(uri->server); \
|
||||
if (uri->user != NULL) \
|
||||
FREE(uri->user); \
|
||||
if (uri->path != NULL) \
|
||||
FREE(uri->path); \
|
||||
if (uri->fragment != NULL) \
|
||||
FREE(uri->fragment); \
|
||||
if (uri->opaque != NULL) \
|
||||
FREE(uri->opaque); \
|
||||
if (uri->authority != NULL) \
|
||||
FREE(uri->authority); \
|
||||
if (uri->query != NULL) \
|
||||
FREE(uri->query); \
|
||||
}
|
||||
|
||||
#define FREE(ptr) \
|
||||
if (ptr != NULL) { \
|
||||
free ((void *)ptr); \
|
||||
ptr = (void *)0xeeeeeeee; \
|
||||
}
|
||||
|
||||
#define URI_FREE(uri) \
|
||||
if (uri != NULL) { \
|
||||
URI_TRIM(uri); \
|
||||
FREE(uri); \
|
||||
}
|
||||
|
||||
|
||||
#define is_hex(c) \
|
||||
(((c >= '0') && (c <= '9')) || \
|
||||
((c >= 'a') && (c <= 'f')) || \
|
||||
((c >= 'A') && (c <= 'F')))
|
||||
|
||||
/**
|
||||
* bURI:
|
||||
*
|
||||
* A parsed bURI reference. This is a struct containing the various fields
|
||||
* as described in RFC 2396 but separated for further processing.
|
||||
*/
|
||||
|
||||
typedef struct _bURI bURI;
|
||||
typedef bURI *bURIptr;
|
||||
struct _bURI {
|
||||
char *scheme; /* the bURI scheme */
|
||||
char *opaque; /* opaque part */
|
||||
char *authority; /* the authority part */
|
||||
char *server; /* the server part */
|
||||
char *user; /* the user part */
|
||||
int port; /* the port number */
|
||||
char *path; /* the path string */
|
||||
char *fragment; /* the fragment identifier */
|
||||
int cleanup; /* parsing potentially unclean bURI */
|
||||
char *query; /* the query string (as it appears in the bURI) */
|
||||
char *query_raw; /* the query string (as it appears in the bURI) */
|
||||
};
|
||||
|
||||
/************************************************************************
|
||||
* *
|
||||
* Generic URI structure functions *
|
||||
* *
|
||||
************************************************************************/
|
||||
|
||||
int minio_uri_parse_into(bURI *, const char *);
|
||||
char *minio_uri_resolve_relative (const char *, const char *);
|
||||
int minio_uri_parse(const char *, bURI **);
|
||||
bURI *minio_uri_parse_raw(const char *, int);
|
||||
bURI *minio_uri_new(void);
|
||||
char *minio_uri_to_string(bURI *);
|
||||
char *minio_uri_string_unescape(const char *, int, char *);
|
||||
char *minio_uri_string_escape(const char *, const char *);
|
||||
|
||||
#endif /* __URI_H__ */
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014,2015 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package uri
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidScheme(t *testing.T) {
|
||||
uri := ParseURI("s3://mybucket/your_key/location")
|
||||
if uri.Scheme == "" {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
|
||||
func TestInvalidScheme(t *testing.T) {
|
||||
uri := ParseURI("s3/mybucket/your_key/location")
|
||||
if uri.Scheme != "" {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Mini Object Storage, (C) 2014 Minio, Inc.
|
||||
* Mini Object Storage, (C) 2014,2015 Minio, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
Reference in New Issue
Block a user