Skip to content
Open
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
18 changes: 9 additions & 9 deletions examples/hello/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#
#
# Copyright (c) 2013 No Face Press, LLC
# License http://opensource.org/licenses/mit-license.php MIT License
#
Expand All @@ -10,27 +10,27 @@ PROG = hello
SRC = hello.c

TOP = ../..
CIVETWEB_LIB = libcivetweb.a
HTTP_LIB = libhttp.a

CFLAGS = -I$(TOP)/include $(COPT)
LIBS = -lpthread

include $(TOP)/resources/Makefile.in-os

ifeq ($(TARGET_OS),LINUX)
ifeq ($(TARGET_OS),LINUX)
LIBS += -ldl
endif

all: $(PROG)

$(PROG): $(CIVETWEB_LIB) $(SRC)
$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(SRC) $(CIVETWEB_LIB) $(LIBS)
$(PROG): $(HTTP_LIB) $(SRC)
$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(SRC) $(HTTP_LIB) $(LIBS)

$(CIVETWEB_LIB):
$(MAKE) -C $(TOP) clean lib
cp $(TOP)/$(CIVETWEB_LIB) .
$(HTTP_LIB):
$(MAKE) -C $(TOP)
cp $(TOP)/lib/$(HTTP_LIB) .

clean:
rm -f $(CIVETWEB_LIB) $(PROG)
rm -f $(HTTP_LIB) $(PROG)

.PHONY: all clean
20 changes: 10 additions & 10 deletions examples/hello/hello.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include <stdio.h>
#include <string.h>
#include "civetweb.h"
#include "libhttp.h"

// This function will be called by civetweb on every new request.
static int begin_request_handler(struct httplib_connection *conn)
// This function will be called by libhttp on every new request.
static int begin_request_handler(struct lh_ctx_t *ctx, struct lh_con_t *conn)
{
const struct httplib_request_info *request_info = httplib_get_request_info(conn);
const struct lh_rqi_t *request_info = httplib_get_request_info(conn);
char content[100];

// Prepare the message we're going to send
Expand All @@ -14,26 +14,26 @@ static int begin_request_handler(struct httplib_connection *conn)
request_info->remote_port);

// Send HTTP reply to the client
httplib_printf(conn,
httplib_printf(ctx,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.
// Returning non-zero tells libhttp that our function has replied to
// the client, and libhttp should not send client any more data.
return 1;
}

int main(void)
{
struct httplib_context *ctx;
struct httplib_callbacks callbacks;
struct lh_ctx_t *ctx;
struct lh_clb_t callbacks;

// List of options. Last element must be NULL.
const char *options[] = {"listening_ports", "8080", NULL};
struct lh_opt_t options[] = {(struct lh_opt_t){"listening_ports","8080"},{NULL}};

// Prepare callbacks structure. We have only one callback, the rest are NULL.
memset(&callbacks, 0, sizeof(callbacks));
Expand Down