00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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
00039 #define METHOD_GET "GET"
00040 #define METHOD_POST "POST"
00041
00042
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
00093 #define STRLEN 256
00094 #define REQ_STRLEN 1024
00095 #define RES_STRLEN 2048
00096
00097
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
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 ssl_connection *ssl;
00122 } *RequestWrapper;
00123
00124 typedef struct request {
00125 char *method;
00126 char *url;
00127 char *protocol;
00128 char *pathinfo;
00129 FILE *inputstream;
00130 HttpHeader headers;
00131 HttpParameter params;
00132 InetAddress inetaddr;
00133 ssl_connection *ssl;
00134 } *HttpRequest;
00135
00136 typedef struct response {
00137 char *protocol;
00138 int status;
00139 char *status_msg;
00140 FILE *outputstream;
00141 unsigned char *outputbuffer;
00142 size_t bufsize;
00143 size_t bufused;
00144 HttpHeader headers;
00145 int is_committed;
00146 ssl_connection *ssl;
00147 } *HttpResponse;
00148
00149
00150 struct ServiceImpl {
00151 void(*doGet)(HttpRequest, HttpResponse);
00152 void(*doPost)(HttpRequest, HttpResponse);
00153 };
00154
00155
00156
00157
00158
00159
00160
00161 struct ServiceImpl Impl;
00162
00163
00164 void *http_processor(void *);
00165 void add_Impl(void *doGetFunc, void *doPostFunc);
00166 void send_error(HttpResponse, int status, char *message);
00167 void send_redirect(HttpResponse res, char *location);
00168 void out_print(HttpResponse res, const char *, ...);
00169 void set_header(HttpResponse res, char *name, char *value);
00170 void set_status(HttpResponse res, int status, char *status_message);
00171 void set_content_type(HttpResponse res, char *mime);
00172 char *get_header(HttpRequest req, const char *header_name);
00173 char *get_headers(HttpResponse res);
00174 char *get_parameter(HttpRequest req, const char *parameter_name);
00175 char *get_status_string(int status_code);
00176 void destroy_wrapper(RequestWrapper wrapper);
00177
00178 #endif