Skip to content

Commit

Permalink
add set_md5
Browse files Browse the repository at this point in the history
  • Loading branch information
shrimp committed Jul 7, 2010
1 parent b3fb207 commit 70f4970
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 4 deletions.
3 changes: 1 addition & 2 deletions config
Expand Up @@ -2,5 +2,4 @@ ngx_addon_name=ngx_http_set_misc_module
HTTP_AUX_FILTER_MODULES="$HTTP_AUX_FILTER_MODULES ngx_http_set_misc_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/src/ngx_http_set_base32.c $ngx_addon_dir/src/ngx_http_set_default_value.c $ngx_addon_dir/src/ngx_http_set_hashed_upstream.c $ngx_addon_dir/src/ngx_http_set_quote_sql.c $ngx_addon_dir/src/ngx_http_set_unescape_uri.c $ngx_addon_dir/src/ngx_http_set_misc_module.c $ngx_addon_dir/src/ngx_http_set_escape_uri.c $ngx_addon_dir/src/ngx_http_set_hash.c $ngx_addon_dir/src/ngx_http_set_local_today.c"
NGX_ADDON_DEPS="$NGX_ADDON_DEPS $ngx_addon_dir/src/ddebug.h $ngx_addon_dir/src/ngx_http_set_default_value.h $ngx_addon_dir/src/ngx_http_set_hashed_upstream.h $ngx_addon_dir/src/ngx_http_set_quote_sql.h $ngx_addon_dir/src/ngx_http_set_unescape_uri.h $ngx_addon_dir/src/ngx_http_set_escape_uri.h $ngx_addon_dir/src/ngx_http_set_hash.h $ngx_addon_dir/src/ngx_http_set_local_today.h"
CFLAGS="$CFLAGS -DNGX_HAVE_OPENSSL_MD5_H -DNGX_HAVE_OPENSSL_SHA1_H -DNDK_SET_VAR -DNDK_HASH -DNDK_SHA1 -DNDK_UPSTREAM_LIST"

CFLAGS="$CFLAGS -DNGX_HAVE_OPENSSL_MD5_H -DNGX_HAVE_OPENSSL_SHA1_H -DNDK_SET_VAR -DNDK_HASH -DNDK_SHA1 -DNDK_UPSTREAM_LIST -DNDK_MD5"
17 changes: 17 additions & 0 deletions src/ngx_http_set_hash.c
Expand Up @@ -24,3 +24,20 @@ ngx_http_set_misc_set_sha1(ngx_http_request_t *r,
return NGX_OK;
}

ngx_int_t
ngx_http_set_misc_set_md5(ngx_http_request_t *r,
ngx_str_t *res, ngx_http_variable_value_t *v)
{
u_char *p;
p = ngx_palloc(r->pool, MD5_DIGEST_LENGTH * 2);
if (p == NULL) {
return NGX_ERROR;
}

ndk_md5_lower_hash((char *) p, (char *) v->data, v->len);

res->data = p;
res->len = MD5_DIGEST_LENGTH * 2;

return NGX_OK;
}
3 changes: 3 additions & 0 deletions src/ngx_http_set_hash.h
Expand Up @@ -11,5 +11,8 @@ ngx_int_t ngx_http_set_misc_set_sha1(ngx_http_request_t *r,
ngx_str_t *res, ngx_http_variable_value_t *v);


ngx_int_t ngx_http_set_misc_set_md5(ngx_http_request_t *r,
ngx_str_t *res, ngx_http_variable_value_t *v);

#endif /* NGX_HTTP_SET_HASH_H */

15 changes: 15 additions & 0 deletions src/ngx_http_set_misc_module.c
Expand Up @@ -13,6 +13,13 @@

#define NGX_UNESCAPE_URI_COMPONENT 0

static ndk_set_var_t ngx_http_set_misc_set_md5_filter = {
NDK_SET_VAR_VALUE,
ngx_http_set_misc_set_md5,
1,
NULL
};

static ndk_set_var_t ngx_http_set_misc_set_sha1_filter = {
NDK_SET_VAR_VALUE,
ngx_http_set_misc_set_sha1,
Expand Down Expand Up @@ -63,6 +70,14 @@ static ndk_set_var_t ngx_http_set_misc_local_today_filter = {
};

static ngx_command_t ngx_http_set_misc_commands[] = {
{ ngx_string ("set_md5"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF
|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF|NGX_CONF_TAKE12,
ndk_set_var_value,
0,
0,
&ngx_http_set_misc_set_md5_filter
},
{
ngx_string ("set_sha1"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF
Expand Down
4 changes: 2 additions & 2 deletions test/lib/Test/Nginx/Util.pm
Expand Up @@ -487,7 +487,7 @@ start_nginx:

}
#warn "sleeping";
sleep 1;
sleep 2;
} else {
if (system($cmd) != 0) {
Test::More::BAIL_OUT("$name - Cannot start nginx using command \"$cmd\".");
Expand Down Expand Up @@ -534,7 +534,7 @@ start_nginx:
if (kill(SIGQUIT, $pid) == 0) { # send quit signal
warn("$name - Failed to send quit signal to the nginx process with PID $pid");
}
sleep 1;
sleep 2;
if (-f $PidFile) {
#warn "killing with force (valgrind or profile)...\n";
kill(SIGKILL, $pid);
Expand Down
41 changes: 41 additions & 0 deletions test/t/hash.t
Expand Up @@ -53,3 +53,44 @@ GET /sha1
--- response_body
da39a3ee5e6b4b0d3255bfef95601890afd80709
=== TEST 4: md5 hello (copy)
--- config
location /md5 {
set_md5 $a hello;
echo $a;
}
--- request
GET /md5
--- response_body
5d41402abc4b2a76b9719d911017c592
=== TEST 5: md5 hello (in-place)
--- config
location /md5 {
set $a hello;
set_md5 $a;
echo $a;
}
--- request
GET /md5
--- response_body
5d41402abc4b2a76b9719d911017c592
=== TEST 6: md5 (empty)
--- config
location /md5 {
set_md5 $a "";
echo $a;
}
--- request
GET /md5
--- response_body
d41d8cd98f00b204e9800998ecf8427e

0 comments on commit 70f4970

Please sign in to comment.