diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-08-21 09:06:58 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-08-21 09:14:05 +0200 |
commit | 3e7a55e9685eb8bf51b6307883b366b2dd38948a (patch) | |
tree | 2829bf6c2ac8cbe726170f871a6c96965c6bc16a | |
parent | c0168fde5043523fb2c05c76ca4506cb734c43b8 (diff) | |
download | libmicrohttpd-3e7a55e9685eb8bf51b6307883b366b2dd38948a.tar.gz libmicrohttpd-3e7a55e9685eb8bf51b6307883b366b2dd38948a.zip |
updates to proposed API based on discussions with EG
-rw-r--r-- | src/include/microhttpd2.h | 168 |
1 files changed, 45 insertions, 123 deletions
diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h index ec15d5dd..61da63b2 100644 --- a/src/include/microhttpd2.h +++ b/src/include/microhttpd2.h | |||
@@ -760,23 +760,51 @@ MHD_option_digest_auth_nc_size (size_t stack_limit_b); | |||
760 | */ | 760 | */ |
761 | _MHD_EXTERN struct MHD_Option | 761 | _MHD_EXTERN struct MHD_Option |
762 | MHD_option_connection_completion (MHD_ConnectionCompledCallback ccc, | 762 | MHD_option_connection_completion (MHD_ConnectionCompledCallback ccc, |
763 | void *ccc_cls;) | 763 | void *ccc_cls); |
764 | |||
765 | |||
766 | /** | ||
767 | * Return values for the #MHD_RequestHeaderCallback implementations. | ||
768 | */ | ||
769 | enum MHD_HeaderResult | ||
770 | { | ||
771 | /** | ||
772 | * Close the connection, we encountered a serious error. | ||
773 | */ | ||
774 | MHD_HR_CLOSE_CONNECTION = 0, | ||
775 | |||
776 | /** | ||
777 | * Continue to handle the connection normally, if requested | ||
778 | * by the client send a "100 CONTINUE" response. If the | ||
779 | * #MHD_RequestHeaderCallback is not defined for a given | ||
780 | * request, this behavior is what will always happen. | ||
781 | */ | ||
782 | MHD_HR_CONTINUE_NORMALLY = 1, | ||
783 | |||
784 | /** | ||
785 | * Refuse handling the upload. This code ensures that MHD will | ||
786 | * not send a "100 CONTINUE" response (even if requested) | ||
787 | * and instead MHD will immediately proceed to the | ||
788 | * #MHD_RequestFetchResponseCallback to get the response. This | ||
789 | * is useful if an upload must be refused, i.e. because it is | ||
790 | * too big or not supported for the given encoding/uri/method. | ||
791 | */ | ||
792 | MHD_HR_REFUSE_UPLOAD = 2 | ||
793 | |||
794 | }; | ||
764 | 795 | ||
765 | 796 | ||
766 | /** | 797 | /** |
767 | * Signature of the callback used by MHD to notify the application | 798 | * Signature of the callback used by MHD to notify the application |
768 | * that we have received the full header of a request. Can be used to | 799 | * that we have received the full header of a request. Can be used to |
769 | * send error responses to a "Expect: 100-continue" request. | 800 | * suppress "100 CONTINUE" responses to requests containing an |
770 | * Note that regular responses should be set in the | 801 | * "Expect: 100-continue" header (by returning #MHD_HR_REFUSE_UPLOAD). |
771 | * #MHD_RequestCompletedCallback. | ||
772 | * | 802 | * |
773 | * @param cls client-defined closure | 803 | * @param cls client-defined closure |
774 | * @ingroup request | 804 | * @ingroup request |
775 | * @return #MHD_YES if the upload was handled successfully, | 805 | * @return how to proceed handling the request |
776 | * #MHD_NO if the socket must be closed due to a serios | ||
777 | * error while handling the request | ||
778 | */ | 806 | */ |
779 | typedef enum MHD_Bool | 807 | typedef enum MHD_HeaderResult |
780 | (*MHD_RequestHeaderCallback) (void *cls); | 808 | (*MHD_RequestHeaderCallback) (void *cls); |
781 | 809 | ||
782 | 810 | ||
@@ -785,13 +813,9 @@ typedef enum MHD_Bool | |||
785 | * | 813 | * |
786 | * @param cls argument given together with the function | 814 | * @param cls argument given together with the function |
787 | * pointer when the handler was registered with MHD | 815 | * pointer when the handler was registered with MHD |
788 | * @param upload_data the data being uploaded (excluding HEADERS, | 816 | * @param upload_data the data being uploaded (excluding headers) |
789 | * for a POST that fits into memory and that is encoded | 817 | * POST data will typically be made available incrementally via |
790 | * with a supported encoding, the POST data will NOT be | 818 | * multiple callbacks |
791 | * given in upload_data and is instead available as | ||
792 | * part of #MHD_get_connection_values; very large POST | ||
793 | * data *will* be made available incrementally in | ||
794 | * @a upload_data) | ||
795 | * @param[in,out] upload_data_size set initially to the size of the | 819 | * @param[in,out] upload_data_size set initially to the size of the |
796 | * @a upload_data provided; the method must update this | 820 | * @a upload_data provided; the method must update this |
797 | * value to the number of bytes NOT processed; | 821 | * value to the number of bytes NOT processed; |
@@ -881,7 +905,7 @@ struct MHD_RequestHandlerCallbacks | |||
881 | * #MHD_HTTP_METHOD_DELETE, #MHD_HTTP_METHOD_POST, etc). The callback | 905 | * #MHD_HTTP_METHOD_DELETE, #MHD_HTTP_METHOD_POST, etc). The callback |
882 | * must initialize @a rhp to provide further callbacks which will | 906 | * must initialize @a rhp to provide further callbacks which will |
883 | * process the request further and ultimately to provide the response | 907 | * process the request further and ultimately to provide the response |
884 | * to give back to the client. | 908 | * to give back to the client, or return #MHD_NO. |
885 | * | 909 | * |
886 | * @param cls argument given together with the function | 910 | * @param cls argument given together with the function |
887 | * pointer when the handler was registered with MHD | 911 | * pointer when the handler was registered with MHD |
@@ -903,112 +927,6 @@ typedef enum MHD_Bool | |||
903 | struct MHD_RequestHandlerCallbacks *rhp); | 927 | struct MHD_RequestHandlerCallbacks *rhp); |
904 | 928 | ||
905 | 929 | ||
906 | /** | ||
907 | * Generic option to set a global URL handler which | ||
908 | * will be called for all requests. You may prefer the | ||
909 | * more convenient, but less generic #MHD_option_url_table(). | ||
910 | * | ||
911 | * @param rc function to call for requests | ||
912 | * @param rc_cls closure to give to @a rc | ||
913 | */ | ||
914 | _MHD_EXTERN struct MHD_Option | ||
915 | MHD_option_url_handler (MHD_RequestCallback rc, | ||
916 | void *rc_cls); | ||
917 | |||
918 | |||
919 | /** | ||
920 | * A client has requested the given url using the given method | ||
921 | * (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT, | ||
922 | * #MHD_HTTP_METHOD_DELETE, #MHD_HTTP_METHOD_POST, etc). The callback | ||
923 | * must initialize @a rhp to provide further callbacks which will | ||
924 | * process the request further and ultimately to provide the response | ||
925 | * to give back to the client. | ||
926 | * | ||
927 | * @param cls argument given together with the function | ||
928 | * pointer when the handler was registered with MHD | ||
929 | * @param request HTTP request handle | ||
930 | * @param[out] must be set to function pointers to be used to | ||
931 | * handle the request further; can be assumed to have | ||
932 | * been initialized to all-NULL values already. | ||
933 | * @return #MHD_YES if the request was handled successfully, | ||
934 | * #MHD_NO if the socket must be closed due to a serious | ||
935 | * error while handling the request | ||
936 | */ | ||
937 | typedef enum MHD_Bool | ||
938 | (*MHD_RequestStartCallback) (void *cls, | ||
939 | struct MHD_Request *request, | ||
940 | struct MHD_RequestHandlerCallbacks *rhp); | ||
941 | |||
942 | |||
943 | /** | ||
944 | * Definition of a request handler for a URL and method. | ||
945 | */ | ||
946 | struct MHD_UrlHandler; | ||
947 | |||
948 | |||
949 | /** | ||
950 | * Create URL handler array terminator. | ||
951 | */ | ||
952 | _MHD_EXTERN struct MHD_UrlHandler | ||
953 | MHD_url_handler_end (void); | ||
954 | |||
955 | |||
956 | /** | ||
957 | * Create a generic URL handler array entry. | ||
958 | * | ||
959 | * @param method HTTP method to which this handler | ||
960 | * matches. Case-insensitive, i.e. "GET". | ||
961 | * @param url Which URL does this handler match. Case-sensitive, | ||
962 | * i.e. "/favicon.ico". | ||
963 | * @param start_cb function to call for matching requests | ||
964 | * @param start_cb_cls closure for @a start_cb | ||
965 | * @return url handler array entry | ||
966 | */ | ||
967 | _MHD_EXTERN struct MHD_UrlHandler | ||
968 | MHD_url_handler_generic (const char *method, | ||
969 | const char *url, | ||
970 | MHD_RequestStartCallback start_cb, | ||
971 | void *start_cb_cls); | ||
972 | |||
973 | |||
974 | /** | ||
975 | * Create a simple URL handler array entry for requests | ||
976 | * where the application simply returns a response and | ||
977 | * has no state to initialize or clean up and where there | ||
978 | * is no upload. | ||
979 | * | ||
980 | * @param method HTTP method to which this handler | ||
981 | * matches. Case-insensitive, i.e. "GET". | ||
982 | * @param url Which URL does this handler match. Case-sensitive, | ||
983 | * i.e. "/favicon.ico". | ||
984 | * @param fetch_cb function to call for matching requests | ||
985 | * @param fetch_cb_cls closure for @a fetch_cb | ||
986 | * @return url handler array entry | ||
987 | */ | ||
988 | _MHD_EXTERN struct MHD_UrlHandler | ||
989 | MHD_url_handler_simple (const char *method, | ||
990 | const char *url, | ||
991 | MHD_RequestFetchResponseCallback fetch_cb, | ||
992 | void *fetch_cb_cls); | ||
993 | |||
994 | |||
995 | /** | ||
996 | * Set a table of @a handlers to process requests of matching methods | ||
997 | * and URLs. Requests that do not match any entry will yield a 404 | ||
998 | * NOT FOUND response. Note that this function may sort the @a | ||
999 | * handlers array in-place for faster (logarithmic) lookups later, | ||
1000 | * hence the argument must be muteable. The @a handlers array must | ||
1001 | * remain allocated by the application throughout the lifetime of the | ||
1002 | * daemon! | ||
1003 | * | ||
1004 | * @param[in,out] handlers url handler table, terminated | ||
1005 | * by #MHD_url_handler_end() | ||
1006 | * @return option array entry | ||
1007 | */ | ||
1008 | _MHD_EXTERN struct MHD_Option | ||
1009 | MHD_option_url_table (struct MHD_UrlHandler handlers[]); | ||
1010 | |||
1011 | |||
1012 | /* **************** Daemon handling functions ***************** */ | 930 | /* **************** Daemon handling functions ***************** */ |
1013 | 931 | ||
1014 | /** | 932 | /** |
@@ -1018,11 +936,15 @@ MHD_option_url_table (struct MHD_UrlHandler handlers[]); | |||
1018 | * persist in memory past this call (note that individual | 936 | * persist in memory past this call (note that individual |
1019 | * arguments passed to the functions may need to | 937 | * arguments passed to the functions may need to |
1020 | * be preserved) | 938 | * be preserved) |
939 | * @param cb function to be called for incoming requests | ||
940 | * @param cb_cls closure for @a cb | ||
1021 | * @return NULL on error, handle to daemon on success | 941 | * @return NULL on error, handle to daemon on success |
1022 | * @ingroup event | 942 | * @ingroup event |
1023 | */ | 943 | */ |
1024 | _MHD_EXTERN struct MHD_Daemon * | 944 | _MHD_EXTERN struct MHD_Daemon * |
1025 | MHD_daemon_start (const struct MHD_Option options[]); | 945 | MHD_daemon_start (const struct MHD_Option options[], |
946 | MHD_RequestCallback cb, | ||
947 | void *cb_cls); | ||
1026 | 948 | ||
1027 | 949 | ||
1028 | /** | 950 | /** |