Commit 32ab35f6 authored by Deomid Ryabkov's avatar Deomid Ryabkov Committed by Sergey Lyubka

Rename hmac_sha1 -> cs_hmac_sha1

    PUBLISHED_FROM=3d4fbd8192d04add406e304b113ce5ec0b1c1165
parent 8ab96ec7
......@@ -12,7 +12,7 @@ static struct mg_serve_http_opts s_http_server_opts;
static void send_error_result(struct mg_connection *nc, const char *msg) {
mg_printf_http_chunk(nc, "Error: %s", msg);
mg_send_http_chunk(nc, "", 0); /* Send empty chunk, the end of response */
mg_send_http_chunk(nc, "", 0); /* Send empty chunk, the end of response */
}
static void link_conns(struct mg_connection *nc1, struct mg_connection *nc2) {
......@@ -36,7 +36,7 @@ static void s3_handler(struct mg_connection *nc, int ev, void *ev_data) {
switch (ev) {
case NS_HTTP_REPLY:
if (nc2 != NULL) {
mg_printf_http_chunk(nc2, "Error: %.*s", (int)hm->message.len,
mg_printf_http_chunk(nc2, "Error: %.*s", (int) hm->message.len,
hm->message.p);
mg_send_http_chunk(nc2, "", 0);
}
......@@ -74,8 +74,9 @@ static void send_s3_request(struct mg_connection *nc, const char *file_name,
/* Prepare S3 authorization header */
snprintf(to_sign, sizeof(to_sign), "%s\n\n%s\n%s\n/%s/%s", method,
content_type, date, bucket, file_name);
hmac_sha1((unsigned char *)s_secret_access_key, strlen(s_secret_access_key),
(unsigned char *)to_sign, strlen(to_sign), (unsigned char *)sha1);
cs_hmac_sha1((unsigned char *) s_secret_access_key,
strlen(s_secret_access_key), (unsigned char *) to_sign,
strlen(to_sign), (unsigned char *) sha1);
mg_base64_encode((unsigned char *) sha1, sizeof(sha1), signature);
snprintf(req, sizeof(req),
"%s /%s HTTP/1.1\r\n"
......@@ -86,7 +87,7 @@ static void send_s3_request(struct mg_connection *nc, const char *file_name,
"Authorization: AWS %s:%s\r\n"
"\r\n",
method, file_name, bucket, host, date, content_type,
(unsigned long)strlen(file_data), s_access_key_id, signature);
(unsigned long) strlen(file_data), s_access_key_id, signature);
mg_printf(s3_conn, "%s%s", req, file_data);
/* S3 request sent, wait for a reply */
}
......@@ -119,9 +120,9 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
switch (ev) {
case NS_HTTP_REQUEST:
if (mg_vcmp(&hm->uri, "/upload") == 0) {
handle_api_call(nc, hm); /* Handle RESTful call */
handle_api_call(nc, hm); /* Handle RESTful call */
} else {
mg_serve_http(nc, hm, s_http_server_opts); /* Serve static content */
mg_serve_http(nc, hm, s_http_server_opts); /* Serve static content */
}
break;
case NS_CLOSE:
......@@ -146,7 +147,7 @@ int main(int argc, char *argv[]) {
/* Use current binary directory as document root */
if (argc > 0 && ((cp = strrchr(argv[0], '/')) != NULL ||
(cp = strrchr(argv[0], '/')) != NULL)) {
(cp = strrchr(argv[0], '/')) != NULL)) {
*cp = '\0';
s_http_server_opts.document_root = argv[0];
}
......@@ -165,8 +166,10 @@ int main(int argc, char *argv[]) {
}
if (s_access_key_id == NULL || s_secret_access_key == NULL) {
fprintf(stderr, "Usage: %s -a access_key_id -s s_secret_access_key "
"[-p port] [-D hexdump_file]\n", argv[0]);
fprintf(stderr,
"Usage: %s -a access_key_id -s s_secret_access_key "
"[-p port] [-D hexdump_file]\n",
argv[0]);
exit(1);
}
......
......@@ -415,9 +415,9 @@ void cs_sha1_final(unsigned char digest[20], cs_sha1_ctx *context) {
memset(&finalcount, '\0', sizeof(finalcount));
}
void hmac_sha1(const unsigned char *key, size_t keylen,
const unsigned char *data, size_t datalen,
unsigned char out[20]) {
void cs_hmac_sha1(const unsigned char *key, size_t keylen,
const unsigned char *data, size_t datalen,
unsigned char out[20]) {
cs_sha1_ctx ctx;
unsigned char buf1[64], buf2[64], tmp_key[20], i;
......
......@@ -362,9 +362,9 @@ typedef struct {
void cs_sha1_init(cs_sha1_ctx *);
void cs_sha1_update(cs_sha1_ctx *, const unsigned char *data, uint32_t len);
void cs_sha1_final(unsigned char digest[20], cs_sha1_ctx *);
void hmac_sha1(const unsigned char *key, size_t key_len,
const unsigned char *text, size_t text_len,
unsigned char out[20]);
void cs_hmac_sha1(const unsigned char *key, size_t key_len,
const unsigned char *text, size_t text_len,
unsigned char out[20]);
#ifdef __cplusplus
}
#endif /* __cplusplus */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment