Skip to content

Commit

Permalink
port to libsoup3
Browse files Browse the repository at this point in the history
Signed-off-by: Fabrice Fontaine <[email protected]>
  • Loading branch information
ffontaine committed Dec 27, 2023
1 parent 7889d82 commit 7e6d77f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
sudo apt update
sudo apt install automake libtool pkg-config libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
sudo apt install libglib2.0-dev libjson-glib-dev gtk-doc-tools libedit-dev libncursesw5-dev
sudo apt install libdaemon-dev libjansson-dev python3-pip python3-setuptools libsoup2.4-dev
sudo apt install libdaemon-dev libjansson-dev python3-pip python3-setuptools libsoup-3.0-dev
- name: Generate
run: ./autogen.sh
- name: Configure
Expand Down Expand Up @@ -72,7 +72,7 @@ jobs:
sudo apt update
sudo apt install automake libtool pkg-config libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
sudo apt install libglib2.0-dev libjson-glib-dev gtk-doc-tools libedit-dev libncursesw5-dev
sudo apt install libdaemon-dev libjansson-dev python3-pip python3-setuptools libsoup2.4-dev
sudo apt install libdaemon-dev libjansson-dev python3-pip python3-setuptools libsoup-3.0-dev
sudo apt install ninja-build python3-wheel
sudo pip3 install meson
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ PKG_CHECK_MODULES(GST, [
])
])

PKG_CHECK_MODULES(LIBSOUP, [libsoup-2.4 >= 2.32])
PKG_CHECK_MODULES(LIBSOUP, [libsoup-3.0 >= 2.99])
AC_SUBST(LIBSOUP_CFLAGS)
AC_SUBST(LIBSOUP_LIBS)

