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
02098b19
Commit
02098b19
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
c189553c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
72 additions
and
40 deletions
+72
-40
mongoose.py
bindings/python/mongoose.py
+2
-4
main.c
main.c
+1
-1
mongoose.c
mongoose.c
+5
-5
mongoose.h
mongoose.h
+64
-30
No files found.
bindings/python/mongoose.py
View file @
02098b19
...
...
@@ -72,6 +72,8 @@ class mg_request_info(ctypes.Structure):
(
'is_ssl'
,
ctypes
.
c_int
),
(
'num_headers'
,
ctypes
.
c_int
),
(
'http_headers'
,
mg_header
*
64
),
(
'user_data'
,
ctypes
.
c_void_p
),
(
'ev_data'
,
ctypes
.
c_void_p
),
]
...
...
@@ -86,10 +88,6 @@ class Connection(object):
self
.
m
=
mongoose
self
.
conn
=
ctypes
.
c_void_p
(
connection
)
self
.
info
=
self
.
m
.
dll
.
mg_get_request_info
(
self
.
conn
)
.
contents
self
.
user_data
=
self
.
m
.
dll
.
mg_get_user_data
(
self
.
conn
)
self
.
log_message
=
self
.
m
.
dll
.
mg_get_log_message
(
self
.
conn
)
self
.
reply_status_code
=
self
.
m
.
dll
.
mg_get_reply_status_code
(
self
.
conn
)
self
.
ssl_context
=
self
.
m
.
dll
.
mg_get_ssl_context
(
self
.
conn
)
def
get_header
(
self
,
name
):
val
=
self
.
m
.
dll
.
mg_get_header
(
self
.
conn
,
name
)
...
...
main.c
View file @
02098b19
...
...
@@ -221,7 +221,7 @@ static void init_server_name(void) {
static
void
*
mongoose_callback
(
enum
mg_event
ev
,
struct
mg_connection
*
conn
)
{
if
(
ev
==
MG_EVENT_LOG
)
{
printf
(
"%s
\n
"
,
mg_get_log_message
(
conn
)
);
printf
(
"%s
\n
"
,
(
const
char
*
)
mg_get_request_info
(
conn
)
->
ev_data
);
}
// Returning NULL marks request as not handled, signalling mongoose to
...
...
mongoose.c
View file @
02098b19
...
...
@@ -632,8 +632,7 @@ const char *mg_version(void) {
return
MONGOOSE_VERSION
;
}
const
struct
mg_request_info
*
mg_get_request_info
(
const
struct
mg_connection
*
conn
)
{
struct
mg_request_info
*
mg_get_request_info
(
struct
mg_connection
*
conn
)
{
return
&
conn
->
request_info
;
}
...
...
@@ -4000,11 +3999,12 @@ static void handle_request(struct mg_connection *conn) {
struct
mgstat
st
;
if
((
conn
->
request_info
.
query_string
=
strchr
(
ri
->
uri
,
'?'
))
!=
NULL
)
{
*
conn
->
request_info
.
query_string
++
=
'\0'
;
*
((
char
*
)
conn
->
request_info
.
query_string
++
)
=
'\0'
;
}
uri_len
=
(
int
)
strlen
(
ri
->
uri
);
url_decode
(
ri
->
uri
,
(
size_t
)
uri_len
,
ri
->
uri
,
(
size_t
)(
uri_len
+
1
),
0
);
remove_double_dots_and_double_slashes
(
ri
->
uri
);
url_decode
(
ri
->
uri
,
(
size_t
)
uri_len
,
(
char
*
)
ri
->
uri
,
(
size_t
)
(
uri_len
+
1
),
0
);
remove_double_dots_and_double_slashes
((
char
*
)
ri
->
uri
);
stat_result
=
convert_uri_to_file_name
(
conn
,
path
,
sizeof
(
path
),
&
st
);
conn
->
throttle
=
set_throttle
(
conn
->
ctx
->
config
[
THROTTLE
],
get_remote_ip
(
conn
),
ri
->
uri
);
...
...
mongoose.h
View file @
02098b19
...
...
@@ -34,35 +34,74 @@ struct mg_connection; // Handle for the individual connection
// This structure contains information about the HTTP request.
struct
mg_request_info
{
c
har
*
request_method
;
// "GET", "POST", etc
c
har
*
uri
;
// URL-decoded URI
c
har
*
http_version
;
// E.g. "1.0", "1.1"
c
har
*
query_string
;
// URL part after '?' (not including '?')
or NULL
c
har
*
remote_user
;
// Authenticated user, or NULL if no auth used
c
onst
char
*
request_method
;
// "GET", "POST", etc
c
onst
char
*
uri
;
// URL-decoded URI
c
onst
char
*
http_version
;
// E.g. "1.0", "1.1"
c
onst
char
*
query_string
;
// URL part after '?', not including '?',
or NULL
c
onst
char
*
remote_user
;
// Authenticated user, or NULL if no auth used
long
remote_ip
;
// Client's IP address
int
remote_port
;
// Client's port
int
is_ssl
;
// 1 if SSL-ed, 0 if not
int
num_headers
;
// Number of headers
struct
mg_header
{
c
har
*
name
;
// HTTP header name
c
har
*
value
;
// HTTP header value
c
onst
char
*
name
;
// HTTP header name
c
onst
char
*
value
;
// HTTP header value
}
http_headers
[
64
];
// Maximum 64 headers
void
*
user_data
;
// User data pointer passed to the mg_start()
void
*
ev_data
;
// Event-specific data pointer
};
// Various events on which user-defined function is called by Mongoose.
// Various events on which user-defined
callback
function is called by Mongoose.
enum
mg_event
{
MG_NEW_REQUEST
,
// New HTTP request has arrived from the client
MG_REQUEST_COMPLETE
,
// Mongoose has finished handling the request
MG_HTTP_ERROR
,
// HTTP error must be returned to the client
MG_EVENT_LOG
,
// Mongoose logs an event, request_info.log_message
MG_INIT_SSL
,
// SSL initialization, sent before certificate setup
MG_WEBSOCKET_CONNECT
,
// Sent on HTTP connect, before websocket handshake.
// New HTTP request has arrived from the client.
// If callback returns non-NULL, Mongoose stops handling current request.
// ev_data contains NULL.
MG_NEW_REQUEST
,
// Mongoose has finished handling the request.
// Callback return value is ignored.
// ev_data contains NULL.
MG_REQUEST_COMPLETE
,
// HTTP error must be returned to the client.
// If callback returns non-NULL, Mongoose stops handling error.
// ev_data contains HTTP error code:
// int http_reply_status_code = (int) request_info->ev_data;
MG_HTTP_ERROR
,
// Mongoose logs a message.
// If callback returns non-NULL, Mongoose stops handling that event.
// ev_data contains a message to be logged:
// const char *log_message = request_info->ev_data;
MG_EVENT_LOG
,
// SSL initialization, sent before certificate setup.
// If callback returns non-NULL, Mongoose does not set up certificates.
// ev_data contains server's OpenSSL context:
// SSL_CTX *ssl_context = request_info->ev_data;
MG_INIT_SSL
,
// Sent on HTTP connect, before websocket handshake.
// If user callback returns NULL, then mongoose proceeds
// with handshake, otherwise it closes the connection.
MG_WEBSOCKET_READY
,
// Handshake has been successfully completed.
MG_WEBSOCKET_MESSAGE
,
// Incoming message from the client
MG_WEBSOCKET_CLOSE
,
// Client has closed the connection
// ev_data contains NULL.
MG_WEBSOCKET_CONNECT
,
// Handshake has been successfully completed.
// Callback's return value is ignored.
// ev_data contains NULL.
MG_WEBSOCKET_READY
,
// Incoming message from the client, data could be read with mg_read().
// If user callback returns non-NULL, mongoose closes the websocket.
// ev_data contains NULL.
MG_WEBSOCKET_MESSAGE
,
// Client has closed the connection.
// Callback's return value is ignored.
// ev_data contains NULL.
MG_WEBSOCKET_CLOSE
,
};
...
...
@@ -155,12 +194,7 @@ int mg_modify_passwords_file(const char *passwords_file_name,
// Return information associated with the request.
// These functions always succeed.
const
struct
mg_request_info
*
mg_get_request_info
(
const
struct
mg_connection
*
);
void
*
mg_get_user_data
(
struct
mg_connection
*
);
const
char
*
mg_get_log_message
(
const
struct
mg_connection
*
);
int
mg_get_reply_status_code
(
const
struct
mg_connection
*
);
void
*
mg_get_ssl_context
(
const
struct
mg_connection
*
);
struct
mg_request_info
*
mg_get_request_info
(
struct
mg_connection
*
);
// Send data to the client.
...
...
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