/[monit]/monit/http/processor.c
ViewVC logotype

Diff of /monit/http/processor.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.14 by martinp, Tue Feb 11 21:27:40 2003 UTC revision 1.15 by hauk, Tue Apr 29 21:28:53 2003 UTC
# Line 163  void add_Impl(void *doGetFunc, void *doP Line 163  void add_Impl(void *doGetFunc, void *doP
163   * @param code Error Code to lookup and send   * @param code Error Code to lookup and send
164   * @param msg Optional error message (may be NULL)   * @param msg Optional error message (may be NULL)
165   */   */
166  void send_error(HttpResponse res, int code, char *msg) {  void send_error(HttpResponse res, int code, const char *msg) {
167    
   char *err= get_status_string(code);  
168    char *server= get_server();    char *server= get_server();
169      const char *err= get_status_string(code);
170        
171    reset_response(res);    reset_response(res);
172    set_content_type(res, "text/html");    set_content_type(res, "text/html");
173    set_status(res, code, err);    set_status(res, code);
174    out_print(res,    out_print(res,
175             "<html><head><title>%d %s</title></head>"\             "<html><head><title>%d %s</title></head>"\
176             "<body bgcolor=#FFFFFF><h2>%s</h2>%s<p>"\             "<body bgcolor=#FFFFFF><h2>%s</h2>%s<p>"\
177             "<hr><a href='%s'><font size=-1>%s</font></a>"\             "<hr><a href='%s'><font size=-1>%s</font></a>"\
178             "</body></html>\r\n",             "</body></html>\r\n",
179              code, err, err, msg?msg:"", SERVER_URL, server);              code, err, err, msg?msg:"", SERVER_URL, server);
   free(err);  
180    free(server);    free(server);
181                        
182  }  }
# Line 189  void send_error(HttpResponse res, int co Line 188  void send_error(HttpResponse res, int co
188   * @param res HttpResponse object   * @param res HttpResponse object
189   * @param location An absolute url to redirect to   * @param location An absolute url to redirect to
190   */   */
191  void send_redirect(HttpResponse res, char *location) {  void send_redirect(HttpResponse res, const char *location) {
192    
   char *string= get_status_string(SC_MOVED_TEMPORARILY);  
193    reset_response(res);    reset_response(res);
194    set_status(res, SC_MOVED_TEMPORARILY, string);    set_status(res, SC_MOVED_TEMPORARILY);
195    set_header(res, "Location", location);    set_header(res, "Location", location);
   free(string);  
196    
197  }  }
198    
# Line 335  void destroy_wrapper(RequestWrapper w) { Line 332  void destroy_wrapper(RequestWrapper w) {
332   * @param name Header key name   * @param name Header key name
333   * @param value Header key value   * @param value Header key value
334   */   */
335  void set_header(HttpResponse res, char *name, char *value) {  void set_header(HttpResponse res, const char *name, const char *value) {
336    
337    HttpHeader h= NEW(h);    HttpHeader h= NEW(h);
338        
# Line 376  void set_header(HttpResponse res, char * Line 373  void set_header(HttpResponse res, char *
373   * @param code A HTTP status code <100-510>   * @param code A HTTP status code <100-510>
374   * @param msg The status code string message   * @param msg The status code string message
375   */   */
376  void set_status(HttpResponse res, int code, char *msg) {  void set_status(HttpResponse res, int code) {
377        
378    res->status= code;    res->status= code;
379    free(res->status_msg);    res->status_msg= get_status_string(code);
   res->status_msg= xstrdup(msg);  
380        
381  }  }
382    
# Line 390  void set_status(HttpResponse res, int co Line 386  void set_status(HttpResponse res, int co
386   * @param res HttpResponse object   * @param res HttpResponse object
387   * @param mime Mime content type, e.g. text/html   * @param mime Mime content type, e.g. text/html
388   */   */
389  void set_content_type(HttpResponse res, char *mime) {  void set_content_type(HttpResponse res, const char *mime) {
390    
391    set_header(res, "Content-Type", mime);    set_header(res, "Content-Type", mime);
392    
# Line 478  char *get_headers(HttpResponse res) { Line 474  char *get_headers(HttpResponse res) {
474   * @return A default status message for the specified HTTP status   * @return A default status message for the specified HTTP status
475   * code.   * code.
476   */   */
477  char *get_status_string(int status) {  const char *get_status_string(int status) {
478    
479    switch (status) {    switch (status) {
480    case SC_OK:    case SC_OK:
481        return xstrdup("OK");        return "OK";
482    case SC_ACCEPTED:    case SC_ACCEPTED:
483        return xstrdup("Accepted");        return "Accepted";
484    case SC_BAD_GATEWAY:    case SC_BAD_GATEWAY:
485        return xstrdup("Bad Gateway");        return "Bad Gateway";
486    case SC_BAD_REQUEST:    case SC_BAD_REQUEST:
487        return xstrdup("Bad Request");        return "Bad Request";
488    case SC_CONFLICT:    case SC_CONFLICT:
489        return xstrdup("Conflict");        return "Conflict";
490    case SC_CONTINUE:    case SC_CONTINUE:
491        return xstrdup("Continue");        return "Continue";
492    case SC_CREATED:    case SC_CREATED:
493        return xstrdup("Created");        return "Created";
494    case SC_EXPECTATION_FAILED:    case SC_EXPECTATION_FAILED:
495        return xstrdup("Expectation Failed");        return "Expectation Failed";
496    case SC_FORBIDDEN:    case SC_FORBIDDEN:
497        return xstrdup("Forbidden");        return "Forbidden";
498    case SC_GATEWAY_TIMEOUT:    case SC_GATEWAY_TIMEOUT:
499        return xstrdup("Gateway Timeout");        return "Gateway Timeout";
500    case SC_GONE:    case SC_GONE:
501        return xstrdup("Gone");        return "Gone";
502    case SC_VERSION_NOT_SUPPORTED:    case SC_VERSION_NOT_SUPPORTED:
503        return xstrdup("HTTP Version Not Supported");        return "HTTP Version Not Supported";
504    case SC_INTERNAL_SERVER_ERROR:    case SC_INTERNAL_SERVER_ERROR:
505        return xstrdup("Internal Server Error");        return "Internal Server Error";
506    case SC_LENGTH_REQUIRED:    case SC_LENGTH_REQUIRED:
507        return xstrdup("Length Required");        return "Length Required";
508    case SC_METHOD_NOT_ALLOWED:    case SC_METHOD_NOT_ALLOWED:
509        return xstrdup("Method Not Allowed");        return "Method Not Allowed";
510    case SC_MOVED_PERMANENTLY:    case SC_MOVED_PERMANENTLY:
511        return xstrdup("Moved Permanently");        return "Moved Permanently";
512    case SC_MOVED_TEMPORARILY:    case SC_MOVED_TEMPORARILY:
513        return xstrdup("Moved Temporarily");        return "Moved Temporarily";
514    case SC_MULTIPLE_CHOICES:    case SC_MULTIPLE_CHOICES:
515        return xstrdup("Multiple Choices");        return "Multiple Choices";
516    case SC_NO_CONTENT:    case SC_NO_CONTENT:
517        return xstrdup("No Content");        return "No Content";
518    case SC_NON_AUTHORITATIVE:    case SC_NON_AUTHORITATIVE:
519        return xstrdup("Non-Authoritative Information");        return "Non-Authoritative Information";
520    case SC_NOT_ACCEPTABLE:    case SC_NOT_ACCEPTABLE:
521        return xstrdup("Not Acceptable");        return "Not Acceptable";
522    case SC_NOT_FOUND:    case SC_NOT_FOUND:
523        return xstrdup("Not Found");        return "Not Found";
524    case SC_NOT_IMPLEMENTED:    case SC_NOT_IMPLEMENTED:
525        return xstrdup("Not Implemented");        return "Not Implemented";
526    case SC_NOT_MODIFIED:    case SC_NOT_MODIFIED:
527        return xstrdup("Not Modified");        return "Not Modified";
528    case SC_PARTIAL_CONTENT:    case SC_PARTIAL_CONTENT:
529        return xstrdup("Partial Content");        return "Partial Content";
530    case SC_PAYMENT_REQUIRED:    case SC_PAYMENT_REQUIRED:
531        return xstrdup("Payment Required");        return "Payment Required";
532    case SC_PRECONDITION_FAILED:    case SC_PRECONDITION_FAILED:
533        return xstrdup("Precondition Failed");        return "Precondition Failed";
534    case SC_PROXY_AUTHENTICATION_REQUIRED:    case SC_PROXY_AUTHENTICATION_REQUIRED:
535        return xstrdup("Proxy Authentication Required");        return "Proxy Authentication Required";
536    case SC_REQUEST_ENTITY_TOO_LARGE:    case SC_REQUEST_ENTITY_TOO_LARGE:
537        return xstrdup("Request Entity Too Large");        return "Request Entity Too Large";
538    case SC_REQUEST_TIMEOUT:    case SC_REQUEST_TIMEOUT:
539        return xstrdup("Request Timeout");        return "Request Timeout";
540    case SC_REQUEST_URI_TOO_LARGE:    case SC_REQUEST_URI_TOO_LARGE:
541        return xstrdup("Request URI Too Large");        return "Request URI Too Large";
542    case SC_RANGE_NOT_SATISFIABLE:    case SC_RANGE_NOT_SATISFIABLE:
543        return xstrdup("Requested Range Not Satisfiable");        return "Requested Range Not Satisfiable";
544    case SC_RESET_CONTENT:    case SC_RESET_CONTENT:
545        return xstrdup("Reset Content");        return "Reset Content";
546    case SC_SEE_OTHER:    case SC_SEE_OTHER:
547        return xstrdup("See Other");        return "See Other";
548    case SC_SERVICE_UNAVAILABLE:    case SC_SERVICE_UNAVAILABLE:
549        return xstrdup("Service Unavailable");        return "Service Unavailable";
550    case SC_SWITCHING_PROTOCOLS:    case SC_SWITCHING_PROTOCOLS:
551        return xstrdup("Switching Protocols");        return "Switching Protocols";
552    case SC_UNAUTHORIZED:    case SC_UNAUTHORIZED:
553        return xstrdup("Unauthorized");        return "Unauthorized";
554    case SC_UNSUPPORTED_MEDIA_TYPE:    case SC_UNSUPPORTED_MEDIA_TYPE:
555        return xstrdup("Unsupported Media Type");        return "Unsupported Media Type";
556    case SC_USE_PROXY:    case SC_USE_PROXY:
557        return xstrdup("Use Proxy");        return "Use Proxy";
558    default: {    default: {
559       char buf[STRLEN];        return "Unknown HTTP status";
      snprintf(buf, STRLEN, "HTTP Response Status %d", status);  
      return xstrdup(buf);  
560      }      }
561    }    }
562    
# Line 1035  static void destroy_HttpResponse(HttpRes Line 1029  static void destroy_HttpResponse(HttpRes
1029            
1030      if ( res->outputstream ) fclose(res->outputstream);      if ( res->outputstream ) fclose(res->outputstream);
1031      free(res->protocol);      free(res->protocol);
     free(res->status_msg);  
1032      free(res->outputbuffer);      free(res->outputbuffer);
1033      if ( res->headers) destroy_entry(res->headers);      if ( res->headers) destroy_entry(res->headers);
1034      free(res);      free(res);
# Line 1146  static void internal_error(int client, i Line 1139  static void internal_error(int client, i
1139    char response[RES_STRLEN];    char response[RES_STRLEN];
1140    char *server= get_server();    char *server= get_server();
1141    char *date= get_date();    char *date= get_date();
1142    char *status_msg= get_status_string(status);    const char *status_msg= get_status_string(status);
1143    
1144    snprintf(response, RES_STRLEN,    snprintf(response, RES_STRLEN,
1145             "%s %d %s\r\n"             "%s %d %s\r\n"
# Line 1164  static void internal_error(int client, i Line 1157  static void internal_error(int client, i
1157    sock_send(client, response, strlen(response), 0);    sock_send(client, response, strlen(response), 0);
1158    free(server);    free(server);
1159    free(date);    free(date);
   free(status_msg);  
1160        
1161  }  }
1162    
# Line 1173  static void internal_error_ssl(ssl_conne Line 1165  static void internal_error_ssl(ssl_conne
1165    char response[RES_STRLEN];    char response[RES_STRLEN];
1166    char *server= get_server();    char *server= get_server();
1167    char *date= get_date();    char *date= get_date();
1168    char *status_msg= get_status_string(status);    const char *status_msg= get_status_string(status);
1169    
1170    snprintf(response, RES_STRLEN,    snprintf(response, RES_STRLEN,
1171             "%s %d %s\r\n"             "%s %d %s\r\n"
# Line 1192  static void internal_error_ssl(ssl_conne Line 1184  static void internal_error_ssl(ssl_conne
1184    send_ssl_socket(ssl, response, strlen(response));    send_ssl_socket(ssl, response, strlen(response));
1185    free(server);    free(server);
1186    free(date);    free(date);
   free(status_msg);  
1187        
1188  }  }
1189    

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26