diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..da2efe8a --- /dev/null +++ b/Makefile @@ -0,0 +1,85 @@ +SRCS = $(wildcard src/*.c) +HDRS = $(wildcard src/*.h) +DEFS ?= -DMG_MAX_HTTP_HEADERS=5 -DMG_ENABLE_LINES -DMG_ENABLE_HTTP_DEBUG_ENDPOINT=1 +CFLAGS ?= -W -Wall -Werror -Isrc -I. -O0 -g $(DEFS) $(TFLAGS) $(EXTRA) +SSL ?= MBEDTLS +CDIR ?= $(realpath $(CURDIR)) +VC98 = docker run --rm -e WINEDEBUG=-all -v $(CDIR):$(CDIR) -w $(CDIR) docker.io/mdashnet/vc98 +VC2017 = docker run --rm -e WINEDEBUG=-all -v $(CDIR):$(CDIR) -w $(CDIR) docker.io/mdashnet/vc2017 +GCC = docker run --rm -v $(CDIR):$(CDIR) -w $(CDIR) mdashnet/cc2 +VCFLAGS = /nologo /W3 /O2 /I. $(DEFS) $(TFLAGS) +CLANG ?= /usr/local/opt/llvm\@9/bin/clang #-L/usr/local/opt/llvm\@8/lib +EXAMPLES := $(wildcard examples/*) +EXAMPLE_TARGET ?= example +.PHONY: $(EXAMPLES) + +ifeq "$(SSL)" "MBEDTLS" +MBEDTLSDIR ?= /usr/local/Cellar/mbedtls/2.23.0 +CFLAGS += -DMG_ENABLE_MBEDTLS=1 -I$(MBEDTLSDIR)/include +LDFLAGS ?= -L$(MBEDTLSDIR)/lib -lmbedtls -lmbedcrypto -lmbedx509 +endif +ifeq "$(SSL)" "OPENSSL" +OPENSSLDIR ?= /usr/local/Cellar/openssl@1.1/1.1.1g +CFLAGS += -DMG_ENABLE_OPENSSL=1 -I$(OPENSSLDIR)/include +LDFLAGS ?= -L$(OPENSSLDIR)/lib -lssl -lcrypto +endif + +all: mg_prefix cpp test ex vc98 vc2017 linux infer fuzz + +ex: $(EXAMPLES) +$(EXAMPLES): + @$(MAKE) -C $@ $(EXAMPLE_TARGET) + +# Check that all external (exported) symbols have "mg_" prefix +mg_prefix: mongoose.c mongoose.h + $(CLANG) mongoose.c $(CFLAGS) -c -o /tmp/x.o && nm /tmp/x.o | grep ' T' | grep -v 'mg_' ; test $$? = 1 + +# C++ build +cpp: CLANG = g++ -Wno-deprecated +cpp: unamalgamated + +# Make sure we can build from an unamalgamated sources +unamalgamated: $(SRCS) $(HDRS) Makefile + $(CLANG) src/*.c tests/unit_test.c $(CFLAGS) $(LDFLAGS) -g -o unit_test + +fuzz: mongoose.c mongoose.h Makefile tests/fuzz.c + $(CLANG) mongoose.c tests/fuzz.c $(CFLAGS) -DMG_ENABLE_LOG=0 -fsanitize=fuzzer,signed-integer-overflow,address $(LDFLAGS) -g -o fuzzer + $(DEBUGGER) ./fuzzer + +# make CC=/usr/local/opt/llvm\@8/bin/clang DEBUGGER=ASAN_OPTIONS=detect_leaks=1 +test: CFLAGS += -DMG_ENABLE_IPV6=1 -fsanitize=address#,undefined +test: mongoose.c mongoose.h clean Makefile tests/unit_test.c + $(CLANG) mongoose.c tests/unit_test.c $(CFLAGS) -coverage $(LDFLAGS) -g -o unit_test + ASAN_OPTIONS=detect_leaks=1 $(DEBUGGER) ./unit_test + +coverage: test + gcov -l -n *.gcno | sed '/^$$/d' | sed 'N;s/\n/ /' + +infer: + infer run -- cc tests/unit_test.c -c -W -Wall -Werror -Isrc -I. -O2 -DMG_ENABLE_MBEDTLS=1 -DMG_ENABLE_LINES -I/usr/local/Cellar/mbedtls/2.23.0/include -DMG_ENABLE_IPV6=1 -g -o /dev/null + +#vc98: VCFLAGS += -DMG_ENABLE_IPV6=1 +vc98: clean Makefile mongoose.c mongoose.h tests/unit_test.c + $(VC98) wine cl mongoose.c tests/unit_test.c $(VCFLAGS) ws2_32.lib /Fe$@.exe + $(VC98) wine $@.exe + +vc2017: CFLAGS += -DMG_ENABLE_IPV6=1 +vc2017: clean Makefile mongoose.c mongoose.h tests/unit_test.c + $(VC2017) wine64 cl mongoose.c tests/unit_test.c $(VCFLAGS) ws2_32.lib /Fe$@.exe + $(VC2017) wine64 $@.exe + +linux: CFLAGS += -DMG_ENABLE_IPV6=1 -fsanitize=address,undefined +linux: clean Makefile mongoose.c mongoose.h tests/unit_test.c + $(GCC) gcc mongoose.c tests/unit_test.c $(CFLAGS) $(LDFLAGS) -o unit_test_gcc + $(GCC) ./unit_test_gcc + +mongoose.c: $(SRCS) Makefile + (cat src/license.h; echo; echo '#include "mongoose.h"' ; (for F in src/private.h src/*.c ; do echo; echo '#ifdef MG_ENABLE_LINES'; echo "#line 1 \"$$F\""; echo '#endif'; cat $$F | sed -e 's,#include ".*,,'; done))> $@ + +mongoose.h: $(HDRS) Makefile + (cat src/license.h src/version.h ; cat src/arch.h src/arch_*.h src/config.h src/str.h src/log.h src/timer.h src/util.h src/url.h src/iobuf.h src/base64.h src/md5.h src/sha1.h src/event.h src/net.h src/http.h src/tls.h src/ws.h src/sntp.h src/mqtt.h src/dns.h | sed -e 's,#include ".*,,' -e 's,^#pragma once,,')> $@ + +clean: EXAMPLE_TARGET = clean +clean: $(EXAMPLES) + rm -rf $(PROG) *.o *.dSYM unit_test* ut fuzzer *.gcov *.gcno *.gcda *.obj *.exe *.ilk *.pdb slow-unit* _CL_* infer-out + diff --git a/docs/c-api/intro.md b/docs/c-api/intro.md deleted file mode 100644 index b6656ea5..00000000 --- a/docs/c-api/intro.md +++ /dev/null @@ -1,16 +0,0 @@ ---- -items: - - { name: mbuf.h } - - { name: mg_net.h } - - { name: mg_http.h } - - { name: mg_http_server.h } - - { name: mg_http_client.h } - - { name: mg_dns.h } - - { name: mg_dns_server.h } - - { name: mg_resolv.h } - - { name: mg_mqtt.h } - - { name: mg_mqtt_server.h } - - { name: mg_coap.h } - - { name: mg_util.h } - - { name: mg_uri.h } ---- diff --git a/docs/c-api/mbuf.h/intro.md b/docs/c-api/mbuf.h/intro.md deleted file mode 100644 index 600a1e09..00000000 --- a/docs/c-api/mbuf.h/intro.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -title: "mbuf.h" -symbol_kind: "intro" -decl_name: "mbuf.h" -items: - - { name: mbuf_append.md } - - { name: mbuf_append_and_free.md } - - { name: mbuf_clear.md } - - { name: mbuf_free.md } - - { name: mbuf_init.md } - - { name: mbuf_insert.md } - - { name: mbuf_move.md } - - { name: mbuf_remove.md } - - { name: mbuf_resize.md } - - { name: mbuf_trim.md } - - { name: struct_mbuf.md } ---- - -Mbufs are mutable/growing memory buffers, like C++ strings. -Mbuf can append data to the end of a buffer or insert data into arbitrary -position in the middle of a buffer. The buffer grows automatically when -needed. - diff --git a/docs/c-api/mbuf.h/mbuf_append.md b/docs/c-api/mbuf.h/mbuf_append.md deleted file mode 100644 index af0de26e..00000000 --- a/docs/c-api/mbuf.h/mbuf_append.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: "mbuf_append()" -decl_name: "mbuf_append" -symbol_kind: "func" -signature: | - size_t mbuf_append(struct mbuf *, const void *data, size_t data_size); ---- - -Appends data to the Mbuf. - -Returns the number of bytes appended or 0 if out of memory. - diff --git a/docs/c-api/mbuf.h/mbuf_append_and_free.md b/docs/c-api/mbuf.h/mbuf_append_and_free.md deleted file mode 100644 index e7be33ac..00000000 --- a/docs/c-api/mbuf.h/mbuf_append_and_free.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: "mbuf_append_and_free()" -decl_name: "mbuf_append_and_free" -symbol_kind: "func" -signature: | - size_t mbuf_append_and_free(struct mbuf *, void *data, size_t data_size); ---- - -Appends data to the Mbuf and frees it (data must be heap-allocated). - -Returns the number of bytes appended or 0 if out of memory. -data is freed irrespective of return value. - diff --git a/docs/c-api/mbuf.h/mbuf_clear.md b/docs/c-api/mbuf.h/mbuf_clear.md deleted file mode 100644 index afefc21a..00000000 --- a/docs/c-api/mbuf.h/mbuf_clear.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mbuf_clear()" -decl_name: "mbuf_clear" -symbol_kind: "func" -signature: | - void mbuf_clear(struct mbuf *); ---- - -Removes all the data from mbuf (if any). - diff --git a/docs/c-api/mbuf.h/mbuf_free.md b/docs/c-api/mbuf.h/mbuf_free.md deleted file mode 100644 index 6b5e455b..00000000 --- a/docs/c-api/mbuf.h/mbuf_free.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mbuf_free()" -decl_name: "mbuf_free" -symbol_kind: "func" -signature: | - void mbuf_free(struct mbuf *); ---- - -Frees the space allocated for the mbuffer and resets the mbuf structure. - diff --git a/docs/c-api/mbuf.h/mbuf_init.md b/docs/c-api/mbuf.h/mbuf_init.md deleted file mode 100644 index bc61ca0e..00000000 --- a/docs/c-api/mbuf.h/mbuf_init.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -title: "mbuf_init()" -decl_name: "mbuf_init" -symbol_kind: "func" -signature: | - void mbuf_init(struct mbuf *, size_t initial_capacity); ---- - -Initialises an Mbuf. -`initial_capacity` specifies the initial capacity of the mbuf. - diff --git a/docs/c-api/mbuf.h/mbuf_insert.md b/docs/c-api/mbuf.h/mbuf_insert.md deleted file mode 100644 index a38137a9..00000000 --- a/docs/c-api/mbuf.h/mbuf_insert.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: "mbuf_insert()" -decl_name: "mbuf_insert" -symbol_kind: "func" -signature: | - size_t mbuf_insert(struct mbuf *, size_t, const void *, size_t); ---- - -Inserts data at a specified offset in the Mbuf. - -Existing data will be shifted forwards and the buffer will -be grown if necessary. -Returns the number of bytes inserted. - diff --git a/docs/c-api/mbuf.h/mbuf_move.md b/docs/c-api/mbuf.h/mbuf_move.md deleted file mode 100644 index 61e20853..00000000 --- a/docs/c-api/mbuf.h/mbuf_move.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mbuf_move()" -decl_name: "mbuf_move" -symbol_kind: "func" -signature: | - void mbuf_move(struct mbuf *from, struct mbuf *to); ---- - -Moves the state from one mbuf to the other. - diff --git a/docs/c-api/mbuf.h/mbuf_remove.md b/docs/c-api/mbuf.h/mbuf_remove.md deleted file mode 100644 index cf3e502d..00000000 --- a/docs/c-api/mbuf.h/mbuf_remove.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mbuf_remove()" -decl_name: "mbuf_remove" -symbol_kind: "func" -signature: | - void mbuf_remove(struct mbuf *, size_t data_size); ---- - -Removes `data_size` bytes from the beginning of the buffer. - diff --git a/docs/c-api/mbuf.h/mbuf_resize.md b/docs/c-api/mbuf.h/mbuf_resize.md deleted file mode 100644 index 0814383f..00000000 --- a/docs/c-api/mbuf.h/mbuf_resize.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: "mbuf_resize()" -decl_name: "mbuf_resize" -symbol_kind: "func" -signature: | - void mbuf_resize(struct mbuf *, size_t new_size); ---- - -Resizes an Mbuf. - -If `new_size` is smaller than buffer's `len`, the -resize is not performed. - diff --git a/docs/c-api/mbuf.h/mbuf_trim.md b/docs/c-api/mbuf.h/mbuf_trim.md deleted file mode 100644 index 743b25f9..00000000 --- a/docs/c-api/mbuf.h/mbuf_trim.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mbuf_trim()" -decl_name: "mbuf_trim" -symbol_kind: "func" -signature: | - void mbuf_trim(struct mbuf *); ---- - -Shrinks an Mbuf by resizing its `size` to `len`. - diff --git a/docs/c-api/mbuf.h/struct_mbuf.md b/docs/c-api/mbuf.h/struct_mbuf.md deleted file mode 100644 index 98dcdc33..00000000 --- a/docs/c-api/mbuf.h/struct_mbuf.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: "struct mbuf" -decl_name: "struct mbuf" -symbol_kind: "struct" -signature: | - struct mbuf { - char *buf; /* Buffer pointer */ - size_t len; /* Data length. Data is located between offset 0 and len. */ - size_t size; /* Buffer size allocated by realloc(1). Must be >= len */ - }; ---- - -Memory buffer descriptor - diff --git a/docs/c-api/mg_coap.h/intro.md b/docs/c-api/mg_coap.h/intro.md deleted file mode 100644 index b3c1cdcc..00000000 --- a/docs/c-api/mg_coap.h/intro.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: "CoAP API reference" -symbol_kind: "intro" -decl_name: "mg_coap.h" -items: - - { name: mg_coap_add_option.md } - - { name: mg_coap_compose.md } - - { name: mg_coap_free_options.md } - - { name: mg_coap_parse.md } - - { name: mg_coap_send_ack.md } - - { name: mg_coap_send_message.md } - - { name: mg_set_protocol_coap.md } - - { name: struct_mg_coap_message.md } - - { name: struct_mg_coap_option.md } ---- - -CoAP message format: - -``` -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- -|Ver| T | TKL | Code | Message ID | Token (if any, TKL bytes) ... -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- -| Options (if any) ... |1 1 1 1 1 1 1 1| Payload (if any) ... -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- -``` - diff --git a/docs/c-api/mg_coap.h/mg_coap_add_option.md b/docs/c-api/mg_coap.h/mg_coap_add_option.md deleted file mode 100644 index 83e91d5f..00000000 --- a/docs/c-api/mg_coap.h/mg_coap_add_option.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: "mg_coap_add_option()" -decl_name: "mg_coap_add_option" -symbol_kind: "func" -signature: | - struct mg_coap_option *mg_coap_add_option(struct mg_coap_message *cm, - uint32_t number, char *value, - size_t len); ---- - -Adds a new option to mg_coap_message structure. -Returns pointer to the newly created option. -Note: options must be freed by using mg_coap_free_options - diff --git a/docs/c-api/mg_coap.h/mg_coap_compose.md b/docs/c-api/mg_coap.h/mg_coap_compose.md deleted file mode 100644 index 844c1b61..00000000 --- a/docs/c-api/mg_coap.h/mg_coap_compose.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: "mg_coap_compose()" -decl_name: "mg_coap_compose" -symbol_kind: "func" -signature: | - uint32_t mg_coap_compose(struct mg_coap_message *cm, struct mbuf *io); ---- - -Composes CoAP message from mg_coap_message structure. -This is a helper function. -Return value: see `mg_coap_send_message()` - diff --git a/docs/c-api/mg_coap.h/mg_coap_free_options.md b/docs/c-api/mg_coap.h/mg_coap_free_options.md deleted file mode 100644 index d429cf49..00000000 --- a/docs/c-api/mg_coap.h/mg_coap_free_options.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -title: "mg_coap_free_options()" -decl_name: "mg_coap_free_options" -symbol_kind: "func" -signature: | - void mg_coap_free_options(struct mg_coap_message *cm); ---- - -Frees the memory allocated for options. -If the cm parameter doesn't contain any option it does nothing. - diff --git a/docs/c-api/mg_coap.h/mg_coap_parse.md b/docs/c-api/mg_coap.h/mg_coap_parse.md deleted file mode 100644 index 86885229..00000000 --- a/docs/c-api/mg_coap.h/mg_coap_parse.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: "mg_coap_parse()" -decl_name: "mg_coap_parse" -symbol_kind: "func" -signature: | - uint32_t mg_coap_parse(struct mbuf *io, struct mg_coap_message *cm); ---- - -Parses CoAP message and fills mg_coap_message and returns cm->flags. -This is a helper function. - -NOTE: usually CoAP works over UDP, so lack of data means format error. -But, in theory, it is possible to use CoAP over TCP (according to RFC) - -The caller has to check results and treat COAP_NOT_ENOUGH_DATA according to -underlying protocol: - -- in case of UDP COAP_NOT_ENOUGH_DATA means COAP_FORMAT_ERROR, -- in case of TCP client can try to receive more data - -Return value: see `mg_coap_send_message()` - diff --git a/docs/c-api/mg_coap.h/mg_coap_send_ack.md b/docs/c-api/mg_coap.h/mg_coap_send_ack.md deleted file mode 100644 index 1475a9c5..00000000 --- a/docs/c-api/mg_coap.h/mg_coap_send_ack.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: "mg_coap_send_ack()" -decl_name: "mg_coap_send_ack" -symbol_kind: "func" -signature: | - uint32_t mg_coap_send_ack(struct mg_connection *nc, uint16_t msg_id); ---- - -Composes CoAP acknowledgement from `mg_coap_message` -and sends it into `nc` connection. -Return value: see `mg_coap_send_message()` - diff --git a/docs/c-api/mg_coap.h/mg_coap_send_message.md b/docs/c-api/mg_coap.h/mg_coap_send_message.md deleted file mode 100644 index a1acc01e..00000000 --- a/docs/c-api/mg_coap.h/mg_coap_send_message.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: "mg_coap_send_message()" -decl_name: "mg_coap_send_message" -symbol_kind: "func" -signature: | - uint32_t mg_coap_send_message(struct mg_connection *nc, - struct mg_coap_message *cm); ---- - -Composes a CoAP message from `mg_coap_message` -and sends it into `nc` connection. -Returns 0 on success. On error, it is a bitmask: - -- `#define MG_COAP_ERROR 0x10000` -- `#define MG_COAP_FORMAT_ERROR (MG_COAP_ERROR | 0x20000)` -- `#define MG_COAP_IGNORE (MG_COAP_ERROR | 0x40000)` -- `#define MG_COAP_NOT_ENOUGH_DATA (MG_COAP_ERROR | 0x80000)` -- `#define MG_COAP_NETWORK_ERROR (MG_COAP_ERROR | 0x100000)` - diff --git a/docs/c-api/mg_coap.h/mg_set_protocol_coap.md b/docs/c-api/mg_coap.h/mg_set_protocol_coap.md deleted file mode 100644 index 523ae7cb..00000000 --- a/docs/c-api/mg_coap.h/mg_set_protocol_coap.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_set_protocol_coap()" -decl_name: "mg_set_protocol_coap" -symbol_kind: "func" -signature: | - int mg_set_protocol_coap(struct mg_connection *nc); ---- - -Sets CoAP protocol handler - triggers CoAP specific events. - diff --git a/docs/c-api/mg_coap.h/struct_mg_coap_message.md b/docs/c-api/mg_coap.h/struct_mg_coap_message.md deleted file mode 100644 index 0ea618a9..00000000 --- a/docs/c-api/mg_coap.h/struct_mg_coap_message.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: "struct mg_coap_message" -decl_name: "struct mg_coap_message" -symbol_kind: "struct" -signature: | - struct mg_coap_message { - uint32_t flags; - uint8_t msg_type; - uint8_t code_class; - uint8_t code_detail; - uint16_t msg_id; - struct mg_str token; - struct mg_coap_option *options; - struct mg_str payload; - struct mg_coap_option *optiomg_tail; - }; ---- - -CoAP message. See RFC 7252 for details. - diff --git a/docs/c-api/mg_coap.h/struct_mg_coap_option.md b/docs/c-api/mg_coap.h/struct_mg_coap_option.md deleted file mode 100644 index b5eeb15f..00000000 --- a/docs/c-api/mg_coap.h/struct_mg_coap_option.md +++ /dev/null @@ -1,16 +0,0 @@ ---- -title: "struct mg_coap_option" -decl_name: "struct mg_coap_option" -symbol_kind: "struct" -signature: | - struct mg_coap_option { - struct mg_coap_option *next; - uint32_t number; - struct mg_str value; - }; ---- - -CoAP options. -Use mg_coap_add_option and mg_coap_free_options -for creation and destruction. - diff --git a/docs/c-api/mg_dns.h/intro.md b/docs/c-api/mg_dns.h/intro.md deleted file mode 100644 index 092332e8..00000000 --- a/docs/c-api/mg_dns.h/intro.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: "DNS API reference" -symbol_kind: "intro" -decl_name: "mg_dns.h" -items: - - { name: mg_dns_copy_questions.md } - - { name: mg_dns_encode_name.md } - - { name: mg_dns_encode_record.md } - - { name: mg_dns_insert_header.md } - - { name: mg_dns_parse_record_data.md } - - { name: mg_dns_uncompress_name.md } - - { name: mg_parse_dns.md } - - { name: mg_send_dns_query.md } - - { name: mg_set_protocol_dns.md } - - { name: struct_mg_dns_message.md } - - { name: struct_mg_dns_resource_record.md } ---- - - - diff --git a/docs/c-api/mg_dns.h/mg_dns_copy_questions.md b/docs/c-api/mg_dns.h/mg_dns_copy_questions.md deleted file mode 100644 index f6f7dcb7..00000000 --- a/docs/c-api/mg_dns.h/mg_dns_copy_questions.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -title: "mg_dns_copy_questions()" -decl_name: "mg_dns_copy_questions" -symbol_kind: "func" -signature: | - int mg_dns_copy_questions(struct mbuf *io, struct mg_dns_message *msg); ---- - -Appends already encoded questions from an existing message. - -This is useful when generating a DNS reply message which includes -all question records. - -Returns the number of appended bytes. - diff --git a/docs/c-api/mg_dns.h/mg_dns_encode_name.md b/docs/c-api/mg_dns.h/mg_dns_encode_name.md deleted file mode 100644 index 1b0e2a78..00000000 --- a/docs/c-api/mg_dns.h/mg_dns_encode_name.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_dns_encode_name()" -decl_name: "mg_dns_encode_name" -symbol_kind: "func" -signature: | - int mg_dns_encode_name(struct mbuf *io, const char *name, size_t len); ---- - -Encodes a DNS name. - diff --git a/docs/c-api/mg_dns.h/mg_dns_encode_record.md b/docs/c-api/mg_dns.h/mg_dns_encode_record.md deleted file mode 100644 index 7c9f2cf2..00000000 --- a/docs/c-api/mg_dns.h/mg_dns_encode_record.md +++ /dev/null @@ -1,25 +0,0 @@ ---- -title: "mg_dns_encode_record()" -decl_name: "mg_dns_encode_record" -symbol_kind: "func" -signature: | - int mg_dns_encode_record(struct mbuf *io, struct mg_dns_resource_record *rr, - const char *name, size_t nlen, const void *rdata, - size_t rlen); ---- - -Encodes and appends a DNS resource record to an IO buffer. - -The record metadata is taken from the `rr` parameter, while the name and data -are taken from the parameters, encoded in the appropriate format depending on -record type and stored in the IO buffer. The encoded values might contain -offsets within the IO buffer. It's thus important that the IO buffer doesn't -get trimmed while a sequence of records are encoded while preparing a DNS -reply. - -This function doesn't update the `name` and `rdata` pointers in the `rr` -struct because they might be invalidated as soon as the IO buffer grows -again. - -Returns the number of bytes appended or -1 in case of error. - diff --git a/docs/c-api/mg_dns.h/mg_dns_insert_header.md b/docs/c-api/mg_dns.h/mg_dns_insert_header.md deleted file mode 100644 index 52b2ac3e..00000000 --- a/docs/c-api/mg_dns.h/mg_dns_insert_header.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: "mg_dns_insert_header()" -decl_name: "mg_dns_insert_header" -symbol_kind: "func" -signature: | - int mg_dns_insert_header(struct mbuf *io, size_t pos, - struct mg_dns_message *msg); ---- - -Inserts a DNS header to an IO buffer. - -Returns the number of bytes inserted. - diff --git a/docs/c-api/mg_dns.h/mg_dns_parse_record_data.md b/docs/c-api/mg_dns.h/mg_dns_parse_record_data.md deleted file mode 100644 index efe56ef4..00000000 --- a/docs/c-api/mg_dns.h/mg_dns_parse_record_data.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: "mg_dns_parse_record_data()" -decl_name: "mg_dns_parse_record_data" -symbol_kind: "func" -signature: | - int mg_dns_parse_record_data(struct mg_dns_message *msg, - struct mg_dns_resource_record *rr, void *data, - size_t data_len); ---- - -Parses the record data from a DNS resource record. - - - A: struct in_addr *ina - - AAAA: struct in6_addr *ina - - CNAME: char buffer - -Returns -1 on error. - -TODO(mkm): MX - diff --git a/docs/c-api/mg_dns.h/mg_dns_uncompress_name.md b/docs/c-api/mg_dns.h/mg_dns_uncompress_name.md deleted file mode 100644 index 5e5fa53b..00000000 --- a/docs/c-api/mg_dns.h/mg_dns_uncompress_name.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -title: "mg_dns_uncompress_name()" -decl_name: "mg_dns_uncompress_name" -symbol_kind: "func" -signature: | - size_t mg_dns_uncompress_name(struct mg_dns_message *msg, struct mg_str *name, - char *dst, int dst_len); ---- - -Uncompresses a DNS compressed name. - -The containing DNS message is required because of the compressed encoding -and reference suffixes present elsewhere in the packet. - -If the name is less than `dst_len` characters long, the remainder -of `dst` is terminated with `\0` characters. Otherwise, `dst` is not -terminated. - -If `dst_len` is 0 `dst` can be NULL. -Returns the uncompressed name length. - diff --git a/docs/c-api/mg_dns.h/mg_parse_dns.md b/docs/c-api/mg_dns.h/mg_parse_dns.md deleted file mode 100644 index 3e28efee..00000000 --- a/docs/c-api/mg_dns.h/mg_parse_dns.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_parse_dns()" -decl_name: "mg_parse_dns" -symbol_kind: "func" -signature: | - int mg_parse_dns(const char *buf, int len, struct mg_dns_message *msg); ---- - -Low-level: parses a DNS response. - diff --git a/docs/c-api/mg_dns.h/mg_send_dns_query.md b/docs/c-api/mg_dns.h/mg_send_dns_query.md deleted file mode 100644 index a6b15da9..00000000 --- a/docs/c-api/mg_dns.h/mg_send_dns_query.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -title: "mg_send_dns_query()" -decl_name: "mg_send_dns_query" -symbol_kind: "func" -signature: | - void mg_send_dns_query(struct mg_connection *nc, const char *name, - int query_type); ---- - -Sends a DNS query to the remote end. - diff --git a/docs/c-api/mg_dns.h/mg_set_protocol_dns.md b/docs/c-api/mg_dns.h/mg_set_protocol_dns.md deleted file mode 100644 index fdf5ab59..00000000 --- a/docs/c-api/mg_dns.h/mg_set_protocol_dns.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: "mg_set_protocol_dns()" -decl_name: "mg_set_protocol_dns" -symbol_kind: "func" -signature: | - void mg_set_protocol_dns(struct mg_connection *nc); ---- - -Attaches a built-in DNS event handler to the given listening connection. - -The DNS event handler parses the incoming UDP packets, treating them as DNS -requests. If an incoming packet gets successfully parsed by the DNS event -handler, a user event handler will receive an `MG_DNS_REQUEST` event, with -`ev_data` pointing to the parsed `struct mg_dns_message`. - -See -[captive_dns_server](https://github.com/cesanta/mongoose/tree/master/examples/captive_dns_server) -example on how to handle DNS request and send DNS reply. - diff --git a/docs/c-api/mg_dns.h/struct_mg_dns_message.md b/docs/c-api/mg_dns.h/struct_mg_dns_message.md deleted file mode 100644 index 9838bec9..00000000 --- a/docs/c-api/mg_dns.h/struct_mg_dns_message.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: "struct mg_dns_message" -decl_name: "struct mg_dns_message" -symbol_kind: "struct" -signature: | - struct mg_dns_message { - struct mg_str pkt; /* packet body */ - uint16_t flags; - uint16_t transaction_id; - int num_questions; - int num_answers; - struct mg_dns_resource_record questions[MG_MAX_DNS_QUESTIONS]; - struct mg_dns_resource_record answers[MG_MAX_DNS_ANSWERS]; - }; ---- - -DNS message (request and response). - diff --git a/docs/c-api/mg_dns.h/struct_mg_dns_resource_record.md b/docs/c-api/mg_dns.h/struct_mg_dns_resource_record.md deleted file mode 100644 index 8ff7af40..00000000 --- a/docs/c-api/mg_dns.h/struct_mg_dns_resource_record.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: "struct mg_dns_resource_record" -decl_name: "struct mg_dns_resource_record" -symbol_kind: "struct" -signature: | - struct mg_dns_resource_record { - struct mg_str name; /* buffer with compressed name */ - int rtype; - int rclass; - int ttl; - enum mg_dns_resource_record_kind kind; - struct mg_str rdata; /* protocol data (can be a compressed name) */ - }; ---- - -DNS resource record. - diff --git a/docs/c-api/mg_dns_server.h/intro.md b/docs/c-api/mg_dns_server.h/intro.md deleted file mode 100644 index d83bb40a..00000000 --- a/docs/c-api/mg_dns_server.h/intro.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: "DNS server API reference" -symbol_kind: "intro" -decl_name: "mg_dns_server.h" -items: - - { name: mg_dns_create_reply.md } - - { name: mg_dns_reply_record.md } - - { name: mg_dns_send_reply.md } ---- - -Disabled by default; enable with `-DMG_ENABLE_DNS_SERVER`. - diff --git a/docs/c-api/mg_dns_server.h/mg_dns_create_reply.md b/docs/c-api/mg_dns_server.h/mg_dns_create_reply.md deleted file mode 100644 index 40c6f225..00000000 --- a/docs/c-api/mg_dns_server.h/mg_dns_create_reply.md +++ /dev/null @@ -1,36 +0,0 @@ ---- -title: "mg_dns_create_reply()" -decl_name: "mg_dns_create_reply" -symbol_kind: "func" -signature: | - struct mg_dns_reply mg_dns_create_reply(struct mbuf *io, - struct mg_dns_message *msg); ---- - -Creates a DNS reply. - -The reply will be based on an existing query message `msg`. -The query body will be appended to the output buffer. -"reply + recursion allowed" will be added to the message flags and the -message's num_answers will be set to 0. - -Answer records can be appended with `mg_dns_send_reply` or by lower -level function defined in the DNS API. - -In order to send a reply use `mg_dns_send_reply`. -It's possible to use a connection's send buffer as reply buffer, -and it will work for both UDP and TCP connections. - -Example: - -```c -reply = mg_dns_create_reply(&nc->send_mbuf, msg); -for (i = 0; i < msg->num_questions; i++) { - rr = &msg->questions[i]; - if (rr->rtype == MG_DNS_A_RECORD) { - mg_dns_reply_record(&reply, rr, 3600, &dummy_ip_addr, 4); - } -} -mg_dns_send_reply(nc, &reply); -``` - diff --git a/docs/c-api/mg_dns_server.h/mg_dns_reply_record.md b/docs/c-api/mg_dns_server.h/mg_dns_reply_record.md deleted file mode 100644 index 408f705f..00000000 --- a/docs/c-api/mg_dns_server.h/mg_dns_reply_record.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: "mg_dns_reply_record()" -decl_name: "mg_dns_reply_record" -symbol_kind: "func" -signature: | - int mg_dns_reply_record(struct mg_dns_reply *reply, - struct mg_dns_resource_record *question, - const char *name, int rtype, int ttl, const void *rdata, - size_t rdata_len); ---- - -Appends a DNS reply record to the IO buffer and to the DNS message. - -The message's num_answers field will be incremented. It's the caller's duty -to ensure num_answers is properly initialised. - -Returns -1 on error. - diff --git a/docs/c-api/mg_dns_server.h/mg_dns_send_reply.md b/docs/c-api/mg_dns_server.h/mg_dns_send_reply.md deleted file mode 100644 index 0460e731..00000000 --- a/docs/c-api/mg_dns_server.h/mg_dns_send_reply.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: "mg_dns_send_reply()" -decl_name: "mg_dns_send_reply" -symbol_kind: "func" -signature: | - void mg_dns_send_reply(struct mg_connection *nc, struct mg_dns_reply *r); ---- - -Sends a DNS reply through a connection. - -The DNS data is stored in an IO buffer pointed by reply structure in `r`. -This function mutates the content of that buffer in order to ensure that -the DNS header reflects the size and flags of the message, that might have -been updated either with `mg_dns_reply_record` or by direct manipulation of -`r->message`. - -Once sent, the IO buffer will be trimmed unless the reply IO buffer -is the connection's send buffer and the connection is not in UDP mode. - diff --git a/docs/c-api/mg_http.h/intro.md b/docs/c-api/mg_http.h/intro.md deleted file mode 100644 index 79b4f0fd..00000000 --- a/docs/c-api/mg_http.h/intro.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: "Common API reference" -symbol_kind: "intro" -decl_name: "mg_http.h" -items: - - { name: mg_connect_ws.md } - - { name: mg_connect_ws_opt.md } - - { name: mg_http_is_authorized.md } - - { name: mg_http_send_digest_auth_request.md } - - { name: mg_printf_websocket_frame.md } - - { name: mg_send_websocket_frame.md } - - { name: mg_send_websocket_framev.md } - - { name: mg_send_websocket_handshake.md } - - { name: mg_send_websocket_handshake2.md } - - { name: mg_send_websocket_handshake3.md } - - { name: mg_send_websocket_handshake3v.md } - - { name: mg_set_protocol_http_websocket.md } - - { name: mg_url_decode.md } - - { name: struct_http_message.md } - - { name: struct_mg_http_multipart_part.md } - - { name: struct_mg_ssi_call_ctx.md } - - { name: struct_websocket_message.md } ---- - - - diff --git a/docs/c-api/mg_http.h/mg_connect_ws.md b/docs/c-api/mg_http.h/mg_connect_ws.md deleted file mode 100644 index 7a5b517d..00000000 --- a/docs/c-api/mg_http.h/mg_connect_ws.md +++ /dev/null @@ -1,29 +0,0 @@ ---- -title: "mg_connect_ws()" -decl_name: "mg_connect_ws" -symbol_kind: "func" -signature: | - struct mg_connection *mg_connect_ws(struct mg_mgr *mgr, - MG_CB(mg_event_handler_t event_handler, - void *user_data); ---- - -Helper function that creates an outbound WebSocket connection. - -`url` is a URL to connect to. It must be properly URL-encoded, e.g. have -no spaces, etc. By default, `mg_connect_ws()` sends Connection and -Host headers. `extra_headers` is an extra HTTP header to send, e.g. -`"User-Agent: my-app\r\n"`. -If `protocol` is not NULL, then a `Sec-WebSocket-Protocol` header is sent. - -Examples: - -```c - nc1 = mg_connect_ws(mgr, ev_handler_1, "ws://echo.websocket.org", NULL, - NULL); - nc2 = mg_connect_ws(mgr, ev_handler_1, "wss://echo.websocket.org", NULL, - NULL); - nc3 = mg_connect_ws(mgr, ev_handler_1, "ws://api.cesanta.com", - "clubby.cesanta.com", NULL); -``` - diff --git a/docs/c-api/mg_http.h/mg_connect_ws_opt.md b/docs/c-api/mg_http.h/mg_connect_ws_opt.md deleted file mode 100644 index e2203cff..00000000 --- a/docs/c-api/mg_http.h/mg_connect_ws_opt.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: "mg_connect_ws_opt()" -decl_name: "mg_connect_ws_opt" -symbol_kind: "func" -signature: | - struct mg_connection *mg_connect_ws_opt( - struct mg_mgr *mgr, MG_CB(mg_event_handler_t ev_handler, void *user_data); ---- - -Helper function that creates an outbound WebSocket connection - -Mostly identical to `mg_connect_ws`, but allows to provide extra parameters -(for example, SSL parameters) - diff --git a/docs/c-api/mg_http.h/mg_http_is_authorized.md b/docs/c-api/mg_http.h/mg_http_is_authorized.md deleted file mode 100644 index 97f029ab..00000000 --- a/docs/c-api/mg_http.h/mg_http_is_authorized.md +++ /dev/null @@ -1,16 +0,0 @@ ---- -title: "mg_http_is_authorized()" -decl_name: "mg_http_is_authorized" -symbol_kind: "func" -signature: | - int mg_http_is_authorized(struct http_message *hm, struct mg_str path, - const char *domain, const char *passwords_file, - int flags); ---- - -Checks whether an http request is authorized. `domain` is the authentication -realm, `passwords_file` is a htdigest file (can be created e.g. with -`htdigest` utility). If either `domain` or `passwords_file` is NULL, this -function always returns 1; otherwise checks the authentication in the -http request and returns 1 only if there is a match; 0 otherwise. - diff --git a/docs/c-api/mg_http.h/mg_http_send_digest_auth_request.md b/docs/c-api/mg_http.h/mg_http_send_digest_auth_request.md deleted file mode 100644 index 77b7f051..00000000 --- a/docs/c-api/mg_http.h/mg_http_send_digest_auth_request.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -title: "mg_http_send_digest_auth_request()" -decl_name: "mg_http_send_digest_auth_request" -symbol_kind: "func" -signature: | - void mg_http_send_digest_auth_request(struct mg_connection *c, - const char *domain); ---- - -Sends 401 Unauthorized response. - diff --git a/docs/c-api/mg_http.h/mg_printf_websocket_frame.md b/docs/c-api/mg_http.h/mg_printf_websocket_frame.md deleted file mode 100644 index a7e8944b..00000000 --- a/docs/c-api/mg_http.h/mg_printf_websocket_frame.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: "mg_printf_websocket_frame()" -decl_name: "mg_printf_websocket_frame" -symbol_kind: "func" -signature: | - void mg_printf_websocket_frame(struct mg_connection *nc, int op_and_flags, - const char *fmt, ...); ---- - -Sends WebSocket frame to the remote end. - -Like `mg_send_websocket_frame()`, but allows to create formatted messages -with `printf()`-like semantics. - diff --git a/docs/c-api/mg_http.h/mg_send_websocket_frame.md b/docs/c-api/mg_http.h/mg_send_websocket_frame.md deleted file mode 100644 index 8a407a68..00000000 --- a/docs/c-api/mg_http.h/mg_send_websocket_frame.md +++ /dev/null @@ -1,26 +0,0 @@ ---- -title: "mg_send_websocket_frame()" -decl_name: "mg_send_websocket_frame" -symbol_kind: "func" -signature: | - void mg_send_websocket_frame(struct mg_connection *nc, int op_and_flags, - const void *data, size_t data_len); ---- - -Send WebSocket frame to the remote end. - -`op_and_flags` specifies the frame's type. It's one of: - -- WEBSOCKET_OP_CONTINUE -- WEBSOCKET_OP_TEXT -- WEBSOCKET_OP_BINARY -- WEBSOCKET_OP_CLOSE -- WEBSOCKET_OP_PING -- WEBSOCKET_OP_PONG - -Orred with one of the flags: - -- WEBSOCKET_DONT_FIN: Don't set the FIN flag on the frame to be sent. - -`data` and `data_len` contain frame data. - diff --git a/docs/c-api/mg_http.h/mg_send_websocket_framev.md b/docs/c-api/mg_http.h/mg_send_websocket_framev.md deleted file mode 100644 index ae7da380..00000000 --- a/docs/c-api/mg_http.h/mg_send_websocket_framev.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: "mg_send_websocket_framev()" -decl_name: "mg_send_websocket_framev" -symbol_kind: "func" -signature: | - void mg_send_websocket_framev(struct mg_connection *nc, int op_and_flags, - const struct mg_str *strings, int num_strings); ---- - -Like `mg_send_websocket_frame()`, but composes a single frame from multiple -buffers. - diff --git a/docs/c-api/mg_http.h/mg_send_websocket_handshake.md b/docs/c-api/mg_http.h/mg_send_websocket_handshake.md deleted file mode 100644 index 20ee7017..00000000 --- a/docs/c-api/mg_http.h/mg_send_websocket_handshake.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: "mg_send_websocket_handshake()" -decl_name: "mg_send_websocket_handshake" -symbol_kind: "func" -signature: | - void mg_send_websocket_handshake(struct mg_connection *nc, const char *uri, - const char *extra_headers); ---- - -Send websocket handshake to the server. - -`nc` must be a valid connection, connected to a server. `uri` is an URI -to fetch, extra_headers` is extra HTTP headers to send or `NULL`. - -This function is intended to be used by websocket client. - -Note that the Host header is mandatory in HTTP/1.1 and must be -included in `extra_headers`. `mg_send_websocket_handshake2` offers -a better API for that. - -Deprecated in favour of `mg_send_websocket_handshake2` - diff --git a/docs/c-api/mg_http.h/mg_send_websocket_handshake2.md b/docs/c-api/mg_http.h/mg_send_websocket_handshake2.md deleted file mode 100644 index 27c5c3b8..00000000 --- a/docs/c-api/mg_http.h/mg_send_websocket_handshake2.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: "mg_send_websocket_handshake2()" -decl_name: "mg_send_websocket_handshake2" -symbol_kind: "func" -signature: | - void mg_send_websocket_handshake2(struct mg_connection *nc, const char *path, - const char *host, const char *protocol, - const char *extra_headers); ---- - -Send websocket handshake to the server. - -`nc` must be a valid connection, connected to a server. `uri` is an URI -to fetch, `host` goes into the `Host` header, `protocol` goes into the -`Sec-WebSocket-Proto` header (NULL to omit), extra_headers` is extra HTTP -headers to send or `NULL`. - -This function is intended to be used by websocket client. - diff --git a/docs/c-api/mg_http.h/mg_send_websocket_handshake3.md b/docs/c-api/mg_http.h/mg_send_websocket_handshake3.md deleted file mode 100644 index 57abb620..00000000 --- a/docs/c-api/mg_http.h/mg_send_websocket_handshake3.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: "mg_send_websocket_handshake3()" -decl_name: "mg_send_websocket_handshake3" -symbol_kind: "func" -signature: | - void mg_send_websocket_handshake3(struct mg_connection *nc, const char *path, - const char *host, const char *protocol, - const char *extra_headers, const char *user, - const char *pass); ---- - -Like mg_send_websocket_handshake2 but also passes basic auth header - diff --git a/docs/c-api/mg_http.h/mg_send_websocket_handshake3v.md b/docs/c-api/mg_http.h/mg_send_websocket_handshake3v.md deleted file mode 100644 index acf8c1e6..00000000 --- a/docs/c-api/mg_http.h/mg_send_websocket_handshake3v.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: "mg_send_websocket_handshake3v()" -decl_name: "mg_send_websocket_handshake3v" -symbol_kind: "func" -signature: | - void mg_send_websocket_handshake3v(struct mg_connection *nc, - const struct mg_str path, - const struct mg_str host, - const struct mg_str protocol, - const struct mg_str extra_headers, - const struct mg_str user, - const struct mg_str pass); ---- - -Same as mg_send_websocket_handshake3 but with strings not necessarily -NUL-temrinated - diff --git a/docs/c-api/mg_http.h/mg_set_protocol_http_websocket.md b/docs/c-api/mg_http.h/mg_set_protocol_http_websocket.md deleted file mode 100644 index 7320ae76..00000000 --- a/docs/c-api/mg_http.h/mg_set_protocol_http_websocket.md +++ /dev/null @@ -1,61 +0,0 @@ ---- -title: "mg_set_protocol_http_websocket()" -decl_name: "mg_set_protocol_http_websocket" -symbol_kind: "func" -signature: | - void mg_set_protocol_http_websocket(struct mg_connection *nc); ---- - -Attaches a built-in HTTP event handler to the given connection. -The user-defined event handler will receive following extra events: - -- MG_EV_HTTP_REQUEST: HTTP request has arrived. Parsed HTTP request - is passed as - `struct http_message` through the handler's `void *ev_data` pointer. -- MG_EV_HTTP_REPLY: The HTTP reply has arrived. The parsed HTTP reply is - passed as `struct http_message` through the handler's `void *ev_data` - pointer. -- MG_EV_HTTP_CHUNK: The HTTP chunked-encoding chunk has arrived. - The parsed HTTP reply is passed as `struct http_message` through the - handler's `void *ev_data` pointer. `http_message::body` would contain - incomplete, reassembled HTTP body. - It will grow with every new chunk that arrives, and it can - potentially consume a lot of memory. An event handler may process - the body as chunks are coming, and signal Mongoose to delete processed - body by setting `MG_F_DELETE_CHUNK` in `mg_connection::flags`. When - the last zero chunk is received, - Mongoose sends `MG_EV_HTTP_REPLY` event with - full reassembled body (if handler did not signal to delete chunks) or - with empty body (if handler did signal to delete chunks). -- MG_EV_WEBSOCKET_HANDSHAKE_REQUEST: server has received the WebSocket - handshake request. `ev_data` contains parsed HTTP request. -- MG_EV_WEBSOCKET_HANDSHAKE_DONE: server has completed the WebSocket - handshake. `ev_data` is a `struct http_message` containing the - client's request (server mode) or server's response (client). - In client mode handler can examine `resp_code`, which should be 101. -- MG_EV_WEBSOCKET_FRAME: new WebSocket frame has arrived. `ev_data` is - `struct websocket_message *` - -When compiled with MG_ENABLE_HTTP_STREAMING_MULTIPART, Mongoose parses -multipart requests and splits them into separate events: -- MG_EV_HTTP_MULTIPART_REQUEST: Start of the request. - This event is sent before body is parsed. After this, the user - should expect a sequence of PART_BEGIN/DATA/END requests. - This is also the last time when headers and other request fields are - accessible. -- MG_EV_HTTP_PART_BEGIN: Start of a part of a multipart message. - Argument: mg_http_multipart_part with var_name and file_name set - (if present). No data is passed in this message. -- MG_EV_HTTP_PART_DATA: new portion of data from the multipart message. - Argument: mg_http_multipart_part. var_name and file_name are preserved, - data is available in mg_http_multipart_part.data. -- MG_EV_HTTP_PART_END: End of the current part. var_name, file_name are - the same, no data in the message. If status is 0, then the part is - properly terminated with a boundary, status < 0 means that connection - was terminated. -- MG_EV_HTTP_MULTIPART_REQUEST_END: End of the multipart request. - Argument: mg_http_multipart_part, var_name and file_name are NULL, - status = 0 means request was properly closed, < 0 means connection - was terminated (note: in this case both PART_END and REQUEST_END are - delivered). - diff --git a/docs/c-api/mg_http.h/mg_url_decode.md b/docs/c-api/mg_http.h/mg_url_decode.md deleted file mode 100644 index 454acd03..00000000 --- a/docs/c-api/mg_http.h/mg_url_decode.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: "mg_url_decode()" -decl_name: "mg_url_decode" -symbol_kind: "func" -signature: | - int mg_url_decode(const char *src, int src_len, char *dst, int dst_len, - int is_form_url_encoded); ---- - -Decodes a URL-encoded string. - -Source string is specified by (`src`, `src_len`), and destination is -(`dst`, `dst_len`). If `is_form_url_encoded` is non-zero, then -`+` character is decoded as a blank space character. This function -guarantees to NUL-terminate the destination. If destination is too small, -then the source string is partially decoded and `-1` is returned. -*Otherwise, -a length of the decoded string is returned, not counting final NUL. - diff --git a/docs/c-api/mg_http.h/struct_http_message.md b/docs/c-api/mg_http.h/struct_http_message.md deleted file mode 100644 index 0f53a7a6..00000000 --- a/docs/c-api/mg_http.h/struct_http_message.md +++ /dev/null @@ -1,42 +0,0 @@ ---- -title: "struct http_message" -decl_name: "struct http_message" -symbol_kind: "struct" -signature: | - struct http_message { - struct mg_str message; /* Whole message: request line + headers + body */ - struct mg_str body; /* Message body. 0-length for requests with no body */ - - /* HTTP Request line (or HTTP response line) */ - struct mg_str method; /* "GET" */ - struct mg_str uri; /* "/my_file.html" */ - struct mg_str proto; /* "HTTP/1.1" -- for both request and response */ - - /* For responses, code and response status message are set */ - int resp_code; - struct mg_str resp_status_msg; - - /* - * Query-string part of the URI. For example, for HTTP request - * GET /foo/bar?param1=val1¶m2=val2 - * | uri | query_string | - * - * Note that question mark character doesn't belong neither to the uri, - * nor to the query_string - */ - struct mg_str query_string; - - /* Headers */ - struct mg_str header_names[MG_MAX_HTTP_HEADERS]; - struct mg_str header_values[MG_MAX_HTTP_HEADERS]; - - /* - * Value of the Content-Length header if present, - * otherwise MG_HTTP_CONTENT_LENGTH_UNKNOWN. - */ - size_t content_length; - }; ---- - -HTTP message - diff --git a/docs/c-api/mg_http.h/struct_mg_http_multipart_part.md b/docs/c-api/mg_http.h/struct_mg_http_multipart_part.md deleted file mode 100644 index ec65f9d9..00000000 --- a/docs/c-api/mg_http.h/struct_mg_http_multipart_part.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: "struct mg_http_multipart_part" -decl_name: "struct mg_http_multipart_part" -symbol_kind: "struct" -signature: | - struct mg_http_multipart_part { - const char *file_name; - const char *var_name; - struct mg_str data; - int status; /* <0 on error */ - void *user_data; - /* - * User handler can indicate how much of the data was consumed - * by setting this variable. By default, it is assumed that all - * data has been consumed by the handler. - * If not all data was consumed, user's handler will be invoked again later - * with the remainder. - */ - size_t num_data_consumed; - }; ---- - -HTTP multipart part - diff --git a/docs/c-api/mg_http.h/struct_mg_ssi_call_ctx.md b/docs/c-api/mg_http.h/struct_mg_ssi_call_ctx.md deleted file mode 100644 index 2b430fd1..00000000 --- a/docs/c-api/mg_http.h/struct_mg_ssi_call_ctx.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: "struct mg_ssi_call_ctx" -decl_name: "struct mg_ssi_call_ctx" -symbol_kind: "struct" -signature: | - struct mg_ssi_call_ctx { - struct http_message *req; /* The request being processed. */ - struct mg_str file; /* Filesystem path of the file being processed. */ - struct mg_str arg; /* The argument passed to the tag: . */ - }; ---- - -SSI call context - diff --git a/docs/c-api/mg_http.h/struct_websocket_message.md b/docs/c-api/mg_http.h/struct_websocket_message.md deleted file mode 100644 index 37b7912a..00000000 --- a/docs/c-api/mg_http.h/struct_websocket_message.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: "struct websocket_message" -decl_name: "struct websocket_message" -symbol_kind: "struct" -signature: | - struct websocket_message { - unsigned char *data; - size_t size; - unsigned char flags; - }; ---- - -WebSocket message - diff --git a/docs/c-api/mg_http_client.h/intro.md b/docs/c-api/mg_http_client.h/intro.md deleted file mode 100644 index 755be418..00000000 --- a/docs/c-api/mg_http_client.h/intro.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: "Client API reference" -symbol_kind: "intro" -decl_name: "mg_http_client.h" -items: - - { name: mg_connect_http.md } - - { name: mg_connect_http_opt.md } - - { name: mg_http_create_digest_auth_header.md } ---- - - - diff --git a/docs/c-api/mg_http_client.h/mg_connect_http.md b/docs/c-api/mg_http_client.h/mg_connect_http.md deleted file mode 100644 index 4664fcd9..00000000 --- a/docs/c-api/mg_http_client.h/mg_connect_http.md +++ /dev/null @@ -1,33 +0,0 @@ ---- -title: "mg_connect_http()" -decl_name: "mg_connect_http" -symbol_kind: "func" -signature: | - struct mg_connection *mg_connect_http( - struct mg_mgr *mgr, - MG_CB(mg_event_handler_t event_handler, void *user_data); ---- - -Helper function that creates an outbound HTTP connection. - -`url` is the URL to fetch. It must be properly URL-encoded, e.g. have -no spaces, etc. By default, `mg_connect_http()` sends the Connection and -Host headers. `extra_headers` is an extra HTTP header to send, e.g. -`"User-Agent: my-app\r\n"`. -If `post_data` is NULL, then a GET request is created. Otherwise, a POST -request is created with the specified POST data. Note that if the data being -posted is a form submission, the `Content-Type` header should be set -accordingly (see example below). - -Examples: - -```c - nc1 = mg_connect_http(mgr, ev_handler_1, "http://www.google.com", NULL, - NULL); - nc2 = mg_connect_http(mgr, ev_handler_1, "https://github.com", NULL, NULL); - nc3 = mg_connect_http( - mgr, ev_handler_1, "my_server:8000/form_submit/", - "Content-Type: application/x-www-form-urlencoded\r\n", - "var_1=value_1&var_2=value_2"); -``` - diff --git a/docs/c-api/mg_http_client.h/mg_connect_http_opt.md b/docs/c-api/mg_http_client.h/mg_connect_http_opt.md deleted file mode 100644 index 29df1d75..00000000 --- a/docs/c-api/mg_http_client.h/mg_connect_http_opt.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -title: "mg_connect_http_opt()" -decl_name: "mg_connect_http_opt" -symbol_kind: "func" -signature: | - struct mg_connection *mg_connect_http_opt( - struct mg_mgr *mgr, MG_CB(mg_event_handler_t ev_handler, void *user_data); ---- - -Helper function that creates an outbound HTTP connection. - -Mostly identical to mg_connect_http, but allows you to provide extra -*parameters -(for example, SSL parameters) - diff --git a/docs/c-api/mg_http_client.h/mg_http_create_digest_auth_header.md b/docs/c-api/mg_http_client.h/mg_http_create_digest_auth_header.md deleted file mode 100644 index 1842ea37..00000000 --- a/docs/c-api/mg_http_client.h/mg_http_create_digest_auth_header.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: "mg_http_create_digest_auth_header()" -decl_name: "mg_http_create_digest_auth_header" -symbol_kind: "func" -signature: | - int mg_http_create_digest_auth_header(char *buf, size_t buf_len, - const char *method, const char *uri, - const char *auth_domain, const char *user, - const char *passwd, const char *nonce); ---- - -Creates digest authentication header for a client request. - diff --git a/docs/c-api/mg_http_server.h/intro.md b/docs/c-api/mg_http_server.h/intro.md deleted file mode 100644 index 1a6055be..00000000 --- a/docs/c-api/mg_http_server.h/intro.md +++ /dev/null @@ -1,33 +0,0 @@ ---- -title: "Server API reference" -symbol_kind: "intro" -decl_name: "mg_http_server.h" -items: - - { name: mg_check_digest_auth.md } - - { name: mg_file_upload_handler.md } - - { name: mg_get_http_basic_auth.md } - - { name: mg_get_http_header.md } - - { name: mg_get_http_var.md } - - { name: mg_http_check_digest_auth.md } - - { name: mg_http_parse_header.md } - - { name: mg_http_parse_header2.md } - - { name: mg_http_reverse_proxy.md } - - { name: mg_http_send_error.md } - - { name: mg_http_send_redirect.md } - - { name: mg_http_serve_file.md } - - { name: mg_parse_http.md } - - { name: mg_parse_http_basic_auth.md } - - { name: mg_parse_multipart.md } - - { name: mg_printf_html_escape.md } - - { name: mg_printf_http_chunk.md } - - { name: mg_register_http_endpoint.md } - - { name: mg_send_head.md } - - { name: mg_send_http_chunk.md } - - { name: mg_send_response_line.md } - - { name: mg_serve_http.md } - - { name: mg_fu_fname_fn.md } - - { name: struct_mg_serve_http_opts.md } ---- - - - diff --git a/docs/c-api/mg_http_server.h/mg_check_digest_auth.md b/docs/c-api/mg_http_server.h/mg_check_digest_auth.md deleted file mode 100644 index 189f0c4a..00000000 --- a/docs/c-api/mg_http_server.h/mg_check_digest_auth.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: "mg_check_digest_auth()" -decl_name: "mg_check_digest_auth" -symbol_kind: "func" -signature: | - int mg_check_digest_auth(struct mg_str method, struct mg_str uri, - struct mg_str username, struct mg_str cnonce, - struct mg_str response, struct mg_str qop, - struct mg_str nc, struct mg_str nonce, - struct mg_str auth_domain, FILE *fp); ---- - -Authenticates given response params against an opened password file. -Returns 1 if authenticated, 0 otherwise. - -It's used by mg_http_check_digest_auth(). - diff --git a/docs/c-api/mg_http_server.h/mg_file_upload_handler.md b/docs/c-api/mg_http_server.h/mg_file_upload_handler.md deleted file mode 100644 index a2c9e016..00000000 --- a/docs/c-api/mg_http_server.h/mg_file_upload_handler.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -title: "mg_file_upload_handler()" -decl_name: "mg_file_upload_handler" -symbol_kind: "func" -signature: | - void mg_file_upload_handler(struct mg_connection *nc, int ev, void *ev_data, - mg_fu_fname_fn local_name_fn - MG_UD_ARG(void *user_data); ---- - -File upload handler. -This handler can be used to implement file uploads with minimum code. -This handler will process MG_EV_HTTP_PART_* events and store file data into -a local file. -`local_name_fn` will be invoked with whatever name was provided by the client -and will expect the name of the local file to open. A return value of NULL -will abort file upload (client will get a "403 Forbidden" response). If -non-null, the returned string must be heap-allocated and will be freed by -the caller. -Exception: it is ok to return the same string verbatim. - -Example: - -```c -struct mg_str upload_fname(struct mg_connection *nc, struct mg_str fname) { - // Just return the same filename. Do not actually do this except in test! - // fname is user-controlled and needs to be sanitized. - return fname; -} -void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { - switch (ev) { - ... - case MG_EV_HTTP_PART_BEGIN: - case MG_EV_HTTP_PART_DATA: - case MG_EV_HTTP_PART_END: - mg_file_upload_handler(nc, ev, ev_data, upload_fname); - break; - } -} -``` - diff --git a/docs/c-api/mg_http_server.h/mg_fu_fname_fn.md b/docs/c-api/mg_http_server.h/mg_fu_fname_fn.md deleted file mode 100644 index 78aa7c8b..00000000 --- a/docs/c-api/mg_http_server.h/mg_fu_fname_fn.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -title: "mg_fu_fname_fn" -decl_name: "mg_fu_fname_fn" -symbol_kind: "typedef" -signature: | - typedef struct mg_str (*mg_fu_fname_fn)(struct mg_connection *nc, - struct mg_str fname); ---- - -Callback prototype for `mg_file_upload_handler()`. - diff --git a/docs/c-api/mg_http_server.h/mg_get_http_basic_auth.md b/docs/c-api/mg_http_server.h/mg_get_http_basic_auth.md deleted file mode 100644 index 103d042f..00000000 --- a/docs/c-api/mg_http_server.h/mg_get_http_basic_auth.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: "mg_get_http_basic_auth()" -decl_name: "mg_get_http_basic_auth" -symbol_kind: "func" -signature: | - int mg_get_http_basic_auth(struct http_message *hm, char *user, size_t user_len, - char *pass, size_t pass_len); ---- - -Gets and parses the Authorization: Basic header -Returns -1 if no Authorization header is found, or if -mg_parse_http_basic_auth -fails parsing the resulting header. - diff --git a/docs/c-api/mg_http_server.h/mg_get_http_header.md b/docs/c-api/mg_http_server.h/mg_get_http_header.md deleted file mode 100644 index b33e91f4..00000000 --- a/docs/c-api/mg_http_server.h/mg_get_http_header.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: "mg_get_http_header()" -decl_name: "mg_get_http_header" -symbol_kind: "func" -signature: | - struct mg_str *mg_get_http_header(struct http_message *hm, const char *name); ---- - -Searches and returns the header `name` in parsed HTTP message `hm`. -If header is not found, NULL is returned. Example: - - struct mg_str *host_hdr = mg_get_http_header(hm, "Host"); - diff --git a/docs/c-api/mg_http_server.h/mg_get_http_var.md b/docs/c-api/mg_http_server.h/mg_get_http_var.md deleted file mode 100644 index 8ca1d915..00000000 --- a/docs/c-api/mg_http_server.h/mg_get_http_var.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: "mg_get_http_var()" -decl_name: "mg_get_http_var" -symbol_kind: "func" -signature: | - int mg_get_http_var(const struct mg_str *buf, const char *name, char *dst, - size_t dst_len); ---- - -Fetches a HTTP form variable. - -Fetches a variable `name` from a `buf` into a buffer specified by `dst`, -`dst_len`. The destination is always zero-terminated. Returns the length of -a fetched variable. If not found, 0 is returned. `buf` must be valid -url-encoded buffer. If destination is too small or an error occured, -negative number is returned. - diff --git a/docs/c-api/mg_http_server.h/mg_http_check_digest_auth.md b/docs/c-api/mg_http_server.h/mg_http_check_digest_auth.md deleted file mode 100644 index 3494eb26..00000000 --- a/docs/c-api/mg_http_server.h/mg_http_check_digest_auth.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: "mg_http_check_digest_auth()" -decl_name: "mg_http_check_digest_auth" -symbol_kind: "func" -signature: | - int mg_http_check_digest_auth(struct http_message *hm, const char *auth_domain, - FILE *fp); ---- - -Authenticates a HTTP request against an opened password file. -Returns 1 if authenticated, 0 otherwise. - diff --git a/docs/c-api/mg_http_server.h/mg_http_parse_header.md b/docs/c-api/mg_http_server.h/mg_http_parse_header.md deleted file mode 100644 index 969a13c9..00000000 --- a/docs/c-api/mg_http_server.h/mg_http_parse_header.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -title: "mg_http_parse_header()" -decl_name: "mg_http_parse_header" -symbol_kind: "func" -signature: | - int mg_http_parse_header(struct mg_str *hdr, const char *var_name, char *buf, - size_t buf_size); ---- - -DEPRECATED: use mg_http_parse_header2() instead. - -Same as mg_http_parse_header2(), but takes buffer as a `char *` (instead of -`char **`), and thus it cannot allocate a new buffer if the provided one -is not enough, and just returns 0 in that case. - diff --git a/docs/c-api/mg_http_server.h/mg_http_parse_header2.md b/docs/c-api/mg_http_server.h/mg_http_parse_header2.md deleted file mode 100644 index 4f1e62ed..00000000 --- a/docs/c-api/mg_http_server.h/mg_http_parse_header2.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: "mg_http_parse_header2()" -decl_name: "mg_http_parse_header2" -symbol_kind: "func" -signature: | - int mg_http_parse_header2(struct mg_str *hdr, const char *var_name, char **buf, - size_t buf_size); ---- - -Parses the HTTP header `hdr`. Finds variable `var_name` and stores its value -in the buffer `*buf`, `buf_size`. If the buffer size is not enough, -allocates a buffer of required size and writes it to `*buf`, similar to -asprintf(). The caller should always check whether the buffer was updated, -and free it if so. - -This function is supposed to parse cookies, authentication headers, etc. -Example (error handling omitted): - - char user_buf[20]; - char *user = user_buf; - struct mg_str *hdr = mg_get_http_header(hm, "Authorization"); - mg_http_parse_header2(hdr, "username", &user, sizeof(user_buf)); - // ... do something useful with user - if (user != user_buf) { - free(user); - } - -Returns the length of the variable's value. If variable is not found, 0 is -returned. - diff --git a/docs/c-api/mg_http_server.h/mg_http_reverse_proxy.md b/docs/c-api/mg_http_server.h/mg_http_reverse_proxy.md deleted file mode 100644 index c0c83835..00000000 --- a/docs/c-api/mg_http_server.h/mg_http_reverse_proxy.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: "mg_http_reverse_proxy()" -decl_name: "mg_http_reverse_proxy" -symbol_kind: "func" -signature: | - void mg_http_reverse_proxy(struct mg_connection *nc, - const struct http_message *hm, struct mg_str mount, - struct mg_str upstream); ---- - -Proxies a given request to a given upstream http server. The path prefix -in `mount` will be stripped of the path requested to the upstream server, -e.g. if mount is /api and upstream is http://localhost:8001/foo -then an incoming request to /api/bar will cause a request to -http://localhost:8001/foo/bar - -EXPERIMENTAL API. Please use http_serve_http + url_rewrites if a static -mapping is good enough. - diff --git a/docs/c-api/mg_http_server.h/mg_http_send_error.md b/docs/c-api/mg_http_server.h/mg_http_send_error.md deleted file mode 100644 index d74aafc1..00000000 --- a/docs/c-api/mg_http_server.h/mg_http_send_error.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -title: "mg_http_send_error()" -decl_name: "mg_http_send_error" -symbol_kind: "func" -signature: | - void mg_http_send_error(struct mg_connection *nc, int code, const char *reason); ---- - -Sends an error response. If reason is NULL, the message will be inferred -from the error code (if supported). - diff --git a/docs/c-api/mg_http_server.h/mg_http_send_redirect.md b/docs/c-api/mg_http_server.h/mg_http_send_redirect.md deleted file mode 100644 index 00d704e0..00000000 --- a/docs/c-api/mg_http_server.h/mg_http_send_redirect.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: "mg_http_send_redirect()" -decl_name: "mg_http_send_redirect" -symbol_kind: "func" -signature: | - void mg_http_send_redirect(struct mg_connection *nc, int status_code, - const struct mg_str location, - const struct mg_str extra_headers); ---- - -Sends a redirect response. -`status_code` should be either 301 or 302 and `location` point to the -new location. -If `extra_headers` is not empty, then `extra_headers` are also sent -after the response line. `extra_headers` must NOT end end with new line. - -Example: - - mg_http_send_redirect(nc, 302, mg_mk_str("/login"), mg_mk_str(NULL)); - diff --git a/docs/c-api/mg_http_server.h/mg_http_serve_file.md b/docs/c-api/mg_http_server.h/mg_http_serve_file.md deleted file mode 100644 index 440d39e5..00000000 --- a/docs/c-api/mg_http_server.h/mg_http_serve_file.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: "mg_http_serve_file()" -decl_name: "mg_http_serve_file" -symbol_kind: "func" -signature: | - void mg_http_serve_file(struct mg_connection *nc, struct http_message *hm, - const char *path, const struct mg_str mime_type, - const struct mg_str extra_headers); ---- - -Serves a specific file with a given MIME type and optional extra headers. - -Example code snippet: - -```c -static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { - switch (ev) { - case MG_EV_HTTP_REQUEST: { - struct http_message *hm = (struct http_message *) ev_data; - mg_http_serve_file(nc, hm, "file.txt", - mg_mk_str("text/plain"), mg_mk_str("")); - break; - } - ... - } -} -``` - diff --git a/docs/c-api/mg_http_server.h/mg_parse_http.md b/docs/c-api/mg_http_server.h/mg_parse_http.md deleted file mode 100644 index fdd5c638..00000000 --- a/docs/c-api/mg_http_server.h/mg_parse_http.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -title: "mg_parse_http()" -decl_name: "mg_parse_http" -symbol_kind: "func" -signature: | - int mg_parse_http(const char *s, int n, struct http_message *hm, int is_req); ---- - -Parses a HTTP message. - -`is_req` should be set to 1 if parsing a request, 0 if reply. - -Returns the number of bytes parsed. If HTTP message is -incomplete `0` is returned. On parse error, a negative number is returned. - diff --git a/docs/c-api/mg_http_server.h/mg_parse_http_basic_auth.md b/docs/c-api/mg_http_server.h/mg_parse_http_basic_auth.md deleted file mode 100644 index 7e3c2118..00000000 --- a/docs/c-api/mg_http_server.h/mg_parse_http_basic_auth.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: "mg_parse_http_basic_auth()" -decl_name: "mg_parse_http_basic_auth" -symbol_kind: "func" -signature: | - int mg_parse_http_basic_auth(struct mg_str *hdr, char *user, size_t user_len, - char *pass, size_t pass_len); ---- - -Parses the Authorization: Basic header -Returns -1 iif the authorization type is not "Basic" or any other error such -as incorrectly encoded base64 user password pair. - diff --git a/docs/c-api/mg_http_server.h/mg_parse_multipart.md b/docs/c-api/mg_http_server.h/mg_parse_multipart.md deleted file mode 100644 index f98d48fa..00000000 --- a/docs/c-api/mg_http_server.h/mg_parse_multipart.md +++ /dev/null @@ -1,46 +0,0 @@ ---- -title: "mg_parse_multipart()" -decl_name: "mg_parse_multipart" -symbol_kind: "func" -signature: | - size_t mg_parse_multipart(const char *buf, size_t buf_len, char *var_name, - size_t var_name_len, char *file_name, - size_t file_name_len, const char **chunk, - size_t *chunk_len); ---- - -Parses the buffer `buf`, `buf_len` that contains multipart form data chunks. -Stores the chunk name in a `var_name`, `var_name_len` buffer. -If a chunk is an uploaded file, then `file_name`, `file_name_len` is -filled with an uploaded file name. `chunk`, `chunk_len` -points to the chunk data. - -Return: number of bytes to skip to the next chunk or 0 if there are - no more chunks. - -Usage example: - -```c - static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { - switch(ev) { - case MG_EV_HTTP_REQUEST: { - struct http_message *hm = (struct http_message *) ev_data; - char var_name[100], file_name[100]; - const char *chunk; - size_t chunk_len, n1, n2; - - n1 = n2 = 0; - while ((n2 = mg_parse_multipart(hm->body.p + n1, - hm->body.len - n1, - var_name, sizeof(var_name), - file_name, sizeof(file_name), - &chunk, &chunk_len)) > 0) { - printf("var: %s, file_name: %s, size: %d, chunk: [%.*s]\n", - var_name, file_name, (int) chunk_len, - (int) chunk_len, chunk); - n1 += n2; - } - } - break; -``` - diff --git a/docs/c-api/mg_http_server.h/mg_printf_html_escape.md b/docs/c-api/mg_http_server.h/mg_printf_html_escape.md deleted file mode 100644 index 6238e28d..00000000 --- a/docs/c-api/mg_http_server.h/mg_printf_html_escape.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_printf_html_escape()" -decl_name: "mg_printf_html_escape" -symbol_kind: "func" -signature: | - void mg_printf_html_escape(struct mg_connection *nc, const char *fmt, ...); ---- - -Sends a printf-formatted HTTP chunk, escaping HTML tags. - diff --git a/docs/c-api/mg_http_server.h/mg_printf_http_chunk.md b/docs/c-api/mg_http_server.h/mg_printf_http_chunk.md deleted file mode 100644 index f99324b2..00000000 --- a/docs/c-api/mg_http_server.h/mg_printf_http_chunk.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -title: "mg_printf_http_chunk()" -decl_name: "mg_printf_http_chunk" -symbol_kind: "func" -signature: | - void mg_printf_http_chunk(struct mg_connection *nc, const char *fmt, ...); ---- - -Sends a printf-formatted HTTP chunk. -Functionality is similar to `mg_send_http_chunk()`. - diff --git a/docs/c-api/mg_http_server.h/mg_register_http_endpoint.md b/docs/c-api/mg_http_server.h/mg_register_http_endpoint.md deleted file mode 100644 index 394bbb51..00000000 --- a/docs/c-api/mg_http_server.h/mg_register_http_endpoint.md +++ /dev/null @@ -1,36 +0,0 @@ ---- -title: "mg_register_http_endpoint()" -decl_name: "mg_register_http_endpoint" -symbol_kind: "func" -signature: | - void mg_register_http_endpoint(struct mg_connection *nc, const char *uri_path, - MG_CB(mg_event_handler_t handler, - void *user_data); ---- - -Registers a callback for a specified http endpoint -Note: if callback is registered it is called instead of the -callback provided in mg_bind - -Example code snippet: - -```c -static void handle_hello1(struct mg_connection *nc, int ev, void *ev_data) { - (void) ev; (void) ev_data; - mg_printf(nc, "HTTP/1.0 200 OK\r\n\r\n[I am Hello1]"); - nc->flags |= MG_F_SEND_AND_CLOSE; -} - -static void handle_hello2(struct mg_connection *nc, int ev, void *ev_data) { - (void) ev; (void) ev_data; - mg_printf(nc, "HTTP/1.0 200 OK\r\n\r\n[I am Hello2]"); - nc->flags |= MG_F_SEND_AND_CLOSE; -} - -void init() { - nc = mg_bind(&mgr, local_addr, cb1); - mg_register_http_endpoint(nc, "/hello1", handle_hello1); - mg_register_http_endpoint(nc, "/hello1/hello2", handle_hello2); -} -``` - diff --git a/docs/c-api/mg_http_server.h/mg_send_head.md b/docs/c-api/mg_http_server.h/mg_send_head.md deleted file mode 100644 index cd334866..00000000 --- a/docs/c-api/mg_http_server.h/mg_send_head.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: "mg_send_head()" -decl_name: "mg_send_head" -symbol_kind: "func" -signature: | - void mg_send_head(struct mg_connection *n, int status_code, - int64_t content_length, const char *extra_headers); ---- - -Sends the response line and headers. -This function sends the response line with the `status_code`, and -automatically -sends one header: either "Content-Length" or "Transfer-Encoding". -If `content_length` is negative, then "Transfer-Encoding: chunked" header -is sent, otherwise, "Content-Length" header is sent. - -NOTE: If `Transfer-Encoding` is `chunked`, then message body must be sent -using `mg_send_http_chunk()` or `mg_printf_http_chunk()` functions. -Otherwise, `mg_send()` or `mg_printf()` must be used. -Extra headers could be set through `extra_headers`. Note `extra_headers` -must NOT be terminated by a new line. - diff --git a/docs/c-api/mg_http_server.h/mg_send_http_chunk.md b/docs/c-api/mg_http_server.h/mg_send_http_chunk.md deleted file mode 100644 index 6a2a4d83..00000000 --- a/docs/c-api/mg_http_server.h/mg_send_http_chunk.md +++ /dev/null @@ -1,25 +0,0 @@ ---- -title: "mg_send_http_chunk()" -decl_name: "mg_send_http_chunk" -symbol_kind: "func" -signature: | - void mg_send_http_chunk(struct mg_connection *nc, const char *buf, size_t len); ---- - -Sends buffer `buf` of size `len` to the client using chunked HTTP encoding. -This function sends the buffer size as hex number + newline first, then -the buffer itself, then the newline. For example, -`mg_send_http_chunk(nc, "foo", 3)` will append the `3\r\nfoo\r\n` string -to the `nc->send_mbuf` output IO buffer. - -NOTE: The HTTP header "Transfer-Encoding: chunked" should be sent prior to -using this function. - -NOTE: do not forget to send an empty chunk at the end of the response, -to tell the client that everything was sent. Example: - -``` - mg_printf_http_chunk(nc, "%s", "my response!"); - mg_send_http_chunk(nc, "", 0); // Tell the client we're finished -``` - diff --git a/docs/c-api/mg_http_server.h/mg_send_response_line.md b/docs/c-api/mg_http_server.h/mg_send_response_line.md deleted file mode 100644 index 5daa74fe..00000000 --- a/docs/c-api/mg_http_server.h/mg_send_response_line.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -title: "mg_send_response_line()" -decl_name: "mg_send_response_line" -symbol_kind: "func" -signature: | - void mg_send_response_line(struct mg_connection *nc, int status_code, - const char *extra_headers); ---- - -Sends the response status line. -If `extra_headers` is not NULL, then `extra_headers` are also sent -after the response line. `extra_headers` must NOT end end with new line. -Example: - - mg_send_response_line(nc, 200, "Access-Control-Allow-Origin: *"); - -Will result in: - - HTTP/1.1 200 OK\r\n - Access-Control-Allow-Origin: *\r\n - diff --git a/docs/c-api/mg_http_server.h/mg_serve_http.md b/docs/c-api/mg_http_server.h/mg_serve_http.md deleted file mode 100644 index 98069503..00000000 --- a/docs/c-api/mg_http_server.h/mg_serve_http.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: "mg_serve_http()" -decl_name: "mg_serve_http" -symbol_kind: "func" -signature: | - void mg_serve_http(struct mg_connection *nc, struct http_message *hm, - struct mg_serve_http_opts opts); ---- - -Serves given HTTP request according to the `options`. - -Example code snippet: - -```c -static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { - struct http_message *hm = (struct http_message *) ev_data; - struct mg_serve_http_opts opts = { .document_root = "/var/www" }; // C99 - - switch (ev) { - case MG_EV_HTTP_REQUEST: - mg_serve_http(nc, hm, opts); - break; - default: - break; - } -} -``` - diff --git a/docs/c-api/mg_http_server.h/struct_mg_serve_http_opts.md b/docs/c-api/mg_http_server.h/struct_mg_serve_http_opts.md deleted file mode 100644 index ae594dba..00000000 --- a/docs/c-api/mg_http_server.h/struct_mg_serve_http_opts.md +++ /dev/null @@ -1,165 +0,0 @@ ---- -title: "struct mg_serve_http_opts" -decl_name: "struct mg_serve_http_opts" -symbol_kind: "struct" -signature: | - struct mg_serve_http_opts { - /* Path to web root directory */ - const char *document_root; - - /* List of index files. Default is "" */ - const char *index_files; - - /* - * Leave as NULL to disable authentication. - * To enable directory protection with authentication, set this to ".htpasswd" - * Then, creating ".htpasswd" file in any directory automatically protects - * it with digest authentication. - * Use `mongoose` web server binary, or `htdigest` Apache utility to - * create/manipulate passwords file. - * Make sure `auth_domain` is set to a valid domain name. - */ - const char *per_directory_auth_file; - - /* Authorization domain (domain name of this web server) */ - const char *auth_domain; - - /* - * Leave as NULL to disable authentication. - * Normally, only selected directories in the document root are protected. - * If absolutely every access to the web server needs to be authenticated, - * regardless of the URI, set this option to the path to the passwords file. - * Format of that file is the same as ".htpasswd" file. Make sure that file - * is located outside document root to prevent people fetching it. - */ - const char *global_auth_file; - - /* Set to "no" to disable directory listing. Enabled by default. */ - const char *enable_directory_listing; - - /* - * SSI files pattern. If not set, "**.shtml$|**.shtm$" is used. - * - * All files that match ssi_pattern are treated as SSI. - * - * Server Side Includes (SSI) is a simple interpreted server-side scripting - * language which is most commonly used to include the contents of a file - * into a web page. It can be useful when it is desirable to include a common - * piece of code throughout a website, for example, headers and footers. - * - * In order for a webpage to recognize an SSI-enabled HTML file, the - * filename should end with a special extension, by default the extension - * should be either .shtml or .shtm - * - * Unknown SSI directives are silently ignored by Mongoose. Currently, - * the following SSI directives are supported: - * <!--#include FILE_TO_INCLUDE --> - * <!--#exec "COMMAND_TO_EXECUTE" --> - * <!--#call COMMAND --> - * - * Note that <!--#include ...> directive supports three path - *specifications: - * - * <!--#include virtual="path" --> Path is relative to web server root - * <!--#include abspath="path" --> Path is absolute or relative to the - * web server working dir - * <!--#include file="path" -->, Path is relative to current document - * <!--#include "path" --> - * - * The include directive may be used to include the contents of a file or - * the result of running a CGI script. - * - * The exec directive is used to execute - * a command on a server, and show command's output. Example: - * - * <!--#exec "ls -l" --> - * - * The call directive is a way to invoke a C handler from the HTML page. - * On each occurence of <!--#call COMMAND OPTIONAL_PARAMS> directive, - * Mongoose calls a registered event handler with MG_EV_SSI_CALL event, - * and event parameter will point to the COMMAND OPTIONAL_PARAMS string. - * An event handler can output any text, for example by calling - * `mg_printf()`. This is a flexible way of generating a web page on - * server side by calling a C event handler. Example: - * - * <!--#call foo --> ... <!--#call bar --> - * - * In the event handler: - * case MG_EV_SSI_CALL: { - * const char *param = (const char *) ev_data; - * if (strcmp(param, "foo") == 0) { - * mg_printf(c, "hello from foo"); - * } else if (strcmp(param, "bar") == 0) { - * mg_printf(c, "hello from bar"); - * } - * break; - * } - */ - const char *ssi_pattern; - - /* IP ACL. By default, NULL, meaning all IPs are allowed to connect */ - const char *ip_acl; - - #if MG_ENABLE_HTTP_URL_REWRITES - /* URL rewrites. - * - * Comma-separated list of `uri_pattern=url_file_or_directory_path` rewrites. - * When HTTP request is received, Mongoose constructs a file name from the - * requested URI by combining `document_root` and the URI. However, if the - * rewrite option is used and `uri_pattern` matches requested URI, then - * `document_root` is ignored. Instead, `url_file_or_directory_path` is used, - * which should be a full path name or a path relative to the web server's - * current working directory. It can also be an URI (http:// or https://) - * in which case mongoose will behave as a reverse proxy for that destination. - * - * Note that `uri_pattern`, as all Mongoose patterns, is a prefix pattern. - * - * If uri_pattern starts with `@` symbol, then Mongoose compares it with the - * HOST header of the request. If they are equal, Mongoose sets document root - * to `file_or_directory_path`, implementing virtual hosts support. - * Example: `@foo.com=/document/root/for/foo.com` - * - * If `uri_pattern` starts with `%` symbol, then Mongoose compares it with - * the listening port. If they match, then Mongoose issues a 301 redirect. - * For example, to redirect all HTTP requests to the - * HTTPS port, do `%80=https://my.site.com`. Note that the request URI is - * automatically appended to the redirect location. - */ - const char *url_rewrites; - #endif - - /* DAV document root. If NULL, DAV requests are going to fail. */ - const char *dav_document_root; - - /* - * DAV passwords file. If NULL, DAV requests are going to fail. - * If passwords file is set to "-", then DAV auth is disabled. - */ - const char *dav_auth_file; - - /* Glob pattern for the files to hide. */ - const char *hidden_file_pattern; - - /* Set to non-NULL to enable CGI, e.g. **.cgi$|**.php$" */ - const char *cgi_file_pattern; - - /* If not NULL, ignore CGI script hashbang and use this interpreter */ - const char *cgi_interpreter; - - /* - * Comma-separated list of Content-Type overrides for path suffixes, e.g. - * ".txt=text/plain; charset=utf-8,.c=text/plain" - */ - const char *custom_mime_types; - - /* - * Extra HTTP headers to add to each server response. - * Example: to enable CORS, set this to "Access-Control-Allow-Origin: *". - */ - const char *extra_headers; - }; ---- - -This structure defines how `mg_serve_http()` works. -Best practice is to set only required settings, and leave the rest as NULL. - diff --git a/docs/c-api/mg_mqtt.h/intro.md b/docs/c-api/mg_mqtt.h/intro.md deleted file mode 100644 index eee90dfe..00000000 --- a/docs/c-api/mg_mqtt.h/intro.md +++ /dev/null @@ -1,29 +0,0 @@ ---- -title: "MQTT API reference" -symbol_kind: "intro" -decl_name: "mg_mqtt.h" -items: - - { name: mg_mqtt_connack.md } - - { name: mg_mqtt_disconnect.md } - - { name: mg_mqtt_match_topic_expression.md } - - { name: mg_mqtt_next_subscribe_topic.md } - - { name: mg_mqtt_ping.md } - - { name: mg_mqtt_pong.md } - - { name: mg_mqtt_puback.md } - - { name: mg_mqtt_pubcomp.md } - - { name: mg_mqtt_publish.md } - - { name: mg_mqtt_pubrec.md } - - { name: mg_mqtt_pubrel.md } - - { name: mg_mqtt_suback.md } - - { name: mg_mqtt_subscribe.md } - - { name: mg_mqtt_unsuback.md } - - { name: mg_mqtt_unsubscribe.md } - - { name: mg_mqtt_vmatch_topic_expression.md } - - { name: mg_send_mqtt_handshake.md } - - { name: mg_send_mqtt_handshake_opt.md } - - { name: mg_set_protocol_mqtt.md } - - { name: struct_mg_mqtt_proto_data.md } ---- - - - diff --git a/docs/c-api/mg_mqtt.h/mg_mqtt_connack.md b/docs/c-api/mg_mqtt.h/mg_mqtt_connack.md deleted file mode 100644 index 7daaf5b4..00000000 --- a/docs/c-api/mg_mqtt.h/mg_mqtt_connack.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_mqtt_connack()" -decl_name: "mg_mqtt_connack" -symbol_kind: "func" -signature: | - void mg_mqtt_connack(struct mg_connection *nc, uint8_t return_code); ---- - -Sends a CONNACK command with a given `return_code`. - diff --git a/docs/c-api/mg_mqtt.h/mg_mqtt_disconnect.md b/docs/c-api/mg_mqtt.h/mg_mqtt_disconnect.md deleted file mode 100644 index c727cad0..00000000 --- a/docs/c-api/mg_mqtt.h/mg_mqtt_disconnect.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_mqtt_disconnect()" -decl_name: "mg_mqtt_disconnect" -symbol_kind: "func" -signature: | - void mg_mqtt_disconnect(struct mg_connection *nc); ---- - -Sends a DISCONNECT command. - diff --git a/docs/c-api/mg_mqtt.h/mg_mqtt_match_topic_expression.md b/docs/c-api/mg_mqtt.h/mg_mqtt_match_topic_expression.md deleted file mode 100644 index 81575b47..00000000 --- a/docs/c-api/mg_mqtt.h/mg_mqtt_match_topic_expression.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: "mg_mqtt_match_topic_expression()" -decl_name: "mg_mqtt_match_topic_expression" -symbol_kind: "func" -signature: | - int mg_mqtt_match_topic_expression(struct mg_str exp, struct mg_str topic); ---- - -Matches a topic against a topic expression - -Returns 1 if it matches; 0 otherwise. - diff --git a/docs/c-api/mg_mqtt.h/mg_mqtt_next_subscribe_topic.md b/docs/c-api/mg_mqtt.h/mg_mqtt_next_subscribe_topic.md deleted file mode 100644 index ccb96e62..00000000 --- a/docs/c-api/mg_mqtt.h/mg_mqtt_next_subscribe_topic.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -title: "mg_mqtt_next_subscribe_topic()" -decl_name: "mg_mqtt_next_subscribe_topic" -symbol_kind: "func" -signature: | - int mg_mqtt_next_subscribe_topic(struct mg_mqtt_message *msg, - struct mg_str *topic, uint8_t *qos, int pos); ---- - -Extracts the next topic expression from a SUBSCRIBE command payload. - -The topic expression name will point to a string in the payload buffer. -Returns the pos of the next topic expression or -1 when the list -of topics is exhausted. - diff --git a/docs/c-api/mg_mqtt.h/mg_mqtt_ping.md b/docs/c-api/mg_mqtt.h/mg_mqtt_ping.md deleted file mode 100644 index 757a825e..00000000 --- a/docs/c-api/mg_mqtt.h/mg_mqtt_ping.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_mqtt_ping()" -decl_name: "mg_mqtt_ping" -symbol_kind: "func" -signature: | - void mg_mqtt_ping(struct mg_connection *nc); ---- - -Sends a PINGREQ command. - diff --git a/docs/c-api/mg_mqtt.h/mg_mqtt_pong.md b/docs/c-api/mg_mqtt.h/mg_mqtt_pong.md deleted file mode 100644 index c79253e3..00000000 --- a/docs/c-api/mg_mqtt.h/mg_mqtt_pong.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_mqtt_pong()" -decl_name: "mg_mqtt_pong" -symbol_kind: "func" -signature: | - void mg_mqtt_pong(struct mg_connection *nc); ---- - -Sends a PINGRESP command. - diff --git a/docs/c-api/mg_mqtt.h/mg_mqtt_puback.md b/docs/c-api/mg_mqtt.h/mg_mqtt_puback.md deleted file mode 100644 index a29a352d..00000000 --- a/docs/c-api/mg_mqtt.h/mg_mqtt_puback.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_mqtt_puback()" -decl_name: "mg_mqtt_puback" -symbol_kind: "func" -signature: | - void mg_mqtt_puback(struct mg_connection *nc, uint16_t message_id); ---- - -Sends a PUBACK command with a given `message_id`. - diff --git a/docs/c-api/mg_mqtt.h/mg_mqtt_pubcomp.md b/docs/c-api/mg_mqtt.h/mg_mqtt_pubcomp.md deleted file mode 100644 index bc3228ca..00000000 --- a/docs/c-api/mg_mqtt.h/mg_mqtt_pubcomp.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_mqtt_pubcomp()" -decl_name: "mg_mqtt_pubcomp" -symbol_kind: "func" -signature: | - void mg_mqtt_pubcomp(struct mg_connection *nc, uint16_t message_id); ---- - -Sends a PUBCOMP command with a given `message_id`. - diff --git a/docs/c-api/mg_mqtt.h/mg_mqtt_publish.md b/docs/c-api/mg_mqtt.h/mg_mqtt_publish.md deleted file mode 100644 index b2a7b013..00000000 --- a/docs/c-api/mg_mqtt.h/mg_mqtt_publish.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: "mg_mqtt_publish()" -decl_name: "mg_mqtt_publish" -symbol_kind: "func" -signature: | - void mg_mqtt_publish(struct mg_connection *nc, const char *topic, - uint16_t message_id, int flags, const void *data, - size_t len); ---- - -Publishes a message to a given topic. - diff --git a/docs/c-api/mg_mqtt.h/mg_mqtt_pubrec.md b/docs/c-api/mg_mqtt.h/mg_mqtt_pubrec.md deleted file mode 100644 index 16cdc7d0..00000000 --- a/docs/c-api/mg_mqtt.h/mg_mqtt_pubrec.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_mqtt_pubrec()" -decl_name: "mg_mqtt_pubrec" -symbol_kind: "func" -signature: | - void mg_mqtt_pubrec(struct mg_connection *nc, uint16_t message_id); ---- - -Sends a PUBREC command with a given `message_id`. - diff --git a/docs/c-api/mg_mqtt.h/mg_mqtt_pubrel.md b/docs/c-api/mg_mqtt.h/mg_mqtt_pubrel.md deleted file mode 100644 index 18a6c581..00000000 --- a/docs/c-api/mg_mqtt.h/mg_mqtt_pubrel.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_mqtt_pubrel()" -decl_name: "mg_mqtt_pubrel" -symbol_kind: "func" -signature: | - void mg_mqtt_pubrel(struct mg_connection *nc, uint16_t message_id); ---- - -Sends a PUBREL command with a given `message_id`. - diff --git a/docs/c-api/mg_mqtt.h/mg_mqtt_suback.md b/docs/c-api/mg_mqtt.h/mg_mqtt_suback.md deleted file mode 100644 index 55cf5e3a..00000000 --- a/docs/c-api/mg_mqtt.h/mg_mqtt_suback.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: "mg_mqtt_suback()" -decl_name: "mg_mqtt_suback" -symbol_kind: "func" -signature: | - void mg_mqtt_suback(struct mg_connection *nc, uint8_t *qoss, size_t qoss_len, - uint16_t message_id); ---- - -Sends a SUBACK command with a given `message_id` -and a sequence of granted QoSs. - diff --git a/docs/c-api/mg_mqtt.h/mg_mqtt_subscribe.md b/docs/c-api/mg_mqtt.h/mg_mqtt_subscribe.md deleted file mode 100644 index 0168db41..00000000 --- a/docs/c-api/mg_mqtt.h/mg_mqtt_subscribe.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: "mg_mqtt_subscribe()" -decl_name: "mg_mqtt_subscribe" -symbol_kind: "func" -signature: | - void mg_mqtt_subscribe(struct mg_connection *nc, - const struct mg_mqtt_topic_expression *topics, - size_t topics_len, uint16_t message_id); ---- - -Subscribes to a bunch of topics. - diff --git a/docs/c-api/mg_mqtt.h/mg_mqtt_unsuback.md b/docs/c-api/mg_mqtt.h/mg_mqtt_unsuback.md deleted file mode 100644 index a86fffc5..00000000 --- a/docs/c-api/mg_mqtt.h/mg_mqtt_unsuback.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_mqtt_unsuback()" -decl_name: "mg_mqtt_unsuback" -symbol_kind: "func" -signature: | - void mg_mqtt_unsuback(struct mg_connection *nc, uint16_t message_id); ---- - -Sends a UNSUBACK command with a given `message_id`. - diff --git a/docs/c-api/mg_mqtt.h/mg_mqtt_unsubscribe.md b/docs/c-api/mg_mqtt.h/mg_mqtt_unsubscribe.md deleted file mode 100644 index b4c1f783..00000000 --- a/docs/c-api/mg_mqtt.h/mg_mqtt_unsubscribe.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -title: "mg_mqtt_unsubscribe()" -decl_name: "mg_mqtt_unsubscribe" -symbol_kind: "func" -signature: | - void mg_mqtt_unsubscribe(struct mg_connection *nc, char **topics, - size_t topics_len, uint16_t message_id); ---- - -Unsubscribes from a bunch of topics. - diff --git a/docs/c-api/mg_mqtt.h/mg_mqtt_vmatch_topic_expression.md b/docs/c-api/mg_mqtt.h/mg_mqtt_vmatch_topic_expression.md deleted file mode 100644 index 4b0a4231..00000000 --- a/docs/c-api/mg_mqtt.h/mg_mqtt_vmatch_topic_expression.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -title: "mg_mqtt_vmatch_topic_expression()" -decl_name: "mg_mqtt_vmatch_topic_expression" -symbol_kind: "func" -signature: | - int mg_mqtt_vmatch_topic_expression(const char *exp, struct mg_str topic); ---- - -Same as `mg_mqtt_match_topic_expression()`, but takes `exp` as a -NULL-terminated string. - diff --git a/docs/c-api/mg_mqtt.h/mg_send_mqtt_handshake.md b/docs/c-api/mg_mqtt.h/mg_send_mqtt_handshake.md deleted file mode 100644 index 0e75c4e3..00000000 --- a/docs/c-api/mg_mqtt.h/mg_send_mqtt_handshake.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_send_mqtt_handshake()" -decl_name: "mg_send_mqtt_handshake" -symbol_kind: "func" -signature: | - void mg_send_mqtt_handshake(struct mg_connection *nc, const char *client_id); ---- - -Sends an MQTT handshake. - diff --git a/docs/c-api/mg_mqtt.h/mg_send_mqtt_handshake_opt.md b/docs/c-api/mg_mqtt.h/mg_send_mqtt_handshake_opt.md deleted file mode 100644 index 2c7a93ca..00000000 --- a/docs/c-api/mg_mqtt.h/mg_send_mqtt_handshake_opt.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -title: "mg_send_mqtt_handshake_opt()" -decl_name: "mg_send_mqtt_handshake_opt" -symbol_kind: "func" -signature: | - void mg_send_mqtt_handshake_opt(struct mg_connection *nc, const char *client_id, - struct mg_send_mqtt_handshake_opts); ---- - -Sends an MQTT handshake with optional parameters. - diff --git a/docs/c-api/mg_mqtt.h/mg_set_protocol_mqtt.md b/docs/c-api/mg_mqtt.h/mg_set_protocol_mqtt.md deleted file mode 100644 index 8c65d385..00000000 --- a/docs/c-api/mg_mqtt.h/mg_set_protocol_mqtt.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: "mg_set_protocol_mqtt()" -decl_name: "mg_set_protocol_mqtt" -symbol_kind: "func" -signature: | - void mg_set_protocol_mqtt(struct mg_connection *nc); ---- - -Attaches a built-in MQTT event handler to the given connection. - -The user-defined event handler will receive following extra events: - -- MG_EV_MQTT_CONNACK -- MG_EV_MQTT_PUBLISH -- MG_EV_MQTT_PUBACK -- MG_EV_MQTT_PUBREC -- MG_EV_MQTT_PUBREL -- MG_EV_MQTT_PUBCOMP -- MG_EV_MQTT_SUBACK - diff --git a/docs/c-api/mg_mqtt.h/struct_mg_mqtt_proto_data.md b/docs/c-api/mg_mqtt.h/struct_mg_mqtt_proto_data.md deleted file mode 100644 index f095589d..00000000 --- a/docs/c-api/mg_mqtt.h/struct_mg_mqtt_proto_data.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: "struct mg_mqtt_proto_data" -decl_name: "struct mg_mqtt_proto_data" -symbol_kind: "struct" -signature: | - struct mg_mqtt_proto_data { - uint16_t keep_alive; - double last_control_time; - }; ---- - -mg_mqtt_proto_data should be in header to allow external access to it - diff --git a/docs/c-api/mg_mqtt_server.h/LIST_ENTRY.md b/docs/c-api/mg_mqtt_server.h/LIST_ENTRY.md deleted file mode 100644 index 3d30ddd3..00000000 --- a/docs/c-api/mg_mqtt_server.h/LIST_ENTRY.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "LIST_ENTRY()" -decl_name: "LIST_ENTRY" -symbol_kind: "func" -signature: | - LIST_ENTRY(mg_mqtt_session); ---- - -Broker - diff --git a/docs/c-api/mg_mqtt_server.h/intro.md b/docs/c-api/mg_mqtt_server.h/intro.md deleted file mode 100644 index 0c2b2b7c..00000000 --- a/docs/c-api/mg_mqtt_server.h/intro.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: "MQTT Server API reference" -symbol_kind: "intro" -decl_name: "mg_mqtt_server.h" -items: - - { name: LIST_ENTRY.md } - - { name: struct_mg_mqtt_broker.md } - - { name: struct_mg_mqtt_session.md } ---- - - - diff --git a/docs/c-api/mg_mqtt_server.h/struct_mg_mqtt_broker.md b/docs/c-api/mg_mqtt_server.h/struct_mg_mqtt_broker.md deleted file mode 100644 index eaaa637f..00000000 --- a/docs/c-api/mg_mqtt_server.h/struct_mg_mqtt_broker.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: "struct mg_mqtt_broker" -decl_name: "struct mg_mqtt_broker" -symbol_kind: "struct" -signature: | - struct mg_mqtt_broker { - LIST_HEAD(_mg_sesshead, mg_mqtt_session) sessions; /* Session list */ - void *user_data; /* User data */ - }; ---- - -MQTT broker. - diff --git a/docs/c-api/mg_mqtt_server.h/struct_mg_mqtt_session.md b/docs/c-api/mg_mqtt_server.h/struct_mg_mqtt_session.md deleted file mode 100644 index e38a4dfa..00000000 --- a/docs/c-api/mg_mqtt_server.h/struct_mg_mqtt_session.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: "struct mg_mqtt_session" -decl_name: "struct mg_mqtt_session" -symbol_kind: "struct" -signature: | - struct mg_mqtt_session { - struct mg_mqtt_broker *brk; /* Broker */ - LIST_ENTRY(mg_mqtt_session) link; /* mg_mqtt_broker::sessions linkage */ - struct mg_connection *nc; /* Connection with the client */ - size_t num_subscriptions; /* Size of `subscriptions` array */ - void *user_data; /* User data */ - struct mg_mqtt_topic_expression *subscriptions; - }; ---- - -MQTT session (Broker side). - diff --git a/docs/c-api/mg_net.h/intro.md b/docs/c-api/mg_net.h/intro.md deleted file mode 100644 index 5caca87c..00000000 --- a/docs/c-api/mg_net.h/intro.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -title: "Core API: TCP/UDP/SSL" -symbol_kind: "intro" -decl_name: "mg_net.h" -items: - - { name: mg_add_sock.md } - - { name: mg_add_sock_opt.md } - - { name: mg_bind.md } - - { name: mg_bind_opt.md } - - { name: mg_broadcast.md } - - { name: mg_check_ip_acl.md } - - { name: mg_connect.md } - - { name: mg_connect_opt.md } - - { name: mg_mgr_free.md } - - { name: mg_mgr_init.md } - - { name: mg_mgr_init_opt.md } - - { name: mg_mgr_poll.md } - - { name: mg_next.md } - - { name: mg_printf.md } - - { name: mg_resolve.md } - - { name: mg_send.md } - - { name: mg_set_ssl.md } - - { name: mg_set_timer.md } - - { name: mg_socketpair.md } - - { name: mg_time.md } - - { name: mg_vprintf.md } - - { name: mg_event_handler_t.md } - - { name: struct_mg_add_sock_opts.md } - - { name: struct_mg_bind_opts.md } - - { name: struct_mg_connect_opts.md } - - { name: struct_mg_connection.md } - - { name: struct_mg_mgr.md } - - { name: struct_mg_mgr_init_opts.md } ---- - -NOTE: Mongoose manager is single threaded. It does not protect -its data structures by mutexes, therefore all functions that are dealing -with a particular event manager should be called from the same thread, -with exception of the `mg_broadcast()` function. It is fine to have different -event managers handled by different threads. - diff --git a/docs/c-api/mg_net.h/mg_add_sock.md b/docs/c-api/mg_net.h/mg_add_sock.md deleted file mode 100644 index e63ce2e4..00000000 --- a/docs/c-api/mg_net.h/mg_add_sock.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -title: "mg_add_sock()" -decl_name: "mg_add_sock" -symbol_kind: "func" -signature: | - struct mg_connection *mg_add_sock(struct mg_mgr *mgr, sock_t sock, - MG_CB(mg_event_handler_t handler, - void *user_data); ---- - -Creates a connection, associates it with the given socket and event handler -and adds it to the manager. - -For more options see the `mg_add_sock_opt` variant. - diff --git a/docs/c-api/mg_net.h/mg_add_sock_opt.md b/docs/c-api/mg_net.h/mg_add_sock_opt.md deleted file mode 100644 index de2a22e9..00000000 --- a/docs/c-api/mg_net.h/mg_add_sock_opt.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -title: "mg_add_sock_opt()" -decl_name: "mg_add_sock_opt" -symbol_kind: "func" -signature: | - struct mg_connection *mg_add_sock_opt(struct mg_mgr *mgr, sock_t sock, - MG_CB(mg_event_handler_t handler, - void *user_data); ---- - -Creates a connection, associates it with the given socket and event handler -and adds to the manager. - -See the `mg_add_sock_opts` structure for a description of the options. - diff --git a/docs/c-api/mg_net.h/mg_bind.md b/docs/c-api/mg_net.h/mg_bind.md deleted file mode 100644 index 9507d51c..00000000 --- a/docs/c-api/mg_net.h/mg_bind.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: "mg_bind()" -decl_name: "mg_bind" -symbol_kind: "func" -signature: | - struct mg_connection *mg_bind(struct mg_mgr *mgr, const char *address, - MG_CB(mg_event_handler_t handler, - void *user_data); ---- - -Creates a listening connection. - -See `mg_bind_opt` for full documentation. - diff --git a/docs/c-api/mg_net.h/mg_bind_opt.md b/docs/c-api/mg_net.h/mg_bind_opt.md deleted file mode 100644 index 823dd0c0..00000000 --- a/docs/c-api/mg_net.h/mg_bind_opt.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: "mg_bind_opt()" -decl_name: "mg_bind_opt" -symbol_kind: "func" -signature: | - struct mg_connection *mg_bind_opt(struct mg_mgr *mgr, const char *address, - MG_CB(mg_event_handler_t handler, - void *user_data); ---- - -Creates a listening connection. - -The `address` parameter specifies which address to bind to. It's format is -the same as for the `mg_connect()` call, where `HOST` part is optional. -`address` can be just a port number, e.g. `:8000`. To bind to a specific -interface, an IP address can be specified, e.g. `1.2.3.4:8000`. By default, -a TCP connection is created. To create UDP connection, prepend `udp://` -prefix, e.g. `udp://:8000`. To summarize, `address` parameter has following -format: `[PROTO://][IP_ADDRESS]:PORT`, where `PROTO` could be `tcp` or -`udp`. - -See the `mg_bind_opts` structure for a description of the optional -parameters. - -Returns a new listening connection or `NULL` on error. -NOTE: The connection remains owned by the manager, do not free(). - diff --git a/docs/c-api/mg_net.h/mg_broadcast.md b/docs/c-api/mg_net.h/mg_broadcast.md deleted file mode 100644 index 6e966afe..00000000 --- a/docs/c-api/mg_net.h/mg_broadcast.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: "mg_broadcast()" -decl_name: "mg_broadcast" -symbol_kind: "func" -signature: | - void mg_broadcast(struct mg_mgr *mgr, mg_event_handler_t cb, void *data, - size_t len); ---- - -Passes a message of a given length to all connections. - -Must be called from a thread that does NOT call `mg_mgr_poll()`. -Note that `mg_broadcast()` is the only function -that can be, and must be, called from a different (non-IO) thread. - -`func` callback function will be called by the IO thread for each -connection. When called, the event will be `MG_EV_POLL`, and a message will -be passed as the `ev_data` pointer. Maximum message size is capped -by `MG_CTL_MSG_MESSAGE_SIZE` which is set to 8192 bytes by default. - diff --git a/docs/c-api/mg_net.h/mg_check_ip_acl.md b/docs/c-api/mg_net.h/mg_check_ip_acl.md deleted file mode 100644 index 83c2c7ba..00000000 --- a/docs/c-api/mg_net.h/mg_check_ip_acl.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: "mg_check_ip_acl()" -decl_name: "mg_check_ip_acl" -symbol_kind: "func" -signature: | - int mg_check_ip_acl(const char *acl, uint32_t remote_ip); ---- - -Verify given IP address against the ACL. - -`remote_ip` - an IPv4 address to check, in host byte order -`acl` - a comma separated list of IP subnets: `x.x.x.x/x` or `x.x.x.x`. -Each subnet is -prepended by either a - or a + sign. A plus sign means allow, where a -minus sign means deny. If a subnet mask is omitted, such as `-1.2.3.4`, -it means that only that single IP address is denied. -Subnet masks may vary from 0 to 32, inclusive. The default setting -is to allow all access. On each request the full list is traversed, -and the last match wins. Example: - -`-0.0.0.0/0,+192.168/16` - deny all accesses, only allow 192.168/16 subnet - -To learn more about subnet masks, see this -link:https://en.wikipedia.org/wiki/Subnetwork[Wikipedia page on Subnetwork]. - -Returns -1 if ACL is malformed, 0 if address is disallowed, 1 if allowed. - diff --git a/docs/c-api/mg_net.h/mg_connect.md b/docs/c-api/mg_net.h/mg_connect.md deleted file mode 100644 index 788be84e..00000000 --- a/docs/c-api/mg_net.h/mg_connect.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: "mg_connect()" -decl_name: "mg_connect" -symbol_kind: "func" -signature: | - struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *address, - MG_CB(mg_event_handler_t handler, - void *user_data); ---- - -Connects to a remote host. - -See `mg_connect_opt()` for full documentation. - diff --git a/docs/c-api/mg_net.h/mg_connect_opt.md b/docs/c-api/mg_net.h/mg_connect_opt.md deleted file mode 100644 index 3ae818a4..00000000 --- a/docs/c-api/mg_net.h/mg_connect_opt.md +++ /dev/null @@ -1,57 +0,0 @@ ---- -title: "mg_connect_opt()" -decl_name: "mg_connect_opt" -symbol_kind: "func" -signature: | - struct mg_connection *mg_connect_opt(struct mg_mgr *mgr, const char *address, - MG_CB(mg_event_handler_t handler, - void *user_data); ---- - -Connects to a remote host. - -The `address` format is `[PROTO://]HOST:PORT`. `PROTO` could be `tcp` or -`udp`. `HOST` could be an IP address, -IPv6 address (if Mongoose is compiled with `-DMG_ENABLE_IPV6`) or a host -name. If `HOST` is a name, Mongoose will resolve it asynchronously. Examples -of valid addresses: `google.com:80`, `udp://1.2.3.4:53`, `10.0.0.1:443`, -`[::1]:80` - -See the `mg_connect_opts` structure for a description of the optional -parameters. - -Returns a new outbound connection or `NULL` on error. - -NOTE: The connection remains owned by the manager, do not free(). - -NOTE: To enable IPv6 addresses `-DMG_ENABLE_IPV6` should be specified -in the compilation flags. - -NOTE: The new connection will receive `MG_EV_CONNECT` as its first event -which will report the connect success status. -If the asynchronous resolution fails or the `connect()` syscall fails for -whatever reason (e.g. with `ECONNREFUSED` or `ENETUNREACH`), then -`MG_EV_CONNECT` event will report failure. Code example below: - -```c -static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { - int connect_status; - - switch (ev) { - case MG_EV_CONNECT: - connect_status = * (int *) ev_data; - if (connect_status == 0) { - // Success - } else { - // Error - printf("connect() error: %s\n", strerror(connect_status)); - } - break; - ... - } -} - - ... - mg_connect(mgr, "my_site.com:80", ev_handler); -``` - diff --git a/docs/c-api/mg_net.h/mg_event_handler_t.md b/docs/c-api/mg_net.h/mg_event_handler_t.md deleted file mode 100644 index 5a482224..00000000 --- a/docs/c-api/mg_net.h/mg_event_handler_t.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: "mg_event_handler_t" -decl_name: "mg_event_handler_t" -symbol_kind: "typedef" -signature: | - typedef void (*mg_event_handler_t)(struct mg_connection *nc, int ev, - void *ev_data MG_UD_ARG(void *user_data)); ---- - -Callback function (event handler) prototype. Must be defined by the user. -Mongoose calls the event handler, passing the events defined below. - diff --git a/docs/c-api/mg_net.h/mg_mgr_free.md b/docs/c-api/mg_net.h/mg_mgr_free.md deleted file mode 100644 index 60ad75bd..00000000 --- a/docs/c-api/mg_net.h/mg_mgr_free.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: "mg_mgr_free()" -decl_name: "mg_mgr_free" -symbol_kind: "func" -signature: | - void mg_mgr_free(struct mg_mgr *mgr); ---- - -De-initialises Mongoose manager. - -Closes and deallocates all active connections. - diff --git a/docs/c-api/mg_net.h/mg_mgr_init.md b/docs/c-api/mg_net.h/mg_mgr_init.md deleted file mode 100644 index 1e44bf50..00000000 --- a/docs/c-api/mg_net.h/mg_mgr_init.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -title: "mg_mgr_init()" -decl_name: "mg_mgr_init" -symbol_kind: "func" -signature: | - void mg_mgr_init(struct mg_mgr *mgr, void *user_data); ---- - -Initialise Mongoose manager. Side effect: ignores SIGPIPE signal. -`mgr->user_data` field will be initialised with a `user_data` parameter. -That is an arbitrary pointer, where the user code can associate some data -with the particular Mongoose manager. For example, a C++ wrapper class -could be written in which case `user_data` can hold a pointer to the -class instance. - diff --git a/docs/c-api/mg_net.h/mg_mgr_init_opt.md b/docs/c-api/mg_net.h/mg_mgr_init_opt.md deleted file mode 100644 index 767fed2c..00000000 --- a/docs/c-api/mg_net.h/mg_mgr_init_opt.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: "mg_mgr_init_opt()" -decl_name: "mg_mgr_init_opt" -symbol_kind: "func" -signature: | - void mg_mgr_init_opt(struct mg_mgr *mgr, void *user_data, - struct mg_mgr_init_opts opts); ---- - -Like `mg_mgr_init` but with more options. - -Notably, this allows you to create a manger and choose -dynamically which networking interface implementation to use. - diff --git a/docs/c-api/mg_net.h/mg_mgr_poll.md b/docs/c-api/mg_net.h/mg_mgr_poll.md deleted file mode 100644 index ef48a190..00000000 --- a/docs/c-api/mg_net.h/mg_mgr_poll.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -title: "mg_mgr_poll()" -decl_name: "mg_mgr_poll" -symbol_kind: "func" -signature: | - int mg_mgr_poll(struct mg_mgr *mgr, int milli); ---- - -This function performs the actual IO and must be called in a loop -(an event loop). It returns number of user events generated (except POLLs). -`milli` is the maximum number of milliseconds to sleep. -`mg_mgr_poll()` checks all connections for IO readiness. If at least one -of the connections is IO-ready, `mg_mgr_poll()` triggers the respective -event handlers and returns. - diff --git a/docs/c-api/mg_net.h/mg_next.md b/docs/c-api/mg_net.h/mg_next.md deleted file mode 100644 index 423af6fd..00000000 --- a/docs/c-api/mg_net.h/mg_next.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: "mg_next()" -decl_name: "mg_next" -symbol_kind: "func" -signature: | - struct mg_connection *mg_next(struct mg_mgr *mgr, struct mg_connection *c); ---- - -Iterates over all active connections. - -Returns the next connection from the list -of active connections or `NULL` if there are no more connections. Below -is the iteration idiom: - -```c -for (c = mg_next(srv, NULL); c != NULL; c = mg_next(srv, c)) { - // Do something with connection `c` -} -``` - diff --git a/docs/c-api/mg_net.h/mg_printf.md b/docs/c-api/mg_net.h/mg_printf.md deleted file mode 100644 index 2448235f..00000000 --- a/docs/c-api/mg_net.h/mg_printf.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: "mg_printf()" -decl_name: "mg_printf" -symbol_kind: "func" -signature: | - int mg_printf(struct mg_connection *, const char *fmt, ...); ---- - -Sends `printf`-style formatted data to the connection. - -See `mg_send` for more details on send semantics. - diff --git a/docs/c-api/mg_net.h/mg_resolve.md b/docs/c-api/mg_net.h/mg_resolve.md deleted file mode 100644 index 9861e182..00000000 --- a/docs/c-api/mg_net.h/mg_resolve.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: "mg_resolve()" -decl_name: "mg_resolve" -symbol_kind: "func" -signature: | - int mg_resolve(const char *domain_name, char *ip_addr_buf, size_t buf_len); ---- - -Convert domain name into IP address. - -This is a utility function. If compilation flags have -`-DMG_ENABLE_GETADDRINFO`, then `getaddrinfo()` call is used for name -resolution. Otherwise, `gethostbyname()` is used. - -CAUTION: this function can block. -Return 1 on success, 0 on failure. - diff --git a/docs/c-api/mg_net.h/mg_send.md b/docs/c-api/mg_net.h/mg_send.md deleted file mode 100644 index c6963a0d..00000000 --- a/docs/c-api/mg_net.h/mg_send.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: "mg_send()" -decl_name: "mg_send" -symbol_kind: "func" -signature: | - void mg_send(struct mg_connection *, const void *buf, int len); ---- - -Sends data to the connection. - -Note that sending functions do not actually push data to the socket. -They just append data to the output buffer. MG_EV_SEND will be delivered when -the data has actually been pushed out. - diff --git a/docs/c-api/mg_net.h/mg_set_ssl.md b/docs/c-api/mg_net.h/mg_set_ssl.md deleted file mode 100644 index 35d12d39..00000000 --- a/docs/c-api/mg_net.h/mg_set_ssl.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: "mg_set_ssl()" -decl_name: "mg_set_ssl" -symbol_kind: "func" -signature: | - const char *mg_set_ssl(struct mg_connection *nc, const char *cert, - const char *ca_cert); ---- - -Note: This function is deprecated. Please, use SSL options in -mg_connect_opt. - -Enables SSL for a given connection. -`cert` is a server certificate file name for a listening connection -or a client certificate file name for an outgoing connection. -The certificate files must be in PEM format. The server certificate file -must contain a certificate, concatenated with a private key, optionally -concatenated with DH parameters. -`ca_cert` is a CA certificate or NULL if peer verification is not -required. -Return: NULL on success or error message on error. - diff --git a/docs/c-api/mg_net.h/mg_set_timer.md b/docs/c-api/mg_net.h/mg_set_timer.md deleted file mode 100644 index 0b089206..00000000 --- a/docs/c-api/mg_net.h/mg_set_timer.md +++ /dev/null @@ -1,31 +0,0 @@ ---- -title: "mg_set_timer()" -decl_name: "mg_set_timer" -symbol_kind: "func" -signature: | - double mg_set_timer(struct mg_connection *c, double timestamp); ---- - -Schedules an MG_EV_TIMER event to be delivered at `timestamp` time. -`timestamp` is UNIX time (the number of seconds since Epoch). It is -`double` instead of `time_t` to allow for sub-second precision. -Returns the old timer value. - -Example: set the connect timeout to 1.5 seconds: - -``` - c = mg_connect(&mgr, "cesanta.com", ev_handler); - mg_set_timer(c, mg_time() + 1.5); - ... - - void ev_handler(struct mg_connection *c, int ev, void *ev_data) { - switch (ev) { - case MG_EV_CONNECT: - mg_set_timer(c, 0); // Clear connect timer - break; - case MG_EV_TIMER: - log("Connect timeout"); - c->flags |= MG_F_CLOSE_IMMEDIATELY; - break; -``` - diff --git a/docs/c-api/mg_net.h/mg_socketpair.md b/docs/c-api/mg_net.h/mg_socketpair.md deleted file mode 100644 index bd36cbce..00000000 --- a/docs/c-api/mg_net.h/mg_socketpair.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: "mg_socketpair()" -decl_name: "mg_socketpair" -symbol_kind: "func" -signature: | - int mg_socketpair(sock_t[2], int sock_type); ---- - -Creates a socket pair. -`sock_type` can be either `SOCK_STREAM` or `SOCK_DGRAM`. -Returns 0 on failure and 1 on success. - diff --git a/docs/c-api/mg_net.h/mg_time.md b/docs/c-api/mg_net.h/mg_time.md deleted file mode 100644 index ec93b897..00000000 --- a/docs/c-api/mg_net.h/mg_time.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_time()" -decl_name: "mg_time" -symbol_kind: "func" -signature: | - double mg_time(void); ---- - -A sub-second precision version of time(). - diff --git a/docs/c-api/mg_net.h/mg_vprintf.md b/docs/c-api/mg_net.h/mg_vprintf.md deleted file mode 100644 index ff66e264..00000000 --- a/docs/c-api/mg_net.h/mg_vprintf.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_vprintf()" -decl_name: "mg_vprintf" -symbol_kind: "func" -signature: | - int mg_vprintf(struct mg_connection *, const char *fmt, va_list ap); ---- - -Same as `mg_printf()`, but takes `va_list ap` as an argument. - diff --git a/docs/c-api/mg_net.h/struct_mg_add_sock_opts.md b/docs/c-api/mg_net.h/struct_mg_add_sock_opts.md deleted file mode 100644 index b4b1737b..00000000 --- a/docs/c-api/mg_net.h/struct_mg_add_sock_opts.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: "struct mg_add_sock_opts" -decl_name: "struct mg_add_sock_opts" -symbol_kind: "struct" -signature: | - struct mg_add_sock_opts { - void *user_data; /* Initial value for connection's user_data */ - unsigned int flags; /* Initial connection flags */ - const char **error_string; /* Placeholder for the error string */ - struct mg_iface *iface; /* Interface instance */ - }; ---- - -Optional parameters to `mg_add_sock_opt()`. - -`flags` is an initial `struct mg_connection::flags` bitmask to set, -see `MG_F_*` flags definitions. - diff --git a/docs/c-api/mg_net.h/struct_mg_bind_opts.md b/docs/c-api/mg_net.h/struct_mg_bind_opts.md deleted file mode 100644 index 13217ec7..00000000 --- a/docs/c-api/mg_net.h/struct_mg_bind_opts.md +++ /dev/null @@ -1,44 +0,0 @@ ---- -title: "struct mg_bind_opts" -decl_name: "struct mg_bind_opts" -symbol_kind: "struct" -signature: | - struct mg_bind_opts { - void *user_data; /* Initial value for connection's user_data */ - unsigned int flags; /* Extra connection flags */ - const char **error_string; /* Placeholder for the error string */ - struct mg_iface *iface; /* Interface instance */ - #if MG_ENABLE_SSL - /* - * SSL settings. - * - * Server certificate to present to clients or client certificate to - * present to tunnel dispatcher (for tunneled connections). - */ - const char *ssl_cert; - /* Private key corresponding to the certificate. If ssl_cert is set but - * ssl_key is not, ssl_cert is used. */ - const char *ssl_key; - /* CA bundle used to verify client certificates or tunnel dispatchers. */ - const char *ssl_ca_cert; - /* Colon-delimited list of acceptable cipher suites. - * Names depend on the library used, for example: - * - * ECDH-ECDSA-AES128-GCM-SHA256:DHE-RSA-AES128-SHA256 (OpenSSL) - * TLS-ECDH-ECDSA-WITH-AES-128-GCM-SHA256:TLS-DHE-RSA-WITH-AES-128-GCM-SHA256 - * (mbedTLS) - * - * For OpenSSL the list can be obtained by running "openssl ciphers". - * For mbedTLS, names can be found in library/ssl_ciphersuites.c - * If NULL, a reasonable default is used. - */ - const char *ssl_cipher_suites; - #endif - }; ---- - -Optional parameters to `mg_bind_opt()`. - -`flags` is an initial `struct mg_connection::flags` bitmask to set, -see `MG_F_*` flags definitions. - diff --git a/docs/c-api/mg_net.h/struct_mg_connect_opts.md b/docs/c-api/mg_net.h/struct_mg_connect_opts.md deleted file mode 100644 index f05bf25f..00000000 --- a/docs/c-api/mg_net.h/struct_mg_connect_opts.md +++ /dev/null @@ -1,62 +0,0 @@ ---- -title: "struct mg_connect_opts" -decl_name: "struct mg_connect_opts" -symbol_kind: "struct" -signature: | - struct mg_connect_opts { - void *user_data; /* Initial value for connection's user_data */ - unsigned int flags; /* Extra connection flags */ - const char **error_string; /* Placeholder for the error string */ - struct mg_iface *iface; /* Interface instance */ - const char *nameserver; /* DNS server to use, NULL for default */ - #if MG_ENABLE_SSL - /* - * SSL settings. - * Client certificate to present to the server. - */ - const char *ssl_cert; - /* - * Private key corresponding to the certificate. - * If ssl_cert is set but ssl_key is not, ssl_cert is used. - */ - const char *ssl_key; - /* - * Verify server certificate using this CA bundle. If set to "*", then SSL - * is enabled but no cert verification is performed. - */ - const char *ssl_ca_cert; - /* Colon-delimited list of acceptable cipher suites. - * Names depend on the library used, for example: - * - * ECDH-ECDSA-AES128-GCM-SHA256:DHE-RSA-AES128-SHA256 (OpenSSL) - * TLS-ECDH-ECDSA-WITH-AES-128-GCM-SHA256:TLS-DHE-RSA-WITH-AES-128-GCM-SHA256 - * (mbedTLS) - * - * For OpenSSL the list can be obtained by running "openssl ciphers". - * For mbedTLS, names can be found in library/ssl_ciphersuites.c - * If NULL, a reasonable default is used. - */ - const char *ssl_cipher_suites; - /* - * Server name verification. If ssl_ca_cert is set and the certificate has - * passed verification, its subject will be verified against this string. - * By default (if ssl_server_name is NULL) hostname part of the address will - * be used. Wildcard matching is supported. A special value of "*" disables - * name verification. - */ - const char *ssl_server_name; - /* - * PSK identity and key. Identity is a NUL-terminated string and key is a hex - * string. Key must be either 16 or 32 bytes (32 or 64 hex digits) for AES-128 - * or AES-256 respectively. - * Note: Default list of cipher suites does not include PSK suites, if you - * want to use PSK you will need to set ssl_cipher_suites as well. - */ - const char *ssl_psk_identity; - const char *ssl_psk_key; - #endif - }; ---- - -Optional parameters to `mg_connect_opt()` - diff --git a/docs/c-api/mg_net.h/struct_mg_connection.md b/docs/c-api/mg_net.h/struct_mg_connection.md deleted file mode 100644 index 24a25267..00000000 --- a/docs/c-api/mg_net.h/struct_mg_connection.md +++ /dev/null @@ -1,74 +0,0 @@ ---- -title: "struct mg_connection" -decl_name: "struct mg_connection" -symbol_kind: "struct" -signature: | - struct mg_connection { - struct mg_connection *next, *prev; /* mg_mgr::active_connections linkage */ - struct mg_connection *listener; /* Set only for accept()-ed connections */ - struct mg_mgr *mgr; /* Pointer to containing manager */ - - sock_t sock; /* Socket to the remote peer */ - int err; - union socket_address sa; /* Remote peer address */ - size_t recv_mbuf_limit; /* Max size of recv buffer */ - struct mbuf recv_mbuf; /* Received data */ - struct mbuf send_mbuf; /* Data scheduled for sending */ - time_t last_io_time; /* Timestamp of the last socket IO */ - double ev_timer_time; /* Timestamp of the future MG_EV_TIMER */ - mg_event_handler_t proto_handler; /* Protocol-specific event handler */ - void *proto_data; /* Protocol-specific data */ - void (*proto_data_destructor)(void *proto_data); - mg_event_handler_t handler; /* Event handler function */ - void *user_data; /* User-specific data */ - union { - void *v; - /* - * the C standard is fussy about fitting function pointers into - * void pointers, since some archs might have fat pointers for functions. - */ - mg_event_handler_t f; - } priv_1; - void *priv_2; - void *mgr_data; /* Implementation-specific event manager's data. */ - struct mg_iface *iface; - unsigned long flags; - /* Flags set by Mongoose */ - #define MG_F_LISTENING (1 << 0) /* This connection is listening */ - #define MG_F_UDP (1 << 1) /* This connection is UDP */ - #define MG_F_RESOLVING (1 << 2) /* Waiting for async resolver */ - #define MG_F_CONNECTING (1 << 3) /* connect() call in progress */ - #define MG_F_SSL (1 << 4) /* SSL is enabled on the connection */ - #define MG_F_SSL_HANDSHAKE_DONE (1 << 5) /* SSL hanshake has completed */ - #define MG_F_WANT_READ (1 << 6) /* SSL specific */ - #define MG_F_WANT_WRITE (1 << 7) /* SSL specific */ - #define MG_F_IS_WEBSOCKET (1 << 8) /* Websocket specific */ - #define MG_F_RECV_AND_CLOSE (1 << 9) /* Drain rx and close the connection. */ - - /* Flags that are settable by user */ - #define MG_F_SEND_AND_CLOSE (1 << 10) /* Push remaining data and close */ - #define MG_F_CLOSE_IMMEDIATELY (1 << 11) /* Disconnect */ - - /* Flags for protocol handlers */ - #define MG_F_PROTO_1 (1 << 12) - #define MG_F_PROTO_2 (1 << 13) - #define MG_F_ENABLE_BROADCAST (1 << 14) /* Allow broadcast address usage */ - - /* Flags left for application */ - #define MG_F_USER_1 (1 << 20) - #define MG_F_USER_2 (1 << 21) - #define MG_F_USER_3 (1 << 22) - #define MG_F_USER_4 (1 << 23) - #define MG_F_USER_5 (1 << 24) - #define MG_F_USER_6 (1 << 25) - - #if MG_ENABLE_SSL - void *ssl_if_data; /* SSL library data. */ - #else - void *unused_ssl_if_data; /* To keep the size of the structure the same. */ - #endif - }; ---- - -Mongoose connection. - diff --git a/docs/c-api/mg_net.h/struct_mg_mgr.md b/docs/c-api/mg_net.h/struct_mg_mgr.md deleted file mode 100644 index 44efa5fd..00000000 --- a/docs/c-api/mg_net.h/struct_mg_mgr.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -title: "struct mg_mgr" -decl_name: "struct mg_mgr" -symbol_kind: "struct" -signature: | - struct mg_mgr { - struct mg_connection *active_connections; - #if MG_ENABLE_HEXDUMP - const char *hexdump_file; /* Debug hexdump file path */ - #endif - #if MG_ENABLE_BROADCAST - sock_t ctl[2]; /* Socketpair for mg_broadcast() */ - #endif - void *user_data; /* User data */ - int num_ifaces; - int num_calls; - struct mg_iface **ifaces; /* network interfaces */ - const char *nameserver; /* DNS server to use */ - }; ---- - -Mongoose event manager. - diff --git a/docs/c-api/mg_net.h/struct_mg_mgr_init_opts.md b/docs/c-api/mg_net.h/struct_mg_mgr_init_opts.md deleted file mode 100644 index 7db23de5..00000000 --- a/docs/c-api/mg_net.h/struct_mg_mgr_init_opts.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -title: "struct mg_mgr_init_opts" -decl_name: "struct mg_mgr_init_opts" -symbol_kind: "struct" -signature: | - struct mg_mgr_init_opts { - const struct mg_iface_vtable *main_iface; - int num_ifaces; - const struct mg_iface_vtable **ifaces; - const char *nameserver; - }; ---- - -Optional parameters to `mg_mgr_init_opt()`. - -If `main_iface` is not NULL, it will be used as the main interface in the -default interface set. The pointer will be free'd by `mg_mgr_free`. -Otherwise, the main interface will be autodetected based on the current -platform. - -If `num_ifaces` is 0 and `ifaces` is NULL, the default interface set will be -used. -This is an advanced option, as it requires you to construct a full interface -set, including special networking interfaces required by some optional -features such as TCP tunneling. Memory backing `ifaces` and each of the -`num_ifaces` pointers it contains will be reclaimed by `mg_mgr_free`. - diff --git a/docs/c-api/mg_resolv.h/intro.md b/docs/c-api/mg_resolv.h/intro.md deleted file mode 100644 index 7de6337c..00000000 --- a/docs/c-api/mg_resolv.h/intro.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: "API reference" -symbol_kind: "intro" -decl_name: "mg_resolv.h" -items: - - { name: mg_resolve_async.md } - - { name: mg_resolve_async_opt.md } - - { name: mg_resolve_from_hosts_file.md } - - { name: mg_set_nameserver.md } - - { name: struct_mg_resolve_async_opts.md } ---- - - - diff --git a/docs/c-api/mg_resolv.h/mg_resolve_async.md b/docs/c-api/mg_resolv.h/mg_resolve_async.md deleted file mode 100644 index e4dc5d5d..00000000 --- a/docs/c-api/mg_resolv.h/mg_resolve_async.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -title: "mg_resolve_async()" -decl_name: "mg_resolve_async" -symbol_kind: "func" -signature: | - int mg_resolve_async(struct mg_mgr *mgr, const char *name, int query, - mg_resolve_callback_t cb, void *data); ---- - -See `mg_resolve_async_opt()` - diff --git a/docs/c-api/mg_resolv.h/mg_resolve_async_opt.md b/docs/c-api/mg_resolv.h/mg_resolve_async_opt.md deleted file mode 100644 index 56f209a7..00000000 --- a/docs/c-api/mg_resolv.h/mg_resolve_async_opt.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: "mg_resolve_async_opt()" -decl_name: "mg_resolve_async_opt" -symbol_kind: "func" -signature: | - int mg_resolve_async_opt(struct mg_mgr *mgr, const char *name, int query, - mg_resolve_callback_t cb, void *data, - struct mg_resolve_async_opts opts); ---- - -Resolved a DNS name asynchronously. - -Upon successful resolution, the user callback will be invoked -with the full DNS response message and a pointer to the user's -context `data`. - -In case of timeout while performing the resolution the callback -will receive a NULL `msg`. - -The DNS answers can be extracted with `mg_next_record` and -`mg_dns_parse_record_data`: - -[source,c] ----- -struct in_addr ina; -struct mg_dns_resource_record *rr = mg_next_record(msg, MG_DNS_A_RECORD, - NULL); -mg_dns_parse_record_data(msg, rr, &ina, sizeof(ina)); ----- - diff --git a/docs/c-api/mg_resolv.h/mg_resolve_from_hosts_file.md b/docs/c-api/mg_resolv.h/mg_resolve_from_hosts_file.md deleted file mode 100644 index 42aa1e67..00000000 --- a/docs/c-api/mg_resolv.h/mg_resolve_from_hosts_file.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: "mg_resolve_from_hosts_file()" -decl_name: "mg_resolve_from_hosts_file" -symbol_kind: "func" -signature: | - int mg_resolve_from_hosts_file(const char *host, union socket_address *usa); ---- - -Resolve a name from `/etc/hosts`. - -Returns 0 on success, -1 on failure. - diff --git a/docs/c-api/mg_resolv.h/mg_set_nameserver.md b/docs/c-api/mg_resolv.h/mg_set_nameserver.md deleted file mode 100644 index 2e33c629..00000000 --- a/docs/c-api/mg_resolv.h/mg_set_nameserver.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_set_nameserver()" -decl_name: "mg_set_nameserver" -symbol_kind: "func" -signature: | - void mg_set_nameserver(struct mg_mgr *mgr, const char *nameserver); ---- - -Set default DNS server - diff --git a/docs/c-api/mg_resolv.h/struct_mg_resolve_async_opts.md b/docs/c-api/mg_resolv.h/struct_mg_resolve_async_opts.md deleted file mode 100644 index 8a836b9a..00000000 --- a/docs/c-api/mg_resolv.h/struct_mg_resolve_async_opts.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: "struct mg_resolve_async_opts" -decl_name: "struct mg_resolve_async_opts" -symbol_kind: "struct" -signature: | - struct mg_resolve_async_opts { - const char *nameserver; - int max_retries; /* defaults to 2 if zero */ - int timeout; /* in seconds; defaults to 5 if zero */ - int accept_literal; /* pseudo-resolve literal ipv4 and ipv6 addrs */ - int only_literal; /* only resolves literal addrs; sync cb invocation */ - struct mg_connection **dns_conn; /* return DNS connection */ - }; ---- - -Options for `mg_resolve_async_opt`. - diff --git a/docs/c-api/mg_uri.h/intro.md b/docs/c-api/mg_uri.h/intro.md deleted file mode 100644 index 50487018..00000000 --- a/docs/c-api/mg_uri.h/intro.md +++ /dev/null @@ -1,11 +0,0 @@ ---- -title: "URI" -symbol_kind: "intro" -decl_name: "mg_uri.h" -items: - - { name: mg_assemble_uri.md } - - { name: mg_parse_uri.md } ---- - - - diff --git a/docs/c-api/mg_uri.h/mg_assemble_uri.md b/docs/c-api/mg_uri.h/mg_assemble_uri.md deleted file mode 100644 index 20065148..00000000 --- a/docs/c-api/mg_uri.h/mg_assemble_uri.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: "mg_assemble_uri()" -decl_name: "mg_assemble_uri" -symbol_kind: "func" -signature: | - int mg_assemble_uri(const struct mg_str *scheme, const struct mg_str *user_info, - const struct mg_str *host, unsigned int port, - const struct mg_str *path, const struct mg_str *query, - const struct mg_str *fragment, int normalize_path, - struct mg_str *uri); ---- - -Assemble URI from parts. Any of the inputs can be NULL or zero-length mg_str. - -If normalize_path is true, path is normalized by resolving relative refs. - -Result is a heap-allocated string (uri->p must be free()d after use). - -Returns 0 on success, -1 on error. - diff --git a/docs/c-api/mg_uri.h/mg_parse_uri.md b/docs/c-api/mg_uri.h/mg_parse_uri.md deleted file mode 100644 index 2d330f18..00000000 --- a/docs/c-api/mg_uri.h/mg_parse_uri.md +++ /dev/null @@ -1,33 +0,0 @@ ---- -title: "mg_parse_uri()" -decl_name: "mg_parse_uri" -symbol_kind: "func" -signature: | - int mg_parse_uri(const struct mg_str uri, struct mg_str *scheme, - struct mg_str *user_info, struct mg_str *host, - unsigned int *port, struct mg_str *path, struct mg_str *query, - struct mg_str *fragment); ---- - -Parses an URI and fills string chunks with locations of the respective -uri components within the input uri string. NULL pointers will be -ignored. - -General syntax: - - [scheme://[user_info@]]host[:port][/path][?query][#fragment] - -Example: - - foo.com:80 - tcp://foo.com:1234 - http://foo.com:80/bar?baz=1 - https://user:pw@foo.com:443/blah - -`path` will include the leading slash. `query` won't include the leading `?`. -`host` can contain embedded colons if surrounded by square brackets in order -to support IPv6 literal addresses. - - -Returns 0 on success, -1 on error. - diff --git a/docs/c-api/mg_util.h/intro.md b/docs/c-api/mg_util.h/intro.md deleted file mode 100644 index 0a0bfe3d..00000000 --- a/docs/c-api/mg_util.h/intro.md +++ /dev/null @@ -1,29 +0,0 @@ ---- -title: "Utility API" -symbol_kind: "intro" -decl_name: "mg_util.h" -items: - - { name: mg_base64_decode.md } - - { name: mg_base64_encode.md } - - { name: mg_basic_auth_header.md } - - { name: mg_conn_addr_to_str.md } - - { name: mg_fopen.md } - - { name: mg_fread.md } - - { name: mg_fwrite.md } - - { name: mg_hexdump.md } - - { name: mg_hexdump_connection.md } - - { name: mg_hexdumpf.md } - - { name: mg_is_big_endian.md } - - { name: mg_mbuf_append_base64.md } - - { name: mg_mbuf_append_base64_putc.md } - - { name: mg_open.md } - - { name: mg_skip.md } - - { name: mg_sock_addr_to_str.md } - - { name: mg_sock_to_str.md } - - { name: mg_start_thread.md } - - { name: mg_stat.md } - - { name: mg_url_encode.md } ---- - - - diff --git a/docs/c-api/mg_util.h/mg_base64_decode.md b/docs/c-api/mg_util.h/mg_base64_decode.md deleted file mode 100644 index 92f7c10b..00000000 --- a/docs/c-api/mg_util.h/mg_base64_decode.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: "mg_base64_decode()" -decl_name: "mg_base64_decode" -symbol_kind: "func" -signature: | - int mg_base64_decode(const unsigned char *s, int len, char *dst); ---- - -Decodes base64-encoded string `s`, `len` into the destination `dst`. -The destination has to have enough space to hold the decoded buffer. -Decoding stops either when all strings have been decoded or invalid an -character appeared. -Destination is '\0'-terminated. -Returns the number of decoded characters. On success, that should be equal -to `len`. On error (invalid character) the return value is smaller then -`len`. - diff --git a/docs/c-api/mg_util.h/mg_base64_encode.md b/docs/c-api/mg_util.h/mg_base64_encode.md deleted file mode 100644 index c3b5c05e..00000000 --- a/docs/c-api/mg_util.h/mg_base64_encode.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: "mg_base64_encode()" -decl_name: "mg_base64_encode" -symbol_kind: "func" -signature: | - void mg_base64_encode(const unsigned char *src, int src_len, char *dst); ---- - -Base64-encode chunk of memory `src`, `src_len` into the destination `dst`. -Destination has to have enough space to hold encoded buffer. -Destination is '\0'-terminated. - diff --git a/docs/c-api/mg_util.h/mg_basic_auth_header.md b/docs/c-api/mg_util.h/mg_basic_auth_header.md deleted file mode 100644 index 724ec053..00000000 --- a/docs/c-api/mg_util.h/mg_basic_auth_header.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: "mg_basic_auth_header()" -decl_name: "mg_basic_auth_header" -symbol_kind: "func" -signature: | - void mg_basic_auth_header(const struct mg_str user, const struct mg_str pass, - struct mbuf *buf); ---- - -Generate a Basic Auth header and appends it to buf. -If pass is NULL, then user is expected to contain the credentials pair -already encoded as `user:pass`. - diff --git a/docs/c-api/mg_util.h/mg_conn_addr_to_str.md b/docs/c-api/mg_util.h/mg_conn_addr_to_str.md deleted file mode 100644 index b7603fb2..00000000 --- a/docs/c-api/mg_util.h/mg_conn_addr_to_str.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: "mg_conn_addr_to_str()" -decl_name: "mg_conn_addr_to_str" -symbol_kind: "func" -signature: | - int mg_conn_addr_to_str(struct mg_connection *c, char *buf, size_t len, - int flags); ---- - -Converts a connection's local or remote address into string. - -The `flags` parameter is a bit mask that controls the behaviour, -see `MG_SOCK_STRINGIFY_*` definitions. - -- MG_SOCK_STRINGIFY_IP - print IP address -- MG_SOCK_STRINGIFY_PORT - print port number -- MG_SOCK_STRINGIFY_REMOTE - print remote peer's IP/port, not local address - -If both port number and IP address are printed, they are separated by `:`. -If compiled with `-DMG_ENABLE_IPV6`, IPv6 addresses are supported. -Return length of the stringified address. - diff --git a/docs/c-api/mg_util.h/mg_fopen.md b/docs/c-api/mg_util.h/mg_fopen.md deleted file mode 100644 index 3cb8568a..00000000 --- a/docs/c-api/mg_util.h/mg_fopen.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: "mg_fopen()" -decl_name: "mg_fopen" -symbol_kind: "func" -signature: | - FILE *mg_fopen(const char *path, const char *mode); ---- - -Opens the given file and returns a file stream. - -`path` and `mode` should be UTF8 encoded. - -Return value is the same as for the `fopen()` call. - diff --git a/docs/c-api/mg_util.h/mg_fread.md b/docs/c-api/mg_util.h/mg_fread.md deleted file mode 100644 index 0ff4994a..00000000 --- a/docs/c-api/mg_util.h/mg_fread.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: "mg_fread()" -decl_name: "mg_fread" -symbol_kind: "func" -signature: | - size_t mg_fread(void *ptr, size_t size, size_t count, FILE *f); ---- - -Reads data from the given file stream. - -Return value is a number of bytes readen. - diff --git a/docs/c-api/mg_util.h/mg_fwrite.md b/docs/c-api/mg_util.h/mg_fwrite.md deleted file mode 100644 index 5ddbbbce..00000000 --- a/docs/c-api/mg_util.h/mg_fwrite.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: "mg_fwrite()" -decl_name: "mg_fwrite" -symbol_kind: "func" -signature: | - size_t mg_fwrite(const void *ptr, size_t size, size_t count, FILE *f); ---- - -Writes data to the given file stream. - -Return value is a number of bytes wtitten. - diff --git a/docs/c-api/mg_util.h/mg_hexdump.md b/docs/c-api/mg_util.h/mg_hexdump.md deleted file mode 100644 index c8376bf6..00000000 --- a/docs/c-api/mg_util.h/mg_hexdump.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -title: "mg_hexdump()" -decl_name: "mg_hexdump" -symbol_kind: "func" -signature: | - int mg_hexdump(const void *buf, int len, char *dst, int dst_len); ---- - -Generates a human-readable hexdump of memory chunk. - -Takes a memory buffer `buf` of length `len` and creates a hex dump of that -buffer in `dst`. The generated output is a-la hexdump(1). -Returns the length of generated string, excluding terminating `\0`. If -returned length is bigger than `dst_len`, the overflow bytes are discarded. - diff --git a/docs/c-api/mg_util.h/mg_hexdump_connection.md b/docs/c-api/mg_util.h/mg_hexdump_connection.md deleted file mode 100644 index 03d8a6b2..00000000 --- a/docs/c-api/mg_util.h/mg_hexdump_connection.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -title: "mg_hexdump_connection()" -decl_name: "mg_hexdump_connection" -symbol_kind: "func" -signature: | - void mg_hexdump_connection(struct mg_connection *nc, const char *path, - const void *buf, int num_bytes, int ev); ---- - -Generates human-readable hexdump of the data sent or received by the -connection. `path` is a file name where hexdump should be written. -`num_bytes` is a number of bytes sent/received. `ev` is one of the `MG_*` -events sent to an event handler. This function is supposed to be called from -the event handler. - diff --git a/docs/c-api/mg_util.h/mg_hexdumpf.md b/docs/c-api/mg_util.h/mg_hexdumpf.md deleted file mode 100644 index dcb14ece..00000000 --- a/docs/c-api/mg_util.h/mg_hexdumpf.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_hexdumpf()" -decl_name: "mg_hexdumpf" -symbol_kind: "func" -signature: | - void mg_hexdumpf(FILE *fp, const void *buf, int len); ---- - -Same as mg_hexdump, but with output going to file instead of a buffer. - diff --git a/docs/c-api/mg_util.h/mg_is_big_endian.md b/docs/c-api/mg_util.h/mg_is_big_endian.md deleted file mode 100644 index 4cd54da7..00000000 --- a/docs/c-api/mg_util.h/mg_is_big_endian.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_is_big_endian()" -decl_name: "mg_is_big_endian" -symbol_kind: "func" -signature: | - int mg_is_big_endian(void); ---- - -Returns true if target platform is big endian. - diff --git a/docs/c-api/mg_util.h/mg_mbuf_append_base64.md b/docs/c-api/mg_util.h/mg_mbuf_append_base64.md deleted file mode 100644 index d0617fcf..00000000 --- a/docs/c-api/mg_util.h/mg_mbuf_append_base64.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_mbuf_append_base64()" -decl_name: "mg_mbuf_append_base64" -symbol_kind: "func" -signature: | - void mg_mbuf_append_base64(struct mbuf *mbuf, const void *data, size_t len); ---- - -Encode `len` bytes starting at `data` as base64 and append them to an mbuf. - diff --git a/docs/c-api/mg_util.h/mg_mbuf_append_base64_putc.md b/docs/c-api/mg_util.h/mg_mbuf_append_base64_putc.md deleted file mode 100644 index a4d2b428..00000000 --- a/docs/c-api/mg_util.h/mg_mbuf_append_base64_putc.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_mbuf_append_base64_putc()" -decl_name: "mg_mbuf_append_base64_putc" -symbol_kind: "func" -signature: | - void mg_mbuf_append_base64_putc(char ch, void *user_data); ---- - -Use with cs_base64_init/update/finish in order to write out base64 in chunks. - diff --git a/docs/c-api/mg_util.h/mg_open.md b/docs/c-api/mg_util.h/mg_open.md deleted file mode 100644 index aaa8e56e..00000000 --- a/docs/c-api/mg_util.h/mg_open.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: "mg_open()" -decl_name: "mg_open" -symbol_kind: "func" -signature: | - int mg_open(const char *path, int flag, int mode); ---- - -Opens the given file and returns a file stream. - -`path` should be UTF8 encoded. - -Return value is the same as for the `open()` syscall. - diff --git a/docs/c-api/mg_util.h/mg_skip.md b/docs/c-api/mg_util.h/mg_skip.md deleted file mode 100644 index cc7b2fd1..00000000 --- a/docs/c-api/mg_util.h/mg_skip.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: "mg_skip()" -decl_name: "mg_skip" -symbol_kind: "func" -signature: | - const char *mg_skip(const char *s, const char *end_string, - const char *delimiters, struct mg_str *v); ---- - -Fetches substring from input string `s`, `end` into `v`. -Skips initial delimiter characters. Records first non-delimiter character -at the beginning of substring `v`. Then scans the rest of the string -until a delimiter character or end-of-string is found. -`delimiters` is a 0-terminated string containing delimiter characters. -Either one of `delimiters` or `end_string` terminates the search. -Returns an `s` pointer, advanced forward where parsing has stopped. - diff --git a/docs/c-api/mg_util.h/mg_sock_addr_to_str.md b/docs/c-api/mg_util.h/mg_sock_addr_to_str.md deleted file mode 100644 index b5cb6fdd..00000000 --- a/docs/c-api/mg_util.h/mg_sock_addr_to_str.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: "mg_sock_addr_to_str()" -decl_name: "mg_sock_addr_to_str" -symbol_kind: "func" -signature: | - int mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len, - int flags); ---- - -Convert the socket's address into string. - -`flags` is MG_SOCK_STRINGIFY_IP and/or MG_SOCK_STRINGIFY_PORT. - diff --git a/docs/c-api/mg_util.h/mg_sock_to_str.md b/docs/c-api/mg_util.h/mg_sock_to_str.md deleted file mode 100644 index fb233b56..00000000 --- a/docs/c-api/mg_util.h/mg_sock_to_str.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_sock_to_str()" -decl_name: "mg_sock_to_str" -symbol_kind: "func" -signature: | - void mg_sock_to_str(sock_t sock, char *buf, size_t len, int flags); ---- - -Legacy interface. - diff --git a/docs/c-api/mg_util.h/mg_start_thread.md b/docs/c-api/mg_util.h/mg_start_thread.md deleted file mode 100644 index 4a3c809f..00000000 --- a/docs/c-api/mg_util.h/mg_start_thread.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: "mg_start_thread()" -decl_name: "mg_start_thread" -symbol_kind: "func" -signature: | - void *mg_start_thread(void *(*thread_func); ---- - -Starts a new detached thread. -Arguments and semantics are the same as pthead's `pthread_create()`. -`thread_func` is a thread function, `thread_func_param` is a parameter -that is passed to the thread function. - diff --git a/docs/c-api/mg_util.h/mg_stat.md b/docs/c-api/mg_util.h/mg_stat.md deleted file mode 100644 index 5bd3b0eb..00000000 --- a/docs/c-api/mg_util.h/mg_stat.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -title: "mg_stat()" -decl_name: "mg_stat" -symbol_kind: "func" -signature: | - int mg_stat(const char *path, cs_stat_t *st); ---- - -Performs a 64-bit `stat()` call against a given file. - -`path` should be UTF8 encoded. - -Return value is the same as for `stat()` syscall. - diff --git a/docs/c-api/mg_util.h/mg_url_encode.md b/docs/c-api/mg_util.h/mg_url_encode.md deleted file mode 100644 index 176ac5f7..00000000 --- a/docs/c-api/mg_util.h/mg_url_encode.md +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: "mg_url_encode()" -decl_name: "mg_url_encode" -symbol_kind: "func" -signature: | - struct mg_str mg_url_encode(const struct mg_str src); ---- - -Same as `mg_url_encode_opt(src, "._-$,;~()/", 0)`. - diff --git a/docs/coap/client-example.md b/docs/coap/client-example.md deleted file mode 100644 index 20cdf588..00000000 --- a/docs/coap/client-example.md +++ /dev/null @@ -1,72 +0,0 @@ ---- -title: CoAP client example ---- - -To create a CoAP client, follow this pattern: - -1. Create an outbound connection by calling `mg_connect` -2. Call `mg_set_protocol_coap` for created connection -3. Create an event handler function that handles the following events: -- `MG_EV_COAP_CON` -- `MG_EV_COAP_NOC` -- `MG_EV_COAP_ACK` -- `MG_EV_COAP_RST` - -Here's an example of the simplest CoAP client. -Error checking is omitted for the sake of clarity: - -```c -#include "mongoose.h" - -static int s_time_to_exit = 0; -static char *s_default_address = "udp://coap.me:5683"; - -static void coap_handler(struct mg_connection *nc, int ev, void *p) { - switch (ev) { - case MG_EV_CONNECT: { - struct mg_coap_message cm; - - memset(&cm, 0, sizeof(cm)); - cm.msg_id = 1; - cm.msg_type = MG_COAP_MSG_CON; - mg_coap_send_message(nc, &cm); - break; - } - case MG_EV_COAP_ACK: - case MG_EV_COAP_RST: { - struct mg_coap_message *cm = (struct mg_coap_message *) p; - printf("ACK/RST for message with msg_id = %d received\n", cm->msg_id); - s_time_to_exit = 1; - break; - } - case MG_EV_CLOSE: { - if (s_time_to_exit == 0) { - printf("Server closed connection\n"); - s_time_to_exit = 1; - } - break; - } - } -} - -int main(int argc, char *argv[]) { - struct mg_mgr mgr; - struct mg_connection *nc; - - mg_mgr_init(&mgr, 0); - - nc = mg_connect(&mgr, s_default_address, coap_handler); - - mg_set_protocol_coap(nc); - - while (!s_time_to_exit) { - mg_mgr_poll(&mgr, 1000000); - } - - mg_mgr_free(&mgr); - - return 0; -} -``` - -See full source code at [CoAP client example](https://github.com/cesanta/mongoose/tree/master/examples/coap_client). diff --git a/docs/coap/server-example.md b/docs/coap/server-example.md deleted file mode 100644 index 676f537f..00000000 --- a/docs/coap/server-example.md +++ /dev/null @@ -1,64 +0,0 @@ ---- -title: CoAP server example ---- - -To create a CoAP server, follow this pattern: -1. Create a listening connection by calling `mg_bind()` or `mg_bind_opt()` -2. 2. Call `mg_set_protocol_coap()` for that listening connection. -3. Create an event handler function that handles the following events: -- `MG_EV_COAP_CON` -- `MG_EV_COAP_NOC` -- `MG_EV_COAP_ACK` -- `MG_EV_COAP_RST` - -Here's an example of the simplest CoAP server. Error checking is omitted for the sake of clarity: - -```c -#include "mongoose.h" - -static char *s_default_address = "udp://:5683"; - -static void coap_handler(struct mg_connection *nc, int ev, void *p) { - switch (ev) { - case MG_EV_COAP_CON: { - uint32_t res; - struct mg_coap_message *cm = (struct mg_coap_message *) p; - printf("CON with msg_id = %d received\n", cm->msg_id); - res = mg_coap_send_ack(nc, cm->msg_id); - if (res == 0) { - printf("Successfully sent ACK for message with msg_id = %d\n", - cm->msg_id); - } else { - printf("Error: %d\n", res); - } - break; - } - case MG_EV_COAP_NOC: - case MG_EV_COAP_ACK: - case MG_EV_COAP_RST: { - struct mg_coap_message *cm = (struct mg_coap_message *) p; - printf("ACK/RST/NOC with msg_id = %d received\n", cm->msg_id); - break; - } - } -} - -int main(void) { - struct mg_mgr mgr; - struct mg_connection *nc; - - mg_mgr_init(&mgr, 0); - - nc = mg_bind(&mgr, s_default_address, coap_handler); - mg_set_protocol_coap(nc); - - while (1) { - mg_mgr_poll(&mgr, 1000); - } - - mg_mgr_free(&mgr); - return 0; -} -``` - -See full source code at [CoAP server example](https://github.com/cesanta/mongoose/tree/master/examples/coap_server). diff --git a/docs/core/intro.md b/docs/core/intro.md deleted file mode 100644 index d07c65f0..00000000 --- a/docs/core/intro.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -title: Misc API -items: - - { name: ../c-api/net.h } - - { name: ../c-api/util.h } - - { name: ../c-api/uri.h } - - { name: ../c-api/mbuf.h } ---- diff --git a/docs/dns/examples.md b/docs/dns/examples.md deleted file mode 100644 index f4957c48..00000000 --- a/docs/dns/examples.md +++ /dev/null @@ -1,81 +0,0 @@ -# Examples - - -## DNS server example - -To create a DNS server, follow this pattern: - -1. Create a listening UDP connection by calling `mg_bind()` or `mg_bind_opt()` -2. Call `mg_set_protocol_dns()` for that listening connection. - That attaches a built-in DNS event handler which parses incoming - data and triggers DNS-specific events. -3. Create an event handler function. - -Here is an example of a simpe DNS server. It is a captive DNS server, meaning -that it replies with the same IP address on all queries, regardless of what -exactly host name is being resolved. Error checking is omitted for -the sake of clarity: - -```c -#include "mongoose.h" -#include - -static const char *s_listening_addr = "udp://:5353"; - -static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { - struct mg_dns_message *msg; - struct mg_dns_resource_record *rr; - struct mg_dns_reply reply; - int i; - - switch (ev) { - case MG_DNS_MESSAGE: { - struct mbuf reply_buf; - mbuf_init(&reply_buf, 512); - msg = (struct mg_dns_message *) ev_data; - reply = mg_dns_create_reply(&reply_buf, msg); - - for (i = 0; i < msg->num_questions; i++) { - char rname[256]; - rr = &msg->questions[i]; - mg_dns_uncompress_name(msg, &rr->name, rname, sizeof(rname) - 1); - fprintf(stdout, "Q type %d name %s\n", rr->rtype, rname); - if (rr->rtype == MG_DNS_A_RECORD) { - in_addr_t addr = inet_addr("127.0.0.1"); - mg_dns_reply_record(&reply, rr, NULL, rr->rtype, 10, &addr, 4); - } - } - - mg_dns_send_reply(nc, &reply); - nc->flags |= MG_F_SEND_AND_CLOSE; - mbuf_free(&reply_buf); - break; - } - } -} - -int main(int argc, char *argv[]) { - struct mg_mgr mgr; - struct mg_connection *c; - - mg_mgr_init(&mgr, NULL); - c = mg_bind(&mgr, s_listening_addr, ev_handler); - mg_set_protocol_dns(c); - - for (;;) { - mg_mgr_poll(&mgr, 1000); - } - mg_mgr_free(&mgr); - - return 0; -} -``` - -See full [Captive DNS server example](https://github.com/cesanta/mongoose/tree/master/examples/captive_dns_server). - - -## DNS client example - -See https://github.com/cesanta/mongoose/blob/master/mongoose.c and search -for the `mg_resolve_async_eh()` function - that is the core of -built-in Mongoose async DNS resolver. diff --git a/docs/dns_resolver/intro.md b/docs/dns_resolver/intro.md deleted file mode 100644 index 3b92e748..00000000 --- a/docs/dns_resolver/intro.md +++ /dev/null @@ -1,6 +0,0 @@ ---- -title: Async DNS resolver -items: - - { name: overview.md } - - { name: ../c-api/resolv.h/ } ---- diff --git a/docs/dns_resolver/overview.md b/docs/dns_resolver/overview.md deleted file mode 100644 index 41049ac5..00000000 --- a/docs/dns_resolver/overview.md +++ /dev/null @@ -1,9 +0,0 @@ ---- -title: Overview ---- - -Mongoose uses non-blocking DNS resolver. For each name to be resolved, -it first checks the `/etc/hosts` file (or, `hosts` on Windows). -If the entry is not found there, then the `8.8.8.8` DNS server is queried. -When IP address is found, Mongoose proceeds with making the connection -with the resolved IP address. diff --git a/docs/http/cgi.md b/docs/http/cgi.md deleted file mode 100644 index 1601254f..00000000 --- a/docs/http/cgi.md +++ /dev/null @@ -1,33 +0,0 @@ -# CGI - -[CGI](https://en.wikipedia.org/wiki/Common_Gateway_Interface) -is a simple mechanism to generate dynamic content. -In order to use CGI, call `mg_serve_http()` function and use -`.cgi` file extension for the CGI files. To be more precise, -all files that match `cgi_file_pattern` setting in the -`struct mg_serve_http_opts` are treated as CGI. -If `cgi_file_pattern` is NULL, `**.cgi$|**.php$` is used. - -If Mongoose recognises a file as CGI, it executes it, and sends the output -back to the client. Therefore, -CGI file must be executable. Mongoose honours the shebang line - see -http://en.wikipedia.org/wiki/Shebang_(Unix). - -For example, if both PHP and Perl CGIs are used, then -`#!/path/to/php-cgi.exe` and `#!/path/to/perl.exe` must be the first lines -of the respective CGI scripts. - -It is possible to hardcode the path to the CGI interpreter for all -CGI scripts and disregard the shebang line. To do that, set the -`cgi_interpreter` setting in the `struct mg_serve_http_opts`. - -NOTE: PHP scripts must use `php-cgi.exe` as CGI interpreter, not `php.exe`. -Example: - -```c - opts.cgi_interpreter = "C:\\ruby\\ruby.exe"; -``` -NOTE: In the CGI handler we don't use explicitly a system call waitpid() for -reaping zombie processes. Instead, we set the SIGCHLD handler to SIG_IGN. -It will cause zombie processes to be reaped automatically. -CAUTION: not all OSes (e.g. QNX) reap zombies if SIGCHLD is ignored. diff --git a/docs/http/client-example.md b/docs/http/client-example.md deleted file mode 100644 index 8d2088b7..00000000 --- a/docs/http/client-example.md +++ /dev/null @@ -1,45 +0,0 @@ -# HTTP client example - -To create an HTTP client, follow this pattern: - -1. Create an outbound connection by calling `mg_connect_http()` -2. Create an event handler function that handles `MG_EV_HTTP_REPLY` event - -Here's an example of the simplest HTTP client. -Error checking is omitted for the sake of clarity: - -```c -#include "mongoose.h" - -static const char *url = "http://www.google.com"; -static int exit_flag = 0; - -static void ev_handler(struct mg_connection *c, int ev, void *p) { - if (ev == MG_EV_HTTP_REPLY) { - struct http_message *hm = (struct http_message *)p; - c->flags |= MG_F_CLOSE_IMMEDIATELY; - fwrite(hm->message.p, 1, (int)hm->message.len, stdout); - putchar('\n'); - exit_flag = 1; - } else if (ev == MG_EV_CLOSE) { - exit_flag = 1; - }; -} - -int main(void) { - struct mg_mgr mgr; - - mg_mgr_init(&mgr, NULL); - mg_connect_http(&mgr, ev_handler, url, NULL, NULL); - - - while (exit_flag == 0) { - mg_mgr_poll(&mgr, 1000); - } - mg_mgr_free(&mgr); - - return 0; -} -``` - -See full source code at [HTTP client example](https://github.com/cesanta/mongoose/tree/master/examples/http_client). diff --git a/docs/http/digest-auth.md b/docs/http/digest-auth.md deleted file mode 100644 index 2c5aef9f..00000000 --- a/docs/http/digest-auth.md +++ /dev/null @@ -1,14 +0,0 @@ -# Digest Authentication - -Mongoose has a built-in Digest (MD5) authentication support. In order to -enable Digest authentication, create a file `.htpasswd` in the directory -you would like to protect. That file should be in the format that Apache's -`htdigest` utility. - -You can use either Apache `htdigest` utility, or -Mongoose pre-build binary at https://www.cesanta.com/binary.html -to add new users into that file: - -``` -mongoose -A /path/to/.htdigest mydomain.com joe joes_password -``` diff --git a/docs/http/events.md b/docs/http/events.md deleted file mode 100644 index 756e8e65..00000000 --- a/docs/http/events.md +++ /dev/null @@ -1,37 +0,0 @@ -#: HTTP events - -As discussed in the overview, `mg_set_protocol_http_websocket()` function -parses incoming data, treats it as HTTP or WebSocket, and triggers high-level -HTTP or WebSocket events. Here is a list of events specific to HTTP. - -- MG_EV_HTTP_REQUEST: An HTTP request has arrived. Parsed request - is passed as - `struct http_message` through the handler's `void *ev_data` pointer. -- MG_EV_HTTP_REPLY: An HTTP reply has arrived. Parsed reply is - passed as `struct http_message` through the handler's `void *ev_data` - pointer. -- MG_EV_HTTP_MULTIPART_REQUEST: A multipart POST request has arrived. - This event is sent before body is parsed. After this, the user - should expect a sequence of MG_EV_HTTP_PART_BEGIN/DATA/END requests. - This is also the last time when headers and other request fields are - accessible. -- MG_EV_HTTP_CHUNK: An HTTP chunked-encoding chunk has arrived. - The parsed HTTP reply is passed as `struct http_message` through the - handler's `void *ev_data` pointer. `http_message::body` would contain - incomplete, reassembled HTTP body. - It will grow with every new chunk that arrives, and it can - potentially consume a lot of memory. The event handler may process - the body as chunks are coming, and signal Mongoose to delete processed - body by setting `MG_F_DELETE_CHUNK` in `mg_connection::flags`. When - the last zero chunk is received, - Mongoose sends `MG_EV_HTTP_REPLY` event with - full reassembled body (if handler did not signal to delete chunks) or - with empty body (if handler did signal to delete chunks). -- MG_EV_HTTP_PART_BEGIN: a new part of multipart message is started, - extra parameters are passed in mg_http_multipart_part -- MG_EV_HTTP_PART_DATA: a new portion of data from the multiparted message - no additional headers are available, only data and data size -- MG_EV_HTTP_PART_END: a final boundary received, analogue to maybe used to - find the end of packet - Note: Mongoose should be compiled with MG_ENABLE_HTTP_STREAMING_MULTIPART - to enable multipart events. diff --git a/docs/http/files.md b/docs/http/files.md deleted file mode 100644 index 9700b5c3..00000000 --- a/docs/http/files.md +++ /dev/null @@ -1,44 +0,0 @@ -# Serving files - -API function `mg_serve_http()` makes it easy to serve files from a filesystem. -Generally speaking, that function is an implementation of the HTTP server -that serves static files, CGI and SSI. It's behavior is driven by a list -of options that are consolidated into the `struct mg_serve_http_opts` -structure. See [struct mg_serve_http_opts](#) definition for the full list -of capabilities of `mg_serve_http()`. - -For example, in order to create a web server that serves static files -from the current directory, implement event handler function as follows: - -```c -static void ev_handler(struct mg_connection *c, int ev, void *ev_data) { - if (ev == MG_EV_HTTP_REQUEST) { - struct mg_serve_http_opts opts; - - memset(&opts, 0, sizeof(opts); // Reset all options to defaults - opts.document_root = "."; // Serve files from the current directory - - mg_serve_http(c, (struct http_message *) ev_data, s_http_server_opts); - } -} -``` - -See working example at [simplest web server](https://github.com/cesanta/mongoose/tree/master/examples/simplest_web_server). - -Sometimes there is no need to implement a full static web server, for example -if one works on a RESTful server. If certain endpoints must return the contents -of a static file, a simpler `mg_http_serve_file()` function can be used: - -```c - static void ev_handler(struct mg_connection *c, int ev, void *ev_data) { - switch (ev) { - case MG_EV_HTTP_REQUEST: { - struct http_message *hm = (struct http_message *) ev_data; - mg_http_serve_file(c, hm, "file.txt", - mg_mk_str("text/plain"), mg_mk_str("")); - break; - } - ... - } - } -``` diff --git a/docs/http/server-example.md b/docs/http/server-example.md deleted file mode 100644 index 5bb7e66b..00000000 --- a/docs/http/server-example.md +++ /dev/null @@ -1,53 +0,0 @@ -# HTTP server example - -To create an HTTP server, follow this pattern: - -1. Create a listening connection by calling `mg_bind()` or `mg_bind_opt()` -2. Call `mg_set_protocol_http_websocket()` for that listening connection. - That attaches a built-in HTTP event handler which parses incoming - data and triggers HTTP-specific events. For example, when an HTTP request - is fully buffered, a built-in HTTP handler parses the request and - calls user-defined event handler with `MG_EV_HTTP_REQUEST` event and - parsed HTTP request as an event data. -3. Create event handler function. Note that event handler receives all - events - low level TCP events like `MG_EV_RECV` and high-level HTTP - events like `MG_EV_HTTP_REQUEST`. Normally, an event handler function - should only handle `MG_EV_HTTP_REQUEST` event. - -Here's an example of the simplest HTTP server. Error checking is omitted for -the sake of clarity: - -```c -#include "mongoose.h" - -static const char *s_http_port = "8000"; - -static void ev_handler(struct mg_connection *c, int ev, void *p) { - if (ev == MG_EV_HTTP_REQUEST) { - struct http_message *hm = (struct http_message *) p; - - // We have received an HTTP request. Parsed request is contained in `hm`. - // Send HTTP reply to the client which shows full original request. - mg_send_head(c, 200, hm->message.len, "Content-Type: text/plain"); - mg_printf(c, "%.*s", (int)hm->message.len, hm->message.p); - } -} - -int main(void) { - struct mg_mgr mgr; - struct mg_connection *c; - - mg_mgr_init(&mgr, NULL); - c = mg_bind(&mgr, s_http_port, ev_handler); - mg_set_protocol_http_websocket(c); - - for (;;) { - mg_mgr_poll(&mgr, 1000); - } - mg_mgr_free(&mgr); - - return 0; -} -``` - -See full [HTTP server example](https://github.com/cesanta/mongoose/tree/master/examples/simplest_web_server). diff --git a/docs/http/ssi.md b/docs/http/ssi.md deleted file mode 100644 index 3f84f400..00000000 --- a/docs/http/ssi.md +++ /dev/null @@ -1,57 +0,0 @@ -# SSI - -Server Side Includes (SSI) is a simple interpreted server-side scripting -language which is most commonly used to include the contents of a file -into a web page. It can be useful when it is desirable to include a common -piece of code throughout a website, for example, headers and footers. - -In order to use SSI, call `mg_serve_http()` function and use -`.shtml` file extension for the SSI files. To be more precise, -all files that match `ssi_pattern` setting in the -`struct mg_serve_http_opts` are treated as SSI. -If `ssi_pattern` is NULL, `**.shtml$|**.shtm$` is used. - -Unknown SSI directives are silently ignored by Mongoose. Currently, -the following SSI directives are supported: - -- `` - inject the content of some other file -- `` - runs a command and inject the output -- `` - triggers `MG_EV_SSI_CALL` event - -Note that `` directive supports three path specifications: - -- `` Path is relative to web server root -- `` Path is absolute or relative to the - web server working dir -- ``, `` - Path is relative to current document - -The include directive may be used to include the contents of a file or -the result of running a CGI script. - -The exec directive is used to execute a command on a server, -and show command's output. Example: `` - -The call directive is a way to invoke a C handler from the HTML page. -On each occurrence of `` directive, -Mongoose calls a registered event handler with `MG_EV_SSI_CALL` event. -Event parameter will point to the `PARAMS` string. -An event handler can output any text, for example by calling -`mg_printf()`. This is a flexible way of generating a web page on -server side by calling a C event handler. Example: - -` ` - -In the event handler: - -```c - case MG_EV_SSI_CALL: { - const char *param = (const char *) ev_data; - if (strcmp(param, "foo") == 0) { - mg_printf(c, "hello from foo"); - } else if (strcmp(param, "bar") == 0) { - mg_printf(c, "hello from bar"); - } - break; - } -``` diff --git a/docs/http/ssl.md b/docs/http/ssl.md deleted file mode 100644 index c15fc90c..00000000 --- a/docs/http/ssl.md +++ /dev/null @@ -1,31 +0,0 @@ -# Enabling SSL (HTTPS) - -To enable SSL on the server side, please follow these steps: - -- Obtain SSL certificate file and private key file -- Declare `struct mg_bind_opts`, initialize `ssl_cert` and `ssl_key` -- Use `mg_bind_opt()` to create listening socket - -Example: - -```c -int main(void) { - struct mg_mgr mgr; - struct mg_connection *c; - struct mg_bind_opts bind_opts; - - mg_mgr_init(&mgr, NULL); - - memset(&bind_opts, 0, sizeof(bind_opts)); - bind_opts.ssl_cert = "server.pem"; - bind_opts.ssl_key = "key.pem"; - - // Use bind_opts to specify SSL certificate & key file - c = mg_bind_opt(&mgr, "443", ev_handler, bind_opts); - mg_set_protocol_http_websocket(c); - - ... -} -``` - -For the full example, please see the [Simplest HTTPS server example](https://github.com/cesanta/mongoose/tree/master/examples/simplest_web_server_ssl). diff --git a/docs/http/upload.md b/docs/http/upload.md deleted file mode 100644 index 7f40d451..00000000 --- a/docs/http/upload.md +++ /dev/null @@ -1,34 +0,0 @@ -# Handling file uploads - -In order to handle file uploads, use the following HTML snippet: - -```HTML -
- - -
-``` - -Uploaded files will be sent to the `/upload` endpoint via the `POST` request. -HTTP body will contain multipart-encoded buffer with the file contents. - -To save the uploaded file, use this code snippet: - -```c -struct mg_str cb(struct mg_connection *c, struct mg_str file_name) { - // Return the same filename. Do not actually do this except in test! - // fname is user-controlled and needs to be sanitized. - return file_name; -} - -void ev_handler(struct mg_connection *c, int ev, void *ev_data) { - switch (ev) { - ... - case MG_EV_HTTP_PART_BEGIN: - case MG_EV_HTTP_PART_DATA: - case MG_EV_HTTP_PART_END: - mg_file_upload_handler(c, ev, ev_data, cb); - break; - } -} -``` diff --git a/docs/intro.md b/docs/intro.md deleted file mode 100644 index c5a8b516..00000000 --- a/docs/intro.md +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: Mongoose - a networking library -color: '#1D6482' -repo: https://github.com/cesanta/mongoose -items: - - { name: overview } - - { name: http } - - { name: mqtt } - - { name: dns } - - { name: coap } - - { name: dns_resolver } - - { name: core } ---- diff --git a/docs/media/mbuf.png b/docs/media/mbuf.png deleted file mode 100644 index a162abc3..00000000 Binary files a/docs/media/mbuf.png and /dev/null differ diff --git a/docs/mqtt/examples.md b/docs/mqtt/examples.md deleted file mode 100644 index 1db73d22..00000000 --- a/docs/mqtt/examples.md +++ /dev/null @@ -1,5 +0,0 @@ -# Examples - -- [Client example](https://github.com/cesanta/mongoose/tree/master/examples/mqtt_client) -- [Server example](https://github.com/cesanta/mongoose/tree/master/examples/mqtt_broker) - diff --git a/docs/overview/build-options.md b/docs/overview/build-options.md deleted file mode 100644 index 6f7dee3a..00000000 --- a/docs/overview/build-options.md +++ /dev/null @@ -1,59 +0,0 @@ -# Build options - -Mongoose source code ships in a single .c file that contains functionality -for all supported protocols (modules). Modules can be disabled at compile -time which reduces the executable's size. That can be done by setting preprocessor -flags. Also, some preprocessor flags can be used to tune internal Mongoose -parameters. - -To set a preprocessor flag during compile time, use the `-D ` -compiler option. For example, to disable both MQTT and CoAP, -compile the application `my_app.c` like this (assumed UNIX system): - -``` - $ cc my_app.c mongoose.c -D MG_DISABLE_MQTT -D MG_DISABLE_COAP -``` -## Enabling flags - -- `MG_ENABLE_SSL` Enable [SSL/TLS support](https://docs.cesanta.com/mongoose/master/#/http/ssl.md/) (OpenSSL API) -- `MG_ENABLE_IPV6` Enable IPv6 support -- `MG_ENABLE_MQTT` enable [MQTT client](https://docs.cesanta.com/mongoose/master/#/mqtt/client_example.md/) (on by default, set to 0 to disable) -- `MG_ENABLE_MQTT_BROKER` enable [MQTT broker](https://docs.cesanta.com/mongoose/master/#/mqtt/server_example.md/) -- `MG_ENABLE_DNS_SERVER` enable DNS server -- `MG_ENABLE_COAP` enable CoAP protocol -- `MG_ENABLE_HTTP` Enable HTTP protocol support (on by default, set to 0 to disable) -- `MG_ENABLE_HTTP_CGI` Enable [CGI](https://docs.cesanta.com/mongoose/master/#/http/cgi.md/) support -- `MG_ENABLE_HTTP_SSI` Enable [Server Side Includes](https://docs.cesanta.com/mongoose/master/#/http/ssi.md/) support -- `MG_ENABLE_HTTP_SSI_EXEC` Enable SSI `exec` operator -- `MG_ENABLE_HTTP_WEBDAV` enable WebDAV extensions to HTTP -- `MG_ENABLE_HTTP_WEBSOCKET` enable WebSocket extension to HTTP (on by default, =0 to disable) -- `MG_ENABLE_BROADCAST` enable `mg_broadcast()` API -- `MG_ENABLE_GETADDRINFO` enable `getaddrinfo()` in `mg_resolve2()` -- `MG_ENABLE_THREADS` enable `mg_start_thread()` API - -## Disabling flags - -- `MG_DISABLE_HTTP_DIGEST_AUTH` disable HTTP Digest (MD5) authorisation support -- `CS_DISABLE_SHA1` disable SHA1 support (used by WebSocket) -- `CS_DISABLE_MD5` disable MD5 support (used by HTTP auth) -- `MG_DISABLE_HTTP_KEEP_ALIVE` useful for embedded systems to save resources - -## Platform specific - -Mongoose tries to detect the target platform whenever possible, but in some cases you have -to explicitly declare some peculiarities of your target, such as: - -- `MG_CC3200`: enable workarounds for the TI CC3200 target. -- `MG_ESP8266`: enable workarounds for the ESP8266 target, add `RTOS_SDK` to specify the RTOS SDK flavour. - -## Tunables - -- `MG_MALLOC`, `MG_CALLOC`, `MG_REALLOC`, `MG_FREE` allow you to a use custom - memory allocator, e.g. `-DMG_MALLOC=my_malloc` -- `MG_USE_READ_WRITE` when set replaces calls to `recv` with `read` and `send` with `write`, - thus enabling to add any kind of file descriptor (files, serial devices) to an event manager. -- `MG_SSL_CRYPTO_MODERN`, `MG_SSL_CRYPTO_OLD` - choose either "Modern" or "Old" ciphers - instead of the default "Intermediate" setting. - See [this article](https://wiki.mozilla.org/Security/Server_Side_TLS#Recommended_configurations) for details. -- `MG_USER_FILE_FUNCTIONS` allow you to use custom file operation, by defining you own `mg_stat`, `mg_fopen`, `mg_open`, `mg_fread` and `mg_fwrite` functions - diff --git a/docs/overview/concept.md b/docs/overview/concept.md deleted file mode 100644 index 52660abb..00000000 --- a/docs/overview/concept.md +++ /dev/null @@ -1,45 +0,0 @@ -# Design Concept - -Mongoose has three basic data structures: - -- `struct mg_mgr` is an event manager that holds all active connections -- `struct mg_connection` describes a connection -- `struct mbuf` describes data buffer (received or sent data) - -Connections could be either *listening*, *outbound* or *inbound*. Outbound -connections are created by the `mg_connect()` call. Listening connections are -created by the `mg_bind()` call. Inbound connections are those accepted by a -listening connection. Each connection is described by the `struct mg_connection` -structure, which has a number of fields like socket, event handler function, -send/receive buffer, flags, etc. - -An application that uses mongoose should follow a standard pattern of -event-driven application: - -1. declare and initialise event manager: - - ```c - struct mg_mgr mgr; - mg_mgr_init(&mgr, NULL); - ``` -2. Create connections. For example, a server application should create - listening connections: - - ```c - struct mg_connection *c = mg_bind(&mgr, "80", ev_handler_function); - mg_set_protocol_http_websocket(c); - ``` - -3. create an event loop by calling `mg_mgr_poll()` in a loop: - - ```c - for (;;) { - mg_mgr_poll(&mgr, 1000); - } - ``` - -`mg_mgr_poll()` iterates over all sockets, accepts new connections, sends and -receives data, closes connections and calls event handler functions for the -respective events. For the full example, see -[Usage Example](#/overview/usage-example.md/) -which implements TCP echo server. diff --git a/docs/overview/conn-flags.md b/docs/overview/conn-flags.md deleted file mode 100644 index b2ed2a74..00000000 --- a/docs/overview/conn-flags.md +++ /dev/null @@ -1,30 +0,0 @@ -# Connection flags - -Each connection has a `flags` bit field. Some flags are set by Mongoose, for -example if a user creates an outbound UDP connection using a `udp://1.2.3.4:5678` -address, Mongoose is going to set a `MG_F_UDP` flag for that connection. Other -flags are meant to be set only by the user event handler to tell Mongoose how to -behave. Below is a list of connection flags that are meant to be set by event -handlers: - -* `MG_F_SEND_AND_CLOSE` tells Mongoose that all data has been appended - to the `send_mbuf`. As soon as Mongoose sends it to the socket, the - connection will be closed. -* `MG_F_BUFFER_BUT_DONT_SEND` tells Mongoose to append data to the `send_mbuf` - but hold on sending it, because the data will be modified later and then will - be sent by clearing the `MG_F_BUFFER_BUT_DONT_SEND` flag. -* `MG_F_CLOSE_IMMEDIATELY` tells Mongoose to close the connection immediately, - usually after an error. -* `MG_F_USER_1`, `MG_F_USER_2`, `MG_F_USER_3`, `MG_F_USER_4` could be used by a - developer to store an application-specific state. - -Flags below are set by Mongoose: - -* `MG_F_SSL_HANDSHAKE_DONE` SSL only, set when SSL handshake is done. -* `MG_F_CONNECTING` set when the connection is in connecting state after - `mg_connect()` call but connect did not finish yet. -* `MG_F_LISTENING` set for all listening connections. -* `MG_F_UDP` set if the connection is UDP. -* `MG_F_IS_WEBSOCKET` set if the connection is a WebSocket connection. -* `MG_F_WEBSOCKET_NO_DEFRAG` should be set by a user if the user wants to switch - off automatic WebSocket frame defragmentation. diff --git a/docs/overview/event-handler.md b/docs/overview/event-handler.md deleted file mode 100644 index bb14ba19..00000000 --- a/docs/overview/event-handler.md +++ /dev/null @@ -1,29 +0,0 @@ -# Event handler function - -Each connection has an event handler function associated with it. That function -must be implemented by the user. Event handler is the key element of the Mongoose -application, since it defines the application's behaviour. This is what an event -handler function looks like: - -```c -static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { - switch (ev) { - /* Event handler code that defines behavior of the connection */ - ... - } -} -``` - -- `struct mg_connection *nc`: Connection that has received an event. -- `int ev`: Event number, defined in `mongoose.h`. For example, when data - arrives on an inbound connection, `ev` would be `MG_EV_RECV`. -- `void *ev_data`: This pointer points to the event-specific data, and it has - a different meaning for different events. For example, for an `MG_EV_RECV` event, - `ev_data` is an `int *` pointer, pointing to the number of bytes received - from the remote peer and saved into the receive IO buffer. The exact meaning of - `ev_data` is described for each event. Protocol-specific events usually have - `ev_data` pointing to structures that hold protocol-specific information. - -NOTE: `struct mg_connection` has `void *user_data` which is a placeholder for -application-specific data. Mongoose does not use that pointer. Event handler -can store any kind of information there. diff --git a/docs/overview/events.md b/docs/overview/events.md deleted file mode 100644 index 152f4405..00000000 --- a/docs/overview/events.md +++ /dev/null @@ -1,50 +0,0 @@ -# Events - -Mongoose accepts incoming connections, reads and writes data and calls -specified event handlers for each connection when appropriate. A typical event -sequence is this: - -- For an outbound connection: `MG_EV_CONNECT` -> (`MG_EV_RECV`, `MG_EV_SEND`, - `MG_EV_POLL` ...) -> `MG_EV_CLOSE` -- For an inbound connection: `MG_EV_ACCEPT` -> (`MG_EV_RECV`, `MG_EV_SEND`, - `MG_EV_POLL` ...) -> `MG_EV_CLOSE` - - -Below is a list of core events triggered by Mongoose (note that each protocol -triggers protocol-specific events in addition to the core ones): - -- `MG_EV_ACCEPT`: sent when a new server connection is accepted by a listening - connection. `void *ev_data` is `union socket_address` of the remote peer. - -- `MG_EV_CONNECT`: sent when a new outbound connection created by `mg_connect()` - either failed or succeeded. `void *ev_data` is `int *success`. If `success` - is 0, then the connection has been established, otherwise it contains an error code. - See `mg_connect_opt()` function for code example. - -- `MG_EV_RECV`: New data is received and appended to the end of `recv_mbuf`. - `void *ev_data` is `int *num_received_bytes`. Typically, event handler should - check received data in `nc->recv_mbuf`, discard processed data by calling - `mbuf_remove()`, set connection flags `nc->flags` if necessary (see `struct - mg_connection`) and write data the remote peer by output functions like - `mg_send()`. - - **WARNING**: Mongoose uses `realloc()` to expand the receive buffer. It is - the user's responsibility to discard processed data from the beginning of the receive - buffer, note the `mbuf_remove()` call in the example above. - -- `MG_EV_SEND`: Mongoose has written data to the remote peer and discarded - written data from the `mg_connection::send_mbuf`. `void *ev_data` is `int - *num_sent_bytes`. - - **NOTE**: Mongoose output functions only append data to the - `mg_connection::send_mbuf`. They do not do any socket writes. An actual IO - is done by `mg_mgr_poll()`. An `MG_EV_SEND` event is just a notification about - an IO has been done. - -- `MG_EV_POLL`: Sent to all connections on each invocation of `mg_mgr_poll()`. - This event could be used to do any housekeeping, for example check whether a - certain timeout has expired and closes the connection or send heartbeat - message, etc. - -- `MG_EV_TIMER`: Sent to the connection if `mg_set_timer()` was called. - diff --git a/docs/overview/intro.md b/docs/overview/intro.md deleted file mode 100644 index 4f7c3607..00000000 --- a/docs/overview/intro.md +++ /dev/null @@ -1,29 +0,0 @@ -# Introduction - -Mongoose is a networking library written in C. -It is a swiss army knife for embedded network programming. -It implements event-driven non-blocking APIs for TCP, UDP, HTTP, -WebSocket, CoAP, MQTT for client and server mode. -Features include: - -- Cross-platform: works on Linux/UNIX, MacOS, QNX, eCos, Windows, Android, - iPhone, FreeRTOS -- Native support for [PicoTCP embedded TCP/IP stack](http://www.picotcp.com), - [LWIP embedded TCP/IP stack](https://en.wikipedia.org/wiki/LwIP) -- Works on a variety of embedded boards: TI CC3200, TI MSP430, STM32, ESP8266; - on all Linux-based boards like Raspberry PI, BeagleBone, etc -- Single-threaded, asynchronous, non-blocking core with simple event-based API -- Built-in protocols: - - plain TCP, plain UDP, SSL/TLS (one-way or two-way), client and server - - HTTP client and server - - WebSocket client and server - - MQTT client and server - - CoAP client and server - - DNS client and server - - asynchronous DNS resolver -- Tiny static and run-time footprint -- Source code is both ISO C and ISO C++ compliant -- Very easy to integrate: just copy - [mongoose.c](https://raw.githubusercontent.com/cesanta/mongoose/master/mongoose.c) and - [mongoose.h](https://raw.githubusercontent.com/cesanta/mongoose/master/mongoose.h) - files to your build tree diff --git a/docs/overview/mbufs.md b/docs/overview/mbufs.md deleted file mode 100644 index 25d92f0e..00000000 --- a/docs/overview/mbufs.md +++ /dev/null @@ -1,12 +0,0 @@ -# Memory buffers - -Each connection has a send and receive buffer, `struct mg_connection::send_mbuf` -and `struct mg_connection::recv_mbuf` respectively. When data arrives, -Mongoose appends received data to the `recv_mbuf` and triggers an `MG_EV_RECV` -event. The user may send data back by calling one of the output functions, like -`mg_send()` or `mg_printf()`. Output functions append data to the `send_mbuf`. -When Mongoose successfully writes data to the socket, it discards data from -`struct mg_connection::send_mbuf` and sends an `MG_EV_SEND` event. When the connection -is closed, an `MG_EV_CLOSE` event is sent. - -![](/docs/media/mbuf.png) diff --git a/docs/overview/usage-example.md b/docs/overview/usage-example.md deleted file mode 100644 index b19deb4c..00000000 --- a/docs/overview/usage-example.md +++ /dev/null @@ -1,42 +0,0 @@ -# Example - TCP echo server - -- Copy `mongoose.c` and `mongoose.h` to your build tree -- Write code that uses the Mongoose API, e.g. in `my_app.c` -- Compile application: `$ cc my_app.c mongoose.c` - -```c -#include "mongoose.h" // Include Mongoose API definitions - -// Define an event handler function -static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { - struct mbuf *io = &nc->recv_mbuf; - - switch (ev) { - case MG_EV_RECV: - // This event handler implements simple TCP echo server - mg_send(nc, io->buf, io->len); // Echo received data back - mbuf_remove(io, io->len); // Discard data from recv buffer - break; - default: - break; - } -} - -int main(void) { - struct mg_mgr mgr; - - mg_mgr_init(&mgr, NULL); // Initialize event manager object - - // Note that many connections can be added to a single event manager - // Connections can be created at any point, e.g. in event handler function - mg_bind(&mgr, "1234", ev_handler); // Create listening connection and add it to the event manager - - for (;;) { // Start infinite event loop - mg_mgr_poll(&mgr, 1000); - } - - mg_mgr_free(&mgr); - return 0; -} -``` - diff --git a/examples/CC3200/Makefile b/examples/CC3200/Makefile deleted file mode 100644 index 5075cd5a..00000000 --- a/examples/CC3200/Makefile +++ /dev/null @@ -1,27 +0,0 @@ -SDK ?= $(shell cat sdk.version) -SRC_DIR ?= $(realpath ../../..) -PORT ?= auto - -.PHONY: all clean - -MAKEFLAGS += w - -all clean: - docker run --rm -i -v $(SRC_DIR):/src $(SDK) \ - /bin/bash -c "\ - make -C /src/mongoose mongoose.c mongoose.h && \ - make -C /src/mongoose/examples/CC3200 -f Makefile.build $@ -$(MAKEFLAGS) \ - " - -ifeq ("$(PORT)", "auto") -PORT = $(shell ls -1 /dev/ttyUSB* | tail -n 1) -endif -flash: - docker run --rm -it --privileged -v $(SRC_DIR):/src $(SDK) /bin/bash -c "\ - cd /usr/local/bin; \ - ./cc3200prog $(PORT) /src/fw/platforms/cc3200/firmware/fw.bin \ - " - -debug: - docker run --rm -it --privileged -v $(SRC_DIR):/src $(SDK) \ - /bin/bash -c "cd /src/fw/platforms/cc3200 && tools/gdb.sh" diff --git a/examples/CC3200/Makefile.build b/examples/CC3200/Makefile.build deleted file mode 100644 index 6e16c3ce..00000000 --- a/examples/CC3200/Makefile.build +++ /dev/null @@ -1,108 +0,0 @@ -# -*- mode: makefile -*- -# This file is executed inside Docker build container. -# It can be used without container too if SDK_PATH is configured. - -PLATFORM = CC3200 -SDK_PATH ?= /cc3200-sdk -REPO_PATH ?= ../../.. -BUILD_DIR ?= ./.build -FW_DIR ?= ./out -SLFS_PATH ?= ./slfs - -BINDIR = $(FW_DIR) -OBJDIR = $(BUILD_DIR) - -include $(SDK_PATH)/tools/gcc_scripts/makedefs - -.PHONY: all clean flash - -PROG = cc3200_example - -IPATH = . ../.. $(REPO_PATH) - -VPATH = ../.. - -MONGOOSE_FEATURES = -DMG_ENABLE_SSL -DMG_ENABLE_HTTP_STREAMING_MULTIPART -DMG_MODULE_LINES - -SDK_FLAGS = -DUSE_FREERTOS -DSL_PLATFORM_MULTI_THREADED -# -DTARGET_IS_CC3200 would reduce code size by using functions in ROM -# but then the code won't work on pre-release chips (XCC3200HZ). - -CFLAGS += -Os -Wall -Werror \ - $(SDK_FLAGS) -DCS_PLATFORM=4 -DCC3200_FS_SLFS \ - $(MONGOOSE_FEATURES) $(CFLAGS_EXTRA) - -FW_ELF = $(FW_DIR)/$(PROG).axf -FW_BIN = $(FW_DIR)/$(PROG).bin -FW_MANIFEST = $(FW_DIR)/manifest.json -FW_ZIP = $(FW_DIR)/firmware.zip -BUILD_INFO_JSON = $(OBJDIR)/build_info.json -SLFS_FILES = $(wildcard $(SLFS_PATH)/*) - -.PHONY: all clean flash - -all: $(OBJDIR) $(FW_DIR) $(FW_ZIP) - -clean: - @rm -rf $(OBJDIR) $(wildcard *~) - @rm -rf $(FW_DIR) $(wildcard *~) - -$(OBJDIR): - @echo " MKDIR $@" - @mkdir -p $(OBJDIR) $(FS_BUILD_DIR) - -$(FW_DIR): - @echo " MKDIR $@" - @mkdir -p $(FW_DIR) - -$(FW_ZIP): $(FW_ELF) $(FW_BIN) $(SLFS_FILES) - @echo " Code size: $(shell ls -l $(FW_BIN) | awk '{print $$5}')" - @echo " GEN $(FW_MANIFEST)" - @fw_meta.py gen_build_info \ - --json_output=$(BUILD_INFO_JSON) - @cp -v $(SLFS_FILES) out/ - @cp $(CC3200_SP_FILE)* $(FW_DIR) - @fw_meta.py create_manifest \ - --name=$(PROG) --platform=$(PLATFORM) \ - --build_info=$(BUILD_INFO_JSON) \ - --output=$(FW_MANIFEST) \ - --src_dir=$(FW_DIR) \ - /sys/servicepack.ucf:type=slfile,src=$(CC3200_SP_FILE),falloc=60416,sign=$(notdir $(CC3200_SP_FILE)).sign \ - $(notdir $(CC3200_SP_FILE)).sign:type=signature,src=$(CC3200_SP_FILE).sign \ - /sys/mcuimg.bin:type=app,src=$(notdir $(FW_BIN)) \ - $(foreach f,$(SLFS_FILES), $(notdir $(f)):type=slfile,src=$(notdir $(f))) - @echo " ZIP $@" - @fw_meta.py create_fw \ - --manifest=$(FW_MANIFEST) \ - --src_dir=$(FW_DIR) \ - --output=$@ - -FREERTOS_SRCS = timers.c list.c queue.c tasks.c port.c heap_3.c osi_freertos.c -DRIVER_SRCS = cpu.c gpio.c gpio_if.c i2c.c i2c_if.c interrupt.c pin.c prcm.c spi.c uart.c udma.c utils.c -SL_SRCS = socket.c wlan.c driver.c device.c netapp.c netcfg.c network_common.c timer.c cc_pal.c fs.c -SDK_SRCS = startup_gcc.c $(FREERTOS_SRCS) $(DRIVER_SRCS) $(SL_SRCS) -IPATH += $(SDK_PATH) $(SDK_PATH)/inc $(SDK_PATH)/driverlib \ - $(SDK_PATH)/example/common $(SDK_PATH)/oslib \ - $(SDK_PATH)/simplelink $(SDK_PATH)/simplelink/include \ - $(SDK_PATH)/simplelink_extlib/provisioninglib \ - $(SDK_PATH)/third_party/FreeRTOS/source \ - $(SDK_PATH)/third_party/FreeRTOS/source/include \ - $(SDK_PATH)/third_party/FreeRTOS/source/portable/GCC/ARM_CM4 -VPATH += $(SDK_PATH)/driverlib $(SDK_PATH)/example/common $(SDK_PATH)/oslib \ - $(SDK_PATH)/simplelink $(SDK_PATH)/simplelink/source \ - $(SDK_PATH)/third_party/FreeRTOS/source \ - $(SDK_PATH)/third_party/FreeRTOS/source/portable/GCC/ARM_CM4 \ - $(SDK_PATH)/third_party/FreeRTOS/source/portable/MemMang \ - -APP_SRCS = main.c bm222.c data.c mongoose.c tmp006.c wifi.c $(SDK_SRCS) -APP_OBJS = $(addprefix $(OBJDIR)/,$(patsubst %.c,%.o,$(APP_SRCS))) - -$(FW_ELF): $(APP_OBJS) - -SCATTERgcc_$(PROG) = $(PROG).ld -ENTRY_$(PROG) = ResetISR - -# Disable certain warnings on SDK sources, we have no control over them anyway. - -SDK_OBJS = $(addprefix $(OBJDIR)/,$(patsubst %.c,%.o,$(SDK_SRCS))) -$(SDK_OBJS): CFLAGS += -include mongoose.h -Wno-missing-braces -Wno-strict-aliasing -Wno-parentheses -Wno-unused-variable diff --git a/examples/CC3200/bm222.c b/examples/CC3200/bm222.c deleted file mode 100644 index 6fb2517a..00000000 --- a/examples/CC3200/bm222.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2014-2016 Cesanta Software Limited - * All rights reserved - */ - -#include "bm222.h" - -#include "mongoose.h" -#include "cs_dbg.h" - -#include "i2c_if.h" - -#define BM222_REG_FIFO_STATUS 0x0e - -#define BM222_REG_PMU_BW 0x10 -#define BM222_PMU_BW_7_81_HZ 0x8 -#define BM222_PMU_BW_31_25_HZ 0xA -#define BM222_PMU_BW_62_5_HZ 0xB -#define BM222_PMU_BW_125_HZ 0xC - -#define BM222_REG_BGW_SOFTRESET 0x14 -#define BM222_DO_SOFT_RESET 0xB6 - -#define BM222_REG_FIFO_CONFIG_1 0x3e -#define BM222_FIFO_MODE_FIFO 0x40 -#define BM222_FIFO_DATA_ALL 0 - -#define BM222_REG_FIFO_DATA 0x3f - -struct bm222_ctx *bm222_init(uint8_t addr) { - struct bm222_ctx *ctx = (struct bm222_ctx *) calloc(1, sizeof(*ctx)); - if (ctx == NULL) return NULL; - ctx->addr = addr; - { - unsigned char val[2] = {BM222_REG_BGW_SOFTRESET, BM222_DO_SOFT_RESET}; - if (I2C_IF_Write(addr, val, 2, 1) != 0) goto out_err; - osi_Sleep(2 /* ms */); /* t_w,up1 = 1.8 ms */ - } - if (!bm222_fifo_init(ctx)) return false; - { - unsigned char val[2] = {BM222_REG_PMU_BW, BM222_PMU_BW_125_HZ}; - if (I2C_IF_Write(addr, val, 2, 1) != 0) goto out_err; - } - return ctx; -out_err: - free(ctx); - return NULL; -} - -bool bm222_fifo_init(struct bm222_ctx *ctx) { - unsigned char val[2] = {BM222_REG_FIFO_CONFIG_1, - BM222_FIFO_MODE_FIFO | BM222_FIFO_DATA_ALL}; - return (I2C_IF_Write(ctx->addr, val, 2, 1) == 0); -} - -bool bm222_get_data(struct bm222_ctx *ctx) { - unsigned char reg = BM222_REG_FIFO_STATUS; - unsigned char val; - if (I2C_IF_ReadFrom(ctx->addr, ®, 1, &val, 1) < 0) return false; - unsigned char len = (val & 0x7f); - unsigned char overflow = (val & 0x80 ? 1 : 0); - LOG(LL_DEBUG, ("FIFO len: %d (ovf? %d)", len, overflow)); - reg = BM222_REG_FIFO_DATA; - int8_t fifo[32 * 6], *v = fifo; - if (I2C_IF_ReadFrom(ctx->addr, ®, 1, (unsigned char *) fifo, len * 6) < - 0) { - return false; - } - double now = mg_time(); - /* Of potentially multiple samples, pick one with maximum difference. */ - int32_t max_d = 0; - bool sampled = false; - struct bm222_sample *ls = ctx->data + ctx->last_index, *s = NULL; - if (ls->ts == 0) { - /* The very first sample. */ - ls->ts = now; - ls->x = v[1]; - ls->y = v[3]; - ls->z = v[5]; - v += 6; - len--; - sampled = true; - s = ls; - } - for (; len > 0; v += 6, len--) { - int32_t dx = ((int32_t) v[1]) - ((int32_t) ls->x); - int32_t dy = ((int32_t) v[3]) - ((int32_t) ls->y); - int32_t dz = ((int32_t) v[5]) - ((int32_t) ls->z); - int32_t d = dx * dx + dy * dy + dz * dz; - if ((d > 2 && d > max_d) || (!sampled && now - ls->ts > 1.0)) { - if (!sampled) { - ctx->last_index = (ctx->last_index + 1) % BM222_NUM_SAMPLES; - s = ctx->data + ctx->last_index; - sampled = true; - } - s->ts = now; - s->x = v[1]; - s->y = v[3]; - s->z = v[5]; - if (d > max_d) max_d = d; - LOG(LL_VERBOSE_DEBUG, - ("dx %d dy %d dz %d d %d", (int) dx, (int) dy, (int) dz, (int) d)); - } - } - return (overflow ? bm222_fifo_init(ctx) : true); /* Clear the ovf flag. */ -} diff --git a/examples/CC3200/bm222.h b/examples/CC3200/bm222.h deleted file mode 100644 index 58e44c11..00000000 --- a/examples/CC3200/bm222.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2014-2016 Cesanta Software Limited - * All rights reserved - */ - -#ifndef CS_MONGOOSE_EXAMPLES_CC3200_BM222_H_ -#define CS_MONGOOSE_EXAMPLES_CC3200_BM222_H_ - -#include -#include - -#define BM222_NUM_SAMPLES 64 -struct bm222_ctx { - uint8_t addr; - struct bm222_sample { - double ts; - int8_t x; - int8_t y; - int8_t z; - } data[BM222_NUM_SAMPLES]; - int last_index; -}; - -struct bm222_ctx *bm222_init(uint8_t addr); -bool bm222_fifo_init(struct bm222_ctx *ctx); -bool bm222_get_data(struct bm222_ctx *ctx); - -#endif /* CS_MONGOOSE_EXAMPLES_CC3200_BM222_H_ */ diff --git a/examples/CC3200/cc3200_example.ld b/examples/CC3200/cc3200_example.ld deleted file mode 100644 index 2a8ceb85..00000000 --- a/examples/CC3200/cc3200_example.ld +++ /dev/null @@ -1,94 +0,0 @@ -/***************************************************************************** -* app.ld -* -* GCC Linker script for Mongoose OS. Based on TI's example "blinky.ld". -* -* Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ -* -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions -* are met: -* -* Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* -* Redistributions in binary form must reproduce the above copyright -* notice, this list of conditions and the following disclaimer in the -* documentation and/or other materials provided with the -* distribution. -* -* Neither the name of Texas Instruments Incorporated nor the names of -* its contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* -******************************************************************************/ - - -HEAP_SIZE = 0xB000; - -MEMORY -{ - /* SRAM size of 240KB (0x3C000) for cc3200 ES 1.33 device onward, - * 176KB (0x2C000) for XCC3200HZ (pre-release device). */ - SRAM (rwx) : ORIGIN = 0x20004000, LENGTH = 0x3C000 -} - -SECTIONS -{ - .text : - { - _text = .; - KEEP(*(.intvecs)) - *(.text*) - *(.rodata*) - *(.ARM.extab* .gnu.linkonce.armextab.*) - . = ALIGN(8); - _etext = .; - } > SRAM - - .ARM : { - __exidx_start = .; - *(.ARM.exidx*) - __exidx_end = .; - } > SRAM - - __init_data = .; - - .data : AT(__init_data) - { - _data = .; - *(.data*) - . = ALIGN (8); - _edata = .; - } > SRAM - - .bss : - { - _bss = .; - *(.bss*) - *(COMMON) - _ebss = .; - } > SRAM - - .heap : - { - _heap = .; - . = . + HEAP_SIZE; - . = ALIGN(8); - _eheap = .; - - } -} diff --git a/examples/CC3200/ccs/MG_hello/.ccsproject b/examples/CC3200/ccs/MG_hello/.ccsproject deleted file mode 100644 index e5975ba8..00000000 --- a/examples/CC3200/ccs/MG_hello/.ccsproject +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/examples/CC3200/ccs/MG_hello/.cproject b/examples/CC3200/ccs/MG_hello/.cproject deleted file mode 100644 index cc90a1b0..00000000 --- a/examples/CC3200/ccs/MG_hello/.cproject +++ /dev/null @@ -1,218 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/CC3200/ccs/MG_hello/.project b/examples/CC3200/ccs/MG_hello/.project deleted file mode 100644 index b7593f52..00000000 --- a/examples/CC3200/ccs/MG_hello/.project +++ /dev/null @@ -1,61 +0,0 @@ - - - MG_hello - - - Mongoose - - - - org.eclipse.cdt.managedbuilder.core.genmakebuilder - - - - - org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder - full,incremental, - - - - - - com.ti.ccstudio.core.ccsNature - org.eclipse.cdt.core.cnature - org.eclipse.cdt.managedbuilder.core.managedBuildNature - org.eclipse.cdt.core.ccnature - org.eclipse.cdt.managedbuilder.core.ScannerConfigNature - - - - gpio_if.c - 1 - CC3200_SDK_ROOT/example/common/gpio_if.c - - - network_common.c - 1 - CC3200_SDK_ROOT/example/common/network_common.c - - - startup_ccs.c - 1 - CC3200_SDK_ROOT/example/common/startup_ccs.c - - - wifi.c - 1 - PARENT-2-PROJECT_LOC/wifi.c - - - wifi.h - 1 - PARENT-2-PROJECT_LOC/wifi.h - - - - - CC3200_SDK_ROOT - $%7BTI_PRODUCTS_DIR%7D/CC3200SDK_1.2.0/cc3200-sdk - - - diff --git a/examples/CC3200/ccs/MG_hello/cc3200v1p32.cmd b/examples/CC3200/ccs/MG_hello/cc3200v1p32.cmd deleted file mode 100644 index 9532c611..00000000 --- a/examples/CC3200/ccs/MG_hello/cc3200v1p32.cmd +++ /dev/null @@ -1,82 +0,0 @@ -//***************************************************************************** -// cc3200v1p32.cmd -// -// CCS linker configuration file for cc3200 ES 1.32. -// -// Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ -// -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// -// Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// -// Neither the name of Texas Instruments Incorporated nor the names of -// its contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -//***************************************************************************** - - ---retain=g_pfnVectors - -//***************************************************************************** -// The following command line options are set as part of the CCS project. -// If you are building using the command line, or for some reason want to -// define them here, you can uncomment and modify these lines as needed. -// If you are using CCS for building, it is probably better to make any such -// modifications in your CCS project and leave this file alone. -//***************************************************************************** - - -//***************************************************************************** -// The starting address of the application. Normally the interrupt vectors -// must be located at the beginning of the application. -//***************************************************************************** -#define RAM_BASE 0x20004000 - -/* System memory map */ - -MEMORY -{ - /* Application uses internal RAM for program and data */ - SRAM_CODE (RWX) : origin = 0x20004000, length = 0x20000 - SRAM_DATA (RWX) : origin = 0x20024000, length = 0x1C000 -} - -/* Section allocation in memory */ - -SECTIONS -{ - .intvecs: > RAM_BASE - .init_array : > SRAM_CODE - .vtable : > SRAM_CODE - .text : > SRAM_CODE - .const : > SRAM_CODE - .cinit : > SRAM_CODE - .pinit : > SRAM_CODE - .data : > SRAM_DATA - .bss : > SRAM_DATA - .sysmem : > SRAM_DATA - .stack : > SRAM_DATA(HIGH) -} - diff --git a/examples/CC3200/ccs/MG_hello/main.c b/examples/CC3200/ccs/MG_hello/main.c deleted file mode 100644 index 49ba81ac..00000000 --- a/examples/CC3200/ccs/MG_hello/main.c +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright (c) 2014-2016 Cesanta Software Limited - * All rights reserved - */ - -/* Set up an AP or connect to existing WiFi network. */ -#define WIFI_AP_SSID "Mongoose" -#define WIFI_AP_PASS "" -#define WIFI_AP_CHAN 6 -// #define WIFI_STA_SSID "YourWiFi" -// #define WIFI_STA_PASS "YourPass" - -#define MGOS_TASK_PRIORITY 3 -#define MG_TASK_STACK_SIZE 8192 - -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -/* Mongoose.h brings in SimpleLink support. Do not include simplelink.h. */ -#include - -#include - -#include "cs_dbg.h" -#include "wifi.h" - -void fs_slfs_set_new_file_size(const char *name, size_t size); - -static const char *upload_form = - "\ -

Upload file

\ -
\ - \ - \ -
"; - -static struct mg_str upload_fname(struct mg_connection *nc, - struct mg_str fname) { - struct mg_str lfn; - char *fn = malloc(fname.len + 4); - memcpy(fn, "SL:", 3); - memcpy(fn + 3, fname.p, fname.len); - fn[3 + fname.len] = '\0'; - if (nc->user_data != NULL) { - intptr_t cl = (intptr_t) nc->user_data; - if (cl >= 0) { - fs_slfs_set_new_file_size(fn + 3, cl); - } - } - lfn.len = fname.len + 4; - lfn.p = fn; - return lfn; -} - -void mg_ev_handler(struct mg_connection *nc, int ev, void *ev_data) { - LOG(LL_DEBUG, ("%p ev %d", nc, ev)); - - switch (ev) { - case MG_EV_ACCEPT: { - char addr[32]; - mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr), - MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT); - LOG(LL_INFO, ("Connection %p from %s", nc, addr)); - break; - } - case MG_EV_HTTP_REQUEST: { - char addr[32]; - struct http_message *hm = (struct http_message *) ev_data; - cs_stat_t st; - mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr), - MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT); - LOG(LL_INFO, - ("HTTP request from %s: %.*s %.*s", addr, (int) hm->method.len, - hm->method.p, (int) hm->uri.len, hm->uri.p)); - if (mg_vcmp(&hm->uri, "/upload") == 0 || - (mg_vcmp(&hm->uri, "/") == 0 && mg_stat("SL:index.html", &st) != 0)) { - mg_send(nc, upload_form, strlen(upload_form)); - nc->flags |= MG_F_SEND_AND_CLOSE; - break; - } - struct mg_serve_http_opts opts; - memset(&opts, 0, sizeof(opts)); - opts.document_root = "SL:"; - mg_serve_http(nc, hm, opts); - break; - } - case MG_EV_CLOSE: { - LOG(LL_INFO, ("Connection %p closed", nc)); - break; - } - /* SimpleLink FS requires pre-declaring max file size. We use Content-Length - * for that purpose - it will not exactly match file size, but is guaranteed - * to exceed it and should be close enough. */ - case MG_EV_HTTP_MULTIPART_REQUEST: { - struct http_message *hm = (struct http_message *) ev_data; - struct mg_str *cl_header = mg_get_http_header(hm, "Content-Length"); - intptr_t cl = -1; - if (cl_header != NULL && cl_header->len < 20) { - char buf[20]; - memcpy(buf, cl_header->p, cl_header->len); - buf[cl_header->len] = '\0'; - cl = atoi(buf); - if (cl < 0) cl = -1; - } - nc->user_data = (void *) cl; - break; - } - case MG_EV_HTTP_PART_BEGIN: - case MG_EV_HTTP_PART_DATA: - case MG_EV_HTTP_PART_END: { - struct mg_http_multipart_part *mp = - (struct mg_http_multipart_part *) ev_data; - if (ev == MG_EV_HTTP_PART_BEGIN) { - LOG(LL_INFO, ("Begin file upload: %s", mp->file_name)); - } else if (ev == MG_EV_HTTP_PART_END) { - LOG(LL_INFO, ("End file upload: %s", mp->file_name)); - } - mg_file_upload_handler(nc, ev, ev_data, upload_fname); - } - } -} - -static void mg_init(struct mg_mgr *mgr) { - LOG(LL_INFO, ("MG task running")); - - stop_nwp(); /* See function description in wifi.c */ - LOG(LL_INFO, ("Starting NWP...")); - int role = sl_Start(0, 0, 0); - if (role < 0) { - LOG(LL_ERROR, ("Failed to start NWP")); - return; - } - - LOG(LL_INFO, ("NWP started")); - - sl_fs_init(); - -#if defined(WIFI_STA_SSID) - if (!wifi_setup_sta(WIFI_STA_SSID, WIFI_STA_PASS)) { - LOG(LL_ERROR, ("Error setting up WiFi station")); - } -#elif defined(WIFI_AP_SSID) - if (!wifi_setup_ap(WIFI_AP_SSID, WIFI_AP_PASS, WIFI_AP_CHAN)) { - LOG(LL_ERROR, ("Error setting up WiFi AP")); - } -#else -#error WiFi not configured -#endif - - /* We don't need SimpleLink's web server. */ - sl_NetAppStop(SL_NET_APP_HTTP_SERVER_ID); - - const char *err = ""; - struct mg_bind_opts opts; - memset(&opts, 0, sizeof(opts)); - opts.error_string = &err; - - struct mg_connection *nc = mg_bind(mgr, "80", mg_ev_handler); - if (nc != NULL) { - mg_set_protocol_http_websocket(nc); - } else { - LOG(LL_ERROR, ("Failed to create listener: %s", err)); - } -} - -#ifndef USE_TIRTOS -/* Int vector table, defined in startup_gcc.c */ -extern void (*const g_pfnVectors[])(void); -#endif - -int main(void) { -#ifndef USE_TIRTOS - MAP_IntVTableBaseSet((unsigned long) &g_pfnVectors[0]); -#endif - MAP_IntEnable(FAULT_SYSTICK); - MAP_IntMasterEnable(); - PRCMCC3200MCUInit(); - - setvbuf(stdout, NULL, _IOLBF, 0); - setvbuf(stderr, NULL, _IOLBF, 0); - cs_log_set_level(LL_INFO); - cs_log_set_file(stdout); - - LOG(LL_INFO, ("Hello, world!")); - - /* Set up the red LED. Note that amber and green cannot be used as they share - * pins with I2C. */ - MAP_PRCMPeripheralClkEnable(PRCM_GPIOA1, PRCM_RUN_MODE_CLK); - MAP_PinTypeGPIO(PIN_64, PIN_MODE_0, false); - MAP_GPIODirModeSet(GPIOA1_BASE, 0x2, GPIO_DIR_MODE_OUT); - GPIO_IF_LedConfigure(LED1); - GPIO_IF_LedOn(MCU_RED_LED_GPIO); - - if (VStartSimpleLinkSpawnTask(8) != 0) { - LOG(LL_ERROR, ("Failed to create SL task")); - } - - if (!mg_start_task(MGOS_TASK_PRIORITY, MG_TASK_STACK_SIZE, mg_init)) { - LOG(LL_ERROR, ("Failed to create MG task")); - } - - osi_start(); - - return 0; -} - -/* These are FreeRTOS hooks for various life situations. */ -void vApplicationMallocFailedHook(void) { -} - -void vApplicationIdleHook(void) { -} - -void vApplicationStackOverflowHook(OsiTaskHandle *th, signed char *tn) { -} - -void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *e, - SlHttpServerResponse_t *resp) { -} - -void SimpleLinkSockEventHandler(SlSockEvent_t *e) { -} - -void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *e) { - LOG(LL_ERROR, ("status %d sender %d", e->EventData.deviceEvent.status, - e->EventData.deviceEvent.sender)); -} diff --git a/examples/CC3200/ccs/MG_hello/targetConfigs/CC3200.ccxml b/examples/CC3200/ccs/MG_hello/targetConfigs/CC3200.ccxml deleted file mode 100755 index 0d9d92f1..00000000 --- a/examples/CC3200/ccs/MG_hello/targetConfigs/CC3200.ccxml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/examples/CC3200/ccs/MG_hello/targetConfigs/readme.txt b/examples/CC3200/ccs/MG_hello/targetConfigs/readme.txt deleted file mode 100755 index af97b62d..00000000 --- a/examples/CC3200/ccs/MG_hello/targetConfigs/readme.txt +++ /dev/null @@ -1,9 +0,0 @@ -The 'targetConfigs' folder contains target-configuration (.ccxml) files, automatically generated based -on the device and connection settings specified in your project on the Properties > General page. - -Please note that in automatic target-configuration management, changes to the project's device and/or -connection settings will either modify an existing or generate a new target-configuration file. Thus, -if you manually edit these auto-generated files, you may need to re-apply your changes. Alternatively, -you may create your own target-configuration file for this project and manage it manually. You can -always switch back to automatic target-configuration management by checking the "Manage the project's -target-configuration automatically" checkbox on the project's Properties > General page. \ No newline at end of file diff --git a/examples/CC3200/ccs/MG_sensor_demo/.ccsproject b/examples/CC3200/ccs/MG_sensor_demo/.ccsproject deleted file mode 100644 index e5975ba8..00000000 --- a/examples/CC3200/ccs/MG_sensor_demo/.ccsproject +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/examples/CC3200/ccs/MG_sensor_demo/.cproject b/examples/CC3200/ccs/MG_sensor_demo/.cproject deleted file mode 100644 index 7c76954b..00000000 --- a/examples/CC3200/ccs/MG_sensor_demo/.cproject +++ /dev/null @@ -1,218 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/CC3200/ccs/MG_sensor_demo/.project b/examples/CC3200/ccs/MG_sensor_demo/.project deleted file mode 100644 index a2b77dd2..00000000 --- a/examples/CC3200/ccs/MG_sensor_demo/.project +++ /dev/null @@ -1,101 +0,0 @@ - - - MG_sensor_demo - - - Mongoose - - - - org.eclipse.cdt.managedbuilder.core.genmakebuilder - - - - - org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder - full,incremental, - - - - - - com.ti.ccstudio.core.ccsNature - org.eclipse.cdt.core.cnature - org.eclipse.cdt.managedbuilder.core.managedBuildNature - org.eclipse.cdt.core.ccnature - org.eclipse.cdt.managedbuilder.core.ScannerConfigNature - - - - bm222.c - 1 - PARENT-2-PROJECT_LOC/bm222.c - - - bm222.h - 1 - PARENT-2-PROJECT_LOC/bm222.h - - - data.c - 1 - PARENT-2-PROJECT_LOC/data.c - - - data.h - 1 - PARENT-2-PROJECT_LOC/data.h - - - gpio_if.c - 1 - CC3200_SDK_ROOT/example/common/gpio_if.c - - - i2c_if.c - 1 - CC3200_SDK_ROOT/example/common/i2c_if.c - - - main.c - 1 - PARENT-2-PROJECT_LOC/main.c - - - network_common.c - 1 - CC3200_SDK_ROOT/example/common/network_common.c - - - startup_ccs.c - 1 - CC3200_SDK_ROOT/example/common/startup_ccs.c - - - tmp006.c - 1 - PARENT-2-PROJECT_LOC/tmp006.c - - - tmp006.h - 1 - PARENT-2-PROJECT_LOC/tmp006.h - - - wifi.c - 1 - PARENT-2-PROJECT_LOC/wifi.c - - - wifi.h - 1 - PARENT-2-PROJECT_LOC/wifi.h - - - - - CC3200_SDK_ROOT - $%7BTI_PRODUCTS_DIR%7D/CC3200SDK_1.2.0/cc3200-sdk - - - diff --git a/examples/CC3200/ccs/MG_sensor_demo/cc3200v1p32.cmd b/examples/CC3200/ccs/MG_sensor_demo/cc3200v1p32.cmd deleted file mode 100644 index 9532c611..00000000 --- a/examples/CC3200/ccs/MG_sensor_demo/cc3200v1p32.cmd +++ /dev/null @@ -1,82 +0,0 @@ -//***************************************************************************** -// cc3200v1p32.cmd -// -// CCS linker configuration file for cc3200 ES 1.32. -// -// Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ -// -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// -// Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the -// distribution. -// -// Neither the name of Texas Instruments Incorporated nor the names of -// its contributors may be used to endorse or promote products derived -// from this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -//***************************************************************************** - - ---retain=g_pfnVectors - -//***************************************************************************** -// The following command line options are set as part of the CCS project. -// If you are building using the command line, or for some reason want to -// define them here, you can uncomment and modify these lines as needed. -// If you are using CCS for building, it is probably better to make any such -// modifications in your CCS project and leave this file alone. -//***************************************************************************** - - -//***************************************************************************** -// The starting address of the application. Normally the interrupt vectors -// must be located at the beginning of the application. -//***************************************************************************** -#define RAM_BASE 0x20004000 - -/* System memory map */ - -MEMORY -{ - /* Application uses internal RAM for program and data */ - SRAM_CODE (RWX) : origin = 0x20004000, length = 0x20000 - SRAM_DATA (RWX) : origin = 0x20024000, length = 0x1C000 -} - -/* Section allocation in memory */ - -SECTIONS -{ - .intvecs: > RAM_BASE - .init_array : > SRAM_CODE - .vtable : > SRAM_CODE - .text : > SRAM_CODE - .const : > SRAM_CODE - .cinit : > SRAM_CODE - .pinit : > SRAM_CODE - .data : > SRAM_DATA - .bss : > SRAM_DATA - .sysmem : > SRAM_DATA - .stack : > SRAM_DATA(HIGH) -} - diff --git a/examples/CC3200/ccs/MG_sensor_demo/targetConfigs/CC3200.ccxml b/examples/CC3200/ccs/MG_sensor_demo/targetConfigs/CC3200.ccxml deleted file mode 100755 index 0d9d92f1..00000000 --- a/examples/CC3200/ccs/MG_sensor_demo/targetConfigs/CC3200.ccxml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/examples/CC3200/ccs/MG_sensor_demo/targetConfigs/readme.txt b/examples/CC3200/ccs/MG_sensor_demo/targetConfigs/readme.txt deleted file mode 100755 index af97b62d..00000000 --- a/examples/CC3200/ccs/MG_sensor_demo/targetConfigs/readme.txt +++ /dev/null @@ -1,9 +0,0 @@ -The 'targetConfigs' folder contains target-configuration (.ccxml) files, automatically generated based -on the device and connection settings specified in your project on the Properties > General page. - -Please note that in automatic target-configuration management, changes to the project's device and/or -connection settings will either modify an existing or generate a new target-configuration file. Thus, -if you manually edit these auto-generated files, you may need to re-apply your changes. Alternatively, -you may create your own target-configuration file for this project and manage it manually. You can -always switch back to automatic target-configuration management by checking the "Manage the project's -target-configuration automatically" checkbox on the project's Properties > General page. \ No newline at end of file diff --git a/examples/CC3200/ccs/Makefile b/examples/CC3200/ccs/Makefile deleted file mode 100644 index 85279a19..00000000 --- a/examples/CC3200/ccs/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -clean: - rm -rf */Debug */Release */.launches */.settings */.xdchelp */src diff --git a/examples/CC3200/ccs/Mongoose/.ccsproject b/examples/CC3200/ccs/Mongoose/.ccsproject deleted file mode 100644 index a74fcde5..00000000 --- a/examples/CC3200/ccs/Mongoose/.ccsproject +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/examples/CC3200/ccs/Mongoose/.cproject b/examples/CC3200/ccs/Mongoose/.cproject deleted file mode 100644 index b7482f93..00000000 --- a/examples/CC3200/ccs/Mongoose/.cproject +++ /dev/null @@ -1,166 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/examples/CC3200/ccs/Mongoose/.project b/examples/CC3200/ccs/Mongoose/.project deleted file mode 100644 index 091a2a58..00000000 --- a/examples/CC3200/ccs/Mongoose/.project +++ /dev/null @@ -1,45 +0,0 @@ - - - Mongoose - - - - - - org.eclipse.cdt.managedbuilder.core.genmakebuilder - - - - - org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder - full,incremental, - - - - - - com.ti.ccstudio.core.ccsNature - org.eclipse.cdt.core.cnature - org.eclipse.cdt.managedbuilder.core.managedBuildNature - org.eclipse.cdt.core.ccnature - org.eclipse.cdt.managedbuilder.core.ScannerConfigNature - - - - mongoose.c - 1 - PARENT-4-PROJECT_LOC/mongoose.c - - - mongoose.h - 1 - PARENT-4-PROJECT_LOC/mongoose.h - - - - - CC3200_SDK_ROOT - $%7BTI_PRODUCTS_DIR%7D/CC3200SDK_1.2.0/cc3200-sdk - - - diff --git a/examples/CC3200/ccs/README.md b/examples/CC3200/ccs/README.md deleted file mode 100644 index c07d92ba..00000000 --- a/examples/CC3200/ccs/README.md +++ /dev/null @@ -1,57 +0,0 @@ -# Code Composer Studio example projects - -To run them you will need: - - [CC3200-LAUNCHXL](http://www.ti.com/tool/cc3200-launchxl) dev board. - - [CC3200SDK 1.2.0](http://www.ti.com/tool/cc3200sdk) installed in `TI_PRODUCTS_DIR/CC3200SDK_1.2.0` (typically `C:\ti\CC3200SDK_1.2.0` on Windows, `/home/USER/ti/CC3200SDK_1.2.0` on Linux). - - The latest CC3200SDK-SERVICEPACK should also be installed and flashed to the device - - Code Composer Studio 6 IDE - - Mongoose source code. Either clone the [Git repo](https://github.com/cesanta/mongoose.git) or download the [ZIP archive](https://github.com/cesanta/mongoose/archive/master.zip). - -## Mongoose - The library project -This project produces `Mongoose.lib` - a static library meant to be used by other projects. -Feel free to use it as a dependency for your own projects or just copy `mongoose.c` and `mongoose.h`. -Note that by default a lot of features are enabled, including file serving (which we use in our examples). -You can trim a lot of fat by turning various build options off. -A minimal HTTP serving configuration is about 25 K (compiled for ARM® Cortex®M4 with GCC 4.9 with size optimization on). - -## MG_hello - A simple demo -MG_hello project is a simple web server that serves files from the SimpleLink file system and allows them to be uploaded. -This project depends on the Mongoose library project, make sure you import them both. -When importing, ensure the “copy project to workspace” checkbox is *unchecked*, otherwise file references will be broken. - -When built and run on the device, by default, the example will set up a Wi-Fi network called “Mongoose” (no password). - -Assuming everything works, you should see the following output in CIO: - -``` -main Hello, world! -mg_init MG task running -mg_init Starting NWP... -mg_init NWP started -wifi_setup_ap WiFi: AP Mongoose configured -``` - -Note: If the demo does not proceed past “Starting NWP…”, please reset the board (possibly related to [this](https://e2e.ti.com/support/wireless_connectivity/simplelink_wifi_cc31xx_cc32xx/f/968/p/499123/1806610#1806610) and our [workaround](https://github.com/cesanta/mongoose/commit/848c884fff80de03051344e230392a68d4b51b84) is not always effective). - -And after connecting to Wi-Fi network Mongoose, the following page on http://192.168.4.1/: - - - -Pick a small file (say favicon.ico) and upload. -You should get “Ok, favicon.ico - 16958 bytes.” and it will be served back to you ([link](http://192.168.4.1/)). -If you upload index.html, it will be served instead of the form (but the form will be accessible at [/upload](http://192.168.4.1/upload)). - -## MG_sensor_demo - A more elaborate demo project - -This demo shows the use of [timers](https://docs.cesanta.com/mongoose/latest/#/c-api/net.h/mg_set_timer/) and serving a WebSocket data stream to (potentially) multiple subscribers. -Data from the on-board temperature sensors and accelerometer is streamed to any clients connected over WebSocket, which allows building of responsive, near-real time dashboards. - -The main [event handler function](https://github.com/cesanta/mongoose/blob/master/examples/CC3200/main.c#L81) in main.c does everything MG_hello’s function does, but also handles the websocket connection event - when `MG_EV_WEBSOCKET_HANDSHAKE_DONE` arrives, it switches the event handler to a different one - data_conn_handler (defined [here](https://github.com/cesanta/mongoose/blob/master/examples/CC3200/data.c#L144) in data.c). Doing this is not required, but it keeps the code modular and function size manageable. - -Data acquisition is performed at regular intervals by a timer. Mongoose timers are not very accurate (remember - everything is executed in single thread), but good enough for this case.The timer is first set [in mg_init()](https://github.com/cesanta/mongoose/blob/master/examples/CC3200/main.c#L200), and the `MG_EV_TIMER` event is handled [in the main handler](https://github.com/cesanta/mongoose/blob/master/examples/CC3200/main.c#L123). Mongoose timers must be re-armed manually. - -To try this demo from Code Composer Studio IDE, follow the steps above for MG_hello. Same as for MG_hello, you will only see an upload for initially. Please upload `main.js` and `index.html` from the [slfs directory](https://github.com/cesanta/mongoose/tree/master/examples/CC3200/slfs) and reload the page. You should see something like this: - - - -[This short video](https://youtu.be/T0aFUKIBZxk) shows the demo in action. diff --git a/examples/CC3200/ccs/sensor_demo.png b/examples/CC3200/ccs/sensor_demo.png deleted file mode 100644 index 24ef2af9..00000000 Binary files a/examples/CC3200/ccs/sensor_demo.png and /dev/null differ diff --git a/examples/CC3200/ccs/upload_form.png b/examples/CC3200/ccs/upload_form.png deleted file mode 100644 index 63e59b32..00000000 Binary files a/examples/CC3200/ccs/upload_form.png and /dev/null differ diff --git a/examples/CC3200/cs_dbg.h b/examples/CC3200/cs_dbg.h deleted file mode 100644 index 8422ca3b..00000000 --- a/examples/CC3200/cs_dbg.h +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (c) 2014-2018 Cesanta Software Limited - * All rights reserved - * - * Licensed under the Apache License, Version 2.0 (the ""License""); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an ""AS IS"" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CS_COMMON_CS_DBG_H_ -#define CS_COMMON_CS_DBG_H_ - -#include "common/platform.h" - -#if CS_ENABLE_STDIO -#include -#endif - -#ifndef CS_ENABLE_DEBUG -#define CS_ENABLE_DEBUG 0 -#endif - -#ifndef CS_LOG_PREFIX_LEN -#define CS_LOG_PREFIX_LEN 24 -#endif - -#ifndef CS_LOG_ENABLE_TS_DIFF -#define CS_LOG_ENABLE_TS_DIFF 0 -#endif - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * Log level; `LL_INFO` is the default. Use `cs_log_set_level()` to change it. - */ -enum cs_log_level { - LL_NONE = -1, - LL_ERROR = 0, - LL_WARN = 1, - LL_INFO = 2, - LL_DEBUG = 3, - LL_VERBOSE_DEBUG = 4, - - _LL_MIN = -2, - _LL_MAX = 5, -}; - -/* - * Set max log level to print; messages with the level above the given one will - * not be printed. - */ -void cs_log_set_level(enum cs_log_level level); - -/* - * A comma-separated set of prefix=level. - * prefix is matched against the log prefix exactly as printed, including line - * number, but partial match is ok. Check stops on first matching entry. - * If nothing matches, default level is used. - * - * Examples: - * main.c:=4 - everything from main C at verbose debug level. - * mongoose.c=1,mjs.c=1,=4 - everything at verbose debug except mg_* and mjs_* - * - */ -void cs_log_set_file_level(const char *file_level); - -/* - * Helper function which prints message prefix with the given `level`. - * If message should be printed (according to the current log level - * and filter), prints the prefix and returns 1, otherwise returns 0. - * - * Clients should typically just use `LOG()` macro. - */ -int cs_log_print_prefix(enum cs_log_level level, const char *fname, int line); - -extern enum cs_log_level cs_log_level; - -#if CS_ENABLE_STDIO - -/* - * Set file to write logs into. If `NULL`, logs go to `stderr`. - */ -void cs_log_set_file(FILE *file); - -/* - * Prints log to the current log file, appends "\n" in the end and flushes the - * stream. - */ -void cs_log_printf(const char *fmt, ...) PRINTF_LIKE(1, 2); - -#if CS_ENABLE_STDIO - -/* - * Format and print message `x` with the given level `l`. Example: - * - * ```c - * LOG(LL_INFO, ("my info message: %d", 123)); - * LOG(LL_DEBUG, ("my debug message: %d", 123)); - * ``` - */ -#define LOG(l, x) \ - do { \ - if (cs_log_print_prefix(l, __FILE__, __LINE__)) { \ - cs_log_printf x; \ - } \ - } while (0) - -#else - -#define LOG(l, x) ((void) l) - -#endif - -#ifndef CS_NDEBUG - -/* - * Shortcut for `LOG(LL_VERBOSE_DEBUG, (...))` - */ -#define DBG(x) LOG(LL_VERBOSE_DEBUG, x) - -#else /* NDEBUG */ - -#define DBG(x) - -#endif - -#else /* CS_ENABLE_STDIO */ - -#define LOG(l, x) -#define DBG(x) - -#endif - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CS_COMMON_CS_DBG_H_ */ diff --git a/examples/CC3200/data.c b/examples/CC3200/data.c deleted file mode 100644 index c47ff94b..00000000 --- a/examples/CC3200/data.c +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright (c) 2014-2016 Cesanta Software Limited - * All rights reserved - */ - -#include "data.h" - -#include -#include - -#include "gpio_if.h" - -#include "bm222.h" -#include "tmp006.h" -#include "cs_dbg.h" - -struct temp_data { - double ts; - double volt; - double temp; -}; - -struct conn_state { - struct temp_data td; - double last_sent_td; - unsigned char led; - double last_sent_led; - double last_sent_acc; -}; - -static int s_tmp006_addr; -static struct temp_data s_temp_data; -static struct bm222_ctx *s_accel_ctx; - -void data_init_sensors(int tmp006_addr, int bm222_addr) { - s_tmp006_addr = tmp006_addr; - if (!tmp006_init(tmp006_addr, TMP006_CONV_2, false)) { - LOG(LL_ERROR, ("Failed to init temperature sensor")); - } else { - LOG(LL_INFO, ("Temperature sensor initialized")); - } - s_accel_ctx = bm222_init(bm222_addr); - if (s_accel_ctx == NULL) { - LOG(LL_ERROR, ("Failed to init accelerometer")); - } else { - LOG(LL_INFO, ("Accelerometer initialized")); - } -} - -void data_collect(void) { - double volt = tmp006_read_sensor_voltage(s_tmp006_addr); - double temp = tmp006_read_die_temp(s_tmp006_addr); - if (volt != TMP006_INVALID_READING && temp != TMP006_INVALID_READING) { - s_temp_data.temp = temp; - s_temp_data.volt = volt; - s_temp_data.ts = mg_time(); - LOG(LL_DEBUG, ("V = %lf mV, T = %lf C", volt, temp)); - } - bm222_get_data(s_accel_ctx); -} - -static void send_temp(struct mg_connection *nc, const struct temp_data *td) { - if (td->ts == 0) return; - mg_printf_websocket_frame(nc, WEBSOCKET_OP_TEXT, - "{\"t\": 0, \"ts\": %lf, \"sv\": %lf, \"dt\": %lf}", - td->ts, td->volt, td->temp); -} - -static void send_led(struct mg_connection *nc, double ts, unsigned char led) { - if (ts == 0) return; - mg_printf_websocket_frame(nc, WEBSOCKET_OP_TEXT, - "{\"t\": 1, \"ts\": %lf, \"v\": %d}", ts, led); -} - -static void send_acc_sample(struct mg_connection *nc, - const struct bm222_sample *s) { - if (s->ts == 0) return; - mg_printf_websocket_frame( - nc, WEBSOCKET_OP_TEXT, - "{\"t\": 2, \"ts\": %lf, \"x\": %d, \"y\": %d, \"z\": %d}", s->ts, s->x, - s->y, s->z); -} - -static double send_acc_data_since(struct mg_connection *nc, - const struct bm222_ctx *ctx, double since) { - int i = (ctx->last_index + 1) % BM222_NUM_SAMPLES, n = BM222_NUM_SAMPLES; - double last_sent_ts = 0; - for (; n > 0; i = (i + 1) % BM222_NUM_SAMPLES, n--) { - const struct bm222_sample *s = ctx->data + i; - if (s->ts <= since) continue; - send_acc_sample(nc, s); - last_sent_ts = s->ts; - } - return last_sent_ts; -} - -static void process_command(struct mg_connection *nc, unsigned char *data, - size_t len) { - // TODO(lsm): use proper JSON parser - int cmd, val; - if (sscanf((char *) data, "{\"t\":%d,\"v\":%d}", &cmd, &val) != 2) { - LOG(LL_ERROR, ("Invalid request: %.*s", (int) len, data)); - return; - } - if (cmd == 1) { - switch (val) { - case '0': { - GPIO_IF_LedOff(MCU_RED_LED_GPIO); - break; - } - case '1': { - GPIO_IF_LedOn(MCU_RED_LED_GPIO); - break; - } - case '2': { - GPIO_IF_LedToggle(MCU_RED_LED_GPIO); - break; - } - default: { - LOG(LL_ERROR, ("Invalid value: %.*s", (int) len, data)); - return; - } - } - } else { - LOG(LL_ERROR, ("Unknown command: %.*s", (int) len, data)); - return; - } -} - -void data_conn_handler(struct mg_connection *nc, int ev, void *ev_data) { - struct conn_state *cs = (struct conn_state *) nc->user_data; - if (cs == NULL) { - cs = (struct conn_state *) calloc(1, sizeof(*cs)); - nc->user_data = cs; - } - switch (ev) { - case MG_EV_POLL: - case MG_EV_TIMER: { - const double now = mg_time(); - const unsigned char led = GPIO_IF_LedStatus(MCU_RED_LED_GPIO); - /* Send if there was a change or repeat last data every second. */ - if (s_temp_data.volt != cs->td.volt || s_temp_data.temp != cs->td.temp || - now > cs->last_sent_td + 1.0) { - memcpy(&cs->td, &s_temp_data, sizeof(cs->td)); - send_temp(nc, &cs->td); - cs->last_sent_td = now; - } - if (led != cs->led || now > cs->last_sent_led + 1.0) { - send_led(nc, now, led); - cs->led = led; - cs->last_sent_led = now; - } - if (s_accel_ctx != NULL) { - const struct bm222_sample *ls = - s_accel_ctx->data + s_accel_ctx->last_index; - if (cs->last_sent_acc == 0) { - send_acc_sample(nc, ls); - cs->last_sent_acc = ls->ts; - } else { - double last_sent_ts = - send_acc_data_since(nc, s_accel_ctx, cs->last_sent_acc); - if (last_sent_ts > 0) cs->last_sent_acc = last_sent_ts; - } - } - nc->ev_timer_time = now + 0.05; - break; - } - case MG_EV_WEBSOCKET_FRAME: { - struct websocket_message *wm = (struct websocket_message *) ev_data; - process_command(nc, wm->data, wm->size); - break; - } - case MG_EV_CLOSE: { - LOG(LL_INFO, ("%p closed", nc)); - free(cs); - break; - } - } -} diff --git a/examples/CC3200/data.h b/examples/CC3200/data.h deleted file mode 100644 index 35be40f9..00000000 --- a/examples/CC3200/data.h +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2014-2016 Cesanta Software Limited - * All rights reserved - */ - -#ifndef CS_MONGOOSE_EXAMPLES_CC3200_DATA_H_ -#define CS_MONGOOSE_EXAMPLES_CC3200_DATA_H_ - -#include "mongoose.h" - -void data_collect(void); -void data_init_sensors(int tmp006_addr, int bm222_addr); -void data_conn_handler(struct mg_connection *nc, int ev, void *p); - -#endif /* CS_MONGOOSE_EXAMPLES_CC3200_DATA_H_ */ diff --git a/examples/CC3200/main.c b/examples/CC3200/main.c deleted file mode 100644 index c37c0e1f..00000000 --- a/examples/CC3200/main.c +++ /dev/null @@ -1,309 +0,0 @@ -/* - * Copyright (c) 2014-2016 Cesanta Software Limited - * All rights reserved - */ - -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -/* Mongoose.h brings in SimpleLink support. Do not include simplelink.h. */ -#include -#include "cs_dbg.h" -#include - -#include "data.h" -#include "wifi.h" - -/* Set up an AP or connect to existing WiFi network. */ -#define WIFI_AP_SSID "Mongoose" -#define WIFI_AP_PASS "" -#define WIFI_AP_CHAN 6 -// #define WIFI_STA_SSID "YourWiFi" -// #define WIFI_STA_PASS "YourPass" - -#define DATA_COLLECTION_INTERVAL_MS 20 - -#define CONSOLE_BAUD_RATE 115200 -#define CONSOLE_UART UARTA0_BASE -#define CONSOLE_UART_PERIPH PRCM_UARTA0 -#define MGOS_TASK_PRIORITY 3 -#define MG_TASK_STACK_SIZE 8192 - -#define BM222_ADDR 0x18 -#define TMP006_ADDR 0x41 - -void fs_slfs_set_file_size(const char *name, size_t size); - -static const char *upload_form = - "\ -

Upload file

\ -
\ - \ - \ -
"; - -static struct mg_str upload_fname(struct mg_connection *nc, - struct mg_str fname) { - struct mg_str lfn; - char *fn = malloc(fname.len + 4); - memcpy(fn, "SL:", 3); - memcpy(fn + 3, fname.p, fname.len); - fn[3 + fname.len] = '\0'; - if (nc->user_data != NULL) { - intptr_t cl = (intptr_t) nc->user_data; - if (cl >= 0) { - fs_slfs_set_file_size(fn + 3, cl); - } - } - lfn.len = fname.len + 4; - lfn.p = fn; - return lfn; -} - -static void mg_ev_handler(struct mg_connection *nc, int ev, void *ev_data) { - switch (ev) { - case MG_EV_ACCEPT: { - char addr[32]; - mg_conn_addr_to_str(nc, addr, sizeof(addr), MG_SOCK_STRINGIFY_REMOTE | - MG_SOCK_STRINGIFY_IP | - MG_SOCK_STRINGIFY_PORT); - LOG(LL_INFO, ("%p conn from %s", nc, addr)); - break; - } - case MG_EV_HTTP_REQUEST: { - char addr[32]; - struct http_message *hm = (struct http_message *) ev_data; - cs_stat_t st; - mg_conn_addr_to_str(nc, addr, sizeof(addr), MG_SOCK_STRINGIFY_REMOTE | - MG_SOCK_STRINGIFY_IP | - MG_SOCK_STRINGIFY_PORT); - LOG(LL_INFO, - ("HTTP request from %s: %.*s %.*s", addr, (int) hm->method.len, - hm->method.p, (int) hm->uri.len, hm->uri.p)); - if (mg_vcmp(&hm->uri, "/upload") == 0 || - (mg_vcmp(&hm->uri, "/") == 0 && mg_stat("SL:index.html", &st) != 0)) { - mg_send(nc, upload_form, strlen(upload_form)); - nc->flags |= MG_F_SEND_AND_CLOSE; - break; - } - struct mg_serve_http_opts opts; - memset(&opts, 0, sizeof(opts)); - opts.document_root = "SL:"; - mg_serve_http(nc, hm, opts); - break; - } - case MG_EV_CLOSE: { - LOG(LL_INFO, ("%p closed", nc)); - break; - } - case MG_EV_WEBSOCKET_HANDSHAKE_DONE: { - LOG(LL_INFO, ("%p switching to data mode", nc)); - nc->handler = data_conn_handler; - nc->ev_timer_time = mg_time(); /* Immediately */ - break; - } - case MG_EV_TIMER: { - data_collect(); - nc->ev_timer_time = mg_time() + (DATA_COLLECTION_INTERVAL_MS * 0.001); - break; - } - /* SimpleLink FS requires pre-declaring max file size. We use Content-Length - * for that purpose - it will not exactly match file size, but is guaranteed - * to exceed it and should be close enough. */ - case MG_EV_HTTP_MULTIPART_REQUEST: { - struct http_message *hm = (struct http_message *) ev_data; - struct mg_str *cl_header = mg_get_http_header(hm, "Content-Length"); - intptr_t cl = -1; - if (cl_header != NULL && cl_header->len < 20) { - char buf[20]; - memcpy(buf, cl_header->p, cl_header->len); - buf[cl_header->len] = '\0'; - cl = atoi(buf); - if (cl < 0) cl = -1; - } - nc->user_data = (void *) cl; - break; - } - case MG_EV_HTTP_PART_BEGIN: - case MG_EV_HTTP_PART_DATA: - case MG_EV_HTTP_PART_END: { - struct mg_http_multipart_part *mp = - (struct mg_http_multipart_part *) ev_data; - if (ev == MG_EV_HTTP_PART_BEGIN) { - LOG(LL_INFO, ("Begin file upload: %s", mp->file_name)); - } else if (ev == MG_EV_HTTP_PART_END) { - LOG(LL_INFO, ("End file upload: %s", mp->file_name)); - } - mg_file_upload_handler(nc, ev, ev_data, upload_fname); - } - } -} - -static void mg_init(struct mg_mgr *mgr) { - LOG(LL_INFO, ("MG task running")); - - stop_nwp(); /* See function description in wifi.c */ - LOG(LL_INFO, ("Starting NWP...")); - int role = sl_Start(0, 0, 0); - if (role < 0) { - LOG(LL_ERROR, ("Failed to start NWP")); - return; - } - - { - SlVersionFull ver; - unsigned char opt = SL_DEVICE_GENERAL_VERSION; - unsigned char len = sizeof(ver); - - memset(&ver, 0, sizeof(ver)); - sl_DevGet(SL_DEVICE_GENERAL_CONFIGURATION, &opt, &len, - (unsigned char *) (&ver)); - LOG(LL_INFO, ("NWP v%ld.%ld.%ld.%ld started, host v%ld.%ld.%ld.%ld", - ver.NwpVersion[0], ver.NwpVersion[1], ver.NwpVersion[2], - ver.NwpVersion[3], SL_MAJOR_VERSION_NUM, SL_MINOR_VERSION_NUM, - SL_VERSION_NUM, SL_SUB_VERSION_NUM)); - } - - GPIO_IF_LedToggle(MCU_RED_LED_GPIO); - - data_init_sensors(TMP006_ADDR, BM222_ADDR); - - sl_fs_init(); - -#if defined(WIFI_STA_SSID) - if (!wifi_setup_sta(WIFI_STA_SSID, WIFI_STA_PASS)) { - LOG(LL_ERROR, ("Error setting up WiFi station")); - } -#elif defined(WIFI_AP_SSID) - if (!wifi_setup_ap(WIFI_AP_SSID, WIFI_AP_PASS, WIFI_AP_CHAN)) { - LOG(LL_ERROR, ("Error setting up WiFi AP")); - } -#else -#error WiFi not configured -#endif - - /* We don't need SimpleLink's web server. */ - sl_NetAppStop(SL_NET_APP_HTTP_SERVER_ID); - - const char *err = ""; - struct mg_bind_opts opts; - memset(&opts, 0, sizeof(opts)); - opts.error_string = &err; - - struct mg_connection *nc = mg_bind_opt(mgr, "80", mg_ev_handler, opts); - if (nc != NULL) { - mg_set_protocol_http_websocket(nc); - nc->ev_timer_time = mg_time(); /* Start data collection */ - } else { - LOG(LL_ERROR, ("Failed to create listener: %s", err)); - } -} - -#ifndef USE_TIRTOS -/* Int vector table, defined in startup_gcc.c */ -extern void (*const g_pfnVectors[])(void); -#endif - -int main(void) { -#ifndef USE_TIRTOS - MAP_IntVTableBaseSet((unsigned long) &g_pfnVectors[0]); -#endif - MAP_IntEnable(FAULT_SYSTICK); - MAP_IntMasterEnable(); - PRCMCC3200MCUInit(); - - /* Console UART init. */ - MAP_PRCMPeripheralClkEnable(CONSOLE_UART_PERIPH, PRCM_RUN_MODE_CLK); - MAP_PinTypeUART(PIN_55, PIN_MODE_3); /* PIN_55 -> UART0_TX */ - MAP_PinTypeUART(PIN_57, PIN_MODE_3); /* PIN_57 -> UART0_RX */ - MAP_UARTConfigSetExpClk( - CONSOLE_UART, MAP_PRCMPeripheralClockGet(CONSOLE_UART_PERIPH), - CONSOLE_BAUD_RATE, - (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); - MAP_UARTFIFOLevelSet(CONSOLE_UART, UART_FIFO_TX1_8, UART_FIFO_RX4_8); - MAP_UARTFIFOEnable(CONSOLE_UART); - - setvbuf(stdout, NULL, _IOLBF, 0); - setvbuf(stderr, NULL, _IOLBF, 0); - cs_log_set_level(LL_INFO); - cs_log_set_file(stdout); - - LOG(LL_INFO, ("Hello, world!")); - - MAP_PinTypeI2C(PIN_01, PIN_MODE_1); /* SDA */ - MAP_PinTypeI2C(PIN_02, PIN_MODE_1); /* SCL */ - I2C_IF_Open(I2C_MASTER_MODE_FST); - - /* Set up the red LED. Note that amber and green cannot be used as they share - * pins with I2C. */ - MAP_PRCMPeripheralClkEnable(PRCM_GPIOA1, PRCM_RUN_MODE_CLK); - MAP_PinTypeGPIO(PIN_64, PIN_MODE_0, false); - MAP_GPIODirModeSet(GPIOA1_BASE, 0x2, GPIO_DIR_MODE_OUT); - GPIO_IF_LedConfigure(LED1); - GPIO_IF_LedOn(MCU_RED_LED_GPIO); - - if (VStartSimpleLinkSpawnTask(8) != 0) { - LOG(LL_ERROR, ("Failed to create SL task")); - } - - if (!mg_start_task(MGOS_TASK_PRIORITY, MG_TASK_STACK_SIZE, mg_init)) { - LOG(LL_ERROR, ("Failed to create MG task")); - } - - osi_start(); - - return 0; -} - -/* These are FreeRTOS hooks for various life situations. */ -void vApplicationMallocFailedHook(void) { -} - -void vApplicationIdleHook(void) { -} - -void vApplicationStackOverflowHook(OsiTaskHandle *th, signed char *tn) { -} - -void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *e, - SlHttpServerResponse_t *resp) { -} - -void SimpleLinkSockEventHandler(SlSockEvent_t *e) { -} - -void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *e) { - LOG(LL_ERROR, ("status %d sender %d", e->EventData.deviceEvent.status, - e->EventData.deviceEvent.sender)); -} - -#ifndef __TI_COMPILER_VERSION__ -int _gettimeofday_r(struct _reent *r, struct timeval *tp, void *tz) { -#else -int gettimeofday(struct timeval *tp, void *tz) { -#endif - unsigned long sec; - unsigned short msec; - MAP_PRCMRTCGet(&sec, &msec); - tp->tv_sec = sec; - tp->tv_usec = ((unsigned long) msec) * 1000; - return 0; -} diff --git a/examples/CC3200/sdk.version b/examples/CC3200/sdk.version deleted file mode 100644 index f8bd0dae..00000000 --- a/examples/CC3200/sdk.version +++ /dev/null @@ -1 +0,0 @@ -docker.cesanta.com/cc3200-build:1.3.0-r2 diff --git a/examples/CC3200/slfs/favicon.ico b/examples/CC3200/slfs/favicon.ico deleted file mode 100644 index f8331f7c..00000000 Binary files a/examples/CC3200/slfs/favicon.ico and /dev/null differ diff --git a/examples/CC3200/slfs/index.html b/examples/CC3200/slfs/index.html deleted file mode 100644 index 73881462..00000000 --- a/examples/CC3200/slfs/index.html +++ /dev/null @@ -1,83 +0,0 @@ -l - - - - CC3200 Mongoose sensor demo - - - - - - - -
- -

Mongoose on CC3200 LaunchPad

- -

- This web page demonstrates how Mongoose embedded networking library can be - used to implement real-time data exchange. Here, a TI CC3200 board pushes - JSON-encoded WebSocket frames to the connected browser, which in turn - graphs the data. Also, the browser can send commands to the device wrapped - into a WebSocket frame to turn an LED on/off. -

- - - -
- -
- - diff --git a/examples/CC3200/slfs/main.js b/examples/CC3200/slfs/main.js deleted file mode 100644 index 97c55c20..00000000 --- a/examples/CC3200/slfs/main.js +++ /dev/null @@ -1,587 +0,0 @@ -/*! jQuery v1.11.3 | (c) 2005, 2015 jQuery Foundation, Inc. | jquery.org/license */ -!function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k={},l="1.11.3",m=function(a,b){return new m.fn.init(a,b)},n=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,o=/^-ms-/,p=/-([\da-z])/gi,q=function(a,b){return b.toUpperCase()};m.fn=m.prototype={jquery:l,constructor:m,selector:"",length:0,toArray:function(){return d.call(this)},get:function(a){return null!=a?0>a?this[a+this.length]:this[a]:d.call(this)},pushStack:function(a){var b=m.merge(this.constructor(),a);return b.prevObject=this,b.context=this.context,b},each:function(a,b){return m.each(this,a,b)},map:function(a){return this.pushStack(m.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(d.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(0>a?b:0);return this.pushStack(c>=0&&b>c?[this[c]]:[])},end:function(){return this.prevObject||this.constructor(null)},push:f,sort:c.sort,splice:c.splice},m.extend=m.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for("boolean"==typeof g&&(j=g,g=arguments[h]||{},h++),"object"==typeof g||m.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!=(e=arguments[h]))for(d in e)a=g[d],c=e[d],g!==c&&(j&&c&&(m.isPlainObject(c)||(b=m.isArray(c)))?(b?(b=!1,f=a&&m.isArray(a)?a:[]):f=a&&m.isPlainObject(a)?a:{},g[d]=m.extend(j,f,c)):void 0!==c&&(g[d]=c));return g},m.extend({expando:"jQuery"+(l+Math.random()).replace(/\D/g,""),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return"function"===m.type(a)},isArray:Array.isArray||function(a){return"array"===m.type(a)},isWindow:function(a){return null!=a&&a==a.window},isNumeric:function(a){return!m.isArray(a)&&a-parseFloat(a)+1>=0},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},isPlainObject:function(a){var b;if(!a||"object"!==m.type(a)||a.nodeType||m.isWindow(a))return!1;try{if(a.constructor&&!j.call(a,"constructor")&&!j.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}if(k.ownLast)for(b in a)return j.call(a,b);for(b in a);return void 0===b||j.call(a,b)},type:function(a){return null==a?a+"":"object"==typeof a||"function"==typeof a?h[i.call(a)]||"object":typeof a},globalEval:function(b){b&&m.trim(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(o,"ms-").replace(p,q)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,b,c){var d,e=0,f=a.length,g=r(a);if(c){if(g){for(;f>e;e++)if(d=b.apply(a[e],c),d===!1)break}else for(e in a)if(d=b.apply(a[e],c),d===!1)break}else if(g){for(;f>e;e++)if(d=b.call(a[e],e,a[e]),d===!1)break}else for(e in a)if(d=b.call(a[e],e,a[e]),d===!1)break;return a},trim:function(a){return null==a?"":(a+"").replace(n,"")},makeArray:function(a,b){var c=b||[];return null!=a&&(r(Object(a))?m.merge(c,"string"==typeof a?[a]:a):f.call(c,a)),c},inArray:function(a,b,c){var d;if(b){if(g)return g.call(b,a,c);for(d=b.length,c=c?0>c?Math.max(0,d+c):c:0;d>c;c++)if(c in b&&b[c]===a)return c}return-1},merge:function(a,b){var c=+b.length,d=0,e=a.length;while(c>d)a[e++]=b[d++];if(c!==c)while(void 0!==b[d])a[e++]=b[d++];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g>f;f++)d=!b(a[f],f),d!==h&&e.push(a[f]);return e},map:function(a,b,c){var d,f=0,g=a.length,h=r(a),i=[];if(h)for(;g>f;f++)d=b(a[f],f,c),null!=d&&i.push(d);else for(f in a)d=b(a[f],f,c),null!=d&&i.push(d);return e.apply([],i)},guid:1,proxy:function(a,b){var c,e,f;return"string"==typeof b&&(f=a[b],b=a,a=f),m.isFunction(a)?(c=d.call(arguments,2),e=function(){return a.apply(b||this,c.concat(d.call(arguments)))},e.guid=a.guid=a.guid||m.guid++,e):void 0},now:function(){return+new Date},support:k}),m.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(a,b){h["[object "+b+"]"]=b.toLowerCase()});function r(a){var b="length"in a&&a.length,c=m.type(a);return"function"===c||m.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a}var s=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u="sizzle"+1*new Date,v=a.document,w=0,x=0,y=ha(),z=ha(),A=ha(),B=function(a,b){return a===b&&(l=!0),0},C=1<<31,D={}.hasOwnProperty,E=[],F=E.pop,G=E.push,H=E.push,I=E.slice,J=function(a,b){for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1},K="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",L="[\\x20\\t\\r\\n\\f]",M="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",N=M.replace("w","w#"),O="\\["+L+"*("+M+")(?:"+L+"*([*^$|!~]?=)"+L+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+N+"))|)"+L+"*\\]",P=":("+M+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+O+")*)|.*)\\)|)",Q=new RegExp(L+"+","g"),R=new RegExp("^"+L+"+|((?:^|[^\\\\])(?:\\\\.)*)"+L+"+$","g"),S=new RegExp("^"+L+"*,"+L+"*"),T=new RegExp("^"+L+"*([>+~]|"+L+")"+L+"*"),U=new RegExp("="+L+"*([^\\]'\"]*?)"+L+"*\\]","g"),V=new RegExp(P),W=new RegExp("^"+N+"$"),X={ID:new RegExp("^#("+M+")"),CLASS:new RegExp("^\\.("+M+")"),TAG:new RegExp("^("+M.replace("w","w*")+")"),ATTR:new RegExp("^"+O),PSEUDO:new RegExp("^"+P),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+L+"*(even|odd|(([+-]|)(\\d*)n|)"+L+"*(?:([+-]|)"+L+"*(\\d+)|))"+L+"*\\)|)","i"),bool:new RegExp("^(?:"+K+")$","i"),needsContext:new RegExp("^"+L+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+L+"*((?:-\\d)?\\d*)"+L+"*\\)|)(?=[^-]|$)","i")},Y=/^(?:input|select|textarea|button)$/i,Z=/^h\d$/i,$=/^[^{]+\{\s*\[native \w/,_=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,aa=/[+~]/,ba=/'|\\/g,ca=new RegExp("\\\\([\\da-f]{1,6}"+L+"?|("+L+")|.)","ig"),da=function(a,b,c){var d="0x"+b-65536;return d!==d||c?b:0>d?String.fromCharCode(d+65536):String.fromCharCode(d>>10|55296,1023&d|56320)},ea=function(){m()};try{H.apply(E=I.call(v.childNodes),v.childNodes),E[v.childNodes.length].nodeType}catch(fa){H={apply:E.length?function(a,b){G.apply(a,I.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function ga(a,b,d,e){var f,h,j,k,l,o,r,s,w,x;if((b?b.ownerDocument||b:v)!==n&&m(b),b=b||n,d=d||[],k=b.nodeType,"string"!=typeof a||!a||1!==k&&9!==k&&11!==k)return d;if(!e&&p){if(11!==k&&(f=_.exec(a)))if(j=f[1]){if(9===k){if(h=b.getElementById(j),!h||!h.parentNode)return d;if(h.id===j)return d.push(h),d}else if(b.ownerDocument&&(h=b.ownerDocument.getElementById(j))&&t(b,h)&&h.id===j)return d.push(h),d}else{if(f[2])return H.apply(d,b.getElementsByTagName(a)),d;if((j=f[3])&&c.getElementsByClassName)return H.apply(d,b.getElementsByClassName(j)),d}if(c.qsa&&(!q||!q.test(a))){if(s=r=u,w=b,x=1!==k&&a,1===k&&"object"!==b.nodeName.toLowerCase()){o=g(a),(r=b.getAttribute("id"))?s=r.replace(ba,"\\$&"):b.setAttribute("id",s),s="[id='"+s+"'] ",l=o.length;while(l--)o[l]=s+ra(o[l]);w=aa.test(a)&&pa(b.parentNode)||b,x=o.join(",")}if(x)try{return H.apply(d,w.querySelectorAll(x)),d}catch(y){}finally{r||b.removeAttribute("id")}}}return i(a.replace(R,"$1"),b,d,e)}function ha(){var a=[];function b(c,e){return a.push(c+" ")>d.cacheLength&&delete b[a.shift()],b[c+" "]=e}return b}function ia(a){return a[u]=!0,a}function ja(a){var b=n.createElement("div");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function ka(a,b){var c=a.split("|"),e=a.length;while(e--)d.attrHandle[c[e]]=b}function la(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&(~b.sourceIndex||C)-(~a.sourceIndex||C);if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function ma(a){return function(b){var c=b.nodeName.toLowerCase();return"input"===c&&b.type===a}}function na(a){return function(b){var c=b.nodeName.toLowerCase();return("input"===c||"button"===c)&&b.type===a}}function oa(a){return ia(function(b){return b=+b,ia(function(c,d){var e,f=a([],c.length,b),g=f.length;while(g--)c[e=f[g]]&&(c[e]=!(d[e]=c[e]))})})}function pa(a){return a&&"undefined"!=typeof a.getElementsByTagName&&a}c=ga.support={},f=ga.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return b?"HTML"!==b.nodeName:!1},m=ga.setDocument=function(a){var b,e,g=a?a.ownerDocument||a:v;return g!==n&&9===g.nodeType&&g.documentElement?(n=g,o=g.documentElement,e=g.defaultView,e&&e!==e.top&&(e.addEventListener?e.addEventListener("unload",ea,!1):e.attachEvent&&e.attachEvent("onunload",ea)),p=!f(g),c.attributes=ja(function(a){return a.className="i",!a.getAttribute("className")}),c.getElementsByTagName=ja(function(a){return a.appendChild(g.createComment("")),!a.getElementsByTagName("*").length}),c.getElementsByClassName=$.test(g.getElementsByClassName),c.getById=ja(function(a){return o.appendChild(a).id=u,!g.getElementsByName||!g.getElementsByName(u).length}),c.getById?(d.find.ID=function(a,b){if("undefined"!=typeof b.getElementById&&p){var c=b.getElementById(a);return c&&c.parentNode?[c]:[]}},d.filter.ID=function(a){var b=a.replace(ca,da);return function(a){return a.getAttribute("id")===b}}):(delete d.find.ID,d.filter.ID=function(a){var b=a.replace(ca,da);return function(a){var c="undefined"!=typeof a.getAttributeNode&&a.getAttributeNode("id");return c&&c.value===b}}),d.find.TAG=c.getElementsByTagName?function(a,b){return"undefined"!=typeof b.getElementsByTagName?b.getElementsByTagName(a):c.qsa?b.querySelectorAll(a):void 0}:function(a,b){var c,d=[],e=0,f=b.getElementsByTagName(a);if("*"===a){while(c=f[e++])1===c.nodeType&&d.push(c);return d}return f},d.find.CLASS=c.getElementsByClassName&&function(a,b){return p?b.getElementsByClassName(a):void 0},r=[],q=[],(c.qsa=$.test(g.querySelectorAll))&&(ja(function(a){o.appendChild(a).innerHTML="",a.querySelectorAll("[msallowcapture^='']").length&&q.push("[*^$]="+L+"*(?:''|\"\")"),a.querySelectorAll("[selected]").length||q.push("\\["+L+"*(?:value|"+K+")"),a.querySelectorAll("[id~="+u+"-]").length||q.push("~="),a.querySelectorAll(":checked").length||q.push(":checked"),a.querySelectorAll("a#"+u+"+*").length||q.push(".#.+[+~]")}),ja(function(a){var b=g.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&q.push("name"+L+"*[*^$|!~]?="),a.querySelectorAll(":enabled").length||q.push(":enabled",":disabled"),a.querySelectorAll("*,:x"),q.push(",.*:")})),(c.matchesSelector=$.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&ja(function(a){c.disconnectedMatch=s.call(a,"div"),s.call(a,"[s!='']:x"),r.push("!=",P)}),q=q.length&&new RegExp(q.join("|")),r=r.length&&new RegExp(r.join("|")),b=$.test(o.compareDocumentPosition),t=b||$.test(o.contains)?function(a,b){var c=9===a.nodeType?a.documentElement:a,d=b&&b.parentNode;return a===d||!(!d||1!==d.nodeType||!(c.contains?c.contains(d):a.compareDocumentPosition&&16&a.compareDocumentPosition(d)))}:function(a,b){if(b)while(b=b.parentNode)if(b===a)return!0;return!1},B=b?function(a,b){if(a===b)return l=!0,0;var d=!a.compareDocumentPosition-!b.compareDocumentPosition;return d?d:(d=(a.ownerDocument||a)===(b.ownerDocument||b)?a.compareDocumentPosition(b):1,1&d||!c.sortDetached&&b.compareDocumentPosition(a)===d?a===g||a.ownerDocument===v&&t(v,a)?-1:b===g||b.ownerDocument===v&&t(v,b)?1:k?J(k,a)-J(k,b):0:4&d?-1:1)}:function(a,b){if(a===b)return l=!0,0;var c,d=0,e=a.parentNode,f=b.parentNode,h=[a],i=[b];if(!e||!f)return a===g?-1:b===g?1:e?-1:f?1:k?J(k,a)-J(k,b):0;if(e===f)return la(a,b);c=a;while(c=c.parentNode)h.unshift(c);c=b;while(c=c.parentNode)i.unshift(c);while(h[d]===i[d])d++;return d?la(h[d],i[d]):h[d]===v?-1:i[d]===v?1:0},g):n},ga.matches=function(a,b){return ga(a,null,null,b)},ga.matchesSelector=function(a,b){if((a.ownerDocument||a)!==n&&m(a),b=b.replace(U,"='$1']"),!(!c.matchesSelector||!p||r&&r.test(b)||q&&q.test(b)))try{var d=s.call(a,b);if(d||c.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return ga(b,n,null,[a]).length>0},ga.contains=function(a,b){return(a.ownerDocument||a)!==n&&m(a),t(a,b)},ga.attr=function(a,b){(a.ownerDocument||a)!==n&&m(a);var e=d.attrHandle[b.toLowerCase()],f=e&&D.call(d.attrHandle,b.toLowerCase())?e(a,b,!p):void 0;return void 0!==f?f:c.attributes||!p?a.getAttribute(b):(f=a.getAttributeNode(b))&&f.specified?f.value:null},ga.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)},ga.uniqueSort=function(a){var b,d=[],e=0,f=0;if(l=!c.detectDuplicates,k=!c.sortStable&&a.slice(0),a.sort(B),l){while(b=a[f++])b===a[f]&&(e=d.push(f));while(e--)a.splice(d[e],1)}return k=null,a},e=ga.getText=function(a){var b,c="",d=0,f=a.nodeType;if(f){if(1===f||9===f||11===f){if("string"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===f||4===f)return a.nodeValue}else while(b=a[d++])c+=e(b);return c},d=ga.selectors={cacheLength:50,createPseudo:ia,match:X,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(ca,da),a[3]=(a[3]||a[4]||a[5]||"").replace(ca,da),"~="===a[2]&&(a[3]=" "+a[3]+" "),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),"nth"===a[1].slice(0,3)?(a[3]||ga.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*("even"===a[3]||"odd"===a[3])),a[5]=+(a[7]+a[8]||"odd"===a[3])):a[3]&&ga.error(a[0]),a},PSEUDO:function(a){var b,c=!a[6]&&a[2];return X.CHILD.test(a[0])?null:(a[3]?a[2]=a[4]||a[5]||"":c&&V.test(c)&&(b=g(c,!0))&&(b=c.indexOf(")",c.length-b)-c.length)&&(a[0]=a[0].slice(0,b),a[2]=c.slice(0,b)),a.slice(0,3))}},filter:{TAG:function(a){var b=a.replace(ca,da).toLowerCase();return"*"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=y[a+" "];return b||(b=new RegExp("(^|"+L+")"+a+"("+L+"|$)"))&&y(a,function(a){return b.test("string"==typeof a.className&&a.className||"undefined"!=typeof a.getAttribute&&a.getAttribute("class")||"")})},ATTR:function(a,b,c){return function(d){var e=ga.attr(d,a);return null==e?"!="===b:b?(e+="","="===b?e===c:"!="===b?e!==c:"^="===b?c&&0===e.indexOf(c):"*="===b?c&&e.indexOf(c)>-1:"$="===b?c&&e.slice(-c.length)===c:"~="===b?(" "+e.replace(Q," ")+" ").indexOf(c)>-1:"|="===b?e===c||e.slice(0,c.length+1)===c+"-":!1):!0}},CHILD:function(a,b,c,d,e){var f="nth"!==a.slice(0,3),g="last"!==a.slice(-4),h="of-type"===b;return 1===d&&0===e?function(a){return!!a.parentNode}:function(b,c,i){var j,k,l,m,n,o,p=f!==g?"nextSibling":"previousSibling",q=b.parentNode,r=h&&b.nodeName.toLowerCase(),s=!i&&!h;if(q){if(f){while(p){l=b;while(l=l[p])if(h?l.nodeName.toLowerCase()===r:1===l.nodeType)return!1;o=p="only"===a&&!o&&"nextSibling"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&s){k=q[u]||(q[u]={}),j=k[a]||[],n=j[0]===w&&j[1],m=j[0]===w&&j[2],l=n&&q.childNodes[n];while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if(1===l.nodeType&&++m&&l===b){k[a]=[w,n,m];break}}else if(s&&(j=(b[u]||(b[u]={}))[a])&&j[0]===w)m=j[1];else while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if((h?l.nodeName.toLowerCase()===r:1===l.nodeType)&&++m&&(s&&((l[u]||(l[u]={}))[a]=[w,m]),l===b))break;return m-=e,m===d||m%d===0&&m/d>=0}}},PSEUDO:function(a,b){var c,e=d.pseudos[a]||d.setFilters[a.toLowerCase()]||ga.error("unsupported pseudo: "+a);return e[u]?e(b):e.length>1?(c=[a,a,"",b],d.setFilters.hasOwnProperty(a.toLowerCase())?ia(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=J(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:ia(function(a){var b=[],c=[],d=h(a.replace(R,"$1"));return d[u]?ia(function(a,b,c,e){var f,g=d(a,null,e,[]),h=a.length;while(h--)(f=g[h])&&(a[h]=!(b[h]=f))}):function(a,e,f){return b[0]=a,d(b,null,f,c),b[0]=null,!c.pop()}}),has:ia(function(a){return function(b){return ga(a,b).length>0}}),contains:ia(function(a){return a=a.replace(ca,da),function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:ia(function(a){return W.test(a||"")||ga.error("unsupported lang: "+a),a=a.replace(ca,da).toLowerCase(),function(b){var c;do if(c=p?b.lang:b.getAttribute("xml:lang")||b.getAttribute("lang"))return c=c.toLowerCase(),c===a||0===c.indexOf(a+"-");while((b=b.parentNode)&&1===b.nodeType);return!1}}),target:function(b){var c=a.location&&a.location.hash;return c&&c.slice(1)===b.id},root:function(a){return a===o},focus:function(a){return a===n.activeElement&&(!n.hasFocus||n.hasFocus())&&!!(a.type||a.href||~a.tabIndex)},enabled:function(a){return a.disabled===!1},disabled:function(a){return a.disabled===!0},checked:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&!!a.checked||"option"===b&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},empty:function(a){for(a=a.firstChild;a;a=a.nextSibling)if(a.nodeType<6)return!1;return!0},parent:function(a){return!d.pseudos.empty(a)},header:function(a){return Z.test(a.nodeName)},input:function(a){return Y.test(a.nodeName)},button:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&"button"===a.type||"button"===b},text:function(a){var b;return"input"===a.nodeName.toLowerCase()&&"text"===a.type&&(null==(b=a.getAttribute("type"))||"text"===b.toLowerCase())},first:oa(function(){return[0]}),last:oa(function(a,b){return[b-1]}),eq:oa(function(a,b,c){return[0>c?c+b:c]}),even:oa(function(a,b){for(var c=0;b>c;c+=2)a.push(c);return a}),odd:oa(function(a,b){for(var c=1;b>c;c+=2)a.push(c);return a}),lt:oa(function(a,b,c){for(var d=0>c?c+b:c;--d>=0;)a.push(d);return a}),gt:oa(function(a,b,c){for(var d=0>c?c+b:c;++db;b++)d+=a[b].value;return d}function sa(a,b,c){var d=b.dir,e=c&&"parentNode"===d,f=x++;return b.first?function(b,c,f){while(b=b[d])if(1===b.nodeType||e)return a(b,c,f)}:function(b,c,g){var h,i,j=[w,f];if(g){while(b=b[d])if((1===b.nodeType||e)&&a(b,c,g))return!0}else while(b=b[d])if(1===b.nodeType||e){if(i=b[u]||(b[u]={}),(h=i[d])&&h[0]===w&&h[1]===f)return j[2]=h[2];if(i[d]=j,j[2]=a(b,c,g))return!0}}}function ta(a){return a.length>1?function(b,c,d){var e=a.length;while(e--)if(!a[e](b,c,d))return!1;return!0}:a[0]}function ua(a,b,c){for(var d=0,e=b.length;e>d;d++)ga(a,b[d],c);return c}function va(a,b,c,d,e){for(var f,g=[],h=0,i=a.length,j=null!=b;i>h;h++)(f=a[h])&&(!c||c(f,d,e))&&(g.push(f),j&&b.push(h));return g}function wa(a,b,c,d,e,f){return d&&!d[u]&&(d=wa(d)),e&&!e[u]&&(e=wa(e,f)),ia(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||ua(b||"*",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:va(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=va(r,n),d(j,[],h,i),k=j.length;while(k--)(l=j[k])&&(r[n[k]]=!(q[n[k]]=l))}if(f){if(e||a){if(e){j=[],k=r.length;while(k--)(l=r[k])&&j.push(q[k]=l);e(null,r=[],j,i)}k=r.length;while(k--)(l=r[k])&&(j=e?J(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=va(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):H.apply(g,r)})}function xa(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[" "],i=g?1:0,k=sa(function(a){return a===b},h,!0),l=sa(function(a){return J(b,a)>-1},h,!0),m=[function(a,c,d){var e=!g&&(d||c!==j)||((b=c).nodeType?k(a,c,d):l(a,c,d));return b=null,e}];f>i;i++)if(c=d.relative[a[i].type])m=[sa(ta(m),c)];else{if(c=d.filter[a[i].type].apply(null,a[i].matches),c[u]){for(e=++i;f>e;e++)if(d.relative[a[e].type])break;return wa(i>1&&ta(m),i>1&&ra(a.slice(0,i-1).concat({value:" "===a[i-2].type?"*":""})).replace(R,"$1"),c,e>i&&xa(a.slice(i,e)),f>e&&xa(a=a.slice(e)),f>e&&ra(a))}m.push(c)}return ta(m)}function ya(a,b){var c=b.length>0,e=a.length>0,f=function(f,g,h,i,k){var l,m,o,p=0,q="0",r=f&&[],s=[],t=j,u=f||e&&d.find.TAG("*",k),v=w+=null==t?1:Math.random()||.1,x=u.length;for(k&&(j=g!==n&&g);q!==x&&null!=(l=u[q]);q++){if(e&&l){m=0;while(o=a[m++])if(o(l,g,h)){i.push(l);break}k&&(w=v)}c&&((l=!o&&l)&&p--,f&&r.push(l))}if(p+=q,c&&q!==p){m=0;while(o=b[m++])o(r,s,g,h);if(f){if(p>0)while(q--)r[q]||s[q]||(s[q]=F.call(i));s=va(s)}H.apply(i,s),k&&!f&&s.length>0&&p+b.length>1&&ga.uniqueSort(i)}return k&&(w=v,j=t),r};return c?ia(f):f}return h=ga.compile=function(a,b){var c,d=[],e=[],f=A[a+" "];if(!f){b||(b=g(a)),c=b.length;while(c--)f=xa(b[c]),f[u]?d.push(f):e.push(f);f=A(a,ya(e,d)),f.selector=a}return f},i=ga.select=function(a,b,e,f){var i,j,k,l,m,n="function"==typeof a&&a,o=!f&&g(a=n.selector||a);if(e=e||[],1===o.length){if(j=o[0]=o[0].slice(0),j.length>2&&"ID"===(k=j[0]).type&&c.getById&&9===b.nodeType&&p&&d.relative[j[1].type]){if(b=(d.find.ID(k.matches[0].replace(ca,da),b)||[])[0],!b)return e;n&&(b=b.parentNode),a=a.slice(j.shift().value.length)}i=X.needsContext.test(a)?0:j.length;while(i--){if(k=j[i],d.relative[l=k.type])break;if((m=d.find[l])&&(f=m(k.matches[0].replace(ca,da),aa.test(j[0].type)&&pa(b.parentNode)||b))){if(j.splice(i,1),a=f.length&&ra(j),!a)return H.apply(e,f),e;break}}}return(n||h(a,o))(f,b,!p,e,aa.test(a)&&pa(b.parentNode)||b),e},c.sortStable=u.split("").sort(B).join("")===u,c.detectDuplicates=!!l,m(),c.sortDetached=ja(function(a){return 1&a.compareDocumentPosition(n.createElement("div"))}),ja(function(a){return a.innerHTML="","#"===a.firstChild.getAttribute("href")})||ka("type|href|height|width",function(a,b,c){return c?void 0:a.getAttribute(b,"type"===b.toLowerCase()?1:2)}),c.attributes&&ja(function(a){return a.innerHTML="",a.firstChild.setAttribute("value",""),""===a.firstChild.getAttribute("value")})||ka("value",function(a,b,c){return c||"input"!==a.nodeName.toLowerCase()?void 0:a.defaultValue}),ja(function(a){return null==a.getAttribute("disabled")})||ka(K,function(a,b,c){var d;return c?void 0:a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),ga}(a);m.find=s,m.expr=s.selectors,m.expr[":"]=m.expr.pseudos,m.unique=s.uniqueSort,m.text=s.getText,m.isXMLDoc=s.isXML,m.contains=s.contains;var t=m.expr.match.needsContext,u=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,v=/^.[^:#\[\.,]*$/;function w(a,b,c){if(m.isFunction(b))return m.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return m.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(v.test(b))return m.filter(b,a,c);b=m.filter(b,a)}return m.grep(a,function(a){return m.inArray(a,b)>=0!==c})}m.filter=function(a,b,c){var d=b[0];return c&&(a=":not("+a+")"),1===b.length&&1===d.nodeType?m.find.matchesSelector(d,a)?[d]:[]:m.find.matches(a,m.grep(b,function(a){return 1===a.nodeType}))},m.fn.extend({find:function(a){var b,c=[],d=this,e=d.length;if("string"!=typeof a)return this.pushStack(m(a).filter(function(){for(b=0;e>b;b++)if(m.contains(d[b],this))return!0}));for(b=0;e>b;b++)m.find(a,d[b],c);return c=this.pushStack(e>1?m.unique(c):c),c.selector=this.selector?this.selector+" "+a:a,c},filter:function(a){return this.pushStack(w(this,a||[],!1))},not:function(a){return this.pushStack(w(this,a||[],!0))},is:function(a){return!!w(this,"string"==typeof a&&t.test(a)?m(a):a||[],!1).length}});var x,y=a.document,z=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,A=m.fn.init=function(a,b){var c,d;if(!a)return this;if("string"==typeof a){if(c="<"===a.charAt(0)&&">"===a.charAt(a.length-1)&&a.length>=3?[null,a,null]:z.exec(a),!c||!c[1]&&b)return!b||b.jquery?(b||x).find(a):this.constructor(b).find(a);if(c[1]){if(b=b instanceof m?b[0]:b,m.merge(this,m.parseHTML(c[1],b&&b.nodeType?b.ownerDocument||b:y,!0)),u.test(c[1])&&m.isPlainObject(b))for(c in b)m.isFunction(this[c])?this[c](b[c]):this.attr(c,b[c]);return this}if(d=y.getElementById(c[2]),d&&d.parentNode){if(d.id!==c[2])return x.find(a);this.length=1,this[0]=d}return this.context=y,this.selector=a,this}return a.nodeType?(this.context=this[0]=a,this.length=1,this):m.isFunction(a)?"undefined"!=typeof x.ready?x.ready(a):a(m):(void 0!==a.selector&&(this.selector=a.selector,this.context=a.context),m.makeArray(a,this))};A.prototype=m.fn,x=m(y);var B=/^(?:parents|prev(?:Until|All))/,C={children:!0,contents:!0,next:!0,prev:!0};m.extend({dir:function(a,b,c){var d=[],e=a[b];while(e&&9!==e.nodeType&&(void 0===c||1!==e.nodeType||!m(e).is(c)))1===e.nodeType&&d.push(e),e=e[b];return d},sibling:function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c}}),m.fn.extend({has:function(a){var b,c=m(a,this),d=c.length;return this.filter(function(){for(b=0;d>b;b++)if(m.contains(this,c[b]))return!0})},closest:function(a,b){for(var c,d=0,e=this.length,f=[],g=t.test(a)||"string"!=typeof a?m(a,b||this.context):0;e>d;d++)for(c=this[d];c&&c!==b;c=c.parentNode)if(c.nodeType<11&&(g?g.index(c)>-1:1===c.nodeType&&m.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?m.unique(f):f)},index:function(a){return a?"string"==typeof a?m.inArray(this[0],m(a)):m.inArray(a.jquery?a[0]:a,this):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(m.unique(m.merge(this.get(),m(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function D(a,b){do a=a[b];while(a&&1!==a.nodeType);return a}m.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return m.dir(a,"parentNode")},parentsUntil:function(a,b,c){return m.dir(a,"parentNode",c)},next:function(a){return D(a,"nextSibling")},prev:function(a){return D(a,"previousSibling")},nextAll:function(a){return m.dir(a,"nextSibling")},prevAll:function(a){return m.dir(a,"previousSibling")},nextUntil:function(a,b,c){return m.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return m.dir(a,"previousSibling",c)},siblings:function(a){return m.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return m.sibling(a.firstChild)},contents:function(a){return m.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:m.merge([],a.childNodes)}},function(a,b){m.fn[a]=function(c,d){var e=m.map(this,b,c);return"Until"!==a.slice(-5)&&(d=c),d&&"string"==typeof d&&(e=m.filter(d,e)),this.length>1&&(C[a]||(e=m.unique(e)),B.test(a)&&(e=e.reverse())),this.pushStack(e)}});var E=/\S+/g,F={};function G(a){var b=F[a]={};return m.each(a.match(E)||[],function(a,c){b[c]=!0}),b}m.Callbacks=function(a){a="string"==typeof a?F[a]||G(a):m.extend({},a);var b,c,d,e,f,g,h=[],i=!a.once&&[],j=function(l){for(c=a.memory&&l,d=!0,f=g||0,g=0,e=h.length,b=!0;h&&e>f;f++)if(h[f].apply(l[0],l[1])===!1&&a.stopOnFalse){c=!1;break}b=!1,h&&(i?i.length&&j(i.shift()):c?h=[]:k.disable())},k={add:function(){if(h){var d=h.length;!function f(b){m.each(b,function(b,c){var d=m.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&f(c)})}(arguments),b?e=h.length:c&&(g=d,j(c))}return this},remove:function(){return h&&m.each(arguments,function(a,c){var d;while((d=m.inArray(c,h,d))>-1)h.splice(d,1),b&&(e>=d&&e--,f>=d&&f--)}),this},has:function(a){return a?m.inArray(a,h)>-1:!(!h||!h.length)},empty:function(){return h=[],e=0,this},disable:function(){return h=i=c=void 0,this},disabled:function(){return!h},lock:function(){return i=void 0,c||k.disable(),this},locked:function(){return!i},fireWith:function(a,c){return!h||d&&!i||(c=c||[],c=[a,c.slice?c.slice():c],b?i.push(c):j(c)),this},fire:function(){return k.fireWith(this,arguments),this},fired:function(){return!!d}};return k},m.extend({Deferred:function(a){var b=[["resolve","done",m.Callbacks("once memory"),"resolved"],["reject","fail",m.Callbacks("once memory"),"rejected"],["notify","progress",m.Callbacks("memory")]],c="pending",d={state:function(){return c},always:function(){return e.done(arguments).fail(arguments),this},then:function(){var a=arguments;return m.Deferred(function(c){m.each(b,function(b,f){var g=m.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&m.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f[0]+"With"](this===d?c.promise():this,g?[a]:arguments)})}),a=null}).promise()},promise:function(a){return null!=a?m.extend(a,d):d}},e={};return d.pipe=d.then,m.each(b,function(a,f){var g=f[2],h=f[3];d[f[1]]=g.add,h&&g.add(function(){c=h},b[1^a][2].disable,b[2][2].lock),e[f[0]]=function(){return e[f[0]+"With"](this===e?d:this,arguments),this},e[f[0]+"With"]=g.fireWith}),d.promise(e),a&&a.call(e,e),e},when:function(a){var b=0,c=d.call(arguments),e=c.length,f=1!==e||a&&m.isFunction(a.promise)?e:0,g=1===f?a:m.Deferred(),h=function(a,b,c){return function(e){b[a]=this,c[a]=arguments.length>1?d.call(arguments):e,c===i?g.notifyWith(b,c):--f||g.resolveWith(b,c)}},i,j,k;if(e>1)for(i=new Array(e),j=new Array(e),k=new Array(e);e>b;b++)c[b]&&m.isFunction(c[b].promise)?c[b].promise().done(h(b,k,c)).fail(g.reject).progress(h(b,j,i)):--f;return f||g.resolveWith(k,c),g.promise()}});var H;m.fn.ready=function(a){return m.ready.promise().done(a),this},m.extend({isReady:!1,readyWait:1,holdReady:function(a){a?m.readyWait++:m.ready(!0)},ready:function(a){if(a===!0?!--m.readyWait:!m.isReady){if(!y.body)return setTimeout(m.ready);m.isReady=!0,a!==!0&&--m.readyWait>0||(H.resolveWith(y,[m]),m.fn.triggerHandler&&(m(y).triggerHandler("ready"),m(y).off("ready")))}}});function I(){y.addEventListener?(y.removeEventListener("DOMContentLoaded",J,!1),a.removeEventListener("load",J,!1)):(y.detachEvent("onreadystatechange",J),a.detachEvent("onload",J))}function J(){(y.addEventListener||"load"===event.type||"complete"===y.readyState)&&(I(),m.ready())}m.ready.promise=function(b){if(!H)if(H=m.Deferred(),"complete"===y.readyState)setTimeout(m.ready);else if(y.addEventListener)y.addEventListener("DOMContentLoaded",J,!1),a.addEventListener("load",J,!1);else{y.attachEvent("onreadystatechange",J),a.attachEvent("onload",J);var c=!1;try{c=null==a.frameElement&&y.documentElement}catch(d){}c&&c.doScroll&&!function e(){if(!m.isReady){try{c.doScroll("left")}catch(a){return setTimeout(e,50)}I(),m.ready()}}()}return H.promise(b)};var K="undefined",L;for(L in m(k))break;k.ownLast="0"!==L,k.inlineBlockNeedsLayout=!1,m(function(){var a,b,c,d;c=y.getElementsByTagName("body")[0],c&&c.style&&(b=y.createElement("div"),d=y.createElement("div"),d.style.cssText="position:absolute;border:0;width:0;height:0;top:0;left:-9999px",c.appendChild(d).appendChild(b),typeof b.style.zoom!==K&&(b.style.cssText="display:inline;margin:0;border:0;padding:1px;width:1px;zoom:1",k.inlineBlockNeedsLayout=a=3===b.offsetWidth,a&&(c.style.zoom=1)),c.removeChild(d))}),function(){var a=y.createElement("div");if(null==k.deleteExpando){k.deleteExpando=!0;try{delete a.test}catch(b){k.deleteExpando=!1}}a=null}(),m.acceptData=function(a){var b=m.noData[(a.nodeName+" ").toLowerCase()],c=+a.nodeType||1;return 1!==c&&9!==c?!1:!b||b!==!0&&a.getAttribute("classid")===b};var M=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,N=/([A-Z])/g;function O(a,b,c){if(void 0===c&&1===a.nodeType){var d="data-"+b.replace(N,"-$1").toLowerCase();if(c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:M.test(c)?m.parseJSON(c):c}catch(e){}m.data(a,b,c)}else c=void 0}return c}function P(a){var b;for(b in a)if(("data"!==b||!m.isEmptyObject(a[b]))&&"toJSON"!==b)return!1; - -return!0}function Q(a,b,d,e){if(m.acceptData(a)){var f,g,h=m.expando,i=a.nodeType,j=i?m.cache:a,k=i?a[h]:a[h]&&h;if(k&&j[k]&&(e||j[k].data)||void 0!==d||"string"!=typeof b)return k||(k=i?a[h]=c.pop()||m.guid++:h),j[k]||(j[k]=i?{}:{toJSON:m.noop}),("object"==typeof b||"function"==typeof b)&&(e?j[k]=m.extend(j[k],b):j[k].data=m.extend(j[k].data,b)),g=j[k],e||(g.data||(g.data={}),g=g.data),void 0!==d&&(g[m.camelCase(b)]=d),"string"==typeof b?(f=g[b],null==f&&(f=g[m.camelCase(b)])):f=g,f}}function R(a,b,c){if(m.acceptData(a)){var d,e,f=a.nodeType,g=f?m.cache:a,h=f?a[m.expando]:m.expando;if(g[h]){if(b&&(d=c?g[h]:g[h].data)){m.isArray(b)?b=b.concat(m.map(b,m.camelCase)):b in d?b=[b]:(b=m.camelCase(b),b=b in d?[b]:b.split(" ")),e=b.length;while(e--)delete d[b[e]];if(c?!P(d):!m.isEmptyObject(d))return}(c||(delete g[h].data,P(g[h])))&&(f?m.cleanData([a],!0):k.deleteExpando||g!=g.window?delete g[h]:g[h]=null)}}}m.extend({cache:{},noData:{"applet ":!0,"embed ":!0,"object ":"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"},hasData:function(a){return a=a.nodeType?m.cache[a[m.expando]]:a[m.expando],!!a&&!P(a)},data:function(a,b,c){return Q(a,b,c)},removeData:function(a,b){return R(a,b)},_data:function(a,b,c){return Q(a,b,c,!0)},_removeData:function(a,b){return R(a,b,!0)}}),m.fn.extend({data:function(a,b){var c,d,e,f=this[0],g=f&&f.attributes;if(void 0===a){if(this.length&&(e=m.data(f),1===f.nodeType&&!m._data(f,"parsedAttrs"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf("data-")&&(d=m.camelCase(d.slice(5)),O(f,d,e[d])));m._data(f,"parsedAttrs",!0)}return e}return"object"==typeof a?this.each(function(){m.data(this,a)}):arguments.length>1?this.each(function(){m.data(this,a,b)}):f?O(f,a,m.data(f,a)):void 0},removeData:function(a){return this.each(function(){m.removeData(this,a)})}}),m.extend({queue:function(a,b,c){var d;return a?(b=(b||"fx")+"queue",d=m._data(a,b),c&&(!d||m.isArray(c)?d=m._data(a,b,m.makeArray(c)):d.push(c)),d||[]):void 0},dequeue:function(a,b){b=b||"fx";var c=m.queue(a,b),d=c.length,e=c.shift(),f=m._queueHooks(a,b),g=function(){m.dequeue(a,b)};"inprogress"===e&&(e=c.shift(),d--),e&&("fx"===b&&c.unshift("inprogress"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+"queueHooks";return m._data(a,c)||m._data(a,c,{empty:m.Callbacks("once memory").add(function(){m._removeData(a,b+"queue"),m._removeData(a,c)})})}}),m.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.lengthh;h++)b(a[h],c,g?d:d.call(a[h],h,b(a[h],c)));return e?a:j?b.call(a):i?b(a[0],c):f},W=/^(?:checkbox|radio)$/i;!function(){var a=y.createElement("input"),b=y.createElement("div"),c=y.createDocumentFragment();if(b.innerHTML="
a",k.leadingWhitespace=3===b.firstChild.nodeType,k.tbody=!b.getElementsByTagName("tbody").length,k.htmlSerialize=!!b.getElementsByTagName("link").length,k.html5Clone="<:nav>"!==y.createElement("nav").cloneNode(!0).outerHTML,a.type="checkbox",a.checked=!0,c.appendChild(a),k.appendChecked=a.checked,b.innerHTML="",k.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue,c.appendChild(b),b.innerHTML="",k.checkClone=b.cloneNode(!0).cloneNode(!0).lastChild.checked,k.noCloneEvent=!0,b.attachEvent&&(b.attachEvent("onclick",function(){k.noCloneEvent=!1}),b.cloneNode(!0).click()),null==k.deleteExpando){k.deleteExpando=!0;try{delete b.test}catch(d){k.deleteExpando=!1}}}(),function(){var b,c,d=y.createElement("div");for(b in{submit:!0,change:!0,focusin:!0})c="on"+b,(k[b+"Bubbles"]=c in a)||(d.setAttribute(c,"t"),k[b+"Bubbles"]=d.attributes[c].expando===!1);d=null}();var X=/^(?:input|select|textarea)$/i,Y=/^key/,Z=/^(?:mouse|pointer|contextmenu)|click/,$=/^(?:focusinfocus|focusoutblur)$/,_=/^([^.]*)(?:\.(.+)|)$/;function aa(){return!0}function ba(){return!1}function ca(){try{return y.activeElement}catch(a){}}m.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,n,o,p,q,r=m._data(a);if(r){c.handler&&(i=c,c=i.handler,e=i.selector),c.guid||(c.guid=m.guid++),(g=r.events)||(g=r.events={}),(k=r.handle)||(k=r.handle=function(a){return typeof m===K||a&&m.event.triggered===a.type?void 0:m.event.dispatch.apply(k.elem,arguments)},k.elem=a),b=(b||"").match(E)||[""],h=b.length;while(h--)f=_.exec(b[h])||[],o=q=f[1],p=(f[2]||"").split(".").sort(),o&&(j=m.event.special[o]||{},o=(e?j.delegateType:j.bindType)||o,j=m.event.special[o]||{},l=m.extend({type:o,origType:q,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&m.expr.match.needsContext.test(e),namespace:p.join(".")},i),(n=g[o])||(n=g[o]=[],n.delegateCount=0,j.setup&&j.setup.call(a,d,p,k)!==!1||(a.addEventListener?a.addEventListener(o,k,!1):a.attachEvent&&a.attachEvent("on"+o,k))),j.add&&(j.add.call(a,l),l.handler.guid||(l.handler.guid=c.guid)),e?n.splice(n.delegateCount++,0,l):n.push(l),m.event.global[o]=!0);a=null}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,n,o,p,q,r=m.hasData(a)&&m._data(a);if(r&&(k=r.events)){b=(b||"").match(E)||[""],j=b.length;while(j--)if(h=_.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o){l=m.event.special[o]||{},o=(d?l.delegateType:l.bindType)||o,n=k[o]||[],h=h[2]&&new RegExp("(^|\\.)"+p.join("\\.(?:.*\\.|)")+"(\\.|$)"),i=f=n.length;while(f--)g=n[f],!e&&q!==g.origType||c&&c.guid!==g.guid||h&&!h.test(g.namespace)||d&&d!==g.selector&&("**"!==d||!g.selector)||(n.splice(f,1),g.selector&&n.delegateCount--,l.remove&&l.remove.call(a,g));i&&!n.length&&(l.teardown&&l.teardown.call(a,p,r.handle)!==!1||m.removeEvent(a,o,r.handle),delete k[o])}else for(o in k)m.event.remove(a,o+b[j],c,d,!0);m.isEmptyObject(k)&&(delete r.handle,m._removeData(a,"events"))}},trigger:function(b,c,d,e){var f,g,h,i,k,l,n,o=[d||y],p=j.call(b,"type")?b.type:b,q=j.call(b,"namespace")?b.namespace.split("."):[];if(h=l=d=d||y,3!==d.nodeType&&8!==d.nodeType&&!$.test(p+m.event.triggered)&&(p.indexOf(".")>=0&&(q=p.split("."),p=q.shift(),q.sort()),g=p.indexOf(":")<0&&"on"+p,b=b[m.expando]?b:new m.Event(p,"object"==typeof b&&b),b.isTrigger=e?2:3,b.namespace=q.join("."),b.namespace_re=b.namespace?new RegExp("(^|\\.)"+q.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=d),c=null==c?[b]:m.makeArray(c,[b]),k=m.event.special[p]||{},e||!k.trigger||k.trigger.apply(d,c)!==!1)){if(!e&&!k.noBubble&&!m.isWindow(d)){for(i=k.delegateType||p,$.test(i+p)||(h=h.parentNode);h;h=h.parentNode)o.push(h),l=h;l===(d.ownerDocument||y)&&o.push(l.defaultView||l.parentWindow||a)}n=0;while((h=o[n++])&&!b.isPropagationStopped())b.type=n>1?i:k.bindType||p,f=(m._data(h,"events")||{})[b.type]&&m._data(h,"handle"),f&&f.apply(h,c),f=g&&h[g],f&&f.apply&&m.acceptData(h)&&(b.result=f.apply(h,c),b.result===!1&&b.preventDefault());if(b.type=p,!e&&!b.isDefaultPrevented()&&(!k._default||k._default.apply(o.pop(),c)===!1)&&m.acceptData(d)&&g&&d[p]&&!m.isWindow(d)){l=d[g],l&&(d[g]=null),m.event.triggered=p;try{d[p]()}catch(r){}m.event.triggered=void 0,l&&(d[g]=l)}return b.result}},dispatch:function(a){a=m.event.fix(a);var b,c,e,f,g,h=[],i=d.call(arguments),j=(m._data(this,"events")||{})[a.type]||[],k=m.event.special[a.type]||{};if(i[0]=a,a.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,a)!==!1){h=m.event.handlers.call(this,a,j),b=0;while((f=h[b++])&&!a.isPropagationStopped()){a.currentTarget=f.elem,g=0;while((e=f.handlers[g++])&&!a.isImmediatePropagationStopped())(!a.namespace_re||a.namespace_re.test(e.namespace))&&(a.handleObj=e,a.data=e.data,c=((m.event.special[e.origType]||{}).handle||e.handler).apply(f.elem,i),void 0!==c&&(a.result=c)===!1&&(a.preventDefault(),a.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,a),a.result}},handlers:function(a,b){var c,d,e,f,g=[],h=b.delegateCount,i=a.target;if(h&&i.nodeType&&(!a.button||"click"!==a.type))for(;i!=this;i=i.parentNode||this)if(1===i.nodeType&&(i.disabled!==!0||"click"!==a.type)){for(e=[],f=0;h>f;f++)d=b[f],c=d.selector+" ",void 0===e[c]&&(e[c]=d.needsContext?m(c,this).index(i)>=0:m.find(c,this,null,[i]).length),e[c]&&e.push(d);e.length&&g.push({elem:i,handlers:e})}return h]","i"),ha=/^\s+/,ia=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,ja=/<([\w:]+)/,ka=/\s*$/g,ra={option:[1,""],legend:[1,"
","
"],area:[1,"",""],param:[1,"",""],thead:[1,"","
"],tr:[2,"","
"],col:[2,"","
"],td:[3,"","
"],_default:k.htmlSerialize?[0,"",""]:[1,"X
","
"]},sa=da(y),ta=sa.appendChild(y.createElement("div"));ra.optgroup=ra.option,ra.tbody=ra.tfoot=ra.colgroup=ra.caption=ra.thead,ra.th=ra.td;function ua(a,b){var c,d,e=0,f=typeof a.getElementsByTagName!==K?a.getElementsByTagName(b||"*"):typeof a.querySelectorAll!==K?a.querySelectorAll(b||"*"):void 0;if(!f)for(f=[],c=a.childNodes||a;null!=(d=c[e]);e++)!b||m.nodeName(d,b)?f.push(d):m.merge(f,ua(d,b));return void 0===b||b&&m.nodeName(a,b)?m.merge([a],f):f}function va(a){W.test(a.type)&&(a.defaultChecked=a.checked)}function wa(a,b){return m.nodeName(a,"table")&&m.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function xa(a){return a.type=(null!==m.find.attr(a,"type"))+"/"+a.type,a}function ya(a){var b=pa.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function za(a,b){for(var c,d=0;null!=(c=a[d]);d++)m._data(c,"globalEval",!b||m._data(b[d],"globalEval"))}function Aa(a,b){if(1===b.nodeType&&m.hasData(a)){var c,d,e,f=m._data(a),g=m._data(b,f),h=f.events;if(h){delete g.handle,g.events={};for(c in h)for(d=0,e=h[c].length;e>d;d++)m.event.add(b,c,h[c][d])}g.data&&(g.data=m.extend({},g.data))}}function Ba(a,b){var c,d,e;if(1===b.nodeType){if(c=b.nodeName.toLowerCase(),!k.noCloneEvent&&b[m.expando]){e=m._data(b);for(d in e.events)m.removeEvent(b,d,e.handle);b.removeAttribute(m.expando)}"script"===c&&b.text!==a.text?(xa(b).text=a.text,ya(b)):"object"===c?(b.parentNode&&(b.outerHTML=a.outerHTML),k.html5Clone&&a.innerHTML&&!m.trim(b.innerHTML)&&(b.innerHTML=a.innerHTML)):"input"===c&&W.test(a.type)?(b.defaultChecked=b.checked=a.checked,b.value!==a.value&&(b.value=a.value)):"option"===c?b.defaultSelected=b.selected=a.defaultSelected:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}}m.extend({clone:function(a,b,c){var d,e,f,g,h,i=m.contains(a.ownerDocument,a);if(k.html5Clone||m.isXMLDoc(a)||!ga.test("<"+a.nodeName+">")?f=a.cloneNode(!0):(ta.innerHTML=a.outerHTML,ta.removeChild(f=ta.firstChild)),!(k.noCloneEvent&&k.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||m.isXMLDoc(a)))for(d=ua(f),h=ua(a),g=0;null!=(e=h[g]);++g)d[g]&&Ba(e,d[g]);if(b)if(c)for(h=h||ua(a),d=d||ua(f),g=0;null!=(e=h[g]);g++)Aa(e,d[g]);else Aa(a,f);return d=ua(f,"script"),d.length>0&&za(d,!i&&ua(a,"script")),d=h=e=null,f},buildFragment:function(a,b,c,d){for(var e,f,g,h,i,j,l,n=a.length,o=da(b),p=[],q=0;n>q;q++)if(f=a[q],f||0===f)if("object"===m.type(f))m.merge(p,f.nodeType?[f]:f);else if(la.test(f)){h=h||o.appendChild(b.createElement("div")),i=(ja.exec(f)||["",""])[1].toLowerCase(),l=ra[i]||ra._default,h.innerHTML=l[1]+f.replace(ia,"<$1>")+l[2],e=l[0];while(e--)h=h.lastChild;if(!k.leadingWhitespace&&ha.test(f)&&p.push(b.createTextNode(ha.exec(f)[0])),!k.tbody){f="table"!==i||ka.test(f)?""!==l[1]||ka.test(f)?0:h:h.firstChild,e=f&&f.childNodes.length;while(e--)m.nodeName(j=f.childNodes[e],"tbody")&&!j.childNodes.length&&f.removeChild(j)}m.merge(p,h.childNodes),h.textContent="";while(h.firstChild)h.removeChild(h.firstChild);h=o.lastChild}else p.push(b.createTextNode(f));h&&o.removeChild(h),k.appendChecked||m.grep(ua(p,"input"),va),q=0;while(f=p[q++])if((!d||-1===m.inArray(f,d))&&(g=m.contains(f.ownerDocument,f),h=ua(o.appendChild(f),"script"),g&&za(h),c)){e=0;while(f=h[e++])oa.test(f.type||"")&&c.push(f)}return h=null,o},cleanData:function(a,b){for(var d,e,f,g,h=0,i=m.expando,j=m.cache,l=k.deleteExpando,n=m.event.special;null!=(d=a[h]);h++)if((b||m.acceptData(d))&&(f=d[i],g=f&&j[f])){if(g.events)for(e in g.events)n[e]?m.event.remove(d,e):m.removeEvent(d,e,g.handle);j[f]&&(delete j[f],l?delete d[i]:typeof d.removeAttribute!==K?d.removeAttribute(i):d[i]=null,c.push(f))}}}),m.fn.extend({text:function(a){return V(this,function(a){return void 0===a?m.text(this):this.empty().append((this[0]&&this[0].ownerDocument||y).createTextNode(a))},null,a,arguments.length)},append:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=wa(this,a);b.appendChild(a)}})},prepend:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=wa(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},remove:function(a,b){for(var c,d=a?m.filter(a,this):this,e=0;null!=(c=d[e]);e++)b||1!==c.nodeType||m.cleanData(ua(c)),c.parentNode&&(b&&m.contains(c.ownerDocument,c)&&za(ua(c,"script")),c.parentNode.removeChild(c));return this},empty:function(){for(var a,b=0;null!=(a=this[b]);b++){1===a.nodeType&&m.cleanData(ua(a,!1));while(a.firstChild)a.removeChild(a.firstChild);a.options&&m.nodeName(a,"select")&&(a.options.length=0)}return this},clone:function(a,b){return a=null==a?!1:a,b=null==b?a:b,this.map(function(){return m.clone(this,a,b)})},html:function(a){return V(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a)return 1===b.nodeType?b.innerHTML.replace(fa,""):void 0;if(!("string"!=typeof a||ma.test(a)||!k.htmlSerialize&&ga.test(a)||!k.leadingWhitespace&&ha.test(a)||ra[(ja.exec(a)||["",""])[1].toLowerCase()])){a=a.replace(ia,"<$1>");try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(m.cleanData(ua(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=arguments[0];return this.domManip(arguments,function(b){a=this.parentNode,m.cleanData(ua(this)),a&&a.replaceChild(b,this)}),a&&(a.length||a.nodeType)?this:this.remove()},detach:function(a){return this.remove(a,!0)},domManip:function(a,b){a=e.apply([],a);var c,d,f,g,h,i,j=0,l=this.length,n=this,o=l-1,p=a[0],q=m.isFunction(p);if(q||l>1&&"string"==typeof p&&!k.checkClone&&na.test(p))return this.each(function(c){var d=n.eq(c);q&&(a[0]=p.call(this,c,d.html())),d.domManip(a,b)});if(l&&(i=m.buildFragment(a,this[0].ownerDocument,!1,this),c=i.firstChild,1===i.childNodes.length&&(i=c),c)){for(g=m.map(ua(i,"script"),xa),f=g.length;l>j;j++)d=i,j!==o&&(d=m.clone(d,!0,!0),f&&m.merge(g,ua(d,"script"))),b.call(this[j],d,j);if(f)for(h=g[g.length-1].ownerDocument,m.map(g,ya),j=0;f>j;j++)d=g[j],oa.test(d.type||"")&&!m._data(d,"globalEval")&&m.contains(h,d)&&(d.src?m._evalUrl&&m._evalUrl(d.src):m.globalEval((d.text||d.textContent||d.innerHTML||"").replace(qa,"")));i=c=null}return this}}),m.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){m.fn[a]=function(a){for(var c,d=0,e=[],g=m(a),h=g.length-1;h>=d;d++)c=d===h?this:this.clone(!0),m(g[d])[b](c),f.apply(e,c.get());return this.pushStack(e)}});var Ca,Da={};function Ea(b,c){var d,e=m(c.createElement(b)).appendTo(c.body),f=a.getDefaultComputedStyle&&(d=a.getDefaultComputedStyle(e[0]))?d.display:m.css(e[0],"display");return e.detach(),f}function Fa(a){var b=y,c=Da[a];return c||(c=Ea(a,b),"none"!==c&&c||(Ca=(Ca||m("