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
5dc317fc
Commit
5dc317fc
authored
Feb 09, 2014
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added -DMONGOOSE_HEXDUMP feature
parent
fbd5d77c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
0 deletions
+54
-0
Embed.md
docs/Embed.md
+3
-0
mongoose.c
mongoose.c
+51
-0
No files found.
docs/Embed.md
View file @
5dc317fc
...
@@ -95,6 +95,9 @@ a couple of kilobytes to the executable size, and also has some runtime penalty.
...
@@ -95,6 +95,9 @@ a couple of kilobytes to the executable size, and also has some runtime penalty.
-DMONGOOSE_USE_STACK_SIZE=X Let mg_start_thread() use stack
-DMONGOOSE_USE_STACK_SIZE=X Let mg_start_thread() use stack
size X, default is OS default
size X, default is OS default
-DMONGOOSE_ENABLE_DEBUG Enables debug messages on stdout, very noisy
-DMONGOOSE_ENABLE_DEBUG Enables debug messages on stdout, very noisy
-DMONGOOSE_HEXDUMP=\"XXX\" Enables hexdump of sent and received traffic
to the text files. XXX must be a prefix of the
IP address whose traffic must be hexdumped.
Mongoose source code contains a well-commented example code, listed below:
Mongoose source code contains a well-commented example code, listed below:
...
...
mongoose.c
View file @
5dc317fc
...
@@ -2026,6 +2026,42 @@ static void callback_http_client_on_connect(struct connection *conn) {
...
@@ -2026,6 +2026,42 @@ static void callback_http_client_on_connect(struct connection *conn) {
}
}
}
}
#ifdef MONGOOSE_HEXDUMP
static
void
hexdump
(
const
struct
connection
*
conn
,
const
void
*
buf
,
int
len
,
const
char
*
marker
)
{
const
unsigned
char
*
p
=
(
const
unsigned
char
*
)
buf
;
char
path
[
MAX_PATH_SIZE
],
date
[
100
],
ascii
[
17
];
FILE
*
fp
;
snprintf
(
path
,
sizeof
(
path
),
"%s.%hu.txt"
,
conn
->
mg_conn
.
remote_ip
,
conn
->
mg_conn
.
remote_port
);
if
((
fp
=
fopen
(
path
,
"a"
))
!=
NULL
)
{
time_t
cur_time
=
time
(
NULL
);
int
i
,
idx
;
strftime
(
date
,
sizeof
(
date
),
"%d/%b/%Y %H:%M:%S"
,
localtime
(
&
cur_time
));
fprintf
(
fp
,
"%s %s %d bytes
\n
"
,
marker
,
date
,
len
);
for
(
i
=
0
;
i
<
len
;
i
++
)
{
idx
=
i
%
16
;
if
(
idx
==
0
)
{
if
(
i
>
0
)
fprintf
(
fp
,
" %s
\n
"
,
ascii
);
fprintf
(
fp
,
"%04x "
,
i
);
}
fprintf
(
fp
,
" %02x"
,
p
[
i
]);
ascii
[
idx
]
=
p
[
i
]
<
0x20
||
p
[
i
]
>
0x7e
?
'.'
:
p
[
i
];
ascii
[
idx
+
1
]
=
'\0'
;
}
while
(
i
++
%
16
)
fprintf
(
fp
,
"%s"
,
" "
);
fprintf
(
fp
,
" %s
\n\n
"
,
ascii
);
fclose
(
fp
);
}
}
#endif
static
void
write_to_socket
(
struct
connection
*
conn
)
{
static
void
write_to_socket
(
struct
connection
*
conn
)
{
struct
iobuf
*
io
=
&
conn
->
remote_iobuf
;
struct
iobuf
*
io
=
&
conn
->
remote_iobuf
;
int
n
=
0
;
int
n
=
0
;
...
@@ -2045,6 +2081,13 @@ static void write_to_socket(struct connection *conn) {
...
@@ -2045,6 +2081,13 @@ static void write_to_socket(struct connection *conn) {
DBG
((
"%p Written %d of %d(%d): [%.*s ...]"
,
DBG
((
"%p Written %d of %d(%d): [%.*s ...]"
,
conn
,
n
,
io
->
len
,
io
->
size
,
io
->
len
<
40
?
io
->
len
:
40
,
io
->
buf
));
conn
,
n
,
io
->
len
,
io
->
size
,
io
->
len
<
40
?
io
->
len
:
40
,
io
->
buf
));
#ifdef MONGOOSE_HEXDUMP
if
(
match_prefix
(
MONGOOSE_HEXDUMP
,
strlen
(
MONGOOSE_HEXDUMP
),
conn
->
mg_conn
.
remote_ip
))
{
hexdump
(
conn
,
io
->
buf
,
n
,
"->"
);
}
#endif
if
(
is_error
(
n
))
{
if
(
is_error
(
n
))
{
conn
->
flags
|=
CONN_CLOSE
;
conn
->
flags
|=
CONN_CLOSE
;
}
else
if
(
n
>
0
)
{
}
else
if
(
n
>
0
)
{
...
@@ -3654,6 +3697,14 @@ static void read_from_socket(struct connection *conn) {
...
@@ -3654,6 +3697,14 @@ static void read_from_socket(struct connection *conn) {
}
}
DBG
((
"%p %d %d (1)"
,
conn
,
n
,
conn
->
flags
));
DBG
((
"%p %d %d (1)"
,
conn
,
n
,
conn
->
flags
));
#ifdef MONGOOSE_HEXDUMP
if
(
match_prefix
(
MONGOOSE_HEXDUMP
,
strlen
(
MONGOOSE_HEXDUMP
),
conn
->
mg_conn
.
remote_ip
))
{
hexdump
(
conn
,
buf
,
n
,
"<-"
);
}
#endif
if
(
is_error
(
n
))
{
if
(
is_error
(
n
))
{
if
(
conn
->
endpoint_type
==
EP_CLIENT
&&
conn
->
local_iobuf
.
len
>
0
)
{
if
(
conn
->
endpoint_type
==
EP_CLIENT
&&
conn
->
local_iobuf
.
len
>
0
)
{
call_http_client_handler
(
conn
,
MG_DOWNLOAD_SUCCESS
);
call_http_client_handler
(
conn
,
MG_DOWNLOAD_SUCCESS
);
...
...
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