aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-12-19 23:38:18 +0000
committerChristian Grothoff <christian@grothoff.org>2014-12-19 23:38:18 +0000
commitb2a041e934bd33a033668d2d94053a4e6085c570 (patch)
tree82f8fcf86f6b16454c7075cc678712c12f48cffc
parent00a5e292872468b37bbfe3be2fefdad680f82cfd (diff)
downloadlibmicrohttpd-b2a041e934bd33a033668d2d94053a4e6085c570.tar.gz
libmicrohttpd-b2a041e934bd33a033668d2d94053a4e6085c570.zip
make MHD_http_unescape() part of API (#3585)
-rw-r--r--ChangeLog5
-rw-r--r--doc/libmicrohttpd.texi133
-rw-r--r--src/include/microhttpd.h29
-rw-r--r--src/microhttpd/daemon.c22
-rw-r--r--src/microhttpd/internal.c6
-rw-r--r--src/microhttpd/internal.h16
-rw-r--r--src/microhttpd/postprocessor.c4
7 files changed, 183 insertions, 32 deletions
diff --git a/ChangeLog b/ChangeLog
index 2b235663..10e10053 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
1Sat Dec 20 00:35:40 CET 2014
2 Adding MHD_http_unescape() to public API (#3585). -CG
3 Updating documentation to document
4 MHD_is_feature_supported(). -CG
5
1Thu Dec 4 00:43:10 CET 2014 6Thu Dec 4 00:43:10 CET 2014
2 If "Connection: upgrade" is requested, do not add 7 If "Connection: upgrade" is requested, do not add
3 "Connection: Keep-Alive" in the response. -GJ 8 "Connection: Keep-Alive" in the response. -GJ
diff --git a/doc/libmicrohttpd.texi b/doc/libmicrohttpd.texi
index 91579c62..b0a1000b 100644
--- a/doc/libmicrohttpd.texi
+++ b/doc/libmicrohttpd.texi
@@ -65,6 +65,7 @@ Free Documentation License".
65* microhttpd-dauth:: Utilizing Authentication. 65* microhttpd-dauth:: Utilizing Authentication.
66* microhttpd-post:: Adding a @code{POST} processor. 66* microhttpd-post:: Adding a @code{POST} processor.
67* microhttpd-info:: Obtaining and modifying status information. 67* microhttpd-info:: Obtaining and modifying status information.
68* microhttpd-util:: Utilities.
68 69
69Appendices 70Appendices
70 71
@@ -2575,6 +2576,138 @@ zero for no timeout.
2575@end deftp 2576@end deftp
2576 2577
2577 2578
2579
2580@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2581
2582@c ------------------------------------------------------------
2583@node microhttpd-util
2584@chapter Utility functions.
2585
2586
2587@menu
2588* microhttpd-util feature:: Test supported MHD features
2589* microhttpd-util unescape:: Unescape strings
2590@end menu
2591
2592
2593@c ------------------------------------------------------------
2594@node microhttpd-util feature
2595@section Testing for supported MHD features
2596
2597
2598@deftp {Enumeration} MHD_FEATURE
2599Values of this enum are used to specify what
2600information about a daemon is desired.
2601@table @code
2602@item MHD_FEATURE_MESSAGES
2603Get whether messages are supported. If supported then in debug
2604mode messages can be printed to stderr or to external logger.
2605
2606@item MHD_FEATURE_SSL
2607Get whether HTTPS is supported. If supported then flag
2608MHD_USE_SSL and options MHD_OPTION_HTTPS_MEM_KEY,
2609MHD_OPTION_HTTPS_MEM_CERT, MHD_OPTION_HTTPS_MEM_TRUST,
2610MHD_OPTION_HTTPS_MEM_DHPARAMS, MHD_OPTION_HTTPS_CRED_TYPE,
2611MHD_OPTION_HTTPS_PRIORITIES can be used.
2612
2613@item MHD_FEATURE_HTTPS_CERT_CALLBACK
2614Get whether option #MHD_OPTION_HTTPS_CERT_CALLBACK is
2615supported.
2616
2617@item MHD_FEATURE_IPv6
2618Get whether IPv6 is supported. If supported then flag
2619MHD_USE_IPv6 can be used.
2620
2621@item MHD_FEATURE_IPv6_ONLY
2622Get whether IPv6 without IPv4 is supported. If not supported
2623then IPv4 is always enabled in IPv6 sockets and
2624flag MHD_USE_DUAL_STACK if always used when MHD_USE_IPv6 is
2625specified.
2626
2627@item MHD_FEATURE_POLL
2628Get whether @code{poll()} is supported. If supported then flag
2629MHD_USE_POLL can be used.
2630
2631@item MHD_FEATURE_EPOLL
2632Get whether @code{epoll()} is supported. If supported then Flags
2633MHD_USE_EPOLL_LINUX_ONLY and
2634MHD_USE_EPOLL_INTERNALLY_LINUX_ONLY can be used.
2635
2636@item MHD_FEATURE_SHUTDOWN_LISTEN_SOCKET
2637Get whether shutdown on listen socket to signal other
2638threads is supported. If not supported flag
2639MHD_USE_PIPE_FOR_SHUTDOWN is automatically forced.
2640
2641@item MHD_FEATURE_SOCKETPAIR
2642Get whether a @code{socketpair()} is used internally instead of
2643a @code{pipe()} to signal other threads.
2644
2645@item MHD_FEATURE_TCP_FASTOPEN
2646Get whether TCP Fast Open is supported. If supported then
2647flag MHD_USE_TCP_FASTOPEN and option
2648MHD_OPTION_TCP_FASTOPEN_QUEUE_SIZE can be used.
2649
2650@item MHD_FEATURE_BASIC_AUTH
2651Get whether HTTP Basic authorization is supported. If supported
2652then functions @code{MHD_basic_auth_get_username_password()} and
2653@code{MHD_queue_basic_auth_fail_response()} can be used.
2654
2655@item MHD_FEATURE_DIGEST_AUTH
2656Get whether HTTP Digest authorization is supported. If
2657supported then options MHD_OPTION_DIGEST_AUTH_RANDOM,
2658MHD_OPTION_NONCE_NC_SIZE and functions @code{MHD_digest_auth_check()},
2659can be used.
2660
2661@item MHD_FEATURE_POSTPROCESSOR
2662Get whether postprocessor is supported. If supported then
2663functions @code{MHD_create_post_processor()},
2664@code{MHD_post_process()}, @code{MHD_destroy_post_processor()}
2665can be used.
2666
2667@end table
2668@end deftp
2669
2670
2671
2672@deftypefun {int} MHD_is_feature_supported (enum MHD_FEATURE feature)
2673Get information about supported MHD features. Indicate that MHD was
2674compiled with or without support for particular feature. Some features
2675require additional support by the kernel. However, kernel support is not
2676checked by this function.
2677
2678@table @var
2679@item feature
2680type of requested information
2681@end table
2682
2683Returns @code{MHD_YES} if the feature is supported,
2684and @code{MHD_NO} if not.
2685@end deftypefun
2686
2687
2688@c ------------------------------------------------------------
2689@node microhttpd-util unescape
2690@section Unescape strings
2691
2692@deftypefun {size_t} MHD_http_unescape (char *val)
2693Process escape sequences ('%HH') Updates val in place; the result
2694should be UTF-8 encoded and cannot be larger than the input. The
2695result must also still be 0-terminated.
2696
2697@table @var
2698@item val
2699value to unescape (modified in the process), must be
2700a 0-terminated UTF-8 string.
2701@end table
2702
2703Returns length of the resulting val (@code{strlen(val)} may be
2704shorter afterwards due to elimination of escape sequences).
2705
2706@end deftypefun
2707
2708
2709
2710
2578@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2711@c ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2579 2712
2580 2713
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index 2bf556e1..c93fed2b 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -1686,6 +1686,19 @@ MHD_set_panic_func (MHD_PanicCallback cb, void *cls);
1686 1686
1687 1687
1688/** 1688/**
1689 * Process escape sequences ('%HH') Updates val in place; the
1690 * result should be UTF-8 encoded and cannot be larger than the input.
1691 * The result must also still be 0-terminated.
1692 *
1693 * @param val value to unescape (modified in the process)
1694 * @return length of the resulting val (`strlen(val)` may be
1695 * shorter afterwards due to elimination of escape sequences)
1696 */
1697_MHD_EXTERN size_t
1698MHD_http_unescape (char *val);
1699
1700
1701/**
1689 * Get a particular header value. If multiple 1702 * Get a particular header value. If multiple
1690 * values match the kind, return any one of them. 1703 * values match the kind, return any one of them.
1691 * 1704 *
@@ -2439,9 +2452,9 @@ MHD_get_version (void);
2439 2452
2440 2453
2441/** 2454/**
2442* Types of information about MHD features, 2455 * Types of information about MHD features,
2443* used by #MHD_is_feature_supported. 2456 * used by #MHD_is_feature_supported().
2444*/ 2457 */
2445enum MHD_FEATURE 2458enum MHD_FEATURE
2446{ 2459{
2447 /** 2460 /**
@@ -2495,7 +2508,7 @@ enum MHD_FEATURE
2495 /** 2508 /**
2496 * Get whether shutdown on listen socket to signal other 2509 * Get whether shutdown on listen socket to signal other
2497 * threads is supported. If not supported flag 2510 * threads is supported. If not supported flag
2498 * MHD_USE_PIPE_FOR_SHUTDOWN is automatically forced. 2511 * #MHD_USE_PIPE_FOR_SHUTDOWN is automatically forced.
2499 */ 2512 */
2500 MHD_FEATURE_SHUTDOWN_LISTEN_SOCKET = 8, 2513 MHD_FEATURE_SHUTDOWN_LISTEN_SOCKET = 8,
2501 2514
@@ -2522,15 +2535,15 @@ enum MHD_FEATURE
2522 /** 2535 /**
2523 * Get whether HTTP Digest authorization is supported. If 2536 * Get whether HTTP Digest authorization is supported. If
2524 * supported then options #MHD_OPTION_DIGEST_AUTH_RANDOM, 2537 * supported then options #MHD_OPTION_DIGEST_AUTH_RANDOM,
2525 * #MHD_OPTION_NONCE_NC_SIZE and functions #MHD_digest_auth_check, 2538 * #MHD_OPTION_NONCE_NC_SIZE and
2526 * #MHD_digest_auth_check can be used. 2539 * #MHD_digest_auth_check() can be used.
2527 */ 2540 */
2528 MHD_FEATURE_DIGEST_AUTH = 12, 2541 MHD_FEATURE_DIGEST_AUTH = 12,
2529 2542
2530 /** 2543 /**
2531 * Get whether postprocessor is supported. If supported then 2544 * Get whether postprocessor is supported. If supported then
2532 * functions #MHD_create_post_processor, #MHD_post_process, 2545 * functions #MHD_create_post_processor(), #MHD_post_process() and
2533 * #MHD_destroy_post_processor, #MHD_destroy_post_processor can 2546 * #MHD_destroy_post_processor() can
2534 * be used. 2547 * be used.
2535 */ 2548 */
2536 MHD_FEATURE_POSTPROCESSOR = 13 2549 MHD_FEATURE_POSTPROCESSOR = 13
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 484df542..c120e3a0 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -2743,6 +2743,26 @@ MHD_select_thread (void *cls)
2743 2743
2744 2744
2745/** 2745/**
2746 * Process escape sequences ('%HH') Updates val in place; the
2747 * result should be UTF-8 encoded and cannot be larger than the input.
2748 * The result must also still be 0-terminated.
2749 *
2750 * @param cls closure (use NULL)
2751 * @param connection handle to connection, not used
2752 * @param val value to unescape (modified in the process)
2753 * @return length of the resulting val (strlen(val) maybe
2754 * shorter afterwards due to elimination of escape sequences)
2755 */
2756static size_t
2757unescape_wrapper (void *cls,
2758 struct MHD_Connection *connection,
2759 char *val)
2760{
2761 return MHD_http_unescape (val);
2762}
2763
2764
2765/**
2746 * Start a webserver on the given port. Variadic version of 2766 * Start a webserver on the given port. Variadic version of
2747 * #MHD_start_daemon_va. 2767 * #MHD_start_daemon_va.
2748 * 2768 *
@@ -3410,7 +3430,7 @@ MHD_start_daemon_va (unsigned int flags,
3410 daemon->connection_limit = MHD_MAX_CONNECTIONS_DEFAULT; 3430 daemon->connection_limit = MHD_MAX_CONNECTIONS_DEFAULT;
3411 daemon->pool_size = MHD_POOL_SIZE_DEFAULT; 3431 daemon->pool_size = MHD_POOL_SIZE_DEFAULT;
3412 daemon->pool_increment = MHD_BUF_INC_SIZE; 3432 daemon->pool_increment = MHD_BUF_INC_SIZE;
3413 daemon->unescape_callback = &MHD_http_unescape; 3433 daemon->unescape_callback = &unescape_wrapper;
3414 daemon->connection_timeout = 0; /* no timeout */ 3434 daemon->connection_timeout = 0; /* no timeout */
3415 daemon->wpipe[0] = MHD_INVALID_PIPE_; 3435 daemon->wpipe[0] = MHD_INVALID_PIPE_;
3416 daemon->wpipe[1] = MHD_INVALID_PIPE_; 3436 daemon->wpipe[1] = MHD_INVALID_PIPE_;
diff --git a/src/microhttpd/internal.c b/src/microhttpd/internal.c
index 37ba1471..5039c32d 100644
--- a/src/microhttpd/internal.c
+++ b/src/microhttpd/internal.c
@@ -124,16 +124,12 @@ MHD_unescape_plus (char *arg)
124 * result should be UTF-8 encoded and cannot be larger than the input. 124 * result should be UTF-8 encoded and cannot be larger than the input.
125 * The result must also still be 0-terminated. 125 * The result must also still be 0-terminated.
126 * 126 *
127 * @param cls closure (use NULL)
128 * @param connection handle to connection, not used
129 * @param val value to unescape (modified in the process) 127 * @param val value to unescape (modified in the process)
130 * @return length of the resulting val (strlen(val) maybe 128 * @return length of the resulting val (strlen(val) maybe
131 * shorter afterwards due to elimination of escape sequences) 129 * shorter afterwards due to elimination of escape sequences)
132 */ 130 */
133size_t 131size_t
134MHD_http_unescape (void *cls, 132MHD_http_unescape (char *val)
135 struct MHD_Connection *connection,
136 char *val)
137{ 133{
138 char *rpos = val; 134 char *rpos = val;
139 char *wpos = val; 135 char *wpos = val;
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h
index 4b25ccb3..4d80d556 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -199,22 +199,6 @@ MHD_DLOG (const struct MHD_Daemon *daemon,
199 const char *format, ...); 199 const char *format, ...);
200#endif 200#endif
201 201
202/**
203 * Process escape sequences ('+'=space, %HH) Updates val in place; the
204 * result should be UTF-8 encoded and cannot be larger than the input.
205 * The result must also still be 0-terminated.
206 *
207 * @param cls closure (use NULL)
208 * @param connection handle to connection, not used
209 * @param val value to unescape (modified in the process)
210 * @return length of the resulting val (strlen(val) maybe
211 * shorter afterwards due to elimination of escape sequences)
212 */
213size_t
214MHD_http_unescape (void *cls,
215 struct MHD_Connection *connection,
216 char *val);
217
218 202
219/** 203/**
220 * Header or cookie in HTTP request or response. 204 * Header or cookie in HTTP request or response.
diff --git a/src/microhttpd/postprocessor.c b/src/microhttpd/postprocessor.c
index 6512c603..95c7938f 100644
--- a/src/microhttpd/postprocessor.c
+++ b/src/microhttpd/postprocessor.c
@@ -382,7 +382,7 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
382 buf[pp->buffer_pos] = '\0'; /* 0-terminate key */ 382 buf[pp->buffer_pos] = '\0'; /* 0-terminate key */
383 pp->buffer_pos = 0; /* reset for next key */ 383 pp->buffer_pos = 0; /* reset for next key */
384 MHD_unescape_plus (buf); 384 MHD_unescape_plus (buf);
385 MHD_http_unescape (NULL, NULL, buf); 385 MHD_http_unescape (buf);
386 poff += equals + 1; 386 poff += equals + 1;
387 pp->state = PP_ProcessValue; 387 pp->state = PP_ProcessValue;
388 pp->value_offset = 0; 388 pp->value_offset = 0;
@@ -443,7 +443,7 @@ post_process_urlencoded (struct MHD_PostProcessor *pp,
443 /* unescape */ 443 /* unescape */
444 xbuf[xoff] = '\0'; /* 0-terminate in preparation */ 444 xbuf[xoff] = '\0'; /* 0-terminate in preparation */
445 MHD_unescape_plus (xbuf); 445 MHD_unescape_plus (xbuf);
446 xoff = MHD_http_unescape (NULL, NULL, xbuf); 446 xoff = MHD_http_unescape (xbuf);
447 /* finally: call application! */ 447 /* finally: call application! */
448 pp->must_ikvi = MHD_NO; 448 pp->must_ikvi = MHD_NO;
449 if (MHD_NO == pp->ikvi (pp->cls, MHD_POSTDATA_KIND, (const char *) &pp[1], /* key */ 449 if (MHD_NO == pp->ikvi (pp->cls, MHD_POSTDATA_KIND, (const char *) &pp[1], /* key */