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
3ffdf545
Commit
3ffdf545
authored
Sep 27, 2012
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API change: folded user_data into request_info, and introduced event-specific ev_data
parent
02098b19
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
26 deletions
+13
-26
mongoose.c
mongoose.c
+8
-21
embed.c
test/embed.c
+3
-3
unit_test.c
test/unit_test.c
+2
-2
No files found.
mongoose.c
View file @
3ffdf545
...
@@ -500,7 +500,6 @@ struct mg_connection {
...
@@ -500,7 +500,6 @@ struct mg_connection {
int64_t
consumed_content
;
// How many bytes of content have been read
int64_t
consumed_content
;
// How many bytes of content have been read
char
*
buf
;
// Buffer for received data
char
*
buf
;
// Buffer for received data
char
*
path_info
;
// PATH_INFO part of the URL
char
*
path_info
;
// PATH_INFO part of the URL
char
*
log_message
;
// Placeholder for the mongoose error log message
int
must_close
;
// 1 if connection must be closed
int
must_close
;
// 1 if connection must be closed
int
buf_size
;
// Buffer size
int
buf_size
;
// Buffer size
int
request_len
;
// Size of the request + headers in a buffer
int
request_len
;
// Size of the request + headers in a buffer
...
@@ -520,22 +519,6 @@ static void *call_user(struct mg_connection *conn, enum mg_event event) {
...
@@ -520,22 +519,6 @@ static void *call_user(struct mg_connection *conn, enum mg_event event) {
NULL
:
conn
->
ctx
->
user_callback
(
event
,
conn
);
NULL
:
conn
->
ctx
->
user_callback
(
event
,
conn
);
}
}
void
*
mg_get_user_data
(
struct
mg_connection
*
conn
)
{
return
conn
!=
NULL
&&
conn
->
ctx
!=
NULL
?
conn
->
ctx
->
user_data
:
NULL
;
}
const
char
*
mg_get_log_message
(
const
struct
mg_connection
*
conn
)
{
return
conn
==
NULL
?
NULL
:
conn
->
log_message
;
}
int
mg_get_reply_status_code
(
const
struct
mg_connection
*
conn
)
{
return
conn
==
NULL
?
-
1
:
conn
->
status_code
;
}
void
*
mg_get_ssl_context
(
const
struct
mg_connection
*
conn
)
{
return
conn
==
NULL
||
conn
->
ctx
==
NULL
?
NULL
:
conn
->
ctx
->
ssl_ctx
;
}
static
int
get_option_index
(
const
char
*
name
)
{
static
int
get_option_index
(
const
char
*
name
)
{
int
i
;
int
i
;
...
@@ -591,7 +574,7 @@ static void cry(struct mg_connection *conn, const char *fmt, ...) {
...
@@ -591,7 +574,7 @@ static void cry(struct mg_connection *conn, const char *fmt, ...) {
// Do not lock when getting the callback value, here and below.
// Do not lock when getting the callback value, here and below.
// I suppose this is fine, since function cannot disappear in the
// I suppose this is fine, since function cannot disappear in the
// same way string option can.
// same way string option can.
conn
->
log_message
=
buf
;
conn
->
request_info
.
ev_data
=
buf
;
if
(
call_user
(
conn
,
MG_EVENT_LOG
)
==
NULL
)
{
if
(
call_user
(
conn
,
MG_EVENT_LOG
)
==
NULL
)
{
fp
=
conn
->
ctx
==
NULL
||
conn
->
ctx
->
config
[
ERROR_LOG_FILE
]
==
NULL
?
NULL
:
fp
=
conn
->
ctx
==
NULL
||
conn
->
ctx
->
config
[
ERROR_LOG_FILE
]
==
NULL
?
NULL
:
mg_fopen
(
conn
->
ctx
->
config
[
ERROR_LOG_FILE
],
"a+"
);
mg_fopen
(
conn
->
ctx
->
config
[
ERROR_LOG_FILE
],
"a+"
);
...
@@ -617,7 +600,7 @@ static void cry(struct mg_connection *conn, const char *fmt, ...) {
...
@@ -617,7 +600,7 @@ static void cry(struct mg_connection *conn, const char *fmt, ...) {
}
}
}
}
}
}
conn
->
log_message
=
NULL
;
conn
->
request_info
.
ev_data
=
NULL
;
}
}
// Return fake connection structure. Used for logging, if connection
// Return fake connection structure. Used for logging, if connection
...
@@ -903,6 +886,7 @@ static void send_http_error(struct mg_connection *conn, int status,
...
@@ -903,6 +886,7 @@ static void send_http_error(struct mg_connection *conn, int status,
int
len
;
int
len
;
conn
->
status_code
=
status
;
conn
->
status_code
=
status
;
conn
->
request_info
.
ev_data
=
(
void
*
)
status
;
if
(
call_user
(
conn
,
MG_HTTP_ERROR
)
==
NULL
)
{
if
(
call_user
(
conn
,
MG_HTTP_ERROR
)
==
NULL
)
{
buf
[
0
]
=
'\0'
;
buf
[
0
]
=
'\0'
;
len
=
0
;
len
=
0
;
...
@@ -4342,6 +4326,7 @@ static int load_dll(struct mg_context *ctx, const char *dll_name,
...
@@ -4342,6 +4326,7 @@ static int load_dll(struct mg_context *ctx, const char *dll_name,
// Dynamically load SSL library. Set up ctx->ssl_ctx pointer.
// Dynamically load SSL library. Set up ctx->ssl_ctx pointer.
static
int
set_ssl_option
(
struct
mg_context
*
ctx
)
{
static
int
set_ssl_option
(
struct
mg_context
*
ctx
)
{
struct
mg_connection
*
conn
;
int
i
,
size
;
int
i
,
size
;
const
char
*
pem
;
const
char
*
pem
;
...
@@ -4372,7 +4357,9 @@ static int set_ssl_option(struct mg_context *ctx) {
...
@@ -4372,7 +4357,9 @@ static int set_ssl_option(struct mg_context *ctx) {
// If user callback returned non-NULL, that means that user callback has
// If user callback returned non-NULL, that means that user callback has
// set up certificate itself. In this case, skip sertificate setting.
// set up certificate itself. In this case, skip sertificate setting.
if
(
call_user
(
fc
(
ctx
),
MG_INIT_SSL
)
==
NULL
&&
conn
=
fc
(
ctx
);
conn
->
request_info
.
ev_data
=
ctx
->
ssl_ctx
;
if
(
call_user
(
conn
,
MG_INIT_SSL
)
==
NULL
&&
(
SSL_CTX_use_certificate_file
(
ctx
->
ssl_ctx
,
pem
,
SSL_FILETYPE_PEM
)
==
0
||
(
SSL_CTX_use_certificate_file
(
ctx
->
ssl_ctx
,
pem
,
SSL_FILETYPE_PEM
)
==
0
||
SSL_CTX_use_PrivateKey_file
(
ctx
->
ssl_ctx
,
pem
,
SSL_FILETYPE_PEM
)
==
0
))
{
SSL_CTX_use_PrivateKey_file
(
ctx
->
ssl_ctx
,
pem
,
SSL_FILETYPE_PEM
)
==
0
))
{
cry
(
fc
(
ctx
),
"%s: cannot open %s: %s"
,
__func__
,
pem
,
ssl_error
());
cry
(
fc
(
ctx
),
"%s: cannot open %s: %s"
,
__func__
,
pem
,
ssl_error
());
...
@@ -4425,7 +4412,7 @@ static int set_acl_option(struct mg_context *ctx) {
...
@@ -4425,7 +4412,7 @@ static int set_acl_option(struct mg_context *ctx) {
}
}
static
void
reset_per_request_attributes
(
struct
mg_connection
*
conn
)
{
static
void
reset_per_request_attributes
(
struct
mg_connection
*
conn
)
{
conn
->
path_info
=
conn
->
log_message
=
NULL
;
conn
->
path_info
=
conn
->
request_info
.
ev_data
=
NULL
;
conn
->
num_bytes_sent
=
conn
->
consumed_content
=
0
;
conn
->
num_bytes_sent
=
conn
->
consumed_content
=
0
;
conn
->
status_code
=
-
1
;
conn
->
status_code
=
-
1
;
conn
->
must_close
=
conn
->
request_len
=
conn
->
throttle
=
0
;
conn
->
must_close
=
conn
->
request_len
=
conn
->
throttle
=
0
;
...
...
test/embed.c
View file @
3ffdf545
...
@@ -119,10 +119,10 @@ static void test_get_request_info(struct mg_connection *conn,
...
@@ -119,10 +119,10 @@ static void test_get_request_info(struct mg_connection *conn,
static
void
test_error
(
struct
mg_connection
*
conn
,
static
void
test_error
(
struct
mg_connection
*
conn
,
const
struct
mg_request_info
*
ri
)
{
const
struct
mg_request_info
*
ri
)
{
(
void
)
ri
;
int
status
=
(
int
)
ri
->
ev_data
;
mg_printf
(
conn
,
"HTTP/1.1 %d XX
\r\n
"
mg_printf
(
conn
,
"HTTP/1.1 %d XX
\r\n
"
"Conntection: close
\r\n\r\n
"
,
mg_get_reply_status_code
(
conn
)
);
"Conntection: close
\r\n\r\n
"
,
status
);
mg_printf
(
conn
,
"Error: [%d]"
,
mg_get_reply_status_code
(
conn
)
);
mg_printf
(
conn
,
"Error: [%d]"
,
status
);
}
}
static
void
test_post
(
struct
mg_connection
*
conn
,
static
void
test_post
(
struct
mg_connection
*
conn
,
...
...
test/unit_test.c
View file @
3ffdf545
...
@@ -136,7 +136,7 @@ static void *event_handler(enum mg_event event,
...
@@ -136,7 +136,7 @@ static void *event_handler(enum mg_event event,
"%s"
,
(
int
)
strlen
(
fetch_data
),
fetch_data
);
"%s"
,
(
int
)
strlen
(
fetch_data
),
fetch_data
);
return
""
;
return
""
;
}
else
if
(
event
==
MG_EVENT_LOG
)
{
}
else
if
(
event
==
MG_EVENT_LOG
)
{
printf
(
"%s
\n
"
,
mg_get_log_message
(
conn
)
);
printf
(
"%s
\n
"
,
(
const
char
*
)
mg_get_request_info
(
conn
)
->
ev_data
);
}
}
return
NULL
;
return
NULL
;
...
...
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