Skip to content

Commit

Permalink
Add md5 (for HTTP Digest Auth)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpq committed Jan 2, 2015
1 parent 942d51d commit 1bab2b5
Show file tree
Hide file tree
Showing 17 changed files with 1,106 additions and 26 deletions.
3 changes: 2 additions & 1 deletion apps/api_server/api_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "db_plugin.h"

static const char *s_http_port = "8000";
static struct ns_serve_http_opts s_http_server_opts = { "web_root" };
static struct ns_serve_http_opts s_http_server_opts;
static int s_sig_num = 0;
static void *s_db_handle = NULL;
static const char *s_db_path = "api_server.db";
Expand Down Expand Up @@ -65,6 +65,7 @@ int main(int argc, char *argv[]) {
ns_mgr_init(&mgr, NULL);
nc = ns_bind(&mgr, s_http_port, ev_handler);
ns_set_protocol_http_websocket(nc);
s_http_server_opts.document_root = "web_root";

/* Parse command line arguments */
for (i = 1; i < argc; i++) {
Expand Down
2 changes: 2 additions & 0 deletions docs/build_opts.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ compile the application `my_app.c` like this (assumed UNIX system):
=== Disabling flags

- `NS_DISABLE_HTTP_WEBSOCKET` disable HTTP + Websocket protocol support
- `NS_DISABLE_HTTP_DIGEST_AUTH` disable HTTP Digest (MD5) authorization support
- `NS_DISABLE_MQTT` disable MQTT support
- `NS_DISABLE_SHA1` disable SHA1 support (used by Websocket)
- `NS_DISABLE_MD5` disable MD5 support (used by HTTP auth)
- `NS_DISABLE_JSON_RPC` disable JSON-RPC support
- `NS_DISABLE_SOCKETPAIR` disable `ns_broadcast()` API

Expand Down
2 changes: 1 addition & 1 deletion examples/http_client/http_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) {
exit(EXIT_FAILURE);
}

ns_connect_http(&mgr, ev_handler, argv[i], NULL);
ns_connect_http(&mgr, ev_handler, argv[i], NULL, NULL);

while (s_exit_flag == 0) {
ns_mgr_poll(&mgr, 1000);
Expand Down
3 changes: 2 additions & 1 deletion examples/raspberry_pi_mjpeg_led/cloud_side.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
#include "fossa.h"

static struct ns_serve_http_opts web_root_opts = { "./web_root" };
static struct ns_serve_http_opts web_root_opts;

/*
* Forwards the jpeg frame data to all open mjpeg connections.
Expand Down Expand Up @@ -129,6 +129,7 @@ int main(int argc, char *argv[]) {
exit(EXIT_FAILURE);
}
ns_set_protocol_http_websocket(nc);
web_root_opts.document_root = "./web_root";

/*
* We explicitly hand over control to the Fossa manager
Expand Down
20 changes: 18 additions & 2 deletions examples/restful_server/restful_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "fossa.h"

static const char *s_http_port = "8000";
static struct ns_serve_http_opts s_http_server_opts = { "." };
static struct ns_serve_http_opts s_http_server_opts;

static void handle_sum_call(struct ns_connection *nc, struct http_message *hm) {
char n1[100], n2[100];
Expand Down Expand Up @@ -44,11 +44,27 @@ static void ev_handler(struct ns_connection *nc, int ev, void *ev_data) {
int main(int argc, char *argv[]) {
struct ns_mgr mgr;
struct ns_connection *nc;
int i;

ns_mgr_init(&mgr, NULL);
nc = ns_bind(&mgr, s_http_port, ev_handler);
ns_set_protocol_http_websocket(nc);
mgr.hexdump_file = argc > 1 ? argv[1] : NULL; /* Allow hexdump debug */
s_http_server_opts.document_root = ".";

/* Process command line options to customize HTTP server */
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-D") == 0 && i + 1 < argc) {
mgr.hexdump_file = argv[++i];
} else if (strcmp(argv[i], "-d") == 0 && i + 1 < argc) {
s_http_server_opts.document_root = argv[++i];
} else if (strcmp(argv[i], "-a") == 0 && i + 1 < argc) {
s_http_server_opts.auth_domain = argv[++i];
} else if (strcmp(argv[i], "-P") == 0 && i + 1 < argc) {
s_http_server_opts.global_auth_file = argv[++i];
} else if (strcmp(argv[i], "-p") == 0 && i + 1 < argc) {
s_http_server_opts.per_directory_auth_file = argv[++i];
}
}

printf("Starting RESTful server on port %s\n", s_http_port);
for (;;) {
Expand Down
3 changes: 2 additions & 1 deletion examples/websocket_chat/websocket_chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

static sig_atomic_t s_signal_received = 0;
static const char *s_http_port = "8000";
static struct ns_serve_http_opts s_http_server_opts = { "." };
static struct ns_serve_http_opts s_http_server_opts;

static void signal_handler(int sig_num) {
signal(sig_num, signal_handler); // Reinstantiate signal handler
Expand Down Expand Up @@ -67,6 +67,7 @@ int main(void) {
ns_mgr_init(&mgr, NULL);

nc = ns_bind(&mgr, s_http_port, ev_handler);
s_http_server_opts.document_root = ".";
ns_set_protocol_http_websocket(nc);

printf("Started on port %s\n", s_http_port);
Expand Down
Loading

0 comments on commit 1bab2b5

Please sign in to comment.