summaryrefslogtreecommitdiffstats
path: root/src/civetweb/examples/_obsolete/hello
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/civetweb/examples/_obsolete/hello
parentInitial commit. (diff)
downloadceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz
ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/civetweb/examples/_obsolete/hello')
-rw-r--r--src/civetweb/examples/_obsolete/hello/Makefile36
-rw-r--r--src/civetweb/examples/_obsolete/hello/hello.c53
2 files changed, 89 insertions, 0 deletions
diff --git a/src/civetweb/examples/_obsolete/hello/Makefile b/src/civetweb/examples/_obsolete/hello/Makefile
new file mode 100644
index 00000000..4424e3b5
--- /dev/null
+++ b/src/civetweb/examples/_obsolete/hello/Makefile
@@ -0,0 +1,36 @@
+#
+# Copyright (c) 2013 No Face Press, LLC
+# License http://opensource.org/licenses/mit-license.php MIT License
+#
+
+#This makefile is used to test the other Makefiles
+
+
+PROG = hello
+SRC = hello.c
+
+TOP = ../..
+CIVETWEB_LIB = libcivetweb.a
+
+CFLAGS = -I$(TOP)/include $(COPT)
+LIBS = -lpthread
+
+include $(TOP)/resources/Makefile.in-os
+
+ifeq ($(TARGET_OS),LINUX)
+ LIBS += -ldl
+endif
+
+all: $(PROG)
+
+$(PROG): $(CIVETWEB_LIB) $(SRC)
+ $(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(SRC) $(CIVETWEB_LIB) $(LIBS)
+
+$(CIVETWEB_LIB):
+ $(MAKE) -C $(TOP) clean lib
+ cp $(TOP)/$(CIVETWEB_LIB) .
+
+clean:
+ rm -f $(CIVETWEB_LIB) $(PROG)
+
+.PHONY: all clean
diff --git a/src/civetweb/examples/_obsolete/hello/hello.c b/src/civetweb/examples/_obsolete/hello/hello.c
new file mode 100644
index 00000000..39253c1a
--- /dev/null
+++ b/src/civetweb/examples/_obsolete/hello/hello.c
@@ -0,0 +1,53 @@
+#include <stdio.h>
+#include <string.h>
+#include "civetweb.h"
+
+// This function will be called by civetweb on every new request.
+static int begin_request_handler(struct mg_connection *conn)
+{
+ const struct mg_request_info *request_info = mg_get_request_info(conn);
+ char content[100];
+
+ // Prepare the message we're going to send
+ int content_length = snprintf(content, sizeof(content),
+ "Hello from civetweb! Remote port: %d",
+ request_info->remote_port);
+
+ // Send HTTP reply to the client
+ mg_printf(conn,
+ "HTTP/1.1 200 OK\r\n"
+ "Content-Type: text/plain\r\n"
+ "Content-Length: %d\r\n" // Always set Content-Length
+ "\r\n"
+ "%s",
+ content_length, content);
+
+ // Returning non-zero tells civetweb that our function has replied to
+ // the client, and civetweb should not send client any more data.
+ return 1;
+}
+
+int main(void)
+{
+ struct mg_context *ctx;
+ struct mg_callbacks callbacks;
+
+ // List of options. Last element must be NULL.
+ const char *options[] = {"listening_ports", "8080", NULL};
+
+ // Prepare callbacks structure. We have only one callback, the rest are NULL.
+ memset(&callbacks, 0, sizeof(callbacks));
+ callbacks.begin_request = begin_request_handler;
+
+ // Start the web server.
+ ctx = mg_start(&callbacks, NULL, options);
+
+ // Wait until user hits "enter". Server is running in separate thread.
+ // Navigating to http://localhost:8080 will invoke begin_request_handler().
+ getchar();
+
+ // Stop the server.
+ mg_stop(ctx);
+
+ return 0;
+}