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
75d9a6c8
Commit
75d9a6c8
authored
Jan 23, 2013
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed mg_connect() and mg_fetch(). Added mg_download()
parent
179761fd
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
257 additions
and
222 deletions
+257
-222
mongoose.c
mongoose.c
+115
-110
mongoose.h
mongoose.h
+22
-26
test.pl
test/test.pl
+7
-8
unit_test.c
test/unit_test.c
+113
-78
No files found.
mongoose.c
View file @
75d9a6c8
This diff is collapsed.
Click to expand it.
mongoose.h
View file @
75d9a6c8
...
@@ -236,12 +236,6 @@ struct mg_request_info *mg_get_request_info(struct mg_connection *);
...
@@ -236,12 +236,6 @@ struct mg_request_info *mg_get_request_info(struct mg_connection *);
int
mg_write
(
struct
mg_connection
*
,
const
void
*
buf
,
size_t
len
);
int
mg_write
(
struct
mg_connection
*
,
const
void
*
buf
,
size_t
len
);
// Send data to the browser using printf() semantics.
//
// Works exactly like mg_write(), but allows to do message formatting.
// Below are the macros for enabling compiler-specific checks for
// printf-like arguments.
#undef PRINTF_FORMAT_STRING
#undef PRINTF_FORMAT_STRING
#if _MSC_VER >= 1400
#if _MSC_VER >= 1400
#include <sal.h>
#include <sal.h>
...
@@ -260,6 +254,11 @@ int mg_write(struct mg_connection *, const void *buf, size_t len);
...
@@ -260,6 +254,11 @@ int mg_write(struct mg_connection *, const void *buf, size_t len);
#define PRINTF_ARGS(x, y)
#define PRINTF_ARGS(x, y)
#endif
#endif
// Send data to the browser using printf() semantics.
//
// Works exactly like mg_write(), but allows to do message formatting.
// Below are the macros for enabling compiler-specific checks for
// printf-like arguments.
int
mg_printf
(
struct
mg_connection
*
,
int
mg_printf
(
struct
mg_connection
*
,
PRINTF_FORMAT_STRING
(
const
char
*
fmt
),
...)
PRINTF_ARGS
(
2
,
3
);
PRINTF_FORMAT_STRING
(
const
char
*
fmt
),
...)
PRINTF_ARGS
(
2
,
3
);
...
@@ -316,32 +315,29 @@ int mg_get_cookie(const struct mg_connection *,
...
@@ -316,32 +315,29 @@ int mg_get_cookie(const struct mg_connection *,
const
char
*
cookie_name
,
char
*
buf
,
size_t
buf_len
);
const
char
*
cookie_name
,
char
*
buf
,
size_t
buf_len
);
// Connect to the remote web server.
// Download data from the remote web server.
// host: host name to connect to, e.g. "foo.com", or "10.12.40.1".
// port: port number, e.g. 80.
// use_ssl: wether to use SSL connection.
// error_buffer, error_buffer_size: error message placeholder.
// request_fmt,...: HTTP request.
// Return:
// Return:
// On success, valid pointer to the new connection
// On success, valid pointer to the new connection, suitable for mg_read().
// On error, NULL
// On error, NULL.
struct
mg_connection
*
mg_connect
(
struct
mg_context
*
ctx
,
// Example:
const
char
*
host
,
int
port
,
int
use_ssl
);
// char ebuf[100];
// struct mg_connection *conn;
// conn = mg_download("google.com", 80, 0, ebuf, sizeof(ebuf),
// "%s", "GET / HTTP/1.0\r\n\r\nHost: google.com\r\n\r\n");
struct
mg_connection
*
mg_download
(
const
char
*
host
,
int
port
,
int
use_ssl
,
char
*
error_buffer
,
size_t
error_buffer_size
,
const
char
*
request_fmt
,
...);
// Close the connection opened by mg_
connect
().
// Close the connection opened by mg_
download
().
void
mg_close_connection
(
struct
mg_connection
*
conn
);
void
mg_close_connection
(
struct
mg_connection
*
conn
);
// Download given URL to a given file.
// url: URL to download
// path: file name where to save the data
// request_info: pointer to a structure that will hold parsed reply headers
// buf, bul_len: a buffer for the reply headers
// Return:
// On error, NULL
// On success, opened file stream to the downloaded contents. The stream
// is positioned to the end of the file. It is the user's responsibility
// to fclose() the opened file stream.
FILE
*
mg_fetch
(
struct
mg_context
*
ctx
,
const
char
*
url
,
const
char
*
path
,
char
*
buf
,
size_t
buf_len
,
struct
mg_request_info
*
request_info
);
// File upload functionality. Each uploaded file gets saved into a temporary
// File upload functionality. Each uploaded file gets saved into a temporary
// file and MG_UPLOAD event is sent.
// file and MG_UPLOAD event is sent.
// Return number of uploaded files.
// Return number of uploaded files.
...
...
test/test.pl
View file @
75d9a6c8
...
@@ -167,7 +167,7 @@ kill_spawned_child();
...
@@ -167,7 +167,7 @@ kill_spawned_child();
# Spawn the server on port $port
# Spawn the server on port $port
my
$cmd
=
"$exe "
.
my
$cmd
=
"$exe "
.
"-listening_ports $port "
.
"-listening_ports
127.0.0.1:
$port "
.
"-access_log_file access.log "
.
"-access_log_file access.log "
.
"-error_log_file debug.log "
.
"-error_log_file debug.log "
.
"-cgi_environment CGI_FOO=foo,CGI_BAR=bar,CGI_BAZ=baz "
.
"-cgi_environment CGI_FOO=foo,CGI_BAR=bar,CGI_BAZ=baz "
.
...
@@ -220,11 +220,10 @@ write_file("$root/a+.txt", '');
...
@@ -220,11 +220,10 @@ write_file("$root/a+.txt", '');
o
(
"GET /a+.txt HTTP/1.0\n\n"
,
'HTTP/1.1 200 OK'
,
'URL-decoding, + in URI'
);
o
(
"GET /a+.txt HTTP/1.0\n\n"
,
'HTTP/1.1 200 OK'
,
'URL-decoding, + in URI'
);
# Test HTTP version parsing
# Test HTTP version parsing
o
(
"GET / HTTPX/1.0\r\n\r\n"
,
'400 Bad Request'
,
'Bad HTTP Version'
,
0
);
o
(
"GET / HTTPX/1.0\r\n\r\n"
,
'^HTTP/1.1 500'
,
'Bad HTTP Version'
,
0
);
o
(
"GET / HTTP/x.1\r\n\r\n"
,
'505 HTTP'
,
'Bad HTTP maj Version'
);
o
(
"GET / HTTP/x.1\r\n\r\n"
,
'^HTTP/1.1 505'
,
'Bad HTTP maj Version'
,
0
);
o
(
"GET / HTTP/1.1z\r\n\r\n"
,
'505 HTTP'
,
'Bad HTTP min Version'
);
o
(
"GET / HTTP/1.1z\r\n\r\n"
,
'^HTTP/1.1 505'
,
'Bad HTTP min Version'
,
0
);
o
(
"GET / HTTP/02.0\r\n\r\n"
,
'505 HTTP version not supported'
,
o
(
"GET / HTTP/02.0\r\n\r\n"
,
'^HTTP/1.1 505'
,
'HTTP Version >1.1'
,
0
);
'HTTP Version >1.1'
);
# File with leading single dot
# File with leading single dot
o
(
"GET /.leading.dot.txt HTTP/1.0\n\n"
,
'abc123'
,
'Leading dot 1'
);
o
(
"GET /.leading.dot.txt HTTP/1.0\n\n"
,
'abc123'
,
'Leading dot 1'
);
...
@@ -463,7 +462,7 @@ sub do_unit_test {
...
@@ -463,7 +462,7 @@ sub do_unit_test {
sub
do_embedded_test
{
sub
do_embedded_test
{
my
$cmd
=
"cc -W -Wall -o $embed_exe $root/embed.c mongoose.c -I. "
.
my
$cmd
=
"cc -W -Wall -o $embed_exe $root/embed.c mongoose.c -I. "
.
"-pthread -DNO_SSL -DLISTENING_PORT=\\\"$port\\\""
;
"-pthread -DNO_SSL -DLISTENING_PORT=\\\"
127.0.0.1:
$port\\\""
;
if
(
on_windows
())
{
if
(
on_windows
())
{
$cmd
=
"cl $root/embed.c mongoose.c /I. /nologo /DNO_SSL "
.
$cmd
=
"cl $root/embed.c mongoose.c /I. /nologo /DNO_SSL "
.
"/DLISTENING_PORT=\\\"$port\\\" /link /out:$embed_exe.exe ws2_32.lib "
;
"/DLISTENING_PORT=\\\"$port\\\" /link /out:$embed_exe.exe ws2_32.lib "
;
...
@@ -514,7 +513,7 @@ sub do_embedded_test {
...
@@ -514,7 +513,7 @@ sub do_embedded_test {
'Remote user: \[\]'
'Remote user: \[\]'
,
'request_info'
,
0
);
,
'request_info'
,
0
);
o
(
"GET /not_exist HTTP/1.0\n\n"
,
'Error: \[404\]'
,
'404 handler'
,
0
);
o
(
"GET /not_exist HTTP/1.0\n\n"
,
'Error: \[404\]'
,
'404 handler'
,
0
);
o
(
"bad request\n\n"
,
'Error: \[
4
00\]'
,
'* error handler'
,
0
);
o
(
"bad request\n\n"
,
'Error: \[
5
00\]'
,
'* error handler'
,
0
);
# o("GET /foo/secret HTTP/1.0\n\n",
# o("GET /foo/secret HTTP/1.0\n\n",
# '401 Unauthorized', 'mg_protect_uri', 0);
# '401 Unauthorized', 'mg_protect_uri', 0);
# o("GET /foo/secret HTTP/1.0\nAuthorization: Digest username=bill\n\n",
# o("GET /foo/secret HTTP/1.0\nAuthorization: Digest username=bill\n\n",
...
...
test/unit_test.c
View file @
75d9a6c8
This diff is collapsed.
Click to expand it.
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