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 
00031 #include <stdio.h>
00032 #include <stdlib.h>
00033 #include <string.h>
00034 #include <unistd.h>
00035 #include <stdarg.h>
00036 #include <errno.h>
00037 #include <fcntl.h>
00038 #include <signal.h>
00039 
00040 #include "config.h"
00041 #include "plibc.h"
00042 #include "microhttpd.h"
00043 
00044 #ifndef MINGW
00045 #include <sys/mman.h>
00046 #include <netdb.h>
00047 #include <netinet/in.h>
00048 #endif
00049 
00050 #include <pthread.h>
00051 
00052 #define MAX(a,b) ((a)<(b)) ? (b) : (a)
00053 #define MIN(a,b) ((a)<(b)) ? (a) : (b)
00054 
00060 #define MHD_BUF_INC_SIZE 2048
00061 
00062 #if HAVE_MESSAGES
00063 
00067 void MHD_DLOG (const struct MHD_Daemon *daemon, const char *format, ...);
00068 #endif
00069 
00074 void MHD_http_unescape (char *val);
00075 
00079 struct MHD_HTTP_Header
00080 {
00081   struct MHD_HTTP_Header *next;
00082 
00083   char *header;
00084 
00085   char *value;
00086 
00087   enum MHD_ValueKind kind;
00088 
00089 };
00090 
00094 struct MHD_Response
00095 {
00096 
00102   struct MHD_HTTP_Header *first_header;
00103 
00108   char *data;
00109 
00114   void *crc_cls;
00115 
00120   MHD_ContentReaderCallback crc;
00121 
00126   MHD_ContentReaderFreeCallback crfc;
00127 
00132   pthread_mutex_t mutex;
00133 
00138   unsigned int reference_count;
00139 
00143   size_t total_size;
00144 
00148   size_t data_size;
00149 
00153   size_t data_buffer_size;
00154 
00159   size_t data_start;
00160 
00161 };
00162 
00177 enum MHD_CONNECTION_STATE
00178 {
00183   MHD_CONNECTION_INIT = 0,
00184 
00188   MHD_CONNECTION_URL_RECEIVED = MHD_CONNECTION_INIT + 1,
00189 
00193   MHD_CONNECTION_HEADER_PART_RECEIVED = MHD_CONNECTION_URL_RECEIVED + 1,
00194 
00198   MHD_CONNECTION_HEADERS_RECEIVED = MHD_CONNECTION_HEADER_PART_RECEIVED + 1,
00199 
00203   MHD_CONNECTION_HEADERS_PROCESSED = MHD_CONNECTION_HEADERS_RECEIVED + 1,
00204 
00208   MHD_CONNECTION_CONTINUE_SENDING = MHD_CONNECTION_HEADERS_PROCESSED + 1,
00209 
00213   MHD_CONNECTION_CONTINUE_SENT = MHD_CONNECTION_CONTINUE_SENDING + 1,
00214 
00218   MHD_CONNECTION_BODY_RECEIVED = MHD_CONNECTION_CONTINUE_SENT + 1,
00219 
00224   MHD_CONNECTION_FOOTER_PART_RECEIVED = MHD_CONNECTION_BODY_RECEIVED + 1,
00225 
00230   MHD_CONNECTION_FOOTERS_RECEIVED = MHD_CONNECTION_FOOTER_PART_RECEIVED + 1,
00231 
00236   MHD_CONNECTION_HEADERS_SENDING = MHD_CONNECTION_FOOTERS_RECEIVED + 1,
00237 
00241   MHD_CONNECTION_HEADERS_SENT = MHD_CONNECTION_HEADERS_SENDING + 1,
00242 
00246   MHD_CONNECTION_NORMAL_BODY_READY = MHD_CONNECTION_HEADERS_SENT + 1,
00247 
00252   MHD_CONNECTION_NORMAL_BODY_UNREADY = MHD_CONNECTION_NORMAL_BODY_READY + 1,
00253 
00257   MHD_CONNECTION_CHUNKED_BODY_READY = MHD_CONNECTION_NORMAL_BODY_UNREADY + 1,
00258 
00262   MHD_CONNECTION_CHUNKED_BODY_UNREADY = MHD_CONNECTION_CHUNKED_BODY_READY + 1,
00263 
00267   MHD_CONNECTION_BODY_SENT = MHD_CONNECTION_CHUNKED_BODY_UNREADY + 1,
00268 
00272   MHD_CONNECTION_FOOTERS_SENDING = MHD_CONNECTION_BODY_SENT + 1,
00273 
00277   MHD_CONNECTION_FOOTERS_SENT = MHD_CONNECTION_FOOTERS_SENDING + 1,
00278 
00283   MHD_CONNECTION_CLOSED = MHD_CONNECTION_FOOTERS_SENT + 1,
00284 
00285 };
00286 
00287 struct MHD_Connection
00288 {
00289 
00293   struct MHD_Connection *next;
00294 
00298   struct MHD_Daemon *daemon;
00299 
00303   struct MHD_HTTP_Header *headers_received;
00304 
00308   struct MHD_Response *response;
00309 
00320   struct MemoryPool *pool;
00321 
00328   void *client_context;
00329 
00334   char *method;
00335 
00340   char *url;
00341 
00346   char *version;
00347 
00354   char *read_buffer;
00355 
00360   char *write_buffer;
00361 
00367   char *last;
00368 
00375   char *colon;
00376 
00381   struct sockaddr_in *addr;
00382 
00387   pthread_t pid;
00388 
00395   size_t read_buffer_size;
00396 
00401   size_t read_buffer_offset;
00402 
00406   size_t write_buffer_size;
00407 
00411   size_t write_buffer_send_offset;
00412 
00417   size_t write_buffer_append_offset;
00418 
00423   size_t remaining_upload_size;
00424 
00430   size_t response_write_position;
00431 
00436   size_t continue_message_write_offset;
00437 
00441   socklen_t addr_len;
00442 
00447   time_t last_activity;
00448 
00454   int socket_fd;
00455 
00463   int read_closed;
00464 
00468   enum MHD_CONNECTION_STATE state;
00469 
00474   unsigned int responseCode;
00475 
00483   int response_unready;
00484 
00488   int have_chunked_response;
00489 
00497   int have_chunked_upload;
00498 
00505   unsigned int current_chunk_size;
00506 
00511   unsigned int current_chunk_offset;
00512 
00513 };
00514 
00515 
00516 
00517 struct MHD_Daemon
00518 {
00519 
00523   MHD_AccessHandlerCallback default_handler;
00524 
00528   void *default_handler_cls;
00529 
00533   struct MHD_Connection *connections;
00534 
00535   MHD_AcceptPolicyCallback apc;
00536 
00537   void *apc_cls;
00538 
00539   MHD_RequestCompletedCallback notify_completed;
00540 
00541   void *notify_completed_cls;
00542 
00546   pthread_t pid;
00547 
00551   int socket_fd;
00552 
00556   int shutdown;
00557 
00561   unsigned int pool_size;
00562 
00566   unsigned int max_connections;
00567 
00572   unsigned int connection_timeout;
00573 
00578   unsigned int per_ip_connection_limit;
00579 
00583   enum MHD_OPTION options;
00584 
00588   unsigned short port;
00589 
00590 };
00591 
00592 
00593 #endif

Generated on Fri Oct 3 15:37:04 2008 for GNU libmicrohttpd by  doxygen 1.5.6