~ubuntu-branches/ubuntu/wily/davix/wily

« back to all changes in this revision

Viewing changes to src/tools/davix_tool_params.cpp

  • Committer: Package Import Robot
  • Author(s): Mattias Ellert
  • Date: 2014-10-23 16:02:47 UTC
  • mfrom: (5.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20141023160247-izv1acuq0bcfv3qn
Tags: 0.3.6-1
Update to version 0.3.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <getopt.h>
25
25
#include <string_utils/stringutils.hpp>
26
26
#include <utils/davix_logger.hpp>
 
27
#include <adevpp/algorithm/algorithm.hpp>
27
28
 
28
29
namespace Davix{
29
30
 
42
43
#define S3_ACCESS_KEY       1006
43
44
#define X509_PRIVATE_KEY    1007
44
45
#define HEADERS_OPTIONS     1008
 
46
#define REDIRECTION_OPT     1009
 
47
#define METALINK_OPT        1010
45
48
 
46
49
// LONG OPTS
47
50
 
49
52
{"debug", no_argument, 0,  DEBUG_OPT }, \
50
53
{"header",  required_argument, 0,  'H' }, \
51
54
{"help", no_argument, 0,'?'}, \
 
55
{"metalink", required_argument, 0, METALINK_OPT }, \
52
56
{"module", required_argument, 0, 'P'}, \
53
57
{"proxy", required_argument, 0, 'x'}, \
 
58
{"redirection", required_argument, 0, REDIRECTION_OPT }, \
54
59
{"trace-headers", no_argument, 0, HEADERS_OPTIONS }, \
55
60
{"verbose", no_argument, 0,  0 }, \
56
61
{"version", no_argument, 0, 'V'}
95
100
 
96
101
 
97
102
static void option_abort(char** argv){
98
 
    std::cerr << argv[0] <<", Error: Wrong argument format" << std::endl;
99
 
    std::cerr << "try 'davix --help' for more informations" <<std::endl;
 
103
    std::cerr << argv[0] <<", Error: Wrong argument format\n";
 
104
    std::cerr << "Try '" << argv[0] <<" --help' for more informations" << std::endl;
100
105
    exit(-1);
101
106
}
102
107
 
105
110
    exit(0);
106
111
}
107
112
 
 
113
template <typename T, typename Y, typename Z>
 
114
Y match_option(T begin, T end,
 
115
               Y begin_res, Y end_res,
 
116
               Z val, char** argv){
 
117
    Y res = Adevpp::match_array(begin, end, begin_res, end_res, val);
 
118
    if(res == end_res){
 
119
        option_abort(argv);
 
120
    }
 
121
    return res;
 
122
}
108
123
 
109
124
static int set_header_field(const std::string & arg, OptParams & p, DavixError** err){
110
125
    dav_size_t pos;
116
131
    return 0;
117
132
}
118
133
 
 
134
static void set_metalink_opt(RequestParams & params, const std::string & metalink_opt, char** argv){
 
135
    const std::string str_opt[] = { "no" , "disable", "auto", "failover" };
 
136
    const Davix::MetalinkMode::MetalinkMode mode_opt[] = { MetalinkMode::Disable, MetalinkMode::Disable, MetalinkMode::Auto, MetalinkMode::FailOver };
 
137
    params.setMetalinkMode(*match_option(str_opt, str_opt+sizeof(str_opt)/sizeof(str_opt[0]),
 
138
                                               mode_opt, mode_opt + sizeof(mode_opt)/sizeof(mode_opt[0]),
 
139
                                               metalink_opt, argv));
 
140
}
 
141
 
 
142
 
 
143
static void set_redirection_opt(RequestParams & params, const std::string & redir_opt, char** argv){
 
144
    const std::string str_opt[] = { "no" , "yes", "auto"};
 
145
    const bool mode_opt[] = { false, true, true };
 
146
    params.setTransparentRedirectionSupport(*match_option(str_opt, str_opt+sizeof(str_opt)/sizeof(str_opt[0]),
 
147
                                               mode_opt, mode_opt + sizeof(mode_opt)/sizeof(mode_opt[0]),
 
148
                                               redir_opt, argv));
 
149
}
119
150
 
120
151
 
121
152
int parse_davix_options_generic(const std::string &opt_filter,
135
166
            case 'E':
136
167
                 p.cred_path = std::string(optarg);
137
168
                 break;
138
 
 
139
169
            case 'k':
140
170
                p.params.setSSLCAcheck(false);
141
171
                break;
185
215
            case 'X':
186
216
                p.req_type = std::string(optarg, 0, 255);
187
217
                break;
 
218
            case METALINK_OPT:
 
219
                 set_metalink_opt(p.params, std::string(optarg), argv);
 
220
                 break;
 
221
            case REDIRECTION_OPT:
 
222
                 set_redirection_opt(p.params, std::string(optarg), argv);
 
223
                 break;
188
224
            case '?':
189
225
            printf(p.help_msg.c_str(), argv[0]);
190
226
                return -1;
298
334
            "\t--debug:                  Debug mode\n"
299
335
            "\t--header, -H:             Add a header field to the request\n"
300
336
            "\t--help, -h:               Display this help message\n"
301
 
            "\t--module, -P name:        Load a plugin or profile by name\n"
302
 
            "\t--proxy, -x url:          SOCKS5 proxy server URL (ex: socks5://login:pass@socks.example.org )\n"
 
337
            "\t--metalink OPT:           Metalink support. (OPT=failover[default]|no) \n"
 
338
            "\t--module, -P NAME:        Load a plugin or profile by name\n"
 
339
            "\t--proxy, -x URL:          SOCKS5 proxy server URL. (Ex: socks5://login:pass@socks.example.org)\n"
 
340
            "\t--redirection OPT:        Transparent redirection support. (OPT=yes[default]|no)\n"
303
341
            "\t--trace-headers:          Trace all HTTP queries headers\n"
304
342
            "\t--verbose:                Verbose mode\n"
305
343
            "\t--version, -V:            Display version\n"
306
344
            "  Security Options:\n"
307
 
            "\t--capath CA_path:         Add an additional certificate authority directory\n"
308
 
            "\t--cert, -E cred_path:     Client Certificate in PEM format\n"
309
 
            "\t--key priv_path:          Private key in PEM format\n"
 
345
            "\t--capath CA_PATH:         Add an additional certificate authority directory\n"
 
346
            "\t--cert, -E CRED_PATH:     Client Certificate in PEM format\n"
 
347
            "\t--key KEY_PATH:           Private key in PEM format\n"
310
348
            "\t--insecure, -k:           Disable SSL credential checks\n"
311
349
            "\t--userlogin:              User login for login/password authentication\n"
312
350
            "\t--userpass:               User password for login/password authentication\n"
313
 
            "\t--s3secretkey:            S3 authentication: secret key\n"
314
 
            "\t--s3accesskey:            S3 authentication: access key\n"
 
351
            "\t--s3secretkey SEC_KEY:    S3 authentication: secret key\n"
 
352
            "\t--s3accesskey ACC_KEY:    S3 authentication: access key\n"
315
353
            );
316
354
    return s;
317
355
}
332
370
}
333
371
 
334
372
 
 
373
const std::string  & get_copy_description_options(){
 
374
    static const std::string s("Usage: %s [OPTIONS ...] <src_url> <dst_url>\n"
 
375
            );
 
376
    return s;
 
377
}
335
378
 
336
379
}
337
380