Line data Source code
1 : #ifndef DDEBUG
2 : #define DDEBUG 0
3 : #endif
4 : #include "ddebug.h"
5 :
6 : #include "ngx_http_set_hash.h"
7 :
8 : #if NGX_HAVE_SHA1
9 : #include "ngx_sha1.h"
10 :
11 : #ifndef SHA_DIGEST_LENGTH
12 : #define SHA_DIGEST_LENGTH 20
13 : #endif
14 :
15 : #endif
16 :
17 : #include "ngx_md5.h"
18 :
19 :
20 : #ifndef MD5_DIGEST_LENGTH
21 : #define MD5_DIGEST_LENGTH 16
22 : #endif
23 :
24 : enum {
25 : #if NGX_HAVE_SHA1
26 : SHA_HEX_LENGTH = SHA_DIGEST_LENGTH * 2,
27 : #endif
28 : MD5_HEX_LENGTH = MD5_DIGEST_LENGTH * 2
29 : };
30 :
31 :
32 : #if NGX_HAVE_SHA1
33 : ngx_int_t
34 0 : ngx_http_set_misc_set_sha1(ngx_http_request_t *r, ngx_str_t *res,
35 : ngx_http_variable_value_t *v)
36 : {
37 : u_char *p;
38 : ngx_sha1_t sha;
39 : u_char sha_buf[SHA_DIGEST_LENGTH];
40 :
41 0 : p = ngx_palloc(r->pool, SHA_HEX_LENGTH);
42 0 : if (p == NULL) {
43 0 : return NGX_ERROR;
44 : }
45 :
46 0 : ngx_sha1_init(&sha);
47 0 : ngx_sha1_update(&sha, v->data, v->len);
48 0 : ngx_sha1_final(sha_buf, &sha);
49 :
50 0 : ngx_hex_dump(p, sha_buf, sizeof(sha_buf));
51 :
52 0 : res->data = p;
53 0 : res->len = SHA_HEX_LENGTH;
54 :
55 0 : return NGX_OK;
56 : }
57 : #endif
58 :
59 :
60 : ngx_int_t
61 0 : ngx_http_set_misc_set_md5(ngx_http_request_t *r, ngx_str_t *res,
62 : ngx_http_variable_value_t *v)
63 : {
64 : u_char *p;
65 : ngx_md5_t md5;
66 : u_char md5_buf[MD5_DIGEST_LENGTH];
67 :
68 0 : p = ngx_palloc(r->pool, MD5_HEX_LENGTH);
69 0 : if (p == NULL) {
70 0 : return NGX_ERROR;
71 : }
72 :
73 0 : ngx_md5_init(&md5);
74 0 : ngx_md5_update(&md5, v->data, v->len);
75 0 : ngx_md5_final(md5_buf, &md5);
76 :
77 0 : ngx_hex_dump(p, md5_buf, sizeof(md5_buf));
78 :
79 0 : res->data = p;
80 0 : res->len = MD5_HEX_LENGTH;
81 :
82 0 : return NGX_OK;
83 : }
|