Adding libsoup hello world.
This commit is contained in:
parent
82ffd20fc6
commit
c686c87f86
@ -3,7 +3,8 @@ project('depueblo', 'c')
|
||||
inc = include_directories('include')
|
||||
|
||||
depueblo_deps = [
|
||||
dependency('glib-2.0')
|
||||
dependency('glib-2.0'),
|
||||
dependency('libsoup-2.4'),
|
||||
]
|
||||
|
||||
sources = [
|
||||
|
41
src/main.c
41
src/main.c
@ -1,5 +1,40 @@
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
int main () {
|
||||
printf ("%s\n", "hello world");
|
||||
#include <libsoup/soup.h>
|
||||
|
||||
static void
|
||||
callback (SoupServer *server,
|
||||
SoupMessage *message,
|
||||
const char *path,
|
||||
GHashTable *query,
|
||||
SoupClientContext *context,
|
||||
gpointer user_data);
|
||||
int
|
||||
main () {
|
||||
SoupServer *soup_server = soup_server_new (NULL, NULL);
|
||||
GError *error = NULL;
|
||||
GMainLoop *loop;
|
||||
soup_server_add_handler (soup_server, "/", callback, NULL, NULL);
|
||||
soup_server_listen_local (soup_server, 8080, 0, &error);
|
||||
if (error) {
|
||||
g_error ("%s\n", error->message);
|
||||
return 1;
|
||||
}
|
||||
loop = g_main_loop_new (NULL, true);
|
||||
g_main_loop_run (loop);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
callback (SoupServer *server,
|
||||
SoupMessage *message,
|
||||
const char *path,
|
||||
GHashTable *query,
|
||||
SoupClientContext *context,
|
||||
gpointer user_data) {
|
||||
char *response_text = "Hello World";
|
||||
soup_message_set_status (message, 200);
|
||||
soup_message_set_response (message, "text/html", SOUP_MEMORY_COPY,
|
||||
response_text, (strlen (response_text))
|
||||
* sizeof *response_text);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user