Expand Down
59 changes: 31 additions & 28 deletions libgstd/gstd_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ GST_DEBUG_CATEGORY_STATIC (gstd_http_debug);
typedef struct _GstdHttpRequest
{
SoupServer *server;
SoupMessage *msg;
SoupServerMessage *msg;
GstdSession *session;
const char *path;
GHashTable *query;
Expand Down Expand Up @@ -73,19 +73,18 @@ static GstdReturnCode gstd_http_stop (GstdIpc * base);
static gboolean gstd_http_init_get_option_group (GstdIpc * base,
GOptionGroup ** group);
static SoupStatus get_status_code (GstdReturnCode ret);
static GstdReturnCode do_get (SoupServer * server, SoupMessage * msg,
static GstdReturnCode do_get (SoupServer * server, SoupServerMessage * msg,
char **output, const char *path, GstdSession * session);
static GstdReturnCode do_post (SoupServer * server, SoupMessage * msg,
static GstdReturnCode do_post (SoupServer * server, SoupServerMessage * msg,
char *name, char *description, char **output, const char *path,
GstdSession * session);
static GstdReturnCode do_put (SoupServer * server, SoupMessage * msg,
static GstdReturnCode do_put (SoupServer * server, SoupServerMessage * msg,
char *name, char **output, const char *path, GstdSession * session);
static GstdReturnCode do_delete (SoupServer * server, SoupMessage * msg,
static GstdReturnCode do_delete (SoupServer * server, SoupServerMessage * msg,
char *name, char **output, const char *path, GstdSession * session);
static void do_request (gpointer data_request, gpointer eval);
static void server_callback (SoupServer * server, SoupMessage * msg,
const char *path, GHashTable * query, SoupClientContext * context,
gpointer data);
static void server_callback (SoupServer * server, SoupServerMessage * msg,
const char *path, GHashTable * query, gpointer data);

static void
gstd_http_class_init (GstdHttpClass * klass)
Expand Down Expand Up @@ -168,7 +167,7 @@ get_status_code (GstdReturnCode ret)
}

static GstdReturnCode
do_get (SoupServer * server, SoupMessage * msg, char **output, const char *path,
do_get (SoupServer * server, SoupServerMessage * msg, char **output, const char *path,
GstdSession * session)
{
gchar *message = NULL;
Expand All @@ -189,7 +188,7 @@ do_get (SoupServer * server, SoupMessage * msg, char **output, const char *path,
}

static GstdReturnCode
do_post (SoupServer * server, SoupMessage * msg, char *name,
do_post (SoupServer * server, SoupServerMessage * msg, char *name,
char *description, char **output, const char *path, GstdSession * session)
{
gchar *message = NULL;
Expand Down Expand Up @@ -224,7 +223,7 @@ do_post (SoupServer * server, SoupMessage * msg, char *name,
}

static GstdReturnCode
do_put (SoupServer * server, SoupMessage * msg, char *name, char **output,
do_put (SoupServer * server, SoupServerMessage * msg, char *name, char **output,
const char *path, GstdSession * session)
{
gchar *message = NULL;
Expand Down Expand Up @@ -254,7 +253,7 @@ do_put (SoupServer * server, SoupMessage * msg, char *name, char **output,
}

static GstdReturnCode
do_delete (SoupServer * server, SoupMessage * msg, char *name,
do_delete (SoupServer * server, SoupServerMessage * msg, char *name,
char **output, const char *path, GstdSession * session)
{
gchar *message = NULL;
Expand Down Expand Up @@ -294,11 +293,12 @@ do_request (gpointer data_request, gpointer eval)
const gchar *description = NULL;
SoupStatus status = SOUP_STATUS_OK;
SoupServer *server = NULL;
SoupMessage *msg = NULL;
SoupServerMessage *msg = NULL;
GstdSession *session = NULL;
const char *path = NULL;
GHashTable *query = NULL;
GstdHttpRequest *data_request_local = NULL;
const char *method;

g_return_if_fail (data_request);

Expand All @@ -316,15 +316,16 @@ do_request (gpointer data_request, gpointer eval)
description_pipe = g_hash_table_lookup (query, "description");
}

if (msg->method == SOUP_METHOD_GET) {
method = soup_server_message_get_method (msg);
if (method == SOUP_METHOD_GET) {
ret = do_get (server, msg, &output, path, session);
} else if (msg->method == SOUP_METHOD_POST) {
} else if (method == SOUP_METHOD_POST) {
ret = do_post (server, msg, name, description_pipe, &output, path, session);
} else if (msg->method == SOUP_METHOD_PUT) {
} else if (method == SOUP_METHOD_PUT) {
ret = do_put (server, msg, name, &output, path, session);
} else if (msg->method == SOUP_METHOD_DELETE) {
} else if (method == SOUP_METHOD_DELETE) {
ret = do_delete (server, msg, name, &output, path, session);
} else if (msg->method == SOUP_METHOD_OPTIONS) {
} else if (method == SOUP_METHOD_OPTIONS) {
ret = GSTD_EOK;
}

Expand All @@ -336,15 +337,15 @@ do_request (gpointer data_request, gpointer eval)
g_free (output);
output = NULL;

soup_message_set_response (msg, "application/json", SOUP_MEMORY_COPY,
soup_server_message_set_response (msg, "application/json", SOUP_MEMORY_COPY,
response, strlen (response));
g_free (response);
response = NULL;

status = get_status_code (ret);
soup_message_set_status (msg, status);
soup_server_message_set_status (msg, status, NULL);
g_mutex_lock (data_request_local->mutex);
soup_server_unpause_message (server, msg);
soup_server_message_unpause (msg);
g_mutex_unlock (data_request_local->mutex);

if (query != NULL) {
Expand All @@ -357,13 +358,14 @@ do_request (gpointer data_request, gpointer eval)
}

static void
server_callback (SoupServer * server, SoupMessage * msg,
server_callback (SoupServer * server, SoupServerMessage * msg,
const char *path, GHashTable * query,
SoupClientContext * context, gpointer data)
gpointer data)
{
GstdSession *session = NULL;
GstdHttp *self = NULL;
GstdHttpRequest *data_request = NULL;
SoupMessageHeaders *response_headers = NULL;

g_return_if_fail (server);
g_return_if_fail (msg);
Expand All @@ -385,14 +387,15 @@ server_callback (SoupServer * server, SoupMessage * msg,
}
data_request->mutex = &self->mutex;

soup_message_headers_append (msg->response_headers,
response_headers = soup_server_message_get_request_headers (msg);
soup_message_headers_append (response_headers,
"Access-Control-Allow-Origin", "*");
soup_message_headers_append (msg->response_headers,
soup_message_headers_append (response_headers,
"Access-Control-Allow-Headers", "origin,range,content-type");
soup_message_headers_append (msg->response_headers,
soup_message_headers_append (response_headers,
"Access-Control-Allow-Methods", "PUT, GET, POST, DELETE");
g_mutex_lock (&self->mutex);
soup_server_pause_message (server, msg);
soup_server_message_pause (msg);
g_mutex_unlock (&self->mutex);
if (!g_thread_pool_push (self->pool, (gpointer) data_request, NULL)) {
GST_ERROR_OBJECT (self->pool, "Thread pool push failed");
Expand Down Expand Up @@ -420,7 +423,7 @@ gstd_http_start (GstdIpc * base, GstdSession * session)
gstd_http_stop (base);

GST_DEBUG_OBJECT (self, "Initializing HTTP server");
self->server = soup_server_new (SOUP_SERVER_SERVER_HEADER, "Gstd-1.0", NULL);
self->server = soup_server_new ("server-header", "Gstd-1.0", NULL);
if (!self->server) {
goto noconnection;
}
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ json_glib_dep = dependency('json-glib-1.0', version : '>=0.16.2')
libd_dep = dependency('libdaemon', version : '>=0.14')
jansson_dep = dependency('jansson', version : '>=2.7')
thread_dep = dependency('threads')
libsoup_dep = dependency('libsoup-2.4', version : '>=2.4')
libsoup_dep = dependency('libsoup-3.0', version : '>=2.99')
libedit_dep = dependency('libedit', version : '>=3.0')

gst_check_required = get_option('enable-tests').enabled()
Expand Down

0 comments on commit 7e6d77f

Please sign in to comment.