Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
ebdf973a
Commit
ebdf973a
authored
Nov 23, 2013
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log_access() moved to log.c
parent
71dd7a96
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
119 additions
and
117 deletions
+119
-117
Makefile
build/Makefile
+1
-1
log.c
build/src/log.c
+44
-0
mongoose.c
build/src/mongoose.c
+0
-58
util.c
build/src/util.c
+15
-0
mongoose.c
mongoose.c
+59
-58
No files found.
build/Makefile
View file @
ebdf973a
...
@@ -29,7 +29,7 @@ VERSION = $(shell perl -lne \
...
@@ -29,7 +29,7 @@ VERSION = $(shell perl -lne \
SOURCES
=
src/internal.h src/util.c src/string.c src/parse_date.c
\
SOURCES
=
src/internal.h src/util.c src/string.c src/parse_date.c
\
src/options.c src/crypto.c src/auth.c src/win32.c src/unix.c
\
src/options.c src/crypto.c src/auth.c src/win32.c src/unix.c
\
src/mg_printf.c src/ssl.c src/http_client.c src/mime.c
\
src/mg_printf.c src/ssl.c src/http_client.c src/mime.c
\
src/directory.c src/mongoose.c src/lua.c
src/directory.c src/
log.c src/
mongoose.c src/lua.c
TINY_SOURCES
=
../mongoose.c main.c
TINY_SOURCES
=
../mongoose.c main.c
LUA_SOURCES
=
$(TINY_SOURCES)
sqlite3.c lsqlite3.c lua_5.2.1.c
LUA_SOURCES
=
$(TINY_SOURCES)
sqlite3.c lsqlite3.c lua_5.2.1.c
...
...
build/src/log.c
0 → 100644
View file @
ebdf973a
#include "internal.h"
static
void
log_header
(
const
struct
mg_connection
*
conn
,
const
char
*
header
,
FILE
*
fp
)
{
const
char
*
header_value
;
if
((
header_value
=
mg_get_header
(
conn
,
header
))
==
NULL
)
{
(
void
)
fprintf
(
fp
,
"%s"
,
" -"
);
}
else
{
(
void
)
fprintf
(
fp
,
"
\"
%s
\"
"
,
header_value
);
}
}
static
void
log_access
(
const
struct
mg_connection
*
conn
)
{
const
struct
mg_request_info
*
ri
;
FILE
*
fp
;
char
date
[
64
],
src_addr
[
IP_ADDR_STR_LEN
];
fp
=
conn
->
ctx
->
config
[
ACCESS_LOG_FILE
]
==
NULL
?
NULL
:
fopen
(
conn
->
ctx
->
config
[
ACCESS_LOG_FILE
],
"a+"
);
if
(
fp
==
NULL
)
return
;
strftime
(
date
,
sizeof
(
date
),
"%d/%b/%Y:%H:%M:%S %z"
,
localtime
(
&
conn
->
birth_time
));
ri
=
&
conn
->
request_info
;
flockfile
(
fp
);
sockaddr_to_string
(
src_addr
,
sizeof
(
src_addr
),
&
conn
->
client
.
rsa
);
fprintf
(
fp
,
"%s - %s [%s]
\"
%s %s HTTP/%s
\"
%d %"
INT64_FMT
,
src_addr
,
ri
->
remote_user
==
NULL
?
"-"
:
ri
->
remote_user
,
date
,
ri
->
request_method
?
ri
->
request_method
:
"-"
,
ri
->
uri
?
ri
->
uri
:
"-"
,
ri
->
http_version
,
conn
->
status_code
,
conn
->
num_bytes_sent
);
log_header
(
conn
,
"Referer"
,
fp
);
log_header
(
conn
,
"User-Agent"
,
fp
);
fputc
(
'\n'
,
fp
);
fflush
(
fp
);
funlockfile
(
fp
);
fclose
(
fp
);
}
build/src/mongoose.c
View file @
ebdf973a
...
@@ -28,21 +28,6 @@ static FILE *mg_fopen(const char *path, const char *mode) {
...
@@ -28,21 +28,6 @@ static FILE *mg_fopen(const char *path, const char *mode) {
#endif
#endif
}
}
static
void
sockaddr_to_string
(
char
*
buf
,
size_t
len
,
const
union
usa
*
usa
)
{
buf
[
0
]
=
'\0'
;
#if defined(USE_IPV6)
inet_ntop
(
usa
->
sa
.
sa_family
,
usa
->
sa
.
sa_family
==
AF_INET
?
(
void
*
)
&
usa
->
sin
.
sin_addr
:
(
void
*
)
&
usa
->
sin6
.
sin6_addr
,
buf
,
len
);
#elif defined(_WIN32)
// Only Windoze Vista (and newer) have inet_ntop()
strncpy
(
buf
,
inet_ntoa
(
usa
->
sin
.
sin_addr
),
len
);
#else
inet_ntop
(
usa
->
sa
.
sa_family
,
(
void
*
)
&
usa
->
sin
.
sin_addr
,
buf
,
len
);
#endif
}
// Print error message to the opened error log stream.
// Print error message to the opened error log stream.
static
void
cry
(
struct
mg_connection
*
conn
,
const
char
*
fmt
,
...)
{
static
void
cry
(
struct
mg_connection
*
conn
,
const
char
*
fmt
,
...)
{
char
buf
[
MG_BUF_LEN
],
src_addr
[
IP_ADDR_STR_LEN
];
char
buf
[
MG_BUF_LEN
],
src_addr
[
IP_ADDR_STR_LEN
];
...
@@ -2122,49 +2107,6 @@ static int set_ports_option(struct mg_context *ctx) {
...
@@ -2122,49 +2107,6 @@ static int set_ports_option(struct mg_context *ctx) {
return
success
;
return
success
;
}
}
static
void
log_header
(
const
struct
mg_connection
*
conn
,
const
char
*
header
,
FILE
*
fp
)
{
const
char
*
header_value
;
if
((
header_value
=
mg_get_header
(
conn
,
header
))
==
NULL
)
{
(
void
)
fprintf
(
fp
,
"%s"
,
" -"
);
}
else
{
(
void
)
fprintf
(
fp
,
"
\"
%s
\"
"
,
header_value
);
}
}
static
void
log_access
(
const
struct
mg_connection
*
conn
)
{
const
struct
mg_request_info
*
ri
;
FILE
*
fp
;
char
date
[
64
],
src_addr
[
IP_ADDR_STR_LEN
];
fp
=
conn
->
ctx
->
config
[
ACCESS_LOG_FILE
]
==
NULL
?
NULL
:
fopen
(
conn
->
ctx
->
config
[
ACCESS_LOG_FILE
],
"a+"
);
if
(
fp
==
NULL
)
return
;
strftime
(
date
,
sizeof
(
date
),
"%d/%b/%Y:%H:%M:%S %z"
,
localtime
(
&
conn
->
birth_time
));
ri
=
&
conn
->
request_info
;
flockfile
(
fp
);
sockaddr_to_string
(
src_addr
,
sizeof
(
src_addr
),
&
conn
->
client
.
rsa
);
fprintf
(
fp
,
"%s - %s [%s]
\"
%s %s HTTP/%s
\"
%d %"
INT64_FMT
,
src_addr
,
ri
->
remote_user
==
NULL
?
"-"
:
ri
->
remote_user
,
date
,
ri
->
request_method
?
ri
->
request_method
:
"-"
,
ri
->
uri
?
ri
->
uri
:
"-"
,
ri
->
http_version
,
conn
->
status_code
,
conn
->
num_bytes_sent
);
log_header
(
conn
,
"Referer"
,
fp
);
log_header
(
conn
,
"User-Agent"
,
fp
);
fputc
(
'\n'
,
fp
);
fflush
(
fp
);
funlockfile
(
fp
);
fclose
(
fp
);
}
// Verify given socket address against the ACL.
// Verify given socket address against the ACL.
// Return -1 if ACL is malformed, 0 if address is disallowed, 1 if allowed.
// Return -1 if ACL is malformed, 0 if address is disallowed, 1 if allowed.
static
int
check_acl
(
struct
mg_context
*
ctx
,
uint32_t
remote_ip
)
{
static
int
check_acl
(
struct
mg_context
*
ctx
,
uint32_t
remote_ip
)
{
...
...
build/src/util.c
View file @
ebdf973a
...
@@ -9,3 +9,18 @@ static struct mg_connection *fc(struct mg_context *ctx) {
...
@@ -9,3 +9,18 @@ static struct mg_connection *fc(struct mg_context *ctx) {
fake_connection
.
event
.
user_data
=
ctx
->
user_data
;
fake_connection
.
event
.
user_data
=
ctx
->
user_data
;
return
&
fake_connection
;
return
&
fake_connection
;
}
}
static
void
sockaddr_to_string
(
char
*
buf
,
size_t
len
,
const
union
usa
*
usa
)
{
buf
[
0
]
=
'\0'
;
#if defined(USE_IPV6)
inet_ntop
(
usa
->
sa
.
sa_family
,
usa
->
sa
.
sa_family
==
AF_INET
?
(
void
*
)
&
usa
->
sin
.
sin_addr
:
(
void
*
)
&
usa
->
sin6
.
sin6_addr
,
buf
,
len
);
#elif defined(_WIN32)
// Only Windoze Vista (and newer) have inet_ntop()
strncpy
(
buf
,
inet_ntoa
(
usa
->
sin
.
sin_addr
),
len
);
#else
inet_ntop
(
usa
->
sa
.
sa_family
,
(
void
*
)
&
usa
->
sin
.
sin_addr
,
buf
,
len
);
#endif
}
mongoose.c
View file @
ebdf973a
...
@@ -480,6 +480,22 @@ static struct mg_connection *fc(struct mg_context *ctx) {
...
@@ -480,6 +480,22 @@ static struct mg_connection *fc(struct mg_context *ctx) {
return
&
fake_connection
;
return
&
fake_connection
;
}
}
static
void
sockaddr_to_string
(
char
*
buf
,
size_t
len
,
const
union
usa
*
usa
)
{
buf
[
0
]
=
'\0'
;
#if defined(USE_IPV6)
inet_ntop
(
usa
->
sa
.
sa_family
,
usa
->
sa
.
sa_family
==
AF_INET
?
(
void
*
)
&
usa
->
sin
.
sin_addr
:
(
void
*
)
&
usa
->
sin6
.
sin6_addr
,
buf
,
len
);
#elif defined(_WIN32)
// Only Windoze Vista (and newer) have inet_ntop()
strncpy
(
buf
,
inet_ntoa
(
usa
->
sin
.
sin_addr
),
len
);
#else
inet_ntop
(
usa
->
sa
.
sa_family
,
(
void
*
)
&
usa
->
sin
.
sin_addr
,
buf
,
len
);
#endif
}
static
void
mg_strlcpy
(
register
char
*
dst
,
register
const
char
*
src
,
size_t
n
)
{
static
void
mg_strlcpy
(
register
char
*
dst
,
register
const
char
*
src
,
size_t
n
)
{
for
(;
*
src
!=
'\0'
&&
n
>
1
;
n
--
)
{
for
(;
*
src
!=
'\0'
&&
n
>
1
;
n
--
)
{
*
dst
++
=
*
src
++
;
*
dst
++
=
*
src
++
;
...
@@ -2594,6 +2610,49 @@ static void handle_directory_request(struct mg_connection *conn,
...
@@ -2594,6 +2610,49 @@ static void handle_directory_request(struct mg_connection *conn,
}
}
static
void
log_header
(
const
struct
mg_connection
*
conn
,
const
char
*
header
,
FILE
*
fp
)
{
const
char
*
header_value
;
if
((
header_value
=
mg_get_header
(
conn
,
header
))
==
NULL
)
{
(
void
)
fprintf
(
fp
,
"%s"
,
" -"
);
}
else
{
(
void
)
fprintf
(
fp
,
"
\"
%s
\"
"
,
header_value
);
}
}
static
void
log_access
(
const
struct
mg_connection
*
conn
)
{
const
struct
mg_request_info
*
ri
;
FILE
*
fp
;
char
date
[
64
],
src_addr
[
IP_ADDR_STR_LEN
];
fp
=
conn
->
ctx
->
config
[
ACCESS_LOG_FILE
]
==
NULL
?
NULL
:
fopen
(
conn
->
ctx
->
config
[
ACCESS_LOG_FILE
],
"a+"
);
if
(
fp
==
NULL
)
return
;
strftime
(
date
,
sizeof
(
date
),
"%d/%b/%Y:%H:%M:%S %z"
,
localtime
(
&
conn
->
birth_time
));
ri
=
&
conn
->
request_info
;
flockfile
(
fp
);
sockaddr_to_string
(
src_addr
,
sizeof
(
src_addr
),
&
conn
->
client
.
rsa
);
fprintf
(
fp
,
"%s - %s [%s]
\"
%s %s HTTP/%s
\"
%d %"
INT64_FMT
,
src_addr
,
ri
->
remote_user
==
NULL
?
"-"
:
ri
->
remote_user
,
date
,
ri
->
request_method
?
ri
->
request_method
:
"-"
,
ri
->
uri
?
ri
->
uri
:
"-"
,
ri
->
http_version
,
conn
->
status_code
,
conn
->
num_bytes_sent
);
log_header
(
conn
,
"Referer"
,
fp
);
log_header
(
conn
,
"User-Agent"
,
fp
);
fputc
(
'\n'
,
fp
);
fflush
(
fp
);
funlockfile
(
fp
);
fclose
(
fp
);
}
// Return number of bytes left to read for this connection
// Return number of bytes left to read for this connection
static
int64_t
left_to_read
(
const
struct
mg_connection
*
conn
)
{
static
int64_t
left_to_read
(
const
struct
mg_connection
*
conn
)
{
return
conn
->
content_len
+
conn
->
request_len
-
conn
->
num_bytes_read
;
return
conn
->
content_len
+
conn
->
request_len
-
conn
->
num_bytes_read
;
...
@@ -2622,21 +2681,6 @@ static FILE *mg_fopen(const char *path, const char *mode) {
...
@@ -2622,21 +2681,6 @@ static FILE *mg_fopen(const char *path, const char *mode) {
#endif
#endif
}
}
static
void
sockaddr_to_string
(
char
*
buf
,
size_t
len
,
const
union
usa
*
usa
)
{
buf
[
0
]
=
'\0'
;
#if defined(USE_IPV6)
inet_ntop
(
usa
->
sa
.
sa_family
,
usa
->
sa
.
sa_family
==
AF_INET
?
(
void
*
)
&
usa
->
sin
.
sin_addr
:
(
void
*
)
&
usa
->
sin6
.
sin6_addr
,
buf
,
len
);
#elif defined(_WIN32)
// Only Windoze Vista (and newer) have inet_ntop()
strncpy
(
buf
,
inet_ntoa
(
usa
->
sin
.
sin_addr
),
len
);
#else
inet_ntop
(
usa
->
sa
.
sa_family
,
(
void
*
)
&
usa
->
sin
.
sin_addr
,
buf
,
len
);
#endif
}
// Print error message to the opened error log stream.
// Print error message to the opened error log stream.
static
void
cry
(
struct
mg_connection
*
conn
,
const
char
*
fmt
,
...)
{
static
void
cry
(
struct
mg_connection
*
conn
,
const
char
*
fmt
,
...)
{
char
buf
[
MG_BUF_LEN
],
src_addr
[
IP_ADDR_STR_LEN
];
char
buf
[
MG_BUF_LEN
],
src_addr
[
IP_ADDR_STR_LEN
];
...
@@ -4716,49 +4760,6 @@ static int set_ports_option(struct mg_context *ctx) {
...
@@ -4716,49 +4760,6 @@ static int set_ports_option(struct mg_context *ctx) {
return
success
;
return
success
;
}
}
static
void
log_header
(
const
struct
mg_connection
*
conn
,
const
char
*
header
,
FILE
*
fp
)
{
const
char
*
header_value
;
if
((
header_value
=
mg_get_header
(
conn
,
header
))
==
NULL
)
{
(
void
)
fprintf
(
fp
,
"%s"
,
" -"
);
}
else
{
(
void
)
fprintf
(
fp
,
"
\"
%s
\"
"
,
header_value
);
}
}
static
void
log_access
(
const
struct
mg_connection
*
conn
)
{
const
struct
mg_request_info
*
ri
;
FILE
*
fp
;
char
date
[
64
],
src_addr
[
IP_ADDR_STR_LEN
];
fp
=
conn
->
ctx
->
config
[
ACCESS_LOG_FILE
]
==
NULL
?
NULL
:
fopen
(
conn
->
ctx
->
config
[
ACCESS_LOG_FILE
],
"a+"
);
if
(
fp
==
NULL
)
return
;
strftime
(
date
,
sizeof
(
date
),
"%d/%b/%Y:%H:%M:%S %z"
,
localtime
(
&
conn
->
birth_time
));
ri
=
&
conn
->
request_info
;
flockfile
(
fp
);
sockaddr_to_string
(
src_addr
,
sizeof
(
src_addr
),
&
conn
->
client
.
rsa
);
fprintf
(
fp
,
"%s - %s [%s]
\"
%s %s HTTP/%s
\"
%d %"
INT64_FMT
,
src_addr
,
ri
->
remote_user
==
NULL
?
"-"
:
ri
->
remote_user
,
date
,
ri
->
request_method
?
ri
->
request_method
:
"-"
,
ri
->
uri
?
ri
->
uri
:
"-"
,
ri
->
http_version
,
conn
->
status_code
,
conn
->
num_bytes_sent
);
log_header
(
conn
,
"Referer"
,
fp
);
log_header
(
conn
,
"User-Agent"
,
fp
);
fputc
(
'\n'
,
fp
);
fflush
(
fp
);
funlockfile
(
fp
);
fclose
(
fp
);
}
// Verify given socket address against the ACL.
// Verify given socket address against the ACL.
// Return -1 if ACL is malformed, 0 if address is disallowed, 1 if allowed.
// Return -1 if ACL is malformed, 0 if address is disallowed, 1 if allowed.
static
int
check_acl
(
struct
mg_context
*
ctx
,
uint32_t
remote_ip
)
{
static
int
check_acl
(
struct
mg_context
*
ctx
,
uint32_t
remote_ip
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment