internal.h

Go to the documentation of this file.
00001 /*
00002   This file is part of libmicrohttpd
00003   (C) 2007, 2008, 2009, 2010 Daniel Pittman and Christian Grothoff
00004   
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Lesser General Public
00007   License as published by the Free Software Foundation; either
00008   version 2.1 of the License, or (at your option) any later version.
00009   
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Lesser General Public License for more details.
00014   
00015   You should have received a copy of the GNU Lesser General Public
00016   License along with this library; if not, write to the Free Software
00017   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 */
00019 
00027 #ifndef INTERNAL_H
00028 #define INTERNAL_H
00029 
00030 #include "platform.h"
00031 #include "microhttpd.h"
00032 #if HTTPS_SUPPORT
00033 #include <gnutls/gnutls.h>
00034 #endif
00035 
00036 #define EXTRA_CHECKS MHD_YES
00037 
00038 #define MHD_MAX(a,b) ((a)<(b)) ? (b) : (a)
00039 #define MHD_MIN(a,b) ((a)<(b)) ? (a) : (b)
00040 
00046 #define MHD_BUF_INC_SIZE 2048
00047 
00051 extern MHD_PanicCallback mhd_panic;
00052 
00056 extern void *mhd_panic_cls;
00057 
00062 enum MHD_PollActions
00063   {
00067     MHD_POLL_ACTION_NOTHING = 0,
00068 
00072     MHD_POLL_ACTION_IN = 1,
00073 
00077     MHD_POLL_ACTION_OUT = 2
00078   };
00079 
00080 
00084 struct MHD_Pollfd 
00085 {
00089   int fd;
00090 
00094   enum MHD_PollActions events;
00095 };
00096 
00097 
00102 #define MAX_NONCE_LENGTH 41
00103 
00104 
00109 struct MHD_NonceNc 
00110 {
00111   
00116   unsigned int nc;
00117 
00121   char nonce[MAX_NONCE_LENGTH];
00122 
00123 };
00124 
00125 #if HAVE_MESSAGES
00126 
00130 void MHD_DLOG (const struct MHD_Daemon *daemon, const char *format, ...);
00131 
00132 #endif
00133 
00144 size_t MHD_http_unescape (void *cls,
00145                           struct MHD_Connection *connection,
00146                           char *val);
00147 
00151 struct MHD_HTTP_Header
00152 {
00156   struct MHD_HTTP_Header *next;
00157 
00162   char *header;
00163 
00167   char *value;
00168 
00173   enum MHD_ValueKind kind;
00174 
00175 };
00176 
00180 struct MHD_Response
00181 {
00182 
00188   struct MHD_HTTP_Header *first_header;
00189 
00194   char *data;
00195 
00200   void *crc_cls;
00201 
00206   MHD_ContentReaderCallback crc;
00207 
00212   MHD_ContentReaderFreeCallback crfc;
00213 
00218   pthread_mutex_t mutex;
00219 
00223   uint64_t total_size;
00224 
00229   uint64_t data_start;
00230 
00234   size_t data_size;
00235 
00239   size_t data_buffer_size;
00240 
00245   unsigned int reference_count;
00246 
00250   int fd;
00251 
00252 };
00253 
00268 enum MHD_CONNECTION_STATE
00269 {
00274   MHD_CONNECTION_INIT = 0,
00275 
00279   MHD_CONNECTION_URL_RECEIVED = MHD_CONNECTION_INIT + 1,
00280 
00284   MHD_CONNECTION_HEADER_PART_RECEIVED = MHD_CONNECTION_URL_RECEIVED + 1,
00285 
00289   MHD_CONNECTION_HEADERS_RECEIVED = MHD_CONNECTION_HEADER_PART_RECEIVED + 1,
00290 
00294   MHD_CONNECTION_HEADERS_PROCESSED = MHD_CONNECTION_HEADERS_RECEIVED + 1,
00295 
00299   MHD_CONNECTION_CONTINUE_SENDING = MHD_CONNECTION_HEADERS_PROCESSED + 1,
00300 
00304   MHD_CONNECTION_CONTINUE_SENT = MHD_CONNECTION_CONTINUE_SENDING + 1,
00305 
00309   MHD_CONNECTION_BODY_RECEIVED = MHD_CONNECTION_CONTINUE_SENT + 1,
00310 
00315   MHD_CONNECTION_FOOTER_PART_RECEIVED = MHD_CONNECTION_BODY_RECEIVED + 1,
00316 
00321   MHD_CONNECTION_FOOTERS_RECEIVED = MHD_CONNECTION_FOOTER_PART_RECEIVED + 1,
00322 
00327   MHD_CONNECTION_HEADERS_SENDING = MHD_CONNECTION_FOOTERS_RECEIVED + 1,
00328 
00332   MHD_CONNECTION_HEADERS_SENT = MHD_CONNECTION_HEADERS_SENDING + 1,
00333 
00337   MHD_CONNECTION_NORMAL_BODY_READY = MHD_CONNECTION_HEADERS_SENT + 1,
00338 
00343   MHD_CONNECTION_NORMAL_BODY_UNREADY = MHD_CONNECTION_NORMAL_BODY_READY + 1,
00344 
00348   MHD_CONNECTION_CHUNKED_BODY_READY = MHD_CONNECTION_NORMAL_BODY_UNREADY + 1,
00349 
00353   MHD_CONNECTION_CHUNKED_BODY_UNREADY = MHD_CONNECTION_CHUNKED_BODY_READY + 1,
00354 
00358   MHD_CONNECTION_BODY_SENT = MHD_CONNECTION_CHUNKED_BODY_UNREADY + 1,
00359 
00363   MHD_CONNECTION_FOOTERS_SENDING = MHD_CONNECTION_BODY_SENT + 1,
00364 
00368   MHD_CONNECTION_FOOTERS_SENT = MHD_CONNECTION_FOOTERS_SENDING + 1,
00369 
00374   MHD_CONNECTION_CLOSED = MHD_CONNECTION_FOOTERS_SENT + 1,
00375 
00376   /*
00377    *  SSL/TLS connection states
00378    */
00379 
00385   MHD_TLS_CONNECTION_INIT = MHD_CONNECTION_CLOSED + 1
00386 
00387 };
00388 
00392 #define DEBUG_STATES MHD_NO
00393 
00394 #if HAVE_MESSAGES
00395 #if DEBUG_STATES
00396 const char *
00397 MHD_state_to_string (enum MHD_CONNECTION_STATE state);
00398 #endif
00399 #endif
00400 
00409 typedef ssize_t (*ReceiveCallback) (struct MHD_Connection * conn,
00410                                     void *write_to, size_t max_bytes);
00411 
00412 
00421 typedef ssize_t (*TransmitCallback) (struct MHD_Connection * conn,
00422                                      const void *write_to, size_t max_bytes);
00423 
00424 
00428 struct MHD_Connection
00429 {
00430 
00434   struct MHD_Connection *next;
00435 
00439   struct MHD_Daemon *daemon;
00440 
00444   struct MHD_HTTP_Header *headers_received;
00445 
00449   struct MHD_Response *response;
00450 
00461   struct MemoryPool *pool;
00462 
00469   void *client_context;
00470 
00475   char *method;
00476 
00481   char *url;
00482 
00487   char *version;
00488 
00495   char *read_buffer;
00496 
00501   char *write_buffer;
00502 
00508   char *last;
00509 
00516   char *colon;
00517 
00522   struct sockaddr_in *addr;
00523 
00528   pthread_t pid;
00529 
00536   size_t read_buffer_size;
00537 
00542   size_t read_buffer_offset;
00543 
00547   size_t write_buffer_size;
00548 
00552   size_t write_buffer_send_offset;
00553 
00558   size_t write_buffer_append_offset;
00559 
00564   uint64_t remaining_upload_size;
00565 
00571   uint64_t response_write_position;
00572 
00577   size_t continue_message_write_offset;
00578 
00582   socklen_t addr_len;
00583 
00588   time_t last_activity;
00589 
00595   int client_aware;
00596 
00602   int socket_fd;
00603 
00611   int read_closed;
00612 
00616   enum MHD_CONNECTION_STATE state;
00617 
00622   unsigned int responseCode;
00623 
00631   int response_unready;
00632 
00636   int have_chunked_response;
00637 
00645   int have_chunked_upload;
00646 
00653   unsigned int current_chunk_size;
00654 
00659   unsigned int current_chunk_offset;
00660 
00664   int (*read_handler) (struct MHD_Connection * connection);
00665 
00669   int (*write_handler) (struct MHD_Connection * connection);
00670 
00674   int (*idle_handler) (struct MHD_Connection * connection);
00675 
00679   ReceiveCallback recv_cls;
00680 
00684   TransmitCallback send_cls;
00685 
00686 #if HTTPS_SUPPORT
00687 
00690   gnutls_session_t tls_session;
00691 
00695   int protocol;
00696 
00700   int cipher;
00701 #endif
00702 };
00703 
00711 typedef void * (*LogCallback)(void * cls, const char * uri);
00712 
00722 typedef size_t (*UnescapeCallback)(void *cls,
00723                                    struct MHD_Connection *conn,
00724                                    char *uri);
00725 
00729 struct MHD_Daemon
00730 {
00731 
00735   MHD_AccessHandlerCallback default_handler;
00736 
00740   void *default_handler_cls;
00741 
00745   struct MHD_Connection *connections;
00746 
00752   MHD_AcceptPolicyCallback apc;
00753 
00757   void *apc_cls;
00758 
00763   MHD_RequestCompletedCallback notify_completed;
00764 
00768   void *notify_completed_cls;
00769 
00777   LogCallback uri_log_callback;
00778 
00782   void *uri_log_callback_cls;
00783 
00787   UnescapeCallback unescape_callback;
00788 
00792   void *unescape_callback_cls;
00793 
00794 #if HAVE_MESSAGES
00795 
00799   void (*custom_error_log) (void *cls, const char *fmt, va_list va);
00800 
00804   void *custom_error_log_cls;
00805 #endif
00806 
00810   struct MHD_Daemon *master;
00811 
00815   struct MHD_Daemon *worker_pool;
00816 
00820   void *per_ip_connection_count;
00821 
00825   size_t pool_size;
00826 
00830   unsigned int worker_pool_size;
00831 
00835   pthread_t pid;
00836 
00840   pthread_mutex_t per_ip_connection_mutex;
00841 
00845   int socket_fd;
00846 
00850   int shutdown;
00851 
00855   unsigned int max_connections;
00856 
00861   unsigned int connection_timeout;
00862 
00867   unsigned int per_ip_connection_limit;
00868 
00872   enum MHD_OPTION options;
00873 
00877   uint16_t port;
00878 
00879 #if HTTPS_SUPPORT
00880 
00883   gnutls_priority_t priority_cache;
00884 
00889   gnutls_credentials_type_t cred_type;
00890 
00894   gnutls_certificate_credentials_t x509_cred;
00895 
00899   gnutls_dh_params_t dh_params;
00900 
00904   const char *https_mem_key;
00905 
00909   const char *https_mem_cert;
00910 
00911 #endif
00912 
00913 #ifdef DAUTH_SUPPORT
00914 
00918   const char *digest_auth_random;
00919 
00923   struct MHD_NonceNc *nnc;
00924 
00928   pthread_mutex_t nnc_lock;
00929 
00933   unsigned int digest_auth_rand_size;
00934 
00938   unsigned int nonce_nc_size;
00939 
00940 #endif
00941 
00942 };
00943 
00944 
00945 #if EXTRA_CHECKS
00946 #define EXTRA_CHECK(a) if (!(a)) abort();
00947 #else
00948 #define EXTRA_CHECK(a)
00949 #endif
00950 
00951 
00952 
00953 #endif

Generated on 16 Nov 2010 for GNU libmicrohttpd by  doxygen 1.6.1