Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: CI

on: [push, pull_request]

jobs:
build:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ubuntu-22.04]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This runtime is not available yet on GitHub Actions.


steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Setup Vala PPA repository
run: sudo add-apt-repository --yes ppa:vala-team

- name: Update APT cache
run: sudo apt-get update --quiet

- name: Install dependencies
run: sudo apt-get install --yes valac libglib2.0-bin libglib2.0-dev libsoup3-dev libsystemd-dev libfcgi-dev gcovr valgrind ninja-build

- name: Install Meson
run: pip3 install meson

- name: Build
run: |
mkdir build
meson -D b_coverage=true -D enable_examples=true . build
ninja -C build -v
- name: Test
run: |
meson test -C build --wrapper valgrind --print-errorlogs --num-processes=1 -v
DESTDIR=$(mktemp -d) ninja -C build -v install
# - name: Generate coverage reports
# run: ninja -C build -v coverage

# - name: Report coverage to Codecov
# uses: codecov/codecov-action@v2.1.0
# with:
# directory: build
# fail_ci_if_error: true
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ gobject = dependency('gobject-2.0', version: '>=2.56')
gio = dependency('gio-2.0', version: '>=2.56')
gio_unix = dependency('gio-unix-2.0', version: '>=2.56')
gmodule = dependency('gmodule-2.0', version: '>=2.40')
soup = dependency('libsoup-2.4', version: '>=2.62')
soup = dependency('libsoup-3.0')
openssl = dependency('openssl')
posix = meson.get_compiler('vala').find_library('posix')

