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 
00062 void MHD_http_unescape (char *val);
00063 
00067 struct MHD_HTTP_Header
00068 {
00069   struct MHD_HTTP_Header *next;
00070 
00071   char *header;
00072 
00073   char *value;
00074 
00075   enum MHD_ValueKind kind;
00076 
00077 };
00078 
00082 struct MHD_Response
00083 {
00084 
00090   struct MHD_HTTP_Header *first_header;
00091 
00096   char *data;
00097 
00102   void *crc_cls;
00103 
00108   MHD_ContentReaderCallback crc;
00109 
00114   MHD_ContentReaderFreeCallback crfc;
00115 
00120   pthread_mutex_t mutex;
00121 
00126   unsigned int reference_count;
00127 
00131   size_t total_size;
00132 
00136   size_t data_size;
00137 
00141   size_t data_buffer_size;
00142 
00147   size_t data_start;
00148 
00149 };
00150 
00165 enum MHD_CONNECTION_STATE
00166 {
00171   MHD_CONNECTION_INIT = 0,
00172 
00176   MHD_CONNECTION_URL_RECEIVED = MHD_CONNECTION_INIT + 1,
00177 
00181   MHD_CONNECTION_HEADER_PART_RECEIVED = MHD_CONNECTION_URL_RECEIVED + 1,
00182 
00186   MHD_CONNECTION_HEADERS_RECEIVED = MHD_CONNECTION_HEADER_PART_RECEIVED + 1,
00187 
00191   MHD_CONNECTION_HEADERS_PROCESSED = MHD_CONNECTION_HEADERS_RECEIVED + 1,
00192 
00196   MHD_CONNECTION_CONTINUE_SENDING = MHD_CONNECTION_HEADERS_PROCESSED + 1,
00197 
00201   MHD_CONNECTION_CONTINUE_SENT = MHD_CONNECTION_CONTINUE_SENDING + 1,
00202 
00206   MHD_CONNECTION_BODY_RECEIVED = MHD_CONNECTION_CONTINUE_SENT + 1,
00207 
00212   MHD_CONNECTION_FOOTER_PART_RECEIVED = MHD_CONNECTION_BODY_RECEIVED + 1,
00213 
00218   MHD_CONNECTION_FOOTERS_RECEIVED = MHD_CONNECTION_FOOTER_PART_RECEIVED + 1,
00219 
00224   MHD_CONNECTION_HEADERS_SENDING = MHD_CONNECTION_FOOTERS_RECEIVED + 1,
00225 
00229   MHD_CONNECTION_HEADERS_SENT = MHD_CONNECTION_HEADERS_SENDING + 1,
00230 
00234   MHD_CONNECTION_NORMAL_BODY_READY = MHD_CONNECTION_HEADERS_SENT + 1,
00235 
00240   MHD_CONNECTION_NORMAL_BODY_UNREADY = MHD_CONNECTION_NORMAL_BODY_READY + 1,
00241 
00245   MHD_CONNECTION_CHUNKED_BODY_READY = MHD_CONNECTION_NORMAL_BODY_UNREADY + 1,
00246 
00250   MHD_CONNECTION_CHUNKED_BODY_UNREADY = MHD_CONNECTION_CHUNKED_BODY_READY + 1,
00251 
00255   MHD_CONNECTION_BODY_SENT = MHD_CONNECTION_CHUNKED_BODY_UNREADY + 1,
00256 
00260   MHD_CONNECTION_FOOTERS_SENDING = MHD_CONNECTION_BODY_SENT + 1,
00261 
00265   MHD_CONNECTION_FOOTERS_SENT = MHD_CONNECTION_FOOTERS_SENDING + 1,
00266 
00271   MHD_CONNECTION_CLOSED = MHD_CONNECTION_FOOTERS_SENT + 1,
00272 
00273   /*
00274    *  SSL/TLS connection states
00275    */
00276 
00277   /*
00278    * The initial connection state for all secure connectoins
00279    * Handshake messages will be processed in this state & while
00280    * in the 'MHD_TLS_HELLO_REQUEST' state
00281    */
00282   MHD_TLS_CONNECTION_INIT = MHD_CONNECTION_CLOSED + 1,
00283 
00284   /*
00285    * This state indicates the server has send a 'Hello Request' to
00286    * the client & a renegotiation of the handshake is in progress.
00287    *
00288    * Handshake messages will processed in this state & while
00289    * in the 'MHD_TLS_CONNECTION_INIT' state
00290    */
00291   MHD_TLS_HELLO_REQUEST,
00292 
00293   MHD_TLS_HANDSHAKE_FAILED,
00294 
00295   MHD_TLS_HANDSHAKE_COMPLETE,
00296 
00297 };
00298 
00302 #define DEBUG_STATES MHD_NO
00303 
00304 #if HAVE_MESSAGES
00305 char *MHD_state_to_string (enum MHD_CONNECTION_STATE state);
00306 #endif
00307 
00316 typedef ssize_t (*ReceiveCallback) (struct MHD_Connection * conn,
00317                                     void *write_to, size_t max_bytes);
00318 
00319 
00328 typedef ssize_t (*TransmitCallback) (struct MHD_Connection * conn,
00329                                      const void *write_to, size_t max_bytes);
00330 
00331 
00332 
00333 struct MHD_Connection
00334 {
00335 
00339   struct MHD_Connection *next;
00340 
00344   struct MHD_Daemon *daemon;
00345 
00349   struct MHD_HTTP_Header *headers_received;
00350 
00354   struct MHD_Response *response;
00355 
00366   struct MemoryPool *pool;
00367 
00374   void *client_context;
00375 
00380   char *method;
00381 
00386   char *url;
00387 
00392   char *version;
00393 
00400   char *read_buffer;
00401 
00406   char *write_buffer;
00407 
00413   char *last;
00414 
00421   char *colon;
00422 
00427   struct sockaddr_in *addr;
00428 
00433   pthread_t pid;
00434 
00441   size_t read_buffer_size;
00442 
00447   size_t read_buffer_offset;
00448 
00452   size_t write_buffer_size;
00453 
00457   size_t write_buffer_send_offset;
00458 
00463   size_t write_buffer_append_offset;
00464 
00469   size_t remaining_upload_size;
00470 
00476   size_t response_write_position;
00477 
00482   size_t continue_message_write_offset;
00483 
00487   socklen_t addr_len;
00488 
00493   time_t last_activity;
00494 
00500   int socket_fd;
00501 
00509   int read_closed;
00510 
00514   enum MHD_CONNECTION_STATE state;
00515 
00520   unsigned int responseCode;
00521 
00529   int response_unready;
00530 
00534   int have_chunked_response;
00535 
00543   int have_chunked_upload;
00544 
00551   unsigned int current_chunk_size;
00552 
00557   unsigned int current_chunk_offset;
00558 
00559   /* handlers used for processing read, write & idle connection operations */
00560   int (*read_handler) (struct MHD_Connection * connection);
00561 
00562   int (*write_handler) (struct MHD_Connection * connection);
00563 
00564   int (*idle_handler) (struct MHD_Connection * connection);
00565 
00566   ReceiveCallback recv_cls;
00567 
00568   TransmitCallback send_cls;
00569 
00570 #if HTTPS_SUPPORT
00571   /* TODO rename as this might be an SSL connection */
00572   MHD_gtls_session_t tls_session;
00573 #endif
00574 };
00575 
00576 struct MHD_Daemon
00577 {
00578 
00582   MHD_AccessHandlerCallback default_handler;
00583 
00587   void *default_handler_cls;
00588 
00592   struct MHD_Connection *connections;
00593 
00594   MHD_AcceptPolicyCallback apc;
00595 
00596   void *apc_cls;
00597 
00598   MHD_RequestCompletedCallback notify_completed;
00599 
00600   void *notify_completed_cls;
00601 
00602   void * (*uri_log_callback)(void * cls, const char * uri);
00603 
00604   void * uri_log_callback_cls;
00605 
00609   pthread_t pid;
00610 
00614   int socket_fd;
00615 
00619   int shutdown;
00620 
00624   unsigned int pool_size;
00625 
00629   unsigned int max_connections;
00630 
00635   unsigned int connection_timeout;
00636 
00641   unsigned int per_ip_connection_limit;
00642 
00646   enum MHD_OPTION options;
00647 
00651   unsigned short port;
00652 
00653 #if HTTPS_SUPPORT
00654   enum MHD_GNUTLS_CredentialsType cred_type;
00655 
00656   /* server x509 credintials */
00657   MHD_gtls_cert_credentials_t x509_cred;
00658 
00659   /* cipher priority cache */
00660   MHD_gnutls_priority_t priority_cache;
00661 
00662   /* Diffie-Hellman parameters */
00663   MHD_gtls_dh_params_t dh_params;
00664 
00665   const char *https_mem_key;
00666 
00667   const char *https_mem_cert;
00668 #endif
00669 };
00670 
00671 
00672 #if EXTRA_CHECKS
00673 #define EXTRA_CHECK(a) if (!(a)) abort();
00674 #else
00675 #define EXTRA_CHECK(a)
00676 #endif
00677 
00678 
00679 
00680 #endif

Generated on Sun Nov 16 16:53:06 2008 for GNU libmicrohttpd by  doxygen 1.5.1