コード例 #1
0
static void oss_clean(const char *filename) {
    aos_pool_t *pool;
    oss_request_options_t *opts;
    aos_string_t bucket;
    aos_string_t key;
    aos_status_t *status;
    aos_table_t *resp_headers;

    aos_pool_create(&pool, NULL);

    opts = oss_request_options_create(pool);
    opts->config = oss_config_create(pool);
    aos_str_set(&opts->config->endpoint, SAMPLE_OSS_ENDPOINT);
    aos_str_set(&opts->config->access_key_id, SAMPLE_ACCESS_KEY_ID);
    aos_str_set(&opts->config->access_key_secret, SAMPLE_ACCESS_KEY_SECRET);
    opts->config->is_cname = 0; 
    opts->ctl = aos_http_controller_create(pool, 0);
    aos_str_set(&bucket, SAMPLE_BUCKET_NAME);
    aos_str_set(&key, filename);

    status = oss_delete_object(opts, &bucket, &key, &resp_headers);
    if (!aos_status_is_ok(status)) {
        aos_error_log("clean oss error. [code=%d, message=%s]", 
                      status->code, status->error_code);
        aos_error_log("example exit");
        aos_pool_destroy(pool);
        exit(-1);
    }

    aos_pool_destroy(pool);
}
コード例 #2
0
void delete_file(oss_media_file_t *file) {
    aos_pool_t *p;
    aos_string_t bucket;
    aos_string_t object;
    oss_request_options_t *options;
    aos_table_t *resp_headers;

    aos_pool_create(&p, NULL);
    options = oss_request_options_create(p);
    options->config = oss_config_create(options->pool);
    aos_str_set(&options->config->endpoint, file->endpoint);
    aos_str_set(&options->config->access_key_id, file->access_key_id);
    aos_str_set(&options->config->access_key_secret, file->access_key_secret);
    options->config->is_cname = file->is_cname;
    options->ctl = aos_http_controller_create(options->pool, 0);    
    aos_str_set(&bucket, file->bucket_name);
    aos_str_set(&object, file->object_key);

    oss_delete_object(options, &bucket, &object, &resp_headers);
}
コード例 #3
0
ファイル: log_api.c プロジェクト: is00hcw/aliyun-log-c-sdk
aos_status_t *log_post_logs_with_sts_token(aos_pool_t *p, const char *endpoint, const char * accesskeyId, const char *accessKey, const char *stsToken, const char *project, const char *logstore, cJSON *root)
{
    aos_string_t project_name, logstore_name;
    aos_table_t *headers = NULL;
    aos_table_t *resp_headers = NULL;
    log_request_options_t *options = NULL;
    aos_list_t buffer;
    unsigned char *md5 = NULL;
    char *buf = NULL;
    int64_t buf_len;
    char *b64_value = NULL;
    aos_buf_t *content = NULL;
    aos_status_t *s = NULL;

    options = log_request_options_create(p);
    options->config = log_config_create(options->pool);
    aos_str_set(&(options->config->endpoint), endpoint);
    aos_str_set(&(options->config->access_key_id), accesskeyId);
    aos_str_set(&(options->config->access_key_secret), accessKey);
    if(stsToken != NULL)
    {
        aos_str_set(&(options->config->sts_token), stsToken);
    }
    options->ctl = aos_http_controller_create(options->pool, 0);
    headers = aos_table_make(p, 5);
    apr_table_set(headers, LOG_API_VERSION, "0.6.0");
    apr_table_set(headers, LOG_COMPRESS_TYPE, "lz4");
    apr_table_set(headers, LOG_SIGNATURE_METHOD, "hmac-sha1");
    apr_table_set(headers, LOG_CONTENT_TYPE, "application/json");
    aos_str_set(&project_name, project);
    aos_str_set(&logstore_name, logstore);

    aos_list_init(&buffer);
    char *body = cJSON_PrintUnformatted(root);
    if(body == NULL)
    {
        s = aos_status_create(options->pool);
        aos_status_set(s, 400, AOS_CLIENT_ERROR_CODE, "fail to format cJSON data");
        return s;
    }
    int org_body_size = strlen(body);
    apr_table_set(headers, LOG_BODY_RAW_SIZE, apr_itoa(options->pool, org_body_size));
    int compress_bound = LZ4_compressBound(org_body_size);
    char *compress_data = aos_pcalloc(options->pool, compress_bound);
    int compressed_size = LZ4_compress(body, compress_data, org_body_size);
    if(compressed_size <= 0)
    {
        s = aos_status_create(options->pool);
        aos_status_set(s, 400, AOS_CLIENT_ERROR_CODE, "fail to compress json data");
        return s;
    }
    content = aos_buf_pack(options->pool, compress_data, compressed_size);
    aos_list_add_tail(&content->node, &buffer);

    //add Content-MD5
    buf_len = aos_buf_list_len(&buffer);
    buf = aos_buf_list_content(options->pool, &buffer);
    md5 = aos_md5(options->pool, buf, (apr_size_t)buf_len);
    b64_value = aos_pcalloc(options->pool, 50);
    int loop = 0;
    for(; loop < 16; ++loop)
    {
        unsigned char a = ((*md5)>>4) & 0xF, b = (*md5) & 0xF;
        b64_value[loop<<1] = a > 9 ? (a - 10 + 'A') : (a + '0');
        b64_value[(loop<<1)|1] = b > 9 ? (b - 10 + 'A') : (b + '0');
        ++md5;
    }
    b64_value[loop<<1] = '\0';
    apr_table_set(headers, LOG_CONTENT_MD5, b64_value);

    s = log_post_logs_from_buffer(options, &project_name, &logstore_name, 
				   &buffer, headers, &resp_headers);
    free(body);
    return s;
}
コード例 #4
0
ファイル: oss_test_util.c プロジェクト: RDFS/aliyun-oss-c-sdk
void init_test_request_options(oss_request_options_t *options, int is_cname)
{
    options->config = oss_config_create(options->pool);
    init_test_config(options->config, is_cname);
    options->ctl = aos_http_controller_create(options->pool, 0);
}