Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 72 lines (60 sloc) 1.64 kB
5a12a3d adding multipart/form-data handler
David J. Goehrig authored
1 // amazon.c
2 //
3 // Copyright (C) 2007 David J. Goehrig
4 // All Rights Reserved
5 //
6
7 #include "include.h"
8 #include "defines.h"
9 #include "alloc.h"
10 #include "str.h"
2f824da a bunch of changes
David J. Goehrig authored
11 #include "log.h"
5a12a3d adding multipart/form-data handler
David J. Goehrig authored
12 #include "files.h"
13 #include "dates.h"
2f824da a bunch of changes
David J. Goehrig authored
14 #include "sockets.h"
15 #include "server.h"
16 #include "requests.h"
17 #include "events.h"
18 #include "wand.h"
c10647f Fixed many issues regarding post
David J. Goehrig authored
19 #include "auth.h"
2f824da a bunch of changes
David J. Goehrig authored
20 #include "amazon.h"
5a12a3d adding multipart/form-data handler
David J. Goehrig authored
21
c10647f Fixed many issues regarding post
David J. Goehrig authored
22 str s3_key;
23 str s3_secret;
5a12a3d adding multipart/form-data handler
David J. Goehrig authored
24
c10647f Fixed many issues regarding post
David J. Goehrig authored
25 void
26 s3_auth(str key, str secret)
5a12a3d adding multipart/form-data handler
David J. Goehrig authored
27 {
c10647f Fixed many issues regarding post
David J. Goehrig authored
28 s3_key = key;
29 s3_secret = secret;
5a12a3d adding multipart/form-data handler
David J. Goehrig authored
30 }
31
32 str
2f824da a bunch of changes
David J. Goehrig authored
33 s3_put_auth_string(str verb, str mime, str date, str bucket, str filename)
5a12a3d adding multipart/form-data handler
David J. Goehrig authored
34 {
06eaeaa Added usage metrics for all requests and added a request_info functio…
David J. Goehrig authored
35 str sts = Str("%s\n\n\%s\n%s\nx-amz-acl:public-read\n/%s/%s",verb,mime,date,bucket,filename);
2f824da a bunch of changes
David J. Goehrig authored
36 debug("STS is %s",sts);
c10647f Fixed many issues regarding post
David J. Goehrig authored
37 return Str("AWS %s:%s",s3_key,base64(hmac1(s3_secret,sts)));
5a12a3d adding multipart/form-data handler
David J. Goehrig authored
38 }
39
b7cfb85 fixed the amazon upload process, amazon uploads now support callbacks!
David Goehrig authored
40 void
41 s3_put(str file, str bucket, str filename, str mime, str callback)
5a12a3d adding multipart/form-data handler
David J. Goehrig authored
42 {
b7cfb85 fixed the amazon upload process, amazon uploads now support callbacks!
David Goehrig authored
43 debug("S3 PUT");
06eaeaa Added usage metrics for all requests and added a request_info functio…
David J. Goehrig authored
44 File fc = load(file);
45 debug("Loaded file %s", file);
6447ba6 don't quite remember
David Goehrig authored
46 debug("MIME is %s",mime);
5a12a3d adding multipart/form-data handler
David J. Goehrig authored
47 str date = Date();
2f824da a bunch of changes
David J. Goehrig authored
48 debug("Date is %s",date);
49 str md5 = base64(md5sum(fc->data,fc->st.st_size));
50 debug("MD5 is %s",md5);
06eaeaa Added usage metrics for all requests and added a request_info functio…
David J. Goehrig authored
51 str auth = s3_put_auth_string(Str("PUT"),mime,date,bucket,filename);
2f824da a bunch of changes
David J. Goehrig authored
52 debug("AUTH is %s", auth);
53 str size = Str("%i",fc->st.st_size);
54 debug("Size is %s",size);
6447ba6 don't quite remember
David Goehrig authored
55
b7cfb85 fixed the amazon upload process, amazon uploads now support callbacks!
David Goehrig authored
56 Request req = new_request(Str("PUT"), Str("%s.s3.amazonaws.com",bucket),Str("/%s",filename));
57
58 request_headers(req,Str("x-amz-acl"),Str("public-read"));
59 request_headers(req,Str("Content-Type"),mime);
60 request_headers(req,Str("Content-Length"),size);
61 request_headers(req,Str("Date"),date);
62 request_headers(req,Str("Authorization"),auth);
63
64 request_file(req,fc);
65
66 request_callback(req,Resp,callback);
67
68 send_request(req);
69
70 debug("S3 PUT DONE");
6447ba6 don't quite remember
David Goehrig authored
71 }
Something went wrong with that request. Please try again.