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
2ac970fa
Commit
2ac970fa
authored
Mar 01, 2014
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moving to event-based API, temporary breaking tests
parent
de35a353
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
109 additions
and
136 deletions
+109
-136
unit_test.c
examples/unit_test.c
+15
-21
mongoose.c
mongoose.c
+80
-105
mongoose.h
mongoose.h
+14
-10
No files found.
examples/unit_test.c
View file @
2ac970fa
...
...
@@ -339,20 +339,17 @@ static const char *test_next_option(void) {
return
NULL
;
}
static
int
cb1
(
struct
mg_connection
*
conn
)
{
int
result
=
MG_REQUEST_NOT_PROCESSED
;
if
(
!
strcmp
(
conn
->
uri
,
"/cb1"
))
{
static
int
evh1
(
struct
mg_connection
*
conn
,
enum
mg_event
ev
)
{
if
(
ev
==
MG_HTTP_ERROR
)
{
mg_printf
(
conn
,
"HTTP/1.0 404 NF
\r\n\r\n
ERR: %d"
,
conn
->
status_code
);
return
MG_TRUE
;
}
else
if
(
ev
==
MG_REQ_BEGIN
&&
!
strcmp
(
conn
->
uri
,
"/cb1"
))
{
mg_printf
(
conn
,
"%s %s %s"
,
conn
->
server_param
==
NULL
?
"?"
:
(
char
*
)
conn
->
server_param
,
conn
->
connection_param
==
NULL
?
"?"
:
"!"
,
conn
->
remote_ip
);
re
sult
=
MG_REQUEST_PROCESSED
;
re
turn
MG_TRUE
;
}
return
result
;
}
static
int
error_handler
(
struct
mg_connection
*
conn
)
{
mg_printf
(
conn
,
"HTTP/1.0 404 NF
\r\n\r\n
ERR: %d"
,
conn
->
status_code
);
return
MG_ERROR_PROCESSED
;
return
MG_FALSE
;
}
static
int
ts1
(
struct
mg_connection
*
conn
)
{
...
...
@@ -379,16 +376,14 @@ static int ts2(struct mg_connection *conn) {
static
const
char
*
test_server
(
void
)
{
char
buf1
[
100
]
=
""
,
buf2
[
100
]
=
""
;
struct
mg_server
*
server
=
mg_create_server
((
void
*
)
"foo"
);
struct
mg_server
*
server
=
mg_create_server
((
void
*
)
"foo"
,
evh1
);
ASSERT
(
server
!=
NULL
);
ASSERT
(
mg_set_option
(
server
,
"listening_port"
,
LISTENING_ADDR
)
==
NULL
);
ASSERT
(
mg_set_option
(
server
,
"document_root"
,
"."
)
==
NULL
);
mg_set_request_handler
(
server
,
cb1
);
mg_set_http_error_handler
(
server
,
error_handler
);
ASSERT
(
mg_connect
(
server
,
"127.0.0.1"
,
atoi
(
HTTP_PORT
),
0
,
ts1
,
buf1
)
==
1
);
ASSERT
(
mg_connect
(
server
,
"127.0.0.1"
,
atoi
(
HTTP_PORT
),
0
,
ts2
,
buf2
)
==
1
);
ASSERT
(
mg_connect
(
server
,
"127.0.0.1"
,
atoi
(
HTTP_PORT
),
0
,
buf1
)
==
1
);
ASSERT
(
mg_connect
(
server
,
"127.0.0.1"
,
atoi
(
HTTP_PORT
),
0
,
buf2
)
==
1
);
{
int
i
;
for
(
i
=
0
;
i
<
50
;
i
++
)
mg_poll_server
(
server
,
1
);
}
ASSERT
(
strcmp
(
buf1
,
"foo ? 127.0.0.1"
)
==
0
);
...
...
@@ -464,15 +459,14 @@ static int cb3(struct mg_connection *conn) {
static
const
char
*
test_mg_connect
(
void
)
{
char
buf2
[
40
]
=
""
,
buf3
[
40
]
=
""
,
buf4
[
40
]
=
""
;
struct
mg_server
*
server
=
mg_create_server
(
NULL
);
struct
mg_server
*
server
=
mg_create_server
(
NULL
,
NULL
);
// cb4h
ASSERT
(
mg_set_option
(
server
,
"listening_port"
,
LISTENING_ADDR
)
==
NULL
);
ASSERT
(
mg_set_option
(
server
,
"document_root"
,
"."
)
==
NULL
);
mg_set_request_handler
(
server
,
cb4h
);
ASSERT
(
mg_connect
(
server
,
""
,
0
,
0
,
NULL
,
NULL
)
==
0
);
ASSERT
(
mg_connect
(
server
,
"127.0.0.1"
,
atoi
(
HTTP_PORT
),
0
,
cb2
,
buf2
)
==
1
);
ASSERT
(
mg_connect
(
server
,
"127.0.0.1"
,
atoi
(
HTTP_PORT
),
0
,
buf2
)
==
1
);
ASSERT
(
mg_connect
(
server
,
"127.0.0.1"
,
29
,
0
,
cb3
,
buf3
)
==
1
);
ASSERT
(
mg_connect
(
server
,
"127.0.0.1"
,
atoi
(
HTTP_PORT
),
0
,
cb4
,
buf4
)
==
1
);
ASSERT
(
mg_connect
(
server
,
"127.0.0.1"
,
atoi
(
HTTP_PORT
),
0
,
buf4
)
==
1
);
{
int
i
;
for
(
i
=
0
;
i
<
50
;
i
++
)
mg_poll_server
(
server
,
1
);
}
...
...
@@ -562,7 +556,7 @@ static const char *test_ssl(void) {
#endif
static
const
char
*
test_mg_set_option
(
void
)
{
struct
mg_server
*
server
=
mg_create_server
(
NULL
);
struct
mg_server
*
server
=
mg_create_server
(
NULL
,
NULL
);
ASSERT
(
mg_set_option
(
server
,
"listening_port"
,
"0"
)
==
NULL
);
ASSERT
(
mg_get_option
(
server
,
"listening_port"
)[
0
]
!=
'\0'
);
mg_destroy_server
(
&
server
);
...
...
@@ -571,7 +565,7 @@ static const char *test_mg_set_option(void) {
static
const
char
*
test_rewrites
(
void
)
{
char
buf1
[
100
]
=
"xx"
;
struct
mg_server
*
server
=
mg_create_server
(
NULL
);
struct
mg_server
*
server
=
mg_create_server
(
NULL
,
NULL
);
ASSERT
(
mg_set_option
(
server
,
"listening_port"
,
"0"
)
==
NULL
);
ASSERT
(
mg_set_option
(
server
,
"document_root"
,
"."
)
==
NULL
);
...
...
mongoose.c
View file @
2ac970fa
This diff is collapsed.
Click to expand it.
mongoose.h
View file @
2ac970fa
...
...
@@ -55,26 +55,31 @@ struct mg_connection {
int
wsbits
;
// First byte of the websocket frame
void
*
server_param
;
// Parameter passed to mg_add_uri_handler()
void
*
connection_param
;
// Placeholder for connection-specific data
void
*
callback_param
;
// Used by mg_iterate_over_connections()
};
struct
mg_server
;
// Opaque structure describing server instance
typedef
int
(
*
mg_handler_t
)(
struct
mg_connection
*
);
enum
mg_result
{
MG_FALSE
,
MG_TRUE
};
enum
mg_event
{
MG_POLL
,
// Callback return value is ignored
MG_AUTH
,
// If callback returns MG_FALSE, authentication fails
MG_REQ_BEGIN
,
// If callback returns MG_FALSE, Mongoose continues with req
MG_REQ_END
,
// Callback return value is ignored
MG_CLOSE
,
// Connection is closed
MG_CONNECT
,
// If callback returns MG_FALSE, connect fails
MG_HTTP_ERROR
// If callback returns MG_FALSE, Mongoose continues with err
};
typedef
int
(
*
mg_handler_t
)(
struct
mg_connection
*
,
enum
mg_event
);
// Server management functions
struct
mg_server
*
mg_create_server
(
void
*
server_param
);
struct
mg_server
*
mg_create_server
(
void
*
server_param
,
mg_handler_t
handler
);
void
mg_destroy_server
(
struct
mg_server
**
);
const
char
*
mg_set_option
(
struct
mg_server
*
,
const
char
*
opt
,
const
char
*
val
);
int
mg_poll_server
(
struct
mg_server
*
,
int
milliseconds
);
void
mg_set_request_handler
(
struct
mg_server
*
,
mg_handler_t
);
void
mg_set_http_close_handler
(
struct
mg_server
*
,
mg_handler_t
);
void
mg_set_http_error_handler
(
struct
mg_server
*
,
mg_handler_t
);
void
mg_set_auth_handler
(
struct
mg_server
*
,
mg_handler_t
);
const
char
**
mg_get_valid_option_names
(
void
);
const
char
*
mg_get_option
(
const
struct
mg_server
*
server
,
const
char
*
name
);
void
mg_set_listening_socket
(
struct
mg_server
*
,
int
sock
);
int
mg_get_listening_socket
(
struct
mg_server
*
);
void
mg_iterate_over_connections
(
struct
mg_server
*
,
mg_handler_t
,
void
*
);
void
mg_iterate_over_connections
(
struct
mg_server
*
,
mg_handler_t
);
// Connection management functions
void
mg_send_status
(
struct
mg_connection
*
,
int
status_code
);
...
...
@@ -115,8 +120,7 @@ enum {
MG_CONNECT_SUCCESS
,
MG_CONNECT_FAILURE
,
MG_DOWNLOAD_SUCCESS
,
MG_DOWNLOAD_FAILURE
};
int
mg_connect
(
struct
mg_server
*
,
const
char
*
host
,
int
port
,
int
use_ssl
,
mg_handler_t
handler
,
void
*
param
);
struct
mg_connection
*
mg_connect
(
struct
mg_server
*
,
const
char
*
,
int
,
int
);
#ifdef __cplusplus
}
...
...
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