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 
00048 #if HAVE_MESSAGES
00049 
00053 void MHD_DLOG (const struct MHD_Daemon *daemon, const char *format, ...);
00054 
00055 #endif
00056 void MHD_tls_log_func (int level, const char *str);
00057 
00065 size_t MHD_http_unescape (char *val);
00066 
00070 struct MHD_HTTP_Header
00071 {
00075   struct MHD_HTTP_Header *next;
00076 
00081   char *header;
00082 
00086   char *value;
00087 
00092   enum MHD_ValueKind kind;
00093 
00094 };
00095 
00099 struct MHD_Response
00100 {
00101 
00107   struct MHD_HTTP_Header *first_header;
00108 
00113   char *data;
00114 
00119   void *crc_cls;
00120 
00125   MHD_ContentReaderCallback crc;
00126 
00131   MHD_ContentReaderFreeCallback crfc;
00132 
00137   pthread_mutex_t mutex;
00138 
00143   unsigned int reference_count;
00144 
00148   uint64_t total_size;
00149 
00153   size_t data_size;
00154 
00158   size_t data_buffer_size;
00159 
00164   uint64_t data_start;
00165 
00166 };
00167 
00182 enum MHD_CONNECTION_STATE
00183 {
00188   MHD_CONNECTION_INIT = 0,
00189 
00193   MHD_CONNECTION_URL_RECEIVED = MHD_CONNECTION_INIT + 1,
00194 
00198   MHD_CONNECTION_HEADER_PART_RECEIVED = MHD_CONNECTION_URL_RECEIVED + 1,
00199 
00203   MHD_CONNECTION_HEADERS_RECEIVED = MHD_CONNECTION_HEADER_PART_RECEIVED + 1,
00204 
00208   MHD_CONNECTION_HEADERS_PROCESSED = MHD_CONNECTION_HEADERS_RECEIVED + 1,
00209 
00213   MHD_CONNECTION_CONTINUE_SENDING = MHD_CONNECTION_HEADERS_PROCESSED + 1,
00214 
00218   MHD_CONNECTION_CONTINUE_SENT = MHD_CONNECTION_CONTINUE_SENDING + 1,
00219 
00223   MHD_CONNECTION_BODY_RECEIVED = MHD_CONNECTION_CONTINUE_SENT + 1,
00224 
00229   MHD_CONNECTION_FOOTER_PART_RECEIVED = MHD_CONNECTION_BODY_RECEIVED + 1,
00230 
00235   MHD_CONNECTION_FOOTERS_RECEIVED = MHD_CONNECTION_FOOTER_PART_RECEIVED + 1,
00236 
00241   MHD_CONNECTION_HEADERS_SENDING = MHD_CONNECTION_FOOTERS_RECEIVED + 1,
00242 
00246   MHD_CONNECTION_HEADERS_SENT = MHD_CONNECTION_HEADERS_SENDING + 1,
00247 
00251   MHD_CONNECTION_NORMAL_BODY_READY = MHD_CONNECTION_HEADERS_SENT + 1,
00252 
00257   MHD_CONNECTION_NORMAL_BODY_UNREADY = MHD_CONNECTION_NORMAL_BODY_READY + 1,
00258 
00262   MHD_CONNECTION_CHUNKED_BODY_READY = MHD_CONNECTION_NORMAL_BODY_UNREADY + 1,
00263 
00267   MHD_CONNECTION_CHUNKED_BODY_UNREADY = MHD_CONNECTION_CHUNKED_BODY_READY + 1,
00268 
00272   MHD_CONNECTION_BODY_SENT = MHD_CONNECTION_CHUNKED_BODY_UNREADY + 1,
00273 
00277   MHD_CONNECTION_FOOTERS_SENDING = MHD_CONNECTION_BODY_SENT + 1,
00278 
00282   MHD_CONNECTION_FOOTERS_SENT = MHD_CONNECTION_FOOTERS_SENDING + 1,
00283 
00288   MHD_CONNECTION_CLOSED = MHD_CONNECTION_FOOTERS_SENT + 1,
00289 
00290   /*
00291    *  SSL/TLS connection states
00292    */
00293 
00299   MHD_TLS_CONNECTION_INIT = MHD_CONNECTION_CLOSED + 1,
00300 
00308   MHD_TLS_HELLO_REQUEST,
00309 
00310   MHD_TLS_HANDSHAKE_FAILED,
00311 
00312   MHD_TLS_HANDSHAKE_COMPLETE,
00313 
00314 };
00315 
00319 #define DEBUG_STATES MHD_NO
00320 
00321 #if HAVE_MESSAGES
00322 char *MHD_state_to_string (enum MHD_CONNECTION_STATE state);
00323 #endif
00324 
00333 typedef ssize_t (*ReceiveCallback) (struct MHD_Connection * conn,
00334                                     void *write_to, size_t max_bytes);
00335 
00336 
00345 typedef ssize_t (*TransmitCallback) (struct MHD_Connection * conn,
00346                                      const void *write_to, size_t max_bytes);
00347 
00348 
00352 struct MHD_Connection
00353 {
00354 
00358   struct MHD_Connection *next;
00359 
00363   struct MHD_Daemon *daemon;
00364 
00368   struct MHD_HTTP_Header *headers_received;
00369 
00373   struct MHD_Response *response;
00374 
00385   struct MemoryPool *pool;
00386 
00393   void *client_context;
00394 
00399   char *method;
00400 
00405   char *url;
00406 
00411   char *version;
00412 
00419   char *read_buffer;
00420 
00425   char *write_buffer;
00426 
00432   char *last;
00433 
00440   char *colon;
00441 
00446   struct sockaddr_in *addr;
00447 
00452   pthread_t pid;
00453 
00460   size_t read_buffer_size;
00461 
00466   size_t read_buffer_offset;
00467 
00471   size_t write_buffer_size;
00472 
00476   size_t write_buffer_send_offset;
00477 
00482   size_t write_buffer_append_offset;
00483 
00488   uint64_t remaining_upload_size;
00489 
00495   uint64_t response_write_position;
00496 
00501   size_t continue_message_write_offset;
00502 
00506   socklen_t addr_len;
00507 
00512   time_t last_activity;
00513 
00519   int socket_fd;
00520 
00528   int read_closed;
00529 
00533   enum MHD_CONNECTION_STATE state;
00534 
00539   unsigned int responseCode;
00540 
00548   int response_unready;
00549 
00553   int have_chunked_response;
00554 
00562   int have_chunked_upload;
00563 
00570   unsigned int current_chunk_size;
00571 
00576   unsigned int current_chunk_offset;
00577 
00581   int (*read_handler) (struct MHD_Connection * connection);
00582 
00586   int (*write_handler) (struct MHD_Connection * connection);
00587 
00591   int (*idle_handler) (struct MHD_Connection * connection);
00592 
00596   ReceiveCallback recv_cls;
00597 
00601   TransmitCallback send_cls;
00602 
00603 #if HTTPS_SUPPORT
00604 
00607   MHD_gtls_session_t tls_session;
00608 #endif
00609 };
00610 
00611 typedef void * (*LogCallback)(void * cls, const char * uri);
00612 
00616 struct MHD_Daemon
00617 {
00618 
00622   MHD_AccessHandlerCallback default_handler;
00623 
00627   void *default_handler_cls;
00628 
00632   struct MHD_Connection *connections;
00633 
00639   MHD_AcceptPolicyCallback apc;
00640 
00644   void *apc_cls;
00645 
00650   MHD_RequestCompletedCallback notify_completed;
00651 
00655   void *notify_completed_cls;
00656 
00664   LogCallback uri_log_callback;
00665 
00669   void *uri_log_callback_cls;
00670 
00671 #if HAVE_MESSAGES
00672 
00676   void (*custom_error_log) (void *cls, const char *fmt, va_list va);
00677 
00681   void *custom_error_log_cls;
00682 #endif
00683 
00687   pthread_t pid;
00688 
00692   int socket_fd;
00693 
00697   int shutdown;
00698 
00702   size_t pool_size;
00703 
00707   unsigned int max_connections;
00708 
00713   unsigned int connection_timeout;
00714 
00719   unsigned int per_ip_connection_limit;
00720 
00724   enum MHD_OPTION options;
00725 
00729   unsigned short port;
00730 
00731 #if HTTPS_SUPPORT
00732 
00736   enum MHD_GNUTLS_CredentialsType cred_type;
00737 
00741   MHD_gtls_cert_credentials_t x509_cred;
00742 
00746   MHD_gnutls_priority_t priority_cache;
00747 
00751   MHD_gtls_dh_params_t dh_params;
00752 
00756   const char *https_mem_key;
00757 
00761   const char *https_mem_cert;
00762 #endif
00763 };
00764 
00765 
00766 #if EXTRA_CHECKS
00767 #define EXTRA_CHECK(a) if (!(a)) abort();
00768 #else
00769 #define EXTRA_CHECK(a)
00770 #endif
00771 
00772 
00773 
00774 #endif

Generated on Fri Feb 27 18:31:22 2009 for GNU libmicrohttpd by  doxygen 1.5.7.1