/* * This file is part of rasdaman community. * * Rasdaman community is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Rasdaman community is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with rasdaman community. If not, see . * * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / rasdaman GmbH. * * For more information please see * or contact Peter Baumann via . */ #include "mymalloc/mymalloc.h" /*------------------------------------------------------------------------*/ /* http-error.c - HTTP Error message handling. */ /*------------------------------------------------------------------------*/ /* Comments: */ /* - Status: */ /* - The internal response strings should be completed and */ /* the overly long lines should be broken up. */ /* - A somewhat more dynamic approach to the handling of the */ /* error string table should be used. */ /*------------------------------------------------------------------------*/ #include "defs.h" #include "protos.h" #include "server.h" #include "http-defs.h" #include "http.h" struct HTTPError HTTPErrorTable[] = { { STATUS_Continue, "Continue", "", "" }, { STATUS_Switching_Protocols, "Switching Protocols", "", "" }, { STATUS_OK, "OK", "", "" }, { STATUS_Created, "Created", "", "" }, { STATUS_Accepted, "Accepted", "", "" }, { STATUS_Non_Authoritative_Information, "Non-Authoritative Information", "", "" }, { STATUS_No_Content, "No Content", "", "" }, { STATUS_Reset_Content, "Reset Content", "", "" }, { STATUS_Partial_Content, "Partial Content", "", "" }, { STATUS_Multiple_Choices, "Multiple Choices", "", "" }, { STATUS_Moved_Permanently, "Moved Permanently", "", "" }, { STATUS_Moved_Temporarily, "Moved Temporarily", "", "" }, { STATUS_See_Other, "See Other", "", "" }, { STATUS_Not_Modified, "Not Modified", "", "" }, { STATUS_Use_Proxy, "Use Proxy", "", "" }, { STATUS_Bad_Request, "Bad Request", "\n400 Bad Request\n"\ "\n

Bad Request

\n"\ "Your browser sent a request that this server could not understand.\n"\ "\n", "\n400 Bad Request\n"\ "\n

Problem mit Request

\n"\ "Ihr Browser hat einen Request geschickt, der von diesem Server "\ "nicht verstanden wurde.\n"\ "\n" }, { STATUS_Unauthorized, "Unauthorized", "\n401 Unauthorized\n"\ "\n

Unauthorized

\n"\ "You have not the necessary rights to get the requested document.\n"\ "\n", "\n401 Unauthorized\n"\ "\n

Nicht Authorisiert

\n"\ "Sie haben nicht die notwendigen Rechte um auf das angeforderte "\ "Dokument zuzugreifen.\n"\ "\n" }, { STATUS_Payment_Required, "Payment Required", "\n402 Payment Required\n\n

Payment Required

\n\n", "\n402 Payment Required\n\n

Payment Required

\n\n" }, { STATUS_Forbidden, "Forbidden", "\n403 Forbidden\n\n

Forbidden

\n\n", "\n403 Forbidden\n\n

Forbidden

\n\n" }, { STATUS_Not_Found, "Not Found", "\n404 Not Found\n"\ "\n

Not Found

\n"\ "Tried hard, really...\n"\ "\n", "\n404 Not Found\n"\ "\n

Nicht Gefunden

\n"\ "Das angeforderte Dokument wurde nicht gefunden.\n"\ "\n" }, { STATUS_Method_Not_Allowed, "Method Not Allowed", "\n405 Method Not Allowed\n\n

Method Not Allowed

\n\n", "\n405 Method Not Allowed\n\n

Method Not Allowed

\n\n" }, { STATUS_Not_Acceptable, "Not Acceptable", "\n406 Not Acceptable\n\n

Not Acceptable

\n\n", "\n406 Not Acceptable\n\n

Not Acceptable

\n\n" }, { STATUS_Proxy_Authentication_Required, "Proxy Authentication Required", "\n407 Proxy Authentication Required\n\n

Proxy Authentication Required

\n\n", "\n407 Proxy Authentication Required\n\n

Proxy Authentication Required

\n\n" }, { STATUS_Request_Timeout, "Request Timeout", "\n408 Request Timeout\n\n

Request Timeout

\n\n", "\n408 Request Timeout\n\n

Request Timeout

\n\n" }, { STATUS_Conflict, "Conflict", "\n409 Conflict\n\n

Conflict

\n\n", "\n409 Conflict\n\n

Conflict

\n\n" }, { STATUS_Gone, "Gone", "\n410 Gone\n\n

Gone

\n\n", "\n410 Gone\n\n

Gone

\n\n" }, { STATUS_Length_Required, "Length Required", "\n411 Length Required\n\n

Length Required

\n\n", "\n411 Length Required\n\n

Length Required

\n\n" }, { STATUS_Precondition_Failed, "Precondition Failed", "\n412 Precondition Failed\n\n

Precondition Failed

\n\n", "\n412 Precondition Failed\n\n

Precondition Failed

\n\n" }, { STATUS_Request_Entity_Too_Large, "Request Entity Too Large", "\n413 Request Entity Too Large\n

