Welcome! Log In Create A New Profile

Advanced

[PATCH] Core: parse octal/hexadecimal numeric config directives

Ari Aosved
November 07, 2014 04:20PM
# HG changeset patch
# User Ari Aosved <ari.aosved@gmail.com>
# Date 1415392382 28800
# Fri Nov 07 12:33:02 2014 -0800
# Node ID 742fb1a59b705ba71f2bab5fede58ff5885ebc71
# Parent 234c5ecb00c04c67bcbb4a3be45fd844f2289462
Core: parse octal/hexadecimal numeric config directives.

When working with modules which need configuration directives dealing with
file modes, it's convenient to specify the numeric values in octal notation.
For instance "hls_directory_create_mode 0775;" is recognizably rwxrwxr-x
whereas "hls_directory_create_mode 509;" would be more prone to mistakes.

diff -r 234c5ecb00c0 -r 742fb1a59b70 src/core/ngx_conf_file.c
--- a/src/core/ngx_conf_file.c Fri Nov 07 17:38:55 2014 +0300
+++ b/src/core/ngx_conf_file.c Fri Nov 07 12:33:02 2014 -0800
@@ -1097,7 +1097,16 @@
}

value = cf->args->elts;
- *np = ngx_atoi(value[1].data, value[1].len);
+ if (value[1].len > 2 && *value[1].data == '0' && *value[1].data+1 == 'x') {
+ *np = ngx_hextoi(value[1].data+2, value[1].len - 2);
+ }
+ else
+ if (value[1].len > 1 && *value[1].data == '0') {
+ *np = ngx_octtoi(value[1].data+1, value[1].len - 1);
+ }
+ else {
+ *np = ngx_atoi(value[1].data, value[1].len);
+ }
if (*np == NGX_ERROR) {
return "invalid number";
}
diff -r 234c5ecb00c0 -r 742fb1a59b70 src/core/ngx_string.c
--- a/src/core/ngx_string.c Fri Nov 07 17:38:55 2014 +0300
+++ b/src/core/ngx_string.c Fri Nov 07 12:33:02 2014 -0800
@@ -1085,6 +1085,36 @@
}


+ngx_int_t
+ngx_octtoi(u_char *line, size_t n)
+{
+ u_char ch;
+ ngx_int_t value;
+
+ if (n == 0) {
+ return NGX_ERROR;
+ }
+
+ for (value = 0; n--; line++) {
+ ch = *line;
+
+ if (ch >= '0' && ch <= '7') {
+ value = value * 8 + (ch - '0');
+ continue;
+ }
+
+ return NGX_ERROR;
+ }
+
+ if (value < 0) {
+ return NGX_ERROR;
+
+ } else {
+ return value;
+ }
+}
+
+
u_char *
ngx_hex_dump(u_char *dst, u_char *src, size_t len)
{
diff -r 234c5ecb00c0 -r 742fb1a59b70 src/core/ngx_string.h
--- a/src/core/ngx_string.h Fri Nov 07 17:38:55 2014 +0300
+++ b/src/core/ngx_string.h Fri Nov 07 12:33:02 2014 -0800
@@ -175,6 +175,7 @@
off_t ngx_atoof(u_char *line, size_t n);
time_t ngx_atotm(u_char *line, size_t n);
ngx_int_t ngx_hextoi(u_char *line, size_t n);
+ngx_int_t ngx_octtoi(u_char *line, size_t n);

u_char *ngx_hex_dump(u_char *dst, u_char *src, size_t len);


_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH] Core: parse octal/hexadecimal numeric config directives

Ari Aosved 636 November 07, 2014 04:20PM

Re: [PATCH] Core: parse octal/hexadecimal numeric config directives

Maxim Dounin 282 November 10, 2014 10:24AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 308
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready