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);
}
Beispiel #2
0
int aos_curl_http_transport_perform(aos_http_transport_t *t_)
{
    int ecode;
    CURLcode code;
    aos_curl_http_transport_t *t = (aos_curl_http_transport_t *)(t_);
    ecode = aos_curl_transport_setup(t);
    if (ecode != AOSE_OK) {
        return ecode;
    }

    t->controller->start_time = apr_time_now();
    code = curl_easy_perform(t->curl);
    t->controller->finish_time = apr_time_now();
    aos_move_transport_state(t, TRANS_STATE_DONE);
    
    if ((code != CURLE_OK) && (t->controller->error_code == AOSE_OK)) {
        ecode = aos_curl_code_to_status(code);
        if (ecode != AOSE_OK) {
            t->controller->error_code = ecode;
            t->controller->reason = apr_pstrdup(t->pool, curl_easy_strerror(code));
            aos_error_log("transport failure curl code:%d error:%s", code, t->controller->reason);
        }
    }
    
    aos_curl_transport_finish(t);
    
    return t->controller->error_code;
}
Beispiel #3
0
size_t aos_curl_default_write_callback(char *ptr, size_t size, size_t nmemb, void *userdata)
{
    int len;
    int bytes;
    aos_curl_http_transport_t *t;

    t = (aos_curl_http_transport_t *)(userdata);
    len = size * nmemb;

    if (t->controller->first_byte_time == 0) {
        t->controller->first_byte_time = apr_time_now();
    }
    
    aos_curl_transport_headers_done(t);

    if (t->controller->error_code != AOSE_OK) {
        aos_debug_log("write callback abort");
        return 0;
    }

    // On HTTP error, we expect to parse an HTTP error response    
    if (t->resp->status < 200 || t->resp->status > 299) {
        bytes = aos_write_http_body_memory(t->resp, ptr, len);
        assert(bytes == len);
        aos_move_transport_state(t, TRANS_STATE_BODY_IN);
        return bytes;
    }

    if (t->resp->type == BODY_IN_MEMORY && t->resp->body_len >= (int64_t)t->controller->options->max_memory_size) {
        t->controller->reason = apr_psprintf(t->pool,
             "receive body too big, current body size: %" APR_INT64_T_FMT ", max memory size: %" APR_INT64_T_FMT,
              t->resp->body_len, t->controller->options->max_memory_size);
        t->controller->error_code = AOSE_OVER_MEMORY;
        aos_error_log("error reason:%s, ", t->controller->reason);
        return 0;
    }

    if ((bytes = t->resp->write_body(t->resp, ptr, len)) < 0) {
        aos_debug_log("write body failure, %d.", bytes);
        t->controller->error_code = AOSE_WRITE_BODY_ERROR;
        t->controller->reason = "write body failure.";
        return 0;
    }
    
    aos_move_transport_state(t, TRANS_STATE_BODY_IN);
    
    return bytes;
}
Beispiel #4
0
int aos_parse_xml_body(aos_list_t *bc, xmlDoc **doc_, xmlNode **root)
{
    int res;
    aos_buf_t *b;    
    xmlDoc *doc;
    xmlParserCtxt *ctxt;
    *root = NULL;

    ctxt = xmlCreatePushParserCtxt(NULL, NULL, NULL, 0, NULL);
    if (ctxt == NULL) {
        aos_error_log("Failed to create parser context.");
        return AOSE_INTERNAL_ERROR;
    }

    aos_list_for_each_entry(b, bc, node) {
        xmlParseChunk(ctxt, (char *)b->pos, aos_buf_size(b), 0);
    }
Beispiel #5
0
int oss_init_read_response_body_to_file(aos_pool_t *p, 
                                        const aos_string_t *filename, 
                                        aos_http_response_t *resp)
{
    int res = AOSE_OK;
    aos_file_buf_t *fb = aos_create_file_buf(p);
    res = aos_open_file_for_write(p, filename->data, fb);
    if (res != AOSE_OK) {
        aos_error_log("Open write file fail, filename:%s\n", filename->data);
        return res;
    }
    resp->file_path = filename->data;
    resp->file_buf = fb;
    resp->write_body = aos_write_http_body_file;
    resp->type = BODY_IN_FILE;

    return res;
}
Beispiel #6
0
int oss_write_request_body_from_file(aos_pool_t *p, 
                                     const aos_string_t *filename, 
                                     aos_http_request_t *req)
{
    int res = AOSE_OK;
    aos_file_buf_t *fb = aos_create_file_buf(p);
    res = aos_open_file_for_all_read(p, filename->data, fb);
    if (res != AOSE_OK) {
        aos_error_log("Open read file fail, filename:%s\n", filename->data);
        return res;
    }

    req->body_len = fb->file_last;
    req->file_path = filename->data;
    req->file_buf = fb;
    req->type = BODY_IN_FILE;
    req->read_body = aos_read_http_body_file;

    return res;
}
Beispiel #7
0
int oss_write_request_body_from_upload_file(aos_pool_t *p, 
                                            oss_upload_file_t *upload_file, 
                                            aos_http_request_t *req)
{
    int res = AOSE_OK;
    aos_file_buf_t *fb = aos_create_file_buf(p);
    res = aos_open_file_for_range_read(p, upload_file->filename.data, 
            upload_file->file_pos, upload_file->file_last, fb);
    if (res != AOSE_OK) {
        aos_error_log("Open read file fail, filename:%s\n", 
                      upload_file->filename.data);
        return res;
    }

    req->body_len = fb->file_last - fb->file_pos;
    req->file_path = upload_file->filename.data;
    req->file_buf = fb;
    req->type = BODY_IN_FILE;
    req->read_body = aos_read_http_body_file;

    return res;
}