void init_unicorn_httpdate(void) { VALUE mod = rb_const_get(rb_cObject, rb_intern("Unicorn")); mod = rb_define_module_under(mod, "HttpResponse"); buf = rb_str_new(0, buf_capa - 1); rb_global_variable(&buf); buf_ptr = RSTRING_PTR(buf); httpdate(Qnil); rb_define_method(mod, "httpdate", httpdate, 0); }
Datum s3test(PG_FUNCTION_ARGS) { CURL *curl; StringInfoData buf; int sc; char *url; char tmp[1024]; struct curl_slist *slist; char *datestring; char *signature; char *bucket = "umitanuki-dbtest"; char *file = "1.txt"; char *host = "s3-ap-northeast-1.amazonaws.com"; char *accesskey = ""; char *secretkey = ""; url = text_to_cstring(PG_GETARG_TEXT_P(0)); url = palloc0(1024); snprintf(url, 1024, "http://%s/%s/%s", host, bucket, file); datestring = httpdate(NULL); signature = s3_signature("GET", datestring, bucket, file, secretkey); slist = NULL; snprintf(tmp, sizeof(tmp), "Date: %s", datestring); slist = curl_slist_append(slist, tmp); snprintf(tmp, sizeof(tmp), "Authorization: AWS %s:%s", accesskey, signature); slist = curl_slist_append(slist, tmp); initStringInfo(&buf); curl = curl_easy_init(); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data_to_buf); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buf); sc = curl_easy_perform(curl); curl_easy_cleanup(curl); PG_RETURN_TEXT_P(cstring_to_text(buf.data)); }