/*
* 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"\
"\nBad Request
\n"\
"Your browser sent a request that this server could not understand.\n"\
"\n",
"\n400 Bad Request\n"\
"\nProblem mit Request
\n"\
"Ihr Browser hat einen Request geschickt, der von diesem Server "\
"nicht verstanden wurde.\n"\
"\n"
},
{
STATUS_Unauthorized,
"Unauthorized",
"\n401 Unauthorized\n"\
"\nUnauthorized
\n"\
"You have not the necessary rights to get the requested document.\n"\
"\n",
"\n401 Unauthorized\n"\
"\nNicht 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\nPayment Required
\n\n",
"\n402 Payment Required\n\nPayment Required
\n\n"
},
{
STATUS_Forbidden,
"Forbidden",
"\n403 Forbidden\n\nForbidden
\n\n",
"\n403 Forbidden\n\nForbidden
\n\n"
},
{
STATUS_Not_Found,
"Not Found",
"\n404 Not Found\n"\
"\nNot Found
\n"\
"Tried hard, really...\n"\
"\n",
"\n404 Not Found\n"\
"\nNicht Gefunden
\n"\
"Das angeforderte Dokument wurde nicht gefunden.\n"\
"\n"
},
{
STATUS_Method_Not_Allowed,
"Method Not Allowed",
"\n405 Method Not Allowed\n\nMethod Not Allowed
\n\n",
"\n405 Method Not Allowed\n\nMethod Not Allowed
\n\n"
},
{
STATUS_Not_Acceptable,
"Not Acceptable",
"\n406 Not Acceptable\n\nNot Acceptable
\n\n",
"\n406 Not Acceptable\n\nNot Acceptable
\n\n"
},
{
STATUS_Proxy_Authentication_Required,
"Proxy Authentication Required",
"\n407 Proxy Authentication Required\n\nProxy Authentication Required
\n\n",
"\n407 Proxy Authentication Required\n\nProxy Authentication Required
\n\n"
},
{
STATUS_Request_Timeout,
"Request Timeout",
"\n408 Request Timeout\n\nRequest Timeout
\n\n",
"\n408 Request Timeout\n\nRequest Timeout
\n\n"
},
{
STATUS_Conflict,
"Conflict",
"\n409 Conflict\n\nConflict
\n\n",
"\n409 Conflict\n\nConflict
\n\n"
},
{
STATUS_Gone,
"Gone",
"\n410 Gone\n\nGone
\n\n",
"\n410 Gone\n\nGone
\n\n"
},
{
STATUS_Length_Required,
"Length Required",
"\n411 Length Required\n\nLength Required
\n\n",
"\n411 Length Required\n\nLength Required
\n\n"
},
{
STATUS_Precondition_Failed,
"Precondition Failed",
"\n412 Precondition Failed\n\nPrecondition Failed
\n\n",
"\n412 Precondition Failed\n\nPrecondition Failed
\n\n"
},
{
STATUS_Request_Entity_Too_Large,
"Request Entity Too Large",
"\n413 Request Entity Too Large\nRequest Entity Too Large\n
\n\n",
"\n413 Request Entity Too Large\nRequest Entity Too Large\n
\n\n"
},
{
STATUS_Request_URI_Too_Long,
"Request-URI Too Long",
"\n414 Request-URI Too Long\nRequest-URI Too Long\n
\n\n",
"\n414 Request-URI Too Long\nRequest-URI Too Long\n
\n\n"
},
{
STATUS_Unsupported_Media_Type,
"Unsupported Media Type",
"\n415 Unsupported Media Type\n\nUnsupported Media Type
\n\n",
"\n415 Unsupported Media Type\n\nUnsupported Media Type
\n\n"
},
{
STATUS_Requested_Range_Not_Valid,
"Requested Range Not Valid",
"\n416 Requested Range Not Valid\n\nRequested Range Not Valid
\n\n",
"\n416 Requested Range Not Valid\n\nRequested Range Not Valid
\n\n"
},
{
STATUS_Internal_Server_Error,
"Internal Server Error",
"\n500 Internal Server Error\n\nInternal Server Error
\n\n",
"\n500 Internal Server Error\n\nInternal Server Error
\n\n"
},
{
STATUS_Not_Implemented,
"Not Implemented",
"\n501 Not Implemented\n\nNot Implemented
\n\n",
"\n501 Not Implemented\n\nNot Implemented
\n\n"
},
{
STATUS_Bad_Gateway,
"Bad Gateway",
"\n502 Bad Gateway\n\nBad Gateway
\n\n",
"\n502 Bad Gateway\n\nBad Gateway
\n\n"
},
{
STATUS_Service_Unavailable,
"Service Unavailable",
"\n503 Service Unavailable\n\nService Unavailable
\n\n",
"\n503 Service Unavailable\n\nService Unavailable
\n\n"
},
{
STATUS_Gateway_Timeout,
"Gateway Timeout",
"\n504 Gateway Timeout\n\nGateway Timeout
\n\n",
"\n504 Gateway Timeout\n\nGateway Timeout
\n\n"
},
{
STATUS_HTTP_Version_Not_Supported,
"HTTP Version Not Supported",
"\n505 HTTP Version Not Supported\n\nHTTP Version Not Supported
\n\n",
"\n505 HTTP Version Not Supported\n\nHTTP 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 );
}