Expand Down
4 changes: 4 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ vsgi_sources = files(
'vsgi-server.vala',
'vsgi-socket-server.vala',
'vsgi-tee-output-stream.vala')
vsgi_internal_header = join_paths(meson.current_build_dir(), 'vsgi-@0@-internal.h'.format(api_version))
vsgi_internal_vapi = join_paths(meson.current_build_dir(), 'vsgi-@0@-internal.vapi'.format(api_version))
vsgi_lib = library('vsgi-' + api_version, vsgi_sources,
dependencies: [glib, gobject, gio, gio_unix, gmodule, soup, openssl, posix],
vala_header: 'vsgi.h',
vala_gir: 'VSGI-@0@.gir'.format(api_version),
build_rpath: join_paths(meson.current_build_dir(), 'servers'),
vala_args: ['--internal-header', vsgi_internal_header,
'--internal-vapi', vsgi_internal_vapi],
link_args: ['-Wl,--disable-new-dtags'],
install: true,
install_dir: [true, 'include/vsgi-' + api_version, true, true],
Expand Down
1 change: 1 addition & 0 deletions src/servers/meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
shared_module('vsgi-http', ['vsgi-http.vala'],
dependencies: [glib, gobject, gio, soup, vsgi_dep],
vala_args: ['--vapi', vsgi_internal_vapi],
install: true,
install_dir: join_paths(get_option('libdir'), 'vsgi-@0@/servers'.format(api_version)))

Expand Down
4 changes: 2 additions & 2 deletions src/servers/vsgi-cgi.vala
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ namespace VSGI.CGI {
[Version (since = "0.1")]
public class Server : VSGI.Server {

public override SList<Soup.URI> uris {
public override SList<Uri> uris {
owned get {
return new SList<Soup.URI> ();
return new SList<Uri> ();
}
}

Expand Down
88 changes: 41 additions & 47 deletions src/servers/vsgi-http.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ namespace VSGI.HTTP {

public Soup.Server server { construct; get; }

public Soup.Message message { construct; get; }
public Soup.ServerMessage message { construct; get; }

public MessageBodyOutputStream (Soup.Server server, Soup.Message message) {
public MessageBodyOutputStream (Soup.Server server, Soup.ServerMessage message) {
Object (server: server, message: message);
}

Expand All @@ -48,12 +48,12 @@ namespace VSGI.HTTP {
// FIXME: throw a IOError here
return -1;
}
message.response_body.append_take (data);
message.get_response_body ().append_take (data);
return data.length;
}

/**
* Resume I/O on the underlying {@link Soup.Message} to flush the
* Resume I/O on the underlying {@link Soup.ServerMessage} to flush the
* written chunks.
*/
public override bool flush (Cancellable? cancellable = null) throws IOError {
Expand All @@ -68,7 +68,7 @@ namespace VSGI.HTTP {
if (finished) {
throw new IOError.CONNECTION_CLOSED ("Connection closed by peer.");
}
message.response_body.complete ();
message.get_response_body ().complete ();
return true;
}
}
Expand All @@ -83,9 +83,7 @@ namespace VSGI.HTTP {
/**
* Message underlying this request.
*/
public Soup.Message message { construct; get; }

public Soup.ClientContext client_context { construct; get; }
public Soup.ServerMessage message { construct; get; }

/**
* {@inheritDoc}
Expand All @@ -96,18 +94,16 @@ namespace VSGI.HTTP {
* @param msg message underlying this request
* @param query parsed HTTP query provided by {@link Soup.ServerCallback}
*/
public Request (Soup.Message msg,
Soup.ClientContext client_context,
public Request (Soup.ServerMessage msg,
HashTable<string, string>? query) {
Object (message: msg,
client_context: client_context,
http_version: msg.http_version,
http_version: msg.get_http_version (),
gateway_interface: "HTTP/1.1",
method: msg.method,
uri: msg.uri,
method: msg.get_method (),
uri: msg.get_uri (),
query: query,
headers: msg.request_headers,
body: new MemoryInputStream.from_data (msg.request_body.data, null));
headers: msg.get_request_headers (),
body: new MemoryInputStream.from_data (msg.get_request_body ().data, null));
}

construct {
Expand All @@ -119,9 +115,9 @@ namespace VSGI.HTTP {
return null;
}
try {
return _client_context == null ? null : client_context.steal_connection ();
return _message == null ? null : message.steal_connection ();
} finally {
_client_context = null;
_message = null;
}
}
}
Expand All @@ -138,28 +134,28 @@ namespace VSGI.HTTP {
/**
* Message underlying this response.
*/
public Soup.Message message { construct; get; }
public Soup.ServerMessage message { construct; get; }

public override uint status {
get { return this.message.status_code; }
set { this.message.status_code = value; }
get { return this.message.get_status (); }
set { this.message.set_status (value, null); }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reuse the existing status message here.

}

public override string? reason_phrase {
owned get { return this.message.reason_phrase == "Unknown Error" ? null : this.message.reason_phrase; }
set { this.message.reason_phrase = value ?? Soup.Status.get_phrase (this.message.status_code); }
owned get { return this.message.get_reason_phrase () == "Unknown Error" ? null : this.message.get_reason_phrase (); }
set { this.message.set_status (this.message.get_status (), value ?? Soup.Status.get_phrase (this.message.get_status ())); }
}

/**
* {@inheritDoc}
*
* @param msg message underlying this response
*/
public Response (Request req, Soup.Server soup_server, Soup.Message msg) {
public Response (Request req, Soup.Server soup_server, Soup.ServerMessage msg) {
Object (request: req,
soup_server: soup_server,
message: msg,
headers: msg.response_headers,
headers: msg.get_response_headers (),
body: new MessageBodyOutputStream (soup_server, msg));
}

Expand All @@ -178,7 +174,7 @@ namespace VSGI.HTTP {
/**
* {@inheritDoc}
*
* Implementation based on {@link Soup.Message} already handles the
* Implementation based on {@link Soup.ServerMessage} already handles the
* writing of the status line.
*/
protected override bool write_status_line (Soup.HTTPVersion http_version, uint status, string reason_phrase, out size_t bytes_written, Cancellable? cancellable = null) throws IOError {
Expand All @@ -192,7 +188,7 @@ namespace VSGI.HTTP {
/**
* {@inheritDoc}
*
* Implementation based on {@link Soup.Message} already handles the
* Implementation based on {@link Soup.ServerMessage} already handles the
* writing of the headers.
*/
protected override bool write_headers (Soup.MessageHeaders headers, out size_t bytes_written, Cancellable? cancellable = null) throws IOError {
Expand Down Expand Up @@ -227,7 +223,7 @@ namespace VSGI.HTTP {
[Description (blurb = "Percent-encoding in the Request-URI path will not be automatically decoded")]
public bool raw_paths { construct; get; default = false; }

public override SList<Soup.URI> uris {
public override SList<Uri> uris {
owned get {
return server.get_uris ();
}
Expand All @@ -240,36 +236,34 @@ namespace VSGI.HTTP {
public bool init (Cancellable? cancellable = null) throws GLib.Error {
if (https) {
server = new Soup.Server (
Soup.SERVER_RAW_PATHS, raw_paths,
Soup.SERVER_TLS_CERTIFICATE, tls_certificate);
"raw-paths", raw_paths,
"tls-certificate", tls_certificate);
} else {
server = new Soup.Server (
Soup.SERVER_RAW_PATHS, raw_paths,
Soup.SERVER_TLS_CERTIFICATE, tls_certificate);
server = new Soup.Server ("raw-paths", raw_paths);
}

// register a catch-all handler
server.add_handler (null, (server, msg, path, query, client) => {
msg.set_status (Soup.Status.OK);
server.add_handler (null, (server, msg, path, query) => {
msg.set_status (Soup.Status.OK, null);

// prevent I/O as we handle everything asynchronously
server.pause_message (msg);

var req = new Request (msg, client, query);
var req = new Request (msg, query);
var res = new Response (req, server, msg);

var auth = req.headers.get_one ("Authorization");
if (auth != null) {
if (Soup.str_case_equal (auth.slice (0, 6), "Basic ")) {
var auth_data = (string) Base64.decode (auth.substring (6));
if (auth_data.index_of_char (':') != -1) {
req.uri.set_user (auth_data.slice (0, auth.index_of_char (':')));
}
} else if (Soup.str_case_equal (auth.slice (0, 7), "Digest ")) {
var auth_data = Soup.header_parse_param_list (auth.substring (7));
req.uri.set_user (auth_data["username"]);
}
}
// if (auth != null) {
// if (VSGI.str_case_equal (auth.slice (0, 6), "Basic ")) {
// var auth_data = (string) Base64.decode (auth.substring (6));
// if (auth_data.index_of_char (':') != -1) {
// req.uri.set_user (auth_data.slice (0, auth.index_of_char (':')));
// }
// } else if (VSGI.str_case_equal (auth.slice (0, 7), "Digest ")) {
// var auth_data = Soup.header_parse_param_list (auth.substring (7));
// req.uri.set_user (auth_data["username"]);
// }
// }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things here: uri is immutable, so this is not a suitable approach and str_case_equal is not visible despite passing --vapi with the internal libvsgi Vala symbols.


handler.handle_async.begin (req, res, (obj, result) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion src/vsgi-application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public class VSGI.Application : GLib.Application {
}

foreach (var uri in server.uris) {
message ("Listening on '%s'.", uri.to_string (false));
message ("Listening on '%s'.", uri.to_string ());
}

// keep the process (and workers) alive
Expand Down
4 changes: 2 additions & 2 deletions src/vsgi-basic-authentication.vala
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public class VSGI.BasicAuthentication : Authentication {
return false;
}

if (!Soup.str_case_equal (header.slice (0, 5), "Basic")) {
if (!str_case_equal (header.slice (0, 5), "Basic")) {
return false;
}

var authorization_data = (string) Base64.decode (header.substring (6));

if (charset != null && !Soup.str_case_equal (charset, "UTF-8")) {
if (charset != null && !str_case_equal (charset, "UTF-8")) {
try {
authorization_data = convert (authorization_data, authorization_data.length, "UTF-8", charset);
} catch (ConvertError err) {
Expand Down
12 changes: 6 additions & 6 deletions src/vsgi-cookie-utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ namespace VSGI.CookieUtils {
public void sign (Soup.Cookie cookie, ChecksumType checksum_type, uint8[] key) {
var checksum = Hmac.compute_for_string (checksum_type,
key,
Hmac.compute_for_string (checksum_type, key, cookie.@value) + cookie.name);
Hmac.compute_for_string (checksum_type, key, cookie.get_value ()) + cookie.get_name ());

cookie.set_value (checksum + cookie.@value);
cookie.set_value (checksum + cookie.get_value ());
}

/**
Expand All @@ -63,19 +63,19 @@ namespace VSGI.CookieUtils {
public bool verify (Soup.Cookie cookie, ChecksumType checksum_type, uint8[] key, out string? @value) {
var checksum_length = Hmac.compute_for_string (checksum_type, key, "").length;

if (cookie.@value.length < checksum_length) {
if (cookie.get_value ().length < checksum_length) {
@value = null;
return false;
}

var checksum = Hmac.compute_for_string (checksum_type,
key,
Hmac.compute_for_string (checksum_type, key, cookie.@value.substring (checksum_length)) + cookie.name);
Hmac.compute_for_string (checksum_type, key, cookie.get_value ().substring (checksum_length)) + cookie.get_name ());

assert (checksum_length == checksum.length);

if (OpenSSL.Crypto.memcmp (checksum, cookie.@value, checksum_length) == 0) {
@value = cookie.@value.substring (checksum_length);
if (OpenSSL.Crypto.memcmp (checksum, cookie.get_value (), checksum_length) == 0) {
@value = cookie.get_value ().substring (checksum_length);
return true;
} else {
@value = null;
Expand Down
Loading