Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
mongoose
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ganil-acq
GANILinux
linux-service
library
mongoose
Commits
5dc317fc
Commit
5dc317fc
authored
11 years ago
by
Sergey Lyubka
Browse files
Options
Downloads
Patches
Plain Diff
Added -DMONGOOSE_HEXDUMP feature
parent
fbd5d77c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
docs/Embed.md
+3
-0
3 additions, 0 deletions
docs/Embed.md
mongoose.c
+51
-0
51 additions, 0 deletions
mongoose.c
with
54 additions
and
0 deletions
docs/Embed.md
+
3
−
0
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:
...
...
This diff is collapsed.
Click to expand it.
mongoose.c
+
51
−
0
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
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment