/** **************************************************************************
* s3.c
*
* Copyright 2008 Bryan Ischo <bryan@ischo.com>
*
* This file is part of libs3.
*
* libs3 is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, version 3 of the License.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of this library and its programs with the
* OpenSSL library, and distribute linked combinations including the two.
*
* libs3 is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License version 3
* along with libs3, in a file named COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
************************************************************************** **/
/**
* This is a 'driver' program that simply converts command-line input into
* calls to libs3 functions, and prints the results.
**/
#include <ctype.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include "libs3.h"
// Some Windows stuff
#ifndef FOPEN_EXTRA_FLAGS
#define FOPEN_EXTRA_FLAGS ""
#endif
// Some Unix stuff (to work around Windows issues)
#ifndef SLEEP_UNITS_PER_SECOND
#define SLEEP_UNITS_PER_SECOND 1
#endif
// Also needed for Windows, because somehow MinGW doesn't define this
extern int putenv(char *);
// Command-line options, saved as globals ------------------------------------
static int forceG = 0;
static int showResponsePropertiesG = 0;
static S3Protocol protocolG = S3ProtocolHTTPS;
static S3UriStyle uriStyleG = S3UriStylePath;
static int retriesG = 5;
// Environment variables, saved as globals ----------------------------------
static const char *accessKeyIdG = 0;
static const char *secretAccessKeyG = 0;
// Request results, saved as globals -----------------------------------------
static int statusG = 0;
static char errorDetailsG[4096] = { 0 };
// Other globals -------------------------------------------------------------
static char putenvBufG[256];
// Option prefixes -----------------------------------------------------------
#define LOCATION_PREFIX "location="
#define LOCATION_PREFIX_LEN (sizeof(LOCATION_PREFIX) - 1)
#define CANNED_ACL_PREFIX "cannedAcl="
#define CANNED_ACL_PREFIX_LEN (sizeof(CANNED_ACL_PREFIX) - 1)
#define PREFIX_PREFIX "prefix="
#define PREFIX_PREFIX_LEN (sizeof(PREFIX_PREFIX) - 1)
#define MARKER_PREFIX "marker="
#define MARKER_PREFIX_LEN (sizeof(MARKER_PREFIX) - 1)
#define DELIMITER_PREFIX "delimiter="
#define DELIMITER_PREFIX_LEN (sizeof(DELIMITER_PREFIX) - 1)
#define MAXKEYS_PREFIX "maxkeys="
#define MAXKEYS_PREFIX_LEN (sizeof(MAXKEYS_PREFIX) - 1)
#define FILENAME_PREFIX "filename="
#define FILENAME_PREFIX_LEN (sizeof(FILENAME_PREFIX) - 1)
#define CONTENT_LENGTH_PREFIX "contentLength="
#define CONTENT_LENGTH_PREFIX_LEN (sizeof(CONTENT_LENGTH_PREFIX) - 1)
#define CACHE_CONTROL_PREFIX "cacheControl="
#define CACHE_CONTROL_PREFIX_LEN (sizeof(CACHE_CONTROL_PREFIX) - 1)
#define CONTENT_TYPE_PREFIX "contentType="
#define CONTENT_TYPE_PREFIX_LEN (sizeof(CONTENT_TYPE_PREFIX) - 1)
#define MD5_PREFIX "md5="
#define MD5_PREFIX_LEN (sizeof(MD5_PREFIX) - 1)
#define CONTENT_DISPOSITION_FILENAME_PREFIX "contentDispositionFilename="
#define CONTENT_DISPOSITION_FILENAME_PREFIX_LEN \
(sizeof(CONTENT_DISPOSITION_FILENAME_PREFIX) - 1)
#define CONTENT_ENCODING_PREFIX "contentEncoding="
#define CONTENT_ENCODING_PREFIX_LEN (sizeof(CONTENT_ENCODING_PREFIX) - 1)
#define EXPIRES_PREFIX "expires="
#define EXPIRES_PREFIX_LEN (sizeof(EXPIRES_PREFIX) - 1)
#define X_AMZ_META_PREFIX "x-amz-meta-"
#define X_AMZ_META_PREFIX_LEN (sizeof(X_AMZ_META_PREFIX) - 1)
#define IF_MODIFIED_SINCE_PREFIX "ifModifiedSince="
#define IF_MODIFIED_SINCE_PREFIX_LEN (sizeof(IF_MODIFIED_SINCE_PREFIX) - 1)
#define IF_NOT_MODIFIED_SINCE_PREFIX "ifNotmodifiedSince="
#define IF_NOT_MODIFIED_SINCE_PREFIX_LEN \
(sizeof(IF_NOT_MODIFIED_SINCE_PREFIX) - 1)
#define IF_MATCH_PREFIX "ifMatch="
#define IF_MATCH_PREFIX_LEN (sizeof(IF_MATCH_PREFIX) - 1)
#define IF_NOT_MATCH_PREFIX "ifNotMatch="
#define IF_NOT_MATCH_PREFIX_LEN (sizeof(IF_NOT_MATCH_PREFIX) - 1)
#define START_BYTE_PREFIX "startByte="
#define START_BYTE_PREFIX_LEN (sizeof(START_BYTE_PREFIX) - 1)
#define BYTE_COUNT_PREFIX "byteCount="
#define BYTE_COUNT_PREFIX_LEN (sizeof(BYTE_COUNT_PREFIX) - 1)
#define ALL_DETAILS_PREFIX "allDetails="
#define ALL_DETAILS_PREFIX_LEN (sizeof(ALL_DETAILS_PREFIX) - 1)
#define NO_STATUS_PREFIX "noStatus="
#define NO_STATUS_PREFIX_LEN (sizeof(NO_STATUS_PREFIX) - 1)
#define RESOURCE_PREFIX "resource="
#define RESOURCE_PREFIX_LEN (sizeof(RESOURCE_PREFIX) - 1)
#define TARGET_BUCKET_PREFIX "targetBucket="
#define TARGET_BUCKET_PREFIX_LEN (sizeof(TARGET_BUCKET_PREFIX) - 1)
#define TARGET_PREFIX_PREFIX "targetPrefix="
#define TARGET_PREFIX_PREFIX_LEN (sizeof(TARGET_PREFIX_PREFIX) - 1)
// util ----------------------------------------------------------------------
static void S3_init()
{
S3Status status;
const char *hostname = getenv("S3_HOSTNAME");
if ((status = S3_initialize("s3", S3_INIT_ALL, hostname))
!= S3StatusOK) {
fprintf(stderr, "Failed to initialize libs3: %s\n",
S3_get_status_name(status));
exit(-1);
}
}
static void printError()
{
if (statusG < S3StatusErrorAccessDenied) {
fprintf(stderr, "\nERROR: %s\n", S3_get_status_name(statusG));
}
else {
fprintf(stderr, "\nERROR: %s\n", S3_get_status_name(statusG));
fprintf(stderr, "%s\n", errorDetailsG);
}
}
static void usageExit(FILE *out)
{
fprintf(out,
"\n Options:\n"
"\n"
" Command Line:\n"
"\n"
" -f/--force : force operation despite warnings\n"
" -h/--vhost-style : use virtual-host-style URIs (default is "
"path-style)\n"
" -u/--unencrypted : unencrypted (use HTTP instead of HTTPS)\n"
" -s/--show-properties : show response properties on stdout\n"
" -r/--retries : retry retryable failures this number of times\n"
" (default is 5)\n"
"\n"
" Environment:\n"
"\n"
" S3_ACCESS_KEY_ID : S3 access key ID (required)\n"
" S3_SECRET_ACCESS_KEY : S3 secret access key (required)\n"
" S3_HOSTNAME : specify alternative S3 host (optional)\n"
"\n"
" Commands (with <required parameters> and [optional parameters]) :\n"
"\n"
" (NOTE: all command parameters take a value and are specified using the\n"
" pattern parameter=value)\n"
"\n"
" help : Prints this help text\n"
"\n"
" list : Lists owned buckets\n"
" [allDetails] : Show full details\n"
"\n"
" test : Tests a bucket for existence and accessibility\n"
" <bucket> : Bucket to test\n"
"\n"
" create : Create a new bucket\n"
" <bucket> : Bucket to create\n"
" [cannedAcl] : Canned ACL for the bucket (see Canned ACLs)\n"
" [location] : Location for bucket (for example, EU)\n"
"\n"
" delete : Delete a bucket or key\n"
" <bucket>[/<key>] : Bucket or bucket/key to delete\n"
"\n"
" list : List bucket contents\n"
" <bucket> : Bucket to list\n"
" [prefix] : Prefix for results set\n"
" [marker] : Where in results set to start listing\n"
" [delimiter] : Delimiter for rolling up results set\n"
" [maxkeys] : Maximum number of keys to return in results set\n"
" [allDetails] : Show full details for each key\n"
"\n
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
libs3-2.0.tar.gz (52个子文件)
libs3-2.0
.gitignore 19B
src
simplexml.c 6KB
service_access_logging.c 21KB
bucket.c 29KB
acl.c 13KB
testsimplexml.c 3KB
mingw_functions.c 3KB
request_context.c 6KB
response_headers_handler.c 7KB
util.c 15KB
service.c 7KB
object.c 15KB
error_parser.c 9KB
general.c 17KB
request.c 49KB
mingw_s3_functions.c 1KB
s3.c 85KB
libs3.spec 2KB
TODO 87B
archlinux
PKGBUILD 609B
inc
simplexml.h 2KB
string_buffer.h 5KB
response_headers_handler.h 2KB
request_context.h 1KB
error_parser.h 3KB
libs3.h 80KB
util.h 4KB
mingw
pthread.h 2KB
sys
select.h 1KB
utsname.h 1KB
request.h 6KB
LICENSE 834B
ChangeLog 653B
GNUmakefile 13KB
mswin
libs3.def 529B
rmrf.bat 85B
COPYING 34KB
debian
control 478B
control.dev 1017B
changelog.Debian 234B
postinst 20B
changelog 174B
INSTALL 2KB
GNUmakefile.osx 10KB
doxyfile 35KB
README 126B
GNUmakefile.mingw 10KB
test
test.sh 5KB
goodxml_01.xml 274B
goodxml_03.xml 20KB
badxml_01.xml 1KB
goodxml_02.xml 1KB
共 52 条
- 1
资源评论
- shuzhan87872017-04-04linux下的版本,刚下载完成,怎么用还需要研究下
- CloseHandler2016-03-21是linux下的代码
- c517772012-08-14咋编译没搞清楚,而且还要依赖其他的软件库
- 愤怒的bird2014-09-05linux环境的代码,环境匹配的用户可以看看,windows下要做此类开发当前还没有合适的C SDK
elainedou
- 粉丝: 1
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功