|
@@ -17,14 +17,8 @@
|
|
#include "cJSON.h"
|
|
#include "cJSON.h"
|
|
#include "civetweb.h"
|
|
#include "civetweb.h"
|
|
|
|
|
|
-
|
|
|
|
-#ifdef NO_SSL
|
|
|
|
#define PORT "8089"
|
|
#define PORT "8089"
|
|
#define HOST_INFO "http://localhost:8089"
|
|
#define HOST_INFO "http://localhost:8089"
|
|
-#else
|
|
|
|
-#define PORT "8089r,8843s"
|
|
|
|
-#define HOST_INFO "https://localhost:8843"
|
|
|
|
-#endif
|
|
|
|
|
|
|
|
#define EXAMPLE_URI "/example"
|
|
#define EXAMPLE_URI "/example"
|
|
#define EXIT_URI "/exit"
|
|
#define EXIT_URI "/exit"
|
|
@@ -65,7 +59,6 @@ ExampleGET(struct mg_connection *conn)
|
|
return 500;
|
|
return 500;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
cJSON_AddStringToObject(obj, "version", CIVETWEB_VERSION);
|
|
cJSON_AddStringToObject(obj, "version", CIVETWEB_VERSION);
|
|
cJSON_AddNumberToObject(obj, "request", ++request);
|
|
cJSON_AddNumberToObject(obj, "request", ++request);
|
|
SendJSON(conn, obj);
|
|
SendJSON(conn, obj);
|
|
@@ -140,22 +133,6 @@ ExamplePUT(struct mg_connection *conn)
|
|
|
|
|
|
|
|
|
|
static int
|
|
static int
|
|
-ExamplePOST(struct mg_connection *conn)
|
|
|
|
-{
|
|
|
|
- /* In this example, do the same for PUT and POST */
|
|
|
|
- return ExamplePUT(conn);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-static int
|
|
|
|
-ExamplePATCH(struct mg_connection *conn)
|
|
|
|
-{
|
|
|
|
- /* In this example, do the same for PUT and PATCH */
|
|
|
|
- return ExamplePUT(conn);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-static int
|
|
|
|
ExampleHandler(struct mg_connection *conn, void *cbdata)
|
|
ExampleHandler(struct mg_connection *conn, void *cbdata)
|
|
{
|
|
{
|
|
|
|
|
|
@@ -165,18 +142,15 @@ ExampleHandler(struct mg_connection *conn, void *cbdata)
|
|
if (0 == strcmp(ri->request_method, "GET")) {
|
|
if (0 == strcmp(ri->request_method, "GET")) {
|
|
return ExampleGET(conn);
|
|
return ExampleGET(conn);
|
|
}
|
|
}
|
|
- if (0 == strcmp(ri->request_method, "PUT")) {
|
|
|
|
|
|
+ if ((0 == strcmp(ri->request_method, "PUT"))
|
|
|
|
+ || (0 == strcmp(ri->request_method, "POST"))
|
|
|
|
+ || (0 == strcmp(ri->request_method, "PATCH"))) {
|
|
|
|
+ /* In this example, do the same for PUT, POST and PATCH */
|
|
return ExamplePUT(conn);
|
|
return ExamplePUT(conn);
|
|
}
|
|
}
|
|
- if (0 == strcmp(ri->request_method, "POST")) {
|
|
|
|
- return ExamplePOST(conn);
|
|
|
|
- }
|
|
|
|
if (0 == strcmp(ri->request_method, "DELETE")) {
|
|
if (0 == strcmp(ri->request_method, "DELETE")) {
|
|
return ExampleDELETE(conn);
|
|
return ExampleDELETE(conn);
|
|
}
|
|
}
|
|
- if (0 == strcmp(ri->request_method, "PATCH")) {
|
|
|
|
- return ExamplePATCH(conn);
|
|
|
|
- }
|
|
|
|
|
|
|
|
/* this is not a GET request */
|
|
/* this is not a GET request */
|
|
mg_send_http_error(
|
|
mg_send_http_error(
|
|
@@ -231,28 +205,9 @@ main(int argc, char *argv[])
|
|
struct mg_context *ctx;
|
|
struct mg_context *ctx;
|
|
int err = 0;
|
|
int err = 0;
|
|
|
|
|
|
-/* Check if libcivetweb has been built with all required features. */
|
|
|
|
-#ifndef NO_SSL
|
|
|
|
- if (!mg_check_feature(2)) {
|
|
|
|
- fprintf(stderr,
|
|
|
|
- "Error: Embedded example built with SSL support, "
|
|
|
|
- "but civetweb library build without.\n");
|
|
|
|
- err = 1;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- mg_init_library(MG_FEATURES_SSL);
|
|
|
|
-
|
|
|
|
-#else
|
|
|
|
|
|
+ /* Check if libcivetweb has been built with all required features. */
|
|
mg_init_library(0);
|
|
mg_init_library(0);
|
|
|
|
|
|
-#endif
|
|
|
|
- if (err) {
|
|
|
|
- fprintf(stderr, "Cannot start CivetWeb - inconsistent build.\n");
|
|
|
|
- return EXIT_FAILURE;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
/* Callback will print error messages to console */
|
|
/* Callback will print error messages to console */
|
|
memset(&callbacks, 0, sizeof(callbacks));
|
|
memset(&callbacks, 0, sizeof(callbacks));
|
|
callbacks.log_message = log_message;
|
|
callbacks.log_message = log_message;
|