processor.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C), 2000-2002 by Contributors to the monit codebase. 
00003  * All Rights Reserved.
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License as
00007  * published by the Free Software Foundation; either version 2 of the
00008  * License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  * 
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software Foundation,
00017  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00018  */
00019 
00020 
00021 #ifndef PROCESSOR_H
00022 #define PROCESSOR_H
00023 
00024 #include <config.h>
00025 #include <stdio.h>
00026 
00027 #include "monitor.h"
00028 #include "net.h"
00029 #include "http_utils.h"
00030 
00031 /* Server masquerade */
00032 #define SERVER_NAME        "monit" 
00033 #define SERVER_VERSION     VERSION
00034 #define SERVER_URL         "http://www.tildeslash.com/monit/"
00035 #define SERVER_PROTOCOL    "HTTP/1.0"
00036 #define DATEFMT             "%a, %d %b %Y %H:%M:%S GMT"
00037 
00038 /* Protocol methods supported */
00039 #define METHOD_GET         "GET"
00040 #define METHOD_POST        "POST"
00041 
00042 /* HTTP Status Codes */
00043 #define SC_CONTINUE                      100
00044 #define SC_SWITCHING_PROTOCOLS           101
00045 #define SC_PROCESSING                    102
00046 #define SC_OK                            200
00047 #define SC_CREATED                       201
00048 #define SC_ACCEPTED                      202
00049 #define SC_NON_AUTHORITATIVE             203
00050 #define SC_NO_CONTENT                    204
00051 #define SC_RESET_CONTENT                 205
00052 #define SC_PARTIAL_CONTENT               206
00053 #define SC_MULTI_STATUS                  207
00054 #define SC_MULTIPLE_CHOICES              300
00055 #define SC_MOVED_PERMANENTLY             301
00056 #define SC_MOVED_TEMPORARILY             302
00057 #define SC_SEE_OTHER                     303
00058 #define SC_NOT_MODIFIED                  304
00059 #define SC_USE_PROXY                     305
00060 #define SC_TEMPORARY_REDIRECT            307
00061 #define SC_BAD_REQUEST                   400
00062 #define SC_UNAUTHORIZED                  401
00063 #define SC_PAYMENT_REQUIRED              402
00064 #define SC_FORBIDDEN                     403
00065 #define SC_NOT_FOUND                     404
00066 #define SC_METHOD_NOT_ALLOWED            405
00067 #define SC_NOT_ACCEPTABLE                406
00068 #define SC_PROXY_AUTHENTICATION_REQUIRED 407
00069 #define SC_REQUEST_TIMEOUT               408
00070 #define SC_CONFLICT                      409
00071 #define SC_GONE                          410
00072 #define SC_LENGTH_REQUIRED               411
00073 #define SC_PRECONDITION_FAILED           412
00074 #define SC_REQUEST_ENTITY_TOO_LARGE      413
00075 #define SC_REQUEST_URI_TOO_LARGE         414
00076 #define SC_UNSUPPORTED_MEDIA_TYPE        415
00077 #define SC_RANGE_NOT_SATISFIABLE         416
00078 #define SC_EXPECTATION_FAILED            417
00079 #define SC_UNPROCESSABLE_ENTITY          422
00080 #define SC_LOCKED                        423
00081 #define SC_FAILED_DEPENDENCY             424
00082 #define SC_INTERNAL_SERVER_ERROR         500
00083 #define SC_NOT_IMPLEMENTED               501
00084 #define SC_BAD_GATEWAY                   502
00085 #define SC_SERVICE_UNAVAILABLE           503
00086 #define SC_GATEWAY_TIMEOUT               504
00087 #define SC_VERSION_NOT_SUPPORTED         505
00088 #define SC_VARIANT_ALSO_VARIES           506
00089 #define SC_INSUFFICIENT_STORAGE          507
00090 #define SC_NOT_EXTENDED                  510
00091 
00092 /* Initial buffer sizes */
00093 #define STRLEN             256
00094 #define REQ_STRLEN         1024
00095 #define RES_STRLEN         2048
00096 
00097 /* Request timeout in seconds */
00098 #define REQUEST_TIMEOUT    30 
00099 
00100 #define TRUE               1
00101 #define FALSE              0
00102 
00103 struct entry {
00104   char *name;
00105   char *value;
00106   /* For internal use */
00107   struct entry *next;
00108 };
00109 typedef struct entry *HttpHeader;
00110 typedef struct entry *HttpParameter;
00111 
00112 typedef struct inetaddress {
00113   char *remote_host;
00114   char *local_host;
00115 } *InetAddress;
00116 
00117 typedef struct requestwrapper {
00118   int socket;
00119   int status;
00120   InetAddress inetaddr;
00121 } *RequestWrapper;
00122 
00123 typedef struct request {
00124   char *method;
00125   char *url;
00126   char *protocol;
00127   char *pathinfo;
00128   FILE *inputstream;
00129   HttpHeader headers;
00130   HttpParameter params;
00131   InetAddress inetaddr;
00132 } *HttpRequest;
00133 
00134 typedef struct response {
00135   char *protocol;
00136   int status;
00137   char *status_msg; 
00138   FILE *outputstream;
00139   unsigned char *outputbuffer;
00140   size_t bufsize;
00141   size_t bufused;
00142   HttpHeader headers;
00143   int is_committed;
00144 } *HttpResponse;
00145 
00146 
00147 struct  ServiceImpl {
00148   void(*doGet)(HttpRequest, HttpResponse);
00149   void(*doPost)(HttpRequest, HttpResponse);
00150 };
00151 
00152 /*
00153  * An object for implementors of the service functions; doGet and
00154  * doPost. Implementing modules i.e. CERVLETS, must implement the
00155  * doGet and doPost functions and the engine will call the add_Impl
00156  * function to setup the callback to these functions.
00157  */
00158 struct ServiceImpl Impl;
00159 
00160 /* Public prototypes */
00161 void *http_processor(void *);
00162 void add_Impl(void *doGetFunc, void *doPostFunc);
00163 void send_error(HttpResponse, int status, char *message);
00164 void send_redirect(HttpResponse res, char *location);
00165 void out_print(HttpResponse res,  const char *, ...);
00166 void set_header(HttpResponse res, char *name, char *value);
00167 void set_status(HttpResponse res, int status, char *status_message);
00168 void set_content_type(HttpResponse res, char *mime);
00169 char *get_header(HttpRequest req, const char *header_name);
00170 char *get_headers(HttpResponse res);
00171 char *get_parameter(HttpRequest req, const char *parameter_name);
00172 char *get_status_string(int status_code);
00173 void destroy_wrapper(RequestWrapper wrapper);
00174 
00175 #endif