internal.h

Go to the documentation of this file.
00001 /*
00002  This file is part of libmicrohttpd
00003  (C) 2007 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.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 {
00088   int fd;
00089 
00093   enum MHD_PollActions events;
00094 };
00095 
00096 
00097 #if HAVE_MESSAGES
00098 
00102 void MHD_DLOG (const struct MHD_Daemon *daemon, const char *format, ...);
00103 
00104 #endif
00105 void MHD_tls_log_func (int level, const char *str);
00106 
00114 size_t MHD_http_unescape (char *val);
00115 
00119 struct MHD_HTTP_Header
00120 {
00124   struct MHD_HTTP_Header *next;
00125 
00130   char *header;
00131 
00135   char *value;
00136 
00141   enum MHD_ValueKind kind;
00142 
00143 };
00144 
00148 struct MHD_Response
00149 {
00150 
00156   struct MHD_HTTP_Header *first_header;
00157 
00162   char *data;
00163 
00168   void *crc_cls;
00169 
00174   MHD_ContentReaderCallback crc;
00175 
00180   MHD_ContentReaderFreeCallback crfc;
00181 
00186   pthread_mutex_t mutex;
00187 
00192   unsigned int reference_count;
00193 
00197   uint64_t total_size;
00198 
00202   size_t data_size;
00203 
00207   size_t data_buffer_size;
00208 
00213   uint64_t data_start;
00214 
00215 };
00216 
00231 enum MHD_CONNECTION_STATE
00232 {
00237   MHD_CONNECTION_INIT = 0,
00238 
00242   MHD_CONNECTION_URL_RECEIVED = MHD_CONNECTION_INIT + 1,
00243 
00247   MHD_CONNECTION_HEADER_PART_RECEIVED = MHD_CONNECTION_URL_RECEIVED + 1,
00248 
00252   MHD_CONNECTION_HEADERS_RECEIVED = MHD_CONNECTION_HEADER_PART_RECEIVED + 1,
00253 
00257   MHD_CONNECTION_HEADERS_PROCESSED = MHD_CONNECTION_HEADERS_RECEIVED + 1,
00258 
00262   MHD_CONNECTION_CONTINUE_SENDING = MHD_CONNECTION_HEADERS_PROCESSED + 1,
00263 
00267   MHD_CONNECTION_CONTINUE_SENT = MHD_CONNECTION_CONTINUE_SENDING + 1,
00268 
00272   MHD_CONNECTION_BODY_RECEIVED = MHD_CONNECTION_CONTINUE_SENT + 1,
00273 
00278   MHD_CONNECTION_FOOTER_PART_RECEIVED = MHD_CONNECTION_BODY_RECEIVED + 1,
00279 
00284   MHD_CONNECTION_FOOTERS_RECEIVED = MHD_CONNECTION_FOOTER_PART_RECEIVED + 1,
00285 
00290   MHD_CONNECTION_HEADERS_SENDING = MHD_CONNECTION_FOOTERS_RECEIVED + 1,
00291 
00295   MHD_CONNECTION_HEADERS_SENT = MHD_CONNECTION_HEADERS_SENDING + 1,
00296 
00300   MHD_CONNECTION_NORMAL_BODY_READY = MHD_CONNECTION_HEADERS_SENT + 1,
00301 
00306   MHD_CONNECTION_NORMAL_BODY_UNREADY = MHD_CONNECTION_NORMAL_BODY_READY + 1,
00307 
00311   MHD_CONNECTION_CHUNKED_BODY_READY = MHD_CONNECTION_NORMAL_BODY_UNREADY + 1,
00312 
00316   MHD_CONNECTION_CHUNKED_BODY_UNREADY = MHD_CONNECTION_CHUNKED_BODY_READY + 1,
00317 
00321   MHD_CONNECTION_BODY_SENT = MHD_CONNECTION_CHUNKED_BODY_UNREADY + 1,
00322 
00326   MHD_CONNECTION_FOOTERS_SENDING = MHD_CONNECTION_BODY_SENT + 1,
00327 
00331   MHD_CONNECTION_FOOTERS_SENT = MHD_CONNECTION_FOOTERS_SENDING + 1,
00332 
00337   MHD_CONNECTION_CLOSED = MHD_CONNECTION_FOOTERS_SENT + 1,
00338 
00339   /*
00340    *  SSL/TLS connection states
00341    */
00342 
00348   MHD_TLS_CONNECTION_INIT = MHD_CONNECTION_CLOSED + 1,
00349 
00357   MHD_TLS_HELLO_REQUEST,
00358 
00359   MHD_TLS_HANDSHAKE_FAILED,
00360 
00361   MHD_TLS_HANDSHAKE_COMPLETE
00362 
00363 };
00364 
00368 #define DEBUG_STATES MHD_NO
00369 
00370 #if HAVE_MESSAGES
00371 char *MHD_state_to_string (enum MHD_CONNECTION_STATE state);
00372 #endif
00373 
00382 typedef ssize_t (*ReceiveCallback) (struct MHD_Connection * conn,
00383                                     void *write_to, size_t max_bytes);
00384 
00385 
00394 typedef ssize_t (*TransmitCallback) (struct MHD_Connection * conn,
00395                                      const void *write_to, size_t max_bytes);
00396 
00397 
00401 struct MHD_Connection
00402 {
00403 
00407   struct MHD_Connection *next;
00408 
00412   struct MHD_Daemon *daemon;
00413 
00417   struct MHD_HTTP_Header *headers_received;
00418 
00422   struct MHD_Response *response;
00423 
00434   struct MemoryPool *pool;
00435 
00442   void *client_context;
00443 
00448   char *method;
00449 
00454   char *url;
00455 
00460   char *version;
00461 
00468   char *read_buffer;
00469 
00474   char *write_buffer;
00475 
00481   char *last;
00482 
00489   char *colon;
00490 
00495   struct sockaddr_in *addr;
00496 
00501   pthread_t pid;
00502 
00509   size_t read_buffer_size;
00510 
00515   size_t read_buffer_offset;
00516 
00520   size_t write_buffer_size;
00521 
00525   size_t write_buffer_send_offset;
00526 
00531   size_t write_buffer_append_offset;
00532 
00537   uint64_t remaining_upload_size;
00538 
00544   uint64_t response_write_position;
00545 
00550   size_t continue_message_write_offset;
00551 
00555   socklen_t addr_len;
00556 
00561   time_t last_activity;
00562 
00568   int client_aware;
00569 
00575   int socket_fd;
00576 
00584   int read_closed;
00585 
00589   enum MHD_CONNECTION_STATE state;
00590 
00595   unsigned int responseCode;
00596 
00604   int response_unready;
00605 
00609   int have_chunked_response;
00610 
00618   int have_chunked_upload;
00619 
00626   unsigned int current_chunk_size;
00627 
00632   unsigned int current_chunk_offset;
00633 
00637   int (*read_handler) (struct MHD_Connection * connection);
00638 
00642   int (*write_handler) (struct MHD_Connection * connection);
00643 
00647   int (*idle_handler) (struct MHD_Connection * connection);
00648 
00652   ReceiveCallback recv_cls;
00653 
00657   TransmitCallback send_cls;
00658 
00659 #if HTTPS_SUPPORT
00660 
00663   MHD_gtls_session_t tls_session;
00664 #endif
00665 };
00666 
00667 typedef void * (*LogCallback)(void * cls, const char * uri);
00668 
00672 struct MHD_Daemon
00673 {
00674 
00678   MHD_AccessHandlerCallback default_handler;
00679 
00683   void *default_handler_cls;
00684 
00688   struct MHD_Connection *connections;
00689 
00695   MHD_AcceptPolicyCallback apc;
00696 
00700   void *apc_cls;
00701 
00706   MHD_RequestCompletedCallback notify_completed;
00707 
00711   void *notify_completed_cls;
00712 
00720   LogCallback uri_log_callback;
00721 
00725   void *uri_log_callback_cls;
00726 
00727 #if HAVE_MESSAGES
00728 
00732   void (*custom_error_log) (void *cls, const char *fmt, va_list va);
00733 
00737   void *custom_error_log_cls;
00738 #endif
00739 
00743   pthread_t pid;
00744 
00748   int socket_fd;
00749 
00753   int shutdown;
00754 
00758   size_t pool_size;
00759 
00763   unsigned int max_connections;
00764 
00769   unsigned int connection_timeout;
00770 
00775   unsigned int per_ip_connection_limit;
00776 
00780   void *per_ip_connection_count;
00781 
00785   pthread_mutex_t per_ip_connection_mutex;
00786 
00790   enum MHD_OPTION options;
00791 
00795   unsigned short port;
00796 
00797 #if HTTPS_SUPPORT
00798 
00802   enum MHD_GNUTLS_CredentialsType cred_type;
00803 
00807   MHD_gtls_cert_credentials_t x509_cred;
00808 
00812   MHD_gnutls_priority_t priority_cache;
00813 
00817   MHD_gtls_dh_params_t dh_params;
00818 
00822   const char *https_mem_key;
00823 
00827   const char *https_mem_cert;
00828 #endif
00829 
00833   struct MHD_Daemon *master;
00834 
00838   struct MHD_Daemon *worker_pool;
00839 
00843   unsigned int worker_pool_size;
00844 };
00845 
00846 
00847 #if EXTRA_CHECKS
00848 #define EXTRA_CHECK(a) if (!(a)) abort();
00849 #else
00850 #define EXTRA_CHECK(a)
00851 #endif
00852 
00853 
00854 
00855 #endif
Generated by  doxygen 1.6.2-20100208