Request Entity Too Large\n

\n\n", "\n413 Request Entity Too Large\n

Request Entity Too Large\n

\n\n" }, { STATUS_Request_URI_Too_Long, "Request-URI Too Long", "\n414 Request-URI Too Long\n

Request-URI Too Long\n

\n\n", "\n414 Request-URI Too Long\n

Request-URI Too Long\n

\n\n" }, { STATUS_Unsupported_Media_Type, "Unsupported Media Type", "\n415 Unsupported Media Type\n\n

Unsupported Media Type

\n\n", "\n415 Unsupported Media Type\n\n

Unsupported Media Type

\n\n" }, { STATUS_Requested_Range_Not_Valid, "Requested Range Not Valid", "\n416 Requested Range Not Valid\n\n

Requested Range Not Valid

\n\n", "\n416 Requested Range Not Valid\n\n

Requested Range Not Valid

\n\n" }, { STATUS_Internal_Server_Error, "Internal Server Error", "\n500 Internal Server Error\n\n

Internal Server Error

\n\n", "\n500 Internal Server Error\n\n

Internal Server Error

\n\n" }, { STATUS_Not_Implemented, "Not Implemented", "\n501 Not Implemented\n\n

Not Implemented

\n\n", "\n501 Not Implemented\n\n

Not Implemented

\n\n" }, { STATUS_Bad_Gateway, "Bad Gateway", "\n502 Bad Gateway\n\n

Bad Gateway

\n\n", "\n502 Bad Gateway\n\n

Bad Gateway

\n\n" }, { STATUS_Service_Unavailable, "Service Unavailable", "\n503 Service Unavailable\n\n

Service Unavailable

\n\n", "\n503 Service Unavailable\n\n

Service Unavailable

\n\n" }, { STATUS_Gateway_Timeout, "Gateway Timeout", "\n504 Gateway Timeout\n\n

Gateway Timeout

\n\n", "\n504 Gateway Timeout\n\n

Gateway Timeout

\n\n" }, { STATUS_HTTP_Version_Not_Supported, "HTTP Version Not Supported", "\n505 HTTP Version Not Supported\n\n

HTTP Version Not Supported

\n\n", "\n505 HTTP Version Not Supported\n\n

HTTP Version Not Supported

\n\n" }, }; #define NUM_STATUSCODES 37 /****** http-error/GetHTTPErrorTableEntry ************************************ * * NAME * * * SYNOPSIS * * * FUNCTION * * * INPUTS * * * RESULT * * * NOTES * * * BUGS * * * SEE ALSO * * ****************************************************************************** * */ int GetHTTPErrorTableEntry( int Code ) { int low; int high; int mid; int check[ NUM_STATUSCODES ]; int i; low = 0; high = NUM_STATUSCODES - 1; for( i = 0; i < NUM_STATUSCODES; i++ ) check[ i ] = 0; while( low <= high ) { mid = ( low + high ) / 2; if( Code < HTTPErrorTable[mid].Code ) { if( check[mid] == 0 ) { check[mid] = 1; high = mid - 1; } else return( 0 ); } else if( Code > HTTPErrorTable[mid].Code ) { if( check[mid] == 0 ) { check[mid] = 1; low = mid + 1; } else return( 0 ); } else { return( mid ); } } } /****** http-error/CreateHTTPError ******************************************* * * NAME * * * SYNOPSIS * * * FUNCTION * * * INPUTS * * * RESULT * * * NOTES * * * BUGS * * * SEE ALSO * * ****************************************************************************** * */ rc_t CreateHTTPError( int Code, struct HTTPMode *Mode, struct HTTPMsg *Msg ) { char *Head; char *Buff; size_t BuffSize = BUFFSIZE; char *Body; size_t BodySize; size_t Used; int Entry; char Date[DATE_BUFFSIZE]; bzero( Date, DATE_BUFFSIZE ); if( ( Head = (char*)mymalloc( BuffSize ) ) == NULL ) { ErrorMsg( E_SYS, ERROR, "ERROR: CreateHTTPError() - malloc() error for head buffer." ); return( ERROR ); } Buff = Head; BuffSize -= 1; HTTP_Date( Date, DATE_BUFFSIZE ); Entry = GetHTTPErrorTableEntry( Code ); Body = HTTPErrorTable[Entry].Message_en; BodySize = strlen( HTTPErrorTable[Entry].Message_en ); CreateStatusLine( Buff, &BuffSize, Code, Mode->Protocol ); Used = strlen( Head ); Buff = Head + Used; BuffSize -= Used; SNPrintf( Buff, &BuffSize, "Date: %s\r\n" "Connection: close\r\n" "%s" "Content-Type: text/html\r\n" "Content-Language: %s\r\n" "Content-Length: %d\r\n\r\n", Date, SERVERFIELD, "en", BodySize ); Msg->Head = Head; Msg->Body = strdup(Body); Msg->BodySize = BodySize; return( OK